/* Shared design system for the Live and Setup pages. */
@font-face {
  font-family: 'PF Din Comp';
  src: url('/assets/fonts/PFDinTextCompPro-Medium.ttf') format('truetype');
  font-display: swap;
}

:root {
  --bg: #0b0d11;
  --panel: #14171e;
  --panel-2: #1b1f28;
  --panel-3: #232836;
  --line: #262b37;
  --line-2: #343a4a;
  --text: #eef0f4;
  --muted: #8e95a6;
  --red: #e2231a;
  --red-2: #ff4a3d;
  --green: #1fa855;
  --green-2: #2ed06d;
  --maroon: #6d0000;
  --blue: #3d7bff;
  --amber: #d99a1b;
  --radius: 14px;
  --din: 'PF Din Comp', 'DIN Condensed', 'Arial Narrow', sans-serif;
  --safe-b: env(safe-area-inset-bottom, 0px);
  color-scheme: dark;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html { -webkit-text-size-adjust: 100%; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body { font: 15px/1.4 -apple-system, BlinkMacSystemFont, 'Segoe UI', Inter, Roboto, sans-serif; }
button, input, select { font: inherit; color: inherit; }
button { touch-action: manipulation; }
a { color: inherit; }
[hidden] { display: none !important; }

/* ---------- top bar */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 12px;
  padding: calc(env(safe-area-inset-top, 0px) + 10px) 16px 10px;
  background: rgba(11, 13, 17, .9);
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 9px; font-family: var(--din); font-size: 24px; letter-spacing: .03em; white-space: nowrap; }
.brand small { font-family: inherit; color: var(--muted); font-size: 18px; }
.conn { width: 10px; height: 10px; border-radius: 50%; background: #666; flex: none; }
.conn.ok { background: var(--green-2); box-shadow: 0 0 0 4px rgba(46, 208, 109, .15); }
.conn.bad { background: var(--red); animation: blink 1s infinite; }
@keyframes blink { 50% { opacity: .3; } }
.spacer { flex: 1; }

/* ---------- cards */
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; min-width: 0; }
.card-title {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  margin: 0 0 12px; min-height: 30px;
  font-family: var(--din); font-size: 19px; letter-spacing: .06em; color: var(--muted); text-transform: uppercase;
}
.subhead { font-family: var(--din); font-size: 15px; letter-spacing: .08em; color: var(--muted); text-transform: uppercase; margin: 14px 0 8px; }
.hint { color: var(--muted); font-size: 13px; }

/* ---------- buttons */
.btn {
  appearance: none; border: 1px solid var(--line-2); background: var(--panel-2);
  border-radius: 10px; padding: 10px 14px; min-height: 44px;
  font-weight: 600; cursor: pointer; user-select: none; -webkit-user-select: none;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  transition: background .12s, border-color .12s, transform .06s, opacity .12s;
  text-decoration: none; white-space: nowrap;
}
.btn:hover { background: var(--panel-3); }
.btn:active { transform: scale(.97); }
.btn.sm { min-height: 34px; padding: 6px 11px; font-size: 13px; border-radius: 8px; }
.btn.ghost { background: transparent; }
.btn.primary { background: var(--blue); border-color: #5b8fff; color: #fff; }
.btn.danger { background: #3a1412; border-color: #7a1e19; color: #ffb4ad; }
.btn.pending, .take.pending { opacity: .6; }
.btn:disabled { opacity: .4; pointer-events: none; }

.seg { display: flex; border: 1px solid var(--line-2); border-radius: 11px; overflow: hidden; background: var(--panel-2); }
.seg > button {
  flex: 1; appearance: none; border: 0; border-right: 1px solid var(--line-2); background: transparent;
  min-height: 46px; padding: 6px 8px; cursor: pointer; color: var(--muted);
  font-family: var(--din); font-size: 20px; letter-spacing: .03em;
}
.seg > button:last-child { border-right: 0; }
.seg > button.on { background: #2b3a5c; color: #fff; }

.chip { appearance: none; border: 1px solid var(--line-2); background: var(--panel-2); border-radius: 999px; padding: 8px 14px; cursor: pointer; font-weight: 600; font-size: 14px; }
.chip:hover { background: var(--panel-3); }

/* ---------- inputs */
.in {
  width: 100%; min-height: 44px; background: #0e1117; border: 1px solid var(--line-2); border-radius: 10px;
  padding: 9px 12px; outline: none; transition: border-color .15s, box-shadow .15s;
}
.in:focus { border-color: var(--blue); box-shadow: 0 0 0 3px rgba(61, 123, 255, .2); }
.in.dirty { border-color: var(--amber); }
.in.saved { border-color: var(--green); }
select.in { appearance: none; background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%); background-position: calc(100% - 18px) 50%, calc(100% - 13px) 50%; background-size: 5px 5px; background-repeat: no-repeat; padding-right: 34px; }
.fld { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.fld > span { font-size: 12px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; }
.check { display: flex; align-items: center; gap: 10px; min-height: 44px; cursor: pointer; }
.check input { width: 20px; height: 20px; flex: none; accent-color: var(--blue); }
.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 12px; }

/* ---------- toasts */
#toasts { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(var(--toast-bottom, 20px) + var(--safe-b)); z-index: 100; display: flex; flex-direction: column; gap: 8px; width: min(440px, calc(100vw - 24px)); pointer-events: none; }
.toast {
  pointer-events: auto; display: flex; align-items: center; gap: 12px; justify-content: space-between;
  background: #1d2230; border: 1px solid var(--line-2); padding: 12px 14px; border-radius: 12px;
  box-shadow: 0 10px 40px rgba(0, 0, 0, .5); animation: toast-in .2s ease-out; transition: opacity .3s, transform .3s;
}
.toast.err { background: #2a1414; border-color: #7a1e19; color: #ffd0cc; }
.toast.ok { background: #122519; border-color: #1f6b3a; color: #c8f5d6; }
.toast.out { opacity: 0; transform: translateY(8px); }
.toast button { appearance: none; border: 0; background: #fff; color: #000; font-weight: 700; border-radius: 8px; padding: 8px 14px; cursor: pointer; font-family: var(--din); font-size: 17px; letter-spacing: .04em; }
@keyframes toast-in { from { opacity: 0; transform: translateY(10px); } }

/* ---------- sheets / dialogs */
dialog { color: var(--text); }
dialog::backdrop { background: rgba(0, 0, 0, .6); backdrop-filter: blur(2px); }
.sheet {
  border: 1px solid var(--line-2); background: var(--panel); border-radius: 18px; padding: 18px;
  width: min(460px, calc(100vw - 20px)); max-height: calc(100vh - 40px);
}
@media (max-width: 600px) {
  .sheet { margin: auto auto 0; border-radius: 18px 18px 0 0; width: 100vw; max-width: 100vw; padding-bottom: calc(18px + var(--safe-b)); }
}
.sheet-title { font-family: var(--din); font-size: 26px; letter-spacing: .03em; margin-bottom: 12px; }
.sheet-text { color: var(--muted); margin: 0 0 16px; }
.sheet-input { width: 100%; font-family: var(--din); font-size: 44px; text-align: center; background: #0e1117; border: 1px solid var(--line-2); border-radius: 12px; padding: 8px; outline: none; }
.sheet-input:focus { border-color: var(--blue); }
.sheet-hint { color: var(--muted); font-size: 13px; margin: 8px 2px; min-height: 1px; }
.sheet-quick { display: flex; flex-wrap: wrap; gap: 8px; margin: 10px 0 4px; }
.sheet-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 16px; }
.sheet-actions .btn { min-height: 52px; font-size: 16px; }
.sheet-title:focus { outline: none; }
