:root {
  --bg: #f2f5fa;
  --surface: #ffffff;
  --ink: #14203a;
  --muted: #6c7a93;
  --line: #e3e8f2;
  --brand: #2f6bed;
  --brand-dark: #1d4fc4;
  --brand-soft: #eaf0ff;
  --green: #12876f;
  --green-soft: #e2f6f0;
  --red: #c73e3e;
  --red-soft: #fdecec;
  --amber: #a86708;
  --amber-soft: #fff4dd;
  --radius: 14px;
  --shadow: 0 10px 30px rgba(20, 32, 58, 0.08);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body { min-height: 100%; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--ink);
  font-size: 14px;
  line-height: 1.45;
}

h1, h2, h3 { margin: 0; line-height: 1.2; }
h1 { font-size: 26px; }
h2 { font-size: 22px; }
h3 { font-size: 15px; }
p { margin: 0; }

.muted { color: var(--muted); }
.small { font-size: 12px; }

/* ---------------------------------------------------------------- login */
.auth-screen {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    radial-gradient(circle at 15% 15%, rgba(47, 107, 237, 0.35), transparent 42%),
    radial-gradient(circle at 85% 80%, rgba(18, 135, 111, 0.22), transparent 45%),
    linear-gradient(150deg, #0d1730 0%, #16264a 55%, #0f1b35 100%);
}

.auth-card {
  width: min(100%, 390px);
  background: var(--surface);
  border-radius: 20px;
  padding: 36px 34px 26px;
  box-shadow: 0 30px 70px rgba(0, 0, 0, 0.35);
}

.auth-card h1 { margin-top: 18px; font-size: 22px; }
.auth-card .muted { margin-top: 6px; font-size: 13px; }

.logo-mark {
  width: 48px;
  height: 48px;
  border-radius: 13px;
  display: grid;
  place-items: center;
  font-weight: 800;
  letter-spacing: 0.5px;
  color: #fff;
  background: linear-gradient(135deg, #2f6bed, #15a58a);
  box-shadow: 0 8px 18px rgba(47, 107, 237, 0.35);
  user-select: none;
}
.logo-mark.small { width: 36px; height: 36px; border-radius: 10px; font-size: 12px; }

.portal-pill {
  display: inline-block;
  margin: 16px 0 22px;
  padding: 5px 11px;
  border-radius: 999px;
  background: var(--brand-soft);
  color: var(--brand-dark);
  font-size: 12px;
  font-weight: 600;
}

.field { display: block; margin-bottom: 14px; }
.field > span {
  display: block;
  margin-bottom: 6px;
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
}
.field input, .input {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fbfcfe;
  color: var(--ink);
  font: inherit;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.field input:focus, .input:focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(47, 107, 237, 0.15);
  background: #fff;
}
.form-error {
  margin: 4px 0 12px;
  padding: 8px 10px;
  border-radius: 8px;
  background: var(--red-soft);
  color: var(--red);
  font-size: 13px;
}
.auth-foot { margin-top: 20px; text-align: center; font-size: 12px; color: var(--muted); }

/* ---------------------------------------------------------------- buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  padding: 9px 14px;
  border-radius: 9px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, transform 0.05s;
}
.btn:hover { background: #f7f9fd; border-color: #cfd8e8; }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }
.btn-primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn-primary:hover { background: var(--brand-dark); border-color: var(--brand-dark); }
.btn-danger { background: var(--red); border-color: var(--red); color: #fff; }
.btn-danger:hover { background: #a92f2f; border-color: #a92f2f; }
.btn-ghost { background: transparent; border-color: rgba(255, 255, 255, 0.22); color: #fff; }
.btn-ghost:hover { background: rgba(255, 255, 255, 0.1); }
.btn-sm { padding: 6px 11px; font-size: 12px; }
.btn-block { width: 100%; }

/* ---------------------------------------------------------------- app shell */
.topbar {
  height: 66px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 0 22px;
  background: linear-gradient(120deg, #101a33, #1a2b52);
  color: #fff;
  position: sticky;
  top: 0;
  z-index: 20;
}
.topbar-left, .topbar-right { display: flex; align-items: center; gap: 12px; }
.brand { font-weight: 700; font-size: 15px; }
.portal-sm { font-size: 11px; color: rgba(255, 255, 255, 0.6); }
.user-chip {
  padding: 6px 11px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.1);
  font-size: 12px;
  font-weight: 600;
}

.shell {
  display: grid;
  grid-template-columns: 224px minmax(0, 1fr);
  min-height: calc(100vh - 66px);
}
.sidebar {
  background: var(--surface);
  border-right: 1px solid var(--line);
  padding: 18px 12px;
  position: sticky;
  top: 66px;
  height: calc(100vh - 66px);
  overflow-y: auto;
}
.nav-label {
  margin: 18px 10px 6px;
  font-size: 10px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
  font-weight: 700;
}
.nav-item {
  display: block;
  width: 100%;
  text-align: left;
  padding: 9px 12px;
  margin: 2px 0;
  border: 0;
  border-radius: 9px;
  background: transparent;
  color: var(--ink);
  font: inherit;
  font-weight: 500;
  cursor: pointer;
}
.nav-item:hover { background: #f3f6fc; }
.nav-item.active { background: var(--brand-soft); color: var(--brand-dark); font-weight: 700; }

.main { padding: 26px 30px 50px; min-width: 0; }
.page-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
}
.page-head h2 { margin-bottom: 4px; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* ---------------------------------------------------------------- cards */
.cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 12px;
  margin-bottom: 18px;
}
.stat-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 15px 16px;
  box-shadow: 0 4px 14px rgba(20, 32, 58, 0.04);
  position: relative;
  overflow: hidden;
}
.stat-card::before {
  content: "";
  position: absolute;
  inset: 0 auto 0 0;
  width: 3px;
  background: var(--brand);
}
.stat-card.green::before { background: var(--green); }
.stat-card.amber::before { background: var(--amber); }
.stat-card .stat-label { color: var(--muted); font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em; }
.stat-card .stat-value { margin-top: 6px; font-size: 24px; font-weight: 800; letter-spacing: -0.02em; }
.stat-card .stat-hint { color: var(--muted); font-size: 11px; margin-top: 2px; }

/* ---------------------------------------------------------------- panels */
.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: 0 4px 14px rgba(20, 32, 58, 0.04);
  margin-bottom: 16px;
  overflow: hidden;
}
.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 15px 18px;
  border-bottom: 1px solid var(--line);
}
.panel > form, .panel > .stack, .panel > .quick-actions { padding: 18px; }

.sync-banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 16px;
  margin-bottom: 16px;
  border-radius: 12px;
  background: var(--brand-soft);
  border: 1px solid #cfdcff;
  color: var(--brand-dark);
  font-weight: 600;
}
.sync-banner.ok { background: var(--green-soft); border-color: #bfe9dd; color: var(--green); }
.sync-banner.error { background: var(--red-soft); border-color: #f3caca; color: var(--red); }

.quick-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.stack { display: flex; flex-direction: column; gap: 12px; }

/* ---------------------------------------------------------------- tables */
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: 13px; }
.table th {
  text-align: left;
  padding: 10px 14px;
  background: #f7f9fd;
  border-bottom: 1px solid var(--line);
  color: var(--muted);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  white-space: nowrap;
}
.table td {
  padding: 10px 14px;
  border-bottom: 1px solid #eef2f8;
  vertical-align: top;
}
.table tbody tr:hover { background: #fafcff; }
.table tbody tr:last-child td { border-bottom: 0; }
.table .num { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
.table .nowrap { white-space: nowrap; }
.empty-row td { text-align: center; color: var(--muted); padding: 28px 14px; }

.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  background: #eef2f9;
  color: #4a5a76;
  font-size: 11px;
  font-weight: 700;
  white-space: nowrap;
}
.badge.green { background: var(--green-soft); color: var(--green); }
.badge.red { background: var(--red-soft); color: var(--red); }
.badge.amber { background: var(--amber-soft); color: var(--amber); }
.badge.blue { background: var(--brand-soft); color: var(--brand-dark); }

/* ---------------------------------------------------------------- toolbar */
.toolbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 18px;
  border-bottom: 1px solid var(--line);
  flex-wrap: wrap;
}
.input.search { max-width: 320px; }
.inline-field { display: inline-flex; align-items: center; gap: 8px; font-size: 12px; color: var(--muted); font-weight: 600; }
.inline-field .input { width: auto; min-width: 80px; padding: 7px 9px; }
.pager {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 12px;
  padding: 12px 18px;
  border-top: 1px solid var(--line);
}

/* ---------------------------------------------------------------- sync */
.checks { display: flex; flex-wrap: wrap; gap: 10px 18px; padding: 0 0 14px; }
.check { display: inline-flex; align-items: center; gap: 7px; font-size: 13px; cursor: pointer; }
.check input { width: 15px; height: 15px; accent-color: var(--brand); }
.sync-controls {
  display: flex;
  align-items: flex-end;
  gap: 12px;
  flex-wrap: wrap;
  padding-top: 4px;
}
.sync-controls .inline-field { flex-direction: column; align-items: flex-start; gap: 5px; }
.sync-progress { display: grid; gap: 8px; padding: 16px 18px; }
.progress-row { display: grid; grid-template-columns: 140px 1fr 120px; gap: 12px; align-items: center; font-size: 12px; }
.progress-bar {
  width: 100%;
  height: 9px;
  border: 0;
  border-radius: 999px;
  overflow: hidden;
  appearance: none;
  background: #edf1f8;
}
.progress-bar::-webkit-progress-bar { background: #edf1f8; border-radius: 999px; }
.progress-bar::-webkit-progress-value { background: linear-gradient(90deg, #2f6bed, #15a58a); border-radius: 999px; }
.progress-bar::-moz-progress-bar { background: linear-gradient(90deg, #2f6bed, #15a58a); border-radius: 999px; }

.spinner {
  width: 14px;
  height: 14px;
  border: 2px solid rgba(47, 107, 237, 0.25);
  border-top-color: var(--brand);
  border-radius: 50%;
  display: inline-block;
  animation: spin 0.8s linear infinite;
  vertical-align: -2px;
  margin-right: 6px;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------------------------------------------------------------- users */
#users-table td, #users-table th { white-space: nowrap; }

/* ---------------------------------------------------------------- toast */
.toast {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 100;
  max-width: 380px;
  padding: 12px 16px;
  border-radius: 11px;
  background: #18233d;
  color: #fff;
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.3);
  font-size: 13px;
  font-weight: 500;
  animation: toast-in 0.18s ease-out;
}
.toast.error { background: #9f2f2f; }
.toast.ok { background: #0f6f5c; }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

/* ---------------------------------------------------------------- responsive */
@media (max-width: 900px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar {
    position: static;
    height: auto;
    display: flex;
    gap: 4px;
    overflow-x: auto;
    border-right: 0;
    border-bottom: 1px solid var(--line);
    padding: 10px 12px;
  }
  .nav-label { display: none; }
  .nav-item { width: auto; white-space: nowrap; }
  .main { padding: 18px 14px 40px; }
  .grid-2 { grid-template-columns: 1fr; }
  .page-head { flex-direction: column; }
  .progress-row { grid-template-columns: 110px 1fr 90px; }
}

@media (max-width: 560px) {
  .topbar { padding: 0 12px; }
  .brand { font-size: 13px; }
  .user-chip { display: none; }
  .cards { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .stat-card .stat-value { font-size: 20px; }
  .toolbar { align-items: stretch; }
  .input.search { max-width: none; }
}
