:root {
  --bg: #0b1416;
  --bg-2: #0f1c1f;
  --panel: #122226;
  --panel-2: #172b30;
  --line: #22393f;
  --line-2: #2c4950;
  --text: #e6f0ee;
  --text-2: #a9bfbb;
  --text-3: #7d9592;
  --accent: #34d3a6;
  --accent-ink: #062a20;
  --accent-soft: rgba(52, 211, 166, 0.14);
  --amber: #f2b84b;
  --amber-soft: rgba(242, 184, 75, 0.15);
  --red: #f26d6d;
  --red-soft: rgba(242, 109, 109, 0.15);
  --blue: #5fa8f5;
  --blue-soft: rgba(95, 168, 245, 0.15);
  --violet: #b58cf5;
  --violet-soft: rgba(181, 140, 245, 0.15);
  --green: #4cc38a;
  --green-soft: rgba(76, 195, 138, 0.15);
  --grey-soft: rgba(160, 180, 178, 0.13);
  --shadow: 0 8px 30px rgba(0, 0, 0, 0.35);
  --radius: 12px;
  --mono: ui-monospace, 'Cascadia Code', Consolas, 'SF Mono', monospace;
  color-scheme: dark;
}

@media (prefers-color-scheme: light) {
  :root:not([data-theme='dark']) {
    --bg: #f3f6f5; --bg-2: #eaf0ef; --panel: #ffffff; --panel-2: #f5f8f7; --line: #dbe5e3; --line-2: #c8d6d3;
    --text: #12201e; --text-2: #4b605c; --text-3: #6f8480; --accent: #0f9d77; --accent-ink: #ffffff;
    --accent-soft: rgba(15, 157, 119, 0.12); --amber: #b7791f; --red: #c53b3b; --blue: #2f73c9; --violet: #7a4fd0;
    --green: #2b8a5c; --shadow: 0 8px 30px rgba(20, 40, 40, 0.12); color-scheme: light;
  }
}
:root[data-theme='light'] {
  --bg: #f3f6f5; --bg-2: #eaf0ef; --panel: #ffffff; --panel-2: #f5f8f7; --line: #dbe5e3; --line-2: #c8d6d3;
  --text: #12201e; --text-2: #4b605c; --text-3: #6f8480; --accent: #0f9d77; --accent-ink: #ffffff;
  --accent-soft: rgba(15, 157, 119, 0.12); --amber: #b7791f; --red: #c53b3b; --blue: #2f73c9; --violet: #7a4fd0;
  --green: #2b8a5c; --shadow: 0 8px 30px rgba(20, 40, 40, 0.12); color-scheme: light;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
button, input, select, textarea { font: inherit; color: inherit; }
h1, h2, h3, h4 { margin: 0; line-height: 1.25; }
h1 { font-size: 22px; font-weight: 650; }
h2 { font-size: 16px; font-weight: 650; }
h3 { font-size: 14px; font-weight: 650; }
code { font-family: var(--mono); font-size: 0.92em; background: var(--panel-2); border: 1px solid var(--line); border-radius: 5px; padding: 0 4px; }

/* ---------- layout ---------- */
.app { display: grid; grid-template-columns: 236px 1fr; min-height: 100vh; }
.side {
  background: var(--bg-2); border-right: 1px solid var(--line); padding: 16px 12px;
  display: flex; flex-direction: column; gap: 4px; position: sticky; top: 0; height: 100vh; overflow-y: auto;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 8px 16px; font-weight: 700; font-size: 15px; }
.logo {
  width: 30px; height: 30px; border-radius: 9px; display: grid; place-items: center;
  background: linear-gradient(135deg, var(--accent), #1f8f9f); color: var(--accent-ink); font-weight: 800; font-size: 13px;
}
.nav-label { font-size: 11px; letter-spacing: 0.08em; text-transform: uppercase; color: var(--text-3); padding: 14px 10px 4px; }
.nav a {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 7px 10px; border-radius: 8px; color: var(--text-2); font-weight: 500;
}
.nav a:hover { background: var(--panel); text-decoration: none; color: var(--text); }
.nav a.on { background: var(--accent-soft); color: var(--accent); }
.badge {
  min-width: 20px; height: 20px; border-radius: 10px; padding: 0 6px; font-size: 11px; font-weight: 700;
  display: inline-grid; place-items: center; background: var(--red); color: #fff;
}
.badge.soft { background: var(--panel-2); color: var(--text-2); border: 1px solid var(--line); }
.side-foot { margin-top: auto; padding-top: 16px; display: flex; gap: 6px; align-items: center; color: var(--text-3); font-size: 12px; }
.main { padding: 24px 28px 60px; max-width: 1280px; width: 100%; }
.topbar { display: none; }
.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 18px; flex-wrap: wrap; }
.page-head p { margin: 4px 0 0; color: var(--text-2); }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.grow { flex: 1; }
.muted { color: var(--text-3); }
.small { font-size: 12px; }
.mt { margin-top: 16px; }
.mt-s { margin-top: 8px; }
.stack { display: flex; flex-direction: column; gap: 12px; }

/* ---------- cards / panels ---------- */
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; }
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 12px; }
.kpis { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 12px; margin-bottom: 18px; }
.kpi {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px;
  cursor: pointer; transition: border-color 0.15s;
}
.kpi:hover { border-color: var(--line-2); }
.kpi .n { font-size: 26px; font-weight: 700; line-height: 1.1; font-variant-numeric: tabular-nums; }
.kpi .l { color: var(--text-2); font-size: 12px; margin-top: 2px; }
.kpi.alert .n { color: var(--red); }
.kpi.warn .n { color: var(--amber); }
.kpi.ok .n { color: var(--accent); }
.kpi.info .n { color: var(--blue); }

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 16px; overflow-x: auto; }
.tabs a {
  padding: 8px 12px; color: var(--text-2); border-bottom: 2px solid transparent; white-space: nowrap; font-weight: 500;
}
.tabs a:hover { color: var(--text); text-decoration: none; }
.tabs a.on { color: var(--accent); border-bottom-color: var(--accent); }

.section { margin-top: 22px; }
.section-title { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; }
.section-title h2 { font-size: 14px; }
.empty { color: var(--text-3); padding: 14px; border: 1px dashed var(--line); border-radius: var(--radius); text-align: center; }

/* job card */
.jobs { display: flex; flex-direction: column; gap: 8px; }
.job {
  display: grid; grid-template-columns: 1fr auto; gap: 4px 12px; align-items: center;
  background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 11px 14px;
  color: var(--text); cursor: pointer; transition: border-color 0.15s, background 0.15s;
}
.job:hover { border-color: var(--line-2); background: var(--panel-2); text-decoration: none; }
.job .t { font-weight: 600; overflow-wrap: anywhere; }
.job .meta { grid-column: 1 / -1; display: flex; gap: 10px; flex-wrap: wrap; color: var(--text-3); font-size: 12px; }
.job.compact { padding: 9px 11px; }

/* board */
.board { display: grid; grid-template-columns: repeat(5, minmax(200px, 1fr)); gap: 12px; overflow-x: auto; padding-bottom: 6px; }
.col { background: var(--bg-2); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px; min-height: 120px; }
.col-head { display: flex; justify-content: space-between; align-items: center; padding: 2px 4px 10px; font-weight: 600; font-size: 13px; }

/* project job list: one row per job */
.job-filter { display: flex; gap: 12px; align-items: flex-end; flex-wrap: wrap; margin-bottom: 10px; }
.job-filter label.f { width: 220px; }
.job-filter label.f.grow { flex: 1; min-width: 180px; width: auto; max-width: 360px; }
.job-filter > .muted { padding-bottom: 9px; }
.jobs-table { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); font-size: 14px; }
.jobs-table th { background: var(--bg-2); white-space: nowrap; padding: 9px 12px; }
.jobs-table td { padding: 10px 12px; vertical-align: middle; }
.jobs-table td.num { color: var(--text-3); font-family: var(--mono); white-space: nowrap; }
.jobs-table td.jt { min-width: 320px; font-weight: 600; }
.jobs-table td.jt a { color: var(--text); }
.jobs-table td.jt .jsub { font-weight: 400; font-size: 12.5px; color: var(--text-3); margin-top: 2px; max-width: 70ch; }
.jobs-table td.nowrap.open { color: var(--accent); font-weight: 600; }
.jobs-table td.nowrap { white-space: nowrap; color: var(--text-2); }
.jobs-table tr.jrow { cursor: pointer; }
.jobs-table tr.jrow:hover td, .jobs-table tr.jrow:focus-visible td { background: var(--panel-2); }
.jobs-table tr:last-child td { border-bottom: 0; }

/* pills */
.pill {
  display: inline-flex; align-items: center; gap: 5px; height: 22px; padding: 0 9px; border-radius: 11px;
  font-size: 11.5px; font-weight: 600; white-space: nowrap; background: var(--grey-soft); color: var(--text-2);
}
.pill::before { content: ''; width: 6px; height: 6px; border-radius: 3px; background: currentColor; }
.pill.amber { background: var(--amber-soft); color: var(--amber); }
.pill.red { background: var(--red-soft); color: var(--red); }
.pill.blue { background: var(--blue-soft); color: var(--blue); }
.pill.teal { background: var(--accent-soft); color: var(--accent); }
.pill.violet { background: var(--violet-soft); color: var(--violet); }
.pill.green { background: var(--green-soft); color: var(--green); }
.pill.plain::before { display: none; }
.chip {
  display: inline-flex; align-items: center; height: 20px; padding: 0 8px; border-radius: 6px; font-size: 11.5px;
  background: var(--panel-2); border: 1px solid var(--line); color: var(--text-2); white-space: nowrap;
}
.prio-high { color: var(--red); font-weight: 600; }

/* ---------- buttons & forms ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; height: 34px; padding: 0 14px;
  border-radius: 9px; border: 1px solid var(--line-2); background: var(--panel-2); color: var(--text);
  font-weight: 600; cursor: pointer; white-space: nowrap; transition: filter 0.15s, background 0.15s;
}
.btn:hover { filter: brightness(1.12); text-decoration: none; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; filter: none; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.danger { background: transparent; border-color: var(--red); color: var(--red); }
.btn.ghost { background: transparent; border-color: transparent; color: var(--text-2); }
.btn.ghost:hover { background: var(--panel-2); color: var(--text); }
.btn.sm { height: 28px; padding: 0 10px; font-size: 12.5px; border-radius: 7px; }
label.f { display: flex; flex-direction: column; gap: 5px; font-size: 12.5px; color: var(--text-2); font-weight: 500; }
input[type='text'], input[type='password'], input[type='date'], input:not([type]), select, textarea {
  width: 100%; background: var(--bg-2); border: 1px solid var(--line-2); border-radius: 9px; padding: 8px 11px;
  outline: none; transition: border-color 0.15s;
}
input:focus, select:focus, textarea:focus { border-color: var(--accent); }
textarea { resize: vertical; min-height: 90px; line-height: 1.5; }
textarea.code { font-family: var(--mono); font-size: 13px; min-height: 380px; }
.check { display: flex; gap: 8px; align-items: center; color: var(--text-2); font-size: 13px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.hint { font-size: 12px; color: var(--text-3); }
.warn-box { background: var(--amber-soft); color: var(--amber); border-radius: 9px; padding: 9px 12px; font-size: 13px; }
.err-box { background: var(--red-soft); color: var(--red); border-radius: 9px; padding: 9px 12px; font-size: 13px; }

/* ---------- job page ---------- */
.job-grid {
  display: grid; grid-template-columns: minmax(0, 1fr) 380px; gap: 16px; align-items: start;
  grid-template-areas: 'a c' 'f c';
}
.ga { grid-area: a; }
.gc { grid-area: c; }
.gf { grid-area: f; }
.action-box {
  background: var(--bg-2); border: 1px solid var(--line-2); border-left: 3px solid var(--accent);
  border-radius: 9px; padding: 12px 14px; white-space: pre-wrap; overflow-wrap: anywhere; font-size: 14px;
}
.pre { white-space: pre-wrap; overflow-wrap: anywhere; }
.facts { display: grid; grid-template-columns: auto 1fr; gap: 7px 14px; font-size: 13px; }
.facts dt { color: var(--text-3); }
.facts dd { margin: 0; overflow-wrap: anywhere; }
.banner {
  display: flex; align-items: center; gap: 10px; border-radius: 10px; padding: 11px 14px; margin-bottom: 14px; font-weight: 500;
}
.banner.red { background: var(--red-soft); color: var(--red); }
.banner.amber { background: var(--amber-soft); color: var(--amber); }
.banner.blue { background: var(--blue-soft); color: var(--blue); }
.banner.violet { background: var(--violet-soft); color: var(--violet); }
.banner.green { background: var(--green-soft); color: var(--green); }

.thread { display: flex; flex-direction: column; gap: 10px; }
.msg { max-width: 88%; border-radius: 12px; padding: 9px 12px; background: var(--panel-2); border: 1px solid var(--line); }
.msg.ali { align-self: flex-end; background: var(--accent-soft); border-color: transparent; }
.msg.system { align-self: center; background: transparent; border: none; color: var(--text-3); font-size: 12px; padding: 2px; text-align: center; }
.msg.k-question { border-color: var(--amber); }
.msg.k-problem { border-color: var(--red); }
.msg.k-result { border-color: var(--green); }
.msg .who { font-size: 11.5px; color: var(--text-3); margin-bottom: 3px; display: flex; gap: 8px; align-items: center; }
.msg .body { white-space: pre-wrap; overflow-wrap: anywhere; }
.composer { display: flex; flex-direction: column; gap: 8px; margin-top: 12px; }

/* ---------- notes ---------- */
.notes-grid { display: grid; grid-template-columns: 280px minmax(0, 1fr); gap: 16px; align-items: start; }
.tree { display: flex; flex-direction: column; gap: 2px; font-size: 13px; }
.tree .grp { font-weight: 650; color: var(--text); padding: 10px 8px 4px; }
.tree .sub { color: var(--text-3); padding: 6px 8px 2px 16px; font-size: 12px; text-transform: uppercase; letter-spacing: 0.05em; }
.tree a { padding: 5px 8px 5px 16px; border-radius: 7px; color: var(--text-2); display: block; }
.tree a.deep { padding-left: 26px; }
.tree a:hover { background: var(--panel-2); text-decoration: none; }
.tree a.on { background: var(--accent-soft); color: var(--accent); }
.md { line-height: 1.6; overflow-wrap: anywhere; }
.md h2, .md h3, .md h4, .md h5 { margin: 18px 0 8px; }
.md p { margin: 8px 0; }
.md ul, .md ol { margin: 8px 0; padding-left: 22px; }
.md li { margin: 3px 0; }
.md pre { background: var(--bg-2); border: 1px solid var(--line); border-radius: 9px; padding: 12px; overflow-x: auto; }
.md pre code { background: none; border: none; padding: 0; }
.md blockquote { margin: 8px 0; padding: 4px 12px; border-left: 3px solid var(--line-2); color: var(--text-2); }
.table-wrap { overflow-x: auto; margin: 10px 0; }
.md table, table.list { border-collapse: collapse; width: 100%; font-size: 13px; }
.md th, .md td, table.list th, table.list td { border-bottom: 1px solid var(--line); padding: 7px 10px; text-align: left; vertical-align: top; }
.md th, table.list th { color: var(--text-3); font-weight: 600; font-size: 12px; }
.split { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

/* ---------- modal & toast ---------- */
.modal-bg {
  position: fixed; inset: 0; background: rgba(0, 0, 0, 0.55); display: grid; place-items: center; z-index: 50; padding: 16px;
}
.modal {
  background: var(--panel); border: 1px solid var(--line-2); border-radius: 14px; box-shadow: var(--shadow);
  width: min(520px, 100%); max-height: calc(100vh - 32px); overflow-y: auto; padding: 20px;
}
.modal.wide { width: min(760px, 100%); }
.modal h2 { margin-bottom: 4px; }
.modal .foot { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }
.key-box { font-family: var(--mono); background: var(--bg-2); border: 1px solid var(--accent); border-radius: 9px; padding: 12px; overflow-wrap: anywhere; user-select: all; }
.toasts { position: fixed; right: 16px; bottom: 16px; display: flex; flex-direction: column; gap: 8px; z-index: 60; }
.toast { background: var(--panel); border: 1px solid var(--line-2); border-left: 3px solid var(--accent); border-radius: 10px; padding: 10px 14px; box-shadow: var(--shadow); max-width: 380px; }
.toast.err { border-left-color: var(--red); }

/* ---------- login ---------- */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login { width: min(400px, 100%); }
.login .pin-input { font-size: 22px; letter-spacing: 0.4em; text-align: center; }
.login .brand { justify-content: center; padding-bottom: 6px; font-size: 18px; }

/* ---------- responsive ---------- */
@media (max-width: 1100px) {
  .job-grid { grid-template-columns: 1fr; grid-template-areas: 'a' 'c' 'f'; }
  .kpis { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}
@media (max-width: 860px) {
  .app { grid-template-columns: 1fr; }
  .side { display: none; position: fixed; inset: 0 30% 0 0; z-index: 40; height: 100vh; box-shadow: var(--shadow); }
  .side.open { display: flex; }
  .topbar {
    display: flex; align-items: center; gap: 10px; padding: 10px 16px; border-bottom: 1px solid var(--line);
    background: var(--bg-2); position: sticky; top: 0; z-index: 30;
  }
  .main { padding: 16px 16px 60px; }
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .notes-grid, .grid2, .grid3, .split { grid-template-columns: 1fr; }
  .board { grid-template-columns: repeat(5, 240px); }
  .msg { max-width: 100%; }
}

/* Work log */
.jobs-table td.wl-place { min-width: 220px; max-width: 320px; overflow-wrap: anywhere; font-size: 12.5px; }
.job-filter.wl label.f { width: 170px; }
.jobs-table td.strong { font-weight: 600; white-space: nowrap; }
.mono { font-family: ui-monospace, Consolas, monospace; font-size: 12px; }

/* Tick boxes + bulk actions */
.jobs-table .tick { width: 34px; text-align: center; }
.jobs-table .tick input { width: 16px; height: 16px; cursor: pointer; accent-color: var(--accent); }
.jobs-table tr.sel td { background: var(--accent-soft); }
.bulk-bar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; padding: 8px 12px; margin-bottom: 10px; border: 1px solid var(--accent); border-radius: 10px; background: var(--accent-soft); }
.bulk-bar[hidden] { display: none; }
.bulk-list { max-height: 45vh; overflow: auto; display: flex; flex-direction: column; gap: 10px; margin-bottom: 8px; }
.bulk-item .action-box { margin-top: 4px; }

/* shared project folder line */
.folder-line { display: flex; flex-wrap: wrap; gap: 6px; align-items: baseline; margin: -6px 0 14px; overflow-wrap: anywhere; }
.folder-line code { font-size: 13px; }
