:root {
  --accent: #3D6BF0;
  --accent-deep: #2851C4;
  --accent-soft: #E9EFFE;
  --accent-soft-hover: #DCE6FD;
  --bg: #F6F8FC;
  --panel: #FFFFFF;
  --panel-2: #F0F3F9;
  --border: #E2E7F0;
  --border-soft: #ECEFF5;
  --text: #1B2233;
  --text-dim: #5B6478;
  --text-faint: #97A0B3;
  --good: #17A673;
  --good-soft: #E4F7EF;
  --bad: #E6494F;
  --bad-soft: #FCEAEA;
  --warn: #DE8A1F;
  --warn-soft: #FDF2E1;
  --mono: 'SFMono-Regular', Consolas, 'Liberation Mono', Menlo, monospace;
  --radius: 10px;
  --radius-lg: 14px;
  --shadow: 0 1px 2px rgba(20,30,60,0.05);
  --shadow-lift: 0 8px 28px rgba(20,30,60,0.14);
}

html[data-theme="dark"] {
  --accent: #5C8CFF;
  --accent-deep: #3D6BF0;
  --accent-soft: rgba(92,140,255,0.16);
  --accent-soft-hover: rgba(92,140,255,0.24);
  --bg: #10151f;
  --panel: #161c29;
  --panel-2: #1c2333;
  --border: #2a3245;
  --border-soft: #212939;
  --text: #E3E8F2;
  --text-dim: #93A0B8;
  --text-faint: #5C6884;
  --good: #35D488;
  --good-soft: rgba(53,212,136,0.14);
  --bad: #FF5D66;
  --bad-soft: rgba(255,93,102,0.14);
  --warn: #F0B53C;
  --warn-soft: rgba(240,181,60,0.14);
  --shadow-lift: 0 12px 32px rgba(0,0,0,0.45);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  transition: background .2s ease, color .2s ease;
}

::selection { background: var(--accent-soft-hover); }

button { font-family: inherit; cursor: pointer; }
input, select { font-family: inherit; }

#app { height: 100%; }

/* ---------- Login / setup / pwchange screens ---------- */
.login-screen {
  height: 100vh;
  height: 100dvh; /* mobile Safari: 100vh ignores the address bar's actual on-screen height */
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  background:
    radial-gradient(circle at 20% 20%, rgba(61,107,240,0.10), transparent 40%),
    radial-gradient(circle at 80% 80%, rgba(61,107,240,0.08), transparent 40%),
    var(--bg);
}

.view.active.login-screen {
  display: flex;
  align-items: center;
  justify-content: center;
}

.login-card {
  width: 380px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 40px 36px 32px;
  box-shadow: var(--shadow-lift);
}

.login-logo {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  margin-bottom: 28px;
}

.login-logo .mark {
  width: 34px;
  height: 34px;
  border-radius: 9px;
  background: linear-gradient(135deg, var(--accent), var(--accent-deep));
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-weight: 700;
  font-size: 16px;
}

.login-logo .word {
  font-size: 20px;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--text);
}

.login-title {
  text-align: center;
  font-size: 14px;
  color: var(--text-dim);
  margin: 0 0 26px;
}

.field-group { margin-bottom: 16px; }

.field-group label {
  display: block;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text-dim);
  margin-bottom: 6px;
}

.field-group input {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 14px;
  background: var(--panel);
  color: var(--text);
  outline: none;
  transition: border-color .15s ease, box-shadow .15s ease;
}

.field-group input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.btn {
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--text);
  padding: 9px 16px;
  border-radius: var(--radius);
  font-size: 13.5px;
  font-weight: 600;
  transition: background .15s ease, border-color .15s ease, transform .05s ease;
}
.btn:hover { background: var(--panel-2); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .55; cursor: default; }

.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}
.btn-primary:hover { background: var(--accent-deep); }

.btn-full { width: 100%; }

.btn-danger {
  background: var(--panel);
  border-color: rgba(230,73,79,0.4);
  color: var(--bad);
}
.btn-danger:hover { background: var(--bad-soft); }

.btn-warn {
  background: var(--panel);
  border-color: rgba(222,138,31,0.45);
  color: var(--warn);
}
.btn-warn:hover { background: var(--warn-soft); }

.login-submit { margin-top: 6px; }

.login-foot {
  text-align: center;
  margin-top: 20px;
  font-size: 12.5px;
  color: var(--text-faint);
}
.login-foot a { color: var(--accent); text-decoration: none; cursor: pointer; }
.login-foot a:hover { text-decoration: underline; }

.form-error {
  background: var(--bad-soft);
  color: var(--bad);
  font-size: 12.5px;
  font-weight: 600;
  padding: 9px 12px;
  border-radius: var(--radius);
  margin-bottom: 16px;
}

.note-box {
  background: var(--warn-soft);
  color: var(--warn);
  font-size: 12px;
  font-weight: 600;
  padding: 9px 12px;
  border-radius: var(--radius);
  margin-top: 10px;
  line-height: 1.4;
}

/* ---------- App shell ---------- */
.shell {
  display: flex;
  height: 100vh;
  height: 100dvh; /* mobile Safari: 100vh ignores the address bar's actual on-screen height */
  width: 100%;
}

.view.active.shell {
  display: flex;
}

.sidebar {
  width: 224px;
  flex-shrink: 0;
  background: var(--panel);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 20px 14px;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 6px 8px 22px;
}

.sidebar-brand .mark {
  width: 26px;
  height: 26px;
  border-radius: 7px;
  background: linear-gradient(135deg, var(--accent), var(--accent-deep));
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-weight: 700;
  font-size: 13px;
}

.sidebar-brand .word {
  font-size: 15.5px;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.nav-group { margin-bottom: 18px; }

.nav-label {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-faint);
  padding: 0 10px;
  margin-bottom: 6px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: 8px;
  font-size: 13.5px;
  color: var(--text-dim);
  cursor: pointer;
  margin-bottom: 2px;
  border: 1px solid transparent;
  user-select: none;
}

.nav-item .ic { width: 18px; text-align: center; font-size: 14px; }

.nav-item:hover { background: var(--panel-2); color: var(--text); }

.nav-item.active {
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 700;
}

.sidebar-foot {
  margin-top: auto;
  padding-top: 14px;
  border-top: 1px solid var(--border-soft);
}

.sidebar-user {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 6px 8px;
  font-size: 12.5px;
  color: var(--text-dim);
}

.sidebar-user .avatar {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: var(--panel-2);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: 700;
  color: var(--text-dim);
}

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

/* ---------- Topbar ---------- */
.topbar {
  height: 58px;
  flex-shrink: 0;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 28px;
  background: var(--panel);
}

.topbar-left { display: flex; align-items: center; gap: 14px; min-width: 0; }

.topbar-crumb {
  font-size: 13px;
  color: var(--text-dim);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.topbar-crumb b { color: var(--text); font-weight: 700; }

/* Hidden on desktop; shown only below the mobile breakpoint (see media query). */
.hamburger-btn {
  display: none;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 4px;
  width: 36px;
  height: 36px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--panel);
  flex-shrink: 0;
}
.hamburger-btn span {
  display: block;
  width: 16px;
  height: 2px;
  background: var(--text-dim);
  border-radius: 1px;
}
.hamburger-btn:hover { background: var(--panel-2); }

.topbar-right { display: flex; align-items: center; gap: 10px; }

.theme-toggle {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 7px 12px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--panel-2);
  color: var(--text-dim);
  font-size: 12.5px;
  font-weight: 600;
}
.theme-toggle:hover { border-color: var(--accent); color: var(--accent); }

.main {
  flex: 1;
  overflow-y: auto;
  padding: 30px 44px 60px;
}

.view { display: none; }
.view.active { display: block; }

.page-header { margin-bottom: 24px; }

.page-header-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.page-header-actions { display: flex; gap: 8px; flex-shrink: 0; }

.page-title { font-size: 24px; font-weight: 700; letter-spacing: -0.02em; margin: 0; }
.page-sub { font-size: 13.5px; color: var(--text-dim); margin: 4px 0 0; }

.btn-compact { padding: 6px 12px; font-size: 12.5px; }

/* ---------- Stat strip ---------- */
.stat-strip {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 14px;
  margin-bottom: 26px;
}

/* Tinted-background style (matches the mobile stat cards): each card's
   category color washes the whole card instead of a thin left accent bar,
   and the label/value pick up that same color. */
.stat-card {
  background: var(--panel);
  border: none;
  border-radius: var(--radius);
  padding: 14px 16px;
  position: relative;
  overflow: hidden;
  text-align: center;
}
.stat-card.c-accent { background: var(--accent-soft); }
.stat-card.c-good { background: var(--good-soft); }
.stat-card.c-bad { background: var(--bad-soft); }
.stat-card.c-warn { background: var(--warn-soft); }
.stat-card.c-accent .stat-label, .stat-card.c-accent .stat-value { color: var(--accent-deep); }
.stat-card.c-good .stat-label, .stat-card.c-good .stat-value { color: var(--good); }
.stat-card.c-bad .stat-label, .stat-card.c-bad .stat-value { color: var(--bad); }
.stat-card.c-warn .stat-label, .stat-card.c-warn .stat-value { color: var(--warn); }

.stat-label {
  font-size: 10.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-faint);
  margin-bottom: 6px;
}
.stat-value { font-size: 25px; font-weight: 700; font-family: var(--mono); letter-spacing: -0.5px; }
.stat-sub { font-size: 11px; color: var(--text-faint); margin-top: 3px; }

/* ---------- Dashboard tiles ---------- */
.tile-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
}

.tile {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 18px;
  position: relative;
  transition: border-color .15s ease;
}
.tile:hover { border-color: var(--accent); }

.tile-top { display: flex; align-items: flex-start; justify-content: space-between; margin-bottom: 14px; }

.tile-icon {
  width: 42px;
  height: 42px;
  border-radius: 11px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  overflow: hidden;
}
.tile-icon img { width: 100%; height: 100%; object-fit: cover; }

.tile-actions { display: flex; align-items: center; gap: 8px; }

.tile-gear-wrap { position: absolute; top: 18px; right: 44px; }

.status-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  flex-shrink: 0;
  box-shadow: 0 0 0 3px rgba(0,0,0,0.03);
}
.status-dot.up { background: var(--good); box-shadow: 0 0 0 3px var(--good-soft); }
.status-dot.down { background: var(--bad); box-shadow: 0 0 0 3px var(--bad-soft); }
.status-dot.unknown { background: var(--text-faint); box-shadow: 0 0 0 3px var(--panel-2); }

.tile-gear {
  width: 26px;
  height: 26px;
  border-radius: 7px;
  border: 1px solid var(--border);
  background: var(--panel);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  color: var(--text-dim);
}
.tile-gear:hover { background: var(--panel-2); }

.tile-title { font-size: 15px; font-weight: 700; margin: 0 0 4px; }
.tile-desc { font-size: 12.5px; color: var(--text-dim); margin: 0 0 12px; line-height: 1.45; }

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

.tile-status-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 11px;
  color: var(--text-faint);
  border-top: 1px solid var(--border-soft);
  padding-top: 10px;
  font-family: var(--mono);
}
.tile-status-row .ok-txt { color: var(--good); font-weight: 700; }
.tile-status-row .bad-txt { color: var(--bad); font-weight: 700; }

.add-tile {
  border: 1.5px dashed var(--border);
  border-radius: var(--radius-lg);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 18px;
  color: var(--text-faint);
  font-size: 13px;
  font-weight: 600;
  background: transparent;
  min-height: 158px;
}
.add-tile:hover { border-color: var(--accent); color: var(--accent); background: var(--accent-soft); }
.add-tile .plus { font-size: 22px; line-height: 1; }

/* ---------- Tile reorder (long-press, iOS-style) ---------- */
/* Only admins get this (matches the gear icon / Add App gating). Long-press
   a tile to enter reorder mode: every tile jiggles except the one you're
   dragging (which lifts instead), and a "Done" button appears to persist the
   new order via PATCH sort_order. */
@keyframes tile-jiggle {
  0% { transform: rotate(-1deg); }
  100% { transform: rotate(1deg); }
}
.tile-grid.reordering .tile {
  animation: tile-jiggle 0.16s infinite alternate ease-in-out;
  /* Stagger so tiles don't all wobble in lockstep — looks more organic. */
  animation-delay: calc(var(--jiggle-i, 0) * 0.05s);
  user-select: none;
  -webkit-user-select: none;
}
.tile-grid.reordering .tile.dragging {
  animation: none;
  transform: scale(1.04) rotate(0deg) !important;
  box-shadow: var(--shadow-lift);
  opacity: 0.85;
  z-index: 5;
}
.tile-grid.reordering .tile a.tile-link { pointer-events: none; } /* long-press shouldn't also open the app */

.drag-ghost {
  position: fixed;
  z-index: 200;
  pointer-events: none;
  opacity: 0.92;
  transform: scale(1.06);
  box-shadow: var(--shadow-lift);
  border-radius: var(--radius-lg);
}

.empty-state {
  padding: 40px 20px;
  text-align: center;
  color: var(--text-faint);
  font-size: 13.5px;
}

/* ---------- Tables ---------- */
.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow-x: auto;
  overflow-y: hidden;
  -webkit-overflow-scrolling: touch;
}

table { width: 100%; min-width: 560px; border-collapse: collapse; }

thead th {
  text-align: left;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-faint);
  padding: 12px 18px;
  border-bottom: 1px solid var(--border);
  background: var(--panel-2);
}

tbody td {
  padding: 13px 18px;
  font-size: 13.5px;
  border-bottom: 1px solid var(--border-soft);
  vertical-align: middle;
}
tbody tr:last-child td { border-bottom: none; }
tbody tr { cursor: default; transition: background .12s ease; }
tbody tr.clickable { cursor: pointer; }
tbody tr.clickable:hover { background: var(--panel-2); }

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

.user-name-cell .avatar {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: var(--accent-soft);
  color: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 700;
  flex-shrink: 0;
}

.u-name { font-weight: 700; font-size: 13.5px; }
.u-email { font-size: 12px; color: var(--text-faint); }
.u-mobile-summary {
  display: none;
  font-size: 11.5px;
  color: var(--text-faint);
  margin-top: 2px;
  /* Some source text (audit "detail" is often raw JSON) has no spaces to
     wrap at, which would otherwise force the whole table to overflow
     horizontally — truncate instead of letting one long token blow out
     the layout. Full text is still in the title tooltip / the drawer. */
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 11.5px;
  font-weight: 700;
  padding: 3px 9px;
  border-radius: 999px;
}
.pill.active { background: var(--good-soft); color: var(--good); }
.pill.suspended { background: var(--bad-soft); color: var(--bad); }
.pill.active::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: var(--good); }
.pill.suspended::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: var(--bad); }

.perm-summary { display: flex; flex-wrap: wrap; gap: 4px; max-width: 320px; }

.perm-chip {
  font-size: 10.5px;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: 5px;
  background: var(--panel-2);
  color: var(--text-dim);
  border: 1px solid var(--border-soft);
}
.perm-chip.lvl-0 { color: var(--text-faint); }
.perm-chip.lvl-3 { background: var(--accent-soft); color: var(--accent); border-color: transparent; }

.row-edit { font-size: 12px; font-weight: 700; color: var(--accent); background: transparent; border: none; padding: 4px 8px; }
.row-edit:hover { text-decoration: underline; }

.toolbar { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; }

.search-box {
  width: 260px;
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 13px;
  background: var(--panel);
  color: var(--text);
  outline: none;
}
.search-box:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }

/* ---------- Overlay / drawer / modal ---------- */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(15,20,35,0.38);
  display: none;
  z-index: 50;
}
.overlay.show { display: block; }

.drawer {
  position: fixed;
  top: 0;
  right: 0;
  height: 100vh;
  height: 100dvh; /* mobile Safari: 100vh ignores the address bar, which was clipping the footer buttons off-screen */
  width: 420px;
  background: var(--panel);
  border-left: 1px solid var(--border);
  box-shadow: var(--shadow-lift);
  z-index: 60;
  transform: translateX(100%);
  transition: transform .22s ease;
  display: flex;
  flex-direction: column;
}
.drawer.show { transform: translateX(0); }

.drawer-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  padding: 22px 24px 18px;
  border-bottom: 1px solid var(--border-soft);
}

.drawer-title-row { display: flex; align-items: center; gap: 12px; }

.drawer-title-row .avatar {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  background: var(--accent-soft);
  color: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 15px;
}

.drawer-title-row .u-name { font-size: 16px; }
.drawer-title-row .u-email { font-size: 12.5px; }

.drawer-close {
  width: 28px;
  height: 28px;
  border-radius: 7px;
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--text-dim);
  font-size: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.drawer-close:hover { background: var(--panel-2); }

.drawer-body { padding: 20px 24px; overflow-y: auto; flex: 1; }

.section-label {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-faint);
  margin: 0 0 12px;
}

.perm-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 0;
  border-bottom: 1px solid var(--border-soft);
}
.perm-row:last-child { border-bottom: none; }

.field-hint {
  font-size: 11.5px;
  color: var(--text-faint);
  margin: -4px 0 0;
}

.switch {
  position: relative;
  display: inline-block;
  width: 40px;
  height: 24px;
  flex-shrink: 0;
}
.switch input {
  opacity: 0;
  width: 0;
  height: 0;
}
.switch .slider {
  position: absolute;
  cursor: pointer;
  inset: 0;
  background: var(--border);
  border-radius: 999px;
  transition: background .15s ease;
}
.switch .slider::before {
  content: "";
  position: absolute;
  height: 18px;
  width: 18px;
  left: 3px;
  top: 3px;
  background: #fff;
  border-radius: 50%;
  transition: transform .15s ease;
  box-shadow: 0 1px 2px rgba(0,0,0,0.25);
}
.switch input:checked + .slider { background: var(--accent); }
.switch input:checked + .slider::before { transform: translateX(16px); }

.perm-app { display: flex; align-items: center; gap: 9px; }

.perm-app .icon-sm {
  width: 26px;
  height: 26px;
  border-radius: 7px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  overflow: hidden;
}
.perm-app .icon-sm img { width: 100%; height: 100%; object-fit: cover; }
.perm-app .name { font-size: 13px; font-weight: 600; }

.perm-select {
  padding: 6px 26px 6px 10px;
  border: 1px solid var(--border);
  border-radius: 7px;
  font-size: 12.5px;
  background: var(--panel);
  color: var(--text);
  outline: none;
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M0 0l5 6 5-6z' fill='%235B6478'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
}
.perm-select:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }

.drawer-footer {
  padding: 18px 24px 22px;
  padding-bottom: max(22px, env(safe-area-inset-bottom, 22px));
  border-top: 1px solid var(--border-soft);
  display: flex;
  gap: 10px;
  flex-shrink: 0; /* never let the header/body squeeze this out of view */
}

.meta-line { font-size: 12.5px; color: var(--text-dim); display: flex; justify-content: space-between; padding: 6px 0; }
.meta-line b { color: var(--text); font-weight: 700; }

/* ---------- Modal ---------- */
.modal-wrap { position: fixed; inset: 0; z-index: 70; display: none; align-items: center; justify-content: center; }
.modal-wrap.show { display: flex; }

.modal {
  width: 460px;
  max-width: 92vw;
  max-height: 86vh;
  overflow-y: auto;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lift);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 22px 16px;
  border-bottom: 1px solid var(--border-soft);
}
.modal-header h3 { margin: 0; font-size: 16px; font-weight: 700; }

.modal-body { padding: 20px 22px; }

.modal-footer {
  padding: 16px 22px 20px;
  border-top: 1px solid var(--border-soft);
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

.remove-link {
  font-size: 12.5px;
  font-weight: 700;
  color: var(--bad);
  cursor: pointer;
  align-self: center;
}
.remove-link:hover { text-decoration: underline; }

.form-row { margin-bottom: 16px; }
.form-row label { display: block; font-size: 12.5px; font-weight: 600; color: var(--text-dim); margin-bottom: 6px; }
.form-row input[type="text"],
.form-row input[type="url"],
.form-row input[type="number"],
.form-row select,
.form-row textarea {
  width: 100%;
  padding: 9px 11px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 13.5px;
  background: var(--panel);
  color: var(--text);
  outline: none;
}
.form-row input:focus,
.form-row select:focus,
.form-row textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.form-row textarea { resize: vertical; min-height: 60px; font-family: inherit; }

.form-two { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }

.temp-pass-box {
  font-family: var(--mono);
  font-size: 20px;
  font-weight: 700;
  letter-spacing: 0.03em;
  background: var(--panel-2);
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  padding: 16px;
  text-align: center;
  color: var(--accent);
  user-select: all;
}

.toast {
  position: fixed;
  bottom: 26px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: var(--text);
  color: var(--bg);
  font-size: 13px;
  font-weight: 600;
  padding: 11px 18px;
  border-radius: 9px;
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s ease, transform .2s ease;
  z-index: 100;
  box-shadow: var(--shadow-lift);
  max-width: 420px;
  text-align: center;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ---------- Errors viewer ---------- */
.error-row {
  padding: 12px 18px;
  border-bottom: 1px solid var(--border-soft);
  font-size: 12.5px;
}
.error-row:last-child { border-bottom: none; }
.error-row .err-when { color: var(--text-faint); font-family: var(--mono); font-size: 11px; }
.error-row .err-msg { color: var(--bad); font-weight: 600; margin-top: 3px; }
.error-row .err-meta { color: var(--text-dim); margin-top: 2px; }

/* ==========================================================================
   Mobile / responsive
   The sidebar becomes an off-canvas overlay drawer (toggled by the hamburger
   button, reusing the existing #overlay backdrop) instead of a permanent
   flex column, so the main content gets the full viewport width. Everything
   else in this block just relaxes fixed pixel widths into something that
   fits a phone screen.
   ========================================================================== */
@media (max-width: 880px) {
  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    height: 100vh;
    height: 100dvh;
    width: 260px;
    max-width: 82vw;
    z-index: 80;
    transform: translateX(-100%);
    transition: transform .2s ease;
    box-shadow: var(--shadow-lift);
  }
  .sidebar.show { transform: translateX(0); }

  .hamburger-btn { display: flex; }

  .topbar { padding: 0 16px; }
  .main { padding: 20px 16px 48px; }

  .page-title { font-size: 19px; }

  /* All 4 stat cards stay on one row even on a phone — small enough that
     abbreviating labels via CSS (not editing the JS-rendered text) keeps
     "Total Apps"/"Offline" from wrapping or getting clipped. */
  .stat-strip { grid-template-columns: repeat(4, 1fr); gap: 5px; }

  /* Tinted-background colors/text-align are the base .stat-card style now
     (desktop matches too) — just shrink padding/type to fit 4-across here. */
  .stat-card { padding: 8px 5px; }

  .stat-label {
    font-size: 8.5px;
    letter-spacing: 0.02em;
    margin-bottom: 2px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  .stat-value { font-size: 19px; letter-spacing: -0.3px; }
  .stat-sub, .sparkline { display: none; } /* redundant with the card above it — save space */

  /* ---- Dashboard tiles: 2-up, status trimmed to just the dot ---- */
  .tile-grid { grid-template-columns: repeat(2, 1fr); gap: 8px; }

  .tile { padding: 12px; }
  .tile-top { margin-bottom: 9px; }
  .tile-icon { width: 40px; height: 40px; border-radius: 10px; font-size: 19px; }
  .tile-title { font-size: 14.5px; margin: 0 0 3px; }
  .tile-desc {
    font-size: 11.5px;
    margin: 0;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
  }
  /* The dot in tile-top already says up/down/unknown at a glance — the
     "checked Xs ago" line is the thing to cut for density on a phone. */
  .tile-status-row { display: none; }
  .tile-gear { width: 20px; height: 20px; font-size: 11px; }
  .tile-gear-wrap { top: 10px; right: 34px; }
  .add-tile { min-height: 90px; padding: 10px; }
  .add-tile .plus { font-size: 16px; }

  .toolbar { flex-direction: column; align-items: stretch; gap: 10px; }
  .search-box { width: 100%; }

  /* ---- Users table: drop Last Login / Permissions / Edit columns so the
     row fits without horizontal scrolling; that info moves into a compact
     one-line summary under the name instead (full detail is one tap away
     in the drawer either way). ---- */
  /* table-layout:fixed so the remaining visible columns respect their set
     widths instead of auto-expanding to fit an unwrapped long token (e.g.
     raw JSON in an audit "detail" summary) — that's what makes the
     ellipsis truncation on .u-mobile-summary actually take effect instead
     of silently blowing the table width out and re-introducing scroll. */
  .users-table, .audit-table, .backups-table { table-layout: fixed; }

  .users-table { min-width: 0; }
  .users-table .col-lastlogin,
  .users-table .col-perms,
  .users-table .col-edit { display: none; }
  /* Name(26%) + Status(12%) summed to 38% on desktop because the other
     columns picked up the rest — with those hidden, stretch Name to fill
     what's left instead of leaving a dead gap at the table's right edge. */
  /* !important: the <th> elements carry inline style="width:X%" for the
     desktop layout, and inline styles always beat stylesheet rules
     regardless of selector specificity — these overrides were silently
     no-ops without it. */
  .users-table th:first-child, .users-table td:first-child { width: 76% !important; }
  .users-table .col-status { width: 24% !important; }
  .u-mobile-summary { display: block; }

  /* ---- Audit Log: Action/Target/Detail fold into a summary line under
     the actor's name, same idea as the Users table above. ---- */
  .audit-table { min-width: 0; }
  .audit-table .col-action,
  .audit-table .col-target,
  .audit-table .col-detail { display: none; }
  /* At was 18% (fine on desktop next to 4 other columns) — shrink it so
     Actor + the folded action/target/detail summary get most of the row. */
  .audit-table th:first-child, .audit-table td:first-child { width: 13% !important; font-size: 10px; }
  .audit-table .col-actor { width: 87% !important; }

  /* ---- Backups: Created/Size fold into a summary line under the name. ---- */
  .backups-table { min-width: 0; }
  .backups-table .col-created,
  .backups-table .col-size { display: none; }
  /* Name was 30% to leave room for Created/Size — with those hidden, give
     it most of the row and keep Download as a narrow trailing column. */
  .backups-table th:first-child, .backups-table td:first-child { width: 75% !important; }
  .backups-table th:last-child, .backups-table td:last-child { width: 25% !important; text-align: right; }

  .drawer { width: 100%; }

  .modal { width: calc(100vw - 32px); }

  .login-card { width: calc(100vw - 40px); max-width: 380px; }

  .form-two { grid-template-columns: 1fr; }

  .drawer-footer { flex-wrap: wrap; }
  .drawer-footer .btn { flex: 1 1 auto; }
}

.upstream-down {
  padding: 30px 20px;
  text-align: center;
  color: var(--bad);
  background: var(--bad-soft);
  border-radius: var(--radius-lg);
  font-size: 13.5px;
  font-weight: 600;
}

a.dl-link { color: var(--accent); font-weight: 700; text-decoration: none; font-size: 12.5px; }
a.dl-link:hover { text-decoration: underline; }
