/* Rubix Scan web UI — theme-aware, no external deps. */
:root {
  --bg: #f4f6fa;
  --surface: #ffffff;
  --surface-2: #f0f3f8;
  --border: #dde3ea;
  --text: #1c2733;
  --text-dim: #5a6b7b;
  --brand: #2f6fed;
  --brand-dark: #1f52bd;
  --crit: #b3123b; --high: #e35d0a; --med: #b7900a; --low: #2f7d32; --info: #4b6584;
  --shadow: 0 1px 3px rgba(16,32,64,.08), 0 4px 16px rgba(16,32,64,.06);
  --radius: 10px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e1420; --surface: #161d2b; --surface-2: #1e2736; --border: #2a3547;
    --text: #e7edf5; --text-dim: #9fb0c3; --brand: #5b8dff; --brand-dark: #3f6fe0;
    --shadow: 0 1px 3px rgba(0,0,0,.4), 0 8px 24px rgba(0,0,0,.3);
  }
}
:root[data-theme="dark"] {
  --bg: #0e1420; --surface: #161d2b; --surface-2: #1e2736; --border: #2a3547;
  --text: #e7edf5; --text-dim: #9fb0c3; --brand: #5b8dff; --brand-dark: #3f6fe0;
}
:root[data-theme="light"] {
  --bg: #f4f6fa; --surface: #fff; --surface-2: #f0f3f8; --border: #dde3ea;
  --text: #1c2733; --text-dim: #5a6b7b; --brand: #2f6fed; --brand-dark: #1f52bd;
}

* { box-sizing: border-box; }
/* The `hidden` attribute must always win over class display rules (.app-root/.auth-root/
   .modal-root set display, which would otherwise override the UA [hidden] { display:none }). */
[hidden] { display: none !important; }
html, body { height: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 15px/1.5 -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
h1,h2,h3 { line-height: 1.25; }

/* ---------- buttons / forms ---------- */
.btn {
  display: inline-flex; align-items: center; gap: 7px; cursor: pointer;
  border: 1px solid var(--brand); background: var(--brand); color: #fff;
  padding: 9px 16px; border-radius: 8px; font-size: 14px; font-weight: 600;
  transition: filter .12s, background .12s; white-space: nowrap;
}
.btn:hover { filter: brightness(1.06); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn-ghost { background: transparent; color: var(--text); border-color: var(--border); }
.btn-ghost:hover { background: var(--surface-2); filter: none; }
.btn-danger { background: var(--crit); border-color: var(--crit); }
.btn-sm { padding: 6px 11px; font-size: 13px; }
label { display: block; font-size: 13px; font-weight: 600; color: var(--text-dim); margin: 12px 0 5px; }
input, select, textarea {
  width: 100%; padding: 10px 12px; border: 1px solid var(--border); border-radius: 8px;
  background: var(--surface); color: var(--text); font: inherit;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--brand); border-color: var(--brand); }
.hint { font-size: 12.5px; color: var(--text-dim); margin-top: 4px; }
.field-row { display: flex; gap: 14px; flex-wrap: wrap; }
.field-row > div { flex: 1; min-width: 180px; }

/* ---------- auth ---------- */
.auth-root {
  min-height: 100%; display: flex; flex-direction: column;
  align-items: center; justify-content: center; padding: 24px; gap: 14px;
}
.auth-card { width: 100%; max-width: 400px; background: var(--surface);
  border: 1px solid var(--border); border-radius: 14px; padding: 30px; box-shadow: var(--shadow); }
.auth-foot { color: var(--text-dim); font-size: 13px; }
.tagline { color: var(--text-dim); margin: 6px 0 18px; font-size: 14px; }
.brand { display: flex; align-items: center; gap: 9px; font-weight: 800; font-size: 19px; }
.brand .logo { font-size: 22px; }
.switch-line { margin-top: 16px; font-size: 14px; color: var(--text-dim); }

/* ---------- app shell ---------- */
.app-root { display: grid; grid-template-columns: 244px 1fr; min-height: 100%; }
.sidebar {
  background: var(--surface); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; padding: 18px 14px; gap: 8px;
  position: sticky; top: 0; height: 100vh;
}
.sidebar .brand { padding: 4px 8px 14px; }
#nav { display: flex; flex-direction: column; gap: 2px; flex: 1; }
.nav-link {
  display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-radius: 8px;
  color: var(--text); font-weight: 600; font-size: 14px; cursor: pointer;
}
.nav-link .ico { width: 20px; text-align: center; }
.nav-link:hover { background: var(--surface-2); text-decoration: none; }
.nav-link.active { background: var(--brand); color: #fff; }
.nav-sep { font-size: 11px; text-transform: uppercase; letter-spacing: .06em;
  color: var(--text-dim); padding: 12px 12px 4px; }
.sidebar-foot { border-top: 1px solid var(--border); padding-top: 12px; }
.whoami { font-size: 12.5px; color: var(--text-dim); margin-bottom: 8px; word-break: break-all; }
.whoami b { color: var(--text); }

.main { display: flex; flex-direction: column; min-width: 0; }
.topbar {
  display: flex; align-items: center; gap: 14px; padding: 16px 26px;
  border-bottom: 1px solid var(--border); background: var(--surface); position: sticky; top: 0; z-index: 5;
}
.topbar h1 { font-size: 20px; margin: 0; flex: 1; }
.page-actions { display: flex; gap: 8px; }
.menu-toggle { display: none; }
.view { padding: 26px; max-width: 1100px; }

/* ---------- cards / kpis / tables ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 20px; box-shadow: var(--shadow); margin-bottom: 18px; }
.card h2 { margin: 0 0 14px; font-size: 16px; }
.grid { display: grid; gap: 16px; }
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 14px; }
.kpi { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 16px; text-align: center; box-shadow: var(--shadow); }
.kpi .n { font-size: 30px; font-weight: 800; }
.kpi .l { font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--text-dim); margin-top: 2px; }

table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--border); vertical-align: top; }
th { font-size: 12px; text-transform: uppercase; letter-spacing: .03em; color: var(--text-dim); }
tr:last-child td { border-bottom: none; }
.table-wrap { overflow-x: auto; }
.clickable { cursor: pointer; }
.clickable:hover td { background: var(--surface-2); }

/* ---------- badges ---------- */
.badge { display: inline-block; font-size: 11px; font-weight: 700; padding: 2px 9px; border-radius: 20px;
  text-transform: uppercase; letter-spacing: .02em; color: #fff; }
.badge.critical { background: var(--crit); } .badge.high { background: var(--high); }
.badge.medium { background: var(--med); } .badge.low { background: var(--low); } .badge.info { background: var(--info); }
.badge.gray { background: var(--text-dim); }
.badge.green { background: var(--low); } .badge.amber { background: var(--high); } .badge.blue { background: var(--brand); }

.pill { display: inline-block; background: var(--surface-2); border: 1px solid var(--border);
  border-radius: 6px; padding: 1px 8px; font-size: 12px; margin: 2px 4px 2px 0; }

/* ---------- misc ---------- */
.muted { color: var(--text-dim); }
.empty { text-align: center; color: var(--text-dim); padding: 40px 20px; }
.empty .big { font-size: 40px; }
.row-between { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.stack > * + * { margin-top: 10px; }
.code { font-family: ui-monospace, SFMono-Regular, Consolas, monospace; background: var(--surface-2);
  padding: 2px 6px; border-radius: 5px; font-size: 13px; word-break: break-all; }
.error-text { color: var(--crit); font-size: 13.5px; margin-top: 10px; min-height: 18px; }
.callout { border-left: 3px solid var(--brand); background: var(--surface-2);
  padding: 10px 14px; border-radius: 6px; font-size: 13.5px; }
.callout.warn { border-color: var(--high); }

/* ---------- toasts ---------- */
.toasts { position: fixed; bottom: 20px; right: 20px; display: flex; flex-direction: column; gap: 10px; z-index: 100; }
.toast { background: var(--surface); border: 1px solid var(--border); border-left: 4px solid var(--brand);
  padding: 12px 16px; border-radius: 8px; box-shadow: var(--shadow); max-width: 340px; font-size: 14px;
  animation: slidein .18s ease; }
.toast.error { border-left-color: var(--crit); }
.toast.success { border-left-color: var(--low); }
@keyframes slidein { from { transform: translateX(20px); opacity: 0; } to { transform: none; opacity: 1; } }

/* ---------- modal ---------- */
.modal-root { position: fixed; inset: 0; background: rgba(10,16,26,.55); display: flex;
  align-items: center; justify-content: center; padding: 20px; z-index: 60; }
.modal { background: var(--surface); border-radius: 14px; border: 1px solid var(--border);
  width: 100%; max-width: 520px; box-shadow: var(--shadow); max-height: 90vh; overflow: auto; }
.modal-head { display: flex; justify-content: space-between; align-items: center;
  padding: 18px 22px; border-bottom: 1px solid var(--border); }
.modal-head h2 { margin: 0; font-size: 17px; }
.modal-body { padding: 22px; }
.modal-foot { padding: 16px 22px; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: 10px; }
.x { cursor: pointer; font-size: 22px; line-height: 1; color: var(--text-dim); background: none; border: none; }

/* ---------- plans ---------- */
.plan-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 16px; }
.plan { border: 1px solid var(--border); border-radius: 12px; padding: 20px; background: var(--surface); }
.plan.current { border-color: var(--brand); box-shadow: 0 0 0 2px var(--brand) inset; }
.plan .price { font-size: 28px; font-weight: 800; margin: 6px 0; }
.plan ul { list-style: none; padding: 0; margin: 12px 0 0; font-size: 13.5px; }
.plan li { padding: 4px 0; border-bottom: 1px dashed var(--border); }

.spinner { width: 34px; height: 34px; border: 3px solid var(--border); border-top-color: var(--brand);
  border-radius: 50%; animation: spin .7s linear infinite; margin: 40px auto; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- responsive ---------- */
@media (max-width: 820px) {
  .app-root { grid-template-columns: 1fr; }
  .sidebar { position: fixed; z-index: 40; width: 244px; transform: translateX(-100%);
    transition: transform .2s; }
  .sidebar.open { transform: none; }
  .menu-toggle { display: inline-flex; }
  .view { padding: 18px; }
}
