:root {
  color-scheme: dark;
  --bg: #0b0d10; --card: #15181d; --text: #e6e9ed; --muted: #9aa5b1; --line: #262b33;
  --accent: #4c8dff; --accent-text: #fff; --ok: #3fb950; --warn: #d29922; --danger: #f85149;
  --rack: #08090b; --rack-edge: #2a2f36; --key: #22262c; --key-text: #e8eaed; --lcd: #0f2a1d; --lcd-text: #7ff0b4;
}
* { box-sizing: border-box; }
body { margin: 0; font: 15px/1.45 system-ui, -apple-system, "Segoe UI", sans-serif; background: var(--bg); color: var(--text); }
header { display: flex; align-items: center; gap: 12px; padding: 12px 16px; background: var(--card); border-bottom: 1px solid var(--line); }
header h1 { font-size: 17px; margin: 0; flex: 1; }
main { max-width: 1180px; margin: 0 auto; padding: 16px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 16px; margin-bottom: 16px; }
h2 { font-size: 16px; margin: 0 0 12px; }
button, .btn { font: inherit; border: 1px solid var(--line); background: var(--card); color: var(--text); padding: 7px 12px; border-radius: 7px; cursor: pointer; }
button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); font-weight: 600; }
button.danger { color: var(--danger); }
button:disabled { opacity: .5; cursor: default; }
input[type=text], input[type=password], textarea, select { font: inherit; width: 100%; padding: 8px 10px; border: 1px solid var(--line); border-radius: 7px; background: var(--bg); color: var(--text); }
label { display: block; font-size: 13px; color: var(--muted); margin: 10px 0 4px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.muted { color: var(--muted); font-size: 13px; }
.hidden { display: none !important; }
.login { max-width: 360px; margin: 10vh auto; }
.error { color: var(--danger); font-size: 13px; min-height: 1.2em; margin-top: 6px; }

.positions { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 12px; }
.position { text-align: left; padding: 14px; border-radius: 10px; display: block; width: 100%; }
.position strong { display: block; font-size: 16px; margin-bottom: 6px; }
.badge { display: inline-block; font-size: 12px; padding: 2px 8px; border-radius: 99px; border: 1px solid currentColor; }
.badge.not_started { color: var(--muted); }
.badge.draft { color: var(--warn); }
.badge.submitted { color: var(--accent); }
.badge.programmed { color: var(--ok); }

/* Rack panels */
.rack { background: var(--rack); border: 2px solid var(--rack-edge); border-radius: 6px; padding: 10px 26px; margin-bottom: 6px; position: relative; overflow-x: auto; }
.rack::before, .rack::after { content: ""; position: absolute; top: 50%; width: 8px; height: 8px; margin-top: -4px; border-radius: 50%; background: var(--rack-edge); }
.rack::before { left: 9px; } .rack::after { right: 9px; }
.rack-title { color: #9aa5b1; font-size: 11px; letter-spacing: .08em; text-transform: uppercase; margin-bottom: 6px; }
.keyrow { display: grid; grid-template-columns: repeat(16, minmax(46px, 1fr)); gap: 5px; min-width: 780px; }
.keyrow + .keyrow { margin-top: 6px; }
.key { background: var(--key); border: 1px solid #444b54; border-radius: 4px; padding: 4px 3px 5px; color: var(--key-text); cursor: pointer; text-align: center; font: inherit; }
.key .lcd { background: var(--lcd); color: var(--lcd-text); font: 10px/1.4 ui-monospace, Menlo, Consolas, monospace; border-radius: 2px; padding: 3px 1px; min-height: 19px; white-space: nowrap; overflow: hidden; text-overflow: clip; }
.key .lcd.empty { color: #3f6b55; }
.key .num { font-size: 10px; color: #9aa5b1; margin-top: 3px; }
.key.sel { outline: 2px solid var(--accent); outline-offset: 1px; }
.key[disabled] { cursor: default; opacity: 1; }

.editor-grid > div { min-width: 0; }
.side { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; align-items: start; }
.side > .card { margin-bottom: 0; }
@media (max-width: 760px) { .side { grid-template-columns: 1fr; } }

.photos { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 10px; }
.photos figure { margin: 0; }
.photos img { width: 100%; border-radius: 8px; border: 1px solid var(--line); cursor: zoom-in; display: block; }
.photos figcaption { font-size: 13px; color: var(--muted); margin-top: 4px; }

table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 8px 6px; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { font-size: 12px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }
.table-wrap { overflow-x: auto; }
.notif { padding: 10px 12px; border-radius: 8px; border: 1px solid var(--line); margin-bottom: 8px; display: flex; justify-content: space-between; gap: 10px; align-items: center; }
.notif.unread { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 8%, transparent); }
.count { background: var(--danger); color: #fff; border-radius: 99px; font-size: 12px; padding: 1px 8px; margin-left: 6px; }
dialog { border: 1px solid var(--line); border-radius: 10px; background: var(--card); color: var(--text); max-width: min(1200px, 96vw); width: 100%; }
dialog::backdrop { background: rgba(0,0,0,.5); }
.keylist { font-size: 13px; columns: 2; column-gap: 24px; }
@media (max-width: 700px) { .keylist { columns: 1; } }
.keylist div { break-inside: avoid; padding: 2px 0; }
.crumbs { font-size: 14px; color: var(--muted); margin-bottom: 8px; }
.crumbs a { color: var(--accent); text-decoration: none; }
details.show { border: 1px solid var(--line); border-radius: 8px; margin-bottom: 10px; }
details.show > summary { padding: 12px 14px; cursor: pointer; display: flex; align-items: center; flex-wrap: wrap; gap: 4px; }
.show-body { padding: 0 14px 14px; }
.room { border-top: 1px solid var(--line); padding-top: 12px; margin-top: 12px; }
h3 { font-size: 15px; }
details.show > summary { list-style: none; }
details.show > summary::-webkit-details-marker { display: none; }
details.show > summary::before { content: "▸"; color: var(--muted); margin-right: 6px; }
details.show[open] > summary::before { content: "▾"; }
.brands { display: flex; justify-content: center; align-items: center; gap: 40px; flex-wrap: wrap; background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 18px 24px; margin-bottom: 16px; }
.brands img { height: 56px; width: auto; max-width: 42%; object-fit: contain; }
@media (max-width: 600px) { .brands { gap: 20px; padding: 14px; } .brands img { height: 34px; } }
@media print { :root { color-scheme: light; --bg: #fff; --card: #fff; --text: #000; --muted: #444; --line: #ccc; } }

/* Phones */
@media (max-width: 700px) {
  main { padding: 12px; }
  header { padding: 10px 12px; gap: 8px; }
  header h1 { font-size: 16px; }
  header .btn, header button { padding: 6px 10px; font-size: 14px; }
  .card { padding: 12px; }

  /* Keypanels wrap to 4 keys per line so every key is visible without sideways scrolling */
  .rack { padding: 8px; overflow: visible; }
  .rack::before, .rack::after { display: none; }
  .keyrow { grid-template-columns: repeat(4, 1fr); min-width: 0; gap: 6px; }
  .keyrow + .keyrow { margin-top: 6px; }
  .key { padding: 6px 4px; }
  .key .lcd { font-size: 13px; min-height: 24px; padding: 4px 2px; }
  .key .num { font-size: 11px; }

  /* Key editor stays pinned to the bottom of the screen while scrolling the panel */
  #editor { padding-bottom: 150px; }
  .side > .keyform { position: fixed; left: 0; right: 0; bottom: 0; z-index: 10; margin: 0; border-radius: 12px 12px 0 0;
    padding: 10px 12px calc(10px + env(safe-area-inset-bottom)); box-shadow: 0 -6px 20px rgba(0,0,0,.5); }
  .keyform h2 { font-size: 14px; margin: 0 0 6px; }
  .keyform label { display: none; }
  input[type=text], input[type=password], textarea, select { font-size: 16px; }
  .keyform .row { margin-top: 8px !important; flex-wrap: nowrap; }

  /* Admin tables become one card per row */
  table.stack thead { display: none; }
  table.stack tr { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 10px; padding: 10px 0; border-bottom: 1px solid var(--line); }
  table.stack td { border: 0; padding: 0; }
  table.stack td:first-child { flex: 1 1 100%; }
  table.stack td:last-child { flex: 1 1 100%; text-align: left !important; white-space: normal !important; }
  table.stack td:last-child:empty { display: none; }
  details.show > summary .row, .show-body > .row { flex-wrap: wrap; }
  #addShow, #addShow input, #backupFilter { width: 100% !important; }
}
