:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --border: #e2e4e9;
  --text: #1c1e24;
  --text-2: #6b7080;
  --primary: #2f6df6;
  --primary-dark: #1f54c8;
  --free-bg: #e8f6ec;
  --free-bd: #4caf7d;
  --resv-bg: #fdf3dc;
  --resv-bd: #e0a52e;
  --seated-bg: #e7effd;
  --seated-bd: #2f6df6;
  --danger: #d64545;
  --radius: 10px;
  font-size: 15px;
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

body {
  margin: 0;
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
}

h1, h2, h3 { margin: 0; font-weight: 600; }

/* ---------- Горна лента ---------- */
.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 24px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.brand { display: flex; align-items: center; gap: 12px; }
.brand-icon { font-size: 26px; }
.brand h1 { font-size: 18px; }
.brand-sub { font-size: 12px; color: var(--text-2); }
.topbar-actions { display: flex; gap: 10px; }

.setup-notice {
  margin: 40px auto;
  max-width: 560px;
  padding: 20px 24px;
  background: #fff8e6;
  border: 1px solid #e0c76e;
  border-radius: var(--radius);
  line-height: 1.6;
}
.setup-notice code { background: #f0e8cd; padding: 1px 5px; border-radius: 4px; }

/* ---------- Бутони ---------- */
.btn {
  padding: 8px 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  font-size: 14px;
  cursor: pointer;
}
.btn:hover { border-color: #c3c7d1; }
.btn-primary {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}
.btn-primary:hover { background: var(--primary-dark); }
.btn-icon { padding: 8px 10px; }
.btn-danger { color: var(--danger); border-color: #eac3c3; }
.btn.toggle.active {
  background: #eef3fe;
  border-color: var(--primary);
  color: var(--primary);
}

/* ---------- Основен изглед ---------- */
.layout {
  display: grid;
  grid-template-columns: 1fr 320px;
  gap: 20px;
  padding: 20px 24px;
  align-items: start;
}
@media (max-width: 1000px) { .layout { grid-template-columns: 1fr; } }

.toolbar {
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 14px;
}
.datenav { display: flex; gap: 6px; align-items: center; }
.date-input {
  padding: 7px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 14px;
  font-family: inherit;
}
.day-summary { color: var(--text-2); font-size: 14px; flex: 1; }
.view-toggle { display: flex; gap: 6px; }

/* ---------- Слотове ---------- */
.slot-row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 18px;
}
.slot-chip {
  padding: 6px 14px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  font-size: 14px;
  cursor: pointer;
}
.slot-chip.active {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}
.slot-chip .free-count { font-size: 12px; opacity: 0.75; margin-left: 4px; }
.closed-msg {
  padding: 14px 18px;
  background: var(--surface);
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  color: var(--text-2);
}

/* ---------- План на залата ---------- */
.zone-title {
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-2);
  margin: 18px 0 10px;
}
.floor-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 12px;
}
.table-card {
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  padding: 12px 14px;
  cursor: pointer;
  min-height: 96px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.table-card .t-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
}
.table-card .t-label { font-size: 17px; font-weight: 600; }
.table-card .t-seats { font-size: 13px; color: var(--text-2); white-space: nowrap; }
.table-card.free .t-seats { color: #16a34a; }
.table-card.resv .t-seats, .table-card.seated .t-seats { color: #dc2626; }
.table-card .t-status { font-size: 13px; margin-top: auto; }
.table-card .t-guest { font-size: 13px; font-weight: 600; }

.table-card.free    { background: var(--free-bg);   border-color: var(--free-bd); }
.table-card.resv    { background: var(--resv-bg);   border-color: var(--resv-bd); }
.table-card.seated  { background: var(--seated-bg); border-color: var(--seated-bd); }
.table-card.inactive { opacity: 0.45; cursor: default; }

/* ---------- График (timeline) ---------- */
.tl-wrap {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  overflow-x: auto;
}
.tl-row {
  display: grid;
  align-items: stretch;
  min-height: 34px;
  border-bottom: 1px solid #f0f1f4;
}
.tl-row:last-child { border-bottom: none; }
.tl-label {
  font-size: 13px;
  font-weight: 600;
  display: flex;
  align-items: center;
  padding-right: 8px;
}
.tl-label span { font-weight: 400; color: var(--text-2); margin-left: 5px; }
.tl-cells { display: grid; position: relative; gap: 2px; padding: 3px 0; }
.tl-hour {
  font-size: 11px;
  color: var(--text-2);
  border-left: 1px solid #eceef2;
  padding-left: 3px;
}
.tl-block {
  border-radius: 6px;
  font-size: 12px;
  padding: 4px 8px;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  cursor: pointer;
}
.tl-block.resv   { background: var(--resv-bg);   border: 1px solid var(--resv-bd); }
.tl-block.seated { background: var(--seated-bg); border: 1px solid var(--seated-bd); }

/* ---------- Страничен панел ---------- */
.sidebar {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
}
.sidebar h2 { font-size: 15px; margin-bottom: 12px; }
.res-list { display: flex; flex-direction: column; gap: 8px; }
.res-item {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 3px;
}
.res-item:hover { border-color: #c3c7d1; }
.res-item .r-top { display: flex; justify-content: space-between; font-size: 14px; }
.res-item .r-time { font-weight: 600; }
.res-item .r-meta { font-size: 13px; color: var(--text-2); }
.res-empty { color: var(--text-2); font-size: 14px; }

.badge {
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 999px;
  align-self: flex-start;
}
.badge.confirmed { background: var(--resv-bg);   color: #8a6410; }
.badge.seated    { background: var(--seated-bg); color: var(--primary-dark); }
.badge.completed { background: #eceef2; color: var(--text-2); }
.badge.no_show   { background: #fdeaea; color: var(--danger); }
.badge.phone     { background: #efe7fb; color: #6b3fb5; }
.badge.waitlist  { background: #fff3d6; color: #9a6a00; }
.wl-count { font-size: 13px; color: var(--text-2); font-weight: 400; }
#waitlistBox { margin-bottom: 18px; }
.wl-item { border-left: 3px solid #e8a900; }

/* ---------- Модали ---------- */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(20, 22, 30, 0.45);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 6vh 16px;
  z-index: 50;
  overflow-y: auto;
}
.modal {
  background: var(--surface);
  border-radius: 14px;
  width: 100%;
  max-width: 520px;
  padding: 20px 22px;
}
.modal-wide { max-width: 760px; }
.modal-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
}
.modal-head h2 { font-size: 17px; }
.modal-foot {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 18px;
}

/* ---------- Форми ---------- */
.form label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 13px;
  color: var(--text-2);
  margin-bottom: 12px;
  flex: 1;
}
.form input, .form select {
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 14px;
  font-family: inherit;
  color: var(--text);
}
.form-row { display: flex; gap: 12px; }
.assign-mode { display: flex; gap: 18px; margin: 4px 0 10px; }
.radio {
  flex-direction: row !important;
  align-items: center;
  gap: 6px !important;
  margin-bottom: 0 !important;
  font-size: 14px !important;
  color: var(--text) !important;
}
.manual-tables {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 10px;
  border: 1px dashed var(--border);
  border-radius: 8px;
  margin-bottom: 10px;
}
.manual-tables .tbl-check {
  flex-direction: row !important;
  align-items: center;
  gap: 5px !important;
  margin: 0 !important;
  font-size: 13px !important;
  color: var(--text) !important;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 5px 10px;
  flex: 0 0 auto;
}
.form-msg {
  padding: 10px 12px;
  border-radius: 8px;
  background: #fdf3dc;
  border: 1px solid #e0c76e;
  font-size: 14px;
  line-height: 1.5;
}
.form-msg .alt-chip {
  display: inline-block;
  margin: 4px 6px 0 0;
  padding: 3px 10px;
  background: var(--surface);
  border: 1px solid var(--resv-bd);
  border-radius: 999px;
  cursor: pointer;
  font-size: 13px;
}

/* ---------- Детайли ---------- */
.detail-grid {
  display: grid;
  grid-template-columns: 130px 1fr;
  gap: 8px 14px;
  font-size: 14px;
}
.detail-grid dt { color: var(--text-2); }
.detail-grid dd { margin: 0; font-weight: 500; }

/* ---------- Настройки ---------- */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 16px; }
.tab {
  padding: 8px 14px;
  border: none;
  background: none;
  font-size: 14px;
  cursor: pointer;
  color: var(--text-2);
  border-bottom: 2px solid transparent;
}
.tab.active { color: var(--primary); border-bottom-color: var(--primary); font-weight: 600; }
.tab-pane { display: none; }
.tab-pane.active { display: block; }

.settings-table { width: 100%; border-collapse: collapse; font-size: 14px; }
.settings-table th {
  text-align: left;
  font-size: 12px;
  color: var(--text-2);
  font-weight: 500;
  padding: 6px 8px;
}
.settings-table td { padding: 5px 8px; border-top: 1px solid #f0f1f4; }
.settings-table input, .settings-table select {
  padding: 6px 8px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 14px;
  font-family: inherit;
  width: 100%;
}
.settings-table input[type="checkbox"] { width: auto; }
.settings-table input[type="number"] { width: 70px; }
.settings-table input[type="time"] { width: 110px; }
.add-row-btn { margin-top: 12px; }

.general-form { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; max-width: 520px; }
.general-form label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 13px;
  color: var(--text-2);
}
.general-form input, .general-form select {
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 14px;
  font-family: inherit;
}

/* ---------- Toast ---------- */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: #23262e;
  color: #fff;
  padding: 10px 18px;
  border-radius: 10px;
  font-size: 14px;
  z-index: 100;
}
.toast.error { background: var(--danger); }

/* ---------- Мобилна оптимизация ---------- */
@media (max-width: 640px) {
  .topbar { flex-wrap: wrap; gap: 8px; padding: 10px 14px; }
  .topbar-actions { width: 100%; flex-wrap: wrap; }
  .floor-grid { grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); }
  .general-form { grid-template-columns: 1fr; }
  .settings-table { display: block; overflow-x: auto; -webkit-overflow-scrolling: touch; }
}

/* ---------- Вход за ресторантьори ---------- */
.login-overlay {
  position: fixed; inset: 0; z-index: 200;
  background: var(--bg);
  display: flex; align-items: center; justify-content: center; padding: 20px;
}
.login-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 16px; padding: 30px 28px; width: 100%; max-width: 380px;
  box-shadow: 0 24px 60px rgba(28, 30, 36, 0.14);
}
.login-brand { font-size: 24px; font-weight: 700; letter-spacing: -0.02em; margin-bottom: 20px; }
.login-brand span { color: var(--primary); }
.login-card h2 { font-size: 19px; margin: 0 0 6px; }
.login-sub { font-size: 13.5px; color: var(--text-2); margin: 0 0 18px; line-height: 1.5; }
.login-card label { display: block; font-size: 13px; color: var(--text-2); margin-bottom: 14px; }
.login-card input {
  width: 100%; margin-top: 5px; padding: 11px 12px;
  border: 1px solid var(--border); border-radius: 8px;
  font-size: 15px; font-family: inherit; color: var(--text);
}
.login-card input:focus { outline: none; border-color: var(--primary); }
.btn-block { width: 100%; justify-content: center; margin-top: 6px; }
.venue-list { display: flex; flex-direction: column; gap: 8px; margin-bottom: 14px; }
.venue-list .btn { width: 100%; justify-content: flex-start; }
