:root {
  --bg: #07070a;
  --bg-elev: #0e0f14;
  --panel: #121319;
  --panel-2: #15161d;
  --line: #23252e;
  --line-bright: #2e3140;
  --text: #e9ecf2;
  --muted: #8b8f9e;
  --dim: #5a5e6c;
  --accent: #ff6a1a;
  --accent-soft: #ff8a4d;
  --accent-deep: #c24a06;
  --ok: #36d399;
  --err: #ff4d57;
  --radius: 4px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", "JetBrains Mono", "Roboto Mono", Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }

body {
  background:
    radial-gradient(1200px 600px at 50% -10%, #16131c 0%, transparent 60%),
    var(--bg);
  color: var(--text);
  font-family: var(--font);
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
  overscroll-behavior: none;
}

/* subtle CRT scanlines */
.scanlines {
  position: fixed; inset: 0; pointer-events: none; z-index: 9;
  background: repeating-linear-gradient(
    to bottom, rgba(255,255,255,0.015) 0 1px, transparent 1px 3px);
  mix-blend-mode: overlay; opacity: .5;
}

/* ===== HUD HEADER ===== */
.hud {
  position: sticky; top: 0; z-index: 5;
  padding: calc(12px + var(--safe-top)) 16px 10px;
  background: linear-gradient(180deg, rgba(10,10,14,.96), rgba(10,10,14,.82));
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
}
.hud__row { display: flex; align-items: center; justify-content: space-between; }
.hud__row--meta { margin-top: 8px; }
.hud__brand {
  font-family: var(--mono); font-weight: 700; letter-spacing: .14em;
  font-size: 13px; color: var(--text);
}
.hud__mark { color: var(--accent); margin-right: 4px; }
.hud__sub { color: var(--dim); font-weight: 500; letter-spacing: .12em; }
.hud__dept {
  font-size: 17px; font-weight: 650; letter-spacing: .01em;
  background: linear-gradient(90deg, #fff, #cfd2db);
  -webkit-background-clip: text; background-clip: text; color: transparent;
}
.hud__date { font-family: var(--mono); font-size: 13px; color: var(--muted); }
.hud__bar {
  margin-top: 10px; height: 2px; background: var(--line); border-radius: 2px; overflow: hidden;
}
.hud__bar-fill {
  display: block; height: 100%; width: 0%;
  background: linear-gradient(90deg, var(--accent-deep), var(--accent), var(--accent-soft));
  box-shadow: 0 0 12px rgba(255,106,26,.6);
  transition: width .35s cubic-bezier(.2,.8,.2,1);
}

.chip {
  font-family: var(--mono); font-size: 11px; letter-spacing: .08em;
  padding: 4px 9px; border-radius: 999px; border: 1px solid var(--line-bright);
  text-transform: uppercase; white-space: nowrap;
}
.chip--idle { color: var(--muted); }
.chip--ok   { color: var(--ok);  border-color: rgba(54,211,153,.4);  background: rgba(54,211,153,.08); }
.chip--warn { color: var(--accent); border-color: rgba(255,106,26,.45); background: rgba(255,106,26,.1); }

/* ===== FORM ===== */
.form { padding: 14px 14px 140px; max-width: 720px; margin: 0 auto; }

.loader { color: var(--muted); font-family: var(--mono); font-size: 13px; text-align: center; padding: 60px 0; }
.loader__spin {
  display: inline-block; width: 12px; height: 12px; margin-right: 8px; vertical-align: middle;
  border: 2px solid var(--line-bright); border-top-color: var(--accent); border-radius: 50%;
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.group { margin-bottom: 18px; }
.group__head {
  display: flex; align-items: center; gap: 10px;
  font-family: var(--mono); font-size: 12px; letter-spacing: .16em;
  color: var(--accent); text-transform: uppercase; margin: 6px 2px 12px;
}
.group__head::before { content: "▌"; color: var(--accent); }
.group__head::after { content: ""; flex: 1; height: 1px;
  background: linear-gradient(90deg, var(--line-bright), transparent); }

.field {
  position: relative;
  background: linear-gradient(180deg, var(--panel), var(--panel-2));
  border: 1px solid var(--line); border-radius: var(--radius);
  padding: 11px 13px; margin-bottom: 9px;
  display: flex; align-items: center; gap: 12px;
  transition: border-color .15s, box-shadow .15s, background .15s;
}
.field::before {
  content: ""; position: absolute; left: 0; top: 8px; bottom: 8px; width: 2px;
  background: var(--line-bright); border-radius: 2px; transition: background .15s;
}
.field:focus-within { border-color: var(--line-bright); box-shadow: 0 0 0 1px rgba(255,106,26,.25), 0 8px 24px rgba(0,0,0,.4); }
.field:focus-within::before { background: var(--accent); box-shadow: 0 0 10px var(--accent); }
.field--err { border-color: rgba(255,77,87,.55); }
.field--err::before { background: var(--err); }
.field--filled::before { background: var(--accent-deep); }

.field__label { flex: 1; min-width: 0; }
.field__name { display: block; font-size: 14px; color: var(--text); line-height: 1.25; }
.field__req { color: var(--accent); margin-left: 3px; }
.field__err { display: none; font-size: 11px; color: var(--err); margin-top: 3px; font-family: var(--mono); }
.field--err .field__err { display: block; }

.field__input {
  width: 116px; flex-shrink: 0; text-align: right;
  background: #0a0b10; color: var(--text);
  border: 1px solid var(--line); border-radius: 3px;
  font-family: var(--mono); font-size: 17px; font-weight: 600;
  padding: 9px 10px; outline: none; -moz-appearance: textfield;
}
.field__input::-webkit-outer-spin-button,
.field__input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.field__input::placeholder { color: var(--dim); font-weight: 400; }
.field__input:focus { border-color: var(--accent); }

.field--text { display: block; }
.field--text .field__input {
  width: 100%; text-align: left; margin-top: 9px; min-height: 64px; resize: vertical;
  font-family: var(--font); font-size: 15px; font-weight: 400; line-height: 1.4;
}

/* ===== DOCK / SUBMIT ===== */
.dock {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 6;
  padding: 12px 14px calc(12px + var(--safe-bottom));
  background: linear-gradient(0deg, rgba(7,7,10,.98) 60%, rgba(7,7,10,0));
}
.dock__note { font-family: var(--mono); font-size: 11px; color: var(--muted); text-align: center; margin-bottom: 8px; min-height: 14px; }
.dock__note--err { color: var(--err); }

.btn {
  position: relative; width: 100%; max-width: 720px; margin: 0 auto; display: block;
  background: linear-gradient(180deg, var(--accent-soft), var(--accent) 45%, var(--accent-deep));
  color: #1a0a00; border: none; border-radius: var(--radius);
  font-family: var(--mono); font-weight: 800; letter-spacing: .14em; font-size: 15px;
  padding: 16px; cursor: pointer; overflow: hidden;
  box-shadow: 0 8px 30px rgba(255,106,26,.32), inset 0 1px 0 rgba(255,255,255,.35);
  transition: transform .08s, filter .15s, opacity .15s;
}
.btn:active { transform: translateY(1px) scale(.995); filter: brightness(1.05); }
.btn:disabled { opacity: .5; filter: grayscale(.4); cursor: not-allowed; box-shadow: none; }
.btn__corner { position: absolute; width: 9px; height: 9px; border: 2px solid rgba(26,10,0,.55); }
.btn__corner--tl { top: 5px; left: 5px; border-right: 0; border-bottom: 0; }
.btn__corner--br { bottom: 5px; right: 5px; border-left: 0; border-top: 0; }

/* ===== SUCCESS ===== */
.done { text-align: center; padding: 70px 24px; animation: rise .4s ease both; }
.done__ring {
  width: 92px; height: 92px; margin: 0 auto 22px; border-radius: 50%;
  border: 2px solid rgba(255,106,26,.4);
  display: grid; place-items: center; position: relative;
  box-shadow: 0 0 40px rgba(255,106,26,.25);
}
.done__ring::after { content: "✓"; font-size: 44px; color: var(--accent); font-weight: 700; }
.done__title { font-family: var(--mono); letter-spacing: .16em; font-size: 18px; color: var(--text); }
.done__sub { color: var(--muted); font-size: 13px; margin-top: 8px; font-family: var(--mono); }
@keyframes rise { from { opacity: 0; transform: translateY(14px); } to { opacity: 1; transform: none; } }

/* ===== TOAST ===== */
.toast {
  position: fixed; left: 50%; bottom: calc(96px + var(--safe-bottom)); transform: translateX(-50%);
  z-index: 20; background: var(--panel); border: 1px solid var(--line-bright);
  color: var(--text); font-size: 13px; padding: 10px 16px; border-radius: 999px;
  box-shadow: 0 10px 30px rgba(0,0,0,.5); animation: rise .25s ease;
}
.toast--err { border-color: rgba(255,77,87,.6); color: #ffd7d9; }

.banner {
  margin: 0 0 14px; padding: 10px 12px; border: 1px dashed var(--line-bright);
  border-radius: var(--radius); color: var(--muted); font-family: var(--mono); font-size: 12px;
}
.banner b { color: var(--accent); }

/* ===== focus / readonly / edit (added) ===== */
.field { scroll-margin-top: 84px; scroll-margin-bottom: 128px; }

/* Strong, obvious highlight of the field you're currently editing. */
.field:focus-within {
  border-color: var(--accent);
  background: linear-gradient(180deg, #18141d, #17171f);
  box-shadow: 0 0 0 1px var(--accent), 0 0 22px rgba(255, 106, 26, .28),
              0 10px 26px rgba(0, 0, 0, .45);
}
.field:focus-within::before { background: var(--accent); box-shadow: 0 0 12px var(--accent); }
.field:focus-within .field__name { color: #fff; }
.field__input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(255, 106, 26, .35);
  background: #100b07;
}

/* Read-only (submitted, not yet in edit mode, or window closed). */
.field--ro { opacity: .9; }
.field--ro::before { background: var(--accent-deep); }
.field__input:disabled {
  color: var(--muted);
  -webkit-text-fill-color: var(--muted);
  cursor: default;
  border-color: var(--line);
  background: #0c0d12;
}

/* Edit button looks distinct from submit. */
.btn--edit {
  background: linear-gradient(180deg, #1b1c24, #15161d);
  color: var(--accent);
  box-shadow: inset 0 0 0 1px var(--line-bright);
}
.btn--edit:active { filter: brightness(1.15); }

/* ===== admin home / menu ===== */
.menu { display: grid; gap: 10px; padding: 6px 0; }
.menu__item {
  display: flex; flex-direction: column; gap: 3px; text-align: left;
  background: linear-gradient(180deg, var(--panel), var(--panel-2));
  border: 1px solid var(--line); border-left: 2px solid var(--accent);
  border-radius: var(--radius); padding: 14px 16px; cursor: pointer; color: var(--text);
  transition: border-color .15s, transform .06s, background .15s;
}
.menu__item:active { transform: translateY(1px); }
.menu__item:hover { border-color: var(--line-bright); }
.menu__item b { font-size: 15px; }
.menu__item span { font-size: 12px; color: var(--muted); }

/* ===== dashboard cards ===== */
.card {
  background: linear-gradient(180deg, var(--panel), var(--panel-2));
  border: 1px solid var(--line); border-radius: var(--radius); padding: 13px 14px; margin-bottom: 11px;
}
.card__head { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.card__title { font-weight: 650; font-size: 15px; }
.card__badge { font-family: var(--mono); font-size: 13px; color: var(--accent); border: 1px solid rgba(255,106,26,.4); border-radius: 999px; padding: 2px 9px; }
.cbar { height: 4px; background: var(--line); border-radius: 3px; overflow: hidden; margin: 10px 0; }
.cbar > span { display: block; height: 100%; background: linear-gradient(90deg, var(--accent-deep), var(--accent)); }
.kv { display: grid; gap: 4px; }
.kv__row { display: flex; justify-content: space-between; font-size: 13px; color: var(--muted); }
.kv__row b { color: var(--text); font-family: var(--mono); }
.missed { margin-top: 10px; font-size: 12px; color: var(--accent-soft); border-top: 1px dashed var(--line-bright); padding-top: 8px; }

/* ===== lists / rows ===== */
.btn-add {
  width: 100%; margin-bottom: 12px; padding: 12px; cursor: pointer;
  background: transparent; color: var(--accent); border: 1px dashed rgba(255,106,26,.5);
  border-radius: var(--radius); font-family: var(--mono); font-size: 13px; letter-spacing: .06em;
}
.btn-add:active { background: rgba(255,106,26,.08); }
.list { display: grid; gap: 8px; }
.row {
  display: flex; align-items: center; justify-content: space-between; gap: 10px; width: 100%; text-align: left;
  background: linear-gradient(180deg, var(--panel), var(--panel-2));
  border: 1px solid var(--line); border-radius: var(--radius); padding: 11px 13px; cursor: pointer; color: var(--text);
}
.row:active { border-color: var(--line-bright); }
.row__main { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.row__main b { font-size: 14px; }
.row__sub { font-size: 12px; color: var(--muted); }
.row__flag { font-family: var(--mono); font-size: 10px; letter-spacing: .06em; color: var(--ok); border: 1px solid rgba(54,211,153,.4); border-radius: 999px; padding: 2px 7px; text-transform: uppercase; }
.row__flag--off { color: var(--dim); border-color: var(--line-bright); }

/* ===== admin forms ===== */
.form2 { display: grid; gap: 12px; padding: 4px 0 8px; }
.f { display: grid; gap: 6px; }
.f > span { font-size: 12px; color: var(--muted); font-family: var(--mono); letter-spacing: .04em; }
.f input, .f select, .form2 input {
  background: #0a0b10; color: var(--text); border: 1px solid var(--line); border-radius: 3px;
  padding: 11px 12px; font-size: 15px; font-family: var(--font); outline: none; width: 100%;
}
.f input:focus, .f select:focus { border-color: var(--accent); box-shadow: 0 0 0 2px rgba(255,106,26,.3); }
.chkrow { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--text); cursor: pointer; padding: 3px 0; }
.chkrow input { width: 16px; height: 16px; accent-color: var(--accent); }
.chkrow--solo { margin-top: 2px; }
.form2__err { color: var(--err); font-size: 12px; font-family: var(--mono); min-height: 14px; }
#f_managed { display: grid; gap: 2px; background: #0a0b10; border: 1px solid var(--line); border-radius: 3px; padding: 8px 10px; }

/* ===== template editor ===== */
.tpl { display: grid; gap: 10px; margin-bottom: 12px; }
.tplrow { background: linear-gradient(180deg, var(--panel), var(--panel-2)); border: 1px solid var(--line); border-left: 2px solid var(--accent-deep); border-radius: var(--radius); padding: 10px 11px; display: grid; gap: 8px; }
.tplrow__top { display: flex; gap: 8px; align-items: center; }
.tplrow__btns { display: flex; gap: 4px; }
.tplrow__btns button { width: 30px; height: 32px; background: #0a0b10; color: var(--text); border: 1px solid var(--line); border-radius: 3px; cursor: pointer; font-size: 14px; }
.tplrow__btns button:disabled { opacity: .35; cursor: default; }
.tplrow__del { color: var(--err) !important; }
.tplrow__bot { display: flex; gap: 8px; align-items: center; }
.tplrow__bot > select { width: 92px; flex-shrink: 0; }
.tplrow input, .tplrow select { background: #0a0b10; color: var(--text); border: 1px solid var(--line); border-radius: 3px; padding: 8px 9px; font-size: 14px; font-family: var(--font); outline: none; width: 100%; }
.tplrow input:focus, .tplrow select:focus { border-color: var(--accent); }
.tplrow .chkrow { white-space: nowrap; }

/* ===== settings / holidays ===== */
.f textarea { background: #0a0b10; color: var(--text); border: 1px solid var(--line); border-radius: 3px; padding: 11px 12px; font-family: var(--font); font-size: 14px; line-height: 1.4; outline: none; width: 100%; resize: vertical; }
.f textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 2px rgba(255,106,26,.3); }
.hint { font-size: 12px; color: var(--muted); background: rgba(255,106,26,.06); border: 1px solid var(--line); border-radius: 3px; padding: 9px 11px; }
.hint b { color: var(--text); }
code { font-family: var(--mono); color: var(--accent-soft); }
