:root {
  color-scheme: light;
  --bg: #f4f5f7;
  --card: #ffffff;
  --surface: #ffffff;
  --hover: #f0f1f4;
  --th: #fafbfc;
  --code: #f0f1f4;
  --nav-link: #444;
  --nav-active: #000;
  --link: #8a5a00;
  --offline-bg: #fff7f7;
  --door-free: #ecfdf3; --door-free-b: #bbf7d0;
  --door-used: #eff6ff; --door-used-b: #bfdbfe;
  --door-open: #fffbeb;
  --door-off: #f3f4f6; --door-off-b: #e5e7eb;
  --badge: #eef0f3;
  --badge-green: #dcfce7; --badge-red: #fee2e2; --badge-amber: #fef3c7; --badge-blue: #dbeafe; --blue: #2563eb;
  --text: #111111;
  --muted: #6b7280;
  --border: #e3e5ea;
  --accent: #FCB040;
  --accent-dark: #E99A1F;
  --green: #16a34a;
  --red: #dc2626;
  --amber: #d97706;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 15px;
  color: var(--text);
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); }
.hidden { display: none !important; }
h1 { font-size: 22px; margin: 0 0 16px; }
h2 { font-size: 17px; margin: 24px 0 12px; }
.muted { color: var(--muted); }
.error { color: var(--red); min-height: 1em; }

nav { display: flex; align-items: center; gap: 4px; padding: 0 16px; background: var(--surface); border-bottom: 3px solid var(--accent); flex-wrap: wrap; }
nav .brand { display: flex; align-items: center; margin-right: 16px; padding: 6px 0; }
nav .brand img { height: 44px; }
nav a { color: var(--nav-link); text-decoration: none; padding: 18px 10px; font-weight: 500; }
nav a.active { color: var(--nav-active); box-shadow: inset 0 -3px var(--nav-active); }
nav #logout { color: var(--nav-link); }
main { padding: 24px 16px; max-width: 1200px; margin: 0 auto; }

.card { background: var(--card); border: 1px solid var(--border); border-radius: 10px; padding: 20px; }
.narrow { max-width: 380px; width: 100%; }
.login { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 16px; }
.login form { display: flex; flex-direction: column; gap: 12px; }

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; margin-bottom: 20px; }
.stat .value { font-size: 28px; font-weight: 700; }
.stat .label { color: var(--muted); }

.toolbar { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 12px; }
.toolbar .grow { flex: 1; }

label { display: flex; flex-direction: column; gap: 4px; font-weight: 500; font-size: 14px; }
input, select, textarea { font: inherit; padding: 8px 10px; border: 1px solid var(--border); border-radius: 6px; background: var(--surface); color: var(--text); }
textarea { min-height: 80px; }
button { font: inherit; padding: 8px 14px; border-radius: 6px; border: 1px solid var(--border); background: var(--surface); cursor: pointer; color: var(--text); }
button:hover { background: var(--hover); }
button.primary { background: var(--accent); border-color: var(--accent); color: #111; font-weight: 700; }
button.primary:hover { background: var(--accent-dark); }
button.danger { color: var(--red); }
button.small { padding: 4px 10px; font-size: 13px; }
button.link { background: none; border: none; padding: 8px; }

.table-wrap { overflow-x: auto; background: var(--card); border: 1px solid var(--border); border-radius: 10px; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--border); white-space: nowrap; }
th { font-size: 13px; color: var(--muted); font-weight: 600; background: var(--th); }
tr:last-child td { border-bottom: none; }
td.actions { text-align: right; }
td.actions button { margin-left: 4px; }
td.wrap { white-space: normal; min-width: 240px; }

.badge { display: inline-block; padding: 2px 8px; border-radius: 99px; font-size: 12px; font-weight: 600; background: var(--badge); color: var(--muted); }
.badge.green { background: var(--badge-green); color: var(--green); }
.badge.red { background: var(--badge-red); color: var(--red); }
.badge.amber { background: var(--badge-amber); color: var(--amber); }
.badge.blue { background: var(--badge-blue); color: var(--blue); }

.grid-form { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; }
.locker-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }
.pairing { display: flex; gap: 20px; align-items: center; flex-wrap: wrap; }
.pairing img { width: 220px; height: 220px; border: 1px solid var(--border); border-radius: 8px; }
code { background: var(--code); padding: 2px 6px; border-radius: 4px; word-break: break-all; }

dialog { background: var(--card); color: var(--text); border: none; border-radius: 12px; padding: 0; width: min(520px, calc(100vw - 32px)); }
dialog::backdrop { background: rgba(0, 0, 0, .4); }
dialog form { padding: 20px; display: flex; flex-direction: column; gap: 12px; }
dialog .buttons { display: flex; justify-content: flex-end; gap: 8px; margin-top: 8px; }

.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: #111; color: #fff; padding: 10px 18px; border-radius: 8px; z-index: 10; max-width: calc(100vw - 32px); }
.toast.error { background: var(--red); }

/* live monitor */
.monitor-locker { margin-bottom: 16px; }
.monitor-locker.offline { border: 2px solid var(--red); background: var(--offline-bg); }
.doors { display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 10px; margin-top: 14px; }
.door { display: flex; flex-direction: column; align-items: flex-start; gap: 2px; padding: 10px; border-radius: 8px; text-align: left; border: 2px solid transparent; min-height: 92px; }
.door .num { font-weight: 700; font-size: 16px; }
.door .size, .door .since { font-size: 12px; color: var(--muted); }
.door .state { font-size: 13px; font-weight: 600; }
.door .who { font-size: 13px; overflow: hidden; text-overflow: ellipsis; max-width: 100%; white-space: nowrap; }
.door.free { background: var(--door-free); border-color: var(--door-free-b); }
.door.used { background: var(--door-used); border-color: var(--door-used-b); }
.door.open { background: var(--door-open); border-color: var(--amber); }
.door.disabled { background: var(--door-off); border-color: var(--door-off-b); color: var(--muted); }
.door[data-offline] { opacity: .55; }
.door:hover { filter: brightness(.97); }
.legend { display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--muted); flex-wrap: wrap; }
.legend i { display: inline-block; width: 14px; height: 14px; border-radius: 4px; margin-left: 8px; }
.legend i.free { background: var(--door-free-b); } .legend i.used { background: var(--door-used-b); } .legend i.open { background: var(--amber); } .legend i.disabled { background: var(--door-off-b); }

.login-logo { display: block; width: 150px; margin: 0 auto 8px; }
a { color: var(--link); }

/* ---------------- dark mode: follows the computer's setting unless chosen in the top bar */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
  color-scheme: dark;
  --bg: #0f1115;
  --card: #1a1d23;
  --surface: #16181d;
  --text: #f3f4f6;
  --muted: #9ca3af;
  --border: #2b2f37;
  --hover: #23262d;
  --th: #1f2229;
  --code: #23262d;
  --nav-link: #c9cdd6;
  --nav-active: #fcb040;
  --link: #fcb040;
  --red: #f87171;
  --green: #4ade80;
  --amber: #fbbf24;
  --offline-bg: #2a1517;
  --door-free: #10251a; --door-free-b: #1f5135;
  --door-used: #142034; --door-used-b: #274a7a;
  --door-open: #2d2410;
  --door-off: #1f2229; --door-off-b: #2b2f37;
  --badge: #2b2f37;
  --badge-green: #12301f; --badge-red: #3b1416; --badge-amber: #3a2c0c; --badge-blue: #15284a; --blue: #93c5fd;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0f1115;
  --card: #1a1d23;
  --surface: #16181d;
  --text: #f3f4f6;
  --muted: #9ca3af;
  --border: #2b2f37;
  --hover: #23262d;
  --th: #1f2229;
  --code: #23262d;
  --nav-link: #c9cdd6;
  --nav-active: #fcb040;
  --link: #fcb040;
  --red: #f87171;
  --green: #4ade80;
  --amber: #fbbf24;
  --offline-bg: #2a1517;
  --door-free: #10251a; --door-free-b: #1f5135;
  --door-used: #142034; --door-used-b: #274a7a;
  --door-open: #2d2410;
  --door-off: #1f2229; --door-off-b: #2b2f37;
  --badge: #2b2f37;
  --badge-green: #12301f; --badge-red: #3b1416; --badge-amber: #3a2c0c; --badge-blue: #15284a; --blue: #93c5fd;
}
.logo-dark { display: none; }
:root[data-resolved="dark"] .logo-dark { display: inline; }
:root[data-resolved="dark"] .logo-light { display: none; }
.login-logo.logo-dark { display: none; }
:root[data-resolved="dark"] .login-logo.logo-dark { display: block; }
#theme { margin-left: auto; padding: 4px 8px; font-size: 13px; }

a.button { display: inline-block; font: inherit; padding: 8px 14px; border-radius: 6px; border: 1px solid var(--border); background: var(--surface); color: var(--text); text-decoration: none; cursor: pointer; }
a.button.primary { background: var(--accent); border-color: var(--accent); color: #111; font-weight: 700; }
a.button.primary:hover { background: var(--accent-dark); }

.copyright { text-align: center; color: var(--muted); font-size: 13px; padding: 24px 16px 32px; }
.copyright a { color: inherit; }
