:root {
  --bg: #faf7f2;
  --panel: #ffffff;
  --ink: #2d2a26;
  --muted: #7b746b;
  --line: #e7e0d6;
  --accent: #6f8a4e;
  --accent-soft: #eef3e4;
  --gold: #b8954a;
  --danger: #b4443c;
  --floor: #f3eee6;
  --shadow: 0 1px 2px rgba(45, 42, 38, .06), 0 4px 14px rgba(45, 42, 38, .06);
  --serif: 'Cormorant Garamond', Georgia, serif;
  --sans: 'Inter', system-ui, -apple-system, 'Segoe UI', sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; margin: 0; }
body { background: var(--bg); color: var(--ink); font: 14px/1.4 var(--sans); }
button, input, select, textarea { font: inherit; color: inherit; }

.app {
  display: grid;
  grid-template-columns: 300px 1fr;
  grid-template-rows: auto 1fr;
  height: 100vh;
}

/* ---------- Top bar ---------- */
.topbar {
  grid-column: 1 / -1;
  display: flex; align-items: center; gap: 16px; flex-wrap: wrap;
  padding: 10px 16px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}
.topbar h1 { margin: 0; font: 600 26px/1 var(--serif); letter-spacing: .5px; }
.stats { display: flex; gap: 6px; flex-wrap: wrap; flex: 1; }
.stat { padding: 3px 10px; border-radius: 999px; background: var(--bg); border: 1px solid var(--line); font-size: 12px; color: var(--muted); }
.stat b { color: var(--ink); font-weight: 600; }
.stat.warn b { color: var(--gold); }
.actions { display: flex; align-items: center; gap: 6px; }
.sep { width: 1px; height: 22px; background: var(--line); margin: 0 4px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 4px;
  padding: 6px 12px; border-radius: 8px;
  border: 1px solid var(--line); background: var(--panel);
  cursor: pointer; font-weight: 500; white-space: nowrap;
}
.btn:hover { border-color: #cfc5b6; background: #fdfbf8; }
.btn:disabled { opacity: .4; cursor: default; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { filter: brightness(1.06); }
.btn.danger { color: var(--danger); }
.btn.icon { width: 32px; padding: 6px 0; font-size: 16px; }

.menu { position: relative; }
.menu summary { list-style: none; }
.menu summary::-webkit-details-marker { display: none; }
.menu-list {
  position: absolute; right: 0; top: calc(100% + 6px); z-index: 50;
  min-width: 230px; padding: 6px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 10px; box-shadow: var(--shadow);
}
.menu-list button { display: block; width: 100%; text-align: left; padding: 8px 10px; border: 0; background: none; border-radius: 6px; cursor: pointer; }
.menu-list button:hover { background: var(--bg); }
.menu-list button.danger { color: var(--danger); }
.menu-list hr { border: 0; border-top: 1px solid var(--line); margin: 6px 0; }

/* ---------- Sidebar ---------- */
.sidebar {
  display: flex; flex-direction: column; min-height: 0;
  background: var(--panel); border-right: 1px solid var(--line);
}
.sidebar.drop-hover { background: var(--accent-soft); }
.side-tools { padding: 12px; border-bottom: 1px solid var(--line); display: grid; gap: 8px; }
.side-tools input[type=search] { width: 100%; padding: 7px 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg); }
.toggle { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); cursor: pointer; }
.groups { flex: 1; overflow-y: auto; padding: 8px 8px 16px; }
.side-hint { margin: 0; padding: 10px 14px; font-size: 11.5px; color: var(--muted); border-top: 1px solid var(--line); }

.group { margin-bottom: 8px; border-radius: 10px; border: 1px solid transparent; }
.group.drop-hover { border-color: var(--accent); background: var(--accent-soft); }
.group-head {
  display: flex; align-items: center; gap: 8px;
  padding: 6px 8px; border-radius: 8px; cursor: grab; user-select: none;
}
.group-head:hover { background: var(--bg); }
.group-head .dot { width: 12px; height: 12px; border-radius: 50%; background: var(--c); flex: none; }
.group-head .gname { font-weight: 600; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.group-head .gcount { font-size: 11px; color: var(--muted); }
.group-head .mini { border: 0; background: none; cursor: pointer; color: var(--muted); padding: 2px 4px; border-radius: 4px; }
.group-head .mini:hover { background: var(--line); color: var(--ink); }
.group.collapsed .guest-list, .group.collapsed .add-guest { display: none; }

.guest-list { list-style: none; margin: 0; padding: 0 4px 0 10px; }
.chip {
  display: flex; align-items: center; gap: 6px;
  margin: 3px 0; padding: 5px 8px 5px 10px;
  background: var(--panel); border: 1px solid var(--line); border-left: 4px solid var(--c);
  border-radius: 6px; cursor: grab; user-select: none;
}
.chip:hover { border-color: #cfc5b6; border-left-color: var(--c); }
.chip.selected { outline: 2px solid var(--accent); outline-offset: 1px; }
.chip.seated { background: var(--bg); color: var(--muted); }
.chip.declined .chip-name { text-decoration: line-through; color: var(--muted); }
.chip-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.badge { font-size: 10.5px; padding: 1px 6px; border-radius: 999px; background: var(--line); color: var(--ink); white-space: nowrap; }
.badge.diet { background: #fbecd9; color: #8a5a1c; }
.badge.tbl { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.all-seated { margin: 2px 0 4px 14px; font-size: 11.5px; color: var(--accent); }

.add-guest { padding: 2px 4px 2px 10px; }
.add-guest input {
  width: 100%; padding: 5px 8px; border: 1px dashed var(--line); border-radius: 6px; background: transparent; font-size: 13px;
}
.add-guest input:focus { border-style: solid; border-color: var(--accent); outline: none; background: var(--panel); }

/* ---------- Floor ---------- */
.floor-wrap { position: relative; min-width: 0; min-height: 0; }
.floor-scroll {
  position: absolute; inset: 0; overflow: auto;
  background-color: var(--floor);
  background-image: radial-gradient(#ddd4c6 1px, transparent 1px);
  background-size: 20px 20px;
  cursor: grab;
}
.floor-scroll.panning { cursor: grabbing; }
.floor-sizer { position: relative; }
.floor { position: absolute; left: 0; top: 0; transform-origin: 0 0; user-select: none; }

.zoom {
  position: absolute; z-index: 10; left: 12px; bottom: 12px;
  display: flex; align-items: center; gap: 4px; padding: 4px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 10px; box-shadow: var(--shadow);
}
.zoom span { min-width: 44px; text-align: center; font-size: 12px; color: var(--muted); }
.zoom .btn { padding: 4px 8px; border: 0; }
.zoom .btn.icon { width: 28px; }

.table { position: absolute; }
.table.dragging { z-index: 5; opacity: .9; }
.table-top {
  position: absolute;
  display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center;
  background: var(--panel); border: 2px solid var(--line); box-shadow: var(--shadow);
  cursor: move; touch-action: none; padding: 6px;
}
.table-top.round { border-radius: 50%; }
.table-top.rect { border-radius: 10px; }
.table-top.full { border-color: var(--gold); }
.table.selected .table-top { border-color: var(--accent); box-shadow: 0 0 0 4px var(--accent-soft), var(--shadow); }
.table-top.drop-hover { background: var(--accent-soft); border-color: var(--accent); }
.t-name { font: 600 18px/1.1 var(--serif); max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.t-count { font-size: 12px; color: var(--muted); margin-top: 2px; }
.t-count.full { color: var(--gold); font-weight: 600; }
.t-meta { font-size: 10.5px; color: var(--muted); margin-top: 2px; }

.seat {
  position: absolute; width: 34px; height: 34px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 11.5px; font-weight: 600; transition: box-shadow .12s, transform .12s;
}
.seat.empty { background: rgba(255,255,255,.7); border: 1.5px dashed #cbbfae; color: #b3a897; font-weight: 500; font-size: 10.5px; }
.seat.filled { background: var(--c); color: #fff; cursor: grab; box-shadow: 0 1px 3px rgba(0,0,0,.18); text-shadow: 0 1px 1px rgba(0,0,0,.2); }
.seat.filled.declined { opacity: .45; }
.seat.diet::after {
  content: ''; position: absolute; right: -1px; top: -1px; width: 9px; height: 9px; border-radius: 50%;
  background: #e8973a; border: 1.5px solid #fff;
}
.seat.selected { box-shadow: 0 0 0 3px var(--panel), 0 0 0 5px var(--accent); }
.seat.match, .seat.pulse { box-shadow: 0 0 0 3px var(--panel), 0 0 0 6px var(--gold); transform: scale(1.12); z-index: 2; }
body.dragging-guest .seat.empty, body.dragging-group .table-top { border-color: var(--accent); }
.seat.drop-hover { transform: scale(1.2); box-shadow: 0 0 0 3px var(--accent); background: var(--accent-soft); }
.seat.filled.drop-hover { background: var(--c); }

/* Room features (stage, dance floor, entrance…) sit behind the tables. */
.fixture {
  position: absolute; display: flex; align-items: center; justify-content: center;
  border-radius: 6px; cursor: move; touch-action: none;
  font: 600 20px/1.1 var(--serif); letter-spacing: .5px; color: #6d655a; text-align: center;
}
.fixture.stage { background: #dcdcdc; border: 2px solid #b9b5ae; }
.fixture.dance { background: rgba(255,255,255,.35); border: 2px dashed #a99e8d; }
.fixture.entrance { background: #fff4d6; border: 2px solid #e2c77c; font-size: 16px; }
.fixture.other { background: #ece6f3; border: 2px solid #c9bcdb; font-size: 16px; }
.fixture.selected { outline: 3px solid var(--accent); outline-offset: 2px; }
.fixture.dragging { opacity: .85; }
.fixture .resize {
  position: absolute; right: -2px; bottom: -2px; width: 16px; height: 16px; cursor: nwse-resize;
  background: linear-gradient(135deg, transparent 50%, #a99e8d 50%); border-bottom-right-radius: 6px;
}
.table.vip .table-top { background: #fff6dc; border-color: #e2c77c; }

/* ---------- Drawer ---------- */
.drawer {
  position: fixed; z-index: 40; right: 0; top: 0; bottom: 0; width: 380px; max-width: 100vw;
  display: flex; flex-direction: column;
  background: var(--panel); border-left: 1px solid var(--line); box-shadow: -8px 0 30px rgba(45,42,38,.12);
  transform: translateX(105%); transition: transform .2s ease;
}
.drawer.open { transform: none; }
.drawer-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 16px; border-bottom: 1px solid var(--line); }
.drawer-head h2 { margin: 0; font: 600 24px/1 var(--serif); }
.drawer-body { flex: 1; overflow-y: auto; padding: 16px; display: grid; gap: 14px; align-content: start; }

.field { display: grid; gap: 5px; }
.field > span { font-size: 11.5px; font-weight: 600; text-transform: uppercase; letter-spacing: .5px; color: var(--muted); }
.field input[type=text], .field input[type=number], .field select, .field textarea {
  width: 100%; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--panel);
}
.field textarea { resize: vertical; min-height: 70px; }
.field input:focus, .field select:focus, .field textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

.seg { display: flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.seg button { flex: 1; padding: 7px 6px; border: 0; background: var(--panel); cursor: pointer; border-right: 1px solid var(--line); }
.seg button:last-child { border-right: 0; }
.seg button.on { background: var(--accent); color: #fff; }

.tags { display: flex; flex-wrap: wrap; gap: 6px; }
.tag { padding: 4px 10px; border-radius: 999px; border: 1px solid var(--line); background: var(--panel); cursor: pointer; font-size: 12.5px; }
.tag.on { background: #fbecd9; border-color: #e8c08a; color: #8a5a1c; }

.swatches { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.swatch { width: 26px; height: 26px; border-radius: 50%; border: 2px solid var(--panel); box-shadow: 0 0 0 1px var(--line); cursor: pointer; }
.swatch.on { box-shadow: 0 0 0 2px var(--ink); }
.swatches input[type=color] { width: 32px; height: 28px; border: 0; padding: 0; background: none; cursor: pointer; }

.list { list-style: none; margin: 0; padding: 0; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.list li { display: flex; align-items: center; gap: 8px; padding: 6px 10px; border-bottom: 1px solid var(--line); font-size: 13px; }
.list li:last-child { border-bottom: 0; }
.list .num { width: 22px; color: var(--muted); font-size: 12px; }
.list .who { flex: 1; cursor: pointer; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.list .who:hover { text-decoration: underline; }
.list .empty { flex: 1; color: #b3a897; }
.list .x { border: 0; background: none; cursor: pointer; color: var(--muted); padding: 0 4px; font-size: 15px; }
.list .x:hover { color: var(--danger); }
.list .dot { width: 9px; height: 9px; border-radius: 50%; background: var(--c); flex: none; }

.summary { padding: 10px 12px; border-radius: 8px; background: #fdf6ec; color: #7a5420; font-size: 12.5px; }
.muted { color: var(--muted); font-size: 12.5px; margin: 0; }
.drawer-actions { display: flex; gap: 8px; flex-wrap: wrap; padding-top: 6px; border-top: 1px solid var(--line); }

.steps { margin: 0; padding-left: 18px; font-size: 12.5px; color: var(--muted); display: grid; gap: 4px; }
.preview { display: grid; gap: 8px; font-size: 13px; }
.preview p { margin: 0; }
.preview .list { max-height: 220px; overflow-y: auto; }
.drawer-body a { color: var(--accent); }

/* ---------- Sync status + login ---------- */
.sync { font-size: 11.5px; color: var(--muted); padding: 2px 8px; border-radius: 999px; background: var(--bg); }
.sync.ok::before { content: '✓ '; color: var(--accent); }
.sync.err { color: var(--danger); background: #fbecea; }

.login {
  position: fixed; inset: 0; z-index: 100; display: flex; align-items: center; justify-content: center; padding: 16px;
  background: radial-gradient(circle at 30% 20%, #fff 0, var(--bg) 60%);
}
.login-card {
  width: 100%; max-width: 360px; display: grid; gap: 12px; padding: 28px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 16px; box-shadow: var(--shadow); text-align: center;
}
.login-card h1 { margin: 0; font: 600 34px/1 var(--serif); }
.login-card p { margin: 0; color: var(--muted); }
.login-card input { padding: 10px 12px; border: 1px solid var(--line); border-radius: 8px; font-size: 15px; }
.login-card input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.login-card .btn { padding: 10px; font-size: 15px; }
.login-error { color: var(--danger) !important; min-height: 1.2em; font-size: 13px; }

/* ---------- Toast ---------- */
.toast {
  position: fixed; z-index: 60; left: 50%; bottom: 24px; transform: translate(-50%, 20px);
  padding: 10px 16px; border-radius: 10px; background: var(--ink); color: #fff; font-size: 13px;
  opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; max-width: 90vw;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- Narrow screens ---------- */
@media (max-width: 760px) {
  .app { grid-template-columns: 1fr; grid-template-rows: auto 40vh 1fr; }
  .stats { order: 3; flex-basis: 100%; }
}

/* ---------- Print ---------- */
.print-view { display: none; }
@media print {
  .app, .toast { display: none !important; }
  .print-view { display: block; font: 11pt/1.35 var(--sans); color: #000; }
  .print-view h1 { font: 600 22pt var(--serif); margin: 0 0 10px; }
  .print-view .page-break { page-break-before: always; }
  .print-tables { columns: 3; column-gap: 24px; }
  .print-table { break-inside: avoid; margin-bottom: 14px; }
  .print-table h2 { font: 600 14pt var(--serif); margin: 0 0 4px; border-bottom: 1px solid #999; }
  .print-table h2 small { font: 9pt var(--sans); color: #555; }
  .print-table ol { margin: 0; padding-left: 20px; }
  .print-table em { color: #555; font-size: 9pt; }
  .print-table .empty { color: #aaa; }
  .print-table p { font-size: 9pt; color: #555; margin: 4px 0 0; }
  .print-view table { width: 100%; border-collapse: collapse; font-size: 10pt; }
  .print-view th, .print-view td { text-align: left; padding: 3px 6px; border-bottom: 1px solid #ccc; }
}

.picker { display: flex; gap: 8px; }
.picker select { flex: 1; min-width: 0; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--panel); }

/* Table number (big) + name (small) on the floor plan */
.t-label {
  max-width: 100%; margin-top: 1px; font-size: 11.5px; font-weight: 600; line-height: 1.2; color: var(--accent);
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; word-break: break-word;
}

/* While a group is being dragged, show only the group headers */
body.dragging-group .groups .guest-list,
body.dragging-group .groups .add-guest,
body.dragging-group .groups .all-seated { display: none; }
body.dragging-group .groups .group { margin-bottom: 2px; }
.group.drop-before { box-shadow: 0 -3px 0 var(--accent); }
.group.drop-after { box-shadow: 0 3px 0 var(--accent); }
