:root {
  --bg: #090a0d;
  --surface: #121318;
  --surface-2: #181a22;
  --border: rgba(255, 255, 255, 0.09);
  --text: #f4f4f5;
  --text-muted: #a1a1aa;
  --accent: #ffffff;
  --green: #30d158;
  --red: #ff453a;
  --blue: #38bdf8;
  --radius: 14px;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  min-height: 100vh;
  background: radial-gradient(110% 80% at 50% -10%, rgba(195, 205, 220, 0.08) 0%, #090a0d 58%);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 14px;
  line-height: 1.5;
}

.mono {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
}

.stack-md {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

/* Login */
.login-shell {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.login-card {
  width: 100%;
  max-width: 390px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 24px;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.5);
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.brand-row {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-logo-box {
  width: 38px;
  height: 38px;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.2);
  padding: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  overflow: hidden;
}

.brand-logo {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.brand-title {
  font-size: 16px;
  font-weight: 700;
  color: #ffffff;
}

.brand-sub {
  font-size: 12px;
  color: var(--text-muted);
}

.brand-pill {
  margin-left: 8px;
  font-size: 10.5px;
  padding: 2px 8px;
  border-radius: 999px;
  background: rgba(56, 189, 248, 0.14);
  color: var(--blue);
  border: 1px solid rgba(56, 189, 248, 0.28);
}

/* Topbar (Matching 9Score Popup Header) */
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  background: rgba(18, 19, 24, 0.90);
  background-image:
    radial-gradient(circle at 92% 50%, rgba(220, 225, 235, 0.15) 0%, rgba(200, 208, 220, 0.03) 40%, rgba(18, 20, 25, 0.75) 75%, rgba(10, 11, 14, 0.92) 100%),
    repeating-conic-gradient(from 0deg at 92% 50%, rgba(18, 20, 26, 0.75) 0deg 9deg, rgba(42, 46, 56, 0.75) 9deg 18deg);
  backdrop-filter: blur(28px) saturate(190%);
  -webkit-backdrop-filter: blur(28px) saturate(190%);
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.35);
}

.topbar-inner {
  max-width: 1120px;
  margin: 0 auto;
  padding: 11px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.hero-icon-box {
  width: 36px;
  height: 36px;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 9px;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.18), 0 2px 6px rgba(0, 0, 0, 0.3);
  flex-shrink: 0;
  padding: 3px;
}

.hero-logo-img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
  filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.35));
}

.hero-meta {
  min-width: 0;
}

.hero-title-row {
  display: flex;
  align-items: center;
  gap: 7px;
  flex-wrap: wrap;
}

.page-title {
  font-size: 14.5px;
  font-weight: 700;
  letter-spacing: -0.015em;
  color: #f4f4f5;
  line-height: 1.25;
}

.hero-subtitle {
  font-size: 11px;
  color: var(--text-muted);
  line-height: 1.3;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.user-chip {
  font-size: 12px;
  font-weight: 600;
  color: #e4e4e7;
  padding: 5px 11px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.07);
  border: 1px solid rgba(255, 255, 255, 0.12);
}

.btn-header-logout {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.18);
  color: #ffffff;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease;
}

.btn-header-logout:hover {
  background: rgba(255, 255, 255, 0.18);
  border-color: rgba(255, 255, 255, 0.28);
}

.container {
  max-width: 1120px;
  margin: 0 auto;
  padding: 18px 16px 48px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

/* Stats & Analytics */
.stats-overview {
  display: grid;
  grid-template-columns: 1.35fr 1fr;
  gap: 12px;
  align-items: stretch;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.stat-card {
  background: var(--surface);
  border: 1px solid rgba(255, 255, 255, 0.08);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.06), 0 4px 16px rgba(0, 0, 0, 0.25);
  border-radius: var(--radius);
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  transition: border-color 0.15s ease;
}

.stat-card:hover {
  border-color: rgba(255, 255, 255, 0.15);
}

.stat-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.stat-glyph {
  color: var(--text-muted);
  opacity: 0.75;
  flex-shrink: 0;
}

.stat-pct {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}

.dot {
  display: inline-block;
  width: 6px;
  height: 6px;
  border-radius: 999px;
  margin-right: 6px;
  vertical-align: middle;
}
.dot-green { background: var(--green); }
.dot-red { background: var(--red); }
.dot-blue { background: var(--blue); }

.stat-label {
  font-size: 12px;
  font-weight: 600;
  color: #d4d4d8;
}

.stat-value {
  font-size: 24px;
  font-weight: 800;
  line-height: 1.1;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
}

.stat-sub {
  font-size: 11.5px;
  color: var(--text-muted);
}

.stat-progress {
  height: 3px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.07);
  overflow: hidden;
  margin-top: 3px;
}

.stat-progress-fill {
  height: 100%;
  border-radius: 999px;
  transition: width 0.35s ease;
}

.fill-green { background: var(--green); }
.fill-red { background: var(--red); }

.analytics-card {
  background: var(--surface);
  border: 1px solid rgba(255, 255, 255, 0.08);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.06), 0 4px 16px rgba(0, 0, 0, 0.25);
  border-radius: var(--radius);
  padding: 16px 18px;
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.analytics-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 10px;
}

.analytics-title {
  font-size: 12.5px;
  font-weight: 600;
  color: #e4e4e7;
}

.weekly-bars {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 8px;
  align-items: end;
  height: 78px;
  padding-top: 6px;
}

.bar-col {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
  gap: 6px;
  height: 100%;
}

.bar-track {
  width: 100%;
  max-width: 18px;
  flex: 1;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  display: flex;
  align-items: flex-end;
  justify-content: center;
}

.bar-fill {
  width: 100%;
  border-radius: 4px 4px 0 0;
  background: var(--blue);
  transition: height 0.3s ease;
  min-height: 2px;
}

.bar-fill.is-zero {
  height: 2px !important;
  background: rgba(255, 255, 255, 0.14);
}

.bar-day {
  font-size: 10px;
  color: var(--text-muted);
}

.analytics-donut-block {
  display: flex;
  align-items: center;
  gap: 16px;
}

.donut-wrap {
  position: relative;
  width: 76px;
  height: 76px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

.donut-ring {
  stroke: rgba(255, 255, 255, 0.1);
}

.donut-seg-green {
  stroke: var(--green);
  stroke-linecap: round;
  transition: stroke-dasharray 0.4s ease;
}

.donut-label {
  position: absolute;
  font-size: 12px;
  font-weight: 800;
  color: #ffffff;
}

.donut-meta {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.text-green { color: var(--green); }
.text-red { color: var(--red); }
.text-blue { color: var(--blue); }

/* Tabs */
.tabs-bar {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  padding-bottom: 2px;
}

.tab-btn {
  padding: 8px 15px;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.09);
  border: 1px solid rgba(255, 255, 255, 0.18);
  color: #e4e4e7;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.15s ease;
}

.tab-btn:hover {
  background: rgba(255, 255, 255, 0.15);
  border-color: rgba(255, 255, 255, 0.3);
  color: #ffffff;
}

.tab-btn.active {
  background: #ffffff;
  color: #090a0d;
  border-color: #ffffff;
}

.tab-panel { display: none; }
.tab-panel.active { display: block; }

/* Cards & Grids */
.grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  align-items: start;
}

.grid-2-tight {
  display: grid;
  grid-template-columns: 0.9fr 1.1fr;
  gap: 10px;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
}

.card-narrow {
  max-width: 620px;
}

.card-title {
  font-size: 15px;
  font-weight: 700;
  margin-bottom: 14px;
}

.card-head-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 14px;
}
.card-head-row .card-title {
  margin-bottom: 0;
}

/* Inputs & Buttons */
.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.field label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
}

.label-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

input, select, textarea {
  width: 100%;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text);
  padding: 9px 12px;
  font-size: 13.5px;
  font-family: inherit;
  outline: none;
}

input:focus, select:focus, textarea:focus {
  border-color: rgba(255, 255, 255, 0.35);
}

.wa-box {
  resize: vertical;
  line-height: 1.5;
  font-size: 12.5px;
  color: #e4e4e7;
}

.preset-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.preset-chip {
  padding: 5px 10px;
  border-radius: 8px;
  border: 1px solid rgba(255, 255, 255, 0.16);
  background: rgba(255, 255, 255, 0.08);
  color: #e4e4e7;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
}

.preset-chip.active {
  background: rgba(56, 189, 248, 0.16);
  border-color: rgba(56, 189, 248, 0.45);
  color: var(--blue);
}

.btn-primary {
  background: #ffffff;
  color: #090a0d;
  border: none;
  border-radius: 10px;
  padding: 10px 16px;
  font-size: 13.5px;
  font-weight: 700;
  cursor: pointer;
}

.btn-primary:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.btn-ghost {
  background: rgba(255, 255, 255, 0.07);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 9px;
  padding: 7px 12px;
  font-size: 12.5px;
  font-weight: 600;
  cursor: pointer;
}

.btn-sm {
  background: rgba(255, 255, 255, 0.09);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 7px;
  padding: 4px 10px;
  font-size: 11.5px;
  font-weight: 600;
  cursor: pointer;
}

.btn-sm:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.btn-accent {
  background: rgba(48, 209, 88, 0.16);
  border-color: rgba(48, 209, 88, 0.4);
  color: var(--green);
}

.btn-danger-sm {
  background: rgba(255, 69, 58, 0.14);
  border-color: rgba(255, 69, 58, 0.35);
  color: var(--red);
}

.full-width { width: 100%; }

.badge-muted {
  font-size: 11.5px;
  padding: 3px 9px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.07);
  color: var(--text-muted);
}

.alert-error {
  background: rgba(255, 69, 58, 0.14);
  border: 1px solid rgba(255, 69, 58, 0.35);
  color: #fca5a5;
  border-radius: 9px;
  padding: 9px 12px;
  font-size: 12.5px;
}

/* History & Logs */
.toolbar-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 14px;
}

.toolbar-filters {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  flex: 1 1 280px;
}

.toolbar-filters input { flex: 1 1 200px; }
.toolbar-filters select { width: auto; min-width: 130px; }

.toolbar-actions {
  display: flex;
  gap: 8px;
}

.history-list, .logs-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.history-item, .log-item {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.history-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px;
}

.history-nim {
  font-weight: 700;
  font-size: 14px;
}

.status-pill {
  font-size: 11px;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 999px;
}

.status-pill.active {
  background: rgba(48, 209, 88, 0.16);
  color: var(--green);
}

.status-pill.expired {
  background: rgba(255, 69, 58, 0.16);
  color: var(--red);
}

.history-meta {
  font-size: 12px;
  color: var(--text-muted);
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.history-key-preview {
  font-size: 11.5px;
  color: #d4d4d8;
  background: rgba(0, 0, 0, 0.28);
  padding: 6px 9px;
  border-radius: 7px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.history-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.log-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-wrap: wrap;
}

.log-action {
  font-size: 11px;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 6px;
  background: rgba(56, 189, 248, 0.14);
  color: var(--blue);
}

.log-time {
  font-size: 11.5px;
  color: var(--text-muted);
}

.verify-result {
  margin-top: 14px;
  padding: 12px 14px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  font-size: 13px;
}

.toast {
  position: fixed;
  right: 16px;
  bottom: 16px;
  background: #ffffff;
  color: #090a0d;
  font-weight: 700;
  font-size: 12.5px;
  padding: 9px 14px;
  border-radius: 10px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.45);
  z-index: 100;
}

.empty-state {
  text-align: center;
  padding: 28px 12px;
  color: var(--text-muted);
}

@media (max-width: 820px) {
  .stats-overview {
    grid-template-columns: 1fr;
  }

  .stats-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .grid-2, .grid-2-tight {
    grid-template-columns: 1fr;
  }

  input, select, textarea {
    font-size: 14px;
  }
}
