:root {
    --bg: #f4f5f7;
    --panel: #ffffff;
    --line: #e2e5ea;
    --text: #1d2330;
    --muted: #6b7280;
    --accent: #2457d6;
    --accent-soft: #e6edfc;
    --hit: #0f8a5f;
    --hit-soft: #dff5ec;
    --danger: #c0392b;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); color: var(--text); font: 14px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
h1 { font-size: 15px; margin: 0 0 10px; }
button { font: inherit; cursor: pointer; }
input[type=text], input[type=password] {
    font: inherit; padding: 7px 9px; border: 1px solid var(--line); border-radius: 6px; width: 100%; background: #fff;
}
input:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
.link { background: none; border: 0; padding: 0; color: var(--accent); }
.link:hover { text-decoration: underline; }
.danger { color: var(--danger); }
.muted { color: var(--muted); }
.small { font-size: 12px; }

/* ---------- Front page ---------- */
.front { overflow: hidden; }
.app { display: grid; grid-template-columns: 230px 1fr; height: 100vh; overflow: hidden; }
.sidebar { background: var(--panel); border-right: 1px solid var(--line); padding: 14px 12px; display: flex; flex-direction: column; min-height: 0; }
.quick { display: flex; gap: 12px; font-size: 12px; margin-bottom: 6px; }
.agent-list { list-style: none; margin: 0 0 12px; padding: 0; overflow-y: auto; flex: 1; min-height: 0; }
.agent-list label { display: flex; align-items: center; gap: 8px; padding: 5px 6px; border-radius: 5px; cursor: pointer; }
.agent-list label:hover { background: var(--bg); }
.agent-list .nm { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.agent-list .ct { font-size: 11px; color: var(--muted); background: var(--bg); border-radius: 10px; padding: 0 7px; }
.agent-list input { accent-color: var(--accent); margin: 0; }
.search { background: var(--accent); margin: -14px -12px 14px; padding: 14px 12px 12px; }
.search label { display: block; color: #fff; font-weight: 700; font-size: 13px; letter-spacing: .02em; margin-bottom: 6px; }
.search input { font-size: 20px; font-weight: 700; text-transform: uppercase; letter-spacing: .08em; padding: 9px 12px; border: 0; border-radius: 8px; }
.search input::placeholder { text-transform: none; letter-spacing: 0; font-weight: 400; font-size: 15px; }
.search input:focus { outline: 3px solid rgba(255,255,255,.45); }
#find-result { margin: 8px 0 0; color: #fff; font-size: 12.5px; line-height: 1.45; }
#find-result:empty { display: none; }

.boxes {
    padding: 12px; overflow-y: auto; display: grid; gap: 10px; align-content: start;
    grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
}
.box { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px 10px; transition: opacity .15s; }
.box header { display: flex; justify-content: space-between; align-items: baseline; font-weight: 600; margin-bottom: 6px; border-bottom: 1px solid var(--line); padding-bottom: 5px; }
.box header small { font-weight: 400; color: var(--muted); font-size: 11px; }
.box.miss { opacity: .35; }
.box.hit { border-color: var(--hit); }
.chips { display: flex; flex-wrap: wrap; gap: 4px; }
.chip { font: 600 11.5px/1 ui-monospace, SFMono-Regular, Menlo, monospace; background: var(--accent-soft); color: var(--accent); padding: 4px 5px; border-radius: 4px; min-width: 28px; text-align: center; }
.chip.on { background: var(--hit); color: #fff; }
.empty { color: var(--muted); grid-column: 1 / -1; text-align: center; margin-top: 15vh; }

/* ---------- Admin ---------- */
.topbar { display: flex; justify-content: space-between; align-items: center; padding: 10px 16px; background: var(--panel); border-bottom: 1px solid var(--line); }
.topbar nav { display: flex; gap: 16px; }
.topbar a, .admin a { color: var(--accent); text-decoration: none; }
.admin-wrap { max-width: 880px; margin: 16px auto; padding: 0 16px; display: grid; gap: 14px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 14px 16px; }
.login { max-width: 320px; margin: 12vh auto; display: grid; gap: 10px; }
.field { display: grid; gap: 4px; font-size: 12px; color: var(--muted); margin-bottom: 12px; }
.field-head { display: flex; justify-content: space-between; font-size: 12px; color: var(--muted); margin-bottom: 6px; }
.state-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(62px, 1fr)); gap: 4px; }
.state-grid label { display: flex; align-items: center; gap: 5px; padding: 4px 6px; border: 1px solid var(--line); border-radius: 5px; font: 600 12px ui-monospace, Menlo, monospace; cursor: pointer; }
.state-grid label:has(input:checked) { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }
.state-grid input { margin: 0; accent-color: var(--accent); }
.actions { display: flex; gap: 14px; align-items: center; margin-top: 14px; }
.card > button, .actions > button { background: var(--accent); color: #fff; border: 0; border-radius: 6px; padding: 8px 16px; }
.msg { margin: 0; padding: 8px 12px; border-radius: 6px; }
.msg.ok { background: var(--hit-soft); color: var(--hit); }
.msg.err { background: #fdecea; color: var(--danger); }
table { width: 100%; border-collapse: collapse; }
td { border-top: 1px solid var(--line); padding: 7px 4px; vertical-align: top; }
td.name { font-weight: 600; white-space: nowrap; width: 1%; padding-right: 16px; }
td.states { font: 12px ui-monospace, Menlo, monospace; color: var(--muted); }
td.row-actions { white-space: nowrap; text-align: right; width: 1%; }
td.row-actions form { display: inline; margin-left: 10px; }

@media (max-width: 640px) {
    .front { overflow: visible; }
    .app { grid-template-columns: 1fr; grid-template-rows: auto 1fr; height: auto; min-height: 100vh; overflow: visible; }
    .sidebar { border-right: 0; border-bottom: 1px solid var(--line); }
    .agent-list { max-height: 30vh; }
}
