* { box-sizing: border-box; font-family: 'Inter', -apple-system, sans-serif; }
:root {
  --bg: #F1F4F9; --panel: #FFFFFF; --border: #E4E9F1; --text: #1B2536;
  --text-muted: #6B7690; --text-heading: #1B2536; --row-hover: #F6F8FC;
  --accent: #3D6BF3; --accent-text: #FFFFFF; --accent-hover: #2F58D9;
  --danger: #E0453F; --ok-bg: #E4F6EC; --ok-text: #0F8A4E;
  --err-bg: #FCEAEA; --err-text: #C23A34; --input-bg: #FFFFFF;
  --sidebar-bg: #FFFFFF; --topbar-bg: #FFFFFF; --shadow: 0 1px 3px rgba(20,30,60,0.06), 0 1px 2px rgba(20,30,60,0.04);
  --mono: 'IBM Plex Mono', 'Courier New', monospace;
}
[data-theme="dark"] {
  --bg: #0B1220; --panel: #121B2E; --border: #223049; --text: #E7ECF3;
  --text-muted: #8A94A6; --text-heading: #E7ECF3; --row-hover: #16233A;
  --accent: #4C7DFF; --accent-text: #FFFFFF; --accent-hover: #6690FF;
  --danger: #F0645E; --ok-bg: #16332480; --ok-text: #35D07F;
  --err-bg: #33161680; --err-text: #F0997B; --input-bg: #0B1220;
  --sidebar-bg: #0E1626; --topbar-bg: #0E1626; --shadow: none;
}
html, body { margin: 0; background: var(--bg); color: var(--text); overflow-x: hidden; }
body { display: flex; min-height: 100vh; }

/* ---------- Layout ---------- */
#app { display: flex; flex-direction: row; width: 100%; min-height: 100vh; }
#app.hidden { display: none; }
.sidebar {
  flex: 0 0 220px; width: 220px; background: var(--sidebar-bg); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; z-index: 10;
}
.main { flex: 1 1 0%; min-width: 0; max-width: 100%; }
.content-pad { padding: 24px 28px; max-width: 1400px; box-sizing: border-box; }
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 14px 28px; background: var(--topbar-bg); border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 5; flex-wrap: wrap;
}
.topbar-search { flex: 1 1 200px; min-width: 0; }
.topbar-search input { max-width: 320px; width: 100%; }

/* ---------- Sidebar ---------- */
.brand { display: flex; align-items: center; gap: 10px; }
.brand-side { padding: 20px 18px; border-bottom: 1px solid var(--border); }
.brand-mark {
  width: 34px; height: 34px; border-radius: 9px; background: var(--accent); color: #fff;
  display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 13px; flex-shrink: 0;
}
.brand-name { font-weight: 600; font-size: 15px; color: var(--text-heading); }
.navlist { padding: 14px 12px; display: flex; flex-direction: column; gap: 2px; flex: 1; min-width: 0; }
.navitem {
  display: flex; align-items: center; gap: 10px; text-align: left; border: none; background: transparent;
  color: var(--text-muted); padding: 10px 12px; border-radius: 8px; font-size: 14px; font-weight: 500; cursor: pointer;
  width: 100%; box-sizing: border-box;
}
.navitem:hover { background: var(--row-hover); border-color: transparent; color: var(--text); }
.navitem.active { background: var(--accent); color: #fff; }
.navicon { font-size: 15px; width: 18px; text-align: center; }
.sidebar-foot { padding: 16px 18px; border-top: 1px solid var(--border); }

/* ---------- Base elements ---------- */
.panel { background: var(--panel); border: 1px solid var(--border); border-radius: 14px; padding: 20px 22px; margin-bottom: 18px; box-shadow: var(--shadow); max-width: 100%; box-sizing: border-box; }
.panel-title { font-size: 14px; font-weight: 600; color: var(--text-heading); margin-bottom: 12px; }
.panel-head-row { display: flex; justify-content: space-between; align-items: center; margin-bottom: 14px; flex-wrap: wrap; gap: 10px; }
.section-divider { margin-top: 18px; border-top: 1px solid var(--border); padding-top: 16px; }
.label { font-size: 11px; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.06em; margin-bottom: 4px; display: block; }
textarea, input, select { width: 100%; background: var(--input-bg); border: 1px solid var(--border); border-radius: 8px; color: var(--text); padding: 9px 12px; font-size: 13px; font-family: 'Inter', sans-serif; }
textarea, #dataTable, .idpill, .mono { font-family: var(--mono); }
textarea:focus, input:focus, select:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(61,107,243,0.15); }
button { cursor: pointer; border-radius: 8px; border: 1px solid var(--border); background: var(--panel); color: var(--text); padding: 9px 16px; font-size: 13px; font-weight: 500; font-family: 'Inter', sans-serif; transition: all .12s; }
button:hover { border-color: var(--accent); color: var(--accent); }
button.primary { background: var(--accent); color: var(--accent-text); border-color: var(--accent); font-weight: 600; }
button.primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); color: #fff; }
#updateBtn { background: #14B8A6; border-color: #14B8A6; color: #fff; font-weight: 600; }
#updateBtn:hover { background: #0D9488; border-color: #0D9488; color: #fff; }
button.danger:hover { border-color: var(--danger); color: var(--danger); }
button.iconbtn { width: 36px; height: 36px; padding: 0; display: inline-flex; align-items: center; justify-content: center; font-size: 16px; }
.theme-icon { font-size: 18px; line-height: 1; }
table { width: 100%; border-collapse: collapse; font-size: 12.5px; color: var(--text); }
th, td { text-align: left; padding: 9px 10px; border-bottom: 1px solid var(--border); white-space: nowrap; color: var(--text); }
th { color: var(--text-muted); font-weight: 600; text-transform: uppercase; font-size: 10px; letter-spacing: 0.05em; position: sticky; top: 0; background: var(--panel); }
tr:hover td { background: var(--row-hover); }
.tablewrap { overflow-x: auto; max-height: 480px; overflow-y: auto; border-radius: 10px; max-width: 100%; }
.grid2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.grid3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; }
.field { margin-bottom: 10px; }
.badge { font-size: 12px; padding: 6px 12px; border-radius: 8px; background: var(--row-hover); color: var(--text); font-weight: 500; display: inline-block; }
.title { font-size: 17px; font-weight: 700; margin: 0; color: var(--text-heading); }
.sub { font-size: 12.5px; color: var(--text-muted); margin: 2px 0 0; }
.row { display: flex; justify-content: space-between; align-items: center; margin-bottom: 14px; flex-wrap: wrap; gap: 10px; }
.actionbar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.filters-row { display: flex; gap: 8px; margin-bottom: 14px; flex-wrap: wrap; }
.filters-row select { width: 180px; }
.bulk-actions-row {
  display: flex; gap: 8px; align-items: center; flex-wrap: wrap;
  background: var(--row-hover); border: 1px solid var(--border); border-radius: 10px;
  padding: 10px 14px; margin-bottom: 14px;
}
.bulk-label { font-size: 12px; color: var(--text-muted); font-weight: 600; margin-right: 4px; }
.msg { font-size: 12.5px; padding: 10px 12px; border-radius: 8px; margin-top: 10px; }
.msg.ok { background: var(--ok-bg); color: var(--ok-text); }
.msg.err { background: var(--err-bg); color: var(--err-text); }
.searchbox { width: 100%; }
.empty { text-align: center; padding: 34px; color: var(--text-muted); font-size: 13px; }
.idpill { font-weight: 600; color: var(--accent); }
.login-wrap { min-height: 100vh; width: 100%; display: flex; align-items: center; justify-content: center; background: var(--bg); }
.login-card { background: var(--panel); border: 1px solid var(--border); border-radius: 16px; padding: 30px; width: 340px; box-shadow: var(--shadow); }
.login-card .brand { margin-bottom: 22px; }
.login-card .title { font-size: 16px; }

/* ---------- Dashboard cards ---------- */
.cards-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 14px; margin-bottom: 18px; }
.stat-card {
  background: var(--panel); border: 1px solid var(--border); border-radius: 14px; padding: 16px 18px;
  display: flex; align-items: center; gap: 14px; box-shadow: var(--shadow);
  text-align: left; cursor: pointer; font-family: 'Inter', sans-serif; width: 100%;
  transition: transform .08s, box-shadow .12s;
}
.stat-card:hover { border-color: var(--accent); color: inherit; transform: translateY(-1px); box-shadow: 0 4px 14px rgba(20,30,60,0.10); }
.stat-card:active { transform: translateY(0); }
.stat-icon { width: 42px; height: 42px; border-radius: 11px; display: flex; align-items: center; justify-content: center; font-size: 18px; flex-shrink: 0; color: #fff; }
.stat-num { font-size: 22px; font-weight: 700; color: var(--text-heading); line-height: 1.1; }
.stat-lbl { font-size: 11.5px; color: var(--text-muted); margin-top: 2px; font-weight: 500; }
.c-blue { background: #3D6BF3; } .c-purple { background: #8B5CF6; } .c-teal { background: #14B8A6; }
.c-red { background: #EF4444; } .c-orange { background: #F59E0B; } .c-cyan { background: #06B6D4; }
.c-green { background: #22C55E; } .c-pink { background: #EC4899; }
tr.row-deactive td { background: #FDE8E8; }
[data-theme="dark"] tr.row-deactive td { background: #3A1414; }
tr.row-deactive:hover td { background: #FBD5D5; }
[data-theme="dark"] tr.row-deactive:hover td { background: #471818; }
.status-pill { font-size: 10px; font-weight: 700; padding: 3px 8px; border-radius: 10px; text-transform: uppercase; letter-spacing: 0.03em; }
.status-pill.active { background: #E4F6EC; color: #0F8A4E; }
.status-pill.deactive { background: #FCEAEA; color: #C23A34; }
[data-theme="dark"] .status-pill.active { background: #16332480; color: #35D07F; }
[data-theme="dark"] .status-pill.deactive { background: #33161680; color: #F0997B; }

.chart-panel { }
.chart-wrap { display: flex; align-items: center; gap: 28px; flex-wrap: wrap; }
.chart-canvas-box { position: relative; width: 200px; height: 200px; flex-shrink: 0; }
.chart-canvas-box canvas { width: 100% !important; height: 100% !important; }
.chart-legend { display: flex; flex-direction: column; gap: 8px; font-size: 13px; flex: 1 1 160px; min-width: 0; }
.chart-legend-item { display: flex; align-items: center; gap: 8px; padding: 3px 6px; border-radius: 6px; transition: background .1s; }
.chart-legend-item:hover { background: var(--row-hover); }
.chart-legend-dot { width: 10px; height: 10px; border-radius: 3px; flex-shrink: 0; }
.chart-legend-count { margin-left: auto; font-weight: 600; color: var(--text-heading); }

.hist-entry { border-bottom: 1px solid var(--border); padding: 10px 0; }
.hist-entry:last-child { border-bottom: none; }

@media (max-width: 620px) {
  #app { flex-direction: column; }
  .sidebar { flex: 0 0 auto; width: 100%; height: auto; position: static; flex-direction: row; align-items: center; overflow-x: auto; }
  .brand-side { border-bottom: none; border-right: 1px solid var(--border); flex-shrink: 0; }
  .navlist { flex-direction: row; padding: 8px; }
  .navitem { width: auto; white-space: nowrap; }
  .sidebar-foot { border-top: none; }
  .content-pad { padding: 16px; }
  .topbar { padding: 12px 16px; }
  .cards-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid3 { grid-template-columns: 1fr; }
  .chart-wrap { flex-direction: column; align-items: flex-start; }
}
