/* Kimatsu Ops — operational UI. No external fonts/CDNs (strict CSP). */
:root {
  --ink: #17202b; --ink-2: #3c4856; --muted: #6b7684; --line: #dfe3e8; --line-2: #eef1f4;
  --bg: #f4f5f7; --card: #ffffff; --side: #1b2430; --side-ink: #c9d1db; --side-hi: #ffffff;
  --accent: #c8102e; --accent-ink: #fff; --accent-soft: #fdecee;
  --ok: #157347; --ok-soft: #e3f4ea; --bad: #b42318; --bad-soft: #fdecea; --warn: #9a6700; --warn-soft: #fff6d6;
  --info: #1d4ed8; --info-soft: #e8efff; --radius: 8px; --shadow: 0 1px 2px rgba(16,24,40,.06), 0 1px 3px rgba(16,24,40,.08);
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; font: 14px/1.5 var(--font); color: var(--ink); background: var(--bg); }
a { color: var(--info); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 22px; margin: 0 0 4px; letter-spacing: -.01em; }
h2 { font-size: 17px; margin: 0 0 12px; }
h3 { font-size: 14px; margin: 0 0 10px; text-transform: uppercase; letter-spacing: .04em; color: var(--ink-2); }
small, .muted { color: var(--muted); }
code, .mono { font-family: var(--mono); font-size: 12.5px; }
.sr, .skip { position: absolute; left: -9999px; }
.skip:focus { left: 8px; top: 8px; background: #fff; padding: 6px 10px; z-index: 99; }

/* Top bar */
.topbar { position: sticky; top: 0; z-index: 30; display: flex; align-items: center; gap: 14px; height: 56px; padding: 0 16px; background: var(--side); color: #fff; }
.brand { display: flex; align-items: center; gap: 10px; color: #fff; font-size: 16px; }
.brand:hover { text-decoration: none; }
.brand-mark { display: grid; place-items: center; width: 30px; height: 30px; border-radius: 7px; background: var(--accent); font-weight: 800; }
.brand-logo { display: grid; place-items: center; background: #fff; border-radius: 6px; padding: 3px 8px; height: 40px; }
.brand-logo img { display: block; height: 34px; width: auto; }
.brand-text { font-weight: 700; letter-spacing: .04em; text-transform: uppercase; font-size: 13px; color: #cbd5e1; }
.topsearch { flex: 1; max-width: 520px; }
.topsearch input { width: 100%; height: 34px; border-radius: 6px; border: 1px solid #364254; background: #263140; color: #fff; padding: 0 12px; }
.topsearch input::placeholder { color: #94a3b8; }
.topright { margin-left: auto; display: flex; align-items: center; gap: 14px; }
.bell { position: relative; color: #fff; font-size: 17px; }
.bell .count { position: absolute; top: -6px; right: -10px; background: var(--accent); color: #fff; border-radius: 10px; font-size: 11px; padding: 0 5px; font-weight: 700; }
.usermenu { position: relative; }
.usermenu summary { cursor: pointer; list-style: none; color: #e2e8f0; }
.usermenu summary::-webkit-details-marker { display: none; }
.usermenu .menu { position: absolute; right: 0; top: 30px; background: #fff; border-radius: var(--radius); box-shadow: 0 8px 24px rgba(0,0,0,.18); min-width: 220px; padding: 6px; }
.usermenu .menu a, .usermenu .menu button { display: block; width: 100%; text-align: left; padding: 8px 10px; color: var(--ink); background: none; border: 0; font: inherit; cursor: pointer; border-radius: 6px; }
.usermenu .menu a:hover, .usermenu .menu button:hover { background: var(--line-2); text-decoration: none; }
.nav-toggle { display: none; background: none; border: 0; color: #fff; font-size: 20px; cursor: pointer; }

/* Shell */
.shell { display: grid; grid-template-columns: 236px 1fr; min-height: calc(100vh - 56px); }
.sidebar { background: var(--side); color: var(--side-ink); padding: 8px 10px 24px; overflow-y: auto; position: sticky; top: 56px; height: calc(100vh - 56px); }
.navgroup { margin: 10px 0 14px; }
.navgroup h4 { margin: 0 0 4px 8px; font-size: 10.5px; letter-spacing: .09em; text-transform: uppercase; color: #7e8b9b; }
.navgroup a { display: block; padding: 6px 10px; border-radius: 6px; color: var(--side-ink); font-size: 13.5px; }
.navgroup a:hover { background: #263140; color: #fff; text-decoration: none; }
.navgroup a.active { background: var(--accent); color: #fff; }
.ver { font-size: 11px; color: #64748b; margin: 18px 10px 0; }
.main { padding: 20px 24px 60px; min-width: 0; }
.envbar { background: repeating-linear-gradient(45deg, #fff6d6, #fff6d6 10px, #fdeeb7 10px, #fdeeb7 20px); border: 1px solid #f0d78c; color: #6b4e00; padding: 6px 12px; border-radius: 6px; margin-bottom: 12px; font-weight: 600; font-size: 12px; }

/* Page header */
.pagehead { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 12px; justify-content: space-between; margin-bottom: 16px; }
.pagehead .sub { color: var(--muted); }
.actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }

/* Cards & grids */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; margin-bottom: 16px; min-width: 0; }
.grid { display: grid; gap: 16px; }
.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(170px, 1fr)); gap: 12px; margin-bottom: 16px; }
.kpi { background: var(--card); border: 1px solid var(--line); border-left: 4px solid var(--line); border-radius: var(--radius); padding: 12px 14px; }
.kpi .v { font-size: 22px; font-weight: 700; font-variant-numeric: tabular-nums; }
.kpi .l { font-size: 12px; color: var(--muted); }
.kpi .lim { font-size: 11px; color: var(--warn); margin-top: 4px; }
.kpi.ok { border-left-color: var(--ok); } .kpi.bad { border-left-color: var(--bad); } .kpi.warn { border-left-color: #e0a800; }
.kpi a { color: inherit; }
.section-title { display: flex; justify-content: space-between; align-items: center; margin: 22px 0 10px; }
.section-title h2 { margin: 0; }

/* Key-value */
.kv { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 10px 20px; margin: 0; }
.kv div { min-width: 0; }
.kv dt { font-size: 11.5px; color: var(--muted); text-transform: uppercase; letter-spacing: .03em; }
.kv dd { margin: 2px 0 0; overflow-wrap: anywhere; }

/* Tables */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table.data { width: 100%; border-collapse: collapse; font-size: 13px; }
table.data th { text-align: left; font-weight: 600; color: var(--ink-2); background: #f8f9fb; border-bottom: 1px solid var(--line); padding: 8px 10px; white-space: nowrap; position: sticky; top: 0; }
table.data th a { color: inherit; }
table.data td { border-bottom: 1px solid var(--line-2); padding: 8px 10px; vertical-align: top; }
table.data tr:hover td { background: #fbfcfd; }
table.data td.num, table.data th.num { text-align: right; font-variant-numeric: tabular-nums; }
table.data tr.row-bad td { background: var(--bad-soft); }
table.data tr.row-warn td { background: var(--warn-soft); }
table.data tr.superseded td { color: var(--muted); text-decoration: line-through; }
table.grid-edit input, table.grid-edit select { width: 100%; min-width: 70px; }
.empty { color: var(--muted); font-style: italic; margin: 6px 0; }

/* Badges */
.badge { display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: 11.5px; font-weight: 600; white-space: nowrap; border: 1px solid transparent; }
.badge-ok { background: var(--ok-soft); color: var(--ok); border-color: #b9e2c9; }
.badge-bad { background: var(--bad-soft); color: var(--bad); border-color: #f5c2bd; }
.badge-warn { background: var(--warn-soft); color: var(--warn); border-color: #f1dc94; }
.badge-info { background: var(--info-soft); color: var(--info); border-color: #c7d6fe; }
.badge-muted { background: var(--line-2); color: var(--ink-2); border-color: var(--line); }
.yes { color: var(--ok); font-weight: 600; } .no { color: var(--muted); }
progress { width: 70px; height: 8px; vertical-align: middle; accent-color: var(--accent); }

/* Gates */
.gates { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 8px; }
.gate { border: 1px solid var(--line); border-radius: 7px; padding: 8px 10px; background: #fff; }
.gate b { display: block; font-size: 12.5px; }
.gate small { display: block; }
.gate.done { border-color: #b9e2c9; background: var(--ok-soft); }
.gate.blocked { border-color: #f5c2bd; background: var(--bad-soft); }
.gate.na { opacity: .6; }
.checklist { list-style: none; padding: 0; margin: 0; }
.checklist li { padding: 6px 0; border-bottom: 1px solid var(--line-2); display: flex; gap: 8px; }
.checklist .ic { width: 20px; flex: none; font-weight: 700; }
.checklist .ok .ic { color: var(--ok); } .checklist .bad .ic { color: var(--bad); }

/* Forms */
form.inline { display: inline; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 12px 18px; }
.field label { display: block; font-size: 12.5px; font-weight: 600; color: var(--ink-2); margin-bottom: 4px; }
.field-textarea { grid-column: 1 / -1; }
.field-bool { align-self: end; }
.field-bool label { font-weight: 500; }
input[type=text], input[type=email], input[type=password], input[type=number], input[type=date], input[type=search], select, textarea {
  width: 100%; min-height: 36px; padding: 6px 10px; border: 1px solid #cbd2da; border-radius: 6px; background: #fff; font: inherit; color: var(--ink);
}
textarea { min-height: 70px; resize: vertical; }
input:focus, select:focus, textarea:focus, button:focus-visible, a:focus-visible { outline: 2px solid #f59e0b; outline-offset: 1px; }
input:disabled, select:disabled, textarea:disabled { background: #f3f4f6; color: var(--ink-2); }
.req { color: var(--bad); }
.check { display: flex; align-items: center; gap: 8px; cursor: pointer; }
.btn { display: inline-flex; align-items: center; gap: 6px; min-height: 34px; padding: 6px 14px; border-radius: 6px; border: 1px solid #c4cbd4; background: #fff; color: var(--ink); font: inherit; font-weight: 600; cursor: pointer; white-space: nowrap; }
.btn:hover { background: #f6f7f9; text-decoration: none; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: #9e0c24; }
.btn-danger { color: var(--bad); border-color: #f0b8b2; }
.btn-danger:hover { background: var(--bad-soft); }
.btn-ok { background: var(--ok); border-color: var(--ok); color: #fff; }
.btn-sm { min-height: 28px; padding: 2px 10px; font-size: 12.5px; }
.formbar { display: flex; gap: 8px; margin-top: 16px; flex-wrap: wrap; }
.filters { display: flex; flex-wrap: wrap; gap: 8px; align-items: flex-end; margin-bottom: 12px; }
.filters .field { min-width: 150px; }
.filters .field label { font-size: 11.5px; }
.pager { display: flex; gap: 6px; align-items: center; margin-top: 12px; flex-wrap: wrap; }
.pager a, .pager span { padding: 4px 10px; border: 1px solid var(--line); border-radius: 6px; background: #fff; }
.pager .cur { background: var(--ink); color: #fff; border-color: var(--ink); }
.tabs { display: flex; gap: 4px; flex-wrap: wrap; margin-bottom: 12px; }
.tabs a { padding: 6px 12px; border-radius: 999px; border: 1px solid var(--line); background: #fff; color: var(--ink-2); font-weight: 600; font-size: 12.5px; }
.tabs a.on { background: var(--ink); color: #fff; border-color: var(--ink); }

/* Flash & alerts */
.flash, .alert { padding: 10px 14px; border-radius: var(--radius); margin-bottom: 12px; border: 1px solid; }
.flash-success { background: var(--ok-soft); border-color: #b9e2c9; color: #0f5132; }
.flash-error, .alert-bad { background: var(--bad-soft); border-color: #f5c2bd; color: #7a1a12; }
.flash-info, .alert-info { background: var(--info-soft); border-color: #c7d6fe; color: #1e3a8a; }
.alert-warn { background: var(--warn-soft); border-color: #f1dc94; color: #6b4e00; }
.alert b { display: block; }
.big-warning { font-size: 15px; font-weight: 700; }

/* Calendar */
.cal { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 4px; }
.cal .dow { font-size: 11px; font-weight: 700; color: var(--muted); text-align: center; text-transform: uppercase; }
.cal .day { min-height: 92px; border: 1px solid var(--line); border-radius: 6px; padding: 5px 6px; background: #fff; font-size: 11.5px; overflow: hidden; }
.cal .day .d { font-weight: 700; font-size: 12.5px; }
.cal .day.off { background: repeating-linear-gradient(135deg, #f3f4f6, #f3f4f6 6px, #eceef1 6px, #eceef1 12px); color: var(--muted); }
.cal .day.over { border-color: var(--bad); box-shadow: inset 0 0 0 1px var(--bad); }
.cal .day.pad { visibility: hidden; }
.cal .day .hol { color: var(--bad); font-weight: 600; }
.cal .bar { height: 6px; border-radius: 3px; background: var(--line-2); margin: 4px 0; overflow: hidden; }
.cal .bar i { display: block; height: 100%; background: var(--accent); }
.u0 { width: 0; } .u10 { width: 10%; } .u20 { width: 20%; } .u30 { width: 30%; } .u40 { width: 40%; } .u50 { width: 50%; }
.u60 { width: 60%; } .u70 { width: 70%; } .u80 { width: 80%; } .u90 { width: 90%; } .u100 { width: 100%; }
.cal .bar i.over { background: var(--bad); }
.legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: 12px; color: var(--muted); margin-top: 8px; }

/* Misc */
.timeline { list-style: none; padding: 0; margin: 0; font-size: 12.5px; }
.timeline li { padding: 5px 0; border-bottom: 1px dashed var(--line); }
.timeline time { color: var(--muted); font-family: var(--mono); font-size: 11.5px; }
.files { list-style: none; padding: 0; margin: 0 0 10px; }
.files li { padding: 4px 0; }
.files li.file-obsolete a, .files li.file-superseded a { text-decoration: line-through; color: var(--muted); }
.upload { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.upload input[type=text] { max-width: 200px; }
.split { display: grid; grid-template-columns: minmax(0, 2fr) minmax(280px, 1fr); gap: 16px; }
.pill { display: inline-block; padding: 2px 8px; border-radius: 4px; background: var(--line-2); font-size: 12px; margin: 2px; }
.code-box { font-family: var(--mono); background: #0f172a; color: #e2e8f0; padding: 10px 12px; border-radius: 6px; overflow-wrap: anywhere; user-select: all; }
.perm-matrix th, .perm-matrix td { text-align: center; }
.perm-matrix td:first-child, .perm-matrix th:first-child { text-align: left; position: sticky; left: 0; background: #fff; }
.perm-matrix select { min-width: 74px; min-height: 28px; padding: 2px 4px; font-size: 12px; }
.perm-matrix .scope-all { background: var(--ok-soft); } .perm-matrix .scope-assigned { background: var(--info-soft); } .perm-matrix .scope-own { background: var(--warn-soft); }

/* Auth */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 20px; background: linear-gradient(160deg, #1b2430 0%, #2b3646 60%, #c8102e 160%); }
.auth .card { width: 100%; max-width: 400px; padding: 28px; }
.auth h1 { margin-bottom: 14px; }
.auth .brand { color: var(--ink); margin-bottom: 18px; }
.auth .field { margin-bottom: 12px; }
.auth .btn { width: 100%; justify-content: center; }

/* Print */
.print-page { max-width: 1000px; margin: 0 auto; padding: 24px; background: #fff; }
.print-page table { width: 100%; border-collapse: collapse; font-size: 12px; margin-bottom: 14px; }
.print-page th, .print-page td { border: 1px solid #999; padding: 4px 6px; text-align: left; vertical-align: top; }
.print-page th { background: #eee; }
.print-page h1 { font-size: 18px; text-align: center; }
.print-page .sig { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 24px; margin-top: 40px; }
.print-page .sig div { border-top: 1px solid #333; padding-top: 4px; font-size: 12px; }
.print-page .fail { color: #b42318; font-weight: 700; }
.print-page .stamp { border: 2px solid; display: inline-block; padding: 4px 10px; font-weight: 800; letter-spacing: .05em; }
.noprint { margin-bottom: 12px; }
@media print { .noprint, .topbar, .sidebar { display: none !important; } body { background: #fff; } .print-page { padding: 0; } }

/* Responsive */
@media (max-width: 1100px) { .split { grid-template-columns: 1fr; } .g3 { grid-template-columns: 1fr 1fr; } }
@media (max-width: 860px) {
  .nav-toggle { display: block; }
  .shell { grid-template-columns: 1fr; }
  .sidebar { position: fixed; left: 0; top: 56px; width: 270px; transform: translateX(-100%); transition: transform .2s; z-index: 40; box-shadow: 4px 0 16px rgba(0,0,0,.3); }
  body.nav-open .sidebar { transform: none; }
  .main { padding: 14px 12px 50px; }
  .topsearch { display: none; }
  .brand-text { display: none; }
  .g2, .g3 { grid-template-columns: 1fr; }
  .cal { grid-template-columns: 1fr; }
  .cal .dow, .cal .day.pad { display: none; }
  .cal .day { min-height: 0; }
  table.data.stack thead { display: none; }
  table.data.stack tr { display: block; border: 1px solid var(--line); border-radius: 8px; margin-bottom: 8px; background: #fff; }
  table.data.stack td { display: flex; justify-content: space-between; gap: 12px; border-bottom: 1px solid var(--line-2); }
  table.data.stack td::before { content: attr(data-label); font-weight: 600; color: var(--muted); font-size: 12px; flex: none; max-width: 45%; }
  table.data.stack td:last-child { border-bottom: 0; }
}
input.out { border-color: var(--bad); background: var(--bad-soft); }
.narrow { max-width: 520px; } .grow { flex: 1; }

.auth-logo { display: flex; flex-direction: column; align-items: center; gap: 6px; margin-bottom: 18px; }
.auth-logo img { width: 220px; max-width: 100%; height: auto; }
.auth-logo span { font-size: 12px; font-weight: 700; letter-spacing: .18em; text-transform: uppercase; color: var(--muted); }
.print-head { display: flex; align-items: center; justify-content: space-between; border-bottom: 2px solid #c8102e; padding-bottom: 8px; margin-bottom: 10px; }
.print-head img { height: 52px; width: auto; }
