/* ============================================================================
   KTS master dashboard — app.css

   THE RULE (§6): every colour in this app comes from a token. A hardcoded hex
   anywhere outside the four token blocks below is a defect. Data-driven
   inline styles (status colours) reference the tokens through var().

   Token blocks:
     1. :root[data-theme="dark"]   — the default
     2. :root[data-theme="light"]
     3. .wall                      — the status wall, which stays DARK in both
                                     themes. It is the signature element, and
                                     glowing tiles on a dark panel read
                                     correctly inside a light UI.
     4. @media print              — paper is white and ink is black in both
                                     themes, the wall included.
   ========================================================================= */

/* ---------------------------------------------------------- 1 · dark (default) */
:root,
:root[data-theme="dark"] {
  --bg:            #0b0e14;
  --bg-grad:       radial-gradient(1200px 600px at 12% -10%, #141b2b 0%, #0b0e14 60%);
  --panel:         #141922;
  --panel-2:       #1a2029;
  --panel-3:       #0e131b;
  --line:          #222a37;
  --line-2:        #2d3747;

  --text:          #e6ecf5;
  --text-dim:      #a8b4c6;
  --text-mute:     #7c8899;

  --brand:         #2FA9F4;   /* the KTS wordmark blue */
  --brand-ink:     #04131f;   /* text ON a brand-coloured surface */
  --violet:        #7E5CF6;
  --magenta:       #F02DC4;
  --cyan:          #3EE9F5;

  --good:          #3ddc97;
  --good-dim:      #1d5f45;
  --warn:          #ffb454;
  --warn-dim:      #6b4a1d;
  --bad:           #ff5c7a;
  --bad-dim:       #6b2233;
  --info:          #64b5ff;

  --shadow:        0 1px 2px rgba(0,0,0,.4), 0 8px 24px rgba(0,0,0,.24);
  --shadow-sm:     0 1px 2px rgba(0,0,0,.3);
  --overlay:       rgba(6,9,14,.72);
  --focus:         var(--brand);
  --selection:     rgba(47,169,244,.28);

  --radius:        12px;
  --radius-sm:     8px;
  --sidebar-w:     236px;
}

/* ------------------------------------------------------------------ 2 · light */
:root[data-theme="light"] {
  --bg:            #f4f6fa;
  --bg-grad:       radial-gradient(1200px 600px at 12% -10%, #e8eef8 0%, #f4f6fa 60%);
  --panel:         #ffffff;
  --panel-2:       #f7f9fc;
  --panel-3:       #eef2f8;
  --line:          #dde3ec;
  --line-2:        #c8d1de;

  --text:          #0f1722;
  --text-dim:      #4a5768;
  --text-mute:     #6b7789;

  --brand:         #1478c4;
  --brand-ink:     #ffffff;
  --violet:        #6742e0;
  --magenta:       #c91aa2;
  --cyan:          #0e93a6;

  --good:          #0f8f5f;
  --good-dim:      #cdf0e0;
  --warn:          #a86412;
  --warn-dim:      #fbe8cc;
  --bad:           #c62a48;
  --bad-dim:       #fbd9e0;
  --info:          #1a6fc4;

  --shadow:        0 1px 2px rgba(16,24,40,.06), 0 8px 24px rgba(16,24,40,.08);
  --shadow-sm:     0 1px 2px rgba(16,24,40,.08);
  --overlay:       rgba(16,24,40,.42);
  --selection:     rgba(20,120,196,.2);
}

/* =============================================================== base ==== */

/* §13.2 — the app switches screens with the `hidden` attribute, but a class on
   the same element sets `display` (.shell{display:grid}), and that class beats
   the browser's default [hidden]{display:none}. Without this line the login,
   setup and app screens all render stacked on first load. */
[hidden] { display: none !important; }

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  background: var(--bg);
  background-image: var(--bg-grad);
  background-attachment: fixed;
  color: var(--text);
  font: 14px/1.55 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-variant-numeric: tabular-nums;
  -webkit-font-smoothing: antialiased;
}

::selection { background: var(--selection); }

a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }

h1, h2, h3 { margin: 0; font-weight: 650; letter-spacing: -.01em; }
h1 { font-size: 20px; }
h2 { font-size: 16px; }
h3 { font-size: 13px; color: var(--text-dim); text-transform: uppercase; letter-spacing: .06em; }

:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; border-radius: 4px; }

.muted   { color: var(--text-mute); }
.dim     { color: var(--text-dim); }
.small   { font-size: 12px; }
.mono    { font-family: ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace; font-size: 12px; }
.right   { text-align: right; }
.center  { text-align: center; }
.nowrap  { white-space: nowrap; }
.grow    { flex: 1; }
.stack   { display: flex; flex-direction: column; gap: 14px; }
.row     { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.good { color: var(--good); } .warn { color: var(--warn); } .bad { color: var(--bad); }

/* ============================================================ login ==== */

.center-screen {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}
.card-auth {
  width: 100%; max-width: 400px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 30px;
}
.card-auth .logo { height: 32px; margin-bottom: 20px; display: block; }

/* ============================================================ shell ==== */

.shell {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  min-height: 100vh;
}

.sidebar {
  background: var(--panel);
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}
.sidebar-head { padding: 20px 18px 14px; }
.sidebar-head img { height: 26px; display: block; }

.nav { padding: 0 10px 10px; flex: 1; }
.nav-group { margin-top: 14px; }
.nav-group > span {
  display: block; padding: 0 8px 6px;
  font-size: 10.5px; font-weight: 700; letter-spacing: .09em;
  text-transform: uppercase; color: var(--text-mute);
}
.nav a {
  display: flex; align-items: center; gap: 9px;
  padding: 7px 9px; border-radius: var(--radius-sm);
  color: var(--text-dim); font-size: 13.5px; font-weight: 500;
  text-decoration: none;
}
.nav a:hover { background: var(--panel-2); color: var(--text); text-decoration: none; }
.nav a.active { background: var(--panel-2); color: var(--text); box-shadow: inset 2px 0 0 var(--brand); }
.nav .pill {
  margin-left: auto; font-size: 11px; font-weight: 700;
  background: var(--bad); color: var(--brand-ink);
  padding: 1px 6px; border-radius: 9px;
}
.nav .ico { width: 15px; text-align: center; opacity: .8; font-size: 13px; }

.sidebar-foot {
  border-top: 1px solid var(--line);
  padding: 10px;
  display: flex; align-items: center; gap: 8px;
}
.sidebar-foot .who { flex: 1; min-width: 0; }
.sidebar-foot .who b { display: block; font-size: 12.5px; }
.sidebar-foot .who span { display: block; font-size: 11px; color: var(--text-mute);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.main { padding: 22px 26px 60px; min-width: 0; }
.page-head {
  display: flex; align-items: flex-start; gap: 14px;
  margin-bottom: 18px; flex-wrap: wrap;
}
.page-head .sub { color: var(--text-mute); font-size: 13px; margin-top: 3px; }
.page-head .actions { margin-left: auto; display: flex; gap: 8px; flex-wrap: wrap; }

/* ========================================================== controls ==== */

.btn {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 7px 13px; border-radius: var(--radius-sm);
  border: 1px solid var(--line-2); background: var(--panel-2); color: var(--text);
  font: inherit; font-size: 13px; font-weight: 550; cursor: pointer;
  white-space: nowrap; text-decoration: none;
}
.btn:hover { background: var(--panel-3); text-decoration: none; }
.btn:active { transform: translateY(1px); }
.btn[disabled] { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
.btn-primary:hover { background: var(--brand); filter: brightness(1.08); }
.btn-danger { color: var(--bad); border-color: var(--bad-dim); }
.btn-sm { padding: 4px 9px; font-size: 12px; }
.btn-icon { padding: 6px 8px; }

input, select, textarea {
  width: 100%;
  padding: 7px 10px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--line-2);
  background: var(--panel-3);
  color: var(--text);
  font: inherit; font-size: 13.5px;
}
textarea { min-height: 84px; resize: vertical; line-height: 1.5; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--focus); outline-offset: 0; border-color: transparent; }
input[type="checkbox"] { width: auto; accent-color: var(--brand); }
label { display: block; font-size: 12px; color: var(--text-dim); margin-bottom: 4px; font-weight: 550; }
.field { margin-bottom: 13px; }
.field .hint { font-size: 11.5px; color: var(--text-mute); margin-top: 4px; }
.field-check { display: flex; align-items: center; gap: 8px; margin-bottom: 11px; }
.field-check label { margin: 0; color: var(--text); font-size: 13px; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

.toolbar {
  display: flex; gap: 8px; align-items: center; flex-wrap: wrap;
  margin-bottom: 14px;
}
.toolbar input, .toolbar select { width: auto; min-width: 130px; }
.toolbar .search { min-width: 200px; }

/* ============================================================ panels ==== */

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
}
.panel-head {
  display: flex; align-items: center; gap: 10px;
  padding: 13px 16px; border-bottom: 1px solid var(--line);
}
.panel-head .actions { margin-left: auto; display: flex; gap: 8px; }
.panel-body { padding: 16px; }
.panel-body.tight { padding: 0; }

.grid { display: grid; gap: 14px; }
.grid-3 { grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); }
.grid-4 { grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); }
.grid-2 { grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); }

.stat { padding: 15px 16px; }
.stat .k { font-size: 11px; font-weight: 700; letter-spacing: .07em;
           text-transform: uppercase; color: var(--text-mute); }
.stat .v { font-size: 27px; font-weight: 680; margin-top: 5px; letter-spacing: -.02em; }
.stat .s { font-size: 12px; color: var(--text-mute); margin-top: 2px; }

/* ============================================================= table ==== */

table { width: 100%; border-collapse: collapse; }
th {
  text-align: left; font-size: 11px; font-weight: 700; letter-spacing: .06em;
  text-transform: uppercase; color: var(--text-mute);
  padding: 9px 12px; border-bottom: 1px solid var(--line); white-space: nowrap;
}
td { padding: 9px 12px; border-bottom: 1px solid var(--line); font-size: 13px; vertical-align: top; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: var(--panel-2); }
tr.clickable { cursor: pointer; }
td .rowact { display: flex; gap: 5px; justify-content: flex-end; }
.table-wrap { overflow-x: auto; }

.empty { padding: 34px 16px; text-align: center; color: var(--text-mute); font-size: 13px; }
.empty b { display: block; color: var(--text-dim); font-size: 14px; margin-bottom: 4px; }

.tag {
  display: inline-block; padding: 1.5px 8px; border-radius: 20px;
  font-size: 11.5px; font-weight: 600; white-space: nowrap;
  background: var(--panel-3); color: var(--text-dim); border: 1px solid var(--line);
}
.tag-good { background: var(--good-dim); color: var(--good); border-color: transparent; }
.tag-warn { background: var(--warn-dim); color: var(--warn); border-color: transparent; }
.tag-bad  { background: var(--bad-dim);  color: var(--bad);  border-color: transparent; }
.tag-brand{ background: var(--selection); color: var(--brand); border-color: transparent; }

.readonly-note {
  display: flex; gap: 9px; align-items: flex-start;
  padding: 10px 13px; border-radius: var(--radius-sm);
  background: var(--panel-3); border: 1px solid var(--line);
  font-size: 12.5px; color: var(--text-dim); margin-bottom: 14px;
}
.readonly-note b { color: var(--text); }

.banner {
  padding: 10px 14px; border-radius: var(--radius-sm);
  font-size: 13px; margin-bottom: 14px;
  border: 1px solid var(--line);
}
.banner-bad  { background: var(--bad-dim);  color: var(--bad);  border-color: transparent; }
.banner-warn { background: var(--warn-dim); color: var(--warn); border-color: transparent; }
.banner-good { background: var(--good-dim); color: var(--good); border-color: transparent; }

.err { color: var(--bad); font-size: 13px; margin: 10px 0; }

/* ====================================================== status wall ==== */
/* 3 · The wall keeps its own dark tokens in BOTH themes (§6). */

.wall {
  --panel:   #141922;
  --panel-2: #1a2029;
  --panel-3: #0e131b;
  --line:    #222a37;
  --line-2:  #2d3747;
  --text:      #e6ecf5;
  --text-dim:  #a8b4c6;
  --text-mute: #7c8899;
  --good: #3ddc97;  --warn: #ffb454;  --bad: #ff5c7a;  --brand: #2FA9F4;

  background: var(--panel-3);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  color: var(--text);
}
.wall-head {
  display: flex; align-items: center; gap: 10px;
  margin-bottom: 14px; color: var(--text-dim); font-size: 12px;
}
.wall-grid {
  display: grid; gap: 11px;
  grid-template-columns: repeat(auto-fill, minmax(196px, 1fr));
}
.tile {
  background: var(--panel);
  border: 1px solid var(--line);
  border-left: 3px solid var(--line-2);
  border-radius: var(--radius-sm);
  padding: 12px 13px;
  cursor: pointer;
  position: relative;
  overflow: hidden;
}
.tile:hover { background: var(--panel-2); }
.tile .name {
  font-weight: 600; font-size: 13.5px; color: var(--text);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.tile .co { font-size: 11px; color: var(--text-mute); margin-top: 1px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tile .foot { display: flex; align-items: center; gap: 7px; margin-top: 10px; }
.tile .dot { width: 8px; height: 8px; border-radius: 50%; flex: none; }
.tile .status { font-size: 12px; font-weight: 650; }
.tile .ms { margin-left: auto; font-size: 11px; color: var(--text-mute); }
.tile .note { font-size: 11px; color: var(--warn); margin-top: 6px; }

.tile-up   { border-left-color: var(--good); }
.tile-up   .dot { background: var(--good); box-shadow: 0 0 10px var(--good); }
.tile-up   .status { color: var(--good); }
.tile-warn { border-left-color: var(--warn); }
.tile-warn .dot { background: var(--warn); box-shadow: 0 0 10px var(--warn); }
.tile-warn .status { color: var(--warn); }
.tile-down { border-left-color: var(--bad); }
.tile-down .dot { background: var(--bad); box-shadow: 0 0 12px var(--bad); }
.tile-down .status { color: var(--bad); }
.tile-down { animation: pulse 2.4s ease-in-out infinite; }
.tile-unknown .dot { background: var(--text-mute); }
.tile-unknown .status { color: var(--text-mute); }

@keyframes pulse { 0%, 100% { background: var(--panel); } 50% { background: var(--panel-2); } }
@media (prefers-reduced-motion: reduce) { .tile-down { animation: none; } }

/* ============================================================ kanban ==== */

.kanban { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); }
.kcol { background: var(--panel-2); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px; }
.kcol > h4 {
  margin: 0 0 9px; font-size: 11.5px; font-weight: 700; letter-spacing: .05em;
  text-transform: uppercase; color: var(--text-mute);
  display: flex; align-items: center; gap: 6px;
}
.kcol > h4 .n { margin-left: auto; background: var(--panel-3); color: var(--text-dim);
  padding: 0 6px; border-radius: 8px; font-size: 11px; }
.kcard {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius-sm);
  padding: 10px 11px; margin-bottom: 8px; cursor: pointer;
}
.kcard:hover { border-color: var(--line-2); }
.kcard .t { font-weight: 600; font-size: 13px; }
.kcard .m { font-size: 11.5px; color: var(--text-mute); margin-top: 4px; }
.kcard .b { display: flex; gap: 6px; margin-top: 8px; flex-wrap: wrap; }
.kcol-empty { font-size: 12px; color: var(--text-mute); padding: 8px 4px; }

/* ============================================================= modal ==== */

.modal-back {
  position: fixed; inset: 0; background: var(--overlay);
  display: grid; place-items: center; padding: 22px; z-index: 50;
  overflow-y: auto;
}
.modal {
  background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow);
  width: 100%; max-width: 560px; max-height: 92vh;
  display: flex; flex-direction: column;
}
.modal-lg { max-width: 860px; }
.modal-head {
  display: flex; align-items: center; gap: 10px;
  padding: 15px 18px; border-bottom: 1px solid var(--line);
}
.modal-body { padding: 18px; overflow-y: auto; }
.modal-foot {
  display: flex; gap: 8px; justify-content: flex-end;
  padding: 13px 18px; border-top: 1px solid var(--line);
}
.modal-foot .left { margin-right: auto; }

.toast {
  position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%);
  background: var(--panel); border: 1px solid var(--line-2); color: var(--text);
  padding: 10px 16px; border-radius: var(--radius-sm); box-shadow: var(--shadow);
  font-size: 13px; z-index: 90; max-width: 90vw;
}
.toast-bad  { border-color: var(--bad);  color: var(--bad); }
.toast-good { border-color: var(--good); color: var(--good); }

/* ============================================================== misc ==== */

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 16px; flex-wrap: wrap; }
.tabs button {
  background: none; border: 0; border-bottom: 2px solid transparent;
  padding: 8px 12px; color: var(--text-mute); font: inherit; font-size: 13px;
  font-weight: 600; cursor: pointer;
}
.tabs button:hover { color: var(--text-dim); }
.tabs button.active { color: var(--brand); border-bottom-color: var(--brand); }

.bar { height: 6px; background: var(--panel-3); border-radius: 4px; overflow: hidden; min-width: 60px; }
.bar > i { display: block; height: 100%; background: var(--brand); border-radius: 4px; }
.bar > i.over { background: var(--good); }

.notes { display: flex; flex-direction: column; gap: 9px; }
.note {
  background: var(--panel-2); border: 1px solid var(--line);
  border-radius: var(--radius-sm); padding: 9px 11px; font-size: 13px;
}
.note .meta { font-size: 11px; color: var(--text-mute); margin-bottom: 3px; }

.kv { display: grid; grid-template-columns: auto 1fr; gap: 6px 14px; font-size: 13px; }
.kv dt { color: var(--text-mute); }
.kv dd { margin: 0; }

.print-only { display: none; }

/* ---------------------------------------------------------------- 4 · print */
/* The fourth token block. Paper is white and ink is black whichever theme the
   screen is in — including the status wall, which is the one place a dark
   surface would be wrong (it would print as a solid block of toner). */
@media print {
  :root, :root[data-theme="dark"], :root[data-theme="light"], .wall {
    --bg:        #ffffff;
    --panel:     #ffffff;
    --panel-2:   #ffffff;
    --panel-3:   #ffffff;
    --text:      #000000;
    --text-dim:  #333333;
    --text-mute: #555555;
    --line:      #cccccc;
    --line-2:    #999999;
    --good:      #0a6b46;
    --warn:      #8a5200;
    --bad:       #a3243c;
    --brand:     #14507f;
    --shadow:    none;
    --shadow-sm: none;
    --bg-grad:   none;
  }
  .sidebar, .page-head .actions, .toolbar, .no-print { display: none !important; }
  .shell { grid-template-columns: 1fr; }
  .print-only { display: block; }
  body { background: var(--bg); color: var(--text); }
  .panel, .wall { border-color: var(--line); box-shadow: none; break-inside: avoid; }
  .tile { animation: none; }
}

@media (max-width: 900px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; flex-direction: row; flex-wrap: wrap;
             border-right: 0; border-bottom: 1px solid var(--line); }
  .sidebar-head { padding: 12px 14px; }
  .nav { display: flex; flex-wrap: wrap; gap: 3px; width: 100%; padding: 0 10px 10px; }
  .nav-group { margin-top: 0; display: contents; }
  .nav-group > span { display: none; }
  .sidebar-foot { width: 100%; }
  .main { padding: 16px 14px 50px; }
  .field-row { grid-template-columns: 1fr; }
}
