/*
 * Tenant console theme — the same dark palette dashboard.html defines, lifted
 * into a file so devices.html and database.html cannot drift from it.
 *
 * NO @import AND NO WEBFONT. database.html displays a live credential at
 * rotation time, and a page holding one should not also be making third-party
 * requests; since these two pages share a stylesheet, neither loads one. The
 * font stack falls through to Inter when the browser already has it and to the
 * system UI font otherwise.
 *
 * Tables rather than cards for anything list-shaped, following the operator
 * console's preference — a device inventory is a table.
 */

:root {
  --bg-canvas: #090d16;
  --bg-surface: #111827;
  --bg-card: #1f293d;
  --bg-card-hover: #28354f;
  --border-subtle: #1e293b;
  --border-default: #334155;
  --primary: #6366f1;
  --primary-hover: #4f46e5;
  --primary-glow: rgba(99, 102, 241, 0.25);
  --accent-cyan: #06b6d4;
  --accent-emerald: #10b981;
  --accent-amber: #f59e0b;
  --accent-red: #ef4444;
  --text-main: #f8fafc;
  --text-muted: #94a3b8;
  --text-dim: #64748b;
  --font-sans: 'Inter', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  --font-mono: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, monospace;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
body {
  background-color: var(--bg-canvas);
  color: var(--text-main);
  font-family: var(--font-sans);
  line-height: 1.6;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

header {
  background: rgba(17, 24, 39, 0.85);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border-subtle);
  position: sticky; top: 0; z-index: 100;
  padding: 0.85rem 2rem;
  display: flex; justify-content: space-between; align-items: center; gap: 1rem;
}
.brand-logo { display: flex; align-items: center; gap: 0.75rem; text-decoration: none; color: var(--text-main); }
.brand-icon { width: 36px; height: 36px; flex: none; filter: drop-shadow(0 0 10px var(--primary-glow)); }
.brand-icon .mark-tile { fill: rgba(99, 102, 241, 0.12); stroke: rgba(99, 102, 241, 0.45); stroke-width: 1.5; }
.brand-icon .mark-loop { fill: none; stroke: url(#pf-mark-grad); stroke-width: 3; stroke-linecap: round; stroke-linejoin: round; }
.brand-name {
  font-size: 1.25rem; font-weight: 700; letter-spacing: -0.02em;
  background: linear-gradient(90deg, #ffffff, #cbd5e1);
  -webkit-background-clip: text; background-clip: text; -webkit-text-fill-color: transparent;
}
.nav-links { display: flex; gap: 0.35rem; align-items: center; flex-wrap: wrap; }
.nav-btn {
  background: transparent; border: 1px solid transparent; color: var(--text-muted);
  padding: 0.45rem 0.9rem; border-radius: 6px; font-size: 0.88rem; font-weight: 500;
  cursor: pointer; transition: all 0.2s ease; text-decoration: none;
  display: inline-block; font-family: var(--font-sans);
}
.nav-btn:hover { color: var(--text-main); background: var(--bg-card); }
.nav-btn.current { color: var(--text-main); background: var(--bg-card); border-color: var(--border-default); }

main { flex: 1; max-width: 1040px; width: 100%; margin: 0 auto; padding: 2rem 1.5rem; }

.crumb { font-size: 0.85rem; color: var(--text-dim); margin-bottom: 0.75rem; }
.crumb a { color: var(--text-muted); text-decoration: none; }
.crumb a:hover { color: var(--text-main); text-decoration: underline; }

.page-head {
  display: flex; justify-content: space-between; align-items: flex-start;
  gap: 1rem; flex-wrap: wrap; margin-bottom: 1.5rem;
}
.page-head h1 { font-size: 1.8rem; font-weight: 800; letter-spacing: -0.02em; margin-bottom: 0.25rem; }
.page-head .subtle { font-family: var(--font-mono); font-size: 0.85rem; color: var(--text-muted); }
.head-actions { display: flex; gap: 0.6rem; flex-wrap: wrap; }

.btn {
  background: var(--primary); color: #fff; border: none;
  padding: 0.55rem 1.1rem; border-radius: 6px; font-weight: 600; font-size: 0.88rem;
  cursor: pointer; transition: background 0.2s ease; font-family: var(--font-sans);
}
.btn:hover { background: var(--primary-hover); }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }
.btn.secondary { background: transparent; border: 1px solid var(--border-default); color: var(--text-main); }
.btn.secondary:hover { background: var(--bg-card-hover); }
.btn.danger { background: var(--accent-red); }
.btn.danger:hover { background: #dc2626; }
.btn.small { padding: 0.3rem 0.65rem; font-size: 0.8rem; }
a.btn { text-decoration: none; display: inline-block; }

.panel {
  background: var(--bg-surface); border: 1px solid var(--border-subtle);
  border-radius: 12px; padding: 1.5rem; margin-bottom: 1.5rem;
}
.panel-header {
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: 1.25rem; gap: 1rem; flex-wrap: wrap;
}
.panel-title { font-size: 1.15rem; font-weight: 700; }
.panel-note { font-size: 0.85rem; color: var(--text-muted); margin-top: -0.5rem; margin-bottom: 1rem; }

.banner {
  display: flex; flex-direction: column; gap: 0.2rem;
  border-radius: 10px; padding: 0.9rem 1.1rem; margin-bottom: 1rem;
  border: 1px solid; font-size: 0.9rem;
  overflow-wrap: anywhere; /* API error strings arrive verbatim */
}
.banner strong { font-size: 0.95rem; }
.banner a { color: inherit; font-weight: 600; }
.banner code {
  font-family: var(--font-mono); font-size: 0.82em;
  background: rgba(0,0,0,0.3); padding: 0.05rem 0.3rem; border-radius: 4px;
}
.banner .banner-note { display: block; margin-top: 0.4rem; opacity: 0.85; font-size: 0.85rem; }
.banner.red { color: #fecaca; background: rgba(239, 68, 68, 0.1); border-color: rgba(239,68,68,0.4); }
.banner.amber { color: #fde68a; background: rgba(245, 158, 11, 0.1); border-color: rgba(245,158,11,0.4); }
.banner.green { color: #a7f3d0; background: rgba(16, 185, 129, 0.1); border-color: rgba(16,185,129,0.4); }

table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
thead th {
  text-align: left; font-size: 0.75rem; font-weight: 700; color: var(--text-muted);
  text-transform: uppercase; letter-spacing: 0.05em;
  padding: 0.5rem 0.75rem; border-bottom: 1px solid var(--border-default); white-space: nowrap;
}
tbody td { padding: 0.7rem 0.75rem; border-bottom: 1px solid var(--border-subtle); vertical-align: middle; }
tbody tr:hover { background: rgba(255,255,255,0.02); }
td.mono, .mono { font-family: var(--font-mono); }
td.right, th.right { text-align: right; }
td.actions { white-space: nowrap; text-align: right; }
td.actions .btn { margin-left: 0.35rem; }
.table-scroll { overflow-x: auto; }
.dim { color: var(--text-dim); }
.empty { text-align: center; color: var(--text-muted); padding: 2.5rem 1rem; }

.kv-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 1.1rem; }
.kv .kv-label {
  font-size: 0.75rem; color: var(--text-muted);
  text-transform: uppercase; letter-spacing: 0.05em; margin-bottom: 0.2rem;
}
.kv .kv-value { font-size: 1rem; font-weight: 600; font-family: var(--font-mono); word-break: break-all; }

.badge {
  display: inline-flex; align-items: center; gap: 0.4rem;
  font-size: 0.75rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.04em;
  padding: 0.15rem 0.55rem; border-radius: 9999px;
}
.badge::before { content: ''; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.badge.green { color: #6ee7b7; background: rgba(16, 185, 129, 0.12); border: 1px solid rgba(16,185,129,0.3); }
.badge.amber { color: #fcd34d; background: rgba(245, 158, 11, 0.12); border: 1px solid rgba(245,158,11,0.3); }
.badge.red   { color: #fca5a5; background: rgba(239, 68, 68, 0.12); border: 1px solid rgba(239,68,68,0.3); }
.badge.grey  { color: var(--text-muted); background: var(--bg-card); border: 1px solid var(--border-default); }

label { display: block; font-size: 0.8rem; color: var(--text-muted); margin-bottom: 0.3rem; font-weight: 600; }
input[type="text"], input[type="search"], select {
  width: 100%; background: var(--bg-canvas); color: var(--text-main);
  border: 1px solid var(--border-default); border-radius: 6px;
  padding: 0.5rem 0.7rem; font-size: 0.9rem; font-family: var(--font-sans);
}
input:focus, select:focus { outline: 2px solid var(--primary); outline-offset: 0; border-color: var(--primary); }
input.mono { font-family: var(--font-mono); }
.field { margin-bottom: 0.9rem; }
.field-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 0.9rem; }
.hint { font-size: 0.78rem; color: var(--text-dim); margin-top: 0.3rem; }

pre.snippet {
  background: var(--bg-canvas); border: 1px solid var(--border-subtle); border-radius: 8px;
  padding: 0.75rem 0.9rem; font-family: var(--font-mono); font-size: 0.82rem;
  overflow-x: auto; white-space: pre; color: #cbd5e1;
}
.snippet-row { display: flex; align-items: flex-start; gap: 0.6rem; margin-bottom: 0.9rem; }
.snippet-row pre { flex: 1; min-width: 0; }

/* Modals. Every destructive action goes through one, and each asks the user to
   type the thing being destroyed rather than to click "yes". */
.modal-backdrop {
  position: fixed; inset: 0; z-index: 500; background: rgba(2, 6, 16, 0.75);
  display: flex; justify-content: center; padding: 1rem;
  /* Every modal here auto-focuses a typed-confirmation field, so on a phone
     the keyboard opens with the dialog. `safe center` centres when the box
     fits and top-anchors when it does not; plain flex-start is the fallback
     for engines without the keyword. The backdrop scrolls so the action row
     can never be clipped out of reach. */
  align-items: flex-start;
  align-items: safe center;
  overflow-y: auto; overscroll-behavior: contain;
}
.modal {
  background: var(--bg-surface); border: 1px solid var(--border-default);
  border-radius: 12px; padding: 1.5rem; max-width: 560px; width: 100%;
  max-height: 90vh; overflow-y: auto;
}
.modal h3 { font-size: 1.15rem; font-weight: 700; margin-bottom: 0.6rem; }
.modal p { font-size: 0.9rem; color: var(--text-muted); margin-bottom: 0.9rem; }
.modal .modal-actions { display: flex; justify-content: flex-end; gap: 0.6rem; margin-top: 1.2rem; flex-wrap: wrap; }
.modal-error { color: #fca5a5; font-size: 0.85rem; margin-top: 0.6rem; min-height: 1.2em; overflow-wrap: anywhere; }

.spinner {
  width: 28px; height: 28px; border: 3px solid var(--border-default);
  border-top-color: var(--primary); border-radius: 50%;
  animation: spin 0.8s linear infinite; margin: 0 auto 1rem auto;
}
@keyframes spin { to { transform: rotate(360deg); } }
.loading { text-align: center; padding: 3rem 1rem; color: var(--text-muted); }

footer {
  border-top: 1px solid var(--border-subtle); padding: 1.5rem 2rem; text-align: center;
  font-size: 0.85rem; color: var(--text-dim); background: var(--bg-surface);
}

#impersonation-bar {
  position: fixed; top: 0; left: 0; right: 0; z-index: 9999;
  display: flex; align-items: center; justify-content: center; flex-wrap: wrap; gap: .4rem 1rem;
  padding: .6rem 1rem; font-size: .85rem;
  background: #7a4b00; color: #fff; border-bottom: 2px solid #ffb020;
}

@media (max-width: 640px) {
  header { padding: 0.75rem 1rem; flex-wrap: wrap; }
  main { padding: 1.25rem 1rem; }
  .panel { padding: 1.1rem; }
  footer { padding: 1.25rem 1rem; }

  /* Tables become cards, the same shape the operator console uses: the header
     row hides and each cell carries its column name in data-label. Rows are
     written with the attribute in the page scripts. */
  .table-scroll:not(.no-stack) thead { display: none; }
  .table-scroll:not(.no-stack) table,
  .table-scroll:not(.no-stack) tbody,
  .table-scroll:not(.no-stack) tr { display: block; width: 100%; }

  .table-scroll:not(.no-stack) tbody tr {
    border: 1px solid var(--border-default);
    border-radius: 10px;
    margin-bottom: 0.6rem;
    padding: 0.2rem 0.75rem;
    background: var(--bg-card);
  }
  .table-scroll:not(.no-stack) tbody tr:hover { background: var(--bg-card); }

  .table-scroll:not(.no-stack) tbody td {
    display: flex; justify-content: space-between; align-items: baseline;
    gap: 1rem;
    border-bottom: 1px dotted var(--border-subtle);
    padding: 0.45rem 0;
    text-align: right;
    overflow-wrap: anywhere;
  }
  .table-scroll:not(.no-stack) tbody tr td:last-child { border-bottom: none; }

  .table-scroll:not(.no-stack) tbody td::before {
    content: attr(data-label);
    flex: none; text-align: left;
    color: var(--text-muted);
    font-size: 0.75rem; font-weight: 700;
    text-transform: uppercase; letter-spacing: 0.05em;
  }
  .table-scroll:not(.no-stack) tbody td:not([data-label])::before { content: none; }

  /* The action buttons read better as a full-width row than a label/value pair. */
  .table-scroll:not(.no-stack) tbody td.actions {
    display: flex; justify-content: flex-end; white-space: normal; text-align: right;
  }
}

/* Hit targets and input sizing follow the pointer, not the width: a tablet
   needs 44px buttons at any width, a narrow desktop window does not. */
@media (pointer: coarse) {
  .btn { padding: 0.7rem 1.1rem; min-height: 44px; }
  .btn.small { padding: 0.55rem 0.8rem; min-height: 44px; }
  .nav-btn { padding: 0.65rem 0.9rem; min-height: 44px; }
  td.actions .btn { margin-top: 0.15rem; margin-bottom: 0.15rem; }
  /* 16px is the iOS no-zoom floor. */
  input[type="text"], input[type="search"], select, textarea { font-size: 16px; }
}
