:root {
  --bg: #f4f1eb;
  --surface: #ffffff;
  --surface-2: #eee8de;
  --ink: #211d18;
  --muted: #6f685f;
  --primary: #b94f2a;
  --primary-dark: #8e371c;
  --success: #24734d;
  --warning: #c98715;
  --danger: #b83232;
  --border: #d9d0c4;
  --shadow: 0 12px 30px rgba(42, 30, 18, 0.1);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--ink);
  background: var(--bg);
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; background: var(--bg); }
body { min-height: 100dvh; }
button, input, select, textarea { font: inherit; }
button { cursor: pointer; }
button:disabled { cursor: wait; opacity: .6; }

.app-header {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 16px;
  background: rgba(255, 255, 255, .95);
  border-bottom: 1px solid var(--border);
  backdrop-filter: blur(12px);
}
.header-title { display: flex; align-items: center; gap: 10px; min-width: 0; }
.header-title h1 { margin: 0; font-size: clamp(1.05rem, 3vw, 1.45rem); white-space: nowrap; }
.brand-mark {
  width: 42px;
  height: 42px;
  border-radius: 13px;
  display: grid;
  place-items: center;
  background: var(--primary);
  color: white;
  font-weight: 900;
  letter-spacing: -.04em;
  flex: 0 0 auto;
}
.header-actions { display: flex; align-items: center; gap: 8px; }

.connection {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 10px;
  border-radius: 999px;
  font-size: .82rem;
  font-weight: 800;
  white-space: nowrap;
}
.connection::before { content: ''; width: 8px; height: 8px; border-radius: 50%; background: currentColor; }
.connection.online { color: var(--success); background: #e7f4ed; }
.connection.offline { color: var(--danger); background: #fdeaea; }

.icon-button, .ghost, .primary, .danger, .success, .warning {
  border: 0;
  border-radius: 12px;
  padding: 10px 14px;
  font-weight: 800;
}
.icon-button, .ghost { background: var(--surface-2); color: var(--ink); }
.primary { background: var(--primary); color: white; }
.primary:hover { background: var(--primary-dark); }
.success { background: var(--success); color: white; }
.warning { background: var(--warning); color: white; }
.danger { background: var(--danger); color: white; }
.wide { width: 100%; }

.page { padding: 16px; max-width: 1600px; margin: 0 auto; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: 18px; box-shadow: var(--shadow); }
.muted { color: var(--muted); }
.hidden { display: none !important; }

.login-dialog {
  border: 0;
  border-radius: 22px;
  padding: 0;
  width: min(92vw, 420px);
  box-shadow: 0 30px 80px rgba(0,0,0,.25);
}
.login-dialog::backdrop { background: rgba(20, 14, 10, .65); backdrop-filter: blur(4px); }
.login-card { padding: 28px; display: grid; gap: 16px; }
.login-card h1 { margin: 0; }
.login-card p { margin: 0; color: var(--muted); }
.login-card label { display: grid; gap: 7px; font-weight: 800; }
.login-card input { font-size: 1.5rem; text-align: center; letter-spacing: .18em; }
.form-error { color: var(--danger) !important; min-height: 1.3em; font-weight: 700; }

input, select, textarea {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 11px 12px;
  background: white;
  color: var(--ink);
}
input:focus, select:focus, textarea:focus { outline: 3px solid rgba(185, 79, 42, .18); border-color: var(--primary); }
textarea { min-height: 72px; resize: vertical; }
label { color: var(--ink); }

.toast-host { position: fixed; z-index: 100; right: 14px; bottom: 14px; display: grid; gap: 8px; max-width: min(90vw, 420px); }
.toast { padding: 13px 16px; border-radius: 13px; background: #211d18; color: white; box-shadow: var(--shadow); font-weight: 750; }
.toast.success { background: var(--success); }
.toast.error { background: var(--danger); }

/* Navigation du terminal de commande */
.terminal-tabs {
  position: sticky;
  top: 67px;
  z-index: 15;
  display: flex;
  gap: 8px;
  padding: 10px 16px;
  background: rgba(244, 241, 235, .96);
  border-bottom: 1px solid var(--border);
  backdrop-filter: blur(10px);
}
.terminal-tab {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 10px 16px;
  background: white;
  color: var(--ink);
  font-weight: 900;
}
.terminal-tab.active { background: var(--ink); color: white; border-color: var(--ink); }
.tab-count {
  min-width: 24px;
  height: 24px;
  display: inline-grid;
  place-items: center;
  padding: 0 7px;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--ink);
  font-size: .82rem;
}
.terminal-tab.active .tab-count { background: rgba(255,255,255,.2); color: white; }
.tab-count.has-orders { background: var(--success); color: white; }
.terminal-tab.attention { animation: ready-pulse 1.1s ease-in-out infinite alternate; border-color: var(--success); }
@keyframes ready-pulse {
  from { box-shadow: 0 0 0 0 rgba(36,115,77,.08); }
  to { box-shadow: 0 0 0 7px rgba(36,115,77,.18); }
}
.pickup-toolbar { margin-bottom: 14px; }
.pickup-toolbar h2 { margin: 0 0 5px; }
.pickup-toolbar p { margin: 0; }
.pickup-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 14px; align-items: start; }
.pickup-order { min-width: 0; }
.order-actions.single-action { grid-template-columns: 1fr; }
.ready-empty { grid-column: 1 / -1; padding: 42px 20px; text-align: center; display: grid; gap: 8px; color: var(--muted); }
.ready-empty strong { color: var(--ink); font-size: 1.15rem; }

/* Terminal commande */
.order-layout { display: grid; grid-template-columns: minmax(0, 1fr) 390px; gap: 16px; align-items: start; }
.catalog { min-width: 0; }
.category-tabs { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 10px; scrollbar-width: thin; }
.category-tab { border: 1px solid var(--border); background: white; color: var(--ink); border-radius: 999px; padding: 10px 15px; font-weight: 850; white-space: nowrap; }
.category-tab.active { background: var(--ink); color: white; border-color: var(--ink); }
.product-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 12px; }
.product-button { min-height: 118px; padding: 15px; border-radius: 16px; border: 1px solid var(--border); background: white; text-align: left; display: flex; flex-direction: column; justify-content: space-between; gap: 12px; box-shadow: 0 6px 18px rgba(42,30,18,.05); }
.product-button:hover, .product-button:active { border-color: var(--primary); transform: translateY(-1px); }
.product-name { font-size: 1.05rem; font-weight: 900; }
.product-price { color: var(--primary); font-size: 1.05rem; font-weight: 900; }
.product-option-badge { align-self: flex-start; padding: 4px 8px; border-radius: 999px; background: #fff0e8; color: var(--primary); font-size: .75rem; font-weight: 900; }
.cart { position: sticky; top: 80px; overflow: hidden; }
.cart-head { padding: 16px; border-bottom: 1px solid var(--border); display: flex; justify-content: space-between; align-items: center; }
.cart-head h2 { margin: 0; font-size: 1.2rem; }
.cart-items { padding: 10px 14px; display: grid; gap: 10px; max-height: calc(100dvh - 390px); overflow-y: auto; }
.cart-empty { padding: 32px 14px; text-align: center; color: var(--muted); }
.cart-line { border: 1px solid var(--border); border-radius: 14px; padding: 11px; display: grid; gap: 9px; }
.cart-line-top { display: flex; justify-content: space-between; gap: 10px; align-items: start; }
.cart-line-name { font-weight: 900; }
.qty-controls { display: inline-flex; align-items: center; gap: 8px; }
.qty-controls button { width: 34px; height: 34px; padding: 0; border-radius: 10px; border: 0; background: var(--surface-2); font-size: 1.2rem; font-weight: 900; }
.qty { min-width: 22px; text-align: center; font-weight: 900; }
.item-note { font-size: .9rem; }
.item-option-label { display: grid; gap: 5px; font-size: .86rem; font-weight: 850; color: var(--muted); }
.sauce-select { font-weight: 800; color: var(--ink); }
.cart-footer { padding: 14px; border-top: 1px solid var(--border); display: grid; gap: 11px; background: #fff; }
.total-row { display: flex; justify-content: space-between; font-size: 1.25rem; font-weight: 950; }
.queue-note { padding: 9px 11px; border-radius: 12px; background: #fff5dd; color: #7b5409; font-size: .86rem; font-weight: 750; }

/* Cuisine */
.kitchen-toolbar { display: flex; gap: 10px; align-items: center; justify-content: space-between; margin-bottom: 14px; flex-wrap: wrap; }
.kitchen-board { display: grid; grid-template-columns: repeat(2, minmax(280px, 1fr)); gap: 14px; align-items: start; }
.kitchen-column { min-height: 65dvh; background: rgba(255,255,255,.48); border: 1px solid var(--border); border-radius: 18px; padding: 12px; }
.column-title { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; }
.column-title h2 { margin: 0; font-size: 1.1rem; }
.count-badge { min-width: 28px; height: 28px; display: grid; place-items: center; padding: 0 8px; border-radius: 999px; background: var(--ink); color: white; font-weight: 900; }
.order-stack { display: grid; gap: 11px; }
.kitchen-order { background: white; border: 2px solid transparent; border-radius: 16px; overflow: hidden; box-shadow: 0 8px 22px rgba(42,30,18,.08); }
.kitchen-order.new { border-color: var(--danger); }
.kitchen-order.preparing { border-color: var(--warning); }
.kitchen-order.ready { border-color: var(--success); }
.order-card-head { padding: 12px 13px; display: flex; justify-content: space-between; align-items: center; background: var(--surface-2); }
.order-number { font-size: 1.4rem; font-weight: 950; }
.order-age { font-weight: 900; color: var(--muted); }
.order-card-body { padding: 12px 13px; display: grid; gap: 8px; }
.order-item { display: grid; grid-template-columns: auto 1fr; gap: 9px; font-size: 1.02rem; }
.order-item strong { font-size: 1.1rem; }
.order-item-option { color: #7b5409; font-weight: 950; padding: 5px 8px; margin: 3px 0 0 29px; background: #fff5dd; border-radius: 8px; }
.order-item-note, .order-note { color: var(--danger); font-weight: 850; padding-left: 29px; }
.order-note { padding: 9px 10px; background: #fff0f0; border-radius: 10px; }
.order-actions { padding: 10px 12px 13px; display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.order-actions .wide-action { grid-column: 1 / -1; }
.empty-column { color: var(--muted); text-align: center; padding: 28px 10px; }

/* Administration */
.admin-grid { display: grid; grid-template-columns: 1fr 1.4fr; gap: 16px; align-items: start; }
.admin-section { padding: 18px; }
.admin-section h2 { margin-top: 0; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.form-grid .full { grid-column: 1 / -1; }
.data-list { display: grid; gap: 9px; margin-top: 14px; }
.data-row { display: grid; grid-template-columns: 1fr auto; align-items: center; gap: 10px; padding: 11px; border: 1px solid var(--border); border-radius: 13px; }
.data-row.inactive { opacity: .55; }
.data-main { min-width: 0; }
.data-main strong { display: block; }
.data-meta { color: var(--muted); font-size: .88rem; }
.field-help { display: block; color: var(--muted); font-size: .8rem; line-height: 1.35; margin-top: 5px; }
.row-actions { display: flex; gap: 6px; }
.row-actions button { padding: 8px 10px; }

@media (max-width: 900px) {
  .order-layout { grid-template-columns: 1fr; }
  .cart { position: static; }
  .cart-items { max-height: none; }
  .kitchen-board { grid-template-columns: 1fr; }
  .kitchen-column { min-height: auto; }
  .admin-grid { grid-template-columns: 1fr; }
}

@media (max-width: 560px) {
  .app-header { padding: 10px; }
  .terminal-tabs { top: 63px; padding: 8px 10px; }
  .terminal-tab { flex: 1; padding: 9px 10px; font-size: .9rem; }
  .page { padding: 10px; }
  .connection { padding: 7px 8px; }
  .connection span { display: none; }
  .product-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 9px; }
  .product-button { min-height: 105px; padding: 12px; }
  .form-grid { grid-template-columns: 1fr; }
  .form-grid .full { grid-column: auto; }
}

/* Historique des commandes dans l’administration */
.admin-tabs { top: 67px; }
.order-history-section { padding: 18px; }
.history-heading { display: flex; justify-content: space-between; gap: 16px; align-items: start; flex-wrap: wrap; }
.history-heading h2 { margin: 0 0 5px; }
.history-heading p { margin: 0; }
.history-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.history-summary { display: grid; grid-template-columns: repeat(6, minmax(130px, 1fr)); gap: 10px; margin: 18px 0; }
.summary-card { padding: 14px; border: 1px solid var(--border); border-radius: 14px; background: var(--surface-2); display: grid; gap: 4px; }
.summary-card span { color: var(--muted); font-size: .82rem; font-weight: 800; }
.summary-card strong { font-size: 1.35rem; }
.summary-card.next-number { background: #e8f5ed; border-color: rgba(36,115,77,.3); }
.history-filters { display: grid; grid-template-columns: minmax(220px, 1fr) minmax(180px, 260px); gap: 10px; margin-bottom: 14px; }
.history-filters label { display: grid; gap: 6px; font-weight: 850; }
.order-history { display: grid; gap: 9px; }
.history-order { border: 1px solid var(--border); border-radius: 14px; background: white; overflow: hidden; }
.history-order summary { list-style: none; cursor: pointer; display: grid; grid-template-columns: auto auto minmax(0, 1fr) auto auto; align-items: center; gap: 10px; padding: 13px; }
.history-order summary::-webkit-details-marker { display: none; }
.history-order summary::after { content: '▾'; color: var(--muted); font-weight: 900; margin-left: 2px; }
.history-order[open] summary::after { transform: rotate(180deg); }
.history-number { font-size: 1.08rem; font-weight: 950; }
.history-date { color: var(--muted); font-size: .9rem; }
.history-total { text-align: right; }
.status-badge { display: inline-flex; align-items: center; border-radius: 999px; padding: 5px 9px; font-size: .75rem; font-weight: 900; white-space: nowrap; }
.status-preparing, .status-new { background: #fff1cc; color: #765100; }
.status-ready { background: #e0f3e7; color: #175c3a; }
.status-completed { background: #e9edf2; color: #394654; }
.status-cancelled { background: #ffe5e5; color: #8d2828; }
.history-order-body { border-top: 1px solid var(--border); padding: 12px 14px 14px; background: #fffcf8; }
.history-order-body ul { list-style: none; padding: 0; margin: 0; display: grid; gap: 8px; }
.history-order-body li { padding: 9px 10px; border-radius: 10px; background: white; border: 1px solid var(--border); }
.history-order-body li > div { display: flex; justify-content: space-between; gap: 12px; }
.history-order-body small { display: block; margin-top: 4px; color: #7b5409; font-weight: 800; }
.history-meta { margin-top: 10px; color: var(--muted); font-size: .8rem; }
.history-empty { padding: 38px 18px; text-align: center; color: var(--muted); border: 1px dashed var(--border); border-radius: 14px; }

@media (max-width: 1100px) {
  .history-summary { grid-template-columns: repeat(3, 1fr); }
}

@media (max-width: 650px) {
  .admin-tabs { top: 63px; }
  .history-summary { grid-template-columns: repeat(2, 1fr); }
  .history-filters { grid-template-columns: 1fr; }
  .history-actions { width: 100%; }
  .history-actions button { flex: 1; }
  .history-order summary { grid-template-columns: auto minmax(0, 1fr) auto auto; }
  .history-order summary .status-badge { grid-row: 2; grid-column: 1 / 3; justify-self: start; }
  .history-order summary .history-date { grid-column: 2; grid-row: 1; }
  .history-total { grid-column: 3; grid-row: 1; }
  .history-order summary::after { grid-column: 4; grid-row: 1; }
}

/* Version 0.6 : configuration des menus déroulants */
.option-config-section {
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 14px;
  margin: 0;
}
.option-config-section legend { padding: 0 7px; font-weight: 900; }
.option-config-section > .field-help { display: block; margin: 0 0 12px; }
.option-config-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; }
.option-config-card { display: grid; align-content: start; gap: 9px; padding: 12px; background: #faf8f3; border: 1px solid var(--border); border-radius: 12px; }
.option-config-card > strong { font-size: .95rem; }
.option-config-card textarea { min-height: 120px; }
.row-actions .danger { padding: 8px 10px; }

@media (max-width: 900px) {
  .option-config-grid { grid-template-columns: 1fr; }
  .option-config-card textarea { min-height: 95px; }
}
.product-option-select { font-weight: 800; color: var(--ink); }
@media (max-width: 560px) {
  .data-row { grid-template-columns: 1fr; align-items: stretch; }
  .row-actions { flex-wrap: wrap; }
  .row-actions button { flex: 1; }
}
