:root {
  --color-primary: #E8743B;
  --color-primary-dark: #C85820;
  --color-primary-light: #FFF0E5;
  --color-secondary: #2D8B8B;
  --color-bg: #FFF8F0;
  --color-surface: #FFFFFF;
  --color-text: #1A1A1A;
  --color-text-light: #6B6B6B;
  --color-border: #E5DDD5;
  --color-danger: #D93636;
  --color-success: #2DA84F;
  --radius: 14px;
  --radius-sm: 10px;
  --shadow: 0 2px 8px rgba(0,0,0,0.06);
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  background: var(--color-bg);
  color: var(--color-text);
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  padding-bottom: calc(70px + var(--safe-bottom));
}

#app {
  max-width: 480px;
  margin: 0 auto;
  min-height: 100vh;
}

/* HEADER */
.header {
  background: var(--color-primary);
  color: #fff;
  padding: calc(16px + var(--safe-top)) 20px 16px;
  text-align: center;
  position: sticky;
  top: 0;
  z-index: 100;
}

.header h1 {
  font-size: 1.4rem;
  font-weight: 700;
}

.header h1 .emoji {
  font-size: 1.2rem;
}

/* TAB BAR (bottom nav) */
.tabbar {
  position: fixed;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 100%;
  max-width: 480px;
  background: var(--color-surface);
  border-top: 1px solid var(--color-border);
  display: flex;
  justify-content: space-around;
  padding: 8px 0 calc(8px + var(--safe-bottom));
  z-index: 200;
}

.tabbar button {
  flex: 1;
  background: none;
  border: none;
  color: var(--color-text-light);
  font-size: 0.7rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 6px;
  cursor: pointer;
}

.tabbar button.active {
  color: var(--color-primary);
}

.tabbar button .icon {
  font-size: 1.4rem;
  line-height: 1;
}

/* VIEWS */
.view {
  display: none;
  padding: 16px;
  animation: fadeIn 0.2s ease;
}

.view.active {
  display: block;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

/* SECTION */
.section-title {
  font-size: 1.15rem;
  font-weight: 700;
  margin: 24px 0 12px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.section-title:first-child {
  margin-top: 8px;
}

.section-title .badge {
  background: var(--color-primary-light);
  color: var(--color-primary-dark);
  font-size: 0.75rem;
  padding: 2px 10px;
  border-radius: 20px;
}

/* CARDS */
.card {
  background: var(--color-surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
  margin-bottom: 12px;
}

.card-link {
  display: block;
  text-decoration: none;
  color: inherit;
  cursor: pointer;
}

/* ORDER CARD (dashboard) */
.order-card {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.order-card .time {
  font-size: 1.3rem;
  font-weight: 800;
  color: var(--color-primary);
}

.order-card .name {
  font-size: 1.05rem;
  font-weight: 600;
}

.order-card .meta {
  font-size: 0.85rem;
  color: var(--color-text-light);
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}

.order-card .num {
  font-size: 0.75rem;
  color: var(--color-text-light);
  background: var(--color-bg);
  padding: 2px 8px;
  border-radius: 6px;
  align-self: flex-start;
}

/* HOME (2 rubriques) */
.home-hero {
  text-align: center;
  padding: 40px 20px 30px;
}

.home-hero h2 {
  font-size: 1.6rem;
  font-weight: 800;
  margin-bottom: 8px;
}

.home-hero p {
  color: var(--color-text-light);
  font-size: 0.9rem;
}

.home-cards {
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding: 0 20px;
}

.home-card {
  background: var(--color-surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 24px 20px;
  display: flex;
  align-items: center;
  gap: 16px;
  text-decoration: none;
  color: inherit;
  cursor: pointer;
  transition: transform 0.1s;
}

.home-card:active {
  transform: scale(0.98);
}

.home-card .emoji {
  font-size: 2.5rem;
  width: 56px;
  height: 56px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 14px;
  background: var(--color-primary-light);
}

.home-card .info h3 {
  font-size: 1.15rem;
  font-weight: 700;
}

.home-card .info p {
  font-size: 0.8rem;
  color: var(--color-text-light);
}

.home-card .chevron {
  margin-left: auto;
  color: var(--color-border);
  font-size: 1.2rem;
}

/* FORMS */
.form-group {
  margin-bottom: 16px;
}

.form-group label {
  display: block;
  font-size: 0.85rem;
  font-weight: 600;
  margin-bottom: 6px;
  color: var(--color-text);
}

.form-group input,
.form-group select,
.form-group textarea {
  width: 100%;
  padding: 12px 14px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  font-size: 16px;
  font-family: inherit;
  background: var(--color-surface);
  color: var(--color-text);
  transition: border 0.15s;
  -webkit-appearance: none;
  appearance: none;
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
  outline: none;
  border-color: var(--color-primary);
}

.form-group textarea {
  resize: vertical;
  min-height: 60px;
}

.form-group select {
  background-image: url("data:image/svg+xml,%3Csvg width='12' height='8' viewBox='0 0 12 8' fill='none' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M1 1L6 6L11 1' stroke='%236B6B6B' stroke-width='2'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 14px center;
  padding-right: 36px;
}

.form-row {
  display: flex;
  gap: 12px;
}

.form-row > * {
  flex: 1;
}

.segmented {
  display: flex;
  background: var(--color-primary-light);
  border-radius: var(--radius-sm);
  padding: 3px;
  margin-bottom: 16px;
}

.segmented button {
  flex: 1;
  background: none;
  border: none;
  padding: 10px;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--color-text-light);
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.15s;
}

.segmented button.active {
  background: var(--color-surface);
  color: var(--color-primary);
  box-shadow: 0 1px 3px rgba(0,0,0,0.08);
}

/* STEPPER */
.stepper {
  display: flex;
  align-items: center;
  gap: 12px;
}

.stepper button {
  width: 36px;
  height: 36px;
  border: none;
  border-radius: 50%;
  font-size: 1.2rem;
  font-weight: 700;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.stepper .minus {
  background: var(--color-primary-light);
  color: var(--color-primary-dark);
}

.stepper .plus {
  background: var(--color-primary);
  color: #fff;
}

.stepper .count {
  font-size: 1.1rem;
  font-weight: 700;
  min-width: 30px;
  text-align: center;
}

/* ITEMS (repas) */
.item-list {
  margin-bottom: 12px;
}

.item-row {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--color-bg);
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  margin-bottom: 8px;
}

.item-row .item-name {
  flex: 1;
  font-weight: 600;
}

.item-row .item-price {
  font-size: 0.85rem;
  color: var(--color-text-light);
}

.item-row .item-qty {
  font-weight: 700;
  color: var(--color-primary);
}

.item-row .item-total {
  font-weight: 600;
  min-width: 60px;
  text-align: right;
}

.item-row button.delete-item {
  background: none;
  border: none;
  color: var(--color-danger);
  font-size: 1.2rem;
  cursor: pointer;
  padding: 4px 8px;
}

.item-add {
  background: var(--color-primary-light);
  border: 1px dashed var(--color-primary);
  border-radius: var(--radius-sm);
  padding: 14px;
  margin-bottom: 16px;
}

.item-add input {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--color-border);
  border-radius: 8px;
  font-size: 16px;
  margin-bottom: 8px;
}

.item-add .item-add-row {
  display: flex;
  gap: 8px;
  align-items: center;
}

.item-add .item-add-row input {
  flex: 1;
  margin-bottom: 0;
}

.item-add .item-add-row .stepper {
  margin: 0;
}

.item-add button.add-btn {
  width: 100%;
  background: var(--color-primary);
  color: #fff;
  border: none;
  padding: 12px;
  border-radius: 8px;
  font-weight: 600;
  font-size: 0.9rem;
  margin-top: 8px;
  cursor: pointer;
}

/* TOTAL */
.total-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 20px;
  background: var(--color-primary);
  color: #fff;
  border-radius: var(--radius);
  margin: 16px 0;
}

.total-bar .label {
  font-weight: 600;
}

.total-bar .amount {
  font-size: 1.3rem;
  font-weight: 800;
}

/* BUTTONS */
.btn-primary {
  width: 100%;
  background: var(--color-primary);
  color: #fff;
  border: none;
  padding: 16px;
  border-radius: var(--radius-sm);
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
  transition: opacity 0.15s;
}

.btn-primary:active {
  opacity: 0.85;
}

.btn-primary:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.btn-secondary {
  width: 100%;
  background: var(--color-surface);
  color: var(--color-text);
  border: 1px solid var(--color-border);
  padding: 14px;
  border-radius: var(--radius-sm);
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
}

.btn-danger {
  width: 100%;
  background: transparent;
  color: var(--color-danger);
  border: 1px solid var(--color-danger);
  padding: 14px;
  border-radius: var(--radius-sm);
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
}

/* SEARCH */
.search-bar {
  padding: 12px 16px;
  background: var(--color-surface);
  position: sticky;
  top: 0;
  z-index: 50;
  border-bottom: 1px solid var(--color-border);
}

.search-bar input {
  width: 100%;
  padding: 10px 14px 10px 38px;
  border: 1px solid var(--color-border);
  border-radius: 20px;
  font-size: 0.95rem;
  background: var(--color-bg) url("data:image/svg+xml,%3Csvg width='16' height='16' viewBox='0 0 16 16' fill='none' xmlns='http://www.w3.org/2000/svg'%3E%3Ccircle cx='7' cy='7' r='5' stroke='%236B6B6B' stroke-width='2'/%3E%3Cpath d='M11 11L15 15' stroke='%236B6B6B' stroke-width='2'/%3E%3C/svg%3E") no-repeat 12px center;
}

/* EMPTY STATE */
.empty {
  text-align: center;
  padding: 60px 20px;
  color: var(--color-text-light);
}

.empty .emoji {
  font-size: 3rem;
  margin-bottom: 12px;
}

.empty p {
  font-size: 0.9rem;
}

/* LOADING */
.loading {
  text-align: center;
  padding: 40px;
  color: var(--color-text-light);
}

.spinner {
  width: 32px;
  height: 32px;
  border: 3px solid var(--color-border);
  border-top-color: var(--color-primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin: 0 auto 12px;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* DETAIL */
.detail-header {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 20px;
}

.detail-header .icon {
  font-size: 2rem;
}

.detail-header .title {
  font-size: 1.3rem;
  font-weight: 800;
}

.detail-header .num {
  font-size: 0.85rem;
  color: var(--color-text-light);
}

.detail-info {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.detail-info .row {
  display: flex;
  justify-content: space-between;
  font-size: 0.9rem;
}

.detail-info .row .label {
  color: var(--color-text-light);
}

.detail-info .row .value {
  font-weight: 600;
  text-align: right;
}

.detail-section-title {
  font-size: 1rem;
  font-weight: 700;
  margin: 20px 0 10px;
}

/* TOAST */
.toast {
  position: fixed;
  bottom: calc(80px + var(--safe-bottom));
  left: 50%;
  transform: translateX(-50%);
  background: var(--color-text);
  color: #fff;
  padding: 12px 24px;
  border-radius: 20px;
  font-size: 0.85rem;
  font-weight: 500;
  z-index: 999;
  animation: toastIn 0.3s ease, toastOut 0.3s ease 2.5s forwards;
}

@keyframes toastIn {
  from { opacity: 0; transform: translateX(-50%) translateY(10px); }
  to { opacity: 1; transform: translateX(-50%) translateY(0); }
}

@keyframes toastOut {
  to { opacity: 0; transform: translateX(-50%) translateY(10px); }
}

/* BACK */
.back-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  background: var(--color-surface);
  position: sticky;
  top: 0;
  z-index: 50;
  border-bottom: 1px solid var(--color-border);
}

.back-bar button {
  background: none;
  border: none;
  font-size: 1.5rem;
  cursor: pointer;
  color: var(--color-primary);
  padding: 4px 8px;
}

.back-bar .title {
  font-size: 1rem;
  font-weight: 700;
}

/* FILTER CHIP */
.filter-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--color-primary-light);
  color: var(--color-primary-dark);
  padding: 6px 14px;
  border-radius: 20px;
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  border: none;
}

/* STATUS BADGE */
.status-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 10px;
  border-radius: 20px;
  font-size: 0.75rem;
  font-weight: 600;
}

.status-btn:active {
  opacity: 0.85;
}

/* RESPONSIVE */
@media (min-width: 481px) {
  body {
    background: #f0f0f0;
  }
  #app {
    background: var(--color-bg);
    box-shadow: 0 0 20px rgba(0,0,0,0.08);
  }
}

/* INTERNAL APP V2 */
[hidden] {
  display: none !important;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.header {
  display: flex;
  align-items: center;
  gap: 12px;
  text-align: left;
}

.header-copy {
  min-width: 0;
  flex: 1;
}

.header-copy p {
  font-size: 0.72rem;
  opacity: 0.9;
}

.header-action {
  border: 1px solid rgba(255, 255, 255, 0.6);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
  padding: 7px 11px;
  font: inherit;
  font-size: 0.75rem;
  font-weight: 700;
  cursor: pointer;
}

.home-card {
  width: 100%;
  border: 0;
  font: inherit;
  text-align: left;
}

.home-card .info {
  display: flex;
  flex: 1;
  flex-direction: column;
}

.home-card .info strong {
  font-size: 1.1rem;
}

.home-card .info small {
  color: var(--color-text-light);
  font-size: 0.78rem;
}

.field-help {
  margin-top: 5px;
  color: var(--color-text-light);
  font-size: 0.75rem;
}

.form-spaced {
  margin-top: 16px;
}

.order-card-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.status-btn {
  width: 100%;
  margin-top: 6px;
  border: 0;
  border-radius: 9px;
  background: var(--color-secondary);
  color: #fff;
  padding: 10px 14px;
  font-size: 0.82rem;
  font-weight: 700;
  cursor: pointer;
}

.status-badge {
  background: #f2f2f2;
  background: color-mix(in srgb, var(--status-color) 12%, white);
  color: var(--status-color);
}

.status-badge-large {
  align-self: flex-start;
  padding: 7px 13px;
  font-size: 0.9rem;
}

.detail-summary .detail-header {
  margin-bottom: 0;
}

.detail-summary .total-bar {
  margin-bottom: 0;
}

.archive-badge {
  margin-left: auto;
  border-radius: 999px;
  background: var(--color-bg);
  color: var(--color-text-light);
  padding: 4px 8px;
  font-size: 0.72rem;
  font-weight: 700;
}

.note-card {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.empty-inline {
  padding: 18px;
  text-align: center;
  color: var(--color-text-light);
}

.status-panel {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.status-actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.status-actions > :only-child {
  grid-column: 1 / -1;
}

.status-change {
  display: flex;
  min-height: 64px;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  padding: 10px;
}

.status-change span {
  font-size: 0.72rem;
  font-weight: 500;
}

.status-change strong {
  font-size: 0.86rem;
}

.btn-compact {
  padding: 10px 14px;
  font-size: 0.82rem;
}

.detail-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 20px;
}

.history-view {
  padding-top: 12px;
}

.history-filters {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 14px;
}

.history-filters .search-bar {
  position: static;
  padding: 0;
  border: 0;
  background: transparent;
}

.date-filter {
  display: flex;
  gap: 8px;
}

.date-filter input {
  flex: 1;
  min-width: 0;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  background: var(--color-surface);
  padding: 10px 12px;
  font: inherit;
}

.date-filter button {
  border: 0;
  border-radius: var(--radius-sm);
  background: var(--color-primary-light);
  color: var(--color-primary-dark);
  padding: 0 12px;
  font-weight: 700;
  cursor: pointer;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  margin-bottom: 18px;
}

.stat-card {
  display: flex;
  min-width: 0;
  flex-direction: column;
  align-items: center;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  background: var(--color-surface);
  padding: 10px 4px;
  text-align: center;
}

.stat-card strong {
  color: var(--color-primary-dark);
  font-size: 1.25rem;
}

.stat-card span {
  color: var(--color-text-light);
  font-size: 0.67rem;
}

/* LOGIN */
.login-body {
  min-height: 100vh;
  padding: 0;
  background:
    radial-gradient(circle at top left, rgba(232, 116, 59, 0.2), transparent 45%),
    linear-gradient(160deg, #fff8f0, #f4e9db);
}

.login-shell {
  display: grid;
  min-height: 100vh;
  place-items: center;
  padding: 24px;
}

.login-card {
  width: min(100%, 390px);
  border: 1px solid rgba(200, 88, 32, 0.16);
  border-radius: 22px;
  background: rgba(255, 255, 255, 0.94);
  box-shadow: 0 20px 55px rgba(73, 44, 25, 0.14);
  padding: 30px 24px;
}

.login-logo {
  display: flex;
  width: min(100%, 270px);
  min-height: 76px;
  align-items: center;
  justify-content: center;
  margin: 0 auto 20px;
  padding: 16px 22px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 18px;
  background: #181818;
  box-shadow: 0 12px 28px rgba(24, 24, 24, 0.2);
}

.login-logo img {
  display: block;
  width: 100%;
  height: auto;
}

.login-card h1 {
  margin-top: 0;
  font-size: 1.55rem;
  text-align: center;
}

.login-intro {
  margin: 8px 0 24px;
  color: var(--color-text-light);
  font-size: 0.9rem;
  text-align: center;
}

.login-card label {
  display: block;
  margin-bottom: 6px;
  font-size: 0.85rem;
  font-weight: 700;
}

.login-card input {
  width: 100%;
  margin-bottom: 8px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  padding: 13px 14px;
  font: inherit;
  font-size: 1.1rem;
  letter-spacing: 0.12em;
}

.login-card input:focus {
  outline: 2px solid rgba(232, 116, 59, 0.25);
  border-color: var(--color-primary);
}

.form-error {
  min-height: 24px;
  color: var(--color-danger);
  font-size: 0.8rem;
}

/* CARTOGRAPHIE */
.delivery-map {
  width: 100%;
  height: 260px;
  margin-top: 12px;
  border: 2px solid var(--color-border);
  border-radius: var(--radius);
  overflow: hidden;
  background: #e8eee8;
  z-index: 1;
}

.detail-map {
  height: 220px;
  margin-top: 0;
}

.map-help,
.map-error {
  margin: 8px 2px 0;
  font-size: 13px;
}

.map-help {
  color: var(--color-text-light);
}

.map-error {
  min-height: 18px;
  color: var(--color-danger);
  font-weight: 700;
}

.navigation-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 14px;
}

.navigation-actions a {
  display: flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
}


.location-detail {
  padding: 12px;
}

.location-unavailable {
  color: var(--color-text-light);
  text-align: center;
  font-weight: 700;
}

.leaflet-container {
  font-family: inherit;
}

.leaflet-control-attribution {
  font-size: 10px;
}

@media (max-width: 360px) {
  .status-actions {
    grid-template-columns: 1fr;
  }

  .stats-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

}