/* css/style.css */

:root {
  --primary: #2C5AA0;
  --accent: #2F8F5B;
  --bg: #F5F7FA;
  --surface: #FFFFFF;
  --border: #E1E5EA;
  --text: #1F2937;
  --text-muted: #6B7280;
  --danger: #DC2626;
  --radius: 8px;
}

* { box-sizing: border-box; }

/* Guarantees the native `hidden` attribute always wins, even against
   ID-selector display rules below (#view-login, #app-shell) that would
   otherwise silently override it due to higher CSS specificity. */
[hidden] { display: none !important; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
}

.view { display: block; }
.view[hidden] { display: none; }

/* ---------------- Login ---------------- */

#view-login {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, var(--primary), var(--accent));
}

.login-card {
  background: var(--surface);
  padding: 2.5rem;
  border-radius: var(--radius);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.15);
  width: 100%;
  max-width: 360px;
}

.login-card h1 {
  margin: 0 0 0.25rem;
  font-size: 1.5rem;
}

.subtitle {
  margin: 0 0 1.5rem;
  color: var(--text-muted);
  font-size: 0.9rem;
}

#login-form label {
  display: block;
  font-size: 0.85rem;
  font-weight: 600;
  margin: 1rem 0 0.35rem;
}

#login-form input {
  width: 100%;
  padding: 0.6rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 0.95rem;
}

#login-form input:focus {
  outline: none;
  border-color: var(--primary);
}

#login-submit {
  margin-top: 1.5rem;
  width: 100%;
  padding: 0.7rem;
  background: var(--primary);
  color: white;
  border: none;
  border-radius: var(--radius);
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
}

#login-submit:hover { opacity: 0.9; }
#login-submit:disabled { opacity: 0.6; cursor: not-allowed; }

.error-text {
  color: var(--danger);
  font-size: 0.85rem;
  margin-top: 0.75rem;
}

/* ---------------- App shell ---------------- */

#app-shell {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  width: 220px;
  background: var(--primary);
  color: white;
  display: flex;
  flex-direction: column;
  padding: 1.5rem 0;
  flex-shrink: 0;
}

.sidebar-header {
  padding: 0 1.5rem 1.5rem;
  border-bottom: 1px solid rgba(255, 255, 255, 0.15);
  margin-bottom: 1rem;
}

.brand { display: block; font-weight: 700; font-size: 1.1rem; }
.brand-sub { display: block; font-size: 0.75rem; opacity: 0.75; }

.nav-link {
  display: block;
  padding: 0.75rem 1.5rem;
  color: white;
  text-decoration: none;
  font-size: 0.9rem;
  border-left: 3px solid transparent;
  background: none;
  border-top: none;
  border-bottom: none;
  border-right: none;
  text-align: left;
  width: 100%;
  cursor: pointer;
  font-family: inherit;
}

.nav-link:hover { background: rgba(255, 255, 255, 0.1); }
.nav-link.active { border-left-color: var(--accent); background: rgba(255, 255, 255, 0.1); font-weight: 600; }
.nav-link-danger { margin-top: auto; color: #FCA5A5; }

.content {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 1rem 1.5rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-weight: 600;
}

.whoami { font-size: 0.85rem; color: var(--text-muted); font-weight: 400; }

.page { padding: 1.5rem; }
.page[hidden] { display: none; }

.toast {
  margin: 1rem 1.5rem 0;
  padding: 0.75rem 1rem;
  border-radius: var(--radius);
  font-size: 0.9rem;
}
.toast.success { background: #DCFCE7; color: #166534; }
.toast.error { background: #FEE2E2; color: #991B1B; }

/* ---------------- Shared table/form styles (used by later pages) ---------------- */

table { width: 100%; border-collapse: collapse; background: var(--surface); border-radius: var(--radius); overflow: hidden; }
th, td { padding: 0.65rem 0.9rem; text-align: left; border-bottom: 1px solid var(--border); font-size: 0.9rem; }
th { background: #F9FAFB; font-weight: 600; color: var(--text-muted); text-transform: uppercase; font-size: 0.75rem; }

button.primary { background: var(--primary); color: white; border: none; padding: 0.55rem 1rem; border-radius: var(--radius); cursor: pointer; font-weight: 600; }
button.secondary { background: var(--surface); color: var(--text); border: 1px solid var(--border); padding: 0.55rem 1rem; border-radius: var(--radius); cursor: pointer; }
button.danger { background: var(--danger); color: white; border: none; padding: 0.4rem 0.8rem; border-radius: var(--radius); cursor: pointer; font-size: 0.85rem; }
button.primary:disabled { opacity: 0.6; cursor: not-allowed; }

/* ---------------- Forms (settings page, and reusable for tables/menu/staff) ---------------- */

.settings-form {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 1.5rem;
  max-width: 720px;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 1.1rem 1.5rem;
}

.form-field { display: flex; flex-direction: column; }

.form-field label {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 0.35rem;
}

.form-field input,
.form-field select {
  padding: 0.55rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 0.9rem;
  font-family: inherit;
  background: white;
}

.form-field input:focus,
.form-field select:focus { outline: none; border-color: var(--primary); }

.color-row { display: flex; align-items: center; gap: 0.6rem; }
.color-row input[type="color"] { width: 42px; height: 34px; padding: 2px; border: 1px solid var(--border); border-radius: var(--radius); cursor: pointer; }
.color-row span { font-size: 0.85rem; color: var(--text-muted); font-family: monospace; }

.form-actions {
  margin-top: 1.5rem;
  padding-top: 1.25rem;
  border-top: 1px solid var(--border);
}

/* ---------------- Toolbar + badges + small buttons (staff/tables/menu pages) ---------------- */

.toolbar {
  display: flex;
  justify-content: flex-end;
  margin-bottom: 1rem;
}

.role-badge {
  display: inline-block;
  padding: 0.2rem 0.6rem;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  background: #E5E7EB;
  color: #374151;
}
.role-admin { background: #EDE9FE; color: #5B21B6; }
.role-manager { background: #DBEAFE; color: #1E40AF; }
.role-waiter { background: #D1FAE5; color: #065F46; }
.role-chef { background: #FEF3C7; color: #92400E; }
.role-cashier { background: #FCE7F3; color: #9D174D; }

.status-badge {
  display: inline-block;
  padding: 0.2rem 0.6rem;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 600;
}
.status-active { background: #DCFCE7; color: #166534; }
.status-inactive { background: #FEE2E2; color: #991B1B; }

.actions-cell { display: flex; gap: 0.4rem; flex-wrap: wrap; }

button.btn-sm {
  padding: 0.35rem 0.65rem;
  font-size: 0.8rem;
  border-radius: 6px;
}

a.btn-sm {
  text-decoration: none;
  display: inline-block;
  text-align: center;
}

/* Status color source — one place each status's color lives, shared by
   the badge (.status-badge.status-x), the floor-plan tile ring
   (.table-tile.status-x), and the legend dot (.legend-dot.status-x). */
.status-empty { background: #F3F4F6; color: #4B5563; }
.status-occupied { background: #FEF3C7; color: #92400E; }
.status-order_placed { background: #DBEAFE; color: #1E40AF; }
.status-preparing { background: #FED7AA; color: #9A3412; }
.status-ready { background: #DCFCE7; color: #166534; }
.status-served { background: #E0E7FF; color: #3730A3; }
.status-needs_bill { background: #FCE7F3; color: #9D174D; }

.table-tile.status-empty, .legend-dot.status-empty { --status-color: #94A3B8; }
.table-tile.status-occupied, .legend-dot.status-occupied { --status-color: #F59E0B; }
.table-tile.status-order_placed, .legend-dot.status-order_placed { --status-color: #3B82F6; }
.table-tile.status-preparing, .legend-dot.status-preparing { --status-color: #FB7185; }
.table-tile.status-ready, .legend-dot.status-ready { --status-color: #10B981; }
.table-tile.status-served, .legend-dot.status-served { --status-color: #A78BFA; }
.table-tile.status-needs_bill, .legend-dot.status-needs_bill { --status-color: #EC4899; }

/* ---------------- Tables page — virtual floor plan ---------------- */

.status-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 0.9rem;
  margin-left: auto;
  align-items: center;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.78rem;
  color: var(--text-muted);
}

.legend-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--status-color);
  display: inline-block;
}

.muted-loading { color: var(--text-muted); }

#table-form-container:empty {
  display: none;
}

.floor-plan {
  background: #1C2333;
  border-radius: 14px;
  padding: 1.25rem;
  display: grid;
  grid-template-columns: repeat(auto-fill, 62px);
  justify-content: start;
  gap: 1.1rem 0.9rem;
  background-image: radial-gradient(rgba(255, 255, 255, 0.035) 1px, transparent 1px);
  background-size: 16px 16px;
}

.table-tile {
  width: 62px;
  height: 62px;
  border-radius: 50%;
  background: #2A3348;
  border: 3px solid var(--status-color);
  position: relative;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
  flex-shrink: 0;
}

.table-tile:hover {
  transform: translateY(-3px);
  box-shadow: 0 8px 18px rgba(0, 0, 0, 0.4);
}

.table-tile-inner {
  display: flex;
  flex-direction: column;
  align-items: center;
  color: #F1F5F9;
}

.table-tile-number {
  font-size: 1.05rem;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  line-height: 1;
}

.seat {
  position: absolute;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.18);
}
.seat:nth-child(1) { top: -10px; left: 50%; transform: translateX(-50%); }
.seat:nth-child(2) { right: -10px; top: 50%; transform: translateY(-50%); }
.seat:nth-child(3) { bottom: -10px; left: 50%; transform: translateX(-50%); }
.seat:nth-child(4) { left: -10px; top: 50%; transform: translateY(-50%); }

.waiter-chip {
  position: absolute;
  bottom: -4px;
  right: -4px;
  width: 21px;
  height: 21px;
  border-radius: 50%;
  color: white;
  font-size: 0.55rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px solid #1C2333;
}

.waiter-chip-empty {
  background: transparent;
  border: 1.5px dashed rgba(255, 255, 255, 0.35);
  color: rgba(255, 255, 255, 0.5);
  font-weight: 400;
  font-size: 0.7rem;
}

/* Responsive: tighten further on narrow screens, and let the sidebar
   collapse out of the way so the floor plan gets full width to breathe. */
@media (max-width: 900px) {
  #app-shell { flex-direction: column; }
  .sidebar { width: 100%; flex-direction: row; flex-wrap: wrap; padding: 0.75rem 1rem; }
  .sidebar-header { border-bottom: none; margin-bottom: 0; padding: 0 1rem 0 0; }
  .nav-link { padding: 0.5rem 0.75rem; }
  .nav-link-danger { margin-top: 0; margin-left: auto; }
  .page { padding: 1rem; }
}

@media (max-width: 640px) {
  .floor-plan { padding: 0.85rem; gap: 0.9rem 0.7rem; grid-template-columns: repeat(auto-fill, 52px); }
  .table-tile { width: 52px; height: 52px; border-width: 2.5px; }
  .table-tile-number { font-size: 0.9rem; }
  .waiter-chip { width: 18px; height: 18px; font-size: 0.5rem; }
  .status-legend { gap: 0.6rem; }
  .legend-item { font-size: 0.7rem; }
  .toolbar { flex-direction: column; align-items: stretch; }
  .status-legend { margin-left: 0; }
}

/* ---------------- Table detail modal ---------------- */

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
  z-index: 1000;
}

.modal-card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 1.75rem;
  max-width: 360px;
  width: 100%;
  position: relative;
  max-height: 90vh;
  overflow-y: auto;
}

.modal-close {
  position: absolute;
  top: 0.9rem;
  right: 1rem;
  background: none;
  border: none;
  font-size: 1.5rem;
  line-height: 1;
  color: var(--text-muted);
  cursor: pointer;
}

.modal-header {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin-bottom: 1.25rem;
}

.modal-table-number {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  background: var(--primary);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  font-size: 1.2rem;
}

.modal-qr-img {
  width: 100%;
  max-width: 220px;
  aspect-ratio: 1;
  display: block;
  margin: 0 auto 0.75rem;
  border: 1px solid var(--border);
  border-radius: 8px;
}

.table-qr-actions {
  display: flex;
  gap: 0.4rem;
}
.table-qr-actions > * { flex: 1; }

/* ---------------- Menu page: tabs ---------------- */

.tabs {
  display: flex;
  gap: 0.25rem;
  border-bottom: 1px solid var(--border);
  margin-bottom: 1.25rem;
}

.tab-btn {
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  padding: 0.65rem 1rem;
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text-muted);
  cursor: pointer;
  font-family: inherit;
}

.tab-btn:hover { color: var(--text); }
.tab-btn.active { color: var(--primary); border-bottom-color: var(--primary); }

.muted-inline { font-size: 0.8rem; color: var(--text-muted); margin-left: 0.4rem; }

/* Availability toggle switch */
.toggle-switch {
  position: relative;
  display: inline-block;
  width: 38px;
  height: 21px;
  vertical-align: middle;
}
.toggle-switch input { opacity: 0; width: 0; height: 0; }
.toggle-slider {
  position: absolute;
  inset: 0;
  background: #D1D5DB;
  border-radius: 999px;
  cursor: pointer;
  transition: background 0.15s ease;
}
.toggle-slider::before {
  content: "";
  position: absolute;
  width: 15px;
  height: 15px;
  left: 3px;
  top: 3px;
  background: white;
  border-radius: 50%;
  transition: transform 0.15s ease;
}
.toggle-switch input:checked + .toggle-slider { background: var(--accent); }
.toggle-switch input:checked + .toggle-slider::before { transform: translateX(17px); }

/* Checkbox pill group (ingredients/modifiers picker on the item form) */
.check-pill-group {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  max-height: 140px;
  overflow-y: auto;
  padding: 0.5rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.check-pill {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  background: #F3F4F6;
  border-radius: 999px;
  padding: 0.3rem 0.7rem;
  font-size: 0.82rem;
  cursor: pointer;
}
.check-pill input { margin: 0; }

/* Removable chips (ingredients list, modifier option list) */
.chip-removable {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  background: #F3F4F6;
  border-radius: 999px;
  padding: 0.35rem 0.5rem 0.35rem 0.85rem;
  font-size: 0.82rem;
  margin: 0.2rem 0.3rem 0.2rem 0;
}

.chip-remove-btn {
  background: #E5E7EB;
  border: none;
  border-radius: 50%;
  width: 18px;
  height: 18px;
  line-height: 1;
  cursor: pointer;
  color: var(--text-muted);
  font-size: 0.9rem;
}
.chip-remove-btn:hover { background: var(--danger); color: white; }

/* Modifier group cards */
.modifier-group-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.1rem;
  margin-bottom: 1rem;
  max-width: 640px;
}

.modifier-group-header {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.75rem;
}

.option-list { display: flex; flex-wrap: wrap; }
/* ---------------- Menu items: image, link buttons, field label row ---------------- */

.field-label-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.35rem;
}
.field-label-row label { margin-bottom: 0; }

.link-btn-sm {
  background: none;
  border: none;
  color: var(--primary);
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  padding: 0;
}
.link-btn-sm:hover { text-decoration: underline; }

.item-image-preview {
  display: block;
  margin-top: 0.5rem;
  width: 96px;
  height: 96px;
  object-fit: cover;
  border-radius: var(--radius);
  border: 1px solid var(--border);
}

.item-thumb {
  width: 44px;
  height: 44px;
  border-radius: 8px;
  object-fit: cover;
  display: block;
}
.item-thumb-empty {
  width: 44px;
  height: 44px;
  border-radius: 8px;
  background: #F3F4F6;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.2rem;
}