/* MFT Doors. Neutral, big targets (HIG: 44 pt minimum, 16 pt margins), light and dark. */
:root {
  --bg: #f4f4f6;
  --surface: #ffffff;
  --text: #1b1b1f;
  --muted: #5c5c66;
  --line: #d9d9de;
  --navy: #2a2f7e;
  --on-navy: #ffffff;
  --red: #c41d2b;
  --on-red: #ffffff;
  --ok: #17703a;
  --warn-bg: #fff4d6;
  --warn-text: #5c4300;
  --err: #b3202c;
  --focus: #2a2f7e;
  --radius: 14px;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111114;
    --surface: #1d1d22;
    --text: #f0f0f4;
    --muted: #a6a6b2;
    --line: #34343c;
    --navy: #5058d6;
    --on-navy: #ffffff;
    --red: #c8212d;
    --ok: #55c284;
    --warn-bg: #3a3017;
    --warn-text: #f3d98a;
    --err: #ff8a92;
    --focus: #9aa0ff;
  }
}

*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 17px/1.35 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-tap-highlight-color: transparent;
}

.app {
  max-width: 560px;
  margin: 0 auto;
  padding: max(16px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) max(24px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
}
.app.wide { max-width: 1040px; }

h1 { font-size: 34px; line-height: 1.2; margin: 8px 0 16px; letter-spacing: 0.01em; }
h2 { font-size: 22px; line-height: 1.25; margin: 0 0 12px; }
.lede { color: var(--muted); margin: 0 0 16px; }

.bar { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 44px; }
.bar h1 { margin: 0; }

/* Buttons */
.btn {
  appearance: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 48px;
  min-width: 48px;
  padding: 0 20px;
  border: 1.5px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
}
.btn:disabled { opacity: 0.45; cursor: default; }
.btn.primary { background: var(--navy); border-color: var(--navy); color: var(--on-navy); }
.btn.danger { background: var(--red); border-color: var(--red); color: var(--on-red); }
.btn.outline { background: transparent; border-color: var(--text); }
.btn.quiet { background: transparent; border-color: transparent; color: var(--navy); }
@media (prefers-color-scheme: dark) { .btn.quiet { color: var(--focus); } }
.btn.small { min-height: 44px; padding: 0 14px; font-size: 15px; }
.btn.danger-text { color: var(--err); }
.btn.big { width: 100%; min-height: 88px; font-size: 28px; border-radius: 18px; }
.btn.outline.big { min-height: 64px; font-size: 22px; }

:focus-visible { outline: 3px solid var(--focus); outline-offset: 3px; }

/* Door list */
.list { list-style: none; margin: 0; padding: 0; display: grid; gap: 12px; }
.row {
  appearance: none;
  display: flex;
  width: 100%;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 68px;
  padding: 12px 18px;
  border: 1.5px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  text-align: left;
  cursor: pointer;
}
.row-name { font-size: 22px; font-weight: 600; }

.status { display: inline-flex; align-items: center; gap: 8px; font-size: 15px; color: var(--muted); white-space: nowrap; }
.dot { width: 10px; height: 10px; border-radius: 50%; border: 2px solid currentColor; }
.status.on { color: var(--ok); }
.status.on .dot { background: currentColor; }
.status.off .dot { background: transparent; }

/* Door screen */
.actions { display: grid; gap: 16px; margin: 8px 0 20px; }
.result { min-height: 3em; margin: 0; font-size: 20px; font-weight: 600; }
.result.good { color: var(--ok); }
.result.bad { color: var(--err); }
.result.pending { color: var(--muted); }

/* Forms and cards */
.card { background: var(--surface); border: 1.5px solid var(--line); border-radius: var(--radius); padding: 16px; margin: 16px 0; }
.form { display: grid; gap: 14px; }
.field { display: grid; gap: 6px; }
.field-label { font-size: 15px; font-weight: 600; color: var(--muted); }
input[type="text"], input[type="password"], input[type="url"], input[type="number"], select {
  width: 100%;
  min-height: 48px;
  padding: 0 14px;
  border: 1.5px solid var(--line);
  border-radius: 12px;
  background: var(--bg);
  color: var(--text);
  font: inherit;
}
.check { display: flex; align-items: center; gap: 12px; min-height: 44px; }
.check input { width: 24px; height: 24px; accent-color: var(--navy); }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 15px; word-break: break-all; }

.msg { margin: 0; min-height: 1.35em; font-size: 16px; }
.msg.error { color: var(--err); font-weight: 600; }
.msg.ok { color: var(--ok); font-weight: 600; }
.msg.warn { background: var(--warn-bg); color: var(--warn-text); padding: 12px 14px; border-radius: 12px; margin-bottom: 16px; }

/* Dialog sheet */
.sheet {
  width: min(92vw, 420px);
  padding: 20px;
  border: 1.5px solid var(--line);
  border-radius: 20px;
  background: var(--surface);
  color: var(--text);
}
.sheet::backdrop { background: rgba(0, 0, 0, 0.5); }
.sheet p { margin: 0 0 16px; color: var(--muted); }
.sheet-actions, .row-actions { display: flex; flex-wrap: wrap; gap: 12px; }
.sheet-actions .btn { flex: 1 1 140px; }

/* Admin */
.tabs { display: flex; gap: 8px; overflow-x: auto; padding: 4px 0 12px; }
.tab { appearance: none; min-height: 44px; padding: 0 16px; border: 1.5px solid var(--line); border-radius: 22px; background: var(--surface); color: var(--text); font: inherit; font-weight: 600; cursor: pointer; white-space: nowrap; }
.tab.current { background: var(--navy); border-color: var(--navy); color: var(--on-navy); }
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: 15px; }
.table th, .table td { text-align: left; padding: 10px 8px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.table th { color: var(--muted); font-weight: 600; }
.door-form { grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); align-items: end; }
.door-form h2, .door-form .row-actions { grid-column: 1 / -1; }

@media (max-width: 640px) {
  .table thead { position: absolute; left: -9999px; }
  .table tr { display: block; padding: 8px 0; border-bottom: 1px solid var(--line); }
  .table td { display: flex; justify-content: space-between; gap: 12px; border: 0; padding: 4px 0; }
  .table td::before { content: attr(data-label); color: var(--muted); font-weight: 600; }
}

@media (prefers-reduced-motion: no-preference) {
  .btn, .row, .tab { transition: opacity 0.15s ease; }
  .btn:active, .row:active { opacity: 0.8; }
}
