/* Ada Management - application styles.
   Mobile-first, no framework, no build step.

   Theming: :root holds light values. Dark values live in one block that is
   applied either explicitly ([data-theme="dark"]) or, for the System option,
   through prefers-color-scheme. The inline snippet in base.html sets
   data-theme before first paint, so switching never flashes. */

:root {
  --bg:          #f4f5f7;
  --surface:     #ffffff;
  --surface-2:   #f7f8fa;
  --surface-3:   #eceef2;
  --border:      #dfe3e9;
  --border-soft: #eaedf1;
  --text:        #191e26;
  --text-soft:   #5a6371;
  --accent:      #1c587f;
  --accent-ink:  #ffffff;
  --accent-soft: #e6eff6;

  --ok:        #256b4d;
  --ok-soft:   #e3f2ea;
  --warn:      #8a5510;
  --warn-soft: #fbeedb;
  --crit:      #97331f;
  --crit-soft: #fbe6e1;
  --info:      #2b5b86;
  --info-soft: #e6eff6;
  --idle:      #5f6875;
  --idle-soft: #eef0f3;

  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .04);
  --sidebar-w: 248px;
  --focus: 2px solid var(--accent);
}

/* Dark values, shared by the explicit choice and by System. */
:root[data-theme="dark"] {
  --bg:          #101318;
  --surface:     #181c23;
  --surface-2:   #1f242c;
  --surface-3:   #262c36;
  --border:      #303845;
  --border-soft: #262c36;
  --text:        #e8ebf0;
  --text-soft:   #a3adbb;
  --accent:      #6fb0dc;
  --accent-ink:  #0c1015;
  --accent-soft: #1b2a37;

  --ok:        #6fce9f;
  --ok-soft:   #162c22;
  --warn:      #e0ae66;
  --warn-soft: #302516;
  --crit:      #f0917f;
  --crit-soft: #341d18;
  --info:      #7fb7e0;
  --info-soft: #172733;
  --idle:      #9aa4b2;
  --idle-soft: #222831;

  --shadow: 0 1px 2px rgba(0, 0, 0, .45);
}

@media (prefers-color-scheme: dark) {
  :root[data-theme="system"] {
    --bg:          #101318;
    --surface:     #181c23;
    --surface-2:   #1f242c;
    --surface-3:   #262c36;
    --border:      #303845;
    --border-soft: #262c36;
    --text:        #e8ebf0;
    --text-soft:   #a3adbb;
    --accent:      #6fb0dc;
    --accent-ink:  #0c1015;
    --accent-soft: #1b2a37;

    --ok:        #6fce9f;
    --ok-soft:   #162c22;
    --warn:      #e0ae66;
    --warn-soft: #302516;
    --crit:      #f0917f;
    --crit-soft: #341d18;
    --info:      #7fb7e0;
    --info-soft: #172733;
    --idle:      #9aa4b2;
    --idle-soft: #222831;

    --shadow: 0 1px 2px rgba(0, 0, 0, .45);
  }
}

* { box-sizing: border-box; }

html, body { margin: 0; padding: 0; max-width: 100%; overflow-x: hidden; }

body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.55 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
        "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3 { margin: 0; font-weight: 600; letter-spacing: -.01em; }
p { margin: 0; }
ul { margin: 0; padding: 0; list-style: none; }

.muted { color: var(--text-soft); }
.small { font-size: .78rem; }

.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

/* Visible keyboard focus everywhere, never removed. */
a:focus-visible, button:focus-visible, input:focus-visible,
label:focus-visible, [tabindex]:focus-visible {
  outline: var(--focus); outline-offset: 2px; border-radius: 6px;
}

.skip-link {
  position: absolute; left: -9999px; top: 0;
  background: var(--accent); color: var(--accent-ink);
  padding: .6rem 1rem; z-index: 100; border-radius: 0 0 var(--radius) 0;
}
.skip-link:focus { left: 0; }

/* ---------- brand ---------- */
.brand { display: flex; align-items: center; gap: .7rem; }
.brand-mark {
  width: 34px; height: 34px; flex: 0 0 34px;
  display: grid; place-items: center;
  background: var(--accent); color: var(--accent-ink);
  border-radius: 9px; font-weight: 700;
}
.brand-text { display: flex; flex-direction: column; line-height: 1.15; min-width: 0; }
.brand-text strong { font-size: .95rem; }
.brand-text small { color: var(--text-soft); font-size: .75rem; }
.brand-lg .brand-mark { width: 42px; height: 42px; flex-basis: 42px; font-size: 1.2rem; }

/* ---------- layout ---------- */
.layout { min-height: 100vh; }
.nav-toggle { position: absolute; opacity: 0; pointer-events: none; }

.nav-scrim {
  position: fixed; inset: 0; z-index: 30;
  background: rgba(8, 11, 16, .5);
  opacity: 0; visibility: hidden; transition: opacity .18s ease;
}
.nav-toggle:checked ~ .nav-scrim { opacity: 1; visibility: visible; }

.sidebar {
  position: fixed; z-index: 40; inset: 0 auto 0 0;
  width: var(--sidebar-w); max-width: 84vw;
  display: flex; flex-direction: column; gap: 1rem;
  padding: 1rem .85rem;
  background: var(--surface);
  border-right: 1px solid var(--border);
  transform: translateX(-100%);
  transition: transform .2s ease;
  overflow-y: auto;
}
.nav-toggle:checked ~ .sidebar { transform: translateX(0); }

.nav { display: flex; flex-direction: column; gap: 2px; flex: 1; }
.nav-item {
  display: flex; align-items: center; justify-content: space-between; gap: .5rem;
  padding: .58rem .7rem; border-radius: 8px;
  color: var(--text-soft); text-decoration: none; font-size: .9rem;
}
a.nav-item:hover { background: var(--surface-3); color: var(--text); }
.nav-item.is-active { background: var(--accent); color: var(--accent-ink); font-weight: 600; }
.nav-item.is-disabled { cursor: default; opacity: .7; }

.badge {
  font-size: .66rem; padding: .12rem .42rem; border-radius: 999px;
  border: 1px solid var(--border); color: var(--text-soft);
  background: var(--surface-2); white-space: nowrap;
}

.sidebar-foot { font-size: .75rem; padding: .2rem .7rem; }
.main-col { display: flex; flex-direction: column; min-height: 100vh; min-width: 0; }

/* ---------- header ---------- */
.header {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: .6rem;
  padding: .7rem 1rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.header-title { min-width: 0; flex: 1; }
.header-title h1 { font-size: 1.05rem; }
.header-title p { font-size: .78rem; }
.header-right { display: flex; align-items: center; gap: .5rem; }

.user-email {
  display: none; max-width: 200px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  font-size: .82rem; color: var(--text-soft);
}

.icon-btn {
  display: grid; place-items: center;
  width: 38px; height: 38px; flex: 0 0 38px;
  border: 1px solid var(--border); border-radius: 9px;
  background: var(--surface-2); cursor: pointer;
}
.burger, .burger::before, .burger::after {
  content: ""; display: block;
  width: 16px; height: 2px; border-radius: 2px; background: var(--text);
}
.burger { position: relative; }
.burger::before { position: absolute; top: -5px; }
.burger::after  { position: absolute; top: 5px; }

/* ---------- theme switch ---------- */
.theme-switch {
  display: inline-flex; padding: 2px; gap: 2px;
  border: 1px solid var(--border); border-radius: 9px;
  background: var(--surface-2);
}
.theme-btn {
  font: inherit; font-size: .85rem; line-height: 1;
  width: 30px; height: 30px;
  display: grid; place-items: center;
  border: 0; border-radius: 7px;
  background: transparent; color: var(--text-soft); cursor: pointer;
}
.theme-btn:hover { background: var(--surface-3); color: var(--text); }
.theme-btn[aria-pressed="true"] {
  background: var(--accent); color: var(--accent-ink); font-weight: 700;
}

.content { padding: 1rem; flex: 1; display: flex; flex-direction: column; gap: 1rem; }

/* ---------- metric cards ---------- */
.cards { display: grid; gap: .8rem; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); }
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow);
  padding: .95rem 1rem; border-top: 3px solid var(--border); min-width: 0;
}
.card-accent-ok   { border-top-color: var(--ok); }
.card-accent-idle { border-top-color: var(--idle); }
.card-accent-warn { border-top-color: var(--warn); }
.card-label { font-size: .78rem; color: var(--text-soft); }
.card-value {
  font-size: 1.85rem; font-weight: 650; letter-spacing: -.02em;
  margin-top: .15rem; font-variant-numeric: tabular-nums;
}
.card-note { font-size: .72rem; color: var(--text-soft); margin-top: .2rem; }

/* ---------- panels ---------- */
.grid-2 { display: grid; gap: 1rem; grid-template-columns: 1fr; }

.panel {
  padding: 1.1rem; background: var(--surface);
  border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); min-width: 0;
}
.panel-head {
  display: flex; align-items: center; gap: .5rem;
  margin-bottom: .8rem; flex-wrap: wrap;
}
.panel-head h2 { font-size: 1rem; flex: 1; }
.panel p + p { margin-top: .5rem; }
.panel-notice { border-left: 3px solid var(--accent); }

.count-pill {
  font-size: .74rem; font-weight: 600; padding: .1rem .5rem;
  border-radius: 999px; background: var(--accent-soft); color: var(--accent);
  border: 1px solid var(--border);
}
.empty { color: var(--text-soft); font-size: .9rem; }

/* ---------- action center ---------- */
.action-list { display: flex; flex-direction: column; gap: .55rem; }
.action {
  display: flex; gap: .65rem; align-items: flex-start;
  padding: .65rem .75rem; border-radius: 9px;
  background: var(--surface-2);
  border: 1px solid var(--border-soft);
  border-left: 3px solid var(--idle);
}
.action-critical { border-left-color: var(--crit); background: var(--crit-soft); }
.action-warning  { border-left-color: var(--warn); background: var(--warn-soft); }
.action-info     { border-left-color: var(--info); background: var(--info-soft); }

/* Status is carried by this text label, not by colour alone. */
.action-tag {
  flex: 0 0 auto; font-size: .68rem; font-weight: 700;
  letter-spacing: .02em; text-transform: uppercase;
  padding: .2rem .45rem; border-radius: 6px;
  border: 1px solid currentColor; white-space: nowrap;
}
.action-critical .action-tag { color: var(--crit); }
.action-warning  .action-tag { color: var(--warn); }
.action-info     .action-tag { color: var(--info); }

.action-body { min-width: 0; }
.action-title { font-size: .9rem; font-weight: 600; }
.action-desc  { font-size: .8rem; margin-top: .12rem; }
.action-date  { font-size: .75rem; margin-top: .2rem; font-variant-numeric: tabular-nums; }

/* ---------- upcoming ---------- */
.upcoming-summary { font-size: .9rem; margin-bottom: .6rem; }
.mini-list { display: flex; flex-direction: column; gap: .3rem; }
.mini-list li {
  display: flex; justify-content: space-between; gap: .5rem;
  font-size: .85rem; padding: .35rem .5rem;
  background: var(--surface-2); border-radius: 7px;
  border: 1px solid var(--border-soft);
}
.mini-key { font-weight: 600; }

/* ---------- quick actions ---------- */
.qa-note { margin-bottom: .7rem; }
.quick-grid { display: grid; gap: .6rem; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); }
.quick {
  font: inherit; text-align: left; cursor: not-allowed;
  display: flex; flex-direction: column; gap: .15rem; align-items: flex-start;
  padding: .7rem .8rem; border-radius: 9px;
  border: 1px dashed var(--border); background: var(--surface-2);
  color: var(--text); opacity: .72;
}
.quick-label { font-size: .88rem; font-weight: 600; }
.quick-hint  { font-size: .74rem; }
.quick .badge { margin-top: .3rem; }

/* ---------- building snapshot ---------- */
.unit-grid {
  display: grid; gap: .5rem;
  grid-template-columns: repeat(auto-fill, minmax(84px, 1fr));
}
.unit {
  display: flex; flex-direction: column; gap: .15rem; align-items: center;
  padding: .55rem .35rem; border-radius: 9px;
  border: 1px solid var(--border); border-top-width: 3px;
  background: var(--surface-2); min-width: 0;
}
.unit-no { font-weight: 700; font-size: .95rem; font-variant-numeric: tabular-nums; }
.unit-status { font-size: .68rem; text-align: center; line-height: 1.25; }

.unit-occupied       { border-top-color: var(--ok);   background: var(--ok-soft); }
.unit-occupied .unit-status { color: var(--ok); }
.unit-vacant         { border-top-color: var(--idle); background: var(--idle-soft); }
.unit-vacant .unit-status { color: var(--idle); }
.unit-renovation     { border-top-color: var(--warn); background: var(--warn-soft); }
.unit-renovation .unit-status { color: var(--warn); }
.unit-reserved       { border-top-color: var(--info); background: var(--info-soft); }
.unit-reserved .unit-status { color: var(--info); }
.unit-out-of-service { border-top-color: var(--crit); background: var(--crit-soft); }
.unit-out-of-service .unit-status { color: var(--crit); }

.legend {
  display: flex; flex-wrap: wrap; gap: .5rem 1rem;
  margin-top: .9rem; padding-top: .8rem;
  border-top: 1px solid var(--border-soft);
  font-size: .76rem; color: var(--text-soft);
}
.legend li { display: flex; align-items: center; gap: .35rem; }
.swatch {
  width: 12px; height: 12px; border-radius: 4px;
  border: 1px solid var(--border); border-top-width: 3px;
}

/* ---------- buttons ---------- */
.btn {
  font: inherit; font-size: .87rem;
  padding: .5rem .85rem; border-radius: 8px;
  border: 1px solid var(--border); background: var(--surface-2);
  color: var(--text); cursor: pointer;
}
.btn:hover { border-color: var(--text-soft); }
.btn-primary {
  background: var(--accent); border-color: var(--accent);
  color: var(--accent-ink); font-weight: 600;
}
.btn-ghost { background: transparent; }
.btn-block { width: 100%; padding: .68rem; font-size: .95rem; }

/* ---------- auth ---------- */
.auth-wrap { min-height: 100vh; display: grid; place-items: center; padding: 1.25rem; }
.auth-card {
  width: 100%; max-width: 380px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 14px; box-shadow: var(--shadow); padding: 1.6rem 1.4rem;
}
.auth-title { font-size: 1.2rem; margin: 1.1rem 0 1rem; }
.auth-foot { font-size: .78rem; margin-top: 1rem; text-align: center; }

.field { margin-bottom: .9rem; }
.field label {
  display: block; font-size: .8rem; font-weight: 600;
  margin-bottom: .3rem; color: var(--text-soft);
}
.field input {
  width: 100%; font: inherit; padding: .6rem .7rem;
  border: 1px solid var(--border); border-radius: 8px;
  background: var(--surface-2); color: var(--text);
}
.field input::placeholder { color: var(--text-soft); opacity: .75; }
.field input:focus { outline: var(--focus); outline-offset: 1px; border-color: var(--accent); }
.field-error { color: var(--crit); font-size: .78rem; margin-top: .25rem; }

.alert {
  border: 1px solid var(--crit); border-left-width: 3px; border-radius: 8px;
  padding: .6rem .75rem; font-size: .85rem;
  color: var(--crit); background: var(--crit-soft); margin-bottom: .9rem;
}

/* ---------- desktop ---------- */
@media (min-width: 900px) {
  .sidebar { transform: none; }
  .nav-scrim, .nav-open { display: none; }
  .main-col { margin-left: var(--sidebar-w); }
  .header { padding: .85rem 1.5rem; }
  .header-title h1 { font-size: 1.15rem; }
  .user-email { display: inline-block; }
  .content { padding: 1.5rem; gap: 1.25rem; }
  .cards { grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); }
  .grid-2 { grid-template-columns: 3fr 2fr; }
}

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