:root {
  --bg: #f4f6f9;
  --card: #fff;
  --text: #1c2330;
  --muted: #5b6575;
  --line: #dde2ea;
  --primary: #1f5fa8;
  --primary-dark: #174a84;
  --ok: #1d7a46;
  --ok-bg: #e5f4ec;
  --warn: #9a5b00;
  --warn-bg: #fff3dc;
  --danger: #b3261e;
  --danger-bg: #fdecea;
  --radius: 10px;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.45;
}
a { color: var(--primary); }
h1 { font-size: 1.4rem; margin: 0 0 1rem; }
h2 { font-size: 1.1rem; margin: 0 0 .75rem; }

.topbar {
  background: var(--primary);
  color: #fff;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: .5rem;
  padding: .6rem 1rem;
}
.brand { color: #fff; font-weight: 700; text-decoration: none; font-size: 1.1rem; margin-right: auto; }
.menu-toggle { background: transparent; color: #fff; border: 1px solid rgba(255,255,255,.6); }
.nav { display: none; width: 100%; flex-direction: column; gap: .1rem; }
.nav.open { display: flex; }
.nav a, .nav .link {
  color: #fff; text-decoration: none; padding: .5rem .6rem; border-radius: 6px; text-align: left;
  background: none; border: 0; font: inherit; cursor: pointer;
}
.nav a.active, .nav a:hover, .nav .link:hover { background: rgba(255,255,255,.18); }
@media (min-width: 900px) {
  .menu-toggle { display: none; }
  .nav, .nav.open { display: flex; flex-direction: row; width: auto; flex-wrap: wrap; }
}

main { max-width: 1100px; margin: 0 auto; padding: 1rem; outline: none; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem; margin-bottom: 1rem; }
.narrow { max-width: 420px; margin: 2rem auto; }

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: .75rem; margin-bottom: 1rem; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: .8rem; }
.stat .num { font-size: 1.6rem; font-weight: 700; }
.stat .lbl { color: var(--muted); font-size: .9rem; }
.bar { height: 8px; background: var(--line); border-radius: 4px; overflow: hidden; margin-top: .4rem; }
.bar > span { display: block; height: 100%; background: var(--primary); }

form .row { display: grid; gap: .75rem; grid-template-columns: 1fr; margin-bottom: .75rem; }
@media (min-width: 600px) {
  form .row.cols-2 { grid-template-columns: 1fr 1fr; }
  form .row.cols-3 { grid-template-columns: 1fr 1fr 1fr; }
  form .row.cols-4 { grid-template-columns: repeat(4, 1fr); }
}
label { display: block; font-weight: 600; font-size: .9rem; margin-bottom: .25rem; }
.hint { color: var(--muted); font-size: .85rem; font-weight: 400; }
input, select {
  width: 100%; padding: .55rem .6rem; font: inherit; border: 1px solid #b9c2cf; border-radius: 6px; background: #fff; color: var(--text);
}
input:focus, select:focus, button:focus-visible { outline: 2px solid var(--primary); outline-offset: 1px; }
input[type=checkbox] { width: auto; }
button {
  font: inherit; padding: .55rem 1rem; border-radius: 6px; border: 1px solid var(--primary);
  background: var(--primary); color: #fff; cursor: pointer;
}
button:hover { background: var(--primary-dark); }
button.secondary { background: #fff; color: var(--primary); }
button.secondary:hover { background: #eef3fa; }
button.danger { background: #fff; color: var(--danger); border-color: var(--danger); }
button.danger:hover { background: var(--danger-bg); }
button.small { padding: .25rem .6rem; font-size: .85rem; }
.actions { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: .92rem; }
th, td { text-align: left; padding: .45rem .5rem; border-bottom: 1px solid var(--line); vertical-align: top; }
th { color: var(--muted); font-weight: 600; white-space: nowrap; }
td.num, th.num { text-align: right; white-space: nowrap; }
code, .code { font-family: ui-monospace, "SFMono-Regular", Consolas, monospace; font-weight: 600; }

.badge { display: inline-block; padding: .1rem .5rem; border-radius: 999px; font-size: .8rem; font-weight: 600; }
.badge.free { background: var(--ok-bg); color: var(--ok); }
.badge.occ { background: #e6eefa; color: var(--primary-dark); }
.badge.blocked { background: var(--danger-bg); color: var(--danger); }
.badge.in { background: var(--ok-bg); color: var(--ok); }
.badge.out { background: var(--warn-bg); color: var(--warn); }

.msg { padding: .6rem .8rem; border-radius: 6px; margin-bottom: .75rem; }
.msg.error { background: var(--danger-bg); color: var(--danger); }
.msg.ok { background: var(--ok-bg); color: var(--ok); }
.muted { color: var(--muted); }

.toast {
  position: fixed; left: 50%; bottom: 1rem; transform: translateX(-50%);
  background: #1c2330; color: #fff; padding: .6rem 1rem; border-radius: 8px; max-width: 90vw;
  opacity: 0; pointer-events: none; transition: opacity .2s;
}
.toast.show { opacity: 1; }
.toast.error { background: var(--danger); }

.filters { display: flex; flex-wrap: wrap; gap: .5rem; margin-bottom: .75rem; }
.filters > * { flex: 1 1 160px; }
.levels { display: grid; grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); gap: .5rem; }
.preview { font-family: ui-monospace, Consolas, monospace; background: var(--bg); padding: .4rem .6rem; border-radius: 6px; }
dialog { border: 1px solid var(--line); border-radius: var(--radius); max-width: 460px; width: calc(100% - 2rem); }
dialog::backdrop { background: rgba(0,0,0,.35); }

h3 { font-size: 1rem; margin: 1rem 0 .5rem; }
.scene-wrap { display: grid; grid-template-columns: 1fr; gap: 1rem; }
.scene-holder { position: relative; }
.scene { height: 60vh; min-height: 320px; border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; background: #eef2f7; }
.scene canvas { display: block; width: 100%; height: 100%; touch-action: none; }
.scene-tip {
  position: absolute; pointer-events: none; background: #1c2330; color: #fff; font-size: .85rem;
  padding: .2rem .5rem; border-radius: 4px; white-space: nowrap; font-family: ui-monospace, Consolas, monospace;
}
.scene-panel { margin-bottom: 0; }
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: .5rem; }
.panel-head h2 { margin: 0; }
.out-form { border-top: 1px solid var(--line); padding-top: .6rem; margin-bottom: .6rem; }
.item-head { margin-bottom: .4rem; }
.in-form { border-top: 2px solid var(--line); margin-top: .75rem; }
.legend { display: flex; flex-wrap: wrap; align-items: center; gap: .3rem; font-size: .9rem; margin: .25rem 0; }
.dot { display: inline-block; width: .9rem; height: .9rem; border-radius: 3px; margin-left: .4rem; }
.dot.free { background: #3aa55d; opacity: .6; }
.dot.occ { background: #1f5fa8; }
.dot.blocked { background: #c0392b; opacity: .6; }
.dot.match { background: #f2b705; }
@media (min-width: 900px) {
  .scene-wrap { grid-template-columns: 1fr 340px; }
  .scene { height: 70vh; }
}
