@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap');

:root {
  --sidebar-bg: #1a1a2e;
  --sidebar-hover: #16213e;
  --accent: #e8643a;
  --accent-hover: #d4532a;
  --accent-light: rgba(232, 100, 58, 0.12);
  --bg: #f4f5f7;
  --surface: #ffffff;
  --border: #e2e4e9;
  --text: #1a1d23;
  --text-muted: #6b7280;
  --text-light: #9ca3af;
  --success: #10b981;
  --warning: #f59e0b;
  --danger: #ef4444;
  --info: #3b82f6;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 1px 3px rgba(0,0,0,0.08), 0 1px 2px rgba(0,0,0,0.04);
  --shadow-md: 0 4px 6px -1px rgba(0,0,0,0.1), 0 2px 4px -1px rgba(0,0,0,0.06);
  --shadow-lg: 0 10px 15px -3px rgba(0,0,0,0.1), 0 4px 6px -2px rgba(0,0,0,0.05);
}

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
  font-family: 'Inter', -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  display: flex;
  height: 100vh;
  overflow: hidden;
}

/* ─── SIDEBAR ─── */
#sidebar {
  width: 220px;
  min-width: 220px;
  background: var(--sidebar-bg);
  display: flex;
  flex-direction: column;
  height: 100vh;
  z-index: 100;
}

#sidebar .logo {
  padding: 24px 20px 20px;
  border-bottom: 1px solid rgba(255,255,255,0.06);
}

#sidebar .logo h1 {
  font-size: 16px;
  font-weight: 700;
  color: #fff;
  line-height: 1.2;
}

#sidebar .logo span {
  font-size: 12px;
  color: var(--accent);
  font-weight: 500;
}

#sidebar nav {
  flex: 1;
  padding: 12px 10px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

#sidebar nav a {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  color: rgba(255,255,255,0.6);
  text-decoration: none;
  font-size: 14px;
  font-weight: 500;
  transition: all 0.15s;
  cursor: pointer;
}

#sidebar nav a:hover {
  background: var(--sidebar-hover);
  color: rgba(255,255,255,0.9);
}

#sidebar nav a.active {
  background: var(--accent-light);
  color: var(--accent);
}

#sidebar nav a .icon { font-size: 18px; width: 22px; text-align: center; }

#sidebar .sidebar-footer {
  padding: 16px;
  border-top: 1px solid rgba(255,255,255,0.06);
  font-size: 12px;
  color: rgba(255,255,255,0.3);
}

/* ─── MAIN ─── */
#main {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.view {
  display: none;
  flex: 1;
  overflow-y: auto;
  padding: 28px 32px;
  flex-direction: column;
  gap: 24px;
}

.view.active { display: flex; }

.view-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
}

.view-header h2 {
  font-size: 22px;
  font-weight: 700;
}

/* ─── BUTTONS ─── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  border: none;
  transition: all 0.15s;
  line-height: 1;
}

.btn-primary { background: var(--accent); color: white; }
.btn-primary:hover { background: var(--accent-hover); }
.btn-sm { padding: 6px 12px; font-size: 13px; }
.btn-outline { background: transparent; border: 1px solid var(--border); color: var(--text); }
.btn-outline:hover { background: var(--bg); }
.btn-danger { background: var(--danger); color: white; }
.btn-danger:hover { background: #dc2626; }
.btn-success { background: var(--success); color: white; }
.btn-success:hover { background: #059669; }
.btn-warning { background: var(--warning); color: white; }
.btn-warning:hover { background: #d97706; }

/* ─── CARDS ─── */
.card {
  background: var(--surface);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
}

.card-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.card-header h3 { font-size: 15px; font-weight: 600; }
.card-body { padding: 20px; }

/* ─── STATS GRID ─── */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 16px;
}

.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
}

.stat-card .label {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 8px;
}

.stat-card .value {
  font-size: 32px;
  font-weight: 700;
  color: var(--text);
  line-height: 1;
}

.stat-card .sub { font-size: 12px; color: var(--text-muted); margin-top: 4px; }
.stat-card.accent .value { color: var(--accent); }
.stat-card.success .value { color: var(--success); }

/* ─── TABLES ─── */
.data-table { width: 100%; border-collapse: collapse; }
.data-table th {
  text-align: left;
  padding: 10px 14px;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  border-bottom: 1px solid var(--border);
  background: #f9fafb;
}
.data-table td {
  padding: 12px 14px;
  font-size: 14px;
  border-bottom: 1px solid #f1f3f5;
  vertical-align: middle;
}
.data-table tr:last-child td { border-bottom: none; }
.data-table tr:hover td { background: #fafafa; }

/* ─── BADGES ─── */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 3px 10px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 600;
}
.badge-green { background: #d1fae5; color: #065f46; }
.badge-red { background: #fee2e2; color: #991b1b; }
.badge-yellow { background: #fef3c7; color: #92400e; }
.badge-orange { background: #ffedd5; color: #9a3412; }
.badge-blue { background: #dbeafe; color: #1e40af; }
.badge-gray { background: #f3f4f6; color: #374151; }

/* ─── CUCINA VIEW ─── */
#view-cucina {
  background: #111827;
  padding: 20px;
}

#view-cucina .view-header h2 { color: white; }
#view-cucina .kitchen-meta { color: rgba(255,255,255,0.5); font-size: 14px; }

.kitchen-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 16px;
}

.kitchen-card {
  border-radius: var(--radius);
  padding: 20px;
  position: relative;
  overflow: hidden;
  transition: transform 0.15s;
}

.kitchen-card:hover { transform: translateY(-2px); }
.kitchen-card.pending { background: #1f2937; border: 2px solid #f59e0b; }
.kitchen-card.preparing { background: #1f2937; border: 2px solid #e8643a; }
.kitchen-card.ready { background: #1f2937; border: 2px solid #10b981; }

.kitchen-card .kc-status {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1px;
  margin-bottom: 12px;
}
.kitchen-card.pending .kc-status { color: #f59e0b; }
.kitchen-card.preparing .kc-status { color: #e8643a; }
.kitchen-card.ready .kc-status { color: #10b981; }

.kitchen-card .kc-customer {
  font-size: 20px;
  font-weight: 700;
  color: white;
  margin-bottom: 4px;
}

.kitchen-card .kc-time {
  font-size: 14px;
  color: rgba(255,255,255,0.5);
  margin-bottom: 16px;
}

.kitchen-card .kc-countdown {
  display: inline-block;
  padding: 4px 10px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 600;
  margin-left: 8px;
}

.kc-countdown.soon { background: #dc2626; color: white; }
.kc-countdown.ok { background: #374151; color: #9ca3af; }

.kitchen-card .kc-items { margin-bottom: 16px; }
.kitchen-card .kc-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 0;
  border-bottom: 1px solid rgba(255,255,255,0.06);
  font-size: 15px;
  color: rgba(255,255,255,0.85);
}
.kitchen-card .kc-item:last-child { border-bottom: none; }
.kitchen-card .kc-qty {
  background: rgba(255,255,255,0.1);
  border-radius: 6px;
  padding: 2px 8px;
  font-weight: 700;
  font-size: 14px;
  color: white;
  min-width: 30px;
  text-align: center;
}

.kitchen-card .kc-notes {
  font-size: 13px;
  color: #f59e0b;
  padding: 8px 12px;
  background: rgba(245,158,11,0.1);
  border-radius: 6px;
  margin-bottom: 16px;
}

.kitchen-card .kc-actions { display: flex; gap: 8px; }
.kitchen-card .kc-actions .btn { flex: 1; justify-content: center; font-size: 13px; padding: 10px; }

.kitchen-empty {
  text-align: center;
  padding: 80px 20px;
  color: rgba(255,255,255,0.3);
  font-size: 18px;
}

/* ─── MAPPA TAVOLI ─── */
.table-map-container {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.table-map-area {
  position: relative;
  width: 100%;
  aspect-ratio: 16/9;
  background: repeating-linear-gradient(
    0deg, transparent, transparent 39px, #f0f0f0 39px, #f0f0f0 40px
  ),
  repeating-linear-gradient(
    90deg, transparent, transparent 39px, #f0f0f0 39px, #f0f0f0 40px
  );
  background-color: #fafafa;
}

.table-token {
  position: absolute;
  transform: translate(-50%, -50%);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  cursor: pointer;
  transition: transform 0.15s, box-shadow 0.15s;
  user-select: none;
  font-size: 11px;
  font-weight: 700;
  text-align: center;
  line-height: 1.2;
}

.table-token:hover { transform: translate(-50%, -50%) scale(1.08); }

.table-token.round { border-radius: 50%; }
.table-token.square { border-radius: 10px; }

.table-token.free { background: #d1fae5; color: #065f46; border: 2px solid #34d399; box-shadow: 0 2px 8px rgba(52,211,153,0.3); }
.table-token.occupied { background: #fee2e2; color: #991b1b; border: 2px solid #f87171; box-shadow: 0 2px 8px rgba(248,113,113,0.3); }
.table-token.reserved { background: #fef3c7; color: #92400e; border: 2px solid #fbbf24; box-shadow: 0 2px 8px rgba(251,191,36,0.3); }

.table-token .t-number { font-size: 13px; font-weight: 700; }
.table-token .t-cap { font-size: 10px; opacity: 0.7; }

.map-legend {
  display: flex;
  gap: 16px;
  padding: 12px 20px;
  border-top: 1px solid var(--border);
  font-size: 12px;
  color: var(--text-muted);
}

.legend-item { display: flex; align-items: center; gap: 6px; }
.legend-dot { width: 12px; height: 12px; border-radius: 50%; }
.legend-dot.free { background: #34d399; }
.legend-dot.occupied { background: #f87171; }
.legend-dot.reserved { background: #fbbf24; }

/* Table Popup */
.table-popup {
  position: fixed;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow-lg);
  z-index: 200;
  min-width: 240px;
  max-width: 300px;
}

.table-popup h3 { font-size: 16px; margin-bottom: 4px; }
.table-popup .popup-sub { font-size: 13px; color: var(--text-muted); margin-bottom: 16px; }
.table-popup .popup-info { font-size: 13px; margin-bottom: 12px; }
.table-popup .popup-info strong { display: block; margin-bottom: 4px; }
.table-popup .popup-actions { display: flex; flex-direction: column; gap: 8px; }
.table-popup .popup-close {
  position: absolute; top: 10px; right: 12px;
  background: none; border: none; font-size: 18px;
  cursor: pointer; color: var(--text-muted);
}

/* ─── EDITOR TAVOLI ─── */
.editor-toolbar {
  display: flex;
  gap: 8px;
  align-items: center;
  padding: 12px 20px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  flex-wrap: wrap;
}

.editor-map-area {
  position: relative;
  width: 100%;
  aspect-ratio: 16/9;
  background: repeating-linear-gradient(
    0deg, transparent, transparent 39px, #e8eaed 39px, #e8eaed 40px
  ),
  repeating-linear-gradient(
    90deg, transparent, transparent 39px, #e8eaed 39px, #e8eaed 40px
  );
  background-color: #f5f5f5;
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.editor-map-area .table-token {
  border: 3px solid;
}

.editor-map-area .table-token.selected {
  outline: 3px solid var(--accent);
  outline-offset: 3px;
}

.editor-map-area .table-token.dragging {
  opacity: 0.7;
  cursor: grabbing;
}

/* ─── MENU VIEW ─── */
.menu-categories { display: flex; gap: 8px; flex-wrap: wrap; }
.menu-category-btn {
  padding: 6px 14px;
  border-radius: 20px;
  border: 1px solid var(--border);
  background: transparent;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s;
  color: var(--text-muted);
}
.menu-category-btn:hover { border-color: var(--accent); color: var(--accent); }
.menu-category-btn.active { background: var(--accent); border-color: var(--accent); color: white; }

.menu-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 12px;
}

.menu-item-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  box-shadow: var(--shadow);
  transition: box-shadow 0.15s;
}
.menu-item-card:hover { box-shadow: var(--shadow-md); }
.menu-item-card.unavailable { opacity: 0.55; }

.menu-item-card .mic-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
}

.menu-item-card .mic-name {
  font-size: 15px;
  font-weight: 600;
  flex: 1;
}

.menu-item-card .mic-price {
  font-size: 15px;
  font-weight: 700;
  color: var(--accent);
  white-space: nowrap;
}

.menu-item-card .mic-cat {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-muted);
}

.menu-item-card .mic-desc {
  font-size: 13px;
  color: var(--text-muted);
  line-height: 1.4;
}

.menu-item-card .mic-actions {
  display: flex;
  gap: 8px;
  margin-top: 4px;
}

/* Toggle switch */
.toggle-switch {
  position: relative;
  display: inline-block;
  width: 40px;
  height: 22px;
}
.toggle-switch input { display: none; }
.toggle-slider {
  position: absolute; inset: 0;
  background: #d1d5db;
  border-radius: 22px;
  cursor: pointer;
  transition: background 0.2s;
}
.toggle-slider:before {
  content: '';
  position: absolute;
  height: 16px; width: 16px;
  left: 3px; bottom: 3px;
  background: white;
  border-radius: 50%;
  transition: transform 0.2s;
}
.toggle-switch input:checked + .toggle-slider { background: var(--success); }
.toggle-switch input:checked + .toggle-slider:before { transform: translateX(18px); }

/* ─── MODALS ─── */
.modal-backdrop {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 500;
  padding: 20px;
}

.modal {
  background: var(--surface);
  border-radius: var(--radius);
  width: 100%;
  max-width: 500px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: var(--shadow-lg);
}

.modal-header {
  padding: 20px 24px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.modal-header h3 { font-size: 17px; font-weight: 600; }

.modal-body { padding: 24px; display: flex; flex-direction: column; gap: 16px; }

.modal-footer {
  padding: 16px 24px;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

.modal-close {
  background: none;
  border: none;
  font-size: 22px;
  cursor: pointer;
  color: var(--text-muted);
  line-height: 1;
}

/* Form */
.form-group { display: flex; flex-direction: column; gap: 6px; }
.form-group label { font-size: 13px; font-weight: 500; color: var(--text-muted); }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

input[type="text"],
input[type="tel"],
input[type="number"],
input[type="date"],
input[type="time"],
select,
textarea {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-family: inherit;
  color: var(--text);
  background: var(--surface);
  outline: none;
  transition: border-color 0.15s;
}

input:focus, select:focus, textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(232,100,58,0.1);
}

textarea { resize: vertical; min-height: 80px; }

/* ─── SCROLLBAR ─── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #d1d5db; border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: #9ca3af; }

/* ─── EMPTY STATES ─── */
.empty-state {
  text-align: center;
  padding: 48px 20px;
  color: var(--text-muted);
}
.empty-state .icon { font-size: 48px; margin-bottom: 12px; }
.empty-state p { font-size: 15px; }

/* ─── TOAST ─── */
#toast-container {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 1000;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.toast {
  padding: 12px 20px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 500;
  color: white;
  box-shadow: var(--shadow-md);
  animation: slideIn 0.25s ease;
}
.toast.success { background: var(--success); }
.toast.error { background: var(--danger); }
.toast.info { background: var(--info); }

@keyframes slideIn {
  from { transform: translateX(100%); opacity: 0; }
  to { transform: translateX(0); opacity: 1; }
}

/* ─── ORDER ITEM ROWS ─── */
.order-item-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  background: #f9fafb;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 14px;
}
.order-item-row .oir-name { flex: 1; font-weight: 500; }
.order-item-row .oir-qty { color: var(--text-muted); font-size: 13px; white-space: nowrap; }
.order-item-row .oir-price { font-weight: 600; color: var(--accent); white-space: nowrap; }
.order-item-row .oir-remove {
  background: none; border: none; cursor: pointer;
  color: var(--text-muted); font-size: 18px; line-height: 1;
  padding: 0 2px;
  transition: color 0.15s;
}
.order-item-row .oir-remove:hover { color: var(--danger); }

/* ─── TABLE ACTION BUTTONS ─── */
.row-actions { display: flex; gap: 4px; }

/* ─── RESPONSIVE ─── */
@media (max-width: 768px) {
  #sidebar { width: 60px; min-width: 60px; }
  #sidebar .logo h1, #sidebar .logo span { display: none; }
  #sidebar nav a span { display: none; }
  #sidebar nav a { justify-content: center; padding: 12px; }
  .view { padding: 16px; }
  .form-row { grid-template-columns: 1fr; }
}
