:root {
  --canvas: #f4f6f8;
  --panel: #ffffff;
  --sidebar: #111827;
  --sidebar-soft: #1d2635;
  --ink: #172033;
  --muted: #687386;
  --line: #e3e7ed;
  --accent: #315ee7;
  --accent-dark: #2448bb;
  --accent-soft: #edf2ff;
  --green: #16825d;
  --green-soft: #e8f7f1;
  --amber: #b06913;
  --amber-soft: #fff4df;
  --red: #c23a36;
  --red-soft: #ffeded;
  --shadow: 0 18px 50px rgba(22, 32, 51, 0.09);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--ink);
  background: var(--canvas);
}

* { box-sizing: border-box; }
body { margin: 0; min-width: 320px; min-height: 100vh; background: var(--canvas); }
button, input, select { font: inherit; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: 0.5; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.mono, code { font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace; }

.eyebrow {
  margin: 0 0 8px;
  color: #8894a7;
  font-size: 11px;
  font-weight: 750;
  letter-spacing: 0.13em;
  text-transform: uppercase;
}

h1, h2 { margin: 0; letter-spacing: -0.035em; }
h1 { font-size: clamp(32px, 4vw, 46px); line-height: 1.06; }
h2 { font-size: 21px; }

input, select {
  width: 100%;
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0 12px;
  outline: none;
  background: #fff;
  color: var(--ink);
  transition: border-color 140ms ease, box-shadow 140ms ease;
}

input:focus, select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(49, 94, 231, 0.13);
}

button.primary, button.secondary {
  min-height: 42px;
  border-radius: 10px;
  padding: 0 16px;
  font-weight: 700;
}

button.primary { border: 1px solid var(--accent); background: var(--accent); color: #fff; }
button.primary:hover { border-color: var(--accent-dark); background: var(--accent-dark); }
button.secondary { border: 1px solid var(--line); background: #fff; color: var(--ink); }
button.secondary:hover { background: #f7f8fa; }
.wide { width: 100%; }

.brand-mark {
  display: grid;
  width: 52px;
  height: 52px;
  place-items: center;
  border-radius: 15px;
  background: linear-gradient(145deg, #4f7aff, #2649bd);
  box-shadow: 0 12px 28px rgba(49, 94, 231, 0.32);
  color: #fff;
  font-size: 16px;
  font-weight: 850;
  letter-spacing: -0.04em;
}

.brand-mark.small { width: 38px; height: 38px; border-radius: 11px; font-size: 13px; box-shadow: none; }

.login-layout { display: grid; grid-template-columns: 1.05fr 0.95fr; min-height: 100vh; }
.login-story {
  position: relative;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: clamp(40px, 8vw, 120px);
  background: #101827;
  color: #fff;
}

.login-story::before, .login-story::after {
  position: absolute;
  content: "";
  border-radius: 50%;
  filter: blur(2px);
}
.login-story::before { width: 450px; height: 450px; right: -230px; top: -160px; background: rgba(71, 109, 231, 0.2); }
.login-story::after { width: 260px; height: 260px; left: -130px; bottom: -100px; background: rgba(45, 192, 145, 0.12); }
.login-story .brand-mark { margin-bottom: 70px; }
.login-story h1 { max-width: 650px; font-size: clamp(42px, 5vw, 72px); }
.login-copy { max-width: 570px; margin: 24px 0 34px; color: #aeb9ca; font-size: 18px; line-height: 1.65; }
.login-features { display: flex; flex-wrap: wrap; gap: 10px; }
.login-features span { border: 1px solid #344154; border-radius: 999px; padding: 9px 13px; color: #bac4d3; font-size: 13px; }
.login-panel { display: grid; place-items: center; padding: 32px; }
.login-card { display: grid; width: min(430px, 100%); gap: 22px; border: 1px solid var(--line); border-radius: 18px; padding: 34px; background: var(--panel); box-shadow: var(--shadow); }
.login-card h2 { margin-bottom: 10px; font-size: 31px; }
.form-hint { margin: 0; color: var(--muted); font-size: 12px; line-height: 1.55; }
.form-hint code { font-size: 11px; }
#setupPasswordStep, #setupCodeStep { display: grid; gap: 18px; }
.setup-secret code { letter-spacing: 0.08em; }

.field { display: block; }
.field > span, .compact-field > span { display: block; margin-bottom: 7px; color: #4f5b6e; font-size: 12px; font-weight: 700; }
.field small { display: block; margin-top: 6px; color: var(--muted); font-size: 11px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.check-field { display: flex; align-items: center; gap: 9px; color: #465267; font-size: 13px; }
.check-field input { width: 17px; min-height: 17px; accent-color: var(--accent); }

.app-layout { display: grid; grid-template-columns: 246px minmax(0, 1fr); min-height: 100vh; }
.sidebar { position: sticky; top: 0; display: flex; height: 100vh; flex-direction: column; padding: 24px 16px 16px; background: var(--sidebar); color: #fff; }
.sidebar-brand { display: flex; align-items: center; gap: 11px; padding: 0 8px 30px; }
.sidebar-brand strong, .sidebar-brand span { display: block; }
.sidebar-brand strong { font-size: 14px; }
.sidebar-brand span { margin-top: 3px; color: #7f8a9b; font-size: 10px; letter-spacing: 0.1em; text-transform: uppercase; }
.sidebar nav { display: grid; gap: 5px; }
.nav-item { display: flex; min-height: 44px; align-items: center; gap: 11px; border: 0; border-radius: 10px; padding: 0 12px; background: transparent; color: #97a3b5; text-align: left; font-size: 13px; font-weight: 650; }
.nav-item:hover { background: #182232; color: #fff; }
.nav-item.active { background: var(--sidebar-soft); color: #fff; }
.nav-icon { display: grid; width: 22px; place-items: center; color: #728098; font-size: 17px; }
.nav-item.active .nav-icon { color: #87a3ff; }
.sidebar-footer { display: grid; grid-template-columns: 36px minmax(0, 1fr) 30px; align-items: center; gap: 9px; margin-top: auto; border-top: 1px solid #263142; padding: 18px 5px 3px; }
.user-avatar { display: grid; width: 36px; height: 36px; place-items: center; border-radius: 10px; background: #263750; color: #a8bcff; font-size: 13px; font-weight: 800; }
.sidebar-user { min-width: 0; }
.sidebar-user strong, .sidebar-user span { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sidebar-user strong { font-size: 12px; }
.sidebar-user span { margin-top: 3px; color: #798699; font-size: 10px; }
.icon-button { display: grid; width: 32px; height: 32px; place-items: center; border: 0; border-radius: 8px; padding: 0; background: transparent; color: #8490a3; font-size: 19px; }
.icon-button:hover { background: rgba(125, 141, 166, 0.13); color: inherit; }

.content { min-width: 0; padding: 34px clamp(24px, 4vw, 58px) 60px; }
.page-header { display: flex; min-height: 90px; align-items: flex-start; justify-content: space-between; gap: 24px; margin-bottom: 28px; }
.page-header h1 { font-size: 35px; }
.page-subtitle { margin: 9px 0 0; color: var(--muted); font-size: 14px; }
.header-actions { display: flex; align-items: flex-end; gap: 10px; }
.compact-field { width: 220px; }

.alert { margin-bottom: 18px; border: 1px solid #cbd7ff; border-radius: 11px; padding: 12px 14px; background: var(--accent-soft); color: #2948a7; font-size: 13px; }
.alert.error { border-color: #f4c4c2; background: var(--red-soft); color: var(--red); }
.alert.success { border-color: #bce5d5; background: var(--green-soft); color: var(--green); }

.metric-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; }
.metric-card { position: relative; overflow: hidden; min-height: 155px; border: 1px solid var(--line); border-radius: 15px; padding: 21px; background: var(--panel); box-shadow: 0 6px 20px rgba(27, 40, 66, 0.035); }
.metric-card::before { position: absolute; content: ""; width: 6px; height: 40px; left: 0; top: 24px; border-radius: 0 5px 5px 0; background: #8793a5; }
.metric-card.accent::before { background: var(--accent); }
.metric-card.warning::before { background: var(--amber); }
.metric-card.success::before { background: var(--green); }
.metric-card span, .metric-card small { display: block; color: var(--muted); }
.metric-card span { font-size: 12px; font-weight: 700; }
.metric-card strong { display: block; margin: 18px 0 10px; font-size: 36px; line-height: 1; letter-spacing: -0.05em; }
.metric-card small { font-size: 11px; }
.dashboard-grid { display: grid; grid-template-columns: 0.8fr 1.2fr; gap: 14px; margin-top: 14px; }
.panel { border: 1px solid var(--line); border-radius: 15px; background: var(--panel); box-shadow: 0 6px 20px rgba(27, 40, 66, 0.03); }
.panel.compact { border-radius: 13px; }
.panel-header { display: flex; min-height: 70px; align-items: center; justify-content: space-between; gap: 16px; border-bottom: 1px solid var(--line); padding: 14px 20px; }
.panel-header h2 { font-size: 17px; letter-spacing: -0.02em; }
.status-breakdown { display: grid; gap: 0; padding: 8px 20px 16px; }
.status-breakdown > div { display: flex; min-height: 54px; align-items: center; justify-content: space-between; border-bottom: 1px solid #edf0f4; }
.status-breakdown > div:last-child { border: 0; }
.status-breakdown span { display: flex; align-items: center; gap: 10px; color: #556175; font-size: 13px; }
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; }
.dot.paid { background: var(--green); }.dot.pending { background: var(--amber); }.dot.cancelled { background: var(--red); }
.quick-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; padding: 18px; }
.quick-grid button { display: block; min-height: 82px; border: 1px solid var(--line); border-radius: 11px; padding: 15px; background: #fafbfc; color: var(--ink); text-align: left; }
.quick-grid button:hover { border-color: #c8d5ff; background: var(--accent-soft); }
.quick-grid strong, .quick-grid span { display: block; }
.quick-grid strong { margin-bottom: 8px; font-size: 13px; }
.quick-grid span { color: var(--muted); font-size: 11px; }

.filters { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 14px; padding: 10px; }
.tabs { display: flex; gap: 3px; }
.tabs button { min-height: 36px; border: 0; border-radius: 8px; padding: 0 13px; background: transparent; color: var(--muted); font-size: 12px; font-weight: 700; }
.tabs button:hover, .tabs button.active { background: var(--accent-soft); color: var(--accent); }
.search-row { display: flex; width: min(540px, 100%); gap: 8px; }
.search-row input { min-height: 40px; }
.table-panel { overflow: hidden; }
.table-scroll { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { border-bottom: 1px solid #edf0f3; padding: 14px 16px; text-align: left; vertical-align: middle; white-space: nowrap; }
th { background: #fafbfc; color: #7b8798; font-size: 10px; font-weight: 800; letter-spacing: 0.08em; text-transform: uppercase; }
td { color: #354054; font-size: 12px; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: #fbfcff; }
.table-primary { display: block; color: var(--ink); font-weight: 720; }
.table-secondary { display: block; max-width: 230px; overflow: hidden; margin-top: 4px; color: var(--muted); font-size: 10px; text-overflow: ellipsis; }
.badge { display: inline-flex; min-height: 25px; align-items: center; border-radius: 999px; padding: 0 9px; background: #eef1f5; color: #5d6879; font-size: 10px; font-weight: 800; letter-spacing: 0.02em; }
.badge.paid, .badge.active { background: var(--green-soft); color: var(--green); }
.badge.pending, .badge.default { background: var(--amber-soft); color: var(--amber); }
.badge.cancelled, .badge.inactive { background: var(--red-soft); color: var(--red); }
.row-actions { display: flex; justify-content: flex-end; gap: 6px; }
.table-action { min-height: 31px; border: 1px solid var(--line); border-radius: 8px; padding: 0 9px; background: #fff; color: #4d596c; font-size: 10px; font-weight: 750; }
.table-action:hover { border-color: #b9c9fb; color: var(--accent); }
.table-action.danger:hover { border-color: #f0b5b2; color: var(--red); }
.empty-state { padding: 54px 20px; color: var(--muted); text-align: center; font-size: 13px; }
.pagination { display: flex; gap: 6px; }
.pagination button { min-width: 40px; padding: 0; }
.security-note { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; border: 1px solid #f0d9ac; border-radius: 12px; padding: 13px 15px; background: #fff9ed; color: #82520d; font-size: 12px; }
.security-note span { color: #8a6b3c; }

dialog { width: min(610px, calc(100vw - 30px)); border: 0; border-radius: 18px; padding: 0; box-shadow: 0 28px 80px rgba(11, 19, 33, 0.28); }
dialog::backdrop { background: rgba(16, 24, 39, 0.62); backdrop-filter: blur(3px); }
.dialog-form { display: grid; gap: 18px; padding: 25px; }
.dialog-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 18px; }
.dialog-header h2 { font-size: 24px; }
.dialog-header .icon-button { margin-top: -5px; margin-right: -5px; color: var(--muted); }
.dialog-actions { display: flex; justify-content: flex-end; gap: 9px; margin-top: 4px; border-top: 1px solid var(--line); padding-top: 18px; }
.scope-field { display: grid; gap: 10px; border: 1px solid var(--line); border-radius: 10px; padding: 13px; }
.scope-field legend { padding: 0 5px; color: #4f5b6e; font-size: 12px; font-weight: 700; }
.secret-box { display: flex; align-items: center; gap: 10px; border: 1px solid #cbd7ff; border-radius: 11px; padding: 10px; background: var(--accent-soft); }
.secret-box code { min-width: 0; flex: 1; overflow-wrap: anywhere; color: #2948a7; font-size: 12px; }
.recovery-codes { margin: 0; border: 1px solid #cbd7ff; border-radius: 11px; padding: 16px; background: var(--accent-soft); color: #2948a7; font-size: 14px; line-height: 1.8; letter-spacing: 0.06em; text-align: center; }

@media (max-width: 1100px) {
  .metric-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .dashboard-grid { grid-template-columns: 1fr; }
  .filters { align-items: stretch; flex-direction: column; }
  .search-row { width: 100%; }
}

@media (max-width: 760px) {
  .login-layout { grid-template-columns: 1fr; }
  .login-story { min-height: 38vh; padding: 32px; }
  .login-story .brand-mark { margin-bottom: 35px; }
  .login-copy { margin-bottom: 0; font-size: 15px; }
  .login-features { display: none; }
  .login-panel { padding: 20px; }
  .login-card { padding: 25px; }
  .app-layout { display: block; }
  .sidebar { position: static; width: 100%; height: auto; padding: 13px; }
  .sidebar-brand { padding: 0 5px 12px; }
  .sidebar nav { display: flex; overflow-x: auto; padding-bottom: 6px; }
  .nav-item { flex: 0 0 auto; min-height: 38px; }
  .nav-icon { display: none; }
  .sidebar-footer { margin-top: 8px; }
  .content { padding: 25px 16px 45px; }
  .page-header { display: block; margin-bottom: 20px; }
  .header-actions { margin-top: 18px; }
  .compact-field { flex: 1; width: auto; }
  .metric-grid { grid-template-columns: 1fr 1fr; gap: 9px; }
  .metric-card { min-height: 130px; padding: 17px; }
  .metric-card strong { font-size: 30px; }
  .tabs { overflow-x: auto; }
  .form-grid { grid-template-columns: 1fr; }
}

@media (max-width: 480px) {
  .metric-grid, .quick-grid { grid-template-columns: 1fr; }
  .search-row { flex-direction: column; }
  .header-actions { align-items: stretch; flex-direction: column; }
  .secret-box { align-items: stretch; flex-direction: column; }
}
