:root {
  /* Светлая, спокойная палитра */
  --bg: #f3f4f7;
  --panel: #ffffff;
  --panel-2: #f6f7f9;
  --line: #e7eaf0;
  --line-soft: #eef1f5;
  --text: #2c3440;
  --muted: #8a93a2;

  --ours-bg: #eaf5ef;
  --ours-bg-2: #e0f0e7;
  --ours-border: #a9d8bf;
  --ours-strong: #3d9b6c;
  --ours-text: #2f7d57;

  --not-bg: #fbfcfd;
  --not-border: #e7eaf0;

  --accent: #4a9d78;
  --accent-ink: #ffffff;
  --plan: #e0a94a;
  --danger: #d1685c;

  --radius: 14px;
  --radius-sm: 10px;
  --shadow: 0 6px 22px rgba(35, 50, 75, 0.07);
  --shadow-soft: 0 2px 8px rgba(35, 50, 75, 0.05);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14171c;
    --panel: #1b1f26;
    --panel-2: #21262f;
    --line: #2c333e;
    --line-soft: #262c35;
    --text: #f4f7fb;
    --muted: #99a3b2;

    --ours-bg: #1b3528;
    --ours-bg-2: #204030;
    --ours-border: #356b4f;
    --ours-strong: #57b487;
    --ours-text: #86d6ab;

    --not-bg: #242a34;
    --not-border: #333b47;

    --accent: #4aa47c;
    --plan: #d6a24c;
    --danger: #d1685c;
    --shadow: 0 8px 26px rgba(0, 0, 0, 0.35);
    --shadow-soft: 0 2px 10px rgba(0, 0, 0, 0.25);
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  padding-bottom: env(safe-area-inset-bottom);
}

/* ---------- Top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 30;
  display: flex; align-items: center; justify-content: space-between;
  gap: 16px; flex-wrap: wrap;
  padding: 12px 20px;
  background: color-mix(in srgb, var(--panel) 88%, transparent);
  backdrop-filter: saturate(1.1) blur(10px);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand-logo {
  width: 40px; height: 40px; border-radius: 11px;
  display: grid; place-items: center;
  background: linear-gradient(135deg, #5fb890, #3d9b6c);
  color: #fff; font-weight: 800; font-size: 20px;
  box-shadow: var(--shadow-soft);
}
.brand-title { font-weight: 700; font-size: 16px; }
.brand-sub { color: var(--muted); font-size: 12.5px; }

.toolbar { display: flex; align-items: center; gap: 18px; flex-wrap: wrap; }
.hotel-picker { display: flex; align-items: center; gap: 6px; }
select#hotel-select {
  background: var(--panel-2); color: var(--text);
  border: 1px solid var(--line); border-radius: var(--radius-sm);
  padding: 8px 12px; font: inherit; font-weight: 600; max-width: 260px; cursor: pointer;
}
.date-box { display: flex; align-items: center; gap: 6px; }
.date-label { color: var(--muted); font-size: 12.5px; margin-right: 2px; }
input[type="date"] {
  background: var(--panel-2); color: var(--text);
  border: 1px solid var(--line); border-radius: var(--radius-sm);
  padding: 7px 10px; font: inherit;
}
.icon-btn, .ghost-btn {
  background: var(--panel-2); color: var(--text);
  border: 1px solid var(--line); border-radius: var(--radius-sm);
  padding: 8px 11px; cursor: pointer; font: inherit; line-height: 1;
  transition: border-color .12s ease, background .12s ease;
}
.icon-btn { min-width: 36px; font-size: 16px; }
.icon-btn:hover, .ghost-btn:hover { border-color: var(--accent); }
.ghost-btn.accent { color: var(--accent); font-weight: 600; border-color: color-mix(in srgb, var(--accent) 45%, var(--line)); }

/* ---------- Tabs ---------- */
.tabs { display: flex; gap: 4px; background: var(--panel-2); border: 1px solid var(--line); border-radius: 12px; padding: 4px; }
.tab {
  border: none; background: transparent; color: var(--muted);
  padding: 8px 18px; border-radius: 9px; cursor: pointer; font: inherit; font-weight: 700; font-size: 14px;
}
.tab.active { background: var(--panel); color: var(--text); box-shadow: var(--shadow-soft); }
.tab:hover:not(.active) { color: var(--text); }

/* ---------- Sub-bar (панель внутри вкладки) ---------- */
.subbar {
  display: flex; align-items: center; gap: 14px; flex-wrap: wrap;
  padding: 14px 20px 4px;
}
.flights-summary { color: var(--muted); font-size: 13.5px; margin-left: auto; }
.flights-summary b { color: var(--text); }

/* ---------- Flights ---------- */
.flights-list { padding: 12px 20px 48px; display: flex; flex-direction: column; gap: 12px; }
.flight-card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px 12px; box-shadow: var(--shadow-soft); }
.flight-head { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; margin-bottom: 10px; }
.flight-name { font-weight: 800; font-size: 17px; }
.flight-name .cap { color: var(--muted); font-weight: 600; font-size: 14px; }
.flight-dates { display: flex; flex-direction: column; gap: 2px; font-size: 12.5px; color: var(--muted); }
.flight-dates b { color: var(--text); font-weight: 600; }
.flight-totals { margin-left: auto; font-size: 13px; color: var(--muted); }
.flight-totals b { color: var(--ours-text); }
.flight-actions { display: flex; gap: 6px; }

.group-rows { display: flex; flex-direction: column; gap: 6px; }
.group-row {
  display: grid; grid-template-columns: 30px minmax(150px, 1.6fr) 96px 1.4fr;
  align-items: center; gap: 10px; text-align: left;
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 10px;
  padding: 9px 12px; cursor: pointer; font: inherit; color: var(--text);
  transition: border-color .12s ease;
}
.group-row:hover { border-color: var(--accent); }
.group-row.not-housed { opacity: .72; }
.g-seq { display: grid; place-items: center; width: 24px; height: 24px; background: var(--panel); border: 1px solid var(--line); border-radius: 7px; font-weight: 700; font-size: 12.5px; }
.g-name { font-weight: 700; display: flex; flex-direction: column; }
.g-leader { font-weight: 400; color: var(--muted); font-size: 12px; }
.g-mz { display: flex; gap: 6px; }
.g-mz i { font-style: normal; font-size: 12px; font-weight: 700; padding: 2px 7px; border-radius: 6px; }
.g-mz .m { background: color-mix(in srgb, #4a7fd0 18%, transparent); color: #4a7fd0; }
.g-mz .z { background: color-mix(in srgb, #c064a8 18%, transparent); color: #c064a8; }
.g-stay { font-size: 12.5px; color: var(--muted); }
.badge-not { background: var(--panel); border: 1px solid var(--line); color: var(--muted); padding: 2px 9px; border-radius: 999px; font-size: 11.5px; font-weight: 600; }
.ghost-btn.small { padding: 6px 10px; font-size: 12.5px; margin-top: 8px; }
.add-grp { color: var(--muted); }

.imp-preview { margin: 10px 0; }
.ok-box { background: var(--ours-bg); border: 1px solid var(--ours-border); color: var(--ours-text); padding: 10px 12px; border-radius: 9px; font-size: 13px; }
.err-box { background: color-mix(in srgb, var(--danger) 12%, transparent); border: 1px solid var(--danger); color: var(--danger); padding: 10px 12px; border-radius: 9px; font-size: 13px; }
select#g-hotel { background: var(--panel); color: var(--text); border: 1px solid var(--line); border-radius: 9px; padding: 10px 11px; font: inherit; }
input[type="file"] { font: inherit; color: var(--muted); }

/* ---------- Summary ---------- */
.summary {
  display: flex; align-items: center; justify-content: space-between;
  gap: 16px; flex-wrap: wrap; padding: 16px 20px 6px;
}
.chips { display: flex; gap: 12px; flex-wrap: wrap; }
.chip {
  display: flex; flex-direction: column;
  background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 10px 16px; min-width: 118px;
  box-shadow: var(--shadow-soft);
}
.chip-num { font-size: 22px; font-weight: 800; letter-spacing: -0.02em; }
.chip-label { color: var(--muted); font-size: 12px; }
.chip-ours { background: var(--ours-bg); border-color: var(--ours-border); }
.chip-ours .chip-num { color: var(--ours-text); }
.chip-muted .chip-num { font-size: 16px; font-weight: 700; }

.summary-right { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; }
.legend { display: flex; gap: 14px; flex-wrap: wrap; color: var(--muted); font-size: 12.5px; }
.lg { display: inline-flex; align-items: center; gap: 6px; }
.sw { width: 14px; height: 14px; border-radius: 5px; display: inline-block; border: 1px solid var(--line); }
.sw-ours { background: var(--ours-bg-2); border-color: var(--ours-border); }
.sw-not { background: var(--not-bg); border-color: var(--not-border); }
.sw-plan { background: transparent; border: 2px dashed var(--plan); }

/* ---------- Board: этажи блоками ---------- */
.board { padding: 12px 20px 48px; display: flex; flex-direction: column; gap: 14px; }

.floor-block {
  background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 14px 16px 16px;
  box-shadow: var(--shadow-soft);
}
.floor-head {
  display: flex; align-items: center; gap: 12px;
  cursor: pointer; margin-bottom: 12px;
}
.floor-badge {
  display: inline-flex; align-items: baseline; gap: 7px;
  font-weight: 800; font-size: 15px;
}
.floor-badge .n {
  display: inline-grid; place-items: center; min-width: 26px; height: 26px; padding: 0 7px;
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 8px; font-size: 13px;
}
.floor-meta { color: var(--muted); font-size: 12.5px; }
.floor-progress {
  margin-left: auto; width: 130px; height: 6px; border-radius: 4px;
  background: var(--line-soft); overflow: hidden;
}
.floor-progress > i { display: block; height: 100%; background: var(--ours-strong); border-radius: 4px; }
.floor-edit { color: var(--muted); font-size: 12.5px; white-space: nowrap; }
.floor-head:hover .floor-edit { color: var(--accent); }

.rooms { display: flex; flex-wrap: wrap; gap: 8px; }
.room {
  position: relative; width: 92px;
  border-radius: var(--radius-sm); padding: 9px 6px; cursor: pointer;
  border: 1px solid var(--not-border); background: var(--not-bg);
  text-align: center; transition: transform .06s ease, box-shadow .12s ease, border-color .12s ease;
}
.room:hover { transform: translateY(-1px); box-shadow: var(--shadow-soft); border-color: var(--muted); }
.room.ours { background: var(--ours-bg); border-color: var(--ours-border); }
.room-no { font-weight: 800; font-size: 15px; color: var(--text); }
.room-beds { color: var(--muted); font-size: 11.5px; margin-top: 2px; }
.room.ours .room-beds { color: var(--ours-text); }
.room.plan::after {
  content: ""; position: absolute; top: 6px; right: 6px;
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--plan); box-shadow: 0 0 0 2px var(--panel);
}

/* ---------- Empty state ---------- */
.empty-state {
  background: var(--panel); border: 1px dashed var(--line);
  border-radius: var(--radius); padding: 30px; text-align: center; box-shadow: var(--shadow-soft);
}
.empty-state h3 { margin: 0 0 6px; }
.empty-state p { color: var(--muted); margin: 0 0 16px; }

/* ---------- Drawer ---------- */
.overlay { position: fixed; inset: 0; z-index: 50; background: rgba(20, 28, 40, 0.4); display: flex; justify-content: flex-end; }
.drawer {
  width: min(460px, 100%); height: 100%;
  background: var(--panel); border-left: 1px solid var(--line);
  box-shadow: var(--shadow); overflow-y: auto; padding: 20px;
  animation: slideIn .18s ease;
}
@keyframes slideIn { from { transform: translateX(24px); opacity: .5; } to { transform: none; opacity: 1; } }
.drawer h2 { margin: 0 0 2px; font-size: 20px; }
.drawer .sub { color: var(--muted); font-size: 13px; margin-bottom: 14px; }
.d-close { float: right; }
.status-line {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 6px 13px; border-radius: 999px; font-weight: 700; font-size: 13px;
  border: 1px solid var(--line); margin-bottom: 4px;
}
.status-ours { background: var(--ours-bg); border-color: var(--ours-border); color: var(--ours-text); }
.status-not { background: var(--panel-2); }

.card { background: var(--panel-2); border: 1px solid var(--line); border-radius: var(--radius); padding: 15px; margin-top: 14px; }
.card h3 { margin: 0 0 10px; font-size: 14px; }
.field { display: flex; flex-direction: column; gap: 5px; margin-bottom: 11px; }
.field label { font-size: 12.5px; color: var(--muted); }
.field input, .field textarea {
  background: var(--panel); color: var(--text);
  border: 1px solid var(--line); border-radius: 9px; padding: 10px 11px; font: inherit;
}
.field textarea { min-height: 160px; resize: vertical; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 14px; line-height: 1.5; }
.hint { color: var(--muted); font-size: 12px; margin: -4px 0 10px; }
.row { display: flex; gap: 8px; }
.row > * { flex: 1; }
.btn { border: none; border-radius: 10px; padding: 11px 13px; cursor: pointer; font: inherit; font-weight: 700; }
.btn-ours { background: var(--accent); color: var(--accent-ink); }
.btn-not { background: var(--panel); color: var(--text); border: 1px solid var(--line); }
.btn-primary { background: var(--accent); color: var(--accent-ink); width: 100%; }
.btn-danger { background: var(--panel); color: var(--danger); border: 1px solid color-mix(in srgb, var(--danger) 40%, var(--line)); width: 100%; }
.btn:disabled { opacity: .5; cursor: default; }

.hist { list-style: none; margin: 0; padding: 0; }
.hist li { display: flex; gap: 10px; padding: 8px 0; border-top: 1px solid var(--line); font-size: 13px; }
.hist li:first-child { border-top: none; }
.hist .when { color: var(--muted); min-width: 92px; }
.tag { font-weight: 700; }
.tag.ours { color: var(--ours-text); }
.tag.not { color: var(--danger); }
.empty { color: var(--muted); font-size: 13px; }

/* ---------- Toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%);
  background: var(--panel); border: 1px solid var(--ours-border);
  color: var(--text); padding: 12px 18px; border-radius: 12px;
  box-shadow: var(--shadow); z-index: 80; font-size: 14px; max-width: 92vw;
}
.toast.err { border-color: var(--danger); }

/* ---------- Mobile ---------- */
@media (max-width: 780px) {
  .topbar { padding: 10px 14px; }
  .toolbar { gap: 10px; width: 100%; }
  .hotel-picker { flex: 1; }
  select#hotel-select { flex: 1; max-width: none; }
  .summary { padding: 12px 14px 4px; }
  .board { padding: 10px 14px 40px; }
  .summary-right { width: 100%; justify-content: space-between; }
  .floor-progress { display: none; }
  .rooms { gap: 7px; }
  .room { width: calc((100% - 21px) / 4); min-width: 72px; }
  .drawer { width: 100%; border-left: none; }
  .subbar { padding: 12px 14px 4px; }
  .flights-list { padding: 10px 14px 40px; }
  .flights-summary { width: 100%; margin-left: 0; }
  .flight-totals { margin-left: 0; width: 100%; }
  .group-row { grid-template-columns: 26px 1fr auto; grid-template-areas: "seq name mz" "seq stay stay"; row-gap: 4px; }
  .g-seq { grid-area: seq; }
  .g-name { grid-area: name; }
  .g-mz { grid-area: mz; }
  .g-stay { grid-area: stay; }
  .tabs { flex: 1; }
  .tab { flex: 1; }
}
@media (max-width: 440px) {
  .room { width: calc((100% - 14px) / 3); }
}
