/* Xena Panel - Material 3 dark blue theme, hand-rolled tokens */

:root {
  /* Material 3 dark "Google Blue" baseline palette */
  --md-sys-color-background: #111318;
  --md-sys-color-surface: #111318;
  --md-sys-color-surface-container: #1e2024;
  --md-sys-color-surface-container-low: #1a1c20;
  --md-sys-color-surface-container-high: #282a2f;
  --md-sys-color-surface-container-highest: #33353a;
  --md-sys-color-on-surface: #e2e2e9;
  --md-sys-color-on-surface-variant: #c4c6d0;

  --md-sys-color-primary: #a8c7fa;
  --md-sys-color-on-primary: #062e6f;
  --md-sys-color-primary-container: #284777;
  --md-sys-color-on-primary-container: #d3e3fd;

  --md-sys-color-outline: #8e9099;
  --md-sys-color-outline-variant: #44474e;

  --md-sys-color-error: #ffb4ab;
  --md-sys-color-on-error: #690005;
  --md-sys-color-error-container: #93000a;
  --md-sys-color-on-error-container: #ffdad6;

  --md-sys-color-success: #abd6ab;
  --md-sys-color-on-success: #1a3a1a;
  --md-sys-color-success-container: #2c4f2c;
  --md-sys-color-on-success-container: #c5ecc5;

  --md-sys-color-warning: #ffd599;
  --md-sys-color-on-warning: #4a2c00;
  --md-sys-color-warning-container: #5c3d00;
  --md-sys-color-on-warning-container: #ffe0bb;

  --md-shape-small: 8px;
  --md-shape-medium: 16px;
  --md-shape-large: 28px;
  --md-shape-full: 100px;
}

* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
  min-height: 100vh;
}

body {
  background: var(--md-sys-color-background);
  color: var(--md-sys-color-on-surface);
  font-family: 'Roboto', 'Segoe UI', system-ui, sans-serif;
  display: flex;
}

.material-symbols-outlined {
  font-variation-settings: 'FILL' 0, 'wght' 400, 'GRAD' 0, 'opsz' 24;
  font-size: 22px;
  line-height: 1;
  vertical-align: middle;
}

/* ---------- Nav rail ---------- */

.nav-rail {
  width: 220px;
  flex-shrink: 0;
  background: var(--md-sys-color-surface-container-low);
  border-right: 1px solid var(--md-sys-color-outline-variant);
  min-height: 100vh;
  padding: 16px 12px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.nav-rail .brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px 20px 12px;
  font-size: 1.1rem;
  font-weight: 500;
  color: var(--md-sys-color-on-surface);
}

.nav-rail .brand .material-symbols-outlined {
  color: var(--md-sys-color-primary);
  font-size: 26px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 10px 16px;
  border-radius: var(--md-shape-full);
  color: var(--md-sys-color-on-surface-variant);
  text-decoration: none;
  font-size: 0.92rem;
  font-weight: 500;
  transition: background 0.15s ease, color 0.15s ease;
}

.nav-item .material-symbols-outlined {
  color: inherit;
}

.nav-item:hover {
  background: var(--md-sys-color-surface-container-high);
  color: var(--md-sys-color-on-surface);
}

.nav-item.active {
  background: var(--md-sys-color-primary-container);
  color: var(--md-sys-color-on-primary-container);
}

.nav-rail .spacer {
  flex: 1;
}

.nav-rail .footer-note {
  padding: 8px 16px;
  font-size: 0.72rem;
  color: var(--md-sys-color-on-surface-variant);
  opacity: 0.7;
}

/* ---------- Main layout ---------- */

main {
  flex: 1;
  min-width: 0;
  padding: 24px 32px 48px;
  max-width: 1280px;
}

.topbar {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 24px;
}

.topbar h1 {
  font-size: 1.6rem;
  font-weight: 500;
  margin: 0;
}

.topbar .updated {
  font-size: 0.8rem;
  color: var(--md-sys-color-on-surface-variant);
}

/* ---------- Grid + cards ---------- */

.grid {
  display: grid;
  grid-template-columns: repeat(12, 1fr);
  gap: 20px;
}

.col-8 { grid-column: span 8; }
.col-4 { grid-column: span 4; }
.col-6 { grid-column: span 6; }
.col-12 { grid-column: span 12; }

@media (max-width: 900px) {
  .col-8, .col-4, .col-6, .col-12 { grid-column: span 12; }
  .nav-rail { display: none; }
}

.card {
  background: var(--md-sys-color-surface-container);
  border-radius: var(--md-shape-large);
  padding: 20px 22px;
}

.card h2 {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 1rem;
  font-weight: 500;
  margin: 0 0 16px 0;
  color: var(--md-sys-color-on-surface);
}

.card h2 .material-symbols-outlined {
  color: var(--md-sys-color-primary);
}

/* ---------- Dashboard summary cards ---------- */

.card-link {
  display: block;
  text-decoration: none;
  color: inherit;
}

.card-link .card {
  height: 100%;
  transition: background 0.15s ease, box-shadow 0.15s ease;
}

.card-link:hover .card {
  background: var(--md-sys-color-surface-container-high);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 1px 3px 1px rgba(0, 0, 0, 0.15);
}

.summary-stat {
  margin-bottom: 12px;
}

.summary-row {
  margin-bottom: 16px;
}

.card-cta {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  margin-top: 12px;
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--md-sys-color-primary);
}

.card-cta .material-symbols-outlined {
  font-size: 18px;
}

/* ---------- Row actions ---------- */

.row-action,
.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  color: var(--md-sys-color-on-surface-variant);
  text-decoration: none;
  border: none;
  background: transparent;
  cursor: pointer;
  font-family: inherit;
  padding: 0;
  transition: background 0.15s ease, color 0.15s ease;
}

.row-action:hover,
.icon-btn:hover {
  background: var(--md-sys-color-surface-container-high);
  color: var(--md-sys-color-on-surface);
}

.row-action .material-symbols-outlined,
.icon-btn .material-symbols-outlined {
  font-size: 20px;
}

.service-actions {
  display: flex;
  align-items: center;
  gap: 2px;
}

/* ---------- Table ---------- */

table {
  width: 100%;
  border-collapse: collapse;
}

th, td {
  text-align: left;
  padding: 10px 8px;
  font-size: 0.88rem;
  border-bottom: 1px solid var(--md-sys-color-outline-variant);
}

th {
  color: var(--md-sys-color-on-surface-variant);
  font-weight: 500;
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

tr:last-child td {
  border-bottom: none;
}

/* ---------- Chips ---------- */

.chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 12px;
  border-radius: var(--md-shape-full);
  font-size: 0.78rem;
  font-weight: 500;
  white-space: nowrap;
}

.chip.green {
  background: var(--md-sys-color-success-container);
  color: var(--md-sys-color-on-success-container);
}

.chip.amber {
  background: var(--md-sys-color-warning-container);
  color: var(--md-sys-color-on-warning-container);
}

.chip.red {
  background: var(--md-sys-color-error-container);
  color: var(--md-sys-color-on-error-container);
}

.chip.grey {
  background: var(--md-sys-color-surface-container-highest);
  color: var(--md-sys-color-on-surface-variant);
}

/* ---------- Rows (services list) ---------- */

.row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 9px 0;
  border-bottom: 1px solid var(--md-sys-color-outline-variant);
  font-size: 0.9rem;
}

.row:last-child {
  border-bottom: none;
}

.row .name {
  display: flex;
  align-items: center;
  gap: 10px;
}

.row .name .material-symbols-outlined {
  color: var(--md-sys-color-on-surface-variant);
  font-size: 20px;
}

/* ---------- Retractable sub-lists (e.g. mailcow containers) ---------- */

.subrow-details {
  margin: 0 0 4px;
  border-bottom: 1px solid var(--md-sys-color-outline-variant);
}

.subrow-details summary {
  cursor: pointer;
  padding: 9px 0;
  font-size: 0.85rem;
  color: var(--md-sys-color-on-surface-variant);
  list-style: none;
}

.subrow-details summary::-webkit-details-marker {
  display: none;
}

.subrow-details summary::before {
  content: 'expand_more';
  font-family: 'Material Symbols Outlined';
  font-size: 18px;
  vertical-align: -4px;
  margin-right: 6px;
  display: inline-block;
  transition: transform 0.15s ease;
}

.subrow-details[open] summary::before {
  transform: rotate(-180deg);
}

.subrow-details .subrow {
  padding-left: 28px;
  border-bottom: none;
}

.subrow-details .subrow:not(:last-child) {
  border-bottom: 1px solid var(--md-sys-color-outline-variant);
}

/* ---------- Stats ---------- */

.stat-line {
  display: flex;
  justify-content: space-between;
  font-size: 0.9rem;
  padding: 6px 0;
}

.stat-line .label {
  color: var(--md-sys-color-on-surface-variant);
}

.bar-track {
  height: 6px;
  border-radius: var(--md-shape-full);
  background: var(--md-sys-color-surface-container-highest);
  overflow: hidden;
  margin-top: 4px;
}

.bar-fill {
  height: 100%;
  background: var(--md-sys-color-primary);
  border-radius: var(--md-shape-full);
}

/* ---------- Files page ---------- */

.breadcrumbs {
  font-size: 0.9rem;
  margin-bottom: 12px;
  color: var(--md-sys-color-on-surface-variant);
}

.breadcrumbs a,
.row .name a {
  color: inherit;
  text-decoration: none;
  border-radius: var(--md-shape-small);
  padding: 2px 6px;
  margin: -2px -6px;
  transition: background 0.15s ease;
}

.breadcrumbs a:hover,
.row .name a:hover {
  background: var(--md-sys-color-surface-container-high);
  color: var(--md-sys-color-on-surface);
}

.breadcrumbs .sep {
  margin: 0 6px;
}

/* ---------- System page ---------- */

.refresh-control {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.8rem;
  color: var(--md-sys-color-on-surface-variant);
}

.refresh-control select {
  padding: 4px 8px;
  border-radius: var(--md-shape-small);
  border: 1px solid var(--md-sys-color-outline);
  background: var(--md-sys-color-surface-container-high);
  color: var(--md-sys-color-on-surface);
  font-family: inherit;
  font-size: 0.8rem;
}

#net-graph {
  width: 100%;
  height: 120px;
  display: block;
}

.graph-legend {
  display: flex;
  gap: 20px;
  margin-top: 8px;
  font-size: 0.8rem;
  color: var(--md-sys-color-on-surface-variant);
}

.legend-dot {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  margin-right: 6px;
}

/* ---------- Backups page ---------- */

.last-run-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 16px 32px;
  margin-bottom: 4px;
}

.last-run-grid .stat-line {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 6px;
  padding: 0;
}

.last-run-grid .stat-line .label {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.add-path-form {
  display: flex;
  gap: 8px;
  margin-top: 12px;
}

.add-path-form input[type="text"] {
  flex: 1;
  padding: 8px 12px;
  border-radius: var(--md-shape-small);
  border: 1px solid var(--md-sys-color-outline);
  background: var(--md-sys-color-surface-container-high);
  color: var(--md-sys-color-on-surface);
  font-family: inherit;
  font-size: 0.85rem;
}

.add-path-form input[type="text"]:focus {
  outline: 2px solid var(--md-sys-color-primary);
  outline-offset: -1px;
}

.row form {
  display: flex;
}

/* ---------- Login page ---------- */

.login-page {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  width: 100%;
}

.login-card {
  background: var(--md-sys-color-surface-container);
  border-radius: var(--md-shape-large);
  padding: 32px 36px;
  width: 100%;
  max-width: 360px;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 2px 6px 2px rgba(0, 0, 0, 0.15);
}

.login-card .brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 1.2rem;
  font-weight: 500;
  margin-bottom: 24px;
}

.login-card .brand .material-symbols-outlined {
  color: var(--md-sys-color-primary);
  font-size: 28px;
}

.field {
  margin-bottom: 18px;
}

.field label {
  display: block;
  font-size: 0.8rem;
  color: var(--md-sys-color-on-surface-variant);
  margin-bottom: 6px;
}

.field input {
  width: 100%;
  padding: 11px 14px;
  border-radius: var(--md-shape-small);
  border: 1px solid var(--md-sys-color-outline);
  background: var(--md-sys-color-surface-container-high);
  color: var(--md-sys-color-on-surface);
  font-size: 0.95rem;
  font-family: inherit;
}

.field input:focus {
  outline: 2px solid var(--md-sys-color-primary);
  outline-offset: -1px;
}

/* ---------- M3 filled text field ---------- */

.m3-field {
  position: relative;
  margin-bottom: 24px;
}

.m3-field input {
  width: 100%;
  height: 56px;
  padding: 22px 16px 8px 16px;
  border: none;
  border-radius: 4px 4px 0 0;
  background: var(--md-sys-color-surface-container-highest);
  border-bottom: 1px solid var(--md-sys-color-outline);
  color: var(--md-sys-color-on-surface);
  font-size: 1rem;
  font-family: inherit;
  transition: border-color 0.15s ease, padding-bottom 0.15s ease;
}

.m3-field input:hover {
  border-bottom-color: var(--md-sys-color-on-surface);
}

.m3-field input:focus {
  outline: none;
  border-bottom: 2px solid var(--md-sys-color-primary);
  padding-bottom: 7px;
}

.m3-field label {
  position: absolute;
  left: 16px;
  top: 18px;
  font-size: 1rem;
  color: var(--md-sys-color-on-surface-variant);
  transition: top 0.15s ease, font-size 0.15s ease, color 0.15s ease;
  pointer-events: none;
}

.m3-field input:focus + label,
.m3-field input:not(:placeholder-shown) + label {
  top: 8px;
  font-size: 0.7rem;
}

.m3-field input:focus + label {
  color: var(--md-sys-color-primary);
}

.m3-field input.has-toggle {
  padding-right: 48px;
}

.m3-field .toggle-visibility {
  position: absolute;
  right: 4px;
  top: 8px;
  width: 40px;
  height: 40px;
  border: none;
  background: transparent;
  color: var(--md-sys-color-on-surface-variant);
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.m3-field .toggle-visibility:hover {
  background: rgba(226, 226, 233, 0.08);
}

/* ---------- M3 filled button ---------- */

.btn-primary {
  width: 100%;
  height: 40px;
  padding: 0 24px;
  border-radius: var(--md-shape-full);
  border: none;
  background: var(--md-sys-color-primary);
  color: var(--md-sys-color-on-primary);
  font-size: 0.9rem;
  font-weight: 500;
  letter-spacing: 0.02em;
  font-family: inherit;
  cursor: pointer;
  margin-top: 8px;
  position: relative;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: box-shadow 0.15s ease;
}

.btn-primary::after {
  content: '';
  position: absolute;
  inset: 0;
  opacity: 0;
  background: var(--md-sys-color-on-primary);
  transition: opacity 0.15s ease;
}

.btn-primary:hover {
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 1px 3px 1px rgba(0, 0, 0, 0.15);
}

.btn-primary:hover::after {
  opacity: 0.08;
}

.btn-primary:active::after {
  opacity: 0.12;
}

.login-error {
  background: var(--md-sys-color-error-container);
  color: var(--md-sys-color-on-error-container);
  border-radius: var(--md-shape-small);
  padding: 10px 14px;
  font-size: 0.85rem;
  margin-bottom: 18px;
  display: flex;
  align-items: center;
  gap: 8px;
}

/* ---------- Profile page ---------- */

.avatar {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  object-fit: cover;
  background: var(--md-sys-color-surface-container-highest);
}

.nav-rail .brand .avatar {
  width: 28px;
  height: 28px;
}

.field-row {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-bottom: 18px;
}

.field input[type="file"] {
  padding: 8px;
}

.success-banner {
  background: var(--md-sys-color-success-container);
  color: var(--md-sys-color-on-success-container);
  border-radius: var(--md-shape-small);
  padding: 10px 14px;
  font-size: 0.85rem;
  margin-bottom: 18px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.qr-wrap {
  display: inline-block;
  background: #fff;
  padding: 12px;
  border-radius: var(--md-shape-small);
  margin: 8px 0 16px;
}

.qr-wrap img {
  display: block;
  width: 180px;
  height: 180px;
  image-rendering: pixelated;
}

.totp-secret {
  font-family: monospace;
  font-size: 0.95rem;
  background: var(--md-sys-color-surface-container-high);
  border-radius: var(--md-shape-small);
  padding: 10px 14px;
  word-break: break-all;
  margin: 8px 0 16px;
}

.help-text {
  font-size: 0.8rem;
  color: var(--md-sys-color-on-surface-variant);
  margin: 0 0 16px;
}

/* ---------- Error banner ---------- */

.banner {
  background: var(--md-sys-color-error-container);
  color: var(--md-sys-color-on-error-container);
  border-radius: var(--md-shape-medium);
  padding: 16px 20px;
  display: flex;
  align-items: center;
  gap: 10px;
}
