:root {
  --navy: #0b1220;
  --navy-2: #111a2e;
  --navy-3: #1a2540;
  --blue: #2563eb;
  --blue-2: #1d4ed8;
  --blue-soft: #dbeafe;
  --blue-border: #60a5fa;
  --ink: #0f172a;
  --muted: #64748b;
  --line: #e2e8f0;
  --bg: #f5f7fb;
  --card: #ffffff;
  --green: #16a34a;
  --green-soft: #dcfce7;
  --red: #dc2626;
  --red-soft: #fee2e2;
  --amber: #d97706;
  --amber-soft: #fef3c7;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(15,23,42,.06), 0 8px 24px rgba(15,23,42,.04);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, Helvetica, Arial, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--ink); }
button, input { font: inherit; }
a { color: var(--blue); }
.shell { display: grid; grid-template-columns: 240px 1fr; min-height: 100vh; }
.sidebar { background: linear-gradient(180deg, var(--navy) 0%, #0a1020 100%); color: #e2e8f0; display: flex; flex-direction: column; padding: 18px 14px; position: sticky; top: 0; height: 100vh; }
.brand { display: flex; gap: 10px; align-items: center; padding: 6px 8px 22px; }
.brand.dark { color: #0b1220; justify-content: center; }
.brand-mark { width: 36px; height: 36px; border-radius: 8px; background: var(--blue); color: #fff; display: grid; place-items: center; font-weight: 800; font-size: 11px; letter-spacing: .04em; }
.brand-title { font-weight: 800; letter-spacing: .08em; font-size: 12px; line-height: 1.1; }
.brand-sub { font-size: 10px; letter-spacing: .18em; color: #94a3b8; }
.brand.dark .brand-sub { color: #64748b; }
.nav { display: flex; flex-direction: column; gap: 2px; flex: 1; overflow: auto; }
.nav a { color: #cbd5e1; text-decoration: none; padding: 10px 12px; border-radius: 8px; font-size: 13.5px; display: flex; align-items: center; gap: 10px; }
.nav a:hover { background: rgba(255,255,255,.06); color: #fff; }
.nav a.active { background: var(--blue); color: #fff; font-weight: 600; }
.nav .ico { width: 18px; opacity: .85; }
.sidebar-foot { border-top: 1px solid rgba(255,255,255,.08); padding-top: 14px; margin-top: 14px; }
.who-name { font-weight: 700; font-size: 13px; }
.who-role { font-size: 10px; letter-spacing: .14em; color: #94a3b8; margin-top: 2px; }
.signout { width: 100%; margin-top: 12px; background: transparent; border: 1px solid rgba(255,255,255,.15); color: #e2e8f0; border-radius: 8px; padding: 9px 10px; cursor: pointer; text-align: left; }
.signout:hover { background: rgba(255,255,255,.06); }
.main { padding: 28px 32px 40px; max-width: 1600px; }
.page-head { display: flex; justify-content: space-between; gap: 24px; align-items: flex-start; margin-bottom: 18px; }
.page-head h1 { margin: 0; font-size: 28px; letter-spacing: .02em; }
.page-head .sub { margin: 6px 0 0; color: var(--muted); font-size: 14px; max-width: 640px; }
.stats { display: flex; gap: 12px; align-items: stretch; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: 12px; min-width: 110px; padding: 12px 16px; box-shadow: var(--shadow); }
.stat .n { font-size: 26px; font-weight: 800; line-height: 1; }
.stat .l { font-size: 11px; letter-spacing: .08em; color: var(--muted); margin-top: 4px; text-transform: uppercase; }
.stat.warn { border-color: #fecaca; background: #fff7f7; }
.stat.warn .n { color: var(--red); }
.btn { border: 0; border-radius: 10px; padding: 10px 14px; cursor: pointer; font-weight: 700; font-size: 13px; letter-spacing: .04em; }
.btn.primary { background: var(--blue); color: #fff; }
.btn.primary:hover { background: var(--blue-2); }
.btn.ghost { background: #fff; border: 1px solid var(--line); color: var(--ink); }
.btn.sm { padding: 7px 10px; font-size: 11.5px; border-radius: 8px; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.toolbar { display: flex; gap: 14px; align-items: center; margin: 10px 0 14px; flex-wrap: wrap; }
.toolbar input[type=search] { flex: 1; min-width: 240px; border: 1px solid var(--line); border-radius: 10px; padding: 11px 14px; background: #fff; }
.toggle { display: inline-flex; align-items: center; gap: 8px; font-size: 12.5px; font-weight: 700; letter-spacing: .04em; color: var(--muted); cursor: pointer; user-select: none; }
.toggle input { appearance: none; width: 38px; height: 22px; border-radius: 999px; background: #cbd5e1; position: relative; transition: .15s; cursor: pointer; }
.toggle input:checked { background: var(--blue); }
.toggle input::after { content: ""; position: absolute; top: 3px; left: 3px; width: 16px; height: 16px; border-radius: 50%; background: #fff; transition: .15s; }
.toggle input:checked::after { left: 19px; }
.hint { color: var(--muted); font-size: 12.5px; }
.hint b { color: var(--ink); }
.matrix-wrap { background: var(--card); border: 1px solid var(--line); border-radius: 14px; box-shadow: var(--shadow); overflow: hidden; }
.matrix { width: 100%; border-collapse: separate; border-spacing: 0; }
.matrix th { text-align: left; font-size: 11px; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); padding: 14px 14px; border-bottom: 1px solid var(--line); background: #fafbfc; position: sticky; top: 0; }
.matrix td { vertical-align: top; padding: 14px; border-bottom: 1px solid var(--line); }
.matrix tr:last-child td { border-bottom: 0; }
.contractor { min-width: 170px; }
.contractor .name { font-weight: 700; font-size: 15px; margin-bottom: 10px; }
.cell { border: 1px solid var(--line); border-radius: 12px; padding: 12px; background: #fff; min-width: 190px; }
.cell.refreshed { border-color: var(--blue-border); box-shadow: inset 0 0 0 1px rgba(96,165,250,.35); }
.cell.failed, .cell.blocked, .cell.logged_out { border-color: #fca5a5; background: #fffafa; }
.cell.awaiting_human { border-color: #fbbf24; background: #fffbeb; }
.cell.not_configured { background: #f8fafc; color: var(--muted); }
.status-line { display: flex; align-items: center; gap: 7px; font-size: 13px; font-weight: 700; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: #94a3b8; flex: none; }
.dot.ok { background: var(--blue); }
.dot.warn { background: var(--amber); }
.dot.bad { background: var(--red); }
.dot.muted { background: #cbd5e1; }
.when { color: var(--muted); font-size: 12px; margin: 4px 0 10px; font-weight: 500; }
.cell-actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.details { position: relative; }
.details summary { list-style: none; cursor: pointer; font-size: 12px; color: var(--muted); font-weight: 600; padding: 6px 0; }
.details summary::-webkit-details-marker { display: none; }
.details summary::-webkit-details-marker { display: none; }
.details summary::after { content: " ▾"; }
.details[open] summary::after { content: " ▴"; }
.details-panel { position: absolute; z-index: 5; left: 0; top: 28px; width: 280px; background: #0b1220; color: #e2e8f0; border-radius: 10px; padding: 12px; font-size: 12px; box-shadow: 0 12px 40px rgba(0,0,0,.25); }
.details-panel dt { color: #94a3b8; margin-top: 6px; }
.details-panel dd { margin: 2px 0 0; }
.mailbox .addr { font-weight: 600; font-size: 13px; word-break: break-all; }
.mailbox .note { color: var(--muted); font-size: 12px; margin: 6px 0 8px; }
.ops { display: grid; grid-template-columns: 1.1fr .9fr; gap: 16px; margin-top: 18px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 16px 18px; box-shadow: var(--shadow); }
.card h3 { margin: 0 0 10px; font-size: 13px; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); }
.empty-ok { background: var(--green-soft); color: #166534; border-radius: 10px; padding: 14px; display: flex; gap: 10px; align-items: center; font-weight: 700; }
.badge { display: inline-block; background: var(--red-soft); color: var(--red); font-weight: 800; font-size: 11px; padding: 3px 8px; border-radius: 999px; letter-spacing: .06em; }
.activity { list-style: none; margin: 0; padding: 0; max-height: 280px; overflow: auto; }
.activity li { display: grid; grid-template-columns: 56px 1fr; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--line); font-size: 13px; }
.activity li:last-child { border-bottom: 0; }
.activity .t { color: var(--muted); font-variant-numeric: tabular-nums; }
.activity .m { color: var(--ink); }
.activity .a { color: var(--muted); font-size: 11px; margin-top: 2px; }
.footer-bar { display: flex; gap: 18px; flex-wrap: wrap; padding: 12px 16px; border-top: 1px solid var(--line); color: var(--muted); font-size: 11px; letter-spacing: .08em; text-transform: uppercase; background: #fafbfc; }
.footer-bar .online { color: var(--green); font-weight: 800; }
.placeholder { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 40px; text-align: center; color: var(--muted); box-shadow: var(--shadow); }
.placeholder h2 { color: var(--ink); margin: 0 0 8px; }
.toast { position: fixed; right: 20px; bottom: 20px; background: #0b1220; color: #fff; padding: 12px 16px; border-radius: 10px; z-index: 50; max-width: 360px; box-shadow: 0 12px 40px rgba(0,0,0,.3); }
.loading { padding: 80px; text-align: center; color: var(--muted); }
.login-body { display: grid; place-items: center; min-height: 100vh; background: radial-gradient(1200px 600px at 50% -10%, #1e3a8a 0%, #0b1220 55%); }
.login-card { width: min(380px, 92vw); background: #fff; border-radius: 16px; padding: 28px; display: flex; flex-direction: column; gap: 12px; box-shadow: 0 30px 80px rgba(0,0,0,.35); }
.login-card input { border: 1px solid var(--line); border-radius: 10px; padding: 12px 14px; }
.login-err { color: var(--red); margin: 0; font-size: 13px; }
.eyebrow { font-size: 11px; letter-spacing: .1em; text-transform: uppercase; color: var(--muted); font-weight: 700; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.chip { display: inline-block; font-size: 11px; padding: 2px 7px; border-radius: 999px; background: #f1f5f9; color: #475569; font-weight: 600; }
.chip.pending { background: var(--amber-soft); color: #92400e; }
.chip.nodata { background: #f1f5f9; color: #64748b; }
@media (max-width: 1100px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar { position: relative; height: auto; }
  .ops { grid-template-columns: 1fr; }
  .matrix-wrap { overflow: auto; }
}

/* Session states (keeper) */
.cell.signed_in { border-color: #86efac; box-shadow: inset 0 0 0 1px rgba(34,197,94,.35); background: #f0fdf4; }
.cell.refreshing { border-color: var(--blue-border); box-shadow: inset 0 0 0 1px rgba(96,165,250,.35); }
.cell.needs_attention { border-color: #fbbf24; background: #fffbeb; }
.dot.ok { background: var(--green); }
.today { font-size: 12px; color: var(--ink); font-weight: 600; margin: -4px 0 8px; }
.contractor-row { cursor: pointer; }
.contractor-row:hover td { background: #f8fafc; }
.contractor-row:hover .cell { background: #fff; }

/* Add / Edit contractor dialog */
.modal-backdrop { position: fixed; inset: 0; background: rgba(15,23,42,.55); display: grid; place-items: center; z-index: 40; padding: 20px; }
.modal { background: #fff; border-radius: 16px; width: min(860px, 96vw); max-height: 92vh; overflow: auto; padding: 22px 24px 20px; box-shadow: 0 30px 80px rgba(0,0,0,.35); }
.modal-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 6px; }
.modal-head h2 { margin: 0; font-size: 20px; }
.icon-x { border: 0; background: transparent; font-size: 28px; line-height: 1; cursor: pointer; color: var(--muted); padding: 0 6px; }
.field { display: flex; flex-direction: column; gap: 6px; margin: 10px 0; font-size: 12.5px; font-weight: 700; letter-spacing: .04em; color: var(--muted); text-transform: uppercase; }
.field input, .field select { font: inherit; font-weight: 500; text-transform: none; letter-spacing: 0; border: 1px solid var(--line); border-radius: 10px; padding: 11px 12px; color: var(--ink); background: #fff; }
.plat-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin: 14px 0; }
.plat { border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px 6px; margin: 0; }
.plat legend { padding: 0 6px; font-size: 12px; font-weight: 800; letter-spacing: .08em; text-transform: uppercase; color: var(--ink); }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 8px; }
.pw-saved { display: inline-block; background: var(--green-soft); color: #166534; font-size: 10px; font-weight: 800; padding: 2px 7px; border-radius: 999px; letter-spacing: .06em; text-transform: uppercase; margin-left: 6px; }
.linkish { background: none; border: 0; color: var(--blue); cursor: pointer; font: inherit; font-size: 11px; font-weight: 700; padding: 0 4px; text-transform: none; letter-spacing: 0; }
@media (max-width: 720px) { .plat-grid { grid-template-columns: 1fr; } }
