:root {
  color-scheme: light;
  --bg: #f3f5fb;
  --bg-deep: #e9edf8;
  --surface: rgba(255, 255, 255, .72);
  --surface-strong: rgba(255, 255, 255, .9);
  --surface-soft: rgba(244, 246, 252, .72);
  --line: rgba(66, 74, 104, .14);
  --line-strong: rgba(80, 88, 122, .24);
  --text: #171923;
  --muted: #687086;
  --faint: #8c94a8;
  --accent: #6d5dfc;
  --accent-2: #897cff;
  --accent-soft: rgba(109, 93, 252, .12);
  --green: #168a5b;
  --green-soft: rgba(24, 174, 112, .12);
  --red: #c13d55;
  --red-soft: rgba(211, 62, 89, .11);
  --amber: #b3700d;
  --amber-soft: rgba(235, 159, 39, .14);
  --blue: #3275cf;
  --blue-soft: rgba(64, 135, 229, .12);
  --shadow: 0 22px 70px rgba(38, 45, 75, .11), inset 0 1px 0 rgba(255,255,255,.75);
  --shadow-soft: 0 10px 32px rgba(38, 45, 75, .08);
  --radius: 22px;
  --radius-sm: 14px;
  --content: 1420px;
}

html.dark {
  color-scheme: dark;
  --bg: #090b12;
  --bg-deep: #06070c;
  --surface: rgba(22, 25, 37, .68);
  --surface-strong: rgba(27, 30, 44, .9);
  --surface-soft: rgba(34, 38, 54, .58);
  --line: rgba(210, 216, 255, .11);
  --line-strong: rgba(211, 217, 255, .2);
  --text: #f5f6fb;
  --muted: #a7adbe;
  --faint: #797f91;
  --accent: #8c7cff;
  --accent-2: #a89eff;
  --accent-soft: rgba(139, 124, 255, .16);
  --green: #48d69b;
  --green-soft: rgba(49, 208, 145, .13);
  --red: #ff7287;
  --red-soft: rgba(255, 95, 121, .13);
  --amber: #f0b24c;
  --amber-soft: rgba(236, 171, 65, .14);
  --blue: #6ba7f7;
  --blue-soft: rgba(87, 155, 246, .14);
  --shadow: 0 28px 90px rgba(0, 0, 0, .36), inset 0 1px 0 rgba(255,255,255,.06);
  --shadow-soft: 0 12px 38px rgba(0, 0, 0, .23);
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  min-width: 320px;
  min-height: 100vh;
  color: var(--text);
  background: var(--bg);
  font-family: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 14px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}
button, input, select, textarea { font: inherit; }
button, select { cursor: pointer; }
a { color: inherit; text-decoration: none; }
h1, h2, p { margin-top: 0; }
h1 { margin-bottom: 8px; font-size: clamp(26px, 3vw, 40px); line-height: 1.08; letter-spacing: -.035em; }
h2 { margin-bottom: 0; font-size: 19px; line-height: 1.2; letter-spacing: -.018em; }
code, .mono { font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.tnum, .metric-value, .amount { font-variant-numeric: tabular-nums; }
.small-text { font-size: 12px; }

.ambient {
  position: fixed;
  inset: 0;
  z-index: 0;
  overflow: hidden;
  pointer-events: none;
  background:
    radial-gradient(circle at 15% 0%, rgba(104, 87, 246, .14), transparent 34%),
    radial-gradient(circle at 85% 28%, rgba(33, 173, 190, .1), transparent 30%),
    linear-gradient(145deg, var(--bg-deep), var(--bg));
}
.ambient i { position: absolute; border-radius: 50%; filter: blur(2px); opacity: .5; }
.ambient i:nth-child(1) { width: 420px; height: 420px; top: -190px; left: 7%; background: rgba(117, 87, 247, .13); }
.ambient i:nth-child(2) { width: 260px; height: 260px; top: 36%; right: -100px; background: rgba(43, 184, 191, .09); }
.ambient i:nth-child(3) { width: 360px; height: 360px; bottom: -220px; left: 35%; background: rgba(120, 105, 255, .08); }
.ambient i:nth-child(4) { width: 90px; height: 90px; top: 18%; left: 45%; background: rgba(255, 193, 92, .06); filter: blur(16px); }
.page-layer { position: relative; z-index: 1; min-height: 100vh; }

.glass {
  background: var(--surface);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  -webkit-backdrop-filter: blur(24px) saturate(135%);
  backdrop-filter: blur(24px) saturate(135%);
}

.brand { display: inline-flex; align-items: center; gap: 11px; min-width: 0; }
.brand-mark {
  display: grid;
  place-items: center;
  flex: 0 0 42px;
  width: 42px;
  height: 42px;
  color: white;
  border-radius: 13px;
  background: linear-gradient(145deg, var(--accent-2), #5845e8);
  box-shadow: 0 10px 28px rgba(98, 77, 238, .28), inset 0 1px 0 rgba(255,255,255,.28);
}
.brand-mark svg { width: 23px; height: 23px; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.brand > span:last-child { display: flex; flex-direction: column; min-width: 0; }
.brand strong { font-size: 15px; letter-spacing: -.01em; white-space: nowrap; }
.brand small { color: var(--muted); font-size: 11px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.brand-auth { margin-bottom: 40px; }

.auth-view { min-height: 100vh; display: grid; place-items: center; padding: 32px 18px; }
.auth-card { width: min(440px, 100%); padding: 30px; border-radius: 28px; }
.auth-card-wide { width: min(520px, 100%); }
.auth-copy { margin-bottom: 28px; }
.auth-copy h1 { font-size: 31px; }
.auth-copy p { margin-bottom: 0; color: var(--muted); }
.auth-foot { margin: 22px 0 0; color: var(--faint); font-size: 12px; text-align: center; }
.auth-back { display: block; margin: 18px auto 0; }

.stack { display: grid; gap: 16px; }
label { display: grid; gap: 7px; color: var(--muted); font-size: 12px; font-weight: 650; }
.label-note { font-weight: 450; }
input, select, textarea {
  width: 100%;
  min-height: 44px;
  color: var(--text);
  background: var(--surface-soft);
  border: 1px solid var(--line);
  border-radius: 12px;
  outline: none;
  padding: 10px 12px;
  transition: border-color .18s ease, box-shadow .18s ease, background .18s ease;
}
input::placeholder, textarea::placeholder { color: var(--faint); }
input:hover, select:hover, textarea:hover { border-color: var(--line-strong); }
input:focus, select:focus, textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); background: var(--surface-strong); }
input:disabled, select:disabled { cursor: not-allowed; opacity: .58; }

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  min-height: 43px;
  padding: 9px 16px;
  border: 1px solid transparent;
  border-radius: 12px;
  color: var(--text);
  background: transparent;
  font-weight: 700;
  white-space: nowrap;
  transition: transform .15s ease, border-color .18s ease, background .18s ease, opacity .18s ease;
}
.button:hover:not(:disabled) { transform: translateY(-1px); }
.button:active:not(:disabled), .press:active:not(:disabled) { transform: translateY(0) scale(.985); }
.button:focus-visible, a:focus-visible, summary:focus-visible { outline: 3px solid var(--accent-soft); outline-offset: 2px; }
.button:disabled { cursor: not-allowed; opacity: .48; }
.button.primary { color: #fff; background: linear-gradient(135deg, var(--accent), #6754eb); box-shadow: 0 9px 24px rgba(92, 74, 224, .22); }
.button.primary:hover:not(:disabled) { box-shadow: 0 12px 30px rgba(92, 74, 224, .3); }
.button.secondary { background: var(--surface-soft); border-color: var(--line); }
.button.secondary:hover:not(:disabled) { background: var(--surface-strong); border-color: var(--line-strong); }
.button.ghost { color: var(--muted); }
.button.ghost:hover:not(:disabled) { color: var(--text); background: var(--surface-soft); }
.button.danger { color: var(--red); background: var(--red-soft); border-color: rgba(217, 75, 99, .2); }
.button.small { min-height: 36px; padding: 7px 11px; font-size: 12px; border-radius: 10px; }
.icon-button { width: 40px; min-height: 40px; padding: 0; }
.icon { width: 17px; height: 17px; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

.eyebrow { color: var(--muted); font-size: 11px; font-weight: 800; letter-spacing: .105em; text-transform: uppercase; }
.error-text { min-height: 19px; margin: 0; color: var(--red); font-size: 12px; }
.notice { margin: 0 0 18px; padding: 13px 16px; border-radius: 12px; }
.notice.error { color: var(--red); background: var(--red-soft); border: 1px solid rgba(217, 75, 99, .18); }

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  border-bottom: 1px solid var(--line);
  background: color-mix(in srgb, var(--bg) 72%, transparent);
  -webkit-backdrop-filter: blur(24px) saturate(150%);
  backdrop-filter: blur(24px) saturate(150%);
}
.topbar-inner { width: min(var(--content), calc(100% - 40px)); min-height: 74px; margin: 0 auto; display: grid; grid-template-columns: 1fr minmax(240px, 380px) 1fr; align-items: center; gap: 22px; }
.project-switcher { display: grid; grid-template-columns: auto minmax(0, 1fr); align-items: center; gap: 10px; }
.project-switcher > span { white-space: nowrap; }
.project-switcher select { min-height: 40px; padding-top: 7px; padding-bottom: 7px; font-weight: 700; }
.topbar-actions { justify-self: end; display: flex; align-items: center; gap: 8px; }

.content { width: min(var(--content), calc(100% - 40px)); margin: 0 auto; padding: 42px 0 70px; }
.welcome-row { display: flex; align-items: flex-end; justify-content: space-between; gap: 28px; margin-bottom: 26px; scroll-margin-top: 100px; }
.welcome-row h1 { margin: 7px 0 6px; }
.status-line { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 7px; }
.status, .count-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 26px;
  padding: 4px 9px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 800;
  white-space: nowrap;
}
.status::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; box-shadow: 0 0 0 3px color-mix(in srgb, currentColor 14%, transparent); }
.status-success { color: var(--green); background: var(--green-soft); }
.status-error { color: var(--red); background: var(--red-soft); }
.status-pending { color: var(--amber); background: var(--amber-soft); }
.status-neutral { color: var(--muted); background: var(--surface-soft); }
.count-badge { min-width: 28px; color: var(--accent); background: var(--accent-soft); }

.empty-state { margin-bottom: 22px; padding: 38px 24px; border-radius: var(--radius); text-align: center; }
.empty-state p { color: var(--muted); }
.empty-icon { display: grid; place-items: center; width: 44px; height: 44px; margin: 0 auto 15px; color: var(--accent); background: var(--accent-soft); border-radius: 14px; font-size: 28px; }

.kpi-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 15px; margin-bottom: 15px; }
.metric { position: relative; overflow: hidden; min-height: 164px; padding: 22px; border-radius: var(--radius); }
.metric::after { content: ""; position: absolute; right: -40px; bottom: -55px; width: 130px; height: 130px; border-radius: 50%; background: var(--accent-soft); filter: blur(7px); }
.metric-icon { position: absolute; top: 18px; right: 18px; display: grid; place-items: center; width: 34px; height: 34px; border-radius: 11px; font-size: 13px; font-weight: 850; }
.metric-icon.violet { color: var(--accent); background: var(--accent-soft); }
.metric-icon.green { color: var(--green); background: var(--green-soft); }
.metric-icon.blue { color: var(--blue); background: var(--blue-soft); }
.metric-icon.amber { color: var(--amber); background: var(--amber-soft); }
.metric .eyebrow { display: block; padding-right: 34px; }
.metric-value { position: relative; z-index: 1; display: block; margin: 22px 0 3px; font-size: clamp(25px, 2.4vw, 35px); line-height: 1; letter-spacing: -.045em; white-space: nowrap; }
.metric small { position: relative; z-index: 1; color: var(--muted); font-size: 12px; }

.workspace-grid { display: grid; grid-template-columns: 1.08fr .92fr; gap: 15px; margin-bottom: 15px; }
.panel { padding: 22px; border-radius: var(--radius); }
.panel + .panel, .management-grid { scroll-margin-top: 96px; }
.panel-head, .history-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 18px; margin-bottom: 20px; }
.panel-head .eyebrow, .history-head .eyebrow { display: block; margin-bottom: 5px; }
.inline-form { display: flex; align-items: end; gap: 10px; }
.inline-form label { flex: 1; min-width: 0; }
.compact-stack { gap: 12px; }
.form-grid { display: grid; gap: 10px; }
.form-grid.two { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.form-note { min-height: 18px; margin: -2px 0 0; color: var(--muted); font-size: 11px; }
.result-box { margin-top: 17px; padding: 16px; border: 1px solid var(--line); border-radius: var(--radius-sm); background: var(--surface-soft); }
.safe-result { border-color: color-mix(in srgb, var(--green) 28%, var(--line)); background: var(--green-soft); }
.result-box .address-line { display: flex; align-items: center; gap: 10px; margin-top: 11px; }
.result-box code { flex: 1; min-width: 0; overflow-wrap: anywhere; color: var(--text); }
.result-meta { display: flex; flex-wrap: wrap; gap: 7px 16px; margin-top: 12px; color: var(--muted); font-size: 12px; }
.state-tile { min-height: 72px; margin-bottom: 10px; padding: 14px 15px; border: 1px solid var(--line); border-radius: var(--radius-sm); background: var(--surface-soft); }
.state-tile strong { display: block; margin-bottom: 3px; }
.state-tile .state-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.state-tile small { color: var(--muted); }
.security-row { display: flex; align-items: center; gap: 12px; }
.security-icon { display: grid; place-items: center; flex: 0 0 42px; width: 42px; height: 42px; color: var(--accent); background: var(--accent-soft); border-radius: 13px; font-size: 11px; font-weight: 850; }

#topups, .history-panel { margin-bottom: 15px; }
.table-scroll { width: 100%; overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius-sm); }
table { width: 100%; border-collapse: collapse; font-size: 12px; }
th { color: var(--muted); background: var(--surface-soft); font-size: 10px; letter-spacing: .06em; text-align: left; text-transform: uppercase; white-space: nowrap; }
th, td { min-height: 44px; padding: 11px 12px; border-bottom: 1px solid var(--line); vertical-align: middle; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr { transition: background .16s ease; }
tbody tr:hover { background: var(--surface-soft); }
.empty-cell { height: 80px; color: var(--muted); text-align: center; }
.cell-detail { display: block; margin-top: 2px; color: var(--muted); font-size: 10px; }
.address-cell { max-width: 210px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.history-head { margin-bottom: 17px; }
.head-actions { display: flex; gap: 7px; }
.filters { display: grid; grid-template-columns: 1fr 1fr 1fr 1fr 1.7fr 1.2fr; gap: 9px; margin-bottom: 14px; }
.filters input, .filters select { min-height: 40px; padding: 8px 10px; font-size: 12px; }
.summary-chips { display: flex; flex-wrap: wrap; gap: 7px; margin-bottom: 14px; }
.summary-chip { display: inline-flex; align-items: baseline; gap: 6px; padding: 7px 10px; border: 1px solid var(--line); border-radius: 999px; color: var(--muted); background: var(--surface-soft); font-size: 11px; }
.summary-chip strong { color: var(--text); }
.summary-chip.success strong { color: var(--green); }
.summary-chip.pending strong { color: var(--amber); }
.summary-chip.failed strong { color: var(--red); }
.history-table td { white-space: nowrap; }
.history-foot { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 12px; margin-top: 14px; }
.pager { display: flex; gap: 7px; }
.limit-select { justify-self: end; display: flex; grid-template-columns: auto 72px; align-items: center; gap: 8px; }
.limit-select select { min-height: 36px; padding: 6px 9px; }

.management-grid { display: grid; grid-template-columns: .9fr 1.25fr; gap: 15px; }
.management-grid .security-panel { grid-column: 1 / -1; }
.profile-list { display: grid; gap: 9px; margin-top: 16px; }
.profile-card { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: center; gap: 12px; padding: 13px; border: 1px solid var(--line); border-radius: var(--radius-sm); background: var(--surface-soft); }
.profile-card.selected { border-color: color-mix(in srgb, var(--accent) 45%, var(--line)); box-shadow: inset 3px 0 var(--accent); }
.profile-card-main { min-width: 0; cursor: pointer; }
.profile-card-title { display: flex; align-items: center; gap: 8px; margin-bottom: 4px; }
.profile-card-title strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.profile-card-meta { display: flex; flex-wrap: wrap; gap: 6px 10px; color: var(--muted); font-size: 11px; }
.profile-actions { display: flex; gap: 6px; }
.compact-table { margin-top: 16px; }
.compact-table .button { min-height: 30px; padding: 5px 8px; }
.key-search { max-width: 460px; }
.secret-box { position: relative; display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 6px 10px; padding: 14px; color: var(--text); background: var(--accent-soft); border: 1px solid color-mix(in srgb, var(--accent) 24%, transparent); border-radius: var(--radius-sm); }
.secret-box > span { grid-column: 1 / -1; color: var(--muted); font-size: 11px; font-weight: 750; text-transform: uppercase; letter-spacing: .07em; }
.secret-box code { align-self: center; min-width: 0; overflow-wrap: anywhere; }
.enroll-uri { margin: 12px 0 16px; color: var(--muted); font-size: 12px; }
.enroll-uri code { display: block; margin-top: 8px; overflow-wrap: anywhere; color: var(--faint); }
.security-panel { display: grid; grid-template-columns: auto 1fr 1fr; align-items: center; column-gap: 28px; }
.security-panel .panel-head { margin: 0; }
.security-row { padding: 0; }

.modal-scrim { position: fixed; inset: 0; z-index: 100; display: grid; place-items: center; padding: 20px; background: rgba(3, 4, 9, .58); -webkit-backdrop-filter: blur(10px); backdrop-filter: blur(10px); }
.modal-card { width: min(440px, 100%); padding: 25px; border-radius: 24px; background: var(--surface-strong); }
.modal-card h2 { margin: 6px 0 9px; font-size: 23px; }
.modal-copy { color: var(--muted); }
.confirm-rows { display: grid; grid-template-columns: auto 1fr; gap: 8px 16px; margin: 20px 0; padding: 14px; border-radius: var(--radius-sm); background: var(--surface-soft); }
.confirm-rows dt { color: var(--muted); }
.confirm-rows dd { margin: 0; text-align: right; font-weight: 750; overflow-wrap: anywhere; }
.confirm-otp { margin: -3px 0 16px; }
.confirm-otp + .error-text { margin-top: -10px; margin-bottom: 10px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 9px; }
.toast { position: fixed; right: 22px; bottom: 22px; z-index: 120; max-width: min(390px, calc(100% - 44px)); padding: 12px 16px; color: var(--text); background: var(--surface-strong); border: 1px solid var(--line-strong); border-radius: 13px; box-shadow: var(--shadow); font-weight: 650; }

@media (max-width: 1120px) {
  .topbar-inner { grid-template-columns: auto 1fr auto; }
  .project-switcher > span { display: none; }
  .kpi-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .filters { grid-template-columns: repeat(3, 1fr); }
  .security-panel { grid-template-columns: 1fr 1fr; }
  .security-panel .panel-head { grid-column: 1 / -1; }
}

@media (max-width: 800px) {
  .topbar-inner { width: min(100% - 24px, var(--content)); min-height: 68px; grid-template-columns: auto 1fr; gap: 10px; }
  .topbar .brand small { display: none; }
  .project-switcher { grid-column: 1 / -1; grid-row: 2; margin-bottom: 10px; }
  .project-switcher > span { display: block; }
  .topbar-actions { grid-column: 2; grid-row: 1; }
  .content { width: min(100% - 24px, var(--content)); padding-top: 28px; }
  .welcome-row { align-items: flex-start; flex-direction: column; gap: 14px; }
  .status-line { justify-content: flex-start; }
  .workspace-grid, .management-grid { grid-template-columns: 1fr; }
  .management-grid .security-panel { grid-column: auto; }
  .security-panel { display: block; }
  .security-panel .panel-head, .security-row { margin-bottom: 16px; }
  .filters { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 560px) {
  .auth-card { padding: 23px; border-radius: 23px; }
  .brand-auth { margin-bottom: 30px; }
  .topbar-refresh span, .topbar .brand > span:last-child { display: none; }
  .topbar-actions { gap: 4px; }
  .button.small { padding-left: 9px; padding-right: 9px; }
  .kpi-grid { grid-template-columns: 1fr; }
  .metric { min-height: 145px; }
  .panel { padding: 18px; }
  .inline-form { align-items: stretch; flex-direction: column; }
  .inline-form .button { width: 100%; }
  .form-grid.two { grid-template-columns: 1fr; }
  .filters { grid-template-columns: 1fr 1fr; }
  .filter-search { grid-column: 1 / -1; }
  .history-head { align-items: stretch; flex-direction: column; }
  .head-actions { justify-content: flex-start; }
  .history-foot { grid-template-columns: 1fr auto; }
  .history-foot .pager { grid-row: 2; }
  .limit-select { grid-column: 2; grid-row: 2; }
  .profile-card { grid-template-columns: 1fr; }
  .profile-actions { justify-content: flex-start; }
  .secret-box { grid-template-columns: 1fr; }
  .secret-box > span { grid-column: auto; }
  .secret-box .button { justify-self: start; }
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after { scroll-behavior: auto !important; transition: none !important; animation: none !important; }
}
