:root {
  --ink: #0f172a;
  --muted: #64748b;
  --accent: #1d4ed8;
  --accent2: #3b82f6;
  --danger: #dc2626;
  --success: #16a34a;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, 'PingFang SC', 'Microsoft YaHei', sans-serif;
  background: linear-gradient(170deg, #1e3a8a 0%, #2563eb 15%, #93c5fd 35%, #f0f4ff 55%, #f8fafc 100%);
  background-attachment: fixed;
  color: var(--ink);
  min-height: 100vh;
}

.bg-shape { display: none; }

/* ── Topbar ──────────────────────────────────────────────── */
.topbar {
  position: sticky;
  top: 0;
  z-index: 100;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 28px;
  background: rgba(255,255,255,.72);
  backdrop-filter: blur(24px);
  -webkit-backdrop-filter: blur(24px);
  border-bottom: 1px solid rgba(255,255,255,.5);
  box-shadow: 0 1px 12px rgba(15,23,42,.06);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.brand-mark {
  width: 32px;
  height: 32px;
  flex-shrink: 0;
  object-fit: contain;
  display: block;
}

.brand-text {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.brand-title {
  margin: 0;
  font-size: 19px;
  line-height: 1.05;
  letter-spacing: -0.02em;
  color: #1e3a8a;
  font-weight: 700;
}

.brand-subtitle {
  margin: 1px 0 0;
  font-size: 11px;
  color: var(--muted);
  line-height: 1.2;
}

/* ── Layout ──────────────────────────────────────────────── */
.layout {
  display: grid;
  grid-template-columns: 220px 1fr;
  gap: 0;
  max-width: 1440px;
  margin: 0 auto;
  min-height: calc(100vh - 60px);
}

/* ── Sidebar nav ─────────────────────────────────────────── */
.nav {
  display: flex;
  flex-direction: column;
  gap: 4px;
  align-self: start;
  position: sticky;
  top: 60px;
  padding: 20px 14px;
  background: rgba(255,255,255,.45);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-right: 1px solid rgba(255,255,255,.5);
  min-height: calc(100vh - 60px);
}

.nav button {
  display: flex;
  align-items: center;
  width: 100%;
  border: none;
  background: transparent;
  color: #334155;
  padding: 11px 14px;
  border-radius: 10px;
  cursor: pointer;
  font-size: 14px;
  font-weight: 500;
  text-align: left;
  transition: all .18s;
  box-shadow: none;
}

.nav button:hover {
  background: rgba(59,130,246,.08);
  color: #1e3a8a;
  transform: none;
}

.nav button.active {
  background: linear-gradient(135deg, #3b82f6, #1d4ed8);
  color: #fff;
  font-weight: 600;
  border-color: transparent;
  box-shadow: 0 4px 16px rgba(37,99,235,.25);
}

/* ── Panels ──────────────────────────────────────────────── */
.panel { display: none; }

.panel.active {
  display: block;
  animation: fadeUp .22s ease;
}

.panel > h2 {
  font-size: 24px;
  font-weight: 700;
  color: var(--ink);
  letter-spacing: -0.02em;
  margin: 0 0 20px;
}

@keyframes fadeUp {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ── Main content area ───────────────────────────────────── */
.layout > :not(.nav) {
  padding: 24px 28px;
}

/* ── Cards ────────────────────────────────────────────────── */
.card {
  background: rgba(255,255,255,.82);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid rgba(255,255,255,.6);
  border-radius: 14px;
  padding: 20px;
  margin-bottom: 16px;
  box-shadow: 0 2px 12px rgba(15,23,42,.05);
}

.card h3 {
  margin-top: 0;
  font-size: 15px;
  font-weight: 600;
  color: #334155;
}

.card > * + * {
  margin-top: 12px;
}

.card > :is(input, select, textarea) {
  display: block;
  width: 100%;
}

/* ── Grid & row helpers ──────────────────────────────────── */
.grid2 { display: grid; grid-template-columns: repeat(2, minmax(0,1fr)); gap: 14px; }
.grid3 { display: grid; grid-template-columns: repeat(3, minmax(0,1fr)); gap: 14px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }

/* ── KPIs ─────────────────────────────────────────────────── */
.kpis { display: grid; grid-template-columns: repeat(4, minmax(0,1fr)); gap: 14px; }
.kpis .card {
  margin: 0;
  transition: all .2s;
}
.kpis .card:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 24px rgba(15,23,42,.1);
}

/* ── Inputs ───────────────────────────────────────────────── */
input, select, button, textarea {
  border: 1px solid #d1d5db;
  border-radius: 10px;
  padding: 10px 14px;
  font-size: 14px;
  transition: border-color .18s ease, box-shadow .18s ease, transform .12s ease;
}

input, select, textarea {
  background: rgba(255,255,255,.9);
  color: var(--ink);
}

input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: #60a5fa;
  box-shadow: 0 0 0 4px rgba(96,165,250,.15);
  background: #fff;
}

/* ── Buttons ──────────────────────────────────────────────── */
button {
  line-height: 1.25;
  white-space: nowrap;
  font-weight: 600;
  letter-spacing: .01em;
  background: linear-gradient(135deg, #3b82f6, #1d4ed8);
  color: #fff;
  cursor: pointer;
  border-color: transparent;
  box-shadow: 0 4px 14px rgba(37,99,235,.2);
}

button:hover {
  transform: translateY(-1px);
  box-shadow: 0 6px 20px rgba(37,99,235,.3);
}

button:active {
  transform: translateY(0);
}

button:disabled {
  background: #9ca3af;
  border-color: #9ca3af;
  color: #f3f4f6;
  box-shadow: none;
  cursor: not-allowed;
  transform: none;
}

button.ghost {
  background: rgba(255,255,255,.7);
  color: #334155;
  border-color: #d1d5db;
  box-shadow: none;
  font-weight: 600;
}

button.ghost:hover {
  background: #fff;
  border-color: #93c5fd;
  color: #1d4ed8;
  transform: none;
}

pre { white-space: pre-wrap; }

/* ── Tables ───────────────────────────────────────────────── */
#docsTable table, #members table {
  width: 100%;
  border-collapse: collapse;
  border-radius: 10px;
  overflow: hidden;
  border: 1px solid rgba(226,232,240,.6);
  background: rgba(255,255,255,.9);
}

#docsTable th, #docsTable td, #members th, #members td {
  border-bottom: 1px solid #f1f5f9;
  padding: 12px;
  text-align: left;
}

#docsTable th, #members th {
  background: rgba(248,250,252,.8);
  color: var(--muted);
  font-size: 12px;
  letter-spacing: .03em;
  text-transform: uppercase;
  font-weight: 600;
}

#docsTable tr:hover, #members tr:hover {
  background: rgba(59,130,246,.04);
}

/* ── Toast ────────────────────────────────────────────────── */
#toast {
  position: fixed;
  bottom: 20px;
  right: 20px;
  background: #1e3a8a;
  color: #fff;
  padding: 12px 20px;
  border-radius: 12px;
  opacity: 0;
  transform: translateY(8px);
  transition: .22s;
  max-width: min(92vw, 720px);
  line-height: 1.4;
  white-space: normal;
  word-break: break-word;
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  box-shadow: 0 8px 24px rgba(30,58,138,.3);
}

#toast.show { opacity: 1; transform: translateY(0); }

/* ── Auth-only layout (pre-login) ─────────────────────────── */
body.auth-only .layout {
  grid-template-columns: 1fr;
  max-width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: calc(100vh - 60px);
  padding: 40px 20px;
}

body.auth-only .nav {
  display: none !important;
}

body.auth-only #tab-auth {
  max-width: 100%;
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 0;
}

body.auth-only #tab-auth > h2 {
  text-align: center;
  color: #fff;
  text-shadow: 0 2px 16px rgba(0,0,0,.1);
  margin-bottom: 24px;
  font-size: 28px;
}

body.auth-only #tab-auth .auth-card {
  background: rgba(255,255,255,.88);
  backdrop-filter: blur(24px);
  -webkit-backdrop-filter: blur(24px);
  border: 1px solid rgba(255,255,255,.6);
  border-radius: 16px;
  padding: 36px 32px;
  width: min(92vw, 440px);
  max-width: 440px;
  box-shadow: 0 16px 48px rgba(15,23,42,.1);
}

body.auth-only #tab-auth .auth-card > * + * {
  margin-top: 12px;
}

body.auth-only #tab-auth input,
body.auth-only #tab-auth select,
body.auth-only #tab-auth textarea {
  width: 100%;
  margin-bottom: 4px;
}

body.auth-only #tab-auth .row {
  justify-content: flex-start;
}

body.auth-only #tab-auth .grid3 {
  grid-template-columns: 1fr;
}

body.auth-only #tab-auth button {
  min-height: 40px;
}

body.auth-only #tab-auth #authLoginView,
body.auth-only #tab-auth #authRegisterView,
body.auth-only #tab-auth #authForgotView {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

body.auth-only #tab-auth #authLoginView > *,
body.auth-only #tab-auth #authRegisterView > *,
body.auth-only #tab-auth #authForgotView > * {
  margin-top: 0;
}

/* ── Modals ───────────────────────────────────────────────── */
#docModal > div, #accountModal > div {
  background: #fff;
  border-radius: 16px;
  box-shadow: 0 24px 64px rgba(15,23,42,.18);
}

#docModal, #accountModal {
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
}

/* ── Verify drop zone ────────────────────────────────────── */
#verifyDropZone {
  border-radius: 14px !important;
  border-color: #93c5fd !important;
  background: rgba(239,246,255,.5) !important;
  transition: all .2s;
}

#verifyDropZone:hover {
  border-color: #3b82f6 !important;
  background: rgba(219,234,254,.4) !important;
}

/* ── Responsive ──────────────────────────────────────────── */
@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; }
  .nav {
    flex-direction: row;
    overflow-x: auto;
    border-right: none;
    border-bottom: 1px solid rgba(255,255,255,.5);
    min-height: auto;
    padding: 12px 14px;
    position: static;
  }
  .nav button { white-space: nowrap; }
  .grid2, .grid3, .kpis { grid-template-columns: 1fr; }
}
