:root {
  --navy: #1a354f; --blue: #1a65d3; --gold: #fbd068; --slate: #2d3e50;
  --ink: #292828; --muted: #6b7778; --line: #dde3ea; --bg: #f4f6f8; --card: #fff; --lightblue: #e6effc;
  --ok: #1f7a4d; --ok-bg: #e3f4ea; --warn: #8a5a00; --warn-bg: #fff3d6; --err: #a8261c; --err-bg: #fbe5e2;
  --radius: 8px;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; color: var(--ink); background: var(--bg); min-height: 100vh; display: flex; flex-direction: column; }
a { color: var(--blue); }
h1 { font-size: 1.6rem; margin: .2em 0 .6em; color: var(--navy); }
h2 { font-size: 1.1rem; margin: 0 0 .7em; color: var(--navy); }
h3 { font-size: 1rem; margin: 0 0 .3em; }
code { background: var(--lightblue); padding: .1em .35em; border-radius: 4px; }
[hidden] { display: none !important; }

.topbar { background: var(--navy); color: #fff; display: flex; align-items: center; gap: 1.5rem; padding: .7rem 1.2rem; flex-wrap: wrap; }
.brand { color: #fff; text-decoration: none; font-weight: 700; display: flex; align-items: center; gap: .5rem; }
.brand-mark { background: var(--gold); color: var(--navy); width: 28px; height: 28px; border-radius: 6px; display: grid; place-items: center; font-weight: 800; }
.mainnav { display: flex; gap: .3rem; flex-wrap: wrap; }
.mainnav a { color: #cfdbe8; text-decoration: none; padding: .35rem .7rem; border-radius: 6px; }
.mainnav a:hover { background: rgba(255,255,255,.08); color: #fff; }
.mainnav a.active { background: rgba(255,255,255,.14); color: #fff; }
.userbox { margin-left: auto; display: flex; align-items: center; gap: .9rem; font-size: .9rem; }
.userbox a, .userbox .linkbtn { color: #cfdbe8; }
.who small { color: var(--gold); margin-left: .3rem; }

.wrap { width: 100%; max-width: 1180px; margin: 0 auto; padding: 1.5rem 1rem 3rem; flex: 1; }
.foot { text-align: center; color: var(--muted); font-size: .8rem; padding: 1rem; }

.flash { padding: .7rem 1rem; border-radius: var(--radius); margin-bottom: 1rem; border: 1px solid transparent; }
.flash-ok { background: var(--ok-bg); color: var(--ok); border-color: #bfe3cd; }
.flash-err { background: var(--err-bg); color: var(--err); border-color: #f1c2bc; }
.flash-warn { background: var(--warn-bg); color: var(--warn); border-color: #f2dc9e; }
.credentials .pw { display: inline-block; font-size: 1.1rem; margin: .3rem .4rem; padding: .2rem .6rem; background: #fff; color: var(--ink); user-select: all; }
.credentials .small { display: block; }

.btn { display: inline-block; font: inherit; padding: .5rem 1rem; border-radius: 6px; border: 1px solid var(--line); background: #fff; color: var(--ink); cursor: pointer; text-decoration: none; }
.btn:hover { border-color: #b8c3cf; }
.btn-primary { background: var(--blue); border-color: var(--blue); color: #fff; }
.btn-primary:hover { background: #1556b5; }
.btn-danger { background: var(--err); border-color: var(--err); color: #fff; }
.btn:disabled { opacity: .5; cursor: default; }
.linkbtn { background: none; border: 0; padding: 0; font: inherit; color: var(--blue); cursor: pointer; text-decoration: underline; }
.linkbtn.danger { color: var(--err); }
form.inline { display: inline; }

input, textarea, select { font: inherit; padding: .5rem .6rem; border: 1px solid #c7d0da; border-radius: 6px; width: 100%; background: #fff; color: var(--ink); }
input:focus, textarea:focus, select:focus { outline: 2px solid var(--lightblue); border-color: var(--blue); }
input[type=checkbox], input[type=radio] { width: auto; }
input[type=file] { border: 1px dashed #b8c3cf; padding: .8rem; }
label { display: block; font-weight: 600; font-size: .9rem; }
label input, label textarea, label select { margin-top: .3rem; font-weight: 400; }
label.check { font-weight: 400; display: flex; gap: .5rem; align-items: baseline; }
fieldset { border: 1px solid var(--line); border-radius: var(--radius); padding: .8rem 1rem; margin: 0; }
legend { font-weight: 700; color: var(--navy); padding: 0 .3rem; }
.stack > * + * { margin-top: 1rem; }
.row { display: flex; gap: .8rem; align-items: flex-end; flex-wrap: wrap; }
.row > label { flex: 1 1 200px; }
.row > label.narrow { flex: 0 0 120px; }
.inline-add { margin-top: 1rem; }
.checklist { max-height: 340px; overflow: auto; display: grid; gap: .35rem; margin-bottom: 1rem; }

.panel { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 1.2rem; }
.cols { display: grid; grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); gap: 1.2rem; align-items: start; }
@media (max-width: 860px) { .cols { grid-template-columns: 1fr; } }
.titlebar { display: flex; justify-content: space-between; align-items: center; gap: 1rem; flex-wrap: wrap; }
.titlebar h1 { margin-bottom: .3em; }
.crumbs { margin: 0 0 .3rem; font-size: .9rem; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.err { color: var(--err); }
.empty { background: var(--card); border: 1px dashed var(--line); border-radius: var(--radius); padding: 2rem; text-align: center; color: var(--muted); }

.auth-card { max-width: 420px; margin: 2rem auto; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 1.8rem; }

.table-wrap { overflow-x: auto; }
.tbl { width: 100%; border-collapse: collapse; background: var(--card); }
.panel .tbl { background: none; }
.tbl th, .tbl td { text-align: left; padding: .6rem .7rem; border-bottom: 1px solid var(--line); vertical-align: top; }
.tbl th { font-size: .8rem; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); background: #fafbfc; }
.tbl tr.dim td { opacity: .55; }
.tbl .actions { white-space: nowrap; }
.tbl .actions form { display: inline; margin-right: .6rem; }
.matrix th:not(:first-child) { min-width: 140px; }

.badge { display: inline-block; font-size: .78rem; font-weight: 600; padding: .15rem .55rem; border-radius: 999px; }
.badge-done { background: var(--ok-bg); color: var(--ok); }
.badge-progress { background: var(--lightblue); color: var(--blue); }
.badge-updated { background: var(--warn-bg); color: var(--warn); }
.badge-new { background: #eef1f4; color: var(--muted); }

.wrap.wide { max-width: 1600px; }
textarea { min-height: 5.5rem; resize: vertical; }

/* Summary strip */
.stats { display: flex; gap: .7rem; flex-wrap: wrap; margin: 0 0 1rem; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: .55rem .9rem; min-width: 120px; }
.stat b { display: block; font-size: 1.35rem; color: var(--navy); line-height: 1.2; }
.stat span { font-size: .8rem; color: var(--muted); }
.stat.alert b { color: var(--err); }
.stat.amber b { color: var(--warn); }

/* Filters and quick add */
.toolbar { display: flex; gap: .7rem; align-items: flex-end; flex-wrap: wrap; margin-bottom: 1rem; }
.toolbar label { flex: 0 1 190px; }
.toolbar label.grow { flex: 1 1 220px; }
.toolbar label.check { flex: 0 0 auto; padding-bottom: .55rem; }
.quickadd { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: .8rem 1rem; margin-bottom: 1rem; }
.quickadd summary { cursor: pointer; font-weight: 600; color: var(--navy); }
.quickadd form { margin-top: .8rem; }

/* Board */
.board { display: grid; grid-template-columns: repeat(5, minmax(230px, 1fr)); gap: .8rem; overflow-x: auto; padding-bottom: .5rem; align-items: start; }
.col { background: #e9edf2; border-radius: var(--radius); padding: .6rem; min-height: 200px; display: flex; flex-direction: column; }
.col-head { display: flex; justify-content: space-between; align-items: center; padding: .1rem .3rem .6rem; font-weight: 700; color: var(--navy); font-size: .92rem; border-bottom: 2px solid var(--gold); margin-bottom: .6rem; }
.col-head .count { background: #fff; color: var(--muted); font-size: .78rem; border-radius: 999px; padding: .05rem .5rem; font-weight: 600; }
.col-body { display: flex; flex-direction: column; gap: .55rem; flex: 1; min-height: 120px; border-radius: 6px; transition: background .1s; }
.col-body.over { background: rgba(26,101,211,.08); outline: 2px dashed rgba(26,101,211,.35); }

.tcard { background: var(--card); border: 1px solid var(--line); border-left: 4px solid var(--line); border-radius: 6px; padding: .6rem .7rem; cursor: grab; position: relative; }
.tcard:hover { box-shadow: 0 4px 12px rgba(26,53,79,.12); }
.tcard.dragging { opacity: .45; }
.tcard.prio-high { border-left-color: var(--gold); }
.tcard.prio-urgent { border-left-color: #e07b00; }
.tcard.nc-potential { border-left-color: #e0a100; background: #fffaf0; box-shadow: inset 0 0 0 1px #f2dc9e; }
.tcard.nc-confirmed { border-left-color: var(--err); background: #fff6f5; box-shadow: inset 0 0 0 1px #f1c2bc; }
.tcard .t-title { font-weight: 600; color: var(--ink); text-decoration: none; display: block; margin: .15rem 0 .35rem; line-height: 1.3; }
.tcard .t-title:hover { color: var(--blue); }
.tcard .t-tags { display: flex; gap: .3rem; flex-wrap: wrap; }
.tcard .t-meta { display: flex; justify-content: space-between; align-items: center; gap: .4rem; margin-top: .45rem; font-size: .8rem; color: var(--muted); }
.tcard .meter { width: 100%; margin: .45rem 0 0; height: 6px; }
.tcard .meter div { background: var(--blue); }
.tcard.done .meter div { background: var(--ok); }
.tcard .pct { font-size: .75rem; color: var(--muted); }
.avatar { display: inline-grid; place-items: center; width: 24px; height: 24px; border-radius: 50%; background: var(--navy); color: #fff; font-size: .7rem; font-weight: 700; flex: 0 0 auto; }
.avatar.none { background: #cfd6de; color: var(--muted); }
.who-line { display: flex; align-items: center; gap: .35rem; min-width: 0; }
.who-line span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.due-overdue { color: var(--err); font-weight: 700; }
.due-soon { color: var(--warn); font-weight: 600; }

.badge-nc { background: var(--err); color: #fff; }
.badge-pnc { background: #ffe7a8; color: #6b4500; }
.badge-sev { background: var(--err-bg); color: var(--err); }
.badge-warn { background: var(--warn-bg); color: var(--warn); }
.badge-cmp { background: var(--lightblue); color: var(--blue); }
.badge-prio { background: #eef1f4; color: var(--slate); }
.badge-err { background: var(--err-bg); color: var(--err); }

/* Task form */
.ncbox { border-color: #f1c2bc; background: #fffaf9; }
.ncbox legend { color: var(--err); }
.ncbox.potential { border-color: #f2dc9e; background: #fffcf3; }
.ncbox.potential legend { color: var(--warn); }
.range-row { display: flex; align-items: center; gap: .8rem; }
.range-row input[type=range] { flex: 1; padding: 0; border: 0; }
.range-row output { min-width: 3.2rem; font-weight: 700; color: var(--navy); }
.log { list-style: none; padding: 0; margin: 0; font-size: .85rem; }
.log li { padding: .4rem 0; border-bottom: 1px solid var(--line); }
.log li:last-child { border-bottom: 0; }
.formbar { display: flex; gap: .7rem; align-items: center; flex-wrap: wrap; }
.formbar .spacer { flex: 1; }
.tbl tr.overdue td:first-child { box-shadow: inset 3px 0 0 var(--err); }
.status-new { background: var(--lightblue); color: var(--blue); }
.status-investigating { background: var(--warn-bg); color: var(--warn); }
.status-responded { background: #ede7fb; color: #5b3fa8; }
.status-closed { background: var(--ok-bg); color: var(--ok); }

@media (max-width: 600px) {
  .userbox { margin-left: 0; width: 100%; }
  h1 { font-size: 1.35rem; }
  .board { grid-template-columns: repeat(5, 82vw); }
}
a.stat { text-decoration: none; color: inherit; }
a.stat:hover { border-color: #b8c3cf; }
.tbl td:first-child { white-space: nowrap; }
