:root {
  --bg: #06080d;
  --bg-elevated: #0c1018;
  --surface: #121826;
  --surface-hover: #1a2233;
  --border: rgba(148, 163, 184, 0.12);
  --text: #f1f5f9;
  --muted: #94a3b8;
  --accent: #3b82f6;
  --danger: #ef4444;
  --danger-bg: rgba(127, 29, 29, 0.88);
  --free: #eab308;
  --free-bg: rgba(133, 77, 14, 0.92);
  --control-h: 42px;
  --font: "DM Sans", system-ui, -apple-system, sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, monospace;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
  margin: 0;
  overflow: hidden;
}

body {
  font-family: var(--font);
  color: var(--text);
  background: var(--bg);
}

.app-shell {
  display: flex;
  flex-direction: column;
  height: 100%;
  width: 100%;
  min-height: 0;
}

.control-bar {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  min-height: var(--control-h);
  padding: 0.25rem 0.5rem;
  border-bottom: 1px solid var(--border);
  background: var(--bg-elevated);
  z-index: 10;
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  flex-shrink: 0;
}

.brand-mark {
  width: 28px;
  height: 28px;
  border-radius: 7px;
  background: linear-gradient(135deg, #1d4ed8, #0891b2);
  display: grid;
  place-items: center;
  color: #fff;
}

.brand-mark svg {
  width: 16px;
  height: 16px;
}

.brand h1 {
  margin: 0;
  font-size: 0.95rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  white-space: nowrap;
}

.stats-inline {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.35rem;
  flex: 1;
  min-width: 0;
  justify-content: center;
}

.stat-pill {
  font-size: 0.68rem;
  padding: 0.15rem 0.45rem;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--surface);
  white-space: nowrap;
}

.stat-pill em {
  font-style: normal;
  color: var(--muted);
  margin-right: 0.25rem;
  text-transform: uppercase;
  font-size: 0.6rem;
  letter-spacing: 0.04em;
}

.stat-pill.danger em { color: #fca5a5; }
.stat-pill.free em { color: #fde047; }

.toolbar {
  display: flex;
  flex-wrap: nowrap;
  gap: 0.3rem;
  align-items: center;
  flex-shrink: 0;
}

.search-wrap {
  position: relative;
}

.search-wrap input {
  width: 7.5rem;
  padding: 0.28rem 0.5rem 0.28rem 1.65rem;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 0.75rem;
  outline: none;
}

.search-wrap input:focus {
  border-color: rgba(59, 130, 246, 0.55);
  width: 10rem;
}

.search-wrap svg {
  position: absolute;
  left: 0.45rem;
  top: 50%;
  transform: translateY(-50%);
  width: 0.85rem;
  height: 0.85rem;
  opacity: 0.5;
}

.chip {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 26px;
  padding: 0;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--surface);
  cursor: pointer;
  user-select: none;
}

.chip:not(.active) {
  opacity: 0.35;
}

.chip-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
}

.chip-dot.blocked { background: var(--danger); }
.chip-dot.free { background: var(--free); }
.chip-dot.other { background: #64748b; }

.alert {
  flex-shrink: 0;
  margin: 0;
  padding: 0.35rem 0.5rem;
  border-bottom: 1px solid rgba(239, 68, 68, 0.35);
  background: rgba(127, 29, 29, 0.35);
  color: #fecaca;
  font-size: 0.72rem;
}

.map-viewport {
  flex: 1;
  min-height: 0;
  overflow: auto;
  padding: 0.35rem 0.4rem 0.5rem;
}

.map-stack {
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
}

.group-card {
  border: 1px solid;
  border-radius: 6px;
  background: var(--bg-elevated);
  overflow: hidden;
}

.group-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 0.2rem 0.45rem;
  border-bottom: 1px solid var(--border);
  min-height: 24px;
}

.group-title {
  font-weight: 700;
  font-size: 0.72rem;
  letter-spacing: 0.04em;
}

.group-meta {
  display: flex;
  gap: 0.35rem;
  font-family: var(--mono);
  font-size: 0.62rem;
  color: var(--muted);
}

.group-meta .meta-blocked { color: #fca5a5; }
.group-meta .meta-free { color: #fde047; }

.group-body {
  padding: 0.3rem 0.35rem 0.35rem;
  overflow-x: auto;
}

.block + .block {
  margin-top: 0.45rem;
  padding-top: 0.45rem;
  border-top: 1px dashed var(--border);
}

.row {
  display: flex;
  flex-wrap: nowrap;
  align-items: stretch;
  gap: 2px;
  margin-bottom: 2px;
}

.cell {
  flex: 0 0 2.1rem;
  width: 2.1rem;
  height: 1.125rem;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--mono);
  font-size: 8px;
  line-height: 1;
  text-align: center;
  white-space: nowrap;
  border: 1px solid rgba(51, 65, 85, 0.65);
  background: var(--surface);
  border-radius: 2px;
  color: #94a3b8;
}

.cell:hover {
  z-index: 1;
  position: relative;
  outline: 1px solid rgba(148, 163, 184, 0.45);
}

.cell.blocked {
  background: var(--danger-bg);
  border-color: var(--danger);
  color: #fecaca;
}

.cell.free {
  background: var(--free-bg);
  border-color: var(--free);
  color: #fef9c3;
}

.cell.match {
  outline: 2px solid #fff;
  outline-offset: 0;
  z-index: 2;
}

.cell.dimmed {
  opacity: 0.18;
}

@media (max-width: 720px) {
  .stats-inline {
    display: none;
  }
  .search-wrap input {
    width: 5.5rem;
  }
}
