/* Dark theme only. Colours follow the i2V product dark theme
   (I2v-Utility assets/dark.css): body #0E131A, surfaces #262A30 / #31353B,
   inputs #464A4F, primary #0099ED. */
:root {
  --bg: #0e131a;
  --panel: #262a30;
  --panel-2: #31353b;
  --text: #ffffff;
  --muted: #d7dbe4;
  --faint: rgba(255, 255, 255, .5);
  --border: rgba(255, 255, 255, .15);
  --line: rgba(193, 196, 198, .1);
  --accent: #0099ed;
  --accent-hover: #008edb;
  --accent-press: #0074b3;
  --accent-soft: #74c2ed;
  --accent-text: #ffffff;
  --selected: #003d5f;
  --danger: #e46e71;
  --danger-bg: #c92629;
  --ok: #6fbf8b;
  --warn: #ff9f29;
  --warn-bg: rgba(255, 159, 41, .12);
  --input: #464a4f;
  --input-fill: #31353b;
  --row-hover: rgba(255, 255, 255, .06);
  --header: rgba(255, 255, 255, .1);
  --radius: 6px;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
a { color: var(--accent-soft); }
h1 { font-size: 20px; margin: 0 0 16px; }
h2 { font-size: 16px; margin: 0 0 12px; }
h3 { font-size: 14px; margin: 16px 0 8px; }
.boot { padding: 40px; color: var(--muted); }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 12px; }
.hidden { display: none !important; }

/* Layout */
.shell { display: flex; min-height: 100vh; }
.nav { position: sticky; top: 0; align-self: flex-start; height: 100vh; overflow-y: auto; width: 210px; flex: none; background: var(--panel); border-right: 1px solid var(--line); padding: 16px 10px; display: flex; flex-direction: column; gap: 2px; }
.nav .brand { font-weight: 700; padding: 4px 10px 16px; display: flex; flex-direction: row; align-items: end; text-align: center; gap: 8px; }
.nav .brand img { flex: none; }
.nav a { display: block; padding: 7px 10px; border-radius: var(--radius); color: var(--text); text-decoration: none; }
.nav a:hover { background: var(--row-hover); }
.nav a.active { background: var(--selected); color: var(--accent-text); box-shadow: inset 3px 0 0 var(--accent); }
.nav .spacer { flex: 1; }
.nav .who { padding: 8px 10px; font-size: 12px; color: var(--muted); border-top: 1px solid var(--line); margin-top: 8px; }
.nav .session { padding: 0 10px 6px; font-size: 11px; color: var(--faint); }
.nav .session.soon { color: var(--warn); }
.main { flex: 1; padding: 24px 28px; min-width: 0; max-width: 1300px; }
/* Top bar + slide-in menu replace the sidebar on tablets and phones. */
.topbar, .navshade { display: none; }
@media (max-width: 1100px) {
  .shell { display: block; }
  .topbar { display: flex; align-items: center; gap: 12px; position: sticky; top: 0; z-index: 50; height: 52px; padding: 0 12px; background: var(--panel); border-bottom: 1px solid var(--border); }
  .topbar img { flex: none; }
  .topbar .title { flex: 1; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .topbar .menu { min-width: 44px; min-height: 40px; padding: 0 10px; font-size: 20px; line-height: 1; }
  .nav { position: fixed; top: 0; bottom: 0; left: 0; z-index: 60; height: auto; width: min(280px, 84vw); transform: translateX(-102%); transition: transform .18s ease; box-shadow: 6px 0 24px rgba(0, 0, 0, .5); }
  .shell.navopen .nav { transform: none; }
  .shell.navopen .navshade { display: block; position: fixed; inset: 0; z-index: 55; background: rgba(0, 0, 0, .6); }
  .nav a { padding: 11px 12px; }
  .main { padding: 16px; max-width: none; }
  .sticky-top { top: 52px; }
}

.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; margin-bottom: 16px; }
.row { display: flex; gap: 12px; flex-wrap: wrap; align-items: flex-end; }
.row > .field { flex: 1 1 180px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
@media (max-width: 1000px) { .grid2 { grid-template-columns: 1fr; } }
.split { display: grid; grid-template-columns: 240px minmax(0, 1fr); gap: 16px; align-items: start; }
@media (max-width: 1100px) {
  .split { grid-template-columns: minmax(0, 1fr); }
  .product-list { display: flex; flex-wrap: wrap; gap: 6px; }
  div.product-list button { display: inline-block; width: auto; margin: 0; border-color: var(--border); }
  div.product-list button.active { border-color: var(--accent); }
}
/* Products & keys: the product list stays in view while the detail scrolls. */
@media (min-width: 1101px) {
  .split > .panel.side { position: sticky; top: 16px; max-height: calc(100vh - 32px); overflow-y: auto; }
}
h3.first { margin-top: 0; }
.toolbar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-bottom: 12px; }
.toolbar .grow { flex: 1; }
.toolbar > select { width: auto; max-width: 240px; }
.toolbar > .grow { min-width: 200px; }

/* Forms */
.field { display: flex; flex-direction: column; gap: 4px; margin-bottom: 10px; }
.field > label, .label { font-size: 12px; font-weight: 600; color: var(--muted); }
input, select, textarea, button { font: inherit; color: inherit; }
input[type=text], input[type=password], input[type=email], input[type=number], input[type=date], input[type=time], input[type=search], select, textarea {
  background: var(--input); border: 1px solid var(--border); border-radius: var(--radius); padding: 7px 9px; width: 100%; min-width: 0;
}
input:focus, select:focus, textarea:focus, button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
/* A value outside the user's allowed range (Generate). */
input.invalid, input.invalid:focus { border-color: var(--danger); outline-color: var(--danger); background: rgba(228, 110, 113, .1); }
.bad { color: var(--danger); }
input:disabled, select:disabled, textarea:disabled { opacity: .55; background: var(--input-fill); }
::placeholder { color: var(--faint); }
input[type=checkbox] { accent-color: var(--accent); width: 15px; height: 15px; }
select option { background: var(--panel); color: var(--text); }
textarea { resize: vertical; }
textarea.key { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 11px; min-height: 90px; word-break: break-all; }
.version { display: flex; gap: 4px; align-items: center; }
.version input { width: 70px; }
.duration { display: flex; gap: 6px; }
.duration input { flex: 1 1 70px; min-width: 60px; }
.duration select { flex: 1 1 100px; width: auto; }
/* Validity on the generate form: start, length, end, then what it amounts to. */
.validity { background: var(--panel-2); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 12px 10px; margin-bottom: 10px; }
.validity .row { align-items: flex-start; }
.validity .row > .field { flex: 1 1 200px; }
.durline { display: flex; gap: 8px 12px; flex-wrap: wrap; align-items: center; }
.durline .duration { flex: 0 0 190px; }
.datetime { display: flex; gap: 6px; }
.datetime input[type=date] { flex: 3 1 130px; min-width: 0; }
.datetime input[type=time] { flex: 2 1 96px; min-width: 0; }
.chips { display: flex; gap: 4px; flex-wrap: wrap; }
.chips button { border-radius: 12px; padding: 2px 9px; font-size: 12px; background: transparent; }
.chips button.active { background: var(--selected); border-color: var(--accent); }
.validity-summary { display: flex; gap: 6px 14px; flex-wrap: wrap; align-items: baseline; padding-top: 8px; border-top: 1px solid var(--line); }
.validity-summary strong { font-weight: 600; }
.validity-summary.bad { color: var(--danger); }
/* Password box with a show/hide button inside its right edge. */
.pwbox { position: relative; display: flex; align-items: center; }
.pwbox input { padding-right: 42px; }
.pwbox .reveal { position: absolute; top: 50%; right: 4px; transform: translateY(-50%); width: 32px; height: 32px; min-height: 0; padding: 0; display: flex; align-items: center; justify-content: center; border: 0; border-radius: 50%; background: transparent; color: var(--faint); transition: color .12s, background-color .12s; }
.pwbox .reveal:hover:not(:disabled) { background: var(--row-hover); color: var(--text); }
.pwbox .reveal:focus-visible { outline: 2px solid var(--accent); outline-offset: 0; color: var(--text); }
.pwbox .reveal[aria-pressed="true"] { color: var(--accent-soft); }
.pwbox .reveal svg { width: 18px; height: 18px; display: block; }
/* Hide Edge's own reveal eye so there is only one. */
input::-ms-reveal { display: none; }
@media (max-width: 900px) { .pwbox input { padding-right: 48px; } .pwbox .reveal { width: 40px; height: 40px; right: 2px; } .pwbox .reveal svg { width: 20px; height: 20px; } }
.check { display: inline-flex; gap: 6px; align-items: center; cursor: pointer; }

button { border: 1px solid var(--border); background: var(--input); border-radius: var(--radius); padding: 7px 12px; cursor: pointer; white-space: nowrap; }
button:hover:not(:disabled) { background: var(--row-hover); }
button.primary { background: var(--accent); color: var(--accent-text); border-color: var(--accent); font-weight: 600; }
button.primary:hover:not(:disabled) { background: var(--accent-hover); border-color: var(--accent-hover); }
button.primary:active:not(:disabled) { background: var(--accent-press); }
button.danger { color: var(--danger); border-color: var(--danger); background: transparent; }
button.primary.danger { background: var(--danger-bg); border-color: var(--danger-bg); color: #fff; }
button.small, .small-btn { padding: 3px 8px; font-size: 12px; }
button:disabled { opacity: .55; cursor: not-allowed; }
.link { background: none; border: 0; color: var(--accent-soft); padding: 0; cursor: pointer; }
.link:hover:not(:disabled) { background: none; text-decoration: underline; }

/* Tables */
.table-wrap { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; }
th, td { text-align: left; padding: 7px 8px; border-bottom: 1px solid var(--line); vertical-align: middle; }
thead th { background: var(--header); }
th { font-size: 12px; color: var(--muted); font-weight: 600; white-space: nowrap; }
tr.clickable { cursor: pointer; }
tr.clickable:hover td { background: var(--row-hover); }
td input[type=number] { width: 120px; }
td.num, th.num { text-align: right; }

.badge { display: inline-block; padding: 1px 7px; border-radius: 10px; font-size: 11px; font-weight: 600; border: 1px solid currentColor; }
.badge.ok { color: var(--ok); }
.badge.bad { color: var(--danger); }
.badge.warn { color: var(--warn); }
.badge.muted { color: var(--muted); }

.notice { border-left: 3px solid var(--warn); background: var(--warn-bg); padding: 8px 12px; border-radius: var(--radius); margin: 8px 0; }
.notice.error { border-color: var(--danger); }
.notice.info { border-color: var(--accent); background: transparent; }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 4px 14px; }
.kv dt { color: var(--muted); font-size: 12px; }
.kv dd { margin: 0; word-break: break-word; }

/* Login */
/* Sign-in (and first password change) sits in the middle of the window. */
#app:has(> .login) { min-height: 100vh; min-height: 100dvh; display: flex; align-items: center; justify-content: center; padding: 24px 16px; }
.login { width: min(380px, 100%); margin: 0; padding: 28px 28px 24px; border-radius: 8px; box-shadow: 0 16px 40px rgba(0, 0, 0, .4); }
.login .login-brand { gap: 10px; margin-bottom: 20px; }
.login .login-brand img { width: 76px; height: auto; }
.login .login-brand h1 { font-size: 19px; }
.login .field { margin-bottom: 12px; }
.login button[type=submit] { width: 100%; margin-top: 4px; }
.login .notice { margin: 0 0 12px; }

/* Dialog */
/* Title and buttons stay in view; only the middle scrolls. */
dialog { border: 1px solid var(--border); border-radius: var(--radius); background: var(--panel); color: var(--text); padding: 0; width: min(760px, 94vw); max-height: 90vh; overflow: hidden; }
dialog[open] { display: flex; flex-direction: column; }
dialog > .dialog-head { flex: none; display: flex; align-items: center; gap: 12px; padding: 10px 10px 10px 20px; border-bottom: 1px solid var(--line); }
dialog > .dialog-head h2 { flex: 1; min-width: 0; margin: 0; overflow-wrap: anywhere; }
.dialog-x { flex: none; width: 34px; height: 34px; padding: 0; border: 0; background: transparent; color: var(--muted); font-size: 22px; line-height: 1; border-radius: var(--radius); }
.dialog-x:hover:not(:disabled) { background: var(--row-hover); color: var(--text); }
/* The body scrolls on its own; reaching its end never scrolls the page behind. */
dialog > .dialog-body { flex: 1 1 auto; min-height: 0; overflow-y: auto; overscroll-behavior: contain; padding: 16px 20px; }
dialog .table-wrap, dialog .choices { overscroll-behavior: contain; }
dialog:focus { outline: none; }
dialog > .dialog-actions { flex: none; margin: 0; padding: 12px 20px; border-top: 1px solid var(--line); background: var(--panel-2); align-items: center; }
.dialog-actions .grow { flex: 1; }
.unsaved { font-size: 12px; }
.unsaved:not(.muted) { color: var(--warn); }
dialog.narrow { width: min(440px, 94vw); }
dialog::backdrop { background: rgba(0, 0, 0, .65); }
dialog { box-shadow: 0 18px 48px rgba(0, 0, 0, .55); }
@media (prefers-reduced-motion: no-preference) {
  dialog[open] { animation: dialog-in .14s ease-out; }
  dialog[open]::backdrop { animation: backdrop-in .14s ease-out; }
}
@keyframes dialog-in { from { opacity: 0; transform: translateY(8px) scale(.985); } }
@keyframes backdrop-in { from { opacity: 0; } }
/* While a popup or the slide-in menu is open the page underneath stays put.
   The reserved gutter keeps the layout from jumping when the scrollbar goes. */
html { scrollbar-gutter: stable; }
html:has(dialog[open]), html:has(.shell.navopen) { overflow: hidden; }
.nav { overscroll-behavior: contain; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }

/* "Apply to…" popups: a tick list of where a value should go. */
.choices { border: 1px solid var(--line); border-radius: var(--radius); }
.choice { display: flex; gap: 10px; align-items: center; padding: 8px 10px; border-bottom: 1px solid var(--line); cursor: pointer; }
.choice:last-child { border-bottom: 0; }
.choice:hover { background: var(--row-hover); }
.choice:has(input:checked) { background: rgba(0, 153, 237, .08); }
.choice.off { cursor: not-allowed; opacity: .55; }
.choice .grow { flex: 1; min-width: 0; }
.choice > .muted { flex: none; white-space: nowrap; }
.bulk .grow { flex: 1; }

/* Toasts */
#toasts { position: fixed; inset: auto 16px 16px auto; margin: 0; padding: 0; border: 0; background: transparent; color: inherit; overflow: visible; display: flex; flex-direction: column; gap: 8px; z-index: 1000; }
.toast { background: var(--panel-2); border: 1px solid var(--border); border-left: 4px solid var(--ok); padding: 10px 14px; border-radius: var(--radius); box-shadow: 0 6px 18px rgba(0,0,0,.5); max-width: 420px; }
.toast.error { border-left-color: var(--danger); }

.pager { display: flex; gap: 8px; align-items: center; justify-content: flex-end; margin-top: 10px; }
.product-list button { display: block; width: 100%; text-align: left; margin-bottom: 4px; }
.product-list button { background: transparent; border-color: transparent; }
.product-list button.active { background: var(--selected); border-color: var(--accent); }
.result-key { margin-top: 8px; }

/* Feature tables: description under the key, bulk-fill bar above */
.fdesc { color: var(--faint); font-size: 12px; margin-top: 1px; }
td.sel, th.sel { width: 28px; padding-right: 0; }
.bulk { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; padding: 8px 10px; margin-bottom: 10px; background: var(--panel-2); border: 1px solid var(--line); border-radius: var(--radius); }
.bulk input[type=number] { width: 110px; }
.bulk input[type=search], .bulk input[type=text] { width: 190px; }
.bulk .sep { width: 1px; align-self: stretch; background: var(--border); }
.bulk .label { white-space: nowrap; }
td input.desc { min-width: 170px; }
td select { min-width: 104px; }
tr.rowsel td { background: rgba(0, 153, 237, .08); }

/* Pasted private keys are masked: the text is never readable on screen. */
textarea.secret { -webkit-text-security: disc; text-security: disc; font-family: ui-monospace, monospace; min-height: 90px; }

/* Session-expiry warning */
#sessionbar { position: fixed; inset: 0 0 auto 0; width: auto; margin: 0; border: 0; z-index: 1100; display: flex; gap: 12px; align-items: center; justify-content: center; padding: 8px 12px; background: #5c3a0d; color: #fff; border-bottom: 1px solid var(--warn); }

/* Page action bar: the main button stays at the bottom of the window. */
.actionbar { position: sticky; bottom: 0; z-index: 5; display: flex; gap: 8px; align-items: center; margin: 12px -16px -16px; padding: 10px 16px; background: var(--panel-2); border-top: 1px solid var(--border); border-radius: 0 0 var(--radius) var(--radius); }
.actionbar .grow { flex: 1; }
.sticky-top { position: sticky; top: 0; z-index: 5; background: var(--panel); padding: 6px 0; }

.login-brand { display: flex; flex-direction: column; align-items: center; text-align: center; gap: 10px; margin-bottom: 16px; }
.login-brand h1 { margin: 0; }

/* ---------- Small screens ---------- */

/* Touch sizes (and 16px inputs, so phones do not zoom on focus). */
@media (max-width: 900px) {
  button { min-height: 40px; }
  button.small { min-height: 36px; padding: 6px 10px; font-size: 13px; }
  .link { min-height: 0; }
  input[type=text], input[type=password], input[type=email], input[type=number], input[type=date], input[type=time], input[type=search], select, textarea { font-size: 16px; padding: 9px 10px; }
  textarea.key { font-size: 12px; }
  input[type=checkbox] { width: 20px; height: 20px; }
  #toasts { inset: auto 12px 12px 12px; }
  .toast { max-width: none; }
  #sessionbar { flex-wrap: wrap; text-align: center; }
}

/* Tables with a header become cards: one block per row, each value on its
   own labelled line (labels are filled in by labelTables() in app.js). */
@media (max-width: 820px) {
  table.cards, table.cards tbody { display: block; width: 100%; }
  table.cards thead { display: none; }
  table.cards tbody { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 8px; }
  table.cards tr { display: flex; flex-wrap: wrap; align-items: center; column-gap: 12px; position: relative; min-width: 0; padding: 8px 10px; background: var(--panel-2); border: 1px solid var(--line); border-radius: var(--radius); }
  table.cards tr.hassel { padding-left: 42px; }
  table.cards tr.rowsel { border-color: var(--accent); }
  table.cards td { flex: 1 1 100%; display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 4px 0; border: 0; text-align: right; min-width: 0; background: transparent !important; overflow-wrap: anywhere; }
  table.cards td[data-label]::before { content: attr(data-label); flex: none; color: var(--muted); font-size: 12px; font-weight: 600; text-align: left; }
  table.cards td:empty { display: none; }
  table.cards td.sel { position: absolute; left: 10px; top: 10px; width: auto; padding: 0; }
  /* The first value is the card's title. */
  table.cards td.title { display: block; text-align: left; font-weight: 600; padding-bottom: 6px; }
  table.cards td.title::before { display: none; }
  table.cards td.title .fdesc { font-weight: 400; }
  /* Unlabelled cells hold hints or row buttons. */
  table.cards td:not([data-label]):not(.title):not(.sel) { justify-content: flex-start; flex-wrap: wrap; gap: 8px; text-align: left; }
  table.cards td input[type=number] { width: 130px; flex: none; }
  table.cards td input[type=text], table.cards td select { flex: 1 1 auto; min-width: 0; width: auto; max-width: 70%; }
  table.cards td input.desc { max-width: none; }
  /* Row buttons: one tidy line of equal buttons. */
  table.cards td:not([data-label]):not(.title):not(.sel) > button { flex: 1 1 0; }
  /* Short number/choice fields sit two to a line, label above the field. */
  table.cards td[data-label="Min"], table.cards td[data-label="Max"], table.cards td[data-label="Type"], table.cards td[data-label="Default"],
  table.cards td[data-label="Given"], table.cards td[data-label="Product default"] { flex: 1 1 calc(50% - 6px); flex-direction: column; align-items: stretch; gap: 3px; text-align: left; }
  table.cards td[data-label="Min"] input, table.cards td[data-label="Max"] input, table.cards td[data-label="Default"] input, table.cards td[data-label="Type"] select { width: 100%; max-width: none; flex: none; }
  dialog table.cards td[data-label="Type"] { display: none; }
  /* Tickable feature rows (Generate): name on the left, value on the right. */
  table.cards tr.hassel td.title { flex: 1 1 0; padding-bottom: 4px; }
  table.cards tr.hassel td[data-label="Value"] { flex: 0 0 auto; }
  table.cards tr.hassel td[data-label="Value"]::before { display: none; }
  table.cards tr.hassel td[data-label="Value"] input[type=number] { width: 104px; }
  table.cards tr.hassel td:not([data-label]):not(.title):not(.sel) { padding-top: 0; }
}

@media (max-width: 640px) {
  h1 { font-size: 18px; margin-bottom: 12px; }
  .panel { padding: 12px; }
  .row > .field { flex: 1 1 100%; }
  .toolbar > select, .toolbar > .grow { width: 100%; max-width: none; flex: 1 1 100%; }
  .kv { grid-template-columns: 1fr; gap: 0; }
  .kv dt { margin-top: 8px; }
  .pager { justify-content: space-between; }

  /* Bulk-fill bars: label on its own line, controls share the next one. */
  .bulk .sep { display: none; }
  .bulk .label { flex: 1 1 100%; }
  .bulk input[type=search], .bulk input[type=text] { flex: 1 1 100%; width: auto; }
  .bulk input[type=number] { flex: 1 1 90px; width: auto; min-width: 0; }
  .bulk > .muted { flex: 1 1 100%; }
  .bulk > button { flex: 1 1 0; }

  /* Pinned page button: full width. */
  .actionbar { margin: 12px -12px -12px; padding: 10px 12px; }
  .actionbar .grow { display: none; }
  .actionbar button { flex: 1; }

  /* Popups fill the screen; title and buttons stay pinned. */
  dialog:not(.narrow) { width: 100vw; max-width: 100vw; height: 100vh; height: 100dvh; max-height: none; margin: 0; border: 0; border-radius: 0; }
  dialog > .dialog-head { padding: 6px 6px 6px 14px; }
  .dialog-x { width: 44px; height: 44px; }
  dialog > .dialog-body { padding: 12px 14px; }
  dialog > .dialog-actions { padding: 10px 14px; flex-wrap: wrap; }
  dialog > .dialog-actions .unsaved { flex: 1 1 100%; }
  dialog > .dialog-actions button { flex: 1 1 auto; }
  .login { padding: 24px 18px 20px; }
}
