:root {
  --bg: #f4f5f7;
  --panel: #fff;
  --line: #dcdfe4;
  --line2: #eaecef;
  --head: #fafbfc;
  --text: #1d2125;
  --muted: #5f6b77;
  --faint: #8a95a1;
  --accent: #1f5fbf;
  --accent-h: #184d9c;
  --accent-bg: #e8f0fb;
  --side: #1e2328;
  --side-t: #c3cad2;
  --side-h: #2a3036;
  --side-on: #313a44;
  --ok: #1d7a46;   --ok-bg: #e3f3e9;
  --warn: #8f5500; --warn-bg: #fcf0d9;
  --bad: #b42318;  --bad-bg: #fbe7e5;
  --info: #1f5fbf; --info-bg: #e8f0fb;
  --pri: #5436b8;  --pri-bg: #eee9fb;
  --neu: #4b5563;  --neu-bg: #eceef1;
  --c-previsit: #1f5fbf;
  --c-works: #c46a00;
  --c-reception: #1d7a46;
  --r: 4px;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { font-size: 13px; }
body {
  margin: 0; background: var(--bg); color: var(--text); line-height: 1.4;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { margin: 0; }

/* ---------- Shell ---------- */
.app { display: grid; grid-template-columns: 200px minmax(0, 1fr); min-height: 100vh; }
.side { background: var(--side); color: var(--side-t); position: sticky; top: 0; height: 100vh; overflow-y: auto; padding-bottom: 16px; }
.brand { padding: 11px 14px; color: #fff; font-weight: 600; font-size: 14px; border-bottom: 1px solid #2d343b; letter-spacing: .2px; }
.brand small { display: block; color: var(--side-t); font-weight: 400; font-size: 11px; letter-spacing: 0; }
.nav-h { padding: 12px 14px 3px; font-size: 10.5px; text-transform: uppercase; letter-spacing: .6px; color: #7f8a95; }
.nav a { display: flex; align-items: center; justify-content: space-between; gap: 6px; padding: 4px 14px; color: var(--side-t); font-size: 12.5px; }
.nav a:hover { background: var(--side-h); color: #fff; text-decoration: none; }
.nav a.on { background: var(--side-on); color: #fff; box-shadow: inset 3px 0 0 var(--accent); }
.nav .cnt { font-size: 10.5px; background: #3a434d; color: #fff; border-radius: 8px; padding: 0 6px; line-height: 16px; }
.nav .cnt.alert { background: var(--bad); }

.main { min-width: 0; display: flex; flex-direction: column; }
.top { height: 40px; background: var(--panel); border-bottom: 1px solid var(--line); display: flex; align-items: center; gap: 12px; padding: 0 14px; position: sticky; top: 0; z-index: 5; }
.top .search { flex: 1; max-width: 380px; }
.top .search input { width: 100%; }
.top .sp { flex: 1; }
.top form { margin: 0; }
.langs { display: inline-flex; gap: 2px; }
.langs a { font-size: 11px; color: var(--muted); padding: 1px 5px; border-radius: 3px; }
.langs a.on { background: var(--neu-bg); color: var(--text); font-weight: 600; }
.langs a:hover { text-decoration: none; background: var(--line2); }
.bell { font-size: 12px; color: var(--muted); }
.bell b { background: var(--bad); color: #fff; border-radius: 8px; padding: 0 5px; font-size: 10.5px; margin-left: 3px; font-weight: 600; }
.who { font-size: 12px; color: var(--muted); }
.content { padding: 12px 16px 32px; }

/* ---------- Page header ---------- */
.ph { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; flex-wrap: wrap; min-height: 26px; }
.ph h1 { font-size: 15px; font-weight: 600; }
.ph .sub { color: var(--muted); font-size: 12px; }
.ph .act { margin-left: auto; display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }

/* ---------- Cards ---------- */
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--r); margin-bottom: 12px; }
.card > .hd { display: flex; align-items: center; gap: 8px; padding: 6px 10px; border-bottom: 1px solid var(--line2); font-weight: 600; font-size: 12.5px; min-height: 34px; }
.card > .hd .act { margin-left: auto; display: flex; gap: 6px; align-items: center; font-weight: 400; }
.card > .bd, .card > form > .bd { padding: 10px; }
.card > .bd.np { padding: 0; }
.card > .ft { padding: 6px 10px; border-top: 1px solid var(--line2); font-size: 12px; color: var(--muted); }

/* ---------- Tables ---------- */
.tw { overflow-x: auto; }
table.t { width: 100%; border-collapse: collapse; font-size: 12.5px; }
.t th { text-align: left; font-weight: 600; color: var(--muted); font-size: 11.5px; background: var(--head); border-bottom: 1px solid var(--line); padding: 5px 8px; white-space: nowrap; }
.t th a { color: var(--muted); }
.t th a.on { color: var(--text); }
.t td { border-bottom: 1px solid var(--line2); padding: 5px 8px; vertical-align: top; }
.t tr:last-child td { border-bottom: 0; }
.t tbody tr:hover td { background: #f8fafc; }
.t .num { text-align: right; font-variant-numeric: tabular-nums; }
.t td.act { text-align: right; white-space: nowrap; }
.t tr.dim td { color: var(--faint); }
.t tr.unread td { font-weight: 600; }
.nowrap { white-space: nowrap; }
.muted { color: var(--muted); }
.faint { color: var(--faint); }
.small { font-size: 11.5px; }
.overdue { color: var(--bad); font-weight: 600; }
.strong { font-weight: 600; }
.clip { max-width: 320px; overflow: hidden; text-overflow: ellipsis; }

/* ---------- Badges ---------- */
.badge { display: inline-block; padding: 0 6px; border-radius: 3px; font-size: 11px; font-weight: 500; white-space: nowrap; line-height: 17px; }
.b-neu { background: var(--neu-bg); color: var(--neu); }
.b-info { background: var(--info-bg); color: var(--info); }
.b-pri { background: var(--pri-bg); color: var(--pri); }
.b-ok { background: var(--ok-bg); color: var(--ok); }
.b-warn { background: var(--warn-bg); color: var(--warn); }
.b-bad { background: var(--bad-bg); color: var(--bad); }
.prio { font-size: 11px; white-space: nowrap; }
.prio.p1 { color: var(--bad); font-weight: 600; }
.prio.p2 { color: var(--muted); }
.prio.p3 { color: var(--faint); }
.tp { display: inline-block; width: 8px; height: 8px; border-radius: 2px; margin-right: 5px; }
.tp-previsit { background: var(--c-previsit); }
.tp-works { background: var(--c-works); }
.tp-reception { background: var(--c-reception); }

/* ---------- Forms ---------- */
input, select, textarea {
  font: inherit; font-size: 12.5px; color: var(--text); background: #fff;
  border: 1px solid var(--line); border-radius: var(--r); padding: 3px 7px; height: 26px;
}
textarea { height: auto; min-height: 50px; resize: vertical; padding: 5px 7px; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-bg); }
input[type=checkbox] { height: auto; margin: 0; }
input[readonly] { background: var(--head); color: var(--muted); }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 4px; height: 26px; padding: 0 10px;
  font: inherit; font-size: 12px; color: var(--text); background: #fff; border: 1px solid var(--line);
  border-radius: var(--r); cursor: pointer; white-space: nowrap;
}
.btn:hover { background: #f2f3f5; text-decoration: none; }
.btn.pri { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.pri:hover { background: var(--accent-h); }
.btn.danger { color: var(--bad); border-color: #efc6c2; }
.btn.danger:hover { background: var(--bad-bg); }
.btn.sm { height: 22px; padding: 0 7px; font-size: 11.5px; }
.btn.block { width: 100%; }
form.inline { display: inline; margin: 0; }

.filters { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; padding: 7px 10px; border-bottom: 1px solid var(--line2); }
.filters select, .filters input[type=text], .filters input[type=search] { max-width: 165px; }
.filters input[type=date] { width: 128px; }
.filters .chk { font-size: 12px; color: var(--muted); }
.filters .reset { font-size: 12px; margin-left: 2px; }

.fg { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px 12px; }
.fg.c3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.fg.c4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.fg .full { grid-column: 1 / -1; }
.fg .span2 { grid-column: span 2; }
.f label { display: block; font-size: 11.5px; color: var(--muted); margin-bottom: 2px; }
.f input:not([type=checkbox]), .f select, .f textarea { width: 100%; }
.f label.req::after { content: " *"; color: var(--bad); }
.f .hint { font-size: 11px; color: var(--faint); margin-top: 2px; }
.chk { display: inline-flex; align-items: center; gap: 6px; font-size: 12.5px; }
.f .chk { margin-top: 20px; }
.sec { grid-column: 1 / -1; font-size: 10.5px; text-transform: uppercase; letter-spacing: .6px; color: var(--faint); margin-top: 6px; padding-bottom: 3px; border-bottom: 1px solid var(--line2); }

/* ---------- Modals ---------- */
dialog.modal { padding: 0; border: 1px solid var(--line); border-radius: 6px; width: min(720px, calc(100vw - 32px)); max-height: calc(100vh - 40px); box-shadow: 0 12px 40px rgba(0, 0, 0, .22); color: var(--text); }
dialog.modal.wide { width: min(940px, calc(100vw - 32px)); }
dialog.modal.narrow { width: min(420px, calc(100vw - 32px)); }
dialog.modal::backdrop { background: rgba(20, 24, 28, .45); }
.modal form, .modal .mw { display: flex; flex-direction: column; max-height: calc(100vh - 42px); margin: 0; }
.m-hd { display: flex; align-items: center; gap: 8px; padding: 8px 12px; border-bottom: 1px solid var(--line2); font-weight: 600; font-size: 13px; }
.m-hd .x { margin-left: auto; border: 0; background: none; font-size: 16px; line-height: 1; color: var(--faint); cursor: pointer; padding: 2px 4px; }
.m-hd .x:hover { color: var(--text); }
.m-bd { padding: 12px; overflow-y: auto; }
.m-ft { display: flex; justify-content: flex-end; align-items: center; gap: 6px; padding: 8px 12px; border-top: 1px solid var(--line2); background: var(--head); }
.m-ft .left { margin-right: auto; }

/* ---------- Flash ---------- */
.flash { padding: 6px 10px; border-radius: var(--r); margin-bottom: 10px; font-size: 12.5px; border: 1px solid; }
.flash.ok { background: var(--ok-bg); color: var(--ok); border-color: #bfe3cc; }
.flash.err { background: var(--bad-bg); color: var(--bad); border-color: #f1c4bf; }
.flash.info { background: var(--info-bg); color: var(--info); border-color: #c6d8f2; }

/* ---------- Housing record ---------- */
.grid2 { display: grid; grid-template-columns: 330px minmax(0, 1fr); gap: 12px; align-items: start; }
.kv { display: grid; grid-template-columns: 118px minmax(0, 1fr); gap: 3px 10px; font-size: 12.5px; margin: 0; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; overflow-wrap: anywhere; }
.kv.wide { grid-template-columns: 170px minmax(0, 1fr); }
.steps { display: flex; margin: 0 0 12px; padding: 0; list-style: none; background: var(--panel); border: 1px solid var(--line); border-radius: var(--r); overflow: hidden; }
.steps li { flex: 1; padding: 5px 8px; font-size: 11.5px; color: var(--faint); border-right: 1px solid var(--line2); min-width: 0; }
.steps li:last-child { border-right: 0; }
.steps li b { display: block; font-size: 10px; font-weight: 600; letter-spacing: .3px; }
.steps li span { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.steps li.done { color: var(--muted); background: #f5f7f9; }
.steps li.cur { color: #fff; background: var(--side); }
.steps li.cur.bad { background: var(--bad); }
.tabs { display: flex; flex-wrap: wrap; border-bottom: 1px solid var(--line); padding: 0 6px; background: var(--head); border-radius: var(--r) var(--r) 0 0; }
.tabs button { border: 0; background: none; padding: 8px 10px 7px; font: inherit; font-size: 12.5px; color: var(--muted); cursor: pointer; border-bottom: 2px solid transparent; margin-bottom: -1px; }
.tabs button:hover { color: var(--text); }
.tabs button.on { color: var(--text); border-bottom-color: var(--accent); font-weight: 600; }
.tabs .n { font-size: 10.5px; color: var(--faint); margin-left: 3px; font-weight: 400; }
.tab { display: none; }
.tab.on { display: block; }
.tab-hd { display: flex; align-items: center; gap: 8px; padding: 7px 10px; border-bottom: 1px solid var(--line2); }
.tab-hd .act { margin-left: auto; display: flex; gap: 6px; }
.rec { border-bottom: 1px solid var(--line2); padding: 10px; }
.rec:last-child { border-bottom: 0; }
.rec-hd { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 8px; }
.rec-hd .act { margin-left: auto; display: flex; gap: 6px; }
.rec .cols { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px 20px; align-items: start; }
.note { background: var(--head); border: 1px solid var(--line2); border-radius: var(--r); padding: 6px 8px; font-size: 12.5px; white-space: pre-wrap; }
.alert-line { background: var(--bad-bg); color: var(--bad); border: 1px solid #f1c4bf; border-radius: var(--r); padding: 6px 10px; margin-bottom: 10px; font-size: 12.5px; }

/* ---------- Dashboard ---------- */
.kpis { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 8px; margin-bottom: 12px; }
.kpi { background: var(--panel); border: 1px solid var(--line); border-radius: var(--r); padding: 7px 10px; }
.kpi .l { font-size: 11.5px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.kpi .v { font-size: 18px; font-weight: 600; font-variant-numeric: tabular-nums; margin-top: 1px; }
.kpi .s { font-size: 11px; color: var(--faint); }
.kpi.alert .v { color: var(--bad); }
.funnel td { padding: 4px 8px; }
.bar { height: 8px; background: var(--neu-bg); border-radius: 2px; overflow: hidden; min-width: 120px; }
.bar i { display: block; height: 100%; background: var(--accent); }
.bar i.bad { background: var(--bad); }
.bar i.ok { background: var(--ok); }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: var(--r); overflow: hidden; background: #fff; }
.seg a { padding: 2px 9px; font-size: 12px; color: var(--text); border-right: 1px solid var(--line); line-height: 20px; }
.seg a:last-child { border-right: 0; }
.seg a:hover { background: #f2f3f5; text-decoration: none; }
.seg a.on { background: var(--side); color: #fff; }

/* ---------- Agenda ---------- */
.cal { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); }
.cal .dh { font-size: 11.5px; color: var(--muted); padding: 5px 6px; background: var(--head); border-right: 1px solid var(--line2); border-bottom: 1px solid var(--line); font-weight: 600; }
.cal .dh.today { color: var(--accent); }
.cal .d { border-right: 1px solid var(--line2); border-bottom: 1px solid var(--line2); min-height: 96px; padding: 3px 4px; min-width: 0; }
.cal .dh:nth-child(7n), .cal .d:nth-child(7n) { border-right: 0; }
.cal .d.out { background: var(--head); }
.cal .d.we { background: #fbfbfc; }
.cal .dn { font-size: 11px; color: var(--muted); display: inline-block; margin-bottom: 2px; padding: 0 3px; }
.cal .d.today .dn { background: var(--accent); color: #fff; border-radius: 3px; }
.cal.week .d { min-height: 440px; }
.ev { display: block; border-left: 3px solid var(--c-previsit); background: #f1f5fb; padding: 2px 5px; margin-bottom: 3px; border-radius: 2px; font-size: 11.5px; color: var(--text); line-height: 1.3; overflow: hidden; }
.ev:hover { text-decoration: none; background: #e6edf8; }
.ev.works { border-left-color: var(--c-works); background: #fbf4ec; }
.ev.works:hover { background: #f6eadb; }
.ev.reception { border-left-color: var(--c-reception); background: #edf6f0; }
.ev.reception:hover { background: #deefe4; }
.ev.cancelled { opacity: .55; text-decoration: line-through; }
.ev .tm { font-weight: 600; }
.ev .un { color: var(--warn); font-weight: 600; }
.ev .l2 { display: block; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.more { font-size: 11px; color: var(--muted); padding-left: 4px; }
.lanes { table-layout: fixed; }
.lanes td { min-width: 110px; }
.lanes th:first-child, .lanes td:first-child { width: 150px; }
.legend { display: flex; gap: 12px; font-size: 11.5px; color: var(--muted); align-items: center; }

/* ---------- Misc ---------- */
.pager { display: flex; gap: 4px; align-items: center; padding: 7px 10px; font-size: 12px; color: var(--muted); border-top: 1px solid var(--line2); }
.pager .sp { flex: 1; }
.empty { padding: 20px; text-align: center; color: var(--faint); font-size: 12.5px; }
.login { min-height: 100vh; display: flex; align-items: center; justify-content: center; background: var(--side); padding: 16px; }
.login .box { width: 330px; background: var(--panel); border-radius: 6px; padding: 18px 20px 20px; }
.login .box .hd { display: flex; align-items: baseline; margin-bottom: 14px; }
.login .box .hd strong { font-size: 16px; }
.login .box .hd .langs { margin-left: auto; }
.login .f { margin-bottom: 10px; }
.stack > * + * { margin-top: 10px; }
.cal-row { display: flex; gap: 6px; align-items: flex-end; margin: 0; }
.cal-row .f { flex: 1; }
.cal-row > input { flex: 1; }

@media (max-width: 1100px) {
  .grid2 { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 800px) {
  .app { grid-template-columns: minmax(0, 1fr); }
  .side { position: static; height: auto; }
  .fg, .fg.c3, .fg.c4, .rec .cols { grid-template-columns: minmax(0, 1fr); }
  .fg .span2 { grid-column: auto; }
  .top .who { display: none; }
}
