:root {
  --bg: #f6f8fb;
  --surface: #ffffff;
  --surface-alt: #f8fafc;
  --border: #e2e8f0;
  --text: #0f172a;
  --muted: #475569;
  --primary: #1d4ed8;
  --primary-hover: #1e40af;
  --danger: #dc2626;
  --danger-bg: #fef2f2;
  --ok: #15803d;
  --ok-bg: #f0fdf4;
  --warn: #b45309;
  --warn-bg: #fffbeb;
  --radius: 10px;
  --shadow: 0 1px 3px rgba(15, 23, 42, 0.07), 0 1px 2px rgba(15, 23, 42, 0.04);
  --mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Inter, sans-serif;
  color: var(--text);
  background: var(--bg);
  line-height: 1.5;
  font-size: 14px;
}

.hidden { display: none !important; }
.muted { color: var(--muted); margin: 4px 0 0; }
.align-right { text-align: right; }

/* Login */
.login-body {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.login-card {
  width: 100%;
  max-width: 420px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 28px;
  box-shadow: 0 10px 25px rgba(15, 23, 42, 0.08);
}
.login-card h1 { font-size: 20px; margin: 12px 0 4px; }
.hint { font-size: 12px; color: var(--muted); margin-top: 16px; }

.brand-mark {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border-radius: 10px;
  background: var(--primary);
  color: #fff;
  font-weight: 700;
  letter-spacing: 0.5px;
}
.brand-mark.small { width: 32px; height: 32px; font-size: 13px; border-radius: 8px; }

/* Topbar */
.topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 20;
}
.topbar-inner {
  max-width: 1220px;
  margin: 0 auto;
  padding: 12px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand-title { font-weight: 600; font-size: 15px; line-height: 1.2; }
.brand-sub { font-size: 12px; color: var(--muted); }
.topbar-right { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.operator-pill {
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 4px 12px;
  font-size: 12px;
  color: var(--muted);
}

/* Container & Stats */
.container {
  max-width: 1220px;
  margin: 0 auto;
  padding: 20px;
}
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(175px, 1fr));
  gap: 12px;
  margin-bottom: 18px;
}
.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  box-shadow: var(--shadow);
}
.stat-label { font-size: 12px; color: var(--muted); font-weight: 500; }
.stat-value { font-size: 24px; font-weight: 700; margin-top: 4px; }
.stat-ok { color: var(--ok); }
.stat-warn { color: var(--warn); }

/* Tabs */
.tabs {
  display: flex;
  gap: 6px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 16px;
  overflow-x: auto;
}
.tab {
  appearance: none;
  border: none;
  background: transparent;
  padding: 10px 16px;
  font-size: 14px;
  font-weight: 500;
  color: var(--muted);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  white-space: nowrap;
}
.tab:hover { color: var(--text); }
.tab.active {
  color: var(--primary);
  border-bottom-color: var(--primary);
}

/* Panels */
.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: var(--shadow);
}
.panel-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}
.panel-header > div:first-child { flex: 1; min-width: 260px; }
.panel-header h2 { margin: 0; font-size: 17px; }
.section-subtitle { margin: 20px 0 10px; font-size: 14px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; }

/* Tables */
.table-wrap { overflow-x: auto; }
.data-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.data-table th, .data-table td {
  text-align: left;
  padding: 9px 10px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
.data-table td { overflow-wrap: anywhere; }
.data-table th {
  font-weight: 600;
  color: var(--muted);
  font-size: 12px;
  background: var(--surface-alt);
  white-space: nowrap;
}
.data-table tr:last-child td { border-bottom: none; }
.empty-cell { text-align: center !important; color: var(--muted); padding: 24px !important; }
.mono { font-family: var(--mono); font-size: 12px; }

/* Badges & Pills */
.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  white-space: nowrap;
}
.badge-ok { background: var(--ok-bg); color: var(--ok); }
.badge-off { background: #f1f5f9; color: #64748b; }
.badge-err { background: var(--danger-bg); color: var(--danger); }
.badge-warn { background: var(--warn-bg); color: var(--warn); }
.badge-ch { background: #eff6ff; color: #1d4ed8; text-transform: uppercase; }

.pill-list { display: flex; flex-wrap: wrap; gap: 4px; }
.pill {
  background: #f1f5f9;
  color: var(--text);
  padding: 2px 7px;
  border-radius: 6px;
  font-size: 11px;
  font-family: var(--mono);
}

/* Progress bar */
.quota-bar {
  width: 110px;
  height: 6px;
  background: #e2e8f0;
  border-radius: 999px;
  overflow: hidden;
  margin-top: 4px;
}
.quota-fill { height: 100%; background: var(--primary); }
.quota-fill.high { background: var(--warn); }
.quota-fill.full { background: var(--danger); }

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 14px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  border: 1px solid transparent;
  white-space: nowrap;
  transition: background 0.15s, border-color 0.15s;
}
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--primary-hover); }
.btn-ghost { background: var(--surface); border-color: var(--border); color: var(--text); }
.btn-ghost:hover:not(:disabled) { background: var(--surface-alt); }
.btn-danger { background: var(--danger-bg); border-color: #fecaca; color: var(--danger); }
.btn-danger:hover:not(:disabled) { background: #fee2e2; }
.btn-sm { padding: 5px 10px; font-size: 12px; }
.btn-full { width: 100%; }
.btn-icon {
  background: transparent;
  border: none;
  font-size: 22px;
  line-height: 1;
  color: var(--muted);
  cursor: pointer;
  padding: 2px 6px;
}
.action-group { display: inline-flex; gap: 6px; justify-content: flex-end; }

/* Forms */
.stack { display: flex; flex-direction: column; gap: 14px; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.field { display: flex; flex-direction: column; gap: 5px; border: none; padding: 0; margin: 0; }
.field span, .field legend { font-size: 12px; font-weight: 600; color: var(--text); }
.field input[type="text"],
.field input[type="password"],
.field input[type="number"],
.field input[type="month"],
.field select {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 13px;
  background: var(--surface);
  color: var(--text);
}
.field input:focus, .field select:focus {
  outline: 2px solid #93c5fd;
  border-color: var(--primary);
}
.field-hint { font-size: 11px; color: var(--muted); }
.checkbox-field {
  flex-direction: row;
  align-items: center;
  gap: 8px;
  margin-top: 18px;
}
.checkbox-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 8px;
  max-height: 180px;
  overflow-y: auto;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-alt);
}
.check-item {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  cursor: pointer;
}
.inline-form { display: flex; gap: 8px; margin: 14px 0; }
.inline-form input {
  flex: 1;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 13px;
}
.month-controls { display: flex; align-items: flex-end; gap: 8px; }
.inline-field { display: flex; flex-direction: column; gap: 3px; font-size: 11px; font-weight: 600; color: var(--muted); }
.inline-field input { padding: 6px 8px; border: 1px solid var(--border); border-radius: 8px; font-size: 13px; }

/* Alerts & One-time token reveal */
.alert {
  padding: 10px 14px;
  border-radius: 8px;
  margin-bottom: 14px;
  font-size: 13px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
}
.alert-ok { background: var(--ok-bg); color: var(--ok); border: 1px solid #bbf7d0; }
.alert-error { background: var(--danger-bg); color: var(--danger); border: 1px solid #fecaca; }
.alert-warn { background: var(--warn-bg); color: var(--warn); border: 1px solid #fde68a; }

.token-reveal {
  background: #0f172a;
  color: #f8fafc;
  padding: 14px;
  border-radius: 10px;
  margin: 12px 0;
}
.token-reveal-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
  font-size: 12px;
  color: #fde68a;
}
.token-code {
  display: block;
  font-family: var(--mono);
  font-size: 12px;
  word-break: break-all;
  background: #1e293b;
  padding: 8px 10px;
  border-radius: 6px;
  color: #38bdf8;
}

/* Modal */
.modal {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}
.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(15, 23, 42, 0.45);
}
.modal-card {
  position: relative;
  width: 100%;
  max-width: 540px;
  max-height: 92vh;
  overflow-y: auto;
  background: var(--surface);
  border-radius: 14px;
  padding: 22px;
  box-shadow: 0 20px 45px rgba(15, 23, 42, 0.25);
}
.modal-card.modal-wide { max-width: 720px; }
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
}
.modal-header h3 { margin: 0; font-size: 17px; }
.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 16px;
}

@media (max-width: 640px) {
  .container { padding: 12px; }
  .form-row { grid-template-columns: 1fr; }
  .panel { padding: 14px; }
  .inline-form { flex-direction: column; }
}

/* Manual tab */
.manual-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  gap: 14px;
  margin-bottom: 16px;
}
.manual-card {
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px 16px;
}
.manual-card h3 { margin: 0 0 8px; font-size: 14px; }
.manual-steps { margin: 0; padding-left: 18px; display: flex; flex-direction: column; gap: 6px; font-size: 13px; }
.code-block-wrap {
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
  margin-bottom: 12px;
}
.code-block-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px;
  background: var(--surface-alt);
  border-bottom: 1px solid var(--border);
  font-size: 12px;
}
.code-pre {
  margin: 0;
  padding: 12px 14px;
  background: #0f172a;
  color: #e2e8f0;
  font-family: var(--mono);
  font-size: 12px;
  line-height: 1.5;
  overflow-x: auto;
}

