/* ============================================================
   Template MVC — design system
   CSS custom properties drive light/dark theming. Default is the
   light palette; dark either follows the OS (prefers-color-scheme)
   or is forced via [data-theme] set by app.js from a user toggle.
   ============================================================ */

:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --surface-hover: #f8f9fb;
  --border: #e3e5ea;
  --text: #14161a;
  --text-muted: #6b7280;
  --text-faint: #9aa0ab;

  --primary: #4f46e5;
  --primary-hover: #4338ca;
  --primary-soft: #eef0fe;
  --primary-contrast: #ffffff;

  --success: #178a4c;
  --success-soft: #e6f6ed;
  --danger: #d92d20;
  --danger-soft: #fdeeec;
  --warning: #b54708;
  --warning-soft: #fef3e0;
  --info: #175cd3;
  --info-soft: #eaf1fd;

  --shadow-sm: 0 1px 2px rgba(16, 24, 40, .06);
  --shadow-md: 0 4px 12px rgba(16, 24, 40, .08);
  --shadow-lg: 0 16px 40px rgba(16, 24, 40, .16);

  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;

  --sidebar-w: 240px;
  --topbar-h: 64px;

  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0d0e12;
    --surface: #16181d;
    --surface-hover: #1c1f26;
    --border: #2a2d35;
    --text: #f1f2f4;
    --text-muted: #9aa0ab;
    --text-faint: #6b7280;

    --primary: #818cf8;
    --primary-hover: #a5b4fc;
    --primary-soft: #1e1b3d;
    --primary-contrast: #0d0e12;

    --success: #3dd68c;
    --success-soft: #0f2b1d;
    --danger: #f97066;
    --danger-soft: #2e1512;
    --warning: #f79009;
    --warning-soft: #2e2008;
    --info: #6fa8f5;
    --info-soft: #10233d;

    --shadow-sm: 0 1px 2px rgba(0, 0, 0, .4);
    --shadow-md: 0 4px 16px rgba(0, 0, 0, .5);
    --shadow-lg: 0 20px 48px rgba(0, 0, 0, .6);

    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  --bg: #0d0e12;
  --surface: #16181d;
  --surface-hover: #1c1f26;
  --border: #2a2d35;
  --text: #f1f2f4;
  --text-muted: #9aa0ab;
  --text-faint: #6b7280;

  --primary: #818cf8;
  --primary-hover: #a5b4fc;
  --primary-soft: #1e1b3d;
  --primary-contrast: #0d0e12;

  --success: #3dd68c;
  --success-soft: #0f2b1d;
  --danger: #f97066;
  --danger-soft: #2e1512;
  --warning: #f79009;
  --warning-soft: #2e2008;
  --info: #6fa8f5;
  --info-soft: #10233d;

  --shadow-sm: 0 1px 2px rgba(0, 0, 0, .4);
  --shadow-md: 0 4px 16px rgba(0, 0, 0, .5);
  --shadow-lg: 0 20px 48px rgba(0, 0, 0, .6);

  color-scheme: dark;
}

/* ---------- reset ---------- */
*, *::before, *::after { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.55 -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  transition: background-color .15s ease, color .15s ease;
}
h1, h2, h3, h4, p { margin: 0 0 .5em; }
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
img { max-width: 100%; }
button, input, select, textarea { font: inherit; color: inherit; }
ul { margin: 0; padding: 0; list-style: none; }

/* ---------- app shell: nav sidebar on the left, content on the right ---------- */
.app-shell {
  display: flex;
  min-height: 100vh;
}

.app-main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.topbar {
  height: var(--topbar-h);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0 1.5rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 20;
}

.topbar-title { font-size: 1.05rem; font-weight: 700; letter-spacing: -.01em; }

.topbar-actions { display: flex; align-items: center; gap: .5rem; }

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 38px;
  height: 38px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-muted);
  cursor: pointer;
}
.icon-btn:hover { background: var(--surface-hover); color: var(--text); }
.icon-btn svg { width: 18px; height: 18px; }

/* theme toggle: show the icon for the theme you'd switch TO */
.theme-icon-light { display: none; }
.theme-icon-dark { display: inline-flex; }
:root[data-theme="dark"] .theme-icon-dark { display: none; }
:root[data-theme="dark"] .theme-icon-light { display: inline-flex; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]):not([data-theme="dark"]) .theme-icon-dark { display: none; }
  :root:not([data-theme="light"]):not([data-theme="dark"]) .theme-icon-light { display: inline-flex; }
}

.menu-toggle { display: none; }

.app-content {
  flex: 1;
  padding: 1.75rem;
 /* max-width: 1180px;*/
  width: 100%;
  margin: 0 auto;
}

/* ---------- sidebar (left-hand nav) ---------- */
.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
}

.sidebar-brand {
  height: var(--topbar-h);
  display: flex;
  align-items: center;
  gap: .6rem;
  padding: 0 1.25rem;
  border-bottom: 1px solid var(--border);
  font-weight: 800;
  letter-spacing: -.02em;
  font-size: 1.05rem;
}

.brand-mark {
  width: 28px; height: 28px;
  border-radius: 8px;
  background: linear-gradient(135deg, var(--primary), #ec4899);
  flex-shrink: 0;
}

.brand-logo {
  height: 28px;
  width: auto;
  max-width: 120px;
  border-radius: 6px;
  flex-shrink: 0;
  object-fit: contain;
}

.sidebar-user {
  display: flex;
  align-items: center;
  gap: .65rem;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border);
}

.avatar {
  width: 36px; height: 36px;
  border-radius: 50%;
  background: var(--primary-soft);
  color: var(--primary);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: .85rem;
  flex-shrink: 0;
}

.sidebar-user-name { font-weight: 600; font-size: .88rem; line-height: 1.2; }
.sidebar-user-role {
  font-size: .74rem;
  color: var(--text-muted);
  text-transform: capitalize;
}

.sidebar-nav { flex: 1; overflow-y: auto; padding: .75rem; }

.nav-link {
  display: flex;
  align-items: center;
  gap: .7rem;
  padding: .6rem .75rem;
  border-radius: var(--radius-md);
  color: var(--text-muted);
  font-size: .88rem;
  font-weight: 500;
  margin-bottom: .15rem;
}
.nav-link:hover { background: var(--surface-hover); color: var(--text); text-decoration: none; }
.nav-link.active { background: var(--primary-soft); color: var(--primary); }
.nav-link svg { width: 18px; height: 18px; flex-shrink: 0; }

.sidebar-footer { padding: .75rem 1.25rem 1.1rem; border-top: 1px solid var(--border); }

.logout-form { margin: 0; }
.logout-link {
  display: flex;
  align-items: center;
  gap: .7rem;
  width: 100%;
  padding: .6rem .75rem;
  border-radius: var(--radius-md);
  color: var(--text-muted);
  font-size: .88rem;
  font-weight: 500;
  background: none;
  border: none;
  cursor: pointer;
  text-align: left;
}
.logout-link:hover { background: var(--danger-soft); color: var(--danger); }
.logout-link svg { width: 18px; height: 18px; }

/* ---------- cards / surfaces ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  padding: 1.5rem;
}
.card + .card { margin-top: 1.25rem; }
.card-title { font-size: 1.05rem; font-weight: 700; margin-bottom: 1.1rem; letter-spacing: -.01em; }
.card-title .muted { font-weight: 400; color: var(--text-muted); font-size: .85rem; display: block; margin-top: .15rem; }

.grid { display: grid; gap: 1.25rem; }
.grid-2 { grid-template-columns: repeat(2, 1fr); }
.grid-4 { grid-template-columns: repeat(4, 1fr); }
@media (max-width: 880px) { .grid-2, .grid-4 { grid-template-columns: 1fr 1fr; } }
@media (max-width: 560px) { .grid-2, .grid-4 { grid-template-columns: 1fr; } }

.settings-grid { display: grid; grid-template-columns: 1.6fr 1fr; gap: 1.25rem; align-items: start; }
@media (max-width: 880px) { .settings-grid { grid-template-columns: 1fr; } }

/* ---------- stat tiles ---------- */
.stat-tile { padding: 1.25rem 1.4rem; }
.stat-label { font-size: .78rem; text-transform: uppercase; letter-spacing: .04em; color: var(--text-muted); font-weight: 600; }
.stat-value { font-size: 1.9rem; font-weight: 800; margin-top: .3rem; letter-spacing: -.02em; }

/* ---------- forms ---------- */
.field { margin-bottom: 1.1rem; }
.field label {
  display: block;
  font-size: .82rem;
  font-weight: 600;
  margin-bottom: .4rem;
  color: var(--text);
}
.field .hint { font-size: .78rem; color: var(--text-muted); margin-top: .35rem; }

.input, select.input {
  width: 100%;
  padding: .6rem .75rem;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-size: .92rem;
  transition: border-color .12s ease, box-shadow .12s ease;
}
.input:focus, select.input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-soft);
}
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
@media (max-width: 560px) { .field-row { grid-template-columns: 1fr; } }

.field-error { color: var(--danger); font-size: .78rem; margin-top: .35rem; }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: .45rem;
  padding: .62rem 1.1rem;
  border-radius: var(--radius-md);
  border: 1px solid transparent;
  font-size: .88rem;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  transition: background-color .12s ease, border-color .12s ease, color .12s ease;
}
.btn:hover { text-decoration: none; }
.btn-block { width: 100%; }
.btn-sm { padding: .4rem .75rem; font-size: .8rem; }

.btn-primary { background: var(--primary); border-color: var(--primary); color: var(--primary-contrast); }
.btn-primary:hover { background: var(--primary-hover); border-color: var(--primary-hover); }

.btn-outline { background: transparent; border-color: var(--border); color: var(--text); }
.btn-outline:hover { background: var(--surface-hover); }

.btn-danger { background: transparent; border-color: var(--border); color: var(--danger); }
.btn-danger:hover { background: var(--danger-soft); border-color: var(--danger-soft); }

.btn-success { background: var(--success); border-color: var(--success); color: #fff; }
.btn-success:hover { filter: brightness(.93); }

.btn-link {
  background: none; border: none; padding: 0; color: var(--primary);
  font-weight: 600; font-size: inherit; cursor: pointer;
}
.btn-link:hover { text-decoration: underline; }

/* ---------- tables ---------- */
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: .88rem; }
.table th {
  text-align: left;
  font-size: .72rem;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--text-muted);
  font-weight: 700;
  padding: .5rem .9rem .7rem;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.table td { padding: .8rem .9rem; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table tr:last-child td { border-bottom: none; }
.table tr:hover td { background: var(--surface-hover); }
.table-actions { display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; }
.table-actions form { margin: 0; }

/* ---------- badges ---------- */
.badge {
  display: inline-flex;
  align-items: center;
  padding: .2rem .6rem;
  border-radius: 999px;
  font-size: .72rem;
  font-weight: 700;
  text-transform: capitalize;
}
.badge-success { background: var(--success-soft); color: var(--success); }
.badge-danger { background: var(--danger-soft); color: var(--danger); }
.badge-muted { background: var(--bg); color: var(--text-muted); border: 1px solid var(--border); }
.badge-primary { background: var(--primary-soft); color: var(--primary); }

/* ---------- alerts / flash ---------- */
.alert {
  display: flex;
  align-items: flex-start;
  gap: .6rem;
  padding: .8rem 1rem;
  border-radius: var(--radius-md);
  font-size: .86rem;
  margin-bottom: .8rem;
  border: 1px solid transparent;
}
.alert-success { background: var(--success-soft); color: var(--success); }
.alert-error { background: var(--danger-soft); color: var(--danger); }
.alert-info { background: var(--info-soft); color: var(--info); }
.alert-warning { background: var(--warning-soft); color: var(--warning); }

/* ---------- auth pages (centered card, no sidebar) ---------- */
.auth-shell {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 2rem 1rem;
  background:
    radial-gradient(900px 480px at 15% -10%, var(--primary-soft), transparent),
    var(--bg);
}
.auth-card {
  width: 100%;
  max-width: 400px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  padding: 2.25rem 2rem;
}
.auth-card.auth-card-wide { max-width: 460px; }
.auth-brand {
  display: flex;
  align-items: center;
  gap: .6rem;
  font-weight: 800;
  font-size: 1.05rem;
  margin-bottom: 1.5rem;
  letter-spacing: -.02em;
}
.auth-title { font-size: 1.3rem; font-weight: 800; letter-spacing: -.02em; margin-bottom: .3rem; }
.auth-subtitle { color: var(--text-muted); font-size: .88rem; margin-bottom: 1.5rem; }
.auth-footer { text-align: center; margin-top: 1.4rem; font-size: .86rem; color: var(--text-muted); }
.auth-theme-toggle { position: fixed; top: 1.25rem; right: 1.25rem; }

.qr-box {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: .75rem;
  padding: 1.25rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  margin-bottom: 1.25rem;
}
.qr-box img { border-radius: var(--radius-sm); background: #fff; padding: 8px; }
.secret-code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  background: var(--surface);
  border: 1px solid var(--border);
  padding: .4rem .6rem;
  border-radius: var(--radius-sm);
  font-size: .8rem;
  letter-spacing: .05em;
  word-break: break-all;
}

.empty-state { text-align: center; padding: 2.5rem 1rem; color: var(--text-muted); }

.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1.5rem;
  flex-wrap: wrap;
}
.page-header h1 { font-size: 1.4rem; letter-spacing: -.02em; }

/* ---------- responsive: collapse sidebar to an off-canvas drawer ---------- */
@media (max-width: 900px) {
  .menu-toggle { display: inline-flex; }
  .sidebar {
    position: fixed;
    top: 0; left: 0; bottom: 0;
    z-index: 40;
    transform: translateX(-100%);
    transition: transform .2s ease;
    box-shadow: var(--shadow-lg);
  }
  .sidebar.is-open { transform: translateX(0); }
  .sidebar-backdrop {
    display: none;
    position: fixed; inset: 0;
    background: rgba(0,0,0,.4);
    z-index: 30;
  }
  .sidebar-backdrop.is-open { display: block; }
  .app-content { padding: 1.25rem; }
}

/* ======================================================================
   RC Hosting additions — utilisation meters, filters, detail lists
   ====================================================================== */
.badge-warning { background: var(--warning-soft); color: var(--warning); }
.badge.platform-proxmox { background: #fff1e6; color: #c2410c; }
.badge.platform-hyperv { background: var(--info-soft); color: var(--info); }
:root[data-theme="dark"] .badge.platform-proxmox { background: #3a1d0a; color: #fdba74; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .badge.platform-proxmox { background: #3a1d0a; color: #fdba74; } }

.muted { color: var(--text-muted); }
.small { font-size: .8rem; }
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.table th.num { text-align: right; }
.nowrap { white-space: nowrap; }
.table td a { font-weight: 600; }
.table.compact td { padding: .5rem .75rem; }
.table tfoot td { font-weight: 700; border-top: 2px solid var(--border); }

.meter-wrap { display: flex; align-items: center; gap: .5rem; min-width: 130px; }
.meter { flex: 1; height: 8px; background: var(--bg); border: 1px solid var(--border); border-radius: 999px; overflow: hidden; min-width: 60px; }
.meter-fill { height: 100%; border-radius: 999px; }
.meter-label { font-size: .78rem; font-weight: 700; min-width: 2.6rem; text-align: right; font-variant-numeric: tabular-nums; }
.meter-caption { font-size: .75rem; color: var(--text-muted); white-space: nowrap; }
.lvl-ok { background: var(--success); }
.lvl-warn { background: #f59e0b; }
.lvl-crit, .lvl-over { background: var(--danger); }
.lvl-text-warn { color: var(--warning); }
.lvl-text-crit, .lvl-text-over { color: var(--danger); }

.grid-3 { grid-template-columns: repeat(3, 1fr); }
.grid-5 { grid-template-columns: repeat(5, 1fr); }
@media (max-width: 1100px) { .grid-5 { grid-template-columns: repeat(3, 1fr); } }
@media (max-width: 880px) { .grid-3, .grid-5 { grid-template-columns: 1fr 1fr; } }
@media (max-width: 560px) { .grid-3, .grid-5 { grid-template-columns: 1fr; } }
.grid + .card, .grid + .grid, .card + .card { margin-top: 1.25rem; }
.stat-sub { font-size: .8rem; color: var(--text-muted); margin-top: .35rem; }
.stat-tile .meter-wrap { margin-top: .6rem; }

.filters { display: flex; flex-wrap: wrap; gap: .6rem; align-items: flex-end; margin-bottom: 1rem; }
.filters .field { margin: 0; min-width: 150px; }
.filters .input { padding-top: .45rem; padding-bottom: .45rem; }

.kv { display: grid; grid-template-columns: max-content 1fr; gap: .45rem 1.25rem; font-size: .9rem; }
.kv dt { color: var(--text-muted); font-weight: 600; }
.kv dd { margin: 0; }

.field-row-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1rem; }
.field-row-4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 1rem; }
@media (max-width: 720px) { .field-row-3, .field-row-4 { grid-template-columns: 1fr 1fr; } }
@media (max-width: 480px) { .field-row-3, .field-row-4 { grid-template-columns: 1fr; } }
.form-section { font-size: .78rem; text-transform: uppercase; letter-spacing: .05em; font-weight: 700; color: var(--text-muted); margin: 1.4rem 0 .7rem; padding-top: 1rem; border-top: 1px solid var(--border); }
.check { display: flex; align-items: center; gap: .45rem; font-weight: 600; cursor: pointer; }
.issue-list { margin: 0; padding-left: 1.1rem; list-style: disc; color: var(--danger); font-size: .82rem; }
.page-header .actions { display: flex; gap: .5rem; flex-wrap: wrap; }
.subtitle { color: var(--text-muted); margin-top: .25rem; font-size: .9rem; }
textarea.input { min-height: 80px; resize: vertical; }
.grid > * { min-width: 0; }
.stat-tile .meter-wrap { flex-wrap: wrap; min-width: 0; }
.stat-tile .meter-caption { flex-basis: 100%; }
.app-main { min-width: 0; }
.grid > .card + .card { margin-top: 0; }
.repeat-row { border: 1px solid var(--border); border-radius: var(--radius-md); padding: .8rem .9rem 0; margin-bottom: .7rem; background: var(--surface-hover); }
.repeat-row .field { margin-bottom: .8rem; }
.repeat-row label { font-size: .75rem; }
.hint { font-size: .78rem; color: var(--text-muted); }
