:root {
  --blue: #1d4ed8;
  --blue-dark: #1e40af;
  --blue-light: #eff6ff;
  --bg: #f8fafc;
  --card: #ffffff;
  --text: #0f172a;
  --muted: #64748b;
  --border: #dbeafe;
  --table-border: #bfdbfe;
  --radius: 12px;
  --shadow: 0 1px 3px rgba(30, 64, 175, 0.08), 0 4px 16px rgba(30, 64, 175, 0.06);
}

* { box-sizing: border-box; margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
button { font-family: inherit; cursor: pointer; }
input, select { font-family: inherit; }

/* Topbar */
.topbar {
  background: linear-gradient(135deg, var(--blue-dark), var(--blue));
  color: #fff;
  position: sticky; top: 0; z-index: 50;
  box-shadow: 0 2px 10px rgba(30, 64, 175, 0.25);
}
.topbar-inner {
  max-width: 1160px; margin: 0 auto; padding: 14px 20px;
  display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap;
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand .logo { width: 42px; height: 42px; object-fit: contain; border-radius: 9px; background: #fff; padding: 3px; }
.brand h1 { font-size: 18px; font-weight: 700; }
.brand p { font-size: 13px; opacity: .85; }
.nav { display: flex; gap: 6px; }
.nav-btn {
  background: rgba(255,255,255,.12); color: #fff; border: 1px solid rgba(255,255,255,.2);
  padding: 9px 16px; border-radius: 9px; font-size: 14px; font-weight: 600; transition: all .15s;
}
.nav-btn:hover { background: rgba(255,255,255,.22); }
.nav-btn.active { background: #fff; color: var(--blue-dark); border-color: #fff; }

main { max-width: 1160px; margin: 0 auto; padding: 24px 20px 60px; }
.page.hidden { display: none; }

/* Cards */
.card {
  background: var(--card); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 22px; margin-bottom: 22px;
}
.card h2 { font-size: 17px; margin-bottom: 4px; color: var(--blue-dark); }
.card .desc { font-size: 13px; color: var(--muted); margin-bottom: 16px; }

/* Stats */
.stats-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 14px; margin-bottom: 22px; }
.stat-card {
  background: var(--card); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 18px; box-shadow: var(--shadow); border-top: 4px solid var(--blue);
}
.stat-card .num { font-size: 28px; font-weight: 800; color: var(--blue-dark); }
.stat-card .lbl { font-size: 13px; color: var(--muted); margin-top: 4px; }
.stat-card.accent { background: linear-gradient(135deg, var(--blue-dark), var(--blue)); color: #fff; border: none; }
.stat-card.accent .num { color: #fff; }
.stat-card.accent .lbl { color: rgba(255,255,255,.85); }

/* Dashboard header + wallpaper + footer */
.dash-header {
  background: linear-gradient(135deg, #1e3a8a, #1d4ed8 55%, #7c3aed);
  color: #fff;
  border-radius: 16px;
  padding: 28px 32px;
  margin-bottom: 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  box-shadow: var(--shadow);
}
.dash-header h1 { font-size: 23px; line-height: 1.3; }
.dash-header p { opacity: .9; margin-top: 5px; font-size: 14px; }
.dash-tag { display: inline-block; background: rgba(255,255,255,.16); padding: 3px 11px; border-radius: 999px; font-size: 12px; font-weight: 600; margin-bottom: 9px; }
.dash-robot { font-size: 54px; filter: drop-shadow(0 0 16px rgba(255,255,255,.4)); }

.hero-wallpaper {
  position: relative;
  overflow: hidden;
  background:
    radial-gradient(circle at 82% 18%, rgba(124,58,237,.45), transparent 55%),
    radial-gradient(circle at 15% 85%, rgba(14,165,233,.4), transparent 50%),
    linear-gradient(135deg, #0f172a, #1e3a8a 55%, #312e81);
  color: #fff;
  border-radius: 16px;
  padding: 46px 32px;
  margin-bottom: 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  box-shadow: var(--shadow);
}
.hero-wallpaper::before {
  content: '';
  position: absolute;
  inset: 0;
  background-image:
    linear-gradient(rgba(255,255,255,.05) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255,255,255,.05) 1px, transparent 1px);
  background-size: 28px 28px;
  pointer-events: none;
}
.hero-wallpaper h2 { font-size: 30px; font-weight: 800; position: relative; }
.hero-wallpaper p { opacity: .9; margin-top: 6px; position: relative; font-size: 14px; }
.hero-robot { font-size: 92px; filter: drop-shadow(0 0 26px rgba(96,165,250,.7)); position: relative; }

.dash-footer {
  text-align: center;
  padding: 18px;
  margin-top: 6px;
  color: var(--muted);
  font-size: 13px;
  border-top: 1px solid var(--border);
}

/* Forms */
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; }
.field { display: flex; flex-direction: column; }
.field label { font-size: 13px; font-weight: 600; color: #334155; margin-bottom: 5px; }
.field input, .field select {
  padding: 10px 12px; border: 1px solid var(--border); border-radius: 9px;
  font-size: 14px; background: #fff; transition: border .15s, box-shadow .15s;
}
.field input:focus, .field select:focus { outline: none; border-color: var(--blue); box-shadow: 0 0 0 3px var(--blue-light); }
.form-actions { margin-top: 16px; display: flex; gap: 10px; }

.btn { display: inline-flex; align-items: center; gap: 6px; padding: 10px 16px; border-radius: 9px; font-size: 14px; font-weight: 600; border: 1px solid transparent; transition: all .15s; }
.btn-primary { background: var(--blue); color: #fff; }
.btn-primary:hover { background: var(--blue-dark); }
.btn-ghost { background: #fff; color: var(--blue-dark); border-color: var(--border); }
.btn-ghost:hover { background: var(--blue-light); }
.btn-danger { background: #fff; color: #dc2626; border-color: #fecaca; }
.btn-danger:hover { background: #fef2f2; }
.btn-sm { padding: 6px 11px; font-size: 13px; border-radius: 8px; }
.hidden { display: none !important; }

/* Filter row */
.filter-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 12px; }
.filter-row label { font-size: 13px; font-weight: 600; color: #334155; }
.filter-row select { padding: 8px 11px; border: 1px solid var(--border); border-radius: 8px; font-size: 14px; background: #fff; }

/* Tables (Excel-like) */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 14px; background: #fff; }
th, td { padding: 9px 11px; border: 1px solid var(--table-border); text-align: center; white-space: nowrap; }
th { background: var(--blue); color: #fff; font-size: 12.5px; text-transform: uppercase; letter-spacing: .02em; font-weight: 600; position: sticky; top: 0; }
td.left, th.left { text-align: left; }
tbody tr:nth-child(even) { background: #f8fbff; }
tbody tr:hover { background: var(--blue-light); }
td.avg { font-weight: 700; background: #eef4ff; color: var(--blue-dark); }
td.dash { color: var(--muted); }

.cell-actions { display: flex; gap: 6px; justify-content: center; flex-wrap: wrap; }

/* Chart */
.chart { display: flex; align-items: flex-end; gap: 18px; height: 240px; padding: 20px 10px 0; border-bottom: 2px solid var(--border); }
.chart .bar-wrap { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; height: 100%; }
.chart .bar { width: 100%; max-width: 56px; background: linear-gradient(180deg, var(--blue), var(--blue-dark)); border-radius: 6px 6px 0 0; min-height: 4px; transition: height .3s; }
.chart .bar-val { font-size: 12px; font-weight: 700; color: var(--blue-dark); margin-bottom: 4px; }
.chart .bar-label { font-size: 11.5px; color: var(--muted); margin-top: 8px; text-align: center; word-break: break-word; }
.chart .empty { color: var(--muted); width: 100%; text-align: center; align-self: center; }

/* Quarterly grouped bar chart */
.qchart { margin-top: 18px; padding-top: 18px; border-top: 1px solid var(--border); }
.qchart h3 { font-size: 15px; color: var(--blue-dark); margin-bottom: 14px; }
.qchart-plot { display: flex; gap: 24px; overflow-x: auto; padding-bottom: 4px; }
.qgroup { flex: 1; min-width: 52px; }
.qbars { display: flex; align-items: flex-end; gap: 5px; height: 260px; border-bottom: 2px solid var(--border); }
.qbar-col { flex: 1; min-width: 0; display: flex; flex-direction: column; justify-content: flex-end; align-items: center; height: 100%; }
.qbar { width: 100%; max-width: 44px; border-radius: 4px 4px 0 0; min-height: 2px; }
.qbar-val { font-size: 10px; color: var(--muted); margin-bottom: 2px; white-space: nowrap; }
.qlabel { text-align: center; font-weight: 700; margin-top: 10px; color: var(--muted); font-size: 13px; }
.qlegend { display: flex; flex-wrap: wrap; gap: 8px 16px; margin-top: 16px; }
.lg { font-size: 12px; color: var(--muted); display: inline-flex; align-items: center; gap: 6px; }
.lg i { width: 11px; height: 11px; border-radius: 3px; display: inline-block; flex-shrink: 0; }

/* Toast */
#toast {
  position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%);
  background: #0f172a; color: #fff; padding: 12px 18px; border-radius: 10px;
  font-size: 14px; box-shadow: 0 10px 30px rgba(0,0,0,.3); z-index: 999;
  opacity: 0; pointer-events: none; transition: opacity .2s;
}
#toast.show { opacity: 1; }
#toast.error { background: #dc2626; }

@media (max-width: 640px) {
  .topbar-inner { flex-direction: column; align-items: flex-start; }
  .nav { width: 100%; }
  .nav-btn { flex: 1; text-align: center; }
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
}
