:root {
  --bg: #f4f6f9; --card: #fff; --text: #1d2433; --muted: #6b7385; --line: #e2e6ee;
  --brand: #1f5fbf; --brand-dark: #174a96; --top: #14213d; --good: #1d8a4e; --warn: #b7791f; --bad: #c53030;
  --radius: 8px;
}
* { box-sizing: border-box; }
body { margin: 0; font: 14px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; background: var(--bg); color: var(--text); }
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
h2 { margin: 0 0 .6rem; font-size: 1.35rem; }
h3 { margin: 0 0 .6rem; font-size: 1.05rem; }
code { background: #eef1f6; padding: 2px 5px; border-radius: 4px; word-break: break-all; }

.top { display: flex; align-items: center; gap: 1.5rem; background: var(--top, #14213d); color: #fff; padding: 0 1.25rem; height: 52px; }
.top .brand { color: #fff; font-weight: 700; font-size: 1.05rem; }
.top nav { display: flex; gap: .25rem; flex: 1; }
.top nav a { color: #c9d3e6; padding: .4rem .75rem; border-radius: 6px; }
.top nav a.on, .top nav a:hover { background: rgba(255,255,255,.12); color: #fff; text-decoration: none; }
.top .me { display: flex; gap: .75rem; align-items: center; color: #c9d3e6; margin: 0; }
.top .me .link { color: #fff; }
.subnav { display: flex; flex-wrap: wrap; gap: .25rem; padding: .5rem 1.25rem; background: #fff; border-bottom: 1px solid var(--line); }
.subnav a { padding: .3rem .7rem; border-radius: 6px; color: var(--muted); }
.subnav a.on { background: #e8effb; color: var(--brand); }

main { padding: 1.25rem; max-width: 1400px; margin: 0 auto; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem 1.25rem; margin-bottom: 1rem; }
.card.narrow { max-width: 760px; }
.card.empty { text-align: center; padding: 2.5rem; color: var(--muted); }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.nowrap { white-space: nowrap; }
.num { text-align: right; }
.right { float: right; }

.flash { padding: .7rem 1rem; border-radius: var(--radius); margin-bottom: 1rem; border: 1px solid; }
.flash.ok { background: #e9f7ef; border-color: #b4e2c6; color: #155d36; }
.flash.err { background: #fdecec; border-color: #f5b5b5; color: #8f1d1d; }

.btn { display: inline-flex; align-items: center; gap: .5rem; background: var(--brand); color: #fff; border: 0; border-radius: 6px; padding: .55rem 1rem; font: inherit; font-weight: 600; cursor: pointer; }
.btn:hover { background: var(--brand-dark); text-decoration: none; }
.btn.small { padding: .35rem .7rem; font-size: 13px; }
.btn.secondary { background: #e8effb; color: var(--brand); }
.btn.danger { background: var(--bad); }
button.link { background: none; border: 0; color: var(--brand); cursor: pointer; font: inherit; padding: 0; }

input, select, textarea { font: inherit; padding: .45rem .6rem; border: 1px solid #cfd5e0; border-radius: 6px; background: #fff; color: inherit; width: 100%; }
input[type=checkbox], input[type=radio] { width: auto; }
input[type=file] { border: 0; padding: 0; }
input.short { width: 90px; }
textarea { resize: vertical; }
label { display: block; font-weight: 600; font-size: 13px; }
label input, label select, label textarea { margin-top: .25rem; font-weight: 400; }
label.inline { display: inline-flex; align-items: center; gap: .4rem; font-weight: 400; margin-right: 1rem; }
label.inline select { width: auto; margin: 0; }
.hint { display: block; font-weight: 400; color: var(--muted); font-size: 12.5px; margin-top: .25rem; }
.stack > * + * { margin-top: .85rem; }
fieldset { border: 1px solid var(--line); border-radius: var(--radius); padding: .75rem 1rem; }
legend { font-weight: 600; padding: 0 .3rem; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: .85rem 1rem; }
.grid-side { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: 1.25rem; align-items: start; }
.inline-form { display: flex; gap: .5rem; align-items: center; }
.inline-form input { width: auto; flex: 1; }
.days { margin-top: .6rem; }

.toolbar { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: .75rem; margin-bottom: 1rem; }
.toolbar h2 { margin: 0; }
.tabs { display: flex; flex-wrap: wrap; gap: .25rem; }
.tabs a { padding: .4rem .8rem; border-radius: 6px; color: var(--muted); background: #fff; border: 1px solid var(--line); }
.tabs a.on { background: var(--brand); color: #fff; border-color: var(--brand); }
.tabs a b { font-weight: 600; margin-left: .25rem; }
.tabs a.alert:not(.on) { color: var(--bad); border-color: #f5b5b5; }
.filters { display: flex; gap: .5rem; }
.filters input, .filters select { width: auto; }

.table-wrap { overflow-x: auto; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); margin-bottom: 1rem; }
.card .table-wrap { border: 0; }
table.list { width: 100%; border-collapse: collapse; }
table.list th { text-align: left; font-size: 12px; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); font-weight: 600; padding: .6rem .75rem; border-bottom: 1px solid var(--line); background: #fafbfd; }
table.list td { padding: .55rem .75rem; border-bottom: 1px solid var(--line); vertical-align: middle; }
table.list tr:last-child td { border-bottom: 0; }
table.list tr:hover td { background: #fafcff; }
table.list tr.is-new td:first-child { box-shadow: inset 3px 0 0 var(--brand); }
table.list tr.muted td { opacity: .6; }
table.compact td, table.compact th { padding: .35rem .5rem; }

.badge, .status, .prio { display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.badge.good { background: #e3f5ea; color: var(--good); }
.badge.warn { background: #fdf3dc; color: var(--warn); }
.badge.bad { background: #fde4e4; color: var(--bad); }
.badge.neutral { background: #e8effb; color: var(--brand); }
.badge.muted { background: #eef0f4; color: var(--muted); }
.status { background: #eef0f4; color: #444c5e; }
.s-new { background: #e8effb; color: var(--brand); }
.s-open { background: #e3f5ea; color: var(--good); }
.s-waiting, .s-on_hold { background: #fdf3dc; color: var(--warn); }
.s-resolved, .s-closed { background: #eef0f4; color: var(--muted); }
.prio { background: transparent; padding-left: 0; }
.prio::before { content: ""; display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 6px; background: #9aa3b5; }
.p-normal::before { background: var(--brand); }
.p-high::before { background: var(--warn); }
.p-critical { color: var(--bad); }
.p-critical::before { background: var(--bad); }

.ticket-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 1rem; margin-bottom: 1rem; }
.ticket-head h2 { margin: .1rem 0 0; }
.head-badges { display: flex; gap: .5rem; }
.ticket-layout { display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: 1.25rem; align-items: start; }
.msg { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); margin-bottom: .85rem; }
.msg header { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; padding: .6rem 1rem; border-bottom: 1px solid var(--line); background: #fafbfd; border-radius: var(--radius) var(--radius) 0 0; }
.msg header .small { margin-left: auto; }
.msg .body { padding: .85rem 1rem; overflow-wrap: anywhere; }
.msg.from-staff { border-left: 3px solid var(--brand); }
.msg.internal { background: #fffbea; border-color: #f2e2a6; border-left: 3px solid var(--warn); }
.msg.internal header { background: #fff6d6; }
.atts { list-style: none; margin: 0; padding: 0 1rem .8rem; }
.sysmsg { text-align: center; color: var(--muted); font-size: 12.5px; margin: .4rem 0 .85rem; }
.reply textarea { min-height: 120px; }
.reply-foot { display: flex; flex-wrap: wrap; gap: 1rem; align-items: center; justify-content: space-between; }
.reply-foot input[type=file] { width: auto; }
.reply-type { display: flex; }
.side .card h3 { font-size: .95rem; }
dl.sla { margin: 0; }
dl.sla dt { font-weight: 600; font-size: 12.5px; color: var(--muted); margin-top: .5rem; }
dl.sla dd { margin: .15rem 0 0; }

.login-page { display: flex; align-items: center; justify-content: center; min-height: 100vh; background: linear-gradient(160deg, var(--top, #14213d), var(--brand)); }
.login-box { background: #fff; padding: 2rem; border-radius: 12px; width: 100%; max-width: 380px; box-shadow: 0 20px 50px rgba(0,0,0,.25); }
.login-box h1 { margin: 0 0 1.25rem; font-size: 1.4rem; }
.btn.ms { width: 100%; justify-content: center; background: #fff; color: #2f2f2f; border: 1px solid #8c8c8c; padding: .7rem; }
.btn.ms:hover { background: #f3f3f3; }
.login-box form { margin-top: 1.25rem; padding-top: 1.25rem; border-top: 1px solid var(--line); }

@media (max-width: 900px) {
  .ticket-layout, .grid-side, .grid2 { grid-template-columns: 1fr; }
  .top { height: auto; flex-wrap: wrap; padding: .5rem 1rem; gap: .5rem; }
  .top nav { order: 3; flex-basis: 100%; overflow-x: auto; }
  main { padding: 1rem; }
}

/* ---------- v2: branding, dashboard, reports, extras ---------- */
.top .brand { display: flex; align-items: center; gap: .6rem; }
.logo-chip { background: #fff; border-radius: 6px; padding: 3px 6px; display: flex; align-items: center; height: 36px; }
.logo-chip img { max-height: 30px; max-width: 120px; display: block; }
.top .me a { color: #fff; }
.login-logo { display: block; max-width: 220px; max-height: 90px; margin: 0 auto 1rem; }
.logo-preview { background: #f4f6f9; border: 1px dashed #cfd5e0; border-radius: var(--radius); padding: 1rem; text-align: center; }
.logo-preview img { max-height: 80px; max-width: 100%; }
input.color { width: 70px; height: 38px; padding: 2px; }
input.tiny { width: 60px; display: inline-block; margin: 0 .25rem; }
h4 { margin: .8rem 0 .3rem; font-size: 13px; color: var(--muted); }
.section-h { font-size: 13px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin: 1.25rem 0 .5rem; }

.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: .75rem; margin-bottom: 1rem; }
.kpi { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: .9rem 1rem; color: var(--text); }
a.kpi:hover { border-color: var(--brand); text-decoration: none; }
.kpi-v { font-size: 1.9rem; font-weight: 700; line-height: 1.15; font-variant-numeric: tabular-nums; }
.kpi-v.good { color: var(--good); } .kpi-v.warn { color: var(--warn); } .kpi-v.bad { color: var(--bad); }
.kpi-l { font-weight: 600; font-size: 13px; margin-top: .2rem; }
.kpi-h { font-size: 12px; color: var(--muted); margin-top: .15rem; }

figure.chart { margin: 0; }
figure.chart figcaption { font-weight: 600; font-size: .95rem; margin-bottom: .4rem; }
figure.chart svg { width: 100%; height: auto; display: block; overflow: visible; font-family: inherit; }
figure.chart svg text { font-variant-numeric: tabular-nums; }
figure.chart .hit { cursor: default; outline: none; }
figure.chart .hit.hover, figure.chart .hit:focus { fill: rgba(31, 95, 191, .06); }
.chart-legend { display: flex; gap: 1rem; font-size: 12.5px; color: var(--muted); margin-bottom: .3rem; }
.chart-legend i { display: inline-block; width: 14px; height: 3px; border-radius: 2px; vertical-align: middle; margin-right: 6px; }
.chart-table { margin-top: .4rem; font-size: 12.5px; }
.chart-table summary { cursor: pointer; color: var(--muted); }
.chart-table table { margin-top: .4rem; }
.tip { position: fixed; z-index: 50; background: #1d2433; color: #fff; padding: .45rem .65rem; border-radius: 6px; font-size: 12.5px; pointer-events: none; box-shadow: 0 4px 14px rgba(0,0,0,.2); }
.tip-h { color: #c9d3e6; margin-bottom: .15rem; }
.tip-row i { display: inline-block; width: 12px; height: 3px; border-radius: 2px; vertical-align: middle; margin-right: 6px; }
.tip-row b { margin-right: .25rem; }
.table-wrap.flat { border: 0; margin: 0; }

.bulkbar { position: sticky; top: 0; z-index: 5; display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; background: #e8effb; border: 1px solid #c8d8f3; border-radius: var(--radius); padding: .5rem .75rem; margin-bottom: .6rem; }
.bulkbar select, .bulkbar input { width: auto; }
th.chk, td.chk { width: 32px; padding-right: 0 !important; }

.reply-type { flex-wrap: wrap; align-items: center; gap: .5rem; }
select.canned { width: auto; margin-left: auto; }
.reply-extra { display: flex; flex-wrap: wrap; gap: .5rem 1.25rem; }
.reply-extra input.cc-input { width: 260px; }
ul.mini { list-style: none; margin: 0 0 .5rem; padding: 0; font-size: 13px; }
ul.mini li { padding: .25rem 0; border-bottom: 1px solid var(--line); }
ul.mini li:last-child { border-bottom: 0; }
form.inline { display: inline; }
.pre { white-space: pre-wrap; }
.mgr-schools label.inline { display: flex; margin: .2rem 0; }

.report-head { display: flex; align-items: center; gap: 1rem; margin-bottom: 1rem; }
.report-head h2 { margin: 0; }
.report-logo { max-height: 56px; max-width: 160px; }
blockquote.feedback { margin: 0 0 .6rem; padding: .5rem .75rem; background: #fafbfd; border-left: 3px solid var(--line); border-radius: 4px; }
blockquote.feedback.r3 { border-left-color: var(--good); }
blockquote.feedback.r1 { border-left-color: var(--bad); }

.kb-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 1rem; }
.kb-list { list-style: none; margin: 0; padding: 0; }
.kb-list li { padding: .4rem 0; border-bottom: 1px solid var(--line); }
.kb-list li:last-child { border-bottom: 0; }
.article .kb-body { font-size: 15px; }
.article .kb-body h3 { margin: 1.2rem 0 .4rem; }
.article .kb-body p { margin: .3rem 0; }
hr { border: 0; border-top: 1px solid var(--line); margin: 1.25rem 0; }

.survey { max-width: 460px; }
.rating { display: flex; gap: .5rem; }
.rating label { flex: 1; text-align: center; border: 2px solid var(--line); border-radius: var(--radius); padding: .7rem .3rem; cursor: pointer; font-weight: 600; }
.rating label.on, .rating label:has(input:checked) { border-color: var(--brand); background: #e8effb; }
.rating label { position: relative; }
.rating input { position: absolute; inset: 0; width: 100%; height: 100%; margin: 0; opacity: 0; cursor: pointer; }
.rating .emoji { display: block; font-size: 1.9rem; }

@media print {
  .top, .subnav, .no-print, .flash, .chart-table summary { display: none !important; }
  body { background: #fff; }
  main { padding: 0; max-width: none; }
  .card, .kpi { break-inside: avoid; border-color: #ccc; }
  .chart-table[open] { display: block; }
  a { color: inherit; }
}
figure.chart svg { max-width: 100%; height: auto; }
table.list th.num { text-align: right; }
.grid2 > *, .grid-side > *, .ticket-layout > * { min-width: 0; }
.card { overflow-x: auto; }
.filters { flex-wrap: wrap; }
@media (max-width: 600px) {
  .filters, .filters select, .filters input[type=search] { width: 100%; }
  .filters select, .filters input { flex: 1 1 140px; }
  .kpis { grid-template-columns: 1fr 1fr; }
  .kpi-v { font-size: 1.5rem; }
}
.inline-form input { min-width: 0; } .inline-form .btn { flex-shrink: 0; }
.atts img.thumb { max-width: 240px; max-height: 180px; border-radius: 6px; border: 1px solid var(--line); margin: .3rem 0; }
