/* Summary: LubSoft Manager styles: design tokens (light + dark), app shell (sidebar, header, content), cards, tables,
   status badges, forms, dialogs, toasts and the login page. System fonts only (strict CSP, nothing external).
   Keywords: css, tokens, dark mode, sidebar, table, badge, dialog, form, toast, login */

:root {
  --bg: #f4f6f9;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --border: #e2e8f0;
  --text: #1e293b;
  --muted: #64748b;
  --accent: #1f5f8b;
  --accent-text: #ffffff;
  --accent-soft: #e3eef7;
  --ok: #15803d;
  --ok-soft: #dcfce7;
  --warn: #b45309;
  --warn-soft: #fef3c7;
  --bad: #b91c1c;
  --bad-soft: #fee2e2;
  --neutral-soft: #eef2f6;
  --sidebar: #16324a;
  --sidebar-text: #c9d7e4;
  --sidebar-active: #234a6b;
  --shadow: 0 1px 2px rgba(15, 23, 42, .06), 0 1px 3px rgba(15, 23, 42, .08);
  --radius: 8px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "Cascadia Mono", Consolas, monospace;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f172a;
    --surface: #162033;
    --surface-2: #1b273d;
    --border: #2a3850;
    --text: #e2e8f0;
    --muted: #94a3b8;
    --accent: #4f9fd6;
    --accent-text: #0b1726;
    --accent-soft: #1c3550;
    --ok: #4ade80;
    --ok-soft: #14361f;
    --warn: #fbbf24;
    --warn-soft: #3a2c0c;
    --bad: #f87171;
    --bad-soft: #3d1717;
    --neutral-soft: #223047;
    --sidebar: #0b1322;
    --sidebar-text: #a9b8c9;
    --sidebar-active: #1c2c44;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); color: var(--text); font: 14px/1.45 var(--font); }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 22px; margin: 0; font-weight: 650; }
h2 { font-size: 16px; margin: 0 0 12px; font-weight: 650; }
h3 { font-size: 14px; margin: 0 0 8px; font-weight: 650; }
code, .mono { font-family: var(--mono); font-size: 12.5px; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.nowrap { white-space: nowrap; }
.right { text-align: right; }
.hidden { display: none !important; }

/* ---- shell ---- */
.shell { display: grid; grid-template-columns: 228px 1fr; min-height: 100vh; }
.sidebar { background: var(--sidebar); color: var(--sidebar-text); padding: 16px 10px; display: flex; flex-direction: column; gap: 2px; position: sticky; top: 0; height: 100vh; }
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 10px 18px; color: #fff; font-weight: 650; font-size: 15px; }
.brand img { width: 28px; height: 28px; }
.brand small { display: block; font-weight: 400; color: var(--sidebar-text); font-size: 11.5px; }
.nav a { display: flex; align-items: center; gap: 10px; padding: 8px 12px; border-radius: 6px; color: var(--sidebar-text); text-decoration: none; }
.nav a:hover { background: var(--sidebar-active); color: #fff; }
.nav a.active { background: var(--sidebar-active); color: #fff; font-weight: 600; }
.nav .count { margin-left: auto; background: var(--warn); color: #111; border-radius: 10px; font-size: 11px; padding: 0 7px; font-weight: 700; }
.nav-section { padding: 14px 12px 4px; font-size: 11px; text-transform: uppercase; letter-spacing: .06em; opacity: .6; }
.sidebar .spacer { flex: 1; }
.sidebar .me { padding: 10px 12px; font-size: 12.5px; border-top: 1px solid rgba(255,255,255,.08); }
.sidebar .me button { margin-top: 6px; }
.main { padding: 22px 28px 40px; min-width: 0; }
.page-head { display: flex; align-items: center; gap: 12px; margin-bottom: 18px; flex-wrap: wrap; }
.page-head .actions { margin-left: auto; display: flex; gap: 8px; flex-wrap: wrap; }
.crumb { font-size: 12.5px; color: var(--muted); margin-bottom: 4px; }

/* ---- cards & grid ---- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px 18px; margin-bottom: 16px; }
.card.flush { padding: 0; overflow: hidden; }
.card.flush > h2 { padding: 14px 18px 0; }
.grid { display: grid; gap: 16px; }
.grid.stats { grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); margin-bottom: 16px; }
.grid.two { grid-template-columns: repeat(auto-fit, minmax(380px, 1fr)); }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); }
.stat .label { color: var(--muted); font-size: 12.5px; }
.stat .value { font-size: 26px; font-weight: 650; margin-top: 2px; }
.stat .sub { font-size: 12.5px; margin-top: 2px; }
.stat a { color: inherit; }
dl.props { display: grid; grid-template-columns: max-content 1fr; gap: 6px 18px; margin: 0; }
dl.props dt { color: var(--muted); }
dl.props dd { margin: 0; overflow-wrap: anywhere; }

/* ---- tables ---- */
.table-wrap { overflow-x: auto; }
table.list { width: 100%; border-collapse: collapse; }
table.list th { text-align: left; font-weight: 600; font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; padding: 10px 14px; border-bottom: 1px solid var(--border); background: var(--surface-2); white-space: nowrap; }
table.list td { padding: 10px 14px; border-bottom: 1px solid var(--border); vertical-align: middle; }
table.list tr:last-child td { border-bottom: 0; }
table.list tr.clickable { cursor: pointer; }
table.list tr.clickable:hover td { background: var(--surface-2); }
table.list td.actions { text-align: right; }
table.list td.actions button { margin: 2px 0 2px 4px; }
table.list tfoot td { font-weight: 650; background: var(--surface-2); }
.empty { padding: 28px 18px; text-align: center; color: var(--muted); }

/* ---- badges ---- */
.badge { display: inline-flex; align-items: center; gap: 6px; padding: 2px 9px; border-radius: 999px; font-size: 12px; font-weight: 600; background: var(--neutral-soft); color: var(--muted); white-space: nowrap; }
.badge::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.badge.plain::before { display: none; }
.badge.up, .badge.active { background: var(--ok-soft); color: var(--ok); }
.badge.degraded, .badge.pending, .badge.trial { background: var(--warn-soft); color: var(--warn); }
.badge.down, .badge.disabled, .badge.suspended { background: var(--bad-soft); color: var(--bad); }
.badge.info { background: var(--accent-soft); color: var(--accent); }
.tag { display: inline-block; padding: 1px 8px; border-radius: 4px; background: var(--neutral-soft); font-size: 12px; margin: 1px 4px 1px 0; }

/* ---- buttons & forms ---- */
button, .btn { font: inherit; border: 1px solid var(--border); background: var(--surface); color: var(--text); border-radius: 6px; padding: 7px 13px; cursor: pointer; display: inline-flex; align-items: center; gap: 6px; text-decoration: none; }
button:hover, .btn:hover { background: var(--surface-2); text-decoration: none; }
button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); font-weight: 600; }
button.primary:hover { filter: brightness(1.08); }
button.danger { color: var(--bad); }
button.small { padding: 3px 9px; font-size: 12.5px; }
button.link { border: 0; background: none; color: var(--accent); padding: 0; }
button:disabled { opacity: .55; cursor: default; }
.sidebar button { background: transparent; color: var(--sidebar-text); border-color: rgba(255,255,255,.15); }
.sidebar button:hover { background: var(--sidebar-active); color: #fff; }

input, select, textarea { font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--border); border-radius: 6px; padding: 7px 10px; width: 100%; }
input:focus, select:focus, textarea:focus, button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
textarea { min-height: 80px; resize: vertical; }
input[type=checkbox] { width: auto; }
.field { display: flex; flex-direction: column; gap: 4px; }
.field label { font-weight: 600; font-size: 12.5px; }
.field .hint { font-size: 12px; color: var(--muted); }
.field.check { flex-direction: row; align-items: center; gap: 8px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px 14px; }
.form-grid .wide { grid-column: 1 / -1; }
.toolbar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-bottom: 12px; }
.toolbar input, .toolbar select { width: auto; min-width: 200px; }
.access-row { display: grid; grid-template-columns: 24px 1fr 160px; gap: 8px; align-items: center; padding: 4px 0; }

/* ---- dialog ---- */
dialog { border: 1px solid var(--border); border-radius: 10px; padding: 0; background: var(--surface); color: var(--text); width: min(640px, 94vw); box-shadow: 0 20px 50px rgba(0,0,0,.25); }
dialog::backdrop { background: rgba(15, 23, 42, .45); }
dialog .dlg-head { padding: 16px 20px 0; }
dialog .dlg-body { padding: 14px 20px; max-height: 70vh; overflow: auto; }
dialog .dlg-foot { padding: 12px 20px 16px; display: flex; justify-content: flex-end; gap: 8px; border-top: 1px solid var(--border); }
.error-box { background: var(--bad-soft); color: var(--bad); padding: 8px 12px; border-radius: 6px; margin-bottom: 10px; }
.secret-box { background: var(--warn-soft); border: 1px solid var(--warn); border-radius: 6px; padding: 10px 12px; }
.secret-box code { display: block; margin: 6px 0; padding: 8px; background: var(--surface); border-radius: 4px; word-break: break-all; user-select: all; }

/* ---- toast ---- */
#toasts { position: fixed; right: 18px; bottom: 18px; display: flex; flex-direction: column; gap: 8px; z-index: 50; }
.toast { background: var(--text); color: var(--bg); padding: 10px 14px; border-radius: 6px; box-shadow: var(--shadow); max-width: 380px; }
.toast.bad { background: var(--bad); color: #fff; }

/* ---- login ---- */
.login { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.login .card { width: min(400px, 100%); padding: 28px; }
.login .brand { color: var(--text); padding: 0 0 18px; }
.login .brand small { color: var(--muted); }
.login form { display: flex; flex-direction: column; gap: 12px; }
.login .note { background: var(--accent-soft); padding: 10px 12px; border-radius: 6px; }

/* ---- host metrics: meters, tiles, charts ---- */
.card-head { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 12px; }
.card-head h2 { margin: 0; }
.card-head .segmented { margin-left: auto; }
.segmented { display: inline-flex; gap: 4px; }
.segmented button.on { background: var(--accent-soft); color: var(--accent); border-color: var(--accent); font-weight: 600; }
.grid.host-stats { grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); margin-bottom: 16px; }
.host .stat { box-shadow: none; }
.host .stat .value { font-size: 22px; }
svg.meter { display: block; width: 100%; height: 6px; margin-top: 6px; }
.meter-track { fill: var(--neutral-soft); }
.meter.ok .meter-fill { fill: var(--ok); }
.meter.warn .meter-fill { fill: var(--warn); }
.meter.bad .meter-fill { fill: var(--bad); }
.usage { display: flex; gap: 14px; flex-wrap: wrap; font-size: 12.5px; }
.usage-item { display: inline-block; min-width: 90px; white-space: nowrap; }
.usage-item svg.meter { margin-top: 3px; }
.grid.charts { grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); margin-bottom: 8px; }
.chart h3 { margin-bottom: 4px; }
.chart-plot { position: relative; min-height: 150px; }
.chart-svg { display: block; }
.chart-grid { stroke: var(--border); stroke-width: 1; }
.chart-label { fill: var(--muted); font-size: 11px; font-family: var(--font); }
.chart-line { fill: none; stroke: var(--accent); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.chart-area { fill: var(--accent); opacity: .12; }
.chart-cross { stroke: var(--muted); stroke-width: 1; stroke-dasharray: 3 3; }
.chart-dot { fill: var(--accent); stroke: var(--surface); stroke-width: 2; }
.chart-hit { fill: transparent; cursor: crosshair; }
.chart-tip { position: absolute; transform: translateX(-50%); background: var(--surface); border: 1px solid var(--border); border-radius: 6px;
  box-shadow: var(--shadow); padding: 3px 8px; font-size: 12px; white-space: nowrap; pointer-events: none; }
.chart-empty { position: absolute; inset: 40% 0 auto; text-align: center; }

/* ---- plan limits editor ---- */
.limits-editor { display: flex; flex-direction: column; gap: 6px; align-items: flex-start; }
.limit-rows { display: flex; flex-direction: column; gap: 6px; width: 100%; }
.limit-row { display: grid; grid-template-columns: 1fr 120px auto; gap: 6px; align-items: center; }

/* ---- small screens ---- */
@media (max-width: 860px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; flex-direction: row; flex-wrap: wrap; align-items: center; }
  .sidebar .nav-section, .sidebar .spacer { display: none; }
  .brand { padding: 4px 10px; }
  .nav { display: flex; flex-wrap: wrap; }
  .main { padding: 16px; }
  .form-grid { grid-template-columns: 1fr; }
  .grid.two { grid-template-columns: 1fr; }
}

/* ---- utilities (no inline styles: the CSP blocks them) ---- */
.pad { padding: 10px 18px; }
.pad-x { padding: 0 18px; }
.mt2 { margin: 2px 0; }
.bad-text { color: var(--bad); }
.code-block { background: var(--surface-2); border: 1px solid var(--border); border-radius: 6px; padding: 10px 12px; white-space: pre-wrap; margin: 8px 0; }
