/* Lively web UI. One file, dark, system fonts, phone-first. app.py mounts this folder at /static. */

:root {
  color-scheme: dark;
  --bg: #0e1013;
  --panel: #161920;
  --panel-2: #1d2129;
  --line: #262b36;
  --fg: #e7e9ee;
  --muted: #8b93a4;
  --accent: #78aeff;
  --accent-strong: #5a98f2;
  --accent-fg: #0a1322;
  --danger: #e5484d;
  --danger-soft: rgba(229, 72, 77, 0.14);
  --ok: #3ecf8e;
  --warn: #f2b84b;
  --radius: 12px;
  --radius-small: 8px;
  --gap: 16px;
  --max: 1040px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.5;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

h1, h2, h3 { margin: 0 0 8px; font-weight: 600; letter-spacing: -0.01em; }
h1 { font-size: 1.6rem; }
h2 { font-size: 1.1rem; }
h3 { font-size: 1rem; }
p { margin: 0 0 12px; }
code { font-family: var(--mono); font-size: 0.9em; color: var(--fg); background: var(--panel-2); padding: 1px 6px; border-radius: 6px; overflow-wrap: break-word; }

.muted { color: var(--muted); }
.small { font-size: 0.875rem; }
.eyebrow { text-transform: uppercase; letter-spacing: 0.08em; font-size: 0.75rem; color: var(--muted); margin-bottom: 4px; }
.nowrap { white-space: nowrap; }
.num { text-align: right; font-variant-numeric: tabular-nums; }
.self-end { align-self: flex-end; }

/* ---- Layout ---------------------------------------------------------------------------------- */

.top { border-bottom: 1px solid var(--line); background: rgba(14, 16, 19, 0.9); backdrop-filter: blur(10px); position: sticky; top: 0; z-index: 10; }
/* Phone: brand and "Sign out" on the first row, the links on a second row of their own. */
.top-inner { max-width: var(--max); margin: 0 auto; padding: 8px var(--gap); display: flex; flex-wrap: wrap; align-items: center; gap: 4px 18px; }
.brand { font-weight: 700; font-size: 1.1rem; color: var(--fg); letter-spacing: -0.01em; padding: 4px 0; }
.brand:hover { text-decoration: none; }
.signout { margin: 0 0 0 auto; }
.nav { order: 3; flex: 1 0 100%; margin-left: -10px; display: flex; gap: 4px; overflow-x: auto; scrollbar-width: none; }
.nav::-webkit-scrollbar { display: none; }
.nav a, .subnav a { color: var(--muted); padding: 6px 10px; border-radius: 8px; white-space: nowrap; font-size: 0.95rem; }
.nav a:hover, .subnav a:hover { color: var(--fg); background: var(--panel); text-decoration: none; }
.nav a[aria-current="page"], .subnav a[aria-current="page"] { color: var(--fg); background: var(--panel-2); }

.subnav { display: flex; gap: 4px; margin: 0 0 20px; overflow-x: auto; scrollbar-width: none; padding-bottom: 2px; }
.subnav::-webkit-scrollbar { display: none; }

.page { flex: 1; width: 100%; max-width: var(--max); margin: 0 auto; padding: 24px var(--gap) 48px; }
.narrow { max-width: 440px; margin: 0 auto; padding-top: 24px; }
.foot { color: var(--muted); font-size: 0.8rem; text-align: center; padding: 16px; border-top: 1px solid var(--line); }

.heading { display: flex; align-items: baseline; justify-content: space-between; gap: var(--gap); flex-wrap: wrap; margin-bottom: 20px; }
.heading h1 { margin: 0; }
.heading p { margin: 0; }
.section-title { margin: 28px 0 12px; font-size: 1rem; color: var(--fg); }
.section-title .muted { font-weight: 400; }

/* ---- Cards and lists ------------------------------------------------------------------------- */

.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; }
.card + .card { margin-top: var(--gap); }
.card h2 { margin-bottom: 12px; }
.hint { margin-top: 28px; }
.hint p:last-child { margin-bottom: 0; }

.list { list-style: none; margin: 0; padding: 0; display: grid; gap: var(--gap); }
.device-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; }
.device-name { margin: 0; font-size: 1.05rem; word-break: break-word; }
.device-head p { margin: 2px 0 0; }
.is-revoked { opacity: 0.6; }

.meta { display: flex; flex-wrap: wrap; gap: 8px 24px; margin: 12px 0 0; }
.meta div { display: flex; flex-direction: column; }
.meta dt { color: var(--muted); font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.06em; }
.meta dd { margin: 0; font-size: 0.95rem; }

.kv { margin: 0; display: grid; gap: 12px; }
.kv div { display: grid; grid-template-columns: 1fr; gap: 2px; align-items: baseline; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; word-break: break-word; }

.empty { color: var(--muted); padding: 24px; border: 1px dashed var(--line); border-radius: var(--radius); text-align: center; }

.stats { display: grid; grid-template-columns: repeat(2, 1fr); gap: var(--gap); margin: 20px 0; }
.stat { display: flex; flex-direction: column; gap: 2px; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; color: var(--fg); }
.stat:hover { text-decoration: none; border-color: #353b48; }
.stat-value { font-size: 1.8rem; font-weight: 600; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }
.stat-label { color: var(--muted); font-size: 0.85rem; }
.stat-attention { border-color: rgba(120, 174, 255, 0.5); }

/* ---- Forms ----------------------------------------------------------------------------------- */

.stack { display: grid; gap: 14px; }
.row { display: flex; gap: 10px; align-items: flex-end; }
.row.wrap { flex-wrap: wrap; margin-top: 14px; }
.row .field { flex: 1; min-width: 120px; }
.inline { display: inline; margin: 0; }

.field { display: flex; flex-direction: column; gap: 6px; }
.field > span { font-size: 0.85rem; color: var(--muted); }
.field.compact > span { font-size: 0.75rem; }

input[type="text"], input[type="email"], input[type="password"], input[type="number"], input[type="file"], select {
  width: 100%;
  font: inherit;
  color: var(--fg);
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: var(--radius-small);
  padding: 10px 12px;
  min-height: 44px;
}
input:focus, select:focus, button:focus-visible, a:focus-visible, summary:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
input:disabled, select:disabled { opacity: 0.5; cursor: not-allowed; }
input[type="file"] { padding: 8px; }
select { appearance: auto; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  font: inherit;
  font-weight: 500;
  color: var(--fg);
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: var(--radius-small);
  padding: 10px 16px;
  min-height: 44px;
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
}
.btn:hover { background: #242a35; text-decoration: none; }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-fg); }
.btn-primary:hover { background: var(--accent-strong); border-color: var(--accent-strong); }
.btn-danger { color: var(--danger); border-color: rgba(229, 72, 77, 0.35); background: transparent; }
.btn-danger:hover { background: var(--danger-soft); }
.btn-quiet { background: transparent; border-color: transparent; color: var(--muted); }
.btn-quiet:hover { color: var(--fg); background: var(--panel); }
.btn-small { padding: 6px 12px; min-height: 36px; font-size: 0.9rem; }

.actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 14px; align-items: flex-start; }
.actions:empty { display: none; }

.inline-details { display: inline-block; }
.inline-details[open] { flex-basis: 100%; }
.inline-details summary { list-style: none; }
.inline-details summary::-webkit-details-marker { display: none; }
.inline-details[open] summary { background: var(--panel); }
.inline-details form { margin-top: 10px; }
.inline-details p { margin: 6px 0 0; }

.create { margin-bottom: 20px; }
.create summary { list-style: none; display: inline-flex; }
.create summary::-webkit-details-marker { display: none; }
.create[open] summary { margin-bottom: 16px; }

.notice { background: var(--panel-2); border: 1px solid var(--line); border-radius: var(--radius-small); padding: 10px 14px; }
.notice-error { border-color: rgba(229, 72, 77, 0.45); background: var(--danger-soft); color: #ffb3b5; }

.badge { display: inline-block; font-size: 0.75rem; font-weight: 600; letter-spacing: 0.02em; padding: 3px 9px; border-radius: 999px; border: 1px solid var(--line); color: var(--muted); white-space: nowrap; }
.badge-ok, .badge-done { color: var(--ok); border-color: rgba(62, 207, 142, 0.4); }
.badge-warn, .badge-queued, .badge-running { color: var(--warn); border-color: rgba(242, 184, 75, 0.4); }
.badge-failed { color: var(--danger); border-color: rgba(229, 72, 77, 0.4); }
.badge-accent { color: var(--accent); border-color: rgba(120, 174, 255, 0.4); }

/* ---- Wallpaper grid -------------------------------------------------------------------------- */

.grid { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: var(--gap); }
.tile { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; display: flex; flex-direction: column; }
.tile.is-draft { border-color: rgba(120, 174, 255, 0.45); }
.poster { position: relative; display: block; aspect-ratio: 16 / 9; background: #0b0d11; }
.poster img { width: 100%; height: 100%; object-fit: cover; display: block; }
.poster-empty { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; color: var(--muted); font-size: 0.9rem; background: linear-gradient(135deg, #141821, #0b0d11); }
.poster-time { position: absolute; right: 8px; bottom: 8px; font-size: 0.75rem; font-variant-numeric: tabular-nums; background: rgba(0, 0, 0, 0.65); color: #fff; padding: 2px 6px; border-radius: 6px; }
.tile-body { padding: 12px 14px 14px; display: flex; flex-direction: column; flex: 1; }
.tile-title { margin: 0 0 2px; font-size: 1rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tile-body p { margin: 0; }
.filename { font-family: var(--mono); font-size: 0.75rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
/* What a generated video's model was told: four lines, the whole text on hover. */
.tile-body .prompt { margin-top: 6px; font-size: 0.8rem; line-height: 1.4; display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 4; line-clamp: 4; overflow: hidden; }
.tile .actions { margin-top: auto; padding-top: 12px; }

/* ---- Tables ---------------------------------------------------------------------------------- */

.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius); background: var(--panel); -webkit-overflow-scrolling: touch; }
table { border-collapse: collapse; width: 100%; font-size: 0.9rem; }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { color: var(--muted); font-weight: 500; font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.06em; white-space: nowrap; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover td { background: rgba(255, 255, 255, 0.02); }

/* ---- Sign in with Google ----------------------------------------------------------------------- */
/* Google's button, dark theme, as its branding guidelines give it: #131314 fill, #8E918F 1px border,
   #E3E3E3 Roboto Medium 14/20 text, the four-colour G at 20 px, 12 px padding and gap, 40 px high. */

.signin { display: grid; gap: 14px; justify-items: center; text-align: center; }
.signin p { margin: 0; }
.gsi-button {
  position: relative;
  display: inline-block;
  height: 40px;
  min-width: min-content;
  max-width: 400px;
  padding: 0 12px;
  overflow: hidden;
  border: 1px solid #8e918f;
  border-radius: 20px;
  background-color: #131314;
  color: #e3e3e3;
  font-family: "Roboto", arial, sans-serif;
  font-size: 14px;
  font-weight: 500;
  letter-spacing: 0.25px;
  line-height: 38px;
  white-space: nowrap;
  text-align: center;
  vertical-align: middle;
  cursor: pointer;
  user-select: none;
}
.gsi-button:hover { text-decoration: none; box-shadow: 0 1px 2px 0 rgba(60, 64, 67, 0.3), 0 1px 3px 1px rgba(60, 64, 67, 0.15); }
.gsi-button-state { position: absolute; inset: 0; opacity: 0; background-color: #fff; }
.gsi-button:hover .gsi-button-state { opacity: 0.08; }
.gsi-button:active .gsi-button-state, .gsi-button:focus-visible .gsi-button-state { opacity: 0.12; }
.gsi-button-content { position: relative; display: flex; align-items: center; height: 100%; }
.gsi-button-icon { display: block; width: 20px; height: 20px; min-width: 20px; margin-right: 12px; }
.gsi-button-icon svg { display: block; }
.gsi-button-text { flex-grow: 1; overflow: hidden; text-overflow: ellipsis; }
.badges { display: inline-flex; flex-wrap: wrap; gap: 6px; justify-content: flex-end; }

/* ---- Wider screens --------------------------------------------------------------------------- */

@media (min-width: 640px) {
  .top-inner { flex-wrap: nowrap; padding: 10px var(--gap); }
  .nav { order: 0; flex: 1 1 auto; margin-left: 0; }
  .signout { margin-left: 0; }
  h1 { font-size: 1.9rem; }
  .page { padding-top: 32px; }
  .stats { grid-template-columns: repeat(4, 1fr); }
  .kv { gap: 10px; }
  .kv div { grid-template-columns: 220px 1fr; gap: 12px; }
  .row.wrap .field { flex: 0 1 220px; }
}

@media (prefers-reduced-motion: no-preference) {
  .btn, .stat, .tile { transition: background-color 120ms ease, border-color 120ms ease; }
}

/* Privacy and Terms: plain reading pages. */
.prose h2 { font-size: 1.05rem; margin: 1.6rem 0 0.4rem; }
.prose p, .prose li { line-height: 1.55; }
.prose ul { padding-left: 1.2rem; }
.foot a { color: inherit; opacity: 0.8; }
