/* Palette matches docs.truvami.com: near-black/white base with the
   Truvami mint-teal (#00ddb3) as the single brand accent. Primary
   buttons are near-black on white in light mode and flip to teal-on-dark
   in dark mode, mirroring the real site's own light/dark behavior. */
:root {
  --bg: #fafafa;
  --panel: #ffffff;
  --border: #e4e4e7;
  --text: #18181b;
  --muted: #71717a;
  --accent: #00ddb3;
  --accent-weak: #e6fbf6;
  --critical: #c0362c;
  --major: #b8860b;
  --ok: #1a7f37;
  --header-bg: #f4f4f5;
  --editable-bg: #f0fdfa;
  --btn-primary-bg: #18181b;
  --btn-primary-text: #ffffff;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0a0a0a;
    --panel: #141414;
    --border: #27272a;
    --text: #f4f4f5;
    --muted: #a1a1aa;
    --accent: #00ddb3;
    --accent-weak: #0d2e28;
    --critical: #ff6b61;
    --major: #e0b23b;
    --ok: #48c774;
    --header-bg: #1c1c1f;
    --editable-bg: rgba(0, 221, 179, 0.08);
    --btn-primary-bg: #00ddb3;
    --btn-primary-text: #0a0a0a;
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
}

#app { display: flex; flex-direction: column; height: 100vh; }

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.brand-title { font-weight: 700; font-size: 15px; display: block; color: var(--accent); }
.brand-sub { font-size: 12px; color: var(--muted); }
.topbar-actions { display: flex; align-items: center; gap: 10px; }

.btn-ghost, .btn-primary {
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--text);
  border-radius: 999px;
  padding: 7px 16px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
}
.btn-primary { background: var(--btn-primary-bg); color: var(--btn-primary-text); border-color: var(--btn-primary-bg); }
.btn-ghost:hover { background: var(--header-bg); }

.save-indicator { font-size: 12px; color: var(--muted); min-width: 90px; text-align: right; }
.save-indicator.saving { color: var(--accent); }
.save-indicator.saved { color: var(--ok); }
.save-indicator.error { color: var(--critical); }

.layout { display: flex; flex: 1; min-height: 0; }

.tabs {
  width: 220px;
  flex-shrink: 0;
  background: var(--panel);
  border-right: 1px solid var(--border);
  overflow-y: auto;
  padding: 8px;
}
.tab-btn {
  display: block;
  width: 100%;
  text-align: left;
  padding: 9px 10px;
  border-radius: 6px;
  border: none;
  background: transparent;
  color: var(--text);
  font-size: 13px;
  cursor: pointer;
  margin-bottom: 2px;
}
.tab-btn:hover { background: var(--header-bg); }
.tab-btn.active { background: var(--accent-weak); color: var(--accent); font-weight: 600; }
.tab-num { color: var(--muted); font-variant-numeric: tabular-nums; margin-right: 6px; }

.content { flex: 1; overflow: auto; padding: 18px; }
.empty-state { color: var(--muted); padding: 40px; text-align: center; }

.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px;
  margin-bottom: 18px;
}
.panel h2 { margin: 0 0 4px; font-size: 16px; }
.panel .panel-sub { color: var(--muted); font-size: 12.5px; margin: 0 0 14px; }

.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: 8px; }
table.grid { border-collapse: collapse; width: 100%; font-size: 12.5px; }
table.grid th, table.grid td {
  border: 1px solid var(--border);
  padding: 6px 8px;
  vertical-align: top;
  text-align: left;
}
table.grid th {
  background: var(--header-bg);
  position: sticky;
  top: 0;
  white-space: nowrap;
  font-weight: 600;
  z-index: 1;
}
table.grid td.pk-cell { background: var(--header-bg); font-weight: 600; white-space: nowrap; }
table.grid .cell {
  min-width: 90px;
  max-width: 420px;
  outline: none;
  white-space: pre-wrap;
  word-break: break-word;
  min-height: 18px;
}
table.grid .cell[contenteditable="true"] { background: var(--editable-bg); border-radius: 3px; }
table.grid .cell[contenteditable="true"]:focus { box-shadow: inset 0 0 0 2px var(--accent); }
table.grid select.cell { width: 100%; background: var(--editable-bg); border: none; font: inherit; color: inherit; padding: 3px; }
/* DEVEUIs and BLE MACs are single fixed-format tokens (e.g.
   687912B1000413C6, AA:BB:CC:DD:EE:FF) — never wrap them mid-string, and
   give the column enough room to show the whole thing without the browser
   needing to shrink it onto two lines. */
table.grid .cell[data-col="deveui"],
table.grid .cell[data-col="deveui_sn"],
table.grid .cell[data-col="ble_mac"] {
  white-space: nowrap;
  min-width: 160px;
}
table.grid tr.row-dirty td { box-shadow: inset 0 0 0 9999px rgba(255, 196, 0, 0.06); }
table.grid tr.row-error td { box-shadow: inset 0 0 0 9999px rgba(255, 0, 0, 0.06); }

.kv-table td:first-child { width: 260px; font-weight: 600; background: var(--header-bg); }

.badges { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 16px; }
.badge {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px 18px;
  min-width: 140px;
}
.badge .n { font-size: 26px; font-weight: 700; display: block; }
.badge .l { font-size: 12px; color: var(--muted); }
.badge.critical .n { color: var(--critical); }
.badge.ok .n { color: var(--ok); }

.readiness-banner {
  padding: 14px 18px;
  border-radius: 12px;
  font-weight: 700;
  margin-bottom: 18px;
  border: 1px solid var(--border);
}
.readiness-banner.hold { background: #fdecea; color: var(--critical); border-color: #f3b7b2; }
.readiness-banner.incomplete { background: #fff6e5; color: var(--major); border-color: #f0dba0; }
.readiness-banner.review { background: var(--accent-weak); color: var(--accent); }
.readiness-banner.ready { background: #eaf7ee; color: var(--ok); border-color: #b6e3c2; }
@media (prefers-color-scheme: dark) {
  .readiness-banner.hold { background: #3a1f1d; }
  .readiness-banner.incomplete { background: #382d13; }
  .readiness-banner.ready { background: #123322; }
}

.list-items { margin: 0; padding-left: 18px; font-size: 13px; line-height: 1.7; }
.muted { color: var(--muted); font-size: 12.5px; }
code { background: var(--header-bg); padding: 1px 5px; border-radius: 4px; font-size: 12px; }

dialog#token-dialog {
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 0;
  background: var(--panel);
  color: var(--text);
  max-width: 420px;
  width: 90%;
}
dialog#token-dialog::backdrop { background: rgba(0,0,0,0.45); }
#token-form { padding: 18px; display: flex; flex-direction: column; gap: 10px; }
#token-input {
  padding: 8px 12px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-size: 13px;
}
.dialog-actions { display: flex; justify-content: space-between; margin-top: 6px; }

.pill { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 11px; font-weight: 600; }
.pill.Pass, .pill.OK, .pill.Yes, .pill.Closed { background: #eaf7ee; color: var(--ok); }
.pill.Fail, .pill.KO, .pill.Critical, .pill.Open { background: #fdecea; color: var(--critical); }
.pill.Blocked, .pill.Major, .pill.Review { background: #fff6e5; color: var(--major); }
@media (prefers-color-scheme: dark) {
  .pill.Pass, .pill.OK, .pill.Yes, .pill.Closed { background: #123322; }
  .pill.Fail, .pill.KO, .pill.Critical, .pill.Open { background: #3a1f1d; }
  .pill.Blocked, .pill.Major, .pill.Review { background: #382d13; }
}

/* ---------------------------------------------------------------
   Photo panel
--------------------------------------------------------------- */
.photo-btn { font-size: 15px; padding: 6px 10px; }
dialog#photo-dialog {
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 0;
  background: var(--panel);
  color: var(--text);
  width: min(560px, 94vw);
  max-height: 88vh;
}
dialog#photo-dialog::backdrop { background: rgba(0,0,0,0.5); }
.photo-dialog-inner { padding: 16px; display: flex; flex-direction: column; gap: 10px; max-height: 82vh; overflow-y: auto; }
.photo-dialog-head { display: flex; justify-content: space-between; align-items: center; }
.photo-dialog-head h3 { margin: 0; }
.photo-row-label { margin: -4px 0 0; }
.photo-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 8px; }
.photo-thumb { position: relative; aspect-ratio: 1; border-radius: 8px; overflow: hidden; border: 1px solid var(--border); }
.photo-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.photo-thumb a { display: block; width: 100%; height: 100%; color: inherit; text-decoration: none; }
/* Non-image attachments (PDFs, spreadsheets, docs, zips...) render as a
   generic file card instead of a broken-image thumbnail: icon, name, size. */
.file-thumb { background: var(--header-bg); }
.file-thumb a {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  height: 100%; padding: 8px 4px; gap: 3px; text-align: center;
}
.file-thumb-icon { font-size: 26px; line-height: 1; }
.file-thumb-name {
  font-size: 10.5px; font-weight: 600; word-break: break-word;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.file-thumb-size { font-size: 10px; color: var(--muted); }
.photo-thumb-del {
  position: absolute; top: 4px; right: 4px;
  background: rgba(0,0,0,0.6); color: #fff; border: none; border-radius: 50%;
  width: 22px; height: 22px; line-height: 1; cursor: pointer; font-size: 14px;
  z-index: 1;
}
.photo-add-row { display: flex; gap: 8px; flex-wrap: wrap; }
.photo-add-btn {
  display: flex; align-items: center; justify-content: center; gap: 6px;
  text-align: center; cursor: pointer; padding: 10px 14px; flex: 1 1 auto;
}
.photo-status { min-height: 16px; }

/* ---------------------------------------------------------------
   Password gate
--------------------------------------------------------------- */
.gate-wrap { display: flex; align-items: center; justify-content: center; min-height: 70vh; }
.gate-form {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 28px 24px;
  width: min(320px, 92vw);
  display: flex;
  flex-direction: column;
  gap: 12px;
  text-align: center;
}
.gate-form h2 { margin: 0; color: var(--accent); }
.gate-form input {
  padding: 12px 18px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-size: 16px; /* avoids iOS Safari auto-zoom on focus */
  text-align: center;
}
.gate-error { min-height: 16px; color: var(--critical); }

/* ---------------------------------------------------------------
   Mobile-first: this app is used mainly on a phone. Below the
   breakpoint every grid collapses from a wide table into stacked
   label:value cards (pure CSS, using each td's data-label), and
   touch targets get bigger.
--------------------------------------------------------------- */
@media (max-width: 760px) {
  .layout { flex-direction: column; }
  .tabs { width: 100%; display: flex; overflow-x: auto; white-space: nowrap; border-right: none; border-bottom: 1px solid var(--border); padding: 6px; }
  .tab-btn { display: inline-block; width: auto; padding: 10px 12px; }
  .content { padding: 10px; }
  .panel { padding: 12px; border-radius: 8px; }
  .badges { gap: 8px; }
  .badge { min-width: 44%; flex: 1 1 44%; padding: 10px 12px; }
  .badge .n { font-size: 22px; }

  table.responsive-grid, table.responsive-grid thead, table.responsive-grid tbody,
  table.responsive-grid th, table.responsive-grid td, table.responsive-grid tr {
    display: block;
  }
  table.responsive-grid thead { position: absolute; top: -9999px; left: -9999px; }
  table.responsive-grid .table-wrap { border: none; }
  table.responsive-grid tr {
    border: 1px solid var(--border);
    border-radius: 10px;
    margin-bottom: 12px;
    padding: 8px 10px;
    background: var(--panel);
  }
  table.responsive-grid td {
    border: none;
    border-bottom: 1px solid var(--border);
    padding: 8px 2px;
    display: flex;
    flex-direction: column;
    gap: 4px;
  }
  table.responsive-grid td:last-child { border-bottom: none; }
  table.responsive-grid td[data-label]:not([data-label=""])::before {
    content: attr(data-label);
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    color: var(--muted);
  }
  table.responsive-grid td.pk-cell { background: transparent; font-size: 15px; }
  table.responsive-grid .cell { min-width: 0; max-width: none; font-size: 14px; padding: 6px 2px; }
  table.responsive-grid .cell[contenteditable="true"] { padding: 8px; }
  table.responsive-grid select.cell { padding: 8px; }
  .table-wrap { overflow-x: visible; }

  .kv-table td:first-child { width: auto; }
  dialog#token-dialog, dialog#photo-dialog { width: 94vw; }
}
