:root {
  --bg: #f7f5ef;
  --bg-2: #f1efe8;
  --surface: #ffffff;
  --surface-2: #fbfaf6;
  --border: #e5e2d8;
  --border-strong: #d3cfc3;
  --text: #1b1a17;
  --text-2: #3a3833;
  --muted: #8b8881;
  --accent: #23211d;
  --accent-2: #3c3832;
  --on-accent: #f8f5ec;
  --highlight: #b38138;
  --highlight-soft: #f1e3c6;
  --success: #4a7256;
  --danger: #ae4a43;
  --warning: #c78c1e;
  --shadow: 0 1px 2px rgba(30,28,24,.04), 0 8px 24px rgba(30,28,24,.06);
  --shadow-lg: 0 4px 12px rgba(30,28,24,.08), 0 20px 48px rgba(30,28,24,.12);
  --radius: 10px;
}

html[data-theme="dark"] {
  --bg: #15171b;
  --bg-2: #1c1f24;
  --surface: #212429;
  --surface-2: #262a30;
  --border: #353a41;
  --border-strong: #4a5059;
  --text: #ebe9e2;
  --text-2: #c7c4ba;
  --muted: #8b8e95;
  --accent: #ebe9e2;
  --accent-2: #d0cdc3;
  --on-accent: #15171b;
  --highlight: #e0a849;
  --highlight-soft: #3a2f1a;
  --success: #6ea97d;
  --danger: #d86a62;
  --warning: #e0a849;
  --shadow: 0 1px 2px rgba(0,0,0,.3), 0 8px 24px rgba(0,0,0,.35);
  --shadow-lg: 0 4px 12px rgba(0,0,0,.4), 0 20px 48px rgba(0,0,0,.5);
}
html[data-theme="dark"] .canvas-wrap {
  background:
    radial-gradient(circle, var(--border) 1px, transparent 1px) 0 0 / 24px 24px,
    var(--bg);
}

/* Theme transition: only active while toggling to avoid impacting other interactions */
html.theme-transition,
html.theme-transition *,
html.theme-transition *::before,
html.theme-transition *::after {
  transition: background-color .3s ease, color .3s ease, border-color .3s ease, fill .3s ease, stroke .3s ease, box-shadow .3s ease !important;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; overscroll-behavior: none; }
body {
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  background: var(--bg);
  color: var(--text);
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

/* Topbar */
.topbar {
  display: flex; justify-content: space-between; align-items: center;
  padding: 10px 18px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  position: sticky; top: 0; z-index: 40;
  gap: 10px;
}
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand h1 { font-size: 15px; margin: 0; letter-spacing: -.2px; font-weight: 600; white-space: nowrap; cursor: pointer; max-width: 50vw; overflow: hidden; text-overflow: ellipsis; }
.brand h1:hover { color: var(--highlight); }
.dialog-msg { margin: 0 0 14px; font-size: 14px; line-height: 1.55; color: var(--text-2); white-space: pre-line; }
.logo {
  width: 30px; height: 30px; border-radius: 8px;
  display: block; object-fit: contain;
  flex-shrink: 0;
}
.logo-dark { display: none; }
html[data-theme="dark"] .logo-light { display: none; }
html[data-theme="dark"] .logo-dark { display: block; }
.top-actions { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }

/* Icon button */
.icon-btn {
  background: transparent; border: 1px solid var(--border);
  width: 34px; height: 34px; border-radius: 8px;
  display: inline-flex; align-items: center; justify-content: center;
  cursor: pointer; color: var(--text);
}
.icon-btn:hover { background: var(--bg-2); }
#btn-theme .icon-moon { display: none; }
html[data-theme="dark"] #btn-theme .icon-sun { display: none; }
html[data-theme="dark"] #btn-theme .icon-moon { display: inline; }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 7px 12px; border-radius: 8px;
  border: 1px solid transparent; cursor: pointer;
  font-size: 13px; font-weight: 500; color: var(--text);
  background: transparent; transition: background .12s, border-color .12s, color .12s;
  user-select: none;
  font-family: inherit;
}
.btn-sm { padding: 4px 9px; font-size: 12px; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.btn-primary:hover { background: var(--accent-2); border-color: var(--accent-2); }
.btn-ghost { background: var(--surface); border-color: var(--border); }
.btn-ghost:hover { background: var(--bg-2); border-color: var(--border-strong); }
.btn-danger { background: var(--danger); border-color: var(--danger); color: var(--surface); }
.btn-danger:hover { filter: brightness(.95); }
.btn-danger-ghost { background: transparent; border-color: transparent; color: var(--danger); }
.btn-danger-ghost:hover { background: rgba(174,74,67,.08); }
.ico { font-size: 15px; font-weight: 600; line-height: 1; }

/* Layout */
.layout {
  display: grid;
  grid-template-columns: 320px 1fr;
  height: calc(100dvh - 53px);
  position: relative;
}

/* Sidebar */
.sidebar {
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
  overflow: hidden;
  min-height: 0;
}
.sidebar-head {
  padding: 14px 14px 10px;
  border-bottom: 1px solid var(--border);
  display: flex; flex-direction: column; gap: 10px;
}
.counts { display: grid; grid-template-columns: repeat(4,1fr); gap: 6px; }
.counts > div {
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: 8px; padding: 7px;
  display: flex; flex-direction: column; align-items: center;
}
.counts strong { font-size: 17px; color: var(--accent); font-weight: 600; }
.counts span { font-size: 10px; color: var(--muted); text-transform: uppercase; letter-spacing: .4px; margin-top: 2px; }

.search-wrap input, .field input, .field textarea, .field select, .quick-add input {
  width: 100%; padding: 9px 11px;
  background: var(--surface);
  border: 1px solid var(--border); border-radius: 8px;
  color: var(--text); font-size: 13px;
  outline: none; transition: border-color .12s, box-shadow .12s;
  font-family: inherit;
}
.search-wrap input:focus, .field input:focus, .field textarea:focus,
.field select:focus, .quick-add input:focus {
  border-color: var(--accent); box-shadow: 0 0 0 3px rgba(35,33,29,.08);
}

.filters { display: flex; gap: 5px; flex-wrap: wrap; }
.chip {
  padding: 4px 11px; border-radius: 16px;
  background: transparent; border: 1px solid var(--border);
  color: var(--muted); cursor: pointer; font-size: 12px;
  font-weight: 500;
  font-family: inherit;
}
.chip:hover { color: var(--text); border-color: var(--border-strong); }
.chip-active { background: var(--accent); color: var(--on-accent); border-color: var(--accent); }

/* Guest list */
.guest-list {
  flex: 1; overflow-y: auto;
  padding: 8px;
  display: flex; flex-direction: column; gap: 5px;
}
.guest-card {
  background: var(--surface);
  border: 1px solid var(--border);
  padding: 9px 11px; border-radius: 8px;
  cursor: pointer;
  display: flex; justify-content: space-between; align-items: center;
  gap: 8px;
  transition: border-color .12s, background .12s, transform .12s;
  touch-action: pan-y;
  user-select: none;
}
.guest-card:hover { border-color: var(--border-strong); background: var(--surface-2); }
.guest-card.dragging { opacity: .35; }
.guest-card.is-plus-one {
  background: var(--highlight-soft);
  border-left: 3px solid var(--highlight);
  padding-left: 8px;
}
.guest-card.is-confirmed .guest-name {
  color: var(--success);
}

/* Confirm toggle (round checkmark) */
.confirm-toggle {
  flex: 0 0 auto;
  width: 22px; height: 22px;
  border-radius: 50%;
  border: 1.5px solid var(--border-strong);
  background: var(--surface);
  color: transparent;
  cursor: pointer;
  padding: 0;
  display: inline-flex; align-items: center; justify-content: center;
  transition: background .12s, border-color .12s, color .12s, transform .1s;
  font-family: inherit;
}
.confirm-toggle:hover { border-color: var(--success); }
.confirm-toggle.on {
  background: var(--success);
  border-color: var(--success);
  color: var(--surface);
}
.confirm-toggle:active { transform: scale(.9); }
.guest-main { flex: 1; min-width: 0; }
.guest-name {
  font-size: 13px; font-weight: 500;
  display: flex; align-items: center; gap: 6px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.guest-meta { font-size: 11px; color: var(--muted); margin-top: 1px; }
.guest-tags { display: flex; gap: 4px; align-items: center; flex-shrink: 0; }
.tag {
  font-size: 10px; padding: 2px 6px; border-radius: 10px;
  background: var(--bg-2); color: var(--muted);
  border: 1px solid var(--border);
  font-weight: 500;
}
.tag-phone { color: var(--success); border-color: rgba(74,114,86,.3); background: rgba(74,114,86,.06); }
.tag-table { color: var(--accent); border-color: var(--border-strong); background: var(--surface-2); }
.tag-plus { color: var(--highlight); border-color: rgba(179,129,56,.35); background: var(--highlight-soft); }

.guest-empty {
  padding: 28px 18px; text-align: center;
  color: var(--muted); font-size: 12px; line-height: 1.5;
}

/* Canvas */
.canvas-wrap {
  position: relative;
  overflow: auto;
  background:
    radial-gradient(circle, var(--border) 1px, transparent 1px) 0 0 / 24px 24px,
    var(--bg);
  -webkit-overflow-scrolling: touch;
  touch-action: pan-x pan-y;
  cursor: grab;
}
.canvas-wrap.is-panning { cursor: grabbing; }
.canvas-wrap.is-panning * { cursor: grabbing !important; }
.canvas-outer {
  position: relative;
  min-width: 100%; min-height: 100%;
  width: 100%; height: 100%;
}
.canvas {
  position: absolute;
  top: 0; left: 0;
  width: 2000px; height: 1400px;
  transform-origin: 0 0;
  will-change: transform;
}

/* Zoom controls */
.zoom-controls {
  position: fixed;
  bottom: 12px; left: calc(320px + 12px);
  display: flex;
  gap: 1px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  box-shadow: var(--shadow);
  z-index: 15;
}
.zoom-btn {
  background: var(--surface);
  border: none;
  padding: 7px 11px;
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  cursor: pointer;
  font-family: inherit;
  transition: background .12s;
  min-width: 34px;
}
.zoom-btn:hover { background: var(--bg-2); }
.zoom-btn:active { background: var(--border); }
.zoom-label { font-size: 12px; min-width: 52px; color: var(--muted); }
.zoom-label:hover { color: var(--text); }
.canvas-hint {
  position: fixed; bottom: 12px; right: 12px;
  background: var(--surface); border: 1px solid var(--border);
  padding: 7px 11px; border-radius: 8px;
  font-size: 11px; color: var(--muted);
  pointer-events: none;
  box-shadow: var(--shadow);
  max-width: 70%;
}

/* Tables on canvas */
.table-node {
  position: absolute;
  display: flex; flex-direction: column; align-items: center;
  cursor: pointer;
  user-select: none;
  touch-action: none;
}
.table-node.drag-moving { z-index: 10; cursor: grabbing; }
.table-circle {
  position: relative;
  border-radius: 50%;
  background: var(--surface);
  border: 1.5px solid var(--border-strong);
  box-shadow: var(--shadow);
  display: grid; place-items: center;
  transition: border-color .12s, transform .12s, box-shadow .12s;
}
.table-circle.square { border-radius: 14px; }
.table-circle.square::before { border-radius: 10px; }
.table-circle::before {
  content: "";
  position: absolute; inset: 10px;
  border-radius: 50%;
  border: 1px dashed var(--border);
}
.table-node.over .table-circle {
  border-color: var(--accent);
  box-shadow: 0 0 0 4px rgba(35,33,29,.08), var(--shadow-lg);
  transform: scale(1.03);
}
.table-node.over-full .table-circle {
  border-color: var(--warning);
  box-shadow: 0 0 0 4px rgba(199,140,30,.15), var(--shadow-lg);
}
.table-center {
  text-align: center; pointer-events: none;
}
.table-count {
  font-size: 32px; font-weight: 600;
  color: var(--accent);
  line-height: 1;
  letter-spacing: -1px;
}
.table-count.over { color: var(--highlight); }
.table-label {
  font-size: 10px; color: var(--muted);
  text-transform: uppercase; letter-spacing: .8px;
  margin-top: 4px;
  font-weight: 500;
}
.table-name {
  margin-top: 8px;
  font-size: 12px; font-weight: 500;
  background: var(--surface); padding: 3px 10px;
  border: 1px solid var(--border); border-radius: 16px;
  box-shadow: var(--shadow);
  color: var(--text);
}

.seat {
  position: absolute;
  width: 12px; height: 12px; border-radius: 50%;
  background: var(--surface); border: 2px solid var(--border);
  transform: translate(-50%, -50%);
  pointer-events: none;
  transition: background .15s, border-color .15s, transform .12s;
}
.seat.occupied {
  background: var(--accent);
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--surface);
  pointer-events: auto;
}
.seat.occupied:hover {
  transform: translate(-50%, -50%) scale(1.35);
}
.seat.over-base { border-color: var(--highlight); }
.seat.over-base.occupied { background: var(--highlight); }

/* Seat hover tooltip */
.seat-tip {
  position: fixed;
  z-index: 300;
  background: var(--accent);
  color: var(--on-accent);
  font-size: 12px; font-weight: 500;
  padding: 5px 10px;
  border-radius: 6px;
  box-shadow: var(--shadow-lg);
  pointer-events: none;
  transform: translate(-50%, calc(-100% - 10px));
  white-space: nowrap;
  max-width: 220px; overflow: hidden; text-overflow: ellipsis;
}
.seat-tip.hidden { display: none; }

/* Shape picker (card style) */
.shape-picker {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}
.shape-option {
  position: relative;
  display: flex; flex-direction: column; align-items: center;
  gap: 8px;
  padding: 16px 10px 12px;
  background: var(--surface-2);
  border: 2px solid var(--border);
  border-radius: 12px;
  cursor: pointer;
  user-select: none;
  transition: border-color .15s, background .15s, transform .1s;
}
.shape-option:hover { border-color: var(--border-strong); }
.shape-option input[type="radio"] {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}
.shape-option:has(input:checked) {
  background: var(--surface);
  border-color: var(--accent);
}
.shape-option:has(input:checked) .shape-draw {
  background: var(--accent);
  border-color: var(--accent);
}
.shape-preview {
  width: 64px; height: 44px;
  display: grid; place-items: center;
}
.shape-draw {
  background: transparent;
  border: 2.5px solid var(--border-strong);
  transition: background .15s, border-color .15s;
}
.shape-draw.circle { width: 38px; height: 38px; border-radius: 50%; }
.shape-draw.rect { width: 52px; height: 30px; border-radius: 4px; }
.shape-name { font-size: 12px; font-weight: 600; color: var(--text-2); }
.shape-option:has(input:checked) .shape-name { color: var(--text); }

/* Real-time remote drag + auto-arrange transitions */
.table-node.remote-moving {
  transition: left .09s linear, top .09s linear;
  z-index: 9;
}
.table-node.rearrange {
  transition: left .65s cubic-bezier(.22,.61,.36,1), top .65s cubic-bezier(.22,.61,.36,1);
}

/* Floating action button (auto-arrange) */
.floating-btn {
  position: fixed;
  bottom: 12px; left: calc(320px + 140px);
  width: 38px; height: 38px;
  border-radius: 8px;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  display: inline-flex; align-items: center; justify-content: center;
  cursor: pointer;
  box-shadow: var(--shadow);
  z-index: 15;
  transition: background .12s, border-color .12s, transform .1s;
}
.floating-btn:hover { background: var(--bg-2); border-color: var(--border-strong); }
.floating-btn:active { transform: scale(.95); }

/* Sidebar view tabs */
.view-tabs {
  display: flex; gap: 4px;
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 3px;
}
.tab-btn {
  flex: 1;
  padding: 6px 10px;
  background: transparent;
  border: none;
  border-radius: 6px;
  color: var(--muted);
  font-size: 12px; font-weight: 500;
  cursor: pointer;
  font-family: inherit;
  transition: background .12s, color .12s;
}
.tab-btn:hover { color: var(--text); }
.tab-btn.tab-active {
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow);
}

/* Table list (sidebar) */
.table-card {
  background: var(--surface);
  border: 1px solid var(--border);
  padding: 10px 12px; border-radius: 8px;
  cursor: pointer;
  display: flex; justify-content: space-between; align-items: center;
  gap: 8px;
  transition: border-color .12s, background .12s;
  user-select: none;
}
.table-card:hover { border-color: var(--border-strong); background: var(--surface-2); }
.table-card .tc-main { flex: 1; min-width: 0; }
.table-card .tc-name { font-size: 13px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.table-card .tc-meta { font-size: 11px; color: var(--muted); margin-top: 2px; }
.table-card .tc-count {
  flex: 0 0 auto;
  font-size: 12px; font-weight: 600;
  padding: 3px 9px;
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: 12px;
  color: var(--accent);
}
.table-card .tc-count.over { color: var(--highlight); border-color: var(--highlight); }
.table-card .tc-count.full { background: var(--accent); color: var(--on-accent); border-color: var(--accent); }
.tc-shape {
  flex: 0 0 auto;
  width: 16px; height: 16px;
  border: 2px solid var(--border-strong);
}
.tc-shape.circle { border-radius: 50%; }
.tc-shape.square { border-radius: 3px; }

/* Drag ghost (custom pointer-drag) */
.drag-ghost {
  position: fixed;
  top: 0; left: 0;
  pointer-events: none;
  z-index: 500;
  background: var(--accent);
  color: var(--on-accent);
  padding: 7px 12px;
  border-radius: 8px;
  font-size: 13px; font-weight: 500;
  box-shadow: var(--shadow-lg);
  transform: translate(-50%, -100%) translateY(-8px);
  white-space: nowrap;
  max-width: 220px; overflow: hidden; text-overflow: ellipsis;
}
.drag-ghost.hidden { display: none; }
body.is-dragging { cursor: grabbing; }

/* Modals */
.modal {
  position: fixed; inset: 0;
  background: rgba(22,20,18,.45);
  backdrop-filter: blur(4px);
  display: grid; place-items: center;
  z-index: 100;
  padding: 16px;
}
.modal.hidden { display: none; }
.modal-card {
  width: min(620px, 100%);
  max-height: calc(100dvh - 32px); overflow: auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 22px;
  position: relative;
  box-shadow: var(--shadow-lg);
}
.modal-sm { width: min(440px, 100%); }
.modal-close {
  position: absolute; top: 10px; right: 12px;
  background: transparent; border: none; color: var(--muted);
  font-size: 24px; cursor: pointer; line-height: 1;
  width: 30px; height: 30px; border-radius: 6px;
}
.modal-close:hover { background: var(--bg-2); color: var(--text); }
.modal-card h2 { margin: 0 0 14px 0; font-size: 18px; font-weight: 600; display: flex; align-items: center; gap: 10px; letter-spacing: -.3px; }
.modal-card h3 { margin: 10px 0; font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .6px; font-weight: 600; }
.modal-body { display: flex; flex-direction: column; gap: 10px; }
.modal-body hr { border: none; border-top: 1px solid var(--border); margin: 6px 0; }
.modal-actions {
  display: flex; justify-content: space-between; gap: 8px;
  margin-top: 16px; padding-top: 14px;
  border-top: 1px solid var(--border);
  flex-wrap: wrap;
}
.modal-actions > div { display: flex; gap: 8px; }

.confirm-row {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 12px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  cursor: pointer;
  user-select: none;
}
.confirm-row input[type="checkbox"] {
  width: 18px; height: 18px; margin: 0;
  accent-color: var(--success);
  cursor: pointer;
}
.confirm-row .confirm-label { font-size: 13px; font-weight: 500; }

.field { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.field label { font-size: 10px; color: var(--muted); text-transform: uppercase; letter-spacing: .5px; font-weight: 600; }
.field-row { display: flex; gap: 10px; flex-wrap: wrap; }
.field-row .field { flex: 1 1 160px; }
.field-sm { max-width: 170px; flex: 0 0 140px !important; }

.section-title { display: flex; justify-content: space-between; align-items: center; }
.hint { font-size: 11px; color: var(--muted); margin: 0; line-height: 1.5; }

.badge {
  font-size: 12px; background: var(--accent); color: var(--on-accent);
  padding: 2px 9px; border-radius: 12px; font-weight: 600;
}

/* Children */
.children-list { display: flex; flex-direction: column; gap: 6px; }
.child-row {
  display: grid; grid-template-columns: 1fr minmax(130px, 180px) auto; gap: 6px;
  align-items: center;
  background: var(--surface-2); border: 1px solid var(--border);
  padding: 7px; border-radius: 8px;
}
.child-row input, .child-row select {
  width: 100%; padding: 6px 8px; background: var(--surface);
  border: 1px solid var(--border); border-radius: 6px;
  color: var(--text); font-size: 12px;
  font-family: inherit;
}
.child-row button {
  background: transparent; border: none; color: var(--danger);
  cursor: pointer; font-size: 18px; padding: 0 8px; border-radius: 6px;
  width: 30px; height: 30px;
}
.child-row button:hover { background: rgba(174,74,67,.08); }

/* Table members */
.table-members { display: flex; flex-direction: column; gap: 6px; max-height: 260px; overflow-y: auto; }
.member-row {
  display: flex; justify-content: space-between; align-items: center;
  background: var(--surface-2); border: 1px solid var(--border);
  padding: 8px 10px; border-radius: 8px;
  gap: 8px;
}
.member-row.is-confirmed .name { color: var(--success); }
.member-row .left { display: flex; align-items: center; gap: 8px; min-width: 0; flex: 1; }
.member-row .name { font-size: 13px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; display: flex; align-items: center; gap: 5px; }
.member-row .phone { font-size: 11px; color: var(--muted); margin-top: 1px; }
.member-row button {
  background: transparent; border: 1px solid var(--border); color: var(--muted);
  border-radius: 6px; padding: 4px 8px; cursor: pointer; font-size: 11px;
  font-family: inherit;
}
.member-row button:hover { color: var(--danger); border-color: var(--danger); }

.quick-add { display: flex; gap: 6px; margin-top: 6px; flex-wrap: wrap; }
.quick-add input { flex: 1 1 200px; }

/* Import */
.import-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px,1fr)); gap: 10px; }
.import-preview {
  max-height: 220px; overflow: auto;
  border: 1px solid var(--border); border-radius: 8px;
  margin-top: 10px;
  background: var(--surface-2);
}
.import-preview table { width: 100%; border-collapse: collapse; font-size: 12px; }
.import-preview th, .import-preview td {
  padding: 6px 10px; text-align: left; border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.import-preview th { background: var(--bg-2); color: var(--muted); font-weight: 600; position: sticky; top: 0; }

/* Toast */
.toast {
  position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%);
  background: var(--accent); color: var(--on-accent);
  padding: 9px 16px; border-radius: 8px; font-size: 13px;
  box-shadow: var(--shadow-lg);
  z-index: 200;
  max-width: calc(100vw - 40px);
}
.toast.hidden { display: none; }
.toast.success { background: var(--success); }
.toast.error { background: var(--danger); }

/* Sidebar backdrop (mobile) */
.sidebar-backdrop {
  position: fixed; inset: 0;
  background: rgba(22,20,18,.4);
  z-index: 30;
  opacity: 0; pointer-events: none;
  transition: opacity .2s;
}
body.sidebar-open .sidebar-backdrop { opacity: 1; pointer-events: auto; }

/* Scrollbars (desktop) */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 10px; border: 2px solid var(--bg); }
::-webkit-scrollbar-thumb:hover { background: var(--border-strong); }

/* ===== Responsive ===== */
.only-mobile { display: none !important; }
.only-desktop { display: inline-flex; }

/* Tablet */
@media (max-width: 1000px) {
  .layout { grid-template-columns: 280px 1fr; }
  .topbar { padding: 9px 14px; }
  .btn-label { display: none; }
  .btn { padding: 7px 10px; }
  .btn .ico + .btn-label { display: none; }
  .icon-btn.only-mobile { display: none !important; }
  .zoom-controls { left: calc(280px + 12px); }
  .floating-btn { left: calc(280px + 140px); }
}

/* Mobile */
@media (max-width: 760px) {
  .topbar { padding: 6px 10px; gap: 4px; min-height: 48px; }
  .brand { gap: 6px; }
  .brand h1 { font-size: 14px; }
  .only-mobile { display: inline-flex !important; }
  .only-desktop { display: none !important; }

  .top-actions { gap: 3px; }
  .top-actions .btn { padding: 6px 8px; min-width: 34px; justify-content: center; }
  .top-actions .btn .ico { font-size: 16px; }
  .icon-btn { width: 34px; height: 34px; }
  .logo { width: 26px; height: 26px; }

  .layout {
    grid-template-columns: 1fr;
    height: calc(100dvh - 48px);
  }
  .sidebar {
    position: fixed;
    top: 48px; left: 0; bottom: 0;
    width: min(320px, 85vw);
    transform: translateX(-100%);
    transition: transform .22s ease;
    z-index: 35;
    box-shadow: var(--shadow-lg);
  }
  body.sidebar-open .sidebar { transform: translateX(0); }

  .sidebar-head { padding: 10px 10px 8px; gap: 8px; }
  .counts { gap: 4px; }
  .counts > div { padding: 6px 4px; }
  .counts strong { font-size: 15px; }
  .counts span { font-size: 9px; }
  .view-tabs { padding: 2px; }
  .tab-btn { padding: 6px 8px; font-size: 11px; }
  .search-wrap input { padding: 8px 10px; font-size: 13px; }
  .filters { gap: 4px; }
  .chip { padding: 4px 9px; font-size: 11px; }
  .guest-list { padding: 6px; gap: 4px; }

  .canvas-hint { font-size: 10px; padding: 6px 10px; max-width: 85%; }

  .modal { padding: 0; align-items: stretch; }
  .modal-card {
    max-height: 100dvh; height: 100dvh;
    width: 100%; max-width: 100%;
    border-radius: 0; border: none;
    padding: 16px 14px 18px;
  }
  .modal-card h2 { font-size: 16px; margin-bottom: 10px; }
  .modal-actions { position: sticky; bottom: 0; background: var(--surface); margin: 14px -14px -18px; padding: 12px 14px; }
  .child-row { grid-template-columns: 1fr; }
  .field-sm { max-width: 100%; flex: 1 1 100% !important; }

  .zoom-controls { bottom: 10px; left: 10px; }
  .zoom-btn { padding: 9px 12px; min-width: 40px; font-size: 16px; }
  .zoom-label { min-width: 56px; font-size: 12px; }
  .floating-btn { bottom: 10px; left: auto; right: 10px; width: 44px; height: 44px; }
}

/* Landscape phone / very short screens: avoid forcing full-height modals */
@media (max-width: 900px) and (max-height: 520px) {
  .topbar { padding: 4px 10px; min-height: 40px; }
  .layout { height: calc(100dvh - 40px); }
  .sidebar { top: 40px; width: min(300px, 60vw); }
  .sidebar-head { padding: 8px 10px; gap: 6px; }
  .counts { display: none; }
  .filters { display: flex; }
  .modal { padding: 10px; align-items: center; }
  .modal-card {
    max-height: calc(100dvh - 20px); height: auto;
    width: min(680px, 100%); max-width: 680px;
    border-radius: 12px; border: 1px solid var(--border);
    padding: 14px 16px;
  }
  .modal-card h2 { font-size: 15px; margin-bottom: 8px; }
  .modal-actions {
    position: static; margin: 12px 0 0; padding: 12px 0 0;
    background: transparent;
  }
  .field-row { gap: 8px; }
  .field-row .field { flex: 1 1 140px; }
  .table-members { max-height: 140px; }
}

/* Very narrow portrait */
@media (max-width: 480px) {
  .brand h1 { display: none; }
  .logo { display: none !important; }
  .counts { grid-template-columns: repeat(2, 1fr); }
  .top-actions .btn { padding: 5px 7px; }
}
