:root {
  --brand: #1f4e79; --brand-2: #2e6da4; --brand-soft: #e8f0f8;
  --bg: #f4f6f9; --surface: #fff; --text: #1d2733; --muted: #5f6b7a; --line: #dfe4ea;
  --ok: #1e7b45; --ok-soft: #e3f4ea; --warn: #9a6200; --warn-soft: #fff4dc;
  --bad: #b3261e; --bad-soft: #fde8e6; --info: #2e6da4; --info-soft: #e6f0fa; --grey-soft: #eef0f3;
  --radius: 8px; --shadow: 0 1px 2px rgba(16,24,40,.06), 0 1px 3px rgba(16,24,40,.08);
  font-size: 15px;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { font-family: "Segoe UI", system-ui, -apple-system, Roboto, Arial, sans-serif; background: var(--bg); color: var(--text); line-height: 1.45; }
a { color: var(--brand-2); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.45rem; margin: 0 0 .25rem; }
h2 { font-size: 1.1rem; margin: 0 0 .75rem; }
h3 { font-size: 1rem; margin: 1rem 0 .5rem; }
p { margin: .3rem 0 .7rem; }
.boot { padding: 3rem; text-align: center; color: var(--muted); }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.nowrap { white-space: nowrap; }
.pre { white-space: pre-wrap; }
.right { text-align: right; }
.hidden { display: none !important; }
.mt { margin-top: 1rem; } .mb { margin-bottom: 1rem; }

/* ---------- layout ---------- */
.topbar { position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: .75rem; height: 56px; padding: 0 1rem; background: var(--brand); color: #fff; }
.topbar .brand { font-weight: 700; letter-spacing: .3px; white-space: nowrap; }
.topbar .inst { opacity: .8; font-size: .85rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar .spacer { flex: 1; }
.topbar form { margin: 0; }
.topbar input[type=search] { width: 220px; border: 0; border-radius: 6px; padding: .45rem .7rem; }
.icon-btn { background: transparent; border: 0; color: #fff; cursor: pointer; font-size: 1.2rem; padding: .35rem .5rem; border-radius: 6px; position: relative; }
.icon-btn:hover { background: rgba(255,255,255,.12); }
.bell-count { position: absolute; top: -2px; right: -4px; background: #e5484d; color: #fff; border-radius: 10px; font-size: .7rem; padding: 0 .35rem; font-weight: 700; }
.menu-btn { display: none; }
.layout { display: flex; min-height: calc(100vh - 56px); }
.sidenav { width: 232px; flex-shrink: 0; background: var(--surface); border-right: 1px solid var(--line); padding: .75rem 0; }
.sidenav a { display: block; padding: .55rem 1.1rem; color: var(--text); border-left: 3px solid transparent; }
.sidenav a:hover { background: var(--brand-soft); text-decoration: none; }
.sidenav a.active { border-left-color: var(--brand); background: var(--brand-soft); font-weight: 600; color: var(--brand); }
.sidenav .sec { font-size: .72rem; text-transform: uppercase; letter-spacing: .6px; color: var(--muted); padding: .9rem 1.1rem .3rem; }
.sidenav .who { padding: .2rem 1.1rem .8rem; border-bottom: 1px solid var(--line); margin-bottom: .4rem; }
.sidenav .who b { display: block; }
main { flex: 1; min-width: 0; padding: 1.25rem 1.5rem 3rem; }
.page-head { display: flex; flex-wrap: wrap; align-items: flex-end; gap: .75rem; justify-content: space-between; margin-bottom: 1rem; }
.page-head .actions { display: flex; flex-wrap: wrap; gap: .5rem; }

/* ---------- cards / grid ---------- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 1rem 1.1rem; margin-bottom: 1rem; min-width: 0; }
.card > h2:first-child { margin-top: 0; }
.grid { display: grid; gap: 1rem; }
.g2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.g3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.kpis { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: .75rem; margin-bottom: 1rem; }
.kpi { display: block; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: .8rem .9rem; box-shadow: var(--shadow); color: var(--text); }
.kpi:hover { text-decoration: none; border-color: var(--brand-2); }
.kpi .n { font-size: 1.7rem; font-weight: 700; line-height: 1.1; }
.kpi .l { font-size: .8rem; color: var(--muted); }
.kpi.bad .n { color: var(--bad); } .kpi.warn .n { color: var(--warn); } .kpi.ok .n { color: var(--ok); }
.kpi.bad { border-left: 4px solid var(--bad); } .kpi.warn { border-left: 4px solid #e5a000; } .kpi.ok { border-left: 4px solid var(--ok); }
.info-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: .6rem 1.2rem; }
.info-grid .k { font-size: .75rem; color: var(--muted); text-transform: uppercase; letter-spacing: .4px; }
.info-grid .v { font-weight: 500; overflow-wrap: anywhere; }
.note { background: var(--grey-soft); border-radius: 6px; padding: .6rem .8rem; font-size: .85rem; color: var(--muted); }
.callout { border-radius: 6px; padding: .7rem .9rem; margin-bottom: 1rem; }
.callout.warn { background: var(--warn-soft); border: 1px solid #f1d38f; }
.callout.bad { background: var(--bad-soft); border: 1px solid #f3b6b0; }
.callout.info { background: var(--info-soft); border: 1px solid #b9d3ee; }
.callout.ok { background: var(--ok-soft); border: 1px solid #a9dabb; }

/* ---------- tables ---------- */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table { border-collapse: collapse; width: 100%; font-size: .9rem; }
th, td { text-align: left; padding: .5rem .6rem; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: .75rem; text-transform: uppercase; letter-spacing: .4px; color: var(--muted); background: #fafbfc; white-space: nowrap; }
tr.row-link { cursor: pointer; }
tr.row-link:hover td { background: #f7fafd; }
tr.overdue td:first-child { box-shadow: inset 3px 0 0 var(--bad); }
td.num, th.num { text-align: right; }
td a.num-link { font-weight: 600; }
.empty { padding: 1rem; color: var(--muted); text-align: center; }

/* ---------- badges ---------- */
.badge { display: inline-block; padding: .1rem .5rem; border-radius: 999px; font-size: .75rem; font-weight: 600; white-space: nowrap; background: var(--grey-soft); color: var(--muted); }
.b-ok { background: var(--ok-soft); color: var(--ok); }
.b-warn { background: var(--warn-soft); color: var(--warn); }
.b-bad { background: var(--bad-soft); color: var(--bad); }
.b-info { background: var(--info-soft); color: var(--info); }
.b-dark { background: #3b4552; color: #fff; }
.p-Critical { background: var(--bad); color: #fff; }
.p-High { background: var(--warn-soft); color: var(--warn); }
.p-Normal { background: var(--info-soft); color: var(--info); }
.p-Low { background: var(--grey-soft); color: var(--muted); }
progress { width: 90px; height: 8px; vertical-align: middle; accent-color: var(--brand-2); }

/* ---------- forms ---------- */
label { display: block; font-size: .85rem; font-weight: 600; margin: .6rem 0 .25rem; }
label .req { color: var(--bad); }
input, select, textarea { width: 100%; font: inherit; padding: .5rem .6rem; border: 1px solid #c8d0da; border-radius: 6px; background: #fff; color: var(--text); }
input:focus, select:focus, textarea:focus { outline: 2px solid #9cc2ea; border-color: var(--brand-2); }
input[type=checkbox], input[type=radio] { width: auto; margin-right: .4rem; }
textarea { min-height: 70px; resize: vertical; }
.check { display: flex; align-items: center; font-weight: 400; margin: .3rem 0; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 1rem; }
.form-grid .full { grid-column: 1 / -1; }
.filters { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: .5rem .75rem; align-items: end; }
.filters label { margin-top: 0; font-weight: 500; font-size: .78rem; color: var(--muted); }
.hint { font-size: .78rem; color: var(--muted); margin-top: .2rem; }
.btn { display: inline-flex; align-items: center; gap: .35rem; font: inherit; font-weight: 600; font-size: .9rem; border-radius: 6px; padding: .5rem .9rem; cursor: pointer; border: 1px solid var(--brand); background: var(--brand); color: #fff; white-space: nowrap; }
.btn:hover { background: #183f63; text-decoration: none; }
.btn.secondary { background: #fff; color: var(--brand); }
.btn.secondary:hover { background: var(--brand-soft); }
.btn.danger { background: var(--bad); border-color: var(--bad); }
.btn.ok { background: var(--ok); border-color: var(--ok); }
.btn.small { padding: .25rem .55rem; font-size: .8rem; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn-row { display: flex; flex-wrap: wrap; gap: .5rem; margin-top: 1rem; }
.linkish { background: none; border: 0; color: var(--brand-2); cursor: pointer; padding: 0; font: inherit; }
.linkish:hover { text-decoration: underline; }

/* ---------- timeline ---------- */
.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { position: relative; padding: 0 0 1rem 1.3rem; border-left: 2px solid var(--line); margin-left: .4rem; }
.timeline li::before { content: ""; position: absolute; left: -6px; top: .3rem; width: 10px; height: 10px; border-radius: 50%; background: var(--brand-2); }
.timeline li.k-returned::before, .timeline li.k-info_requested::before { background: var(--bad); }
.timeline li.k-verified::before, .timeline li.k-closed::before { background: var(--ok); }
.timeline li.k-on_hold::before, .timeline li.k-change_requested::before { background: #e5a000; }
.timeline .meta { font-size: .8rem; color: var(--muted); }
.timeline .fields { margin-top: .25rem; font-size: .9rem; }
.timeline .fields div { margin-top: .15rem; }

/* ---------- modal & toast ---------- */
.modal-back { position: fixed; inset: 0; background: rgba(15,23,32,.45); z-index: 50; display: flex; align-items: flex-start; justify-content: center; padding: 4vh 1rem; overflow-y: auto; }
.modal { background: #fff; border-radius: 10px; width: 100%; max-width: 640px; box-shadow: 0 10px 40px rgba(0,0,0,.25); }
.modal.wide { max-width: 980px; }
.modal header { display: flex; justify-content: space-between; align-items: center; padding: .9rem 1.1rem; border-bottom: 1px solid var(--line); }
.modal header h2 { margin: 0; }
.modal .body { padding: .5rem 1.1rem 1.1rem; }
#toast-root { position: fixed; bottom: 1rem; right: 1rem; z-index: 60; display: flex; flex-direction: column; gap: .5rem; max-width: calc(100vw - 2rem); }
.toast { background: #1d2733; color: #fff; padding: .7rem 1rem; border-radius: 8px; box-shadow: var(--shadow); max-width: 420px; }
.toast.err { background: var(--bad); }

/* ---------- login ---------- */
.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 1rem; background: linear-gradient(135deg, #1f4e79, #2e6da4); }
.login { background: #fff; border-radius: 12px; padding: 2rem; width: 100%; max-width: 400px; box-shadow: 0 10px 40px rgba(0,0,0,.25); }
.login h1 { color: var(--brand); }
.err-text { color: var(--bad); font-size: .9rem; margin-top: .6rem; }

/* ---------- notifications ---------- */
.notif { display: flex; gap: .75rem; padding: .7rem .2rem; border-bottom: 1px solid var(--line); cursor: pointer; }
.notif.unread { background: #f5f9fe; }
.notif .dot { width: 9px; height: 9px; border-radius: 50%; margin-top: .45rem; flex-shrink: 0; background: var(--info); }
.notif .dot.critical { background: var(--bad); } .notif .dot.warning { background: #e5a000; }
.notif.read .dot { background: #c7ced6; }

.matrix td, .matrix th { text-align: center; padding: .35rem; }
.matrix td:first-child, .matrix th:first-child { text-align: left; }

/* ---------- responsive ---------- */
@media (max-width: 960px) {
  .menu-btn { display: inline-block; }
  .sidenav { position: fixed; top: 56px; bottom: 0; left: 0; z-index: 30; transform: translateX(-100%); transition: transform .2s; overflow-y: auto; box-shadow: var(--shadow); }
  .sidenav.open { transform: translateX(0); }
  .topbar .inst { display: none; }
  .topbar input[type=search] { width: 140px; }
  .g2, .g3 { grid-template-columns: 1fr; }
  main { padding: 1rem; }
}
@media (max-width: 600px) {
  .form-grid { grid-template-columns: 1fr; }
  .topbar form.search { display: none; }
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .modal-back { padding: 0; }
  .modal { border-radius: 0; min-height: 100vh; }
  table { font-size: .85rem; }
}
@media print {
  .topbar, .sidenav, .page-head .actions, .btn { display: none !important; }
  main { padding: 0; }
  .card { box-shadow: none; break-inside: avoid; }
}
.icon-btn.small { font-size: .85rem; border: 1px solid rgba(255,255,255,.35); }

/* Card-style tables on phones */
@media (max-width: 700px) {
  table.cards thead { display: none; }
  table.cards, table.cards tbody, table.cards tr, table.cards td { display: block; width: 100%; }
  table.cards tr { border: 1px solid var(--line); border-radius: 8px; margin-bottom: .6rem; padding: .35rem .2rem; background: #fff; }
  table.cards td { border: 0; padding: .2rem .6rem; }
  table.cards td[data-label]:not(:empty)::before { content: attr(data-label); display: block; font-size: .68rem; text-transform: uppercase; letter-spacing: .4px; color: var(--muted); }
  table.cards td:empty { display: none; }
  tr.overdue td:first-child { box-shadow: none; }
  table.cards tr.overdue { border-left: 4px solid var(--bad); }
}
