/* ============================================================
   SapienOS — UI/UX mock-up design system
   Multi-modal building monitoring platform (ADD v2.2)
   Dark "operations console" default + light "enterprise" theme.
   ============================================================ */

@import url('https://fonts.googleapis.com/css2?family=Fira+Code:wght@400;500;600;700&family=Fira+Sans:wght@300;400;500;600;700&display=swap');

/* ---------- Theme tokens ---------- */
:root,
[data-theme="dark"] {
  --bg:        #0B1220;
  --surface:   #111A2B;
  --surface-2: #0E1626;
  --elev:      #16203492;
  --card:      #131D30;
  --muted:     #1A2538;
  --border:    #243149;
  --border-2:  #2E3D58;
  --text:      #F1F5F9;
  --text-2:    #9AA8BF;
  --text-3:    #647189;
  --accent:    #2DD4A7;   /* SapienOS teal-green */
  --accent-ink:#04140F;
  --blue:      #3B82F6;
  --ok:        #22C55E;
  --warn:      #F59E0B;
  --danger:    #F0506E;
  --info:      #38BDF8;
  --purple:    #A78BFA;
  --ok-bg:     rgba(34,197,94,.14);
  --warn-bg:   rgba(245,158,11,.16);
  --danger-bg: rgba(240,80,110,.16);
  --info-bg:   rgba(56,189,248,.14);
  --grid:      #1E2A40;
  --shadow:    0 10px 30px -12px rgba(0,0,0,.6);
  --twin-bg-a: #0E1A2C;
  --twin-bg-b: #0A1320;
  color-scheme: dark;
}

[data-theme="light"] {
  --bg:        #EEF2F7;
  --surface:   #FFFFFF;
  --surface-2: #F6F8FB;
  --elev:      #FFFFFFcc;
  --card:      #FFFFFF;
  --muted:     #EEF2F8;
  --border:    #E2E8F0;
  --border-2:  #D4DDE9;
  --text:      #0F1B2D;
  --text-2:    #51607A;
  --text-3:    #8593A8;
  --accent:    #0FA27E;
  --accent-ink:#FFFFFF;
  --blue:      #2563EB;
  --ok:        #16A34A;
  --warn:      #D97706;
  --danger:    #DC2C50;
  --info:      #0284C7;
  --purple:    #7C5CD4;
  --ok-bg:     rgba(22,163,74,.12);
  --warn-bg:   rgba(217,119,6,.13);
  --danger-bg: rgba(220,44,80,.10);
  --info-bg:   rgba(2,132,199,.10);
  --grid:      #E7EDF4;
  --shadow:    0 12px 28px -16px rgba(15,27,45,.28);
  --twin-bg-a: #E9F0F8;
  --twin-bg-b: #DCE6F2;
  color-scheme: light;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  font-family: 'Fira Sans', system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  transition: background .25s ease, color .25s ease;
}

.mono { font-family: 'Fira Code', ui-monospace, monospace; font-variant-numeric: tabular-nums; }
.num  { font-family: 'Fira Code', ui-monospace, monospace; font-variant-numeric: tabular-nums; }

a { color: inherit; text-decoration: none; }
h1,h2,h3,h4 { margin: 0; font-weight: 600; letter-spacing: -.01em; }
::selection { background: var(--accent); color: var(--accent-ink); }

/* ---------- App shell ---------- */
.app { display: grid; grid-template-columns: 248px 1fr; min-height: 100dvh; }

.sidebar {
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
  position: sticky; top: 0; height: 100dvh;
}
.brand {
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  margin: 14px 14px 10px; padding: 12px 12px 10px;
  /* fixed brand slate — the logo artwork is designed for this background in both themes */
  background: linear-gradient(150deg, #597694, #3d5875);
  border-radius: 12px;
  box-shadow: 0 0 0 1px rgba(255,255,255,.08) inset, 0 8px 20px -12px rgba(0,0,0,.5);
}
.brand .brand-logo { display: block; width: 100%; max-width: 176px; height: auto; }
.brand .tag { font-size: 10px; color: rgba(255,255,255,.72); letter-spacing: .14em; text-transform: uppercase; }

.asset-switch {
  margin: 4px 14px 12px; padding: 10px 12px;
  background: var(--muted); border: 1px solid var(--border);
  border-radius: 10px; cursor: pointer;
  display: flex; align-items: center; gap: 10px;
}
.asset-switch:hover { border-color: var(--border-2); }
.asset-switch .ico { width: 30px; height: 30px; border-radius: 7px; background: var(--surface-2); display: grid; place-items: center; flex: none; color: var(--text-2); }
.asset-switch small { color: var(--text-3); font-size: 10.5px; display: block; }
.asset-switch .name { font-weight: 600; font-size: 13px; }
.asset-switch .chev { margin-left: auto; color: var(--text-3); }

.nav { padding: 6px 12px; overflow-y: auto; flex: 1; }
.nav .group { color: var(--text-3); font-size: 10px; letter-spacing: .12em; text-transform: uppercase; margin: 14px 10px 6px; }
.nav a {
  display: flex; align-items: center; gap: 11px;
  padding: 9px 11px; border-radius: 9px; color: var(--text-2);
  font-size: 13.5px; font-weight: 500; position: relative;
  transition: background .15s, color .15s;
}
.nav a svg { width: 18px; height: 18px; flex: none; }
.nav a:hover { background: var(--muted); color: var(--text); }
.nav a.active { background: var(--accent); color: var(--accent-ink); }
.nav a.active svg { color: var(--accent-ink); }
.nav a .count { margin-left: auto; font-size: 11px; font-weight: 600; padding: 1px 7px; border-radius: 20px; background: var(--danger); color:#fff; }
.nav a.disabled { opacity: .42; cursor: not-allowed; }
.nav a .soon { margin-left: auto; font-size: 9px; letter-spacing: .06em; color: var(--text-3); border: 1px solid var(--border-2); padding: 1px 5px; border-radius: 5px; }

.side-foot { border-top: 1px solid var(--border); padding: 12px 14px; display: flex; align-items: center; gap: 10px; }
.avatar { width: 32px; height: 32px; border-radius: 50%; background: linear-gradient(140deg,#6366F1,#A855F7); display:grid; place-items:center; color:#fff; font-weight:600; font-size:12px; flex:none;}
.side-foot .name { font-size: 12.5px; font-weight: 600; }
.side-foot .role { font-size: 10.5px; color: var(--text-3); }

/* ---------- Topbar ---------- */
.main { display: flex; flex-direction: column; min-width: 0; }
.topbar {
  height: 60px; border-bottom: 1px solid var(--border);
  background: var(--surface); backdrop-filter: blur(8px);
  display: flex; align-items: center; gap: 16px; padding: 0 22px;
  position: sticky; top: 0; z-index: 30;
}
.crumbs { display: flex; align-items: center; gap: 7px; font-size: 13px; color: var(--text-2); min-width: 0; }
.crumbs .sep { color: var(--text-3); }
.crumbs b { color: var(--text); font-weight: 600; }
.crumbs .live { display:inline-flex; align-items:center; gap:6px; margin-left:4px; font-size:11px; color:var(--ok); }
.crumbs .live .dot { width:7px; height:7px; border-radius:50%; background:var(--ok); box-shadow:0 0 0 0 var(--ok); animation: pulse 2s infinite; }
@keyframes pulse { 0%{box-shadow:0 0 0 0 rgba(34,197,94,.5);} 70%{box-shadow:0 0 0 7px rgba(34,197,94,0);} 100%{box-shadow:0 0 0 0 rgba(34,197,94,0);} }

.top-actions { margin-left: auto; display: flex; align-items: center; gap: 8px; }
.icon-btn {
  width: 38px; height: 38px; border-radius: 9px; border: 1px solid var(--border);
  background: var(--muted); color: var(--text-2); display: grid; place-items: center;
  cursor: pointer; position: relative; transition: .15s;
}
.icon-btn:hover { color: var(--text); border-color: var(--border-2); }
.icon-btn svg { width: 18px; height: 18px; }
.icon-btn .dot-badge { position:absolute; top:7px; right:8px; width:7px; height:7px; border-radius:50%; background:var(--danger); border:2px solid var(--surface); }
.search {
  display: flex; align-items: center; gap: 8px; height: 38px; padding: 0 12px;
  background: var(--muted); border: 1px solid var(--border); border-radius: 9px;
  color: var(--text-3); width: 230px; font-size: 13px;
}
.search svg { width: 16px; height: 16px; }
.search kbd { margin-left: auto; font-size: 10px; border: 1px solid var(--border-2); border-radius: 5px; padding: 1px 5px; font-family: 'Fira Code'; }

/* ---------- Content ---------- */
.content { padding: 22px; display: flex; flex-direction: column; gap: 18px; }
.page-head { display: flex; align-items: flex-end; gap: 16px; flex-wrap: wrap; }
.page-head h1 { font-size: 21px; }
.page-head p { margin: 3px 0 0; color: var(--text-2); font-size: 13px; }
.page-head .right { margin-left: auto; display: flex; gap: 8px; align-items: center; }

/* ---------- Cards ---------- */
.card {
  background: var(--card); border: 1px solid var(--border);
  border-radius: 14px; box-shadow: var(--shadow);
}
.card.pad { padding: 18px; }
.card-h { display: flex; align-items: center; gap: 10px; padding: 14px 18px; border-bottom: 1px solid var(--border); }
.card-h h3 { font-size: 14px; }
.card-h .sub { font-size: 11.5px; color: var(--text-3); }
.card-h .right { margin-left: auto; display: flex; gap: 8px; align-items: center; }
.card-b { padding: 18px; }

.grid { display: grid; gap: 16px; }
.cols-4 { grid-template-columns: repeat(4, 1fr); }
.cols-3 { grid-template-columns: repeat(3, 1fr); }
.cols-2 { grid-template-columns: repeat(2, 1fr); }

/* ---------- KPI ---------- */
.kpi { padding: 16px 17px; }
.kpi .lbl { font-size: 11.5px; color: var(--text-2); display: flex; align-items: center; gap: 7px; }
.kpi .lbl .gi { width: 26px; height: 26px; border-radius: 7px; display: grid; place-items: center; flex:none; }
.kpi .val { font-size: 27px; font-weight: 600; margin-top: 10px; letter-spacing: -.02em; }
.kpi .val small { font-size: 13px; color: var(--text-3); font-weight: 500; }
.kpi .meta { margin-top: 6px; font-size: 11.5px; color: var(--text-3); display: flex; align-items: center; gap: 6px; }
.delta { display: inline-flex; align-items: center; gap: 3px; font-weight: 600; }
.delta.up { color: var(--ok); } .delta.down { color: var(--danger); } .delta.flat { color: var(--text-3); }

/* ---------- Badges / pills ---------- */
.badge { display: inline-flex; align-items: center; gap: 5px; font-size: 11px; font-weight: 600;
  padding: 3px 9px; border-radius: 20px; border: 1px solid transparent; white-space: nowrap; }
.badge .d { width: 6px; height: 6px; border-radius: 50%; }
.b-ok { background: var(--ok-bg); color: var(--ok); } .b-ok .d{background:var(--ok);}
.b-warn { background: var(--warn-bg); color: var(--warn); } .b-warn .d{background:var(--warn);}
.b-danger { background: var(--danger-bg); color: var(--danger); } .b-danger .d{background:var(--danger);}
.b-info { background: var(--info-bg); color: var(--info); } .b-info .d{background:var(--info);}
.b-muted { background: var(--muted); color: var(--text-2); border-color: var(--border); }
.pill { display:inline-flex; align-items:center; gap:6px; font-size:11.5px; font-weight:500; color: var(--text-2);
  padding: 5px 10px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface-2); }

/* ---------- Buttons ---------- */
.btn { display: inline-flex; align-items: center; gap: 8px; font-family: inherit; font-size: 13px; font-weight: 600;
  padding: 9px 14px; border-radius: 9px; border: 1px solid var(--border); background: var(--muted);
  color: var(--text); cursor: pointer; transition: .15s; }
.btn svg { width: 16px; height: 16px; }
.btn:hover { border-color: var(--border-2); }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
.btn.primary:hover { filter: brightness(1.06); }
.btn.danger { background: var(--danger); color: #fff; border-color: transparent; }
.btn.ghost { background: transparent; }
.btn.sm { padding: 6px 10px; font-size: 12px; }

.seg { display: inline-flex; background: var(--muted); border: 1px solid var(--border); border-radius: 9px; padding: 3px; gap: 2px; }
.seg button { font-family: inherit; font-size: 12px; font-weight: 600; color: var(--text-2);
  background: transparent; border: 0; padding: 6px 11px; border-radius: 7px; cursor: pointer; }
.seg button.on { background: var(--surface); color: var(--text); box-shadow: 0 1px 2px rgba(0,0,0,.2); }

/* ---------- Tables ---------- */
table.tbl { width: 100%; border-collapse: collapse; font-size: 13px; }
table.tbl th { text-align: left; font-size: 10.5px; letter-spacing: .06em; text-transform: uppercase;
  color: var(--text-3); font-weight: 600; padding: 10px 14px; border-bottom: 1px solid var(--border); }
table.tbl td { padding: 12px 14px; border-bottom: 1px solid var(--border); color: var(--text); }
table.tbl tr:last-child td { border-bottom: 0; }
table.tbl tbody tr:hover { background: var(--surface-2); }
table.tbl tr.row-hl td { background: color-mix(in srgb, var(--accent) 13%, transparent); }
table.tbl tr.row-hl td:first-child { box-shadow: inset 3px 0 0 var(--accent); }
.t-sub { color: var(--text-3); font-size: 11.5px; }

/* ---------- Misc ---------- */
.divider { height: 1px; background: var(--border); margin: 4px 0; }
.dl { display: grid; grid-template-columns: auto 1fr; gap: 9px 14px; font-size: 13px; }
.dl dt { color: var(--text-3); }
.dl dd { margin: 0; text-align: right; font-weight: 500; }
.bar { height: 7px; border-radius: 20px; background: var(--muted); overflow: hidden; }
.bar > span { display: block; height: 100%; border-radius: 20px; }
.legend { display: flex; gap: 16px; flex-wrap: wrap; font-size: 11.5px; color: var(--text-2); }
.legend i { width: 10px; height: 10px; border-radius: 3px; display: inline-block; margin-right: 6px; vertical-align: -1px; }
.note { font-size: 11.5px; color: var(--text-3); display: flex; gap: 8px; align-items: flex-start; }
.note svg { width: 15px; height: 15px; flex: none; margin-top: 1px; }
.banner { display:flex; gap:11px; align-items:flex-start; padding:12px 14px; border-radius:11px;
  border:1px solid var(--border); background: var(--surface-2); font-size:12.5px; color: var(--text-2); }
.banner svg { width:18px; height:18px; flex:none; }
.banner.gov { border-color: color-mix(in srgb, var(--purple) 40%, var(--border)); background: color-mix(in srgb, var(--purple) 9%, transparent); }

/* chart wrap */
.cellspark { width: 96px; height: 30px; }
.chart { width: 100%; display: block; }
.chart text { font-family: 'Fira Code'; fill: var(--text-3); font-size: 10px; }
.spark { display: block; }

/* responsiveness */
@media (max-width: 1180px){ .cols-4{grid-template-columns:repeat(2,1fr);} }
@media (max-width: 1024px){
  .app { grid-template-columns: 1fr; }
  .sidebar { position: fixed; left: -260px; z-index: 60; transition: left .2s; }
  .sidebar.open { left: 0; }
  .twin-layout, .alerts-layout, .shm-layout { grid-template-columns: 1fr !important; }
  .search { display: none; }
}
@media (max-width: 720px){ .cols-4,.cols-3,.cols-2{grid-template-columns:1fr;} }

/* hamburger only on small */
.hamb { display: none; }
@media (max-width: 1024px){ .hamb { display: grid; } }

@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }
