/* ============================================================
   EHP Locks — door access console
   Concept: "the room rack". One tag per door; certainty first.

   Fonts are served from this server. Nothing is fetched from a
   third party, so staff browsers make no outside requests.
   ============================================================ */

@font-face {
  font-family: 'Archivo';
  src: url('/fonts/archivo-var-latin.woff2') format('woff2-variations');
  font-weight: 400 700;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: 'Plex Mono';
  src: url('/fonts/plexmono-500-latin.woff2') format('woff2');
  font-weight: 500;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: 'Plex Mono';
  src: url('/fonts/plexmono-600-latin.woff2') format('woff2');
  font-weight: 600;
  font-style: normal;
  font-display: swap;
}

:root {
  /* canvas + ink */
  --canvas:      #EDF0F2;
  --surface:     #FFFFFF;
  --surface-2:   #F5F7F8;
  --ink:         #10151A;
  --ink-2:       #3C4650;
  --muted:       #5B6670;
  --line:        #D8DEE3;
  --line-soft:   #E7EBEE;

  /* Black, white and blue. Blue is the only colour that carries meaning;
     everything else is greyscale. Red survives in one place only: a door
     that never confirmed, and the actions that change a real lock. */
  --accent:      #1A4FD0;
  --accent-ink:  #FFFFFF;
  --accent-soft: #E8EEFC;
  --accent-line: #AFC4F4;

  /* lock state — each pair checked for >=4.5:1 at small text sizes */
  --ok:          #1A4FD0;  /* 5.9:1 on --ok-soft */
  --ok-soft:     #E8EEFC;
  --pending:     #44505C;  /* 7.2:1 on --pending-soft */
  --pending-soft:#EDF0F3;
  --risk:        #B3261E;  /* 5.6:1 on --risk-soft */
  --risk-soft:   #FCE8E6;
  --idle:        #5B6670;  /* 5.1:1 on --idle-soft */
  --idle-soft:   #EDF0F3;

  --radius:      10px;
  --radius-sm:   7px;
  --tap:         44px;

  --shadow-sheet: 0 18px 48px rgba(16, 21, 26, .18);

  --sans: 'Archivo', ui-sans-serif, system-ui, -apple-system, 'Segoe UI', sans-serif;
  --mono: 'Plex Mono', ui-monospace, 'SF Mono', Menlo, Consolas, monospace;

  /* state tints: carry door state across the rack without a side stripe */
  --tint-ok:      #F6F9FE;
  --tint-pending: #F7F9FA;
  --tint-risk:    #FDF4F3;
  --tint-idle:    var(--surface);
}

:root[data-theme="dark"],
html.dark {
  --canvas:      #0E1317;
  --surface:     #161C22;
  --surface-2:   #1C242B;
  --ink:         #E7ECF0;
  --ink-2:       #B6C1CB;
  --muted:       #8C99A5;
  --line:        #2A343D;
  --line-soft:   #222B33;

  --accent:      #7FA8FF;
  --accent-ink:  #07152F;
  --accent-soft: #16263F;
  --accent-line: #2F4C7A;

  --ok:          #7FA8FF;
  --ok-soft:     #16263F;
  --pending:     #A6B2BE;
  --pending-soft:#232B33;
  --risk:        #FF7A70;
  --risk-soft:   #3A1512;
  --idle:        #8C99A5;
  --idle-soft:   #1E262D;

  --tint-ok:      #141C28;
  --tint-pending: #1A2027;
  --tint-risk:    #241617;
  --tint-idle:    var(--surface);

  --shadow-sheet: 0 18px 48px rgba(0, 0, 0, .55);
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  background: var(--canvas);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* No interface text below 12px, so PINs and statuses stay readable
   on a phone at a door. */
small, .form-help, .signin-foot { font-size: .8125rem; }

button, a, label, select, input { touch-action: manipulation; }

h1, h2, h3 { margin: 0; font-weight: 600; letter-spacing: -0.015em; }
h1 { font-size: 1.3rem; }
h2 { font-size: 1.05rem; }
h3 { font-size: .95rem; }
p  { margin: 0; }

button, input, select, textarea { font: inherit; color: inherit; }

:where(a, button, input, select, [tabindex]):focus-visible {
  outline: 2.5px solid var(--accent);
  outline-offset: 2px;
  border-radius: 4px;
}

.hidden { display: none !important; }
.muted  { color: var(--muted); }
.sr-only {
  position: absolute; width: 1px; height: 1px;
  padding: 0; margin: -1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

svg { width: 1em; height: 1em; stroke-width: 1.8; fill: none; display: block; }

/* ============================================================
   Shell
   ============================================================ */

.app-shell {
  display: grid;
  grid-template-columns: 232px 1fr;
  height: 100vh;
  height: 100dvh;
}

.sidebar {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 18px 12px;
  background: var(--surface);
  border-right: 1px solid var(--line);
  overflow-y: auto;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 2px 8px 18px;
  font-weight: 600;
  letter-spacing: -0.02em;
}
.brand-logo { width: 28px; height: 28px; border-radius: 6px; object-fit: contain; }

.sidebar nav { display: flex; flex-direction: column; gap: 2px; }

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: var(--tap);
  padding: 0 10px;
  border: 0;
  border-radius: var(--radius-sm);
  background: none;
  color: var(--ink-2);
  text-align: left;
  cursor: pointer;
  font-weight: 500;
}
.nav-item:hover { background: var(--surface-2); color: var(--ink); }
.nav-item.active {
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 600;
}
.nav-item [data-icon] { font-size: 17px; color: currentColor; }
.nav-count {
  margin-left: auto;
  min-width: 20px;
  padding: 1px 6px;
  border-radius: 99px;
  background: var(--risk);
  color: #fff;
  font-size: .72rem;
  font-weight: 700;
  text-align: center;
  font-variant-numeric: tabular-nums;
}

.sidebar-bottom { margin-top: auto; padding-top: 14px; display: flex; flex-direction: column; gap: 2px; }

.service-note {
  display: flex;
  gap: 9px;
  padding: 10px;
  margin-bottom: 6px;
  border: 1px solid var(--line-soft);
  border-radius: var(--radius-sm);
  color: var(--muted);
  font-size: .8rem;
  line-height: 1.35;
}
.service-note [data-icon] { font-size: 15px; flex: none; margin-top: 1px; }

/* ============================================================
   Main / topbar
   ============================================================ */

.main { display: flex; flex-direction: column; min-width: 0; overflow: hidden; }

.topbar {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 14px 22px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  flex: none;
}
.topbar-titles { min-width: 0; }
.topbar-titles p { color: var(--muted); font-size: .84rem; }
.topbar-actions { margin-left: auto; display: flex; align-items: center; gap: 8px; flex: none; }

.menu-button { display: none; }

.eufy-chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 9px 14px;
  border: 1px solid var(--line);
  border-radius: 99px;
  font-size: .8125rem;
  font-weight: 500;
  color: var(--ink-2);
  white-space: nowrap;
}
.status-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--idle); flex: none; }
.eufy-chip.is-ok   { border-color: var(--ok);   color: var(--ok); }
.eufy-chip.is-ok   .status-dot { background: var(--ok); }
.eufy-chip.is-down { border-color: var(--risk); color: var(--risk); background: var(--risk-soft); }
.eufy-chip.is-down .status-dot { background: var(--risk); }

/* buttons */
.primary, .secondary, .danger, .ghost {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 30px;
  padding: 0 11px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  font-weight: 600;
  font-size: .8125rem;
  cursor: pointer;
  white-space: nowrap;
}
.primary   { background: var(--accent); color: var(--accent-ink); }
.primary:hover:not(:disabled)   { filter: brightness(1.08); }
.secondary { background: var(--surface); color: var(--ink); border-color: var(--line); }
.secondary:hover:not(:disabled) { background: var(--surface-2); }
.danger    { background: var(--surface); color: var(--risk); border-color: var(--line); }
.danger:hover:not(:disabled)    { background: var(--risk-soft); border-color: var(--risk); }
.ghost     { background: none; color: var(--ink-2); min-height: 28px; padding: 0 8px; }
.ghost:hover:not(:disabled) { background: var(--surface-2); color: var(--ink); }
.primary:disabled, .secondary:disabled, .danger:disabled, .ghost:disabled { opacity: .5; cursor: not-allowed; }
.full { width: 100%; }

.icon-button {
  display: inline-flex; align-items: center; justify-content: center;
  width: 32px; height: 32px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--ink-2);
  cursor: pointer;
}
.icon-button:hover { background: var(--surface-2); color: var(--ink); }

/* ============================================================
   Scrollable view body
   ============================================================ */

.view { flex: 1; overflow-y: auto; padding: 18px 22px 40px; }

/* ---- Attention strip: the "what needs me" line ---- */

.attention {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 16px;
}
.attention:empty { display: none; }

.alert {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  padding: 9px 13px;
  border-radius: var(--radius-sm);
  border: 1px solid;
  font-size: .86rem;
  font-weight: 500;
  cursor: pointer;
  background: var(--surface);
  text-align: left;
}
.alert strong { font-variant-numeric: tabular-nums; }
.alert.risk    { border-color: var(--risk);    background: var(--risk-soft);    color: var(--risk); }
.alert.pending { border-color: var(--pending); background: var(--pending-soft); color: var(--pending); }
.alert.calm    { border-color: var(--line);    color: var(--ink-2); }
.alert [data-icon] { font-size: 16px; }

/* ---- Day counters ---- */

.daybar {
  display: flex;
  flex-wrap: wrap;
  gap: 22px;
  padding: 0 2px 16px;
  border-bottom: 1px solid var(--line);
  margin-bottom: 16px;
}
.daystat { display: flex; align-items: baseline; gap: 8px; }
.daystat b {
  font-size: 1.5rem;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.03em;
}
.daystat span { color: var(--muted); font-size: .86rem; }

/* ---- Toolbar: search + filters + density ---- */

.toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 16px;
}

.search {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 1 1 230px;
  max-width: 340px;
  height: 32px;
  padding: 0 12px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  color: var(--muted);
}
.search:focus-within { border-color: var(--accent); }
.search input { flex: 1; min-width: 0; border: 0; background: none; outline: none; color: var(--ink); }
.search kbd {
  font-family: var(--mono);
  font-size: .68rem;
  padding: 2px 5px;
  border: 1px solid var(--line);
  border-radius: 4px;
  color: var(--muted);
}

.sort select {
  min-height: 30px;
  padding: 0 9px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface);
  font-size: .8125rem;
  cursor: pointer;
}
.sort select:focus { border-color: var(--accent); }

.filters { display: flex; gap: 6px; flex-wrap: wrap; }
.chip {
  min-height: 30px;
  padding: 0 11px;
  border: 1px solid var(--line);
  border-radius: 99px;
  background: var(--surface);
  color: var(--ink-2);
  font-size: .84rem;
  font-weight: 500;
  cursor: pointer;
}
.chip:hover { background: var(--surface-2); }
.chip[aria-pressed="true"] {
  background: var(--ink);
  border-color: var(--ink);
  color: var(--canvas);
  font-weight: 600;
}
.chip b { font-variant-numeric: tabular-nums; opacity: .75; margin-left: 4px; }

/* ============================================================
   The rack — one tag per door
   ============================================================ */

.rack {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(282px, 1fr));
  gap: 12px;
}

/* Door state is carried by the card's own surface and border, so a whole
   rack reads at a glance without a stripe down the side of every card. */
.tag {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 11px;
  padding: 15px 16px;
  background: var(--tint, var(--surface));
  border: 1px solid var(--edge, var(--line));
  border-radius: var(--radius);
  text-align: left;
}

/* The room name is the real control; it stretches over the whole card so the
   card is clickable, while the action buttons stay separately focusable. */
.tag-open {
  border: 0;
  background: none;
  padding: 0;
  font: inherit;
  font-size: 1rem;
  font-weight: 600;
  letter-spacing: -0.02em;
  color: inherit;
  cursor: pointer;
  text-align: left;
}
.tag .tag-open::after { content: ""; position: absolute; inset: 0; border-radius: var(--radius); }
.tag .tag-open:focus-visible { outline: none; }
.tag .tag-open:focus-visible::after { outline: 2.5px solid var(--accent); outline-offset: -2px; }
.tag:has(.tag-open:hover) { border-color: var(--accent-line); }
.tag-actions { position: relative; z-index: 1; }
.tag.is-selected { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }
.tag.state-ok      { --tint: var(--tint-ok);      --edge: var(--accent-line); }
.tag.state-pending { --tint: var(--tint-pending); --edge: var(--pending); }
.tag.state-risk    { --tint: var(--tint-risk);    --edge: var(--risk); }
.tag.state-idle    { --tint: var(--tint-idle);    --edge: var(--line); }

.tag-head { display: flex; align-items: flex-start; gap: 10px; }
.tag-room { min-width: 0; flex: 1; }
.tag-room h2 { font-size: 1rem; letter-spacing: -0.02em; }
.tag-room small { display: block; color: var(--muted); font-size: .8125rem; margin-top: 1px; }

.state {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  flex: none;
  padding: 4px 9px 4px 7px;
  border-radius: 99px;
  font-size: .8125rem;
  font-weight: 600;
  letter-spacing: .005em;
}
.state [data-icon] { font-size: 14px; }
.state-ok      .state, .state.ok      { background: var(--ok-soft);      color: var(--ok); }
.state-pending .state, .state.pending { background: var(--pending-soft); color: var(--pending); }
.state-risk    .state, .state.risk    { background: var(--risk-soft);    color: var(--risk); }
.state-idle    .state, .state.idle    { background: var(--idle-soft);    color: var(--idle); }

.tag-guest { display: flex; align-items: center; gap: 10px; min-height: 38px; }
.tag-guest .who { min-width: 0; flex: 1; }
.tag-guest .who strong { display: block; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tag-guest .who small  { color: var(--muted); font-size: .78rem; }

.pin {
  font-family: var(--mono);
  font-weight: 600;
  font-size: 1.02rem;
  letter-spacing: .14em;
  padding: 5px 9px;
  border-radius: 6px;
  background: var(--surface-2);
  border: 1px solid var(--line-soft);
  color: var(--ink);
  flex: none;
}
.pin.empty { color: var(--muted); letter-spacing: normal; font-family: var(--sans); font-weight: 500; }

.stay {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: .81rem;
  color: var(--ink-2);
  font-variant-numeric: tabular-nums;
}
.stay .arrow { color: var(--muted); }
.stay .nights { color: var(--muted); }

.tag-actions { display: flex; gap: 7px; flex-wrap: wrap; }
.tag-actions .primary,
.tag-actions .secondary,
.tag-actions .danger { min-height: 30px; font-size: .8125rem; padding: 0 10px; flex: 1 1 auto; }

.empty-state {
  padding: 56px 20px;
  text-align: center;
  color: var(--muted);
  border: 1px dashed var(--line);
  border-radius: var(--radius);
}
.empty-state h2 { color: var(--ink); margin-bottom: 5px; }

/* ---- table (density toggle) ---- */

.table-wrap { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: auto; }
table { width: 100%; border-collapse: collapse; font-size: .88rem; }
thead th {
  position: sticky; top: 0;
  background: var(--surface-2);
  text-align: left;
  font-size: .78rem;
  font-weight: 600;
  color: var(--muted);
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}
td, tbody th { padding: 11px 12px; border-bottom: 1px solid var(--line-soft); vertical-align: middle; text-align: left; }
tbody th { font-weight: 600; }
tbody tr:hover { background: var(--surface-2); }
tbody tr:last-child td, tbody tr:last-child th { border-bottom: 0; }
td .pin { font-size: .92rem; padding: 3px 7px; }

/* ============================================================
   Detail sheet
   ============================================================ */

.sheet-scrim {
  position: fixed; inset: 0;
  background: rgba(16, 21, 26, .45);
  z-index: 40;
}
.sheet {
  position: fixed;
  top: 0; right: 0; bottom: 0;
  width: min(440px, 100%);
  background: var(--surface);
  border-left: 1px solid var(--line);
  box-shadow: var(--shadow-sheet);
  z-index: 41;
  display: flex;
  flex-direction: column;
  animation: sheet-in .22s cubic-bezier(.2, .8, .3, 1);
}
@keyframes sheet-in { from { transform: translateX(14px); opacity: .6; } to { transform: none; opacity: 1; } }

.sheet-head {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 16px 18px;
  border-bottom: 1px solid var(--line);
  flex: none;
}
.sheet-head .titles { flex: 1; min-width: 0; }
.sheet-head h2 { font-size: 1.15rem; }
.sheet-head p { color: var(--muted); font-size: .83rem; margin-top: 2px; }

.sheet-body { flex: 1; overflow-y: auto; padding: 16px 18px 28px; display: flex; flex-direction: column; gap: 18px; }
.sheet-foot { flex: none; padding: 12px 18px; border-top: 1px solid var(--line); display: flex; gap: 8px; background: var(--surface); }

.section-title {
  font-size: .76rem;
  font-weight: 700;
  color: var(--muted);
  letter-spacing: .04em;
  margin-bottom: 9px;
}

.facts { display: grid; gap: 1px; background: var(--line-soft); border: 1px solid var(--line-soft); border-radius: var(--radius-sm); overflow: hidden; }
.fact { display: flex; gap: 12px; padding: 9px 12px; background: var(--surface); font-size: .86rem; }
.fact span  { color: var(--muted); flex: none; width: 120px; }
.fact strong { font-weight: 600; min-width: 0; word-break: break-word; }
.fact.wide span { width: auto; }

/* Money owed is the one thing a front desk must not miss. */
.note.money { font-weight: 600; }
.fact strong.owing { color: var(--risk); }

.notes-block { margin-top: 12px; display: flex; flex-direction: column; gap: 8px; }
.note-item {
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
}
.note-item p { font-size: .875rem; line-height: 1.45; white-space: pre-wrap; }
.note-item small { display: block; margin-top: 5px; color: var(--muted); font-size: .8125rem; }

.code-card {
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  background: var(--surface);
}
.code-card + .code-card { margin-top: 9px; }
.code-top { display: flex; align-items: center; gap: 10px; }
.code-top .who { flex: 1; min-width: 0; }
.code-top .who strong { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.code-top .who small { color: var(--muted); font-size: .78rem; }
.code-actions { display: flex; gap: 6px; flex-wrap: wrap; }
.code-actions button { min-height: 28px; font-size: .8125rem; padding: 0 9px; }

.note {
  font-size: .82rem;
  line-height: 1.45;
  padding: 9px 11px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--line);
  color: var(--ink-2);
  background: var(--surface-2);
}
.note.warn { border-color: var(--pending); background: var(--pending-soft); color: var(--pending); }
.note.bad  { border-color: var(--risk);    background: var(--risk-soft);    color: var(--risk); }

/* ============================================================
   Employees
   ============================================================ */

.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px;
}
.panel + .panel { margin-top: 14px; }
.panel-head { display: flex; align-items: flex-start; gap: 14px; flex-wrap: wrap; margin-bottom: 16px; }
.panel-head .titles { flex: 1; min-width: 220px; }
.panel-head p { color: var(--muted); font-size: .85rem; margin-top: 3px; }
.panel-actions { display: flex; gap: 8px; flex-wrap: wrap; }

.coverage { margin-top: 10px; }
.coverage-bar { height: 7px; border-radius: 99px; background: var(--idle-soft); overflow: hidden; }
.coverage-bar i { display: block; height: 100%; background: var(--ok); border-radius: 99px; }
.coverage small { display: block; margin-top: 6px; color: var(--muted); font-size: .8rem; font-variant-numeric: tabular-nums; }

.person {
  display: flex;
  align-items: center;
  gap: 13px;
  padding: 13px 0;
  border-top: 1px solid var(--line-soft);
  flex-wrap: wrap;
}
.person:first-child { border-top: 0; }
.avatar {
  width: 38px; height: 38px;
  flex: none;
  display: grid; place-items: center;
  border-radius: 50%;
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 700;
}
.person-main { flex: 1; min-width: 160px; }
.person-main strong { display: block; }
.person-main small { display: block; color: var(--muted); font-size: .79rem; }
.person-main .pin { font-size: .85rem; padding: 2px 6px; letter-spacing: .1em; }
.person-actions { display: flex; gap: 6px; flex-wrap: wrap; }
.person-actions button { min-height: 28px; font-size: .8125rem; padding: 0 9px; }

/* ============================================================
   Settings
   ============================================================ */

.field { display: flex; flex-direction: column; gap: 6px; font-size: .86rem; font-weight: 500; }
.field input, .field select {
  min-height: 40px;
  padding: 0 11px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface);
  outline: none;
  font-weight: 400;
}
.field input:focus, .field select:focus { border-color: var(--accent); }
.field small { font-weight: 400; color: var(--muted); }

.connect-row { display: flex; gap: 10px; align-items: flex-end; flex-wrap: wrap; }
.connect-row .field { flex: 1 1 260px; }

.conn-label {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 10px; border-radius: 99px;
  background: var(--idle-soft); color: var(--idle);
  font-size: .78rem; font-weight: 600;
}
.conn-label.connected { background: var(--ok-soft); color: var(--ok); }

.switch {
  display: flex;
  gap: 11px;
  align-items: flex-start;
  padding: 13px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: .87rem;
}
.switch input { width: 18px; height: 18px; margin: 1px 0 0; accent-color: var(--accent); flex: none; }
.switch small { display: block; color: var(--muted); font-weight: 400; margin-top: 2px; }

.flow {
  display: flex; align-items: center; gap: 9px; flex-wrap: wrap;
  padding: 12px 13px;
  border: 1px solid var(--accent-line);
  background: var(--accent-soft);
  border-radius: var(--radius-sm);
  font-size: .85rem;
  color: var(--ink-2);
  margin-bottom: 14px;
}
.flow b { color: var(--accent); }

.map-row {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  padding: 11px 0;
  border-top: 1px solid var(--line-soft);
}
.map-row:first-child { border-top: 0; }
.map-row .room { flex: 1; min-width: 150px; }
.map-row .room small { display: block; color: var(--muted); font-size: .78rem; }
.map-row select { min-width: 190px; min-height: 38px; padding: 0 10px; border: 1px solid var(--line); border-radius: var(--radius-sm); background: var(--surface); }
.map-row.unmapped select { border-color: var(--pending); }

.log { display: flex; flex-direction: column; }
.log-row { display: flex; gap: 11px; padding: 10px 0; border-top: 1px solid var(--line-soft); font-size: .86rem; }
.log-row:first-child { border-top: 0; }
.log-row i { width: 7px; height: 7px; border-radius: 50%; background: var(--ok); margin-top: 7px; flex: none; }
.log-row.is-error i { background: var(--risk); }
.log-row small { display: block; color: var(--muted); font-size: .78rem; font-variant-numeric: tabular-nums; }

/* ============================================================
   Overlays: login + modal
   ============================================================ */

.overlay {
  position: fixed; inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(16, 21, 26, .5);
  overflow-y: auto;
}
.card-form {
  width: min(430px, 100%);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sheet);
  padding: 22px;
  display: flex;
  flex-direction: column;
  gap: 13px;
  margin: auto;
}
.card-form h2 { font-size: 1.15rem; }
.card-form > p { color: var(--muted); font-size: .86rem; }
.login-brand { display: flex; align-items: center; gap: 10px; font-weight: 600; }

.modal-head { display: flex; align-items: flex-start; gap: 12px; }
.modal-head .titles { flex: 1; }
.modal-head p { color: var(--muted); font-size: .83rem; margin-top: 2px; }

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 11px; }
.grid-2 .wide { grid-column: 1 / -1; }

.pin-input { display: flex; gap: 7px; }
.pin-input input {
  flex: 1;
  font-family: var(--mono);
  font-size: 1.05rem;
  letter-spacing: .22em;
}

.form-error {
  padding: 9px 11px;
  border-radius: var(--radius-sm);
  background: var(--risk-soft);
  border: 1px solid var(--risk);
  color: var(--risk);
  font-size: .85rem;
}
.form-help { font-size: .81rem; color: var(--muted); line-height: 1.45; }
.modal-actions { display: flex; gap: 9px; }
.modal-actions .primary, .modal-actions .secondary { flex: 1; }

.challenge { display: flex; flex-direction: column; gap: 11px; }

/* Confirm: says plainly what is about to happen to a real door. */
.confirm-card { width: min(410px, 100%); gap: 14px; }
.confirm-card h2 { font-size: 1.1rem; }
.confirm-card > p { color: var(--ink-2); font-size: .9rem; }
.confirm-points {
  margin: 0;
  padding: 12px 14px 12px 30px;
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  border: 1px solid var(--line-soft);
  font-size: .86rem;
  color: var(--ink-2);
}
.confirm-points:empty { display: none; }
.confirm-points li + li { margin-top: 5px; }
.confirm-card.is-danger .primary { background: var(--risk); color: #fff; }

/* ---- All door codes: one row per code, editable in place ---- */

.rack.is-list { grid-template-columns: 1fr; gap: 8px; }

.code-line {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto auto;
  align-items: center;
  gap: 14px;
  padding: 12px 14px;
  background: var(--tint, var(--surface));
  border: 1px solid var(--edge, var(--line));
  border-radius: var(--radius);
}
.code-line.state-ok      { --tint: var(--tint-ok);      --edge: var(--accent-line); }
.code-line.state-pending { --tint: var(--tint-pending); --edge: var(--pending); }
.code-line.state-risk    { --tint: var(--tint-risk);    --edge: var(--risk); }
.code-line.state-idle    { --tint: var(--tint-idle);    --edge: var(--line); }

.code-line-main { min-width: 0; }
.code-line-main strong { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.code-line-main small { color: var(--muted); font-size: .8125rem; }
.code-line-actions { display: flex; gap: 7px; flex-wrap: wrap; }
.code-line-actions button { min-height: 28px; font-size: .8125rem; padding: 0 9px; }
.code-line-note { grid-column: 1 / -1; margin: 0; }

@media (max-width: 760px) {
  .code-line { grid-template-columns: auto minmax(0, 1fr); }
  .code-line .state { grid-column: 2; justify-self: start; }
  .code-line-actions { grid-column: 1 / -1; }
  .code-line-actions button { flex: 1 1 auto; }
}

/* Rooms with nothing booked stay out of the way. */
.tag.is-empty { gap: 8px; padding: 12px 14px; }
.tag.is-empty .tag-room h2 { font-size: .94rem; font-weight: 500; }
.tag.is-empty .tag-guest { min-height: 0; }
.challenge img { width: 100%; border-radius: var(--radius-sm); border: 1px solid var(--line); background: #fff; }

/* ============================================================
   Toast
   ============================================================ */

.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translate(-50%, 18px);
  z-index: 60;
  max-width: min(440px, calc(100vw - 32px));
  padding: 11px 16px;
  border-radius: var(--radius-sm);
  background: var(--ink);
  color: var(--canvas);
  font-size: .88rem;
  font-weight: 500;
  opacity: 0;
  pointer-events: none;
  transition: opacity .18s, transform .18s;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.error { background: var(--risk); color: #fff; }

/* ============================================================
   Responsive
   ============================================================ */

@media (max-width: 920px) {
  .app-shell { grid-template-columns: 1fr; }

  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    width: 258px;
    z-index: 45;
    transform: translateX(-100%);
    transition: transform .22s cubic-bezier(.2, .8, .3, 1);
  }
  .sidebar.open { transform: none; }
  .nav-scrim { position: fixed; inset: 0; background: rgba(16, 21, 26, .45); z-index: 44; }

  .menu-button { display: inline-flex; }
  .topbar { padding: 11px 14px; gap: 10px; }
  .topbar-titles { overflow: hidden; }
  .topbar-titles h1 { font-size: 1.1rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .topbar-titles p { display: none; }
  /* The attention strip already reports a lost Eufy connection in red,
     so the chip is redundant where space is tight. */
  .eufy-chip { display: none; }
  .view { padding: 14px 14px 110px; }

  .rack { grid-template-columns: 1fr; }
  .sheet { width: 100%; top: auto; height: 92dvh; border-left: 0; border-top-left-radius: 14px; border-top-right-radius: 14px; animation: sheet-up .24s cubic-bezier(.2, .8, .3, 1); }
  @keyframes sheet-up { from { transform: translateY(22px); opacity: .7; } to { transform: none; opacity: 1; } }

  .daybar { gap: 16px; }
  .daystat b { font-size: 1.3rem; }
  .grid-2 { grid-template-columns: 1fr; }
  .fact span { width: 104px; }
}

@media (max-width: 420px) {
  .tag-actions { flex-direction: column; }
  .tag-actions .primary, .tag-actions .secondary, .tag-actions .danger { width: 100%; }
}

/* Touch devices: every control reaches the 44px target and 8px spacing
   Apple and Material ask for, without inflating the pointer layout. */
@media (pointer: coarse) {
  .primary, .secondary, .danger, .ghost,
  .chip, .icon-button,
  .code-actions button, .person-actions button, .tag-actions button {
    min-height: var(--tap);
  }
  .icon-button { width: var(--tap); }
  .code-actions, .person-actions, .tag-actions, .filters, .panel-actions { gap: 8px; }
  .field input, .field select, .map-row select { min-height: var(--tap); }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .001ms !important; transition-duration: .001ms !important; }
}

@media print { .sidebar, .topbar-actions, .toolbar, .tag-actions { display: none !important; } }
