:root {
  --bg-canvas: #f4f6fb;
  --bg-sidebar: #ffffff;
  --bg-topbar: rgba(255, 255, 255, 0.88);
  --bg-card: #ffffff;
  --bg-subtle: #f8fafc;
  --bg-input: #ffffff;
  --bg-hover: #f1f5f9;
  --text-main: #0f172a;
  --text-secondary: #334155;
  --text-muted: #64748b;
  --text-faint: #94a3b8;
  --border-color: #e2e8f0;
  --border-subtle: #f1f5f9;
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --primary-soft: #eff6ff;
  --primary-border: #bfdbfe;
  --amber: #d97706;
  --amber-bright: #f59e0b;
  --amber-soft: #fffbeb;
  --amber-border: #fde68a;
  --emerald: #059669;
  --emerald-soft: #ecfdf5;
  --emerald-border: #a7f3d0;
  --rose: #e11d48;
  --rose-soft: #fff1f2;
  --rose-border: #fecdd3;
  --purple: #7c3aed;
  --purple-soft: #f5f3ff;
  --purple-border: #ddd6fe;
  --shadow-sm: 0 1px 3px rgba(15, 23, 42, 0.05);
  --shadow-md: 0 4px 12px rgba(15, 23, 42, 0.06);
  --shadow-lg: 0 12px 32px rgba(15, 23, 42, 0.12);
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;
}

[data-theme="dark"] {
  --bg-canvas: #0b1120;
  --bg-sidebar: #111827;
  --bg-topbar: rgba(17, 24, 39, 0.88);
  --bg-card: #1e293b;
  --bg-subtle: #0f172a;
  --bg-input: #0f172a;
  --bg-hover: #334155;
  --text-main: #f8fafc;
  --text-secondary: #cbd5e1;
  --text-muted: #94a3b8;
  --text-faint: #64748b;
  --border-color: #334155;
  --border-subtle: #1e293b;
  --primary: #3b82f6;
  --primary-hover: #2563eb;
  --primary-soft: rgba(59, 130, 246, 0.15);
  --primary-border: rgba(59, 130, 246, 0.35);
  --amber: #fbbf24;
  --amber-bright: #f59e0b;
  --amber-soft: rgba(245, 158, 11, 0.14);
  --amber-border: rgba(245, 158, 11, 0.35);
  --emerald: #34d399;
  --emerald-soft: rgba(16, 185, 129, 0.14);
  --emerald-border: rgba(16, 185, 129, 0.35);
  --rose: #fb7185;
  --rose-soft: rgba(244, 63, 94, 0.15);
  --rose-border: rgba(244, 63, 94, 0.4);
  --purple: #a78bfa;
  --purple-soft: rgba(139, 92, 246, 0.15);
  --purple-border: rgba(139, 92, 246, 0.35);
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.25);
  --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.35);
  --shadow-lg: 0 16px 40px rgba(0, 0, 0, 0.5);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg-canvas);
  color: var(--text-main);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

button, input, select, textarea {
  font: inherit;
  color: inherit;
}

button {
  cursor: pointer;
}

button:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

a {
  color: inherit;
  text-decoration: none;
}

[hidden] {
  display: none !important;
}

/* ================= LOGIN SCENE ================= */
.login-wrapper {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: radial-gradient(circle at 20% 20%, var(--primary-soft), transparent 45%),
              radial-gradient(circle at 80% 80%, var(--amber-soft), transparent 45%),
              var(--bg-canvas);
}

.login-box {
  width: 100%;
  max-width: 420px;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: 18px;
  padding: 36px 32px;
  box-shadow: var(--shadow-lg);
}

.login-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 24px;
}

.brand-logo {
  width: 42px;
  height: 42px;
  border-radius: 12px;
  background: linear-gradient(135deg, #2563eb, #4f46e5);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
  font-weight: 800;
  box-shadow: 0 6px 16px rgba(37, 99, 235, 0.3);
  flex-shrink: 0;
}

.brand-title {
  font-size: 18px;
  font-weight: 700;
  letter-spacing: -0.3px;
}

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

.login-box h1 {
  font-size: 24px;
  font-weight: 700;
  margin: 0 0 8px;
}

.login-desc {
  color: var(--text-muted);
  font-size: 13px;
  margin: 0 0 24px;
}

.form-group {
  margin-bottom: 16px;
}

.form-group label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 6px;
}

.input-control {
  width: 100%;
  padding: 11px 14px;
  background: var(--bg-input);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  font-size: 13px;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.input-control:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-soft);
}

.login-err {
  color: var(--rose);
  font-size: 12px;
  min-height: 18px;
  margin: 8px 0;
}

/* ================= APP SHELL & SIDEBAR ================= */
.app-shell {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  width: 248px;
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border-color);
  position: fixed;
  top: 0;
  bottom: 0;
  left: 0;
  z-index: 30;
  display: flex;
  flex-direction: column;
  padding: 22px 14px 18px;
  transition: transform 0.2s ease;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 0 10px 18px;
  border-bottom: 1px solid var(--border-subtle);
}

.nav-section-label {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--text-faint);
  padding: 16px 12px 6px;
}

.nav-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.nav-btn {
  border: 0;
  background: transparent;
  color: var(--text-secondary);
  padding: 10px 12px;
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 13px;
  font-weight: 500;
  text-align: left;
  transition: background 0.15s, color 0.15s;
}

.nav-btn:hover {
  background: var(--bg-hover);
  color: var(--text-main);
}

.nav-btn.active {
  background: var(--primary-soft);
  color: var(--primary);
  font-weight: 600;
}

.nav-icon {
  font-size: 16px;
  width: 20px;
  text-align: center;
  flex-shrink: 0;
}

.nav-badge {
  margin-left: auto;
  font-size: 11px;
  font-weight: 600;
  padding: 2px 7px;
  border-radius: 20px;
  background: var(--bg-subtle);
  color: var(--text-muted);
}

.nav-badge.amber {
  background: var(--amber-soft);
  color: var(--amber);
  border: 1px solid var(--amber-border);
}

.nav-badge.rose {
  background: var(--rose-soft);
  color: var(--rose);
  border: 1px solid var(--rose-border);
}

.nav-badge.emerald {
  background: var(--emerald-soft);
  color: var(--emerald);
}

.sidebar-footer {
  margin-top: auto;
  padding-top: 14px;
  border-top: 1px solid var(--border-subtle);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.sidebar-status {
  padding: 10px 12px;
  background: var(--bg-subtle);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  font-size: 11px;
  color: var(--text-muted);
}

.dot-live {
  display: inline-block;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--emerald);
  margin-right: 6px;
  box-shadow: 0 0 0 3px var(--emerald-soft);
}

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

/* ================= MAIN AREA & TOPBAR ================= */
.main-area {
  margin-left: 248px;
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.topbar {
  height: 64px;
  background: var(--bg-topbar);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border-color);
  position: sticky;
  top: 0;
  z-index: 20;
  padding: 0 28px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: 12px;
}

.mobile-toggle {
  display: none;
  border: 1px solid var(--border-color);
  background: var(--bg-card);
  border-radius: var(--radius-sm);
  padding: 6px 10px;
  font-size: 16px;
}

.breadcrumb {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--text-muted);
}

.breadcrumb strong {
  color: var(--text-main);
  font-weight: 600;
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.workspace-body {
  padding: 26px 28px 48px;
  max-width: 1560px;
  width: 100%;
  margin: 0 auto;
}

.page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 22px;
  flex-wrap: wrap;
}

.page-eyebrow {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 1.2px;
  text-transform: uppercase;
  color: var(--primary);
  margin: 0 0 4px;
}

.page-title {
  font-size: 24px;
  font-weight: 700;
  margin: 0;
  letter-spacing: -0.4px;
}

.page-subtitle {
  font-size: 13px;
  color: var(--text-muted);
  margin: 4px 0 0;
}

.page-toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

/* ================= BUTTONS & BADGES ================= */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 14px;
  border-radius: var(--radius-md);
  font-size: 12.5px;
  font-weight: 600;
  border: 1px solid var(--border-color);
  background: var(--bg-card);
  color: var(--text-secondary);
  transition: all 0.15s ease;
  white-space: nowrap;
}

.btn:hover:not(:disabled) {
  background: var(--bg-hover);
  border-color: var(--text-faint);
}

.btn-sm {
  padding: 5px 10px;
  font-size: 11.5px;
  border-radius: var(--radius-sm);
}

.btn-primary {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}

.btn-primary:hover:not(:disabled) {
  background: var(--primary-hover);
  border-color: var(--primary-hover);
}

.btn-amber {
  background: linear-gradient(135deg, #f59e0b, #d97706);
  border-color: #d97706;
  color: #fff;
  box-shadow: 0 2px 8px rgba(217, 119, 6, 0.25);
}

.btn-amber:hover:not(:disabled) {
  filter: brightness(1.06);
}

.btn-emerald {
  background: var(--emerald);
  border-color: var(--emerald);
  color: #fff;
}

.btn-rose {
  background: var(--rose-soft);
  border-color: var(--rose-border);
  color: var(--rose);
}

.btn-rose:hover:not(:disabled) {
  background: var(--rose);
  color: #fff;
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 8px;
  border-radius: 6px;
  font-size: 11px;
  font-weight: 600;
  line-height: 1.3;
  white-space: nowrap;
}

.badge.verified, .badge.emerald {
  background: var(--emerald-soft);
  color: var(--emerald);
  border: 1px solid var(--emerald-border);
}

.badge.observed, .badge.blue {
  background: var(--primary-soft);
  color: var(--primary);
  border: 1px solid var(--primary-border);
}

.badge.pending, .badge.attention, .badge.amber {
  background: var(--amber-soft);
  color: var(--amber);
  border: 1px solid var(--amber-border);
}

.badge.failed, .badge.rose {
  background: var(--rose-soft);
  color: var(--rose);
  border: 1px solid var(--rose-border);
}

.badge.purple {
  background: var(--purple-soft);
  color: var(--purple);
  border: 1px solid var(--purple-border);
}

.badge.disabled, .badge.unknown {
  background: var(--bg-subtle);
  color: var(--text-muted);
  border: 1px solid var(--border-color);
}

/* ================= KPI CARDS ================= */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 16px;
  margin-bottom: 22px;
}

.kpi-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 18px 20px;
  box-shadow: var(--shadow-sm);
  position: relative;
  transition: transform 0.15s, box-shadow 0.15s;
}

.kpi-card.clickable {
  cursor: pointer;
}

.kpi-card.clickable:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
  border-color: var(--primary-border);
}

.kpi-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  margin: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.kpi-value {
  font-size: 28px;
  font-weight: 800;
  margin: 10px 0 6px;
  letter-spacing: -0.8px;
  font-variant-numeric: tabular-nums;
}

.kpi-value small {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-muted);
  margin-left: 4px;
}

.kpi-foot {
  font-size: 11.5px;
  color: var(--text-muted);
  margin: 0;
}

/* ================= FILTER TOOLBAR ================= */
.filter-bar {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 14px 18px;
  margin-bottom: 20px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  box-shadow: var(--shadow-sm);
}

.filter-row {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.filter-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  min-width: 48px;
}

.pill-btn {
  border: 1px solid var(--border-color);
  background: var(--bg-subtle);
  color: var(--text-secondary);
  padding: 6px 12px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 500;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: all 0.15s;
}

.pill-btn:hover {
  border-color: var(--primary);
  color: var(--primary);
}

.pill-btn.active {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
  font-weight: 600;
}

.pill-btn.amber.active {
  background: var(--amber-bright);
  border-color: var(--amber);
  color: #fff;
}

.pill-btn.rose.active {
  background: var(--rose);
  border-color: var(--rose);
  color: #fff;
}

/* ================= COUPON TICKET GRID ================= */
.coupon-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 16px;
}

.coupon-ticket {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-left: 5px solid var(--primary);
  border-radius: var(--radius-lg);
  padding: 16px 18px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 12px;
  box-shadow: var(--shadow-sm);
  transition: transform 0.15s, box-shadow 0.15s;
}

.coupon-ticket:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}

.coupon-ticket.type-hf01 {
  border-left-color: var(--amber-bright);
}

.coupon-ticket.type-ll01 {
  border-left-color: var(--primary);
}

.coupon-ticket.type-other {
  border-left-color: var(--purple);
}

.coupon-ticket.urgent-today {
  border-color: var(--rose-border);
  border-left: 5px solid var(--rose);
  background: linear-gradient(to right, var(--rose-soft), var(--bg-card) 35%);
}

.coupon-ticket.urgent-soon {
  border-color: var(--amber-border);
  border-left: 5px solid var(--amber-bright);
}

.coupon-top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 10px;
}

.coupon-price {
  font-size: 26px;
  font-weight: 800;
  color: var(--amber);
  line-height: 1;
  font-variant-numeric: tabular-nums;
}

.coupon-price small {
  font-size: 12px;
  font-weight: 600;
  margin-left: 2px;
}

.coupon-name {
  font-size: 15px;
  font-weight: 700;
  margin: 6px 0 4px;
  color: var(--text-main);
}

.coupon-threshold {
  display: inline-block;
  font-size: 11.5px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 5px;
  background: var(--emerald-soft);
  color: var(--emerald);
  border: 1px solid var(--emerald-border);
  margin-bottom: 8px;
}

.coupon-meta {
  font-size: 11.5px;
  color: var(--text-muted);
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.coupon-meta-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.coupon-actions {
  padding-top: 12px;
  border-top: 1px dashed var(--border-color);
  display: flex;
  align-items: center;
  gap: 8px;
}

.coupon-actions .btn-main {
  flex: 1;
}

/* ================= PANELS & TABLES ================= */
.panel {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  margin-bottom: 20px;
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}

.panel-head {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.panel-head h2 {
  font-size: 15px;
  font-weight: 700;
  margin: 0;
}

.panel-subtitle {
  font-size: 12px;
  color: var(--text-muted);
  margin: 3px 0 0;
}

.panel-body {
  padding: 18px 20px;
}

.panel-foot {
  padding: 11px 20px;
  background: var(--bg-subtle);
  border-top: 1px solid var(--border-subtle);
  font-size: 11.5px;
  color: var(--text-muted);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.grid-2 {
  display: grid;
  grid-template-columns: 1.5fr 1fr;
  gap: 20px;
  margin-bottom: 20px;
}

.grid-equal {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
  margin-bottom: 20px;
}

.account-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 16px;
  margin-bottom: 22px;
}

.account-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 18px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 14px;
  box-shadow: var(--shadow-sm);
}

.table-wrap {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  text-align: left;
  font-size: 12.5px;
}

th {
  background: var(--bg-subtle);
  color: var(--text-muted);
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border-color);
  white-space: nowrap;
}

td {
  padding: 13px 16px;
  border-bottom: 1px solid var(--border-subtle);
  color: var(--text-secondary);
  vertical-align: middle;
}

tbody tr:last-child td {
  border-bottom: 0;
}

tbody tr:hover {
  background: var(--bg-hover);
}

.subtext {
  display: block;
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 3px;
}

.mono {
  font-family: "JetBrains Mono", Consolas, monospace;
  font-size: 11.5px;
}

/* ================= SCHEDULE & ALERTS ================= */
.schedule-item {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 11px 0;
  border-bottom: 1px solid var(--border-subtle);
}

.schedule-item:last-child {
  border-bottom: 0;
}

.schedule-time {
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--primary);
  min-width: 68px;
}

/* ================= DRAWER & MODAL ================= */
.drawer-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.55);
  backdrop-filter: blur(3px);
  z-index: 50;
  display: flex;
  justify-content: flex-end;
}

.drawer-panel {
  width: min(760px, 94vw);
  height: 100vh;
  background: var(--bg-card);
  border-left: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow-lg);
}

.drawer-header {
  padding: 18px 22px;
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.drawer-body {
  padding: 20px 22px;
  flex: 1;
  overflow-y: auto;
}

.terminal-pre {
  background: #0f172a;
  color: #e2e8f0;
  border: 1px solid #334155;
  border-radius: var(--radius-md);
  padding: 16px;
  font-family: Consolas, "Courier New", monospace;
  font-size: 12px;
  line-height: 1.7;
  white-space: pre-wrap;
  word-break: break-all;
  max-height: 70vh;
  overflow-y: auto;
}

/* ================= TOAST ================= */
.toast-container {
  position: fixed;
  top: 20px;
  right: 20px;
  z-index: 100;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.toast-item {
  padding: 12px 18px;
  border-radius: var(--radius-md);
  font-size: 13px;
  font-weight: 600;
  box-shadow: var(--shadow-lg);
  color: #fff;
  background: var(--primary);
}

.toast-item.success {
  background: #059669;
}

.toast-item.error {
  background: #e11d48;
}

.empty-box {
  padding: 40px 20px;
  text-align: center;
  color: var(--text-muted);
  font-size: 13px;
}

/* ================= RESPONSIVE ================= */
@media (max-width: 1150px) {
  .kpi-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  .coupon-grid, .account-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  .grid-2, .grid-equal {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 780px) {
  .sidebar {
    transform: translateX(-100%);
  }
  .sidebar.open {
    transform: translateX(0);
    box-shadow: var(--shadow-lg);
  }
  .main-area {
    margin-left: 0;
  }
  .mobile-toggle {
    display: inline-flex;
  }
  .topbar {
    padding: 0 16px;
  }
  .workspace-body {
    padding: 18px 16px 40px;
  }
  .coupon-grid, .account-grid, .kpi-grid {
    grid-template-columns: 1fr;
  }
}
