:root {
  --ink: #1d1a16;
  --muted: #6d6458;
  --paper: #f3efe6;
  --card: #fffdf8;
  --line: #ddd4c4;
  --side: #1c1914;
  --side-2: #2a241c;
  --copper: #b85a28;
  --copper-ink: #fff7ef;
  --ok: #1f6b43;
  --ok-bg: #e5f4ea;
  --warn: #9a6b12;
  --warn-bg: #f8efd4;
  --bad: #9b2c1a;
  --bad-bg: #f8e4de;
  --wait: #4d5a6a;
  --wait-bg: #e7ebf0;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
html { overflow-x: hidden; }
body {
  font-family: "IBM Plex Sans", "Segoe UI", sans-serif;
  background: var(--paper);
  color: var(--ink);
  display: flex;
  max-width: 100%;
  overflow-x: hidden;
}

a { color: var(--copper); text-decoration: none; }
a:hover { text-decoration: underline; }
code, .mono {
  font-family: "IBM Plex Mono", ui-monospace, monospace;
  font-size: 0.86em;
}

.sidebar {
  width: 248px;
  min-height: 100vh;
  background: var(--side);
  color: #efe7da;
  padding: 22px 18px;
  display: flex;
  flex-direction: column;
  gap: 28px;
  position: sticky;
  top: 0;
}
.brand { display: flex; gap: 12px; align-items: center; }
.brand-mark {
  width: 40px; height: 40px; border-radius: 10px;
  background: var(--copper); color: var(--copper-ink);
  display: grid; place-items: center;
  font-family: "Source Serif 4", Georgia, serif;
  font-weight: 600; font-size: 1.1rem;
}
.brand strong { display: block; font-size: 0.95rem; }
.brand small { color: #b8aa96; }

.sidebar nav { display: flex; flex-direction: column; gap: 4px; }
.sidebar nav a {
  color: #d8cbb8;
  padding: 9px 11px;
  border-radius: 8px;
  text-decoration: none;
}
.sidebar nav a.on,
.sidebar nav a:hover { background: var(--side-2); color: #fff; text-decoration: none; }

.sidebar-fila button,
.btn {
  border: 0;
  border-radius: 8px;
  padding: 10px 14px;
  font: inherit;
  cursor: pointer;
}
.sidebar-fila button {
  width: 100%;
  background: #3a3228;
  color: #efe7da;
}
.sidebar-user { margin-top: auto; font-size: 0.88rem; color: #c9bba6; }
.sidebar-user small { display: block; text-transform: uppercase; letter-spacing: 0.04em; margin: 4px 0 10px; }
.sidebar-user a { color: #e8c4a6; }

.topbar, .nav-backdrop { display: none; }
.menu-btn { display: none; }

.main { flex: 1; padding: 28px 32px 48px; min-width: 0; max-width: 100%; overflow-x: hidden; }
.card { max-width: 100%; }
.table-wrap { width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch; }
.page-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; margin-bottom: 22px; }
.page-head h1 {
  font-family: "Source Serif 4", Georgia, serif;
  font-weight: 600;
  font-size: 2rem;
  margin: 0;
}
.eyebrow {
  text-transform: uppercase;
  letter-spacing: 0.12em;
  font-size: 0.72rem;
  color: var(--muted);
  margin: 0 0 6px;
}
.lead, .muted { color: var(--muted); }
.tiny { font-size: 0.75rem; }

.stats {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 22px;
}
.stats.compact { grid-template-columns: repeat(6, minmax(0, 1fr)); }
.stats article {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 14px 16px;
}
.stats strong { display: block; font-size: 1.7rem; line-height: 1.1; }
.stats span { color: var(--muted); font-size: 0.82rem; }
.stat-bad { border-color: #e3b2a6; background: var(--bad-bg); }

.grid-2 { display: grid; grid-template-columns: 1.2fr 0.8fr; gap: 16px; margin-bottom: 16px; }
.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 18px 18px 8px;
  margin-bottom: 16px;
}
.card h2 { margin: 0 0 12px; font-size: 1.05rem; }
.card-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 8px; }
.card-head h2 { margin: 0; }

.table { width: 100%; border-collapse: collapse; font-size: 0.92rem; }
.table th, .table td { text-align: left; padding: 10px 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
.table th { color: var(--muted); font-weight: 500; font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.04em; }

.badge {
  display: inline-block;
  border-radius: 999px;
  padding: 2px 8px;
  font-size: 0.75rem;
  font-weight: 500;
}
.badge-ok { background: var(--ok-bg); color: var(--ok); }
.badge-warn { background: var(--warn-bg); color: var(--warn); }
.badge-bad { background: var(--bad-bg); color: var(--bad); }
.badge-wait { background: var(--wait-bg); color: var(--wait); }

.btn-primary { background: var(--copper); color: var(--copper-ink); }
.btn-ghost { background: transparent; border: 1px solid var(--line); color: var(--ink); }
.row-actions { display: flex; gap: 8px; }
.row-actions input { width: 150px; margin: 0; }
.team-actions {
  display: flex;
  align-items: center;
  flex-wrap: nowrap;
  gap: 8px;
}
.team-actions form {
  display: flex;
  align-items: center;
  gap: 6px;
  margin: 0;
}
.team-actions input {
  width: 118px;
  margin: 0;
  padding: 8px 10px;
}
.team-actions .btn {
  padding: 8px 10px;
  white-space: nowrap;
}
.table td:has(.team-actions) {
  white-space: nowrap;
  width: 1%;
}

label { display: block; font-weight: 500; margin-bottom: 12px; }
input, select {
  display: block;
  width: 100%;
  margin-top: 6px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  font: inherit;
}
.check { display: flex; align-items: center; gap: 8px; font-weight: 400; }
.check input { width: auto; margin: 0; }
.stack { max-width: 520px; }
.form-card p { margin-top: 0; }
.ocr-card { padding: 22px 20px 24px; }
.ocr-grid {
  display: grid;
  grid-template-columns: minmax(260px, 0.9fr) minmax(0, 1.2fr);
  gap: 28px;
  align-items: start;
}
.ocr-pane h2 { margin: 0 0 8px; font-size: 1.15rem; }
.ocr-pane .kicker {
  margin: 0 0 4px;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}
.ocr-drop {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 52px;
  border: 1px dashed var(--line);
  border-radius: 12px;
  background: #f7f4ee;
  cursor: pointer;
  margin: 14px 0 12px;
}
.ocr-drop input { display: none; }
.ocr-preview-wrap {
  border: 1px solid var(--line);
  border-radius: 12px;
  min-height: 180px;
  display: grid;
  place-items: center;
  overflow: hidden;
  background: #f3efe6;
  margin-bottom: 12px;
}
.ocr-preview-wrap img { width: 100%; height: auto; display: none; }
.ocr-preview-wrap img.is-on { display: block; }
.ocr-fields label { margin-bottom: 12px; }
.ocr-pair {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 12px;
}
@media (max-width: 900px) {
  .ocr-grid { grid-template-columns: 1fr; }
}
.filters {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}
.filters input, .filters select { width: auto; min-width: 180px; margin: 0; }
.filters-card { padding: 16px 18px; }
.filters-full {
  display: grid;
  grid-template-columns: minmax(0, 1.6fr) minmax(0, 1fr) minmax(0, 1fr) auto;
  gap: 10px;
  width: 100%;
  margin: 0;
  align-items: stretch;
}
.filters-full input,
.filters-full select { width: 100%; min-width: 0; }
.filters-full .btn { height: 100%; min-height: 42px; }
.filters-full.cols-5 {
  grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr) minmax(0, 1fr) minmax(0, 1fr) auto;
}

.flash { border-radius: 10px; padding: 10px 12px; margin-bottom: 16px; }
.flash-ok { background: var(--ok-bg); color: var(--ok); }
.flash-bad { background: var(--bad-bg); color: var(--bad); }

.confirm-card { background: #fff8ee; }
.confirm-form { display: grid; grid-template-columns: 1fr auto auto; gap: 16px; align-items: end; }
.fila-list { list-style: none; padding: 0; }
.fila-list li { display: flex; justify-content: space-between; padding: 8px 0; border-bottom: 1px solid var(--line); }

.kv { display: grid; gap: 10px; }
.kv div { display: grid; grid-template-columns: 140px 1fr; gap: 8px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; }
.timeline { list-style: none; padding: 0; }
.timeline li { padding: 8px 0; border-bottom: 1px solid var(--line); }
.timeline span { display: block; font-size: 0.82rem; }

.auth-body {
  display: grid;
  place-items: center;
  min-height: 100vh;
  background:
    radial-gradient(circle at 10% 20%, #e8d3b8 0, transparent 40%),
    radial-gradient(circle at 90% 80%, #d7c4a6 0, transparent 36%),
    var(--paper);
}
.auth-card {
  width: min(440px, 92vw);
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 32px;
  box-shadow: 0 20px 50px rgba(40, 28, 16, 0.08);
}
.auth-card h1 {
  font-family: "Source Serif 4", Georgia, serif;
  margin: 0 0 8px;
}
.hint { font-size: 0.82rem; color: var(--muted); }

.head-side { display: flex; flex-direction: column; align-items: flex-end; gap: 10px; }
.op-pill {
  display: inline-flex; align-items: center; gap: 6px;
  border-radius: 999px; padding: 5px 10px; font-size: 0.8rem; font-weight: 600;
}
.op-pill.is-ok { background: var(--ok-bg); color: var(--ok); }
.op-pill.is-warn { background: var(--warn-bg); color: var(--warn); }
.grid-ops { display: grid; grid-template-columns: 1.4fr 0.8fr; gap: 16px; margin-bottom: 16px; }
.ops-map {
  position: relative; height: 280px; border-radius: 12px; overflow: hidden;
  background: #dfe8df;
}
.map-grid {
  position: absolute; inset: 0;
  background:
    linear-gradient(rgba(255,255,255,0.35) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255,255,255,0.35) 1px, transparent 1px);
  background-size: 28px 28px;
}
.map-empty { position: relative; padding: 40px 16px; text-align: center; color: var(--muted); }
.pin {
  position: absolute; transform: translate(-50%, -50%);
  display: flex; flex-direction: column; align-items: center; gap: 4px;
}
.pin span {
  width: 28px; height: 28px; border-radius: 50%;
  display: grid; place-items: center; color: #fff; font-weight: 700; font-size: 0.78rem;
  box-shadow: 0 4px 10px rgba(0,0,0,0.15);
}
.pin em { font-style: normal; font-size: 0.7rem; background: #fff; padding: 1px 6px; border-radius: 8px; }
.pin.live span { background: #1f7a4d; }
.pin.pause span { background: #c4881c; }
.pin.off span { background: #8a8a8a; }
.crew, .occ { list-style: none; padding: 0; margin: 0 0 12px; }
.crew li, .occ li { display: flex; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.crew strong, .occ strong { display: block; }
.crew small, .occ span, .occ small { display: block; color: var(--muted); font-size: 0.82rem; }
.dot { width: 10px; height: 10px; border-radius: 50%; margin-top: 6px; flex-shrink: 0; }
.dot.ok { background: #1f7a4d; }
.dot.warn { background: #c4881c; }
.dot.off { background: #9aa0a6; }
.tech-card { background: #f7f4ee; }
.tech-alert { background: var(--bad-bg); color: var(--bad); padding: 8px 10px; border-radius: 8px; }
.mass-bar {
  display: flex; flex-wrap: wrap; gap: 12px; align-items: end;
  padding-bottom: 12px; margin-bottom: 8px; border-bottom: 1px solid var(--line);
}
.mass-bar label { margin: 0; }
.mass-bar select { min-width: 200px; }

@media (max-width: 1100px) {
  .stats, .stats.compact { grid-template-columns: repeat(3, 1fr); }
  .grid-2, .grid-ops, .confirm-form { grid-template-columns: 1fr; }
  .filters-full { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 780px) {
  body { display: block; }
  .topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    position: sticky;
    top: 0;
    z-index: 60;
    background: var(--side);
    color: #efe7da;
    padding: 10px 12px;
  }
  .topbar .brand { min-width: 0; }
  .topbar .brand strong { font-size: 0.88rem; }
  .topbar .brand small { display: block; font-size: 0.68rem; }
  .menu-btn {
    display: grid;
    place-items: center;
    width: 42px;
    height: 42px;
    flex-shrink: 0;
    border: 0;
    border-radius: 10px;
    background: #3a3228;
    color: #efe7da;
    cursor: pointer;
  }
  .menu-btn .ico:last-child { display: none; }
  body.menu-open .menu-btn .ico:first-child { display: none; }
  body.menu-open .menu-btn .ico:last-child { display: block; }
  .nav-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 45;
    background: rgba(20, 16, 12, 0.55);
  }
  body.menu-open .nav-backdrop { display: block; }
  body.menu-open { overflow: hidden; }
  .sidebar-brand { display: none; }
  .sidebar {
    position: fixed;
    left: 0;
    top: 62px;
    z-index: 50;
    width: min(280px, 86vw);
    height: calc(100dvh - 62px);
    min-height: 0;
    padding: 16px;
    transform: translateX(-105%);
    transition: transform 0.22s ease;
    box-shadow: none;
  }
  body.menu-open .sidebar {
    transform: none;
    box-shadow: 8px 0 28px rgba(0, 0, 0, 0.28);
  }
  .main { padding: 16px 12px 32px; }
  .page-head { flex-direction: column; align-items: stretch; }
  .page-head h1 { font-size: 1.5rem; }
  .head-side { align-items: stretch; width: 100%; }
  .row-actions { flex-wrap: wrap; }
  .row-actions .btn { flex: 1; text-align: center; }
  .stats, .stats.ops, .stats.compact { grid-template-columns: 1fr 1fr; }
  .filters-full, .filters-full.cols-5 { grid-template-columns: 1fr; }
  .mass-bar { flex-direction: column; align-items: stretch; }
  .mass-bar select { min-width: 0; width: 100%; }
  .table-cards thead { display: none; }
  .table-cards, .table-cards tbody, .table-cards tr, .table-cards td { display: block; width: 100%; }
  .table-cards tr {
    border: 1px solid var(--line);
    border-radius: 12px;
    padding: 10px 12px;
    margin-bottom: 10px;
    background: #fff;
  }
  .table-cards td {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    border: 0;
    padding: 6px 0;
  }
  .table-cards td::before {
    content: attr(data-label);
    color: var(--muted);
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    flex: 0 0 38%;
  }
  .table-cards td:has(.team-actions) {
    flex-direction: column;
    align-items: stretch;
    white-space: normal;
    width: auto;
  }
  .table-cards .team-actions {
    width: 100%;
  }
  .table-cards .team-actions input { flex: 1; width: auto; min-width: 0; }
}
