:root {
  --bg: #f3f5f7; --panel: #fff; --ink: #14212b; --muted: #5d6d7a; --line: #e2e7ec; --line-strong: #cfd7de;
  --brand: #0b6bcb; --brand-ink: #fff; --brand-soft: #e7f1fb;
  --ok: #1a7f4b; --ok-soft: #e5f5ec; --warn: #a86400; --warn-soft: #fdf2e0; --fail: #c0362c; --fail-soft: #fbe9e7;
  --info: #44607a; --info-soft: #edf2f6;
  --radius: 10px; --shadow: 0 1px 2px rgba(16,33,48,.06), 0 1px 1px rgba(16,33,48,.04);
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; color: var(--ink); background: var(--bg); }
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 22px; margin: 0; }
h2 { font-size: 15px; margin: 0 0 10px; }
h3 { font-size: 13px; margin: 0 0 6px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
small, .muted { color: var(--muted); }
code, .mono { font-family: var(--mono); font-size: 12.5px; }

#app { display: flex; min-height: 100vh; }
#nav { width: 220px; flex: none; background: #0f1e2a; color: #c9d6e0; display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; }
#nav[hidden] { display: none; }
.brand { display: flex; gap: 10px; align-items: center; padding: 18px 16px; color: #fff; }
.brand small { display: block; color: #8ea3b3; font-size: 12px; }
.logo { width: 30px; height: 30px; border-radius: 8px; background: var(--brand) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 32 32'%3E%3Cpath d='M9 20a10 10 0 0 1 14 0M12 23a5.5 5.5 0 0 1 8 0' stroke='white' stroke-width='2.4' fill='none' stroke-linecap='round'/%3E%3Ccircle cx='16' cy='25.5' r='1.6' fill='white'/%3E%3C/svg%3E") center/100% no-repeat; }
#nav nav { display: flex; flex-direction: column; padding: 6px 8px; gap: 2px; flex: 1; }
#nav nav a { color: #c9d6e0; padding: 8px 10px; border-radius: 7px; display: flex; justify-content: space-between; align-items: center; }
#nav nav a:hover { background: #1a2e3d; text-decoration: none; }
#nav nav a.active { background: #1f3a50; color: #fff; }
.me { padding: 14px 16px; border-top: 1px solid #1d3242; display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.me a { color: #fff; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.me .link { color: #8ea3b3; }

main { flex: 1; min-width: 0; padding: 22px 28px 60px; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 18px; flex-wrap: wrap; }
.page-head .sub { color: var(--muted); margin-top: 2px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.grid { display: grid; gap: 16px; }
.cols-2 { grid-template-columns: minmax(0, 3fr) minmax(0, 2fr); }
.cols-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
@media (max-width: 1100px) { .cols-2 { grid-template-columns: 1fr; } .cols-4 { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 760px) { #nav { display: none !important; } main { padding: 16px; } }

.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); }
.card + .card { margin-top: 16px; }
.stat b { display: block; font-size: 26px; font-variant-numeric: tabular-nums; }
.stat span { color: var(--muted); }

button, .btn { font: inherit; border: 1px solid var(--line-strong); background: #fff; color: var(--ink); padding: 7px 12px; border-radius: 8px; cursor: pointer; display: inline-flex; align-items: center; gap: 6px; text-decoration: none; white-space: nowrap; }
button:hover, .btn:hover { background: #f5f7f9; text-decoration: none; }
button.primary, .btn.primary { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
button.primary:hover { background: #095bad; }
button.danger { color: var(--fail); border-color: #e7b9b4; }
button.danger:hover { background: var(--fail-soft); }
button.link { border: 0; background: none; padding: 0; color: var(--brand); }
button:disabled { opacity: .55; cursor: progress; }
button.sm { padding: 4px 9px; font-size: 13px; }

input, select, textarea { font: inherit; color: inherit; border: 1px solid var(--line-strong); border-radius: 8px; padding: 7px 10px; background: #fff; width: 100%; }
input:focus, select:focus, textarea:focus { outline: 2px solid #b8d6f3; border-color: var(--brand); }
textarea { min-height: 84px; resize: vertical; }
label { display: block; font-weight: 600; font-size: 13px; margin-bottom: 4px; }
.field { margin-bottom: 12px; }
.field small { font-weight: 400; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 14px; }
.form-grid .full { grid-column: 1 / -1; }
.search { max-width: 340px; }
.check { display: flex; gap: 8px; align-items: center; font-weight: 400; }
.check input { width: auto; }

table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 9px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 600; }
tr.click { cursor: pointer; }
tr.click:hover td { background: #f8fafb; }
tr.unread td:first-child { box-shadow: inset 3px 0 0 var(--brand); }
tr.unread .subj { font-weight: 700; }
.table-wrap { overflow-x: auto; }

.pill { display: inline-block; font-size: 12px; padding: 1px 8px; border-radius: 99px; background: var(--info-soft); color: var(--info); font-weight: 600; white-space: nowrap; }
.pill.ok { background: var(--ok-soft); color: var(--ok); }
.pill.warn { background: var(--warn-soft); color: var(--warn); }
.pill.fail { background: var(--fail-soft); color: var(--fail); }
.pill.open { background: var(--brand-soft); color: var(--brand); }
.pill.pending { background: var(--warn-soft); color: var(--warn); }
.pill.resolved { background: #eef0f2; color: var(--muted); }
#nav .pill { background: var(--brand); color: #fff; }

.findings { display: flex; flex-direction: column; gap: 8px; }
.finding { border-left: 4px solid var(--info); background: var(--info-soft); padding: 9px 12px; border-radius: 6px; }
.finding.ok { border-color: var(--ok); background: var(--ok-soft); }
.finding.warn { border-color: var(--warn); background: var(--warn-soft); }
.finding.fail { border-color: var(--fail); background: var(--fail-soft); }
.finding b { display: block; }
.finding .who { float: right; font-size: 11px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }
.finding p { margin: 3px 0 0; }

.kv { display: grid; grid-template-columns: max-content 1fr; gap: 4px 14px; margin: 0; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; font-variant-numeric: tabular-nums; word-break: break-word; }
.panels { display: grid; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); gap: 12px; margin-top: 14px; }
.panel { border: 1px solid var(--line); border-radius: 8px; padding: 12px; }
.panel h3 { display: flex; justify-content: space-between; }

.thread { display: flex; flex-direction: column; gap: 10px; max-height: 60vh; overflow-y: auto; padding: 4px 2px; }
.msg { max-width: 82%; padding: 9px 12px; border-radius: 12px; white-space: pre-wrap; word-break: break-word; }
.msg .meta { display: block; font-size: 12px; color: var(--muted); margin-bottom: 3px; white-space: normal; }
.msg.customer { background: #eef1f4; align-self: flex-start; border-bottom-left-radius: 4px; }
.msg.agent { background: var(--brand-soft); align-self: flex-end; border-bottom-right-radius: 4px; }
.msg.system { background: none; border: 1px dashed var(--line-strong); align-self: center; max-width: 95%; font-size: 13px; color: var(--muted); }

.empty { color: var(--muted); padding: 24px; text-align: center; }
.codebox { font-family: var(--mono); font-size: 34px; letter-spacing: .2em; text-align: center; padding: 14px; background: var(--brand-soft); border-radius: 10px; margin: 10px 0; }
pre.json { background: #0f1e2a; color: #d6e2ea; padding: 12px; border-radius: 8px; overflow: auto; max-height: 420px; font-size: 12px; }
details summary { cursor: pointer; color: var(--brand); }
.hist-item { border-bottom: 1px solid var(--line); padding: 8px 0; }
.hist-item:last-child { border-bottom: 0; }

#toast { position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%) translateY(20px); background: #14212b; color: #fff; padding: 10px 16px; border-radius: 8px; opacity: 0; pointer-events: none; transition: .2s; max-width: 90vw; z-index: 50; }
#toast.show { opacity: 1; transform: translateX(-50%); }
#toast.err { background: var(--fail); }

dialog { border: 0; border-radius: 12px; padding: 0; width: min(560px, 94vw); box-shadow: 0 20px 60px rgba(0,0,0,.25); }
dialog::backdrop { background: rgba(10,20,30,.45); }
#modal-form { padding: 20px; }
#modal-form .actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }

.login-wrap { min-height: 80vh; display: grid; place-items: center; }
.login { width: min(360px, 92vw); }
.login .logo { width: 44px; height: 44px; margin-bottom: 12px; }
.spinner { width: 14px; height: 14px; border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; display: inline-block; animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* fixes */
[hidden] { display: none !important; }
.grid { align-items: start; }
.grid > .card + .card { margin-top: 0; }
.grid.cols-4 { align-items: stretch; }
