/* Bistro Thai — commandes fournisseur. Mobile d'abord, fond clair, accents vert foncé. */

:root {
  --bg: #f6f5ef;
  --surface: #ffffff;
  --surface-2: #f0efe6;
  --text: #1c2420;
  --muted: #56615a;
  --border: #d9d8cc;
  --green: #1e4d2f;
  --green-2: #2c6a42;
  --green-soft: #e3efe6;
  --green-line: #9cc4a8;
  --danger: #a3261b;
  --danger-soft: #fbe9e6;
  --warn: #7a5200;
  --warn-soft: #fff3d6;
  --focus: #1f6feb;
  --radius: 12px;
  --tap: 48px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", "Noto Sans Thai", "Thonburi", "Leelawadee UI",
    "PingFang SC", "Hiragino Sans GB", "Noto Sans SC", "Microsoft YaHei", sans-serif;
  color-scheme: light;
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; scroll-padding-top: 120px; scroll-padding-bottom: 140px; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.45;
  overflow-x: hidden;
}
:lang(th) { line-height: 1.6; }
[hidden] { display: none !important; }
h1, h2, h3, h4 { line-height: 1.25; margin: 0; }
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
.sr-only {
  position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}
.skip { position: absolute; left: -9999px; top: 0; }
.skip:focus { left: 8px; top: 8px; z-index: 100; background: var(--surface); padding: 8px 12px; border-radius: 8px; }

/* ---------------------------------------------------------------- boutons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: var(--tap); padding: 10px 18px; border-radius: 10px;
  border: 1px solid transparent; font-weight: 600; cursor: pointer; text-decoration: none;
  touch-action: manipulation; text-align: center;
}
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn-primary { background: var(--green); color: #fff; }
.btn-primary:not(:disabled):hover { background: var(--green-2); }
.btn-secondary { background: var(--surface); color: var(--green); border-color: var(--green-line); }
.btn-secondary:not(:disabled):hover { background: var(--green-soft); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger-outline { background: var(--surface); color: var(--danger); border-color: #e2b4ae; }
.btn-block { width: 100%; }
.btn-lg { min-height: 56px; font-size: 1.05rem; }
.btn-sm { min-height: 40px; padding: 6px 12px; font-size: .92rem; }
.btn-link {
  background: none; border: 0; color: var(--green); padding: 8px 4px; min-height: 44px;
  font-weight: 600; cursor: pointer; display: inline-flex; align-items: center; gap: 6px;
}
.btn-link svg { fill: currentColor; }
.btn-icon {
  background: none; border: 0; width: 40px; height: 40px; border-radius: 8px;
  font-size: 1.4rem; line-height: 1; cursor: pointer; color: inherit;
}

/* ---------------------------------------------------------------- connexion */
.login { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; }
.login-card {
  width: 100%; max-width: 420px; background: var(--surface); border: 1px solid var(--border);
  border-radius: 16px; padding: 28px 22px; text-align: center; box-shadow: 0 6px 24px rgba(30, 77, 47, .08);
}
.login-card h1 { color: var(--green); font-size: 1.6rem; margin-top: 8px; }
.login-sub { color: var(--muted); margin: 6px 0 22px; }
.login-card form { display: grid; gap: 12px; text-align: left; }
.login-card label { font-weight: 600; line-height: 1.5; }
.login-card input {
  min-height: 52px; border: 1px solid var(--border); border-radius: 10px; padding: 10px 14px;
  font-size: 1.2rem; background: #fff;
}
.form-error { color: var(--danger); background: var(--danger-soft); padding: 10px 12px; border-radius: 8px; margin: 0; }

/* ---------------------------------------------------------------- en-tête et onglets */
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 10px 16px; padding-top: max(10px, env(safe-area-inset-top));
  background: var(--green); color: #fff;
}
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand img { border-radius: 8px; background: #fff; flex: none; }
.brand strong { display: block; font-size: 1.05rem; }
.brand-sub { display: block; font-size: .8rem; opacity: .85; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sync { display: flex; align-items: center; gap: 6px; font-size: .8rem; text-align: right; min-width: 0; }
.sync .dot { width: 10px; height: 10px; border-radius: 50%; background: #9be3b0; flex: none; box-shadow: 0 0 0 2px rgba(255,255,255,.25); }
.sync[data-status="syncing"] .dot { background: #ffe08a; }
.sync[data-status="offline"] .dot, .sync[data-status="error"] .dot { background: #ff8a7a; }
.sync[data-status="offline"], .sync[data-status="error"] { font-weight: 700; }

.tabs {
  position: sticky; top: 0; z-index: 20;
  display: grid; grid-template-columns: 1fr 1fr 1fr 1.55fr; gap: 4px;
  padding: 6px 8px; background: var(--surface); border-bottom: 1px solid var(--border);
  box-shadow: 0 2px 6px rgba(0,0,0,.04);
}
.tabs [role="tab"] {
  position: relative;
  min-height: 52px; padding: 6px 4px; border: 1px solid transparent; border-radius: 10px;
  background: transparent; color: var(--muted); font-weight: 600; font-size: .95rem; cursor: pointer;
  display: flex; align-items: center; justify-content: center; gap: 6px; text-align: center; line-height: 1.2;
  touch-action: manipulation; min-width: 0;
}
.tabs [role="tab"][aria-selected="true"] { background: var(--green); color: #fff; }
.tabs [role="tab"]:not([aria-selected="true"]):hover { background: var(--green-soft); color: var(--green); }
.tab-order-label { min-width: 0; display: flex; flex-wrap: wrap; justify-content: center; column-gap: 4px; }
.nowrap { white-space: nowrap; }
.badge {
  display: inline-grid; place-items: center; min-width: 26px; height: 26px; padding: 0 7px; border-radius: 13px;
  background: var(--green-soft); color: var(--green); font-size: .85rem; font-weight: 700; flex: none;
  border: 2px solid var(--surface);
}
#tab-order { padding-right: 18px; }
#tab-order .badge { position: absolute; top: -4px; right: -4px; min-width: 24px; height: 24px; font-size: .8rem; }
[aria-selected="true"] .badge { background: #fff; color: var(--green); border-color: var(--green); }
.badge[data-zero="1"] { opacity: .7; }

main { max-width: 860px; margin: 0 auto; padding: 0 0 24px; }

/* ---------------------------------------------------------------- saisie */
.searchbar { padding: 12px 16px 4px; }
.search-wrap { position: relative; }
.search-icon { position: absolute; left: 12px; top: 50%; width: 20px; height: 20px; transform: translateY(-50%); fill: var(--muted); pointer-events: none; }
#search {
  width: 100%; min-height: 50px; padding: 10px 48px 10px 42px; border-radius: 12px;
  border: 1px solid var(--border); background: var(--surface); font-size: 1rem;
  -webkit-appearance: none; appearance: none;
}
.search-clear {
  position: absolute; right: 4px; top: 50%; transform: translateY(-50%);
  width: 42px; height: 42px; border: 0; background: none; font-size: 1.5rem; color: var(--muted); cursor: pointer;
}
.notice-area { padding: 0 16px; }
.notice {
  display: flex; gap: 10px; align-items: flex-start; justify-content: space-between;
  padding: 12px 14px; border-radius: 10px; margin: 10px 0; border: 1px solid transparent;
}
.notice p { margin: 0; }
.notice-info { background: var(--green-soft); border-color: var(--green-line); }
.notice-success { background: var(--green-soft); border-color: var(--green-line); color: var(--green); }
.notice-warn { background: var(--warn-soft); border-color: #ecd08c; color: #4d3500; }
.notice-error { background: var(--danger-soft); border-color: #eab9b2; color: #6e1a12; }
.notice-actions { display: flex; align-items: center; gap: 4px; flex-wrap: wrap; justify-content: flex-end; }

.category { margin-top: 18px; }
.category-title {
  font-size: 1.05rem; color: var(--green); padding: 8px 16px; display: flex; flex-wrap: wrap; gap: 4px 10px; align-items: baseline;
}
.category-zh { font-size: .85rem; color: var(--muted); font-weight: 500; }
.products { list-style: none; margin: 0; padding: 0 12px; display: grid; gap: 8px; }
.product {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 12px 12px 10px; display: grid; gap: 8px;
}
.product.has-qty { border-color: var(--green-2); box-shadow: inset 4px 0 0 var(--green-2); }
.product.has-error { border-color: var(--danger); box-shadow: inset 4px 0 0 var(--danger); }
.p-head { display: grid; gap: 2px; min-width: 0; }
.p-name { font-size: 1.02rem; font-weight: 700; overflow-wrap: anywhere; }
.p-meta { margin: 0; font-size: .85rem; color: var(--muted); display: flex; flex-wrap: wrap; gap: 2px 10px; }
.p-ref { white-space: nowrap; }
.p-ref [lang="zh-Hans"] { color: var(--text); font-weight: 600; }
.p-variant { margin: 0; font-size: .85rem; color: var(--muted); font-style: italic; }
.p-already, .p-family {
  margin: 4px 0 0; font-size: .88rem; font-weight: 600; padding: 4px 8px; border-radius: 6px; justify-self: start;
}
.p-already { background: var(--green-soft); color: var(--green); }
.p-family { background: var(--warn-soft); color: #4d3500; }
.p-controls { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 8px 10px; align-items: end; }
.p-field { display: grid; gap: 4px; min-width: 0; }
.p-label { font-size: .8rem; color: var(--muted); font-weight: 600; }
.stepper { display: grid; grid-template-columns: var(--tap) minmax(48px, 1fr) var(--tap); gap: 4px; }
.step {
  min-height: var(--tap); border-radius: 10px; border: 1px solid var(--green-line); background: var(--green-soft);
  color: var(--green); font-size: 1.5rem; font-weight: 700; cursor: pointer; touch-action: manipulation; padding: 0;
}
.step:active { background: #cfe4d6; }
.qty {
  min-height: var(--tap); width: 100%; min-width: 0; border-radius: 10px; border: 1px solid var(--border);
  background: #fff; text-align: center; font-size: 1.15rem; font-weight: 700; padding: 6px 4px;
}
.qty[aria-invalid="true"] { border-color: var(--danger); background: var(--danger-soft); }
.unit, .unit-fixed {
  min-height: var(--tap); width: 100%; border-radius: 10px; border: 1px solid var(--border); background: #fff;
  padding: 8px 10px; font-size: .95rem; min-width: 0;
}
.unit-fixed { display: flex; align-items: center; background: var(--surface-2); font-weight: 600; }
.p-error { margin: 0; color: var(--danger); font-weight: 600; font-size: .9rem; }
.empty-state { padding: 24px 16px; color: var(--muted); text-align: center; }

.draftbar {
  position: sticky; bottom: 0; z-index: 15; margin-top: 18px;
  background: rgba(246, 245, 239, .96); border-top: 1px solid var(--border);
  padding: 10px 16px; padding-bottom: max(10px, env(safe-area-inset-bottom));
  backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
}
.draft-summary { margin: 0 0 8px; font-size: .9rem; color: var(--muted); text-align: center; font-weight: 600; }
.draft-summary[data-error="1"] { color: var(--danger); }

/* ---------------------------------------------------------------- commande */
#panel-order { padding: 14px 16px; }
.order-head { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: 6px 12px; margin-bottom: 8px; }
.order-head h2 { font-size: 1.25rem; color: var(--green); }
.order-meta { margin: 0; color: var(--muted); }
.message-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px; margin: 12px 0;
  display: grid; gap: 10px;
}
.message-card h3 { font-size: 1rem; }
.message-card .help { margin: 2px 0 0; }
.help { color: var(--muted); font-size: .88rem; margin: 4px 0; }
.message {
  margin: 0; padding: 14px; border-radius: 10px; background: #fbfbf7; border: 1px dashed var(--green-line);
  white-space: pre-wrap; overflow-wrap: anywhere; font-family: var(--font); font-size: 1.05rem; line-height: 1.7;
  user-select: text; -webkit-user-select: text; max-width: 100%;
}
.copy-status { margin: 0; min-height: 1.4em; font-weight: 600; text-align: center; }
.copy-status.is-success { color: var(--green); }
.copy-status.is-error { color: var(--danger); }
.review h3 { font-size: 1rem; margin-bottom: 6px; }
.review { display: block; }
.review ul { margin: 0; padding-left: 18px; display: grid; gap: 10px; }
.review-reason { font-size: .9rem; }
.review .btn { margin-top: 6px; }
.lines h3 { font-size: 1rem; margin: 18px 0 6px; }
.lines-cat { font-size: .92rem; color: var(--green); margin: 14px 0 6px; }
.line-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.line { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 10px 12px; display: grid; gap: 8px; }
.line-review { border-color: var(--danger); }
.line-zh { margin: 0; font-weight: 700; font-size: 1.02rem; overflow-wrap: anywhere; }
.line-local { margin: 0; color: var(--muted); font-size: .9rem; overflow-wrap: anywhere; }
.line-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.line-msg { margin: 0; font-weight: 600; font-size: .9rem; }
.line-msg.is-success { color: var(--green); }
.line-msg.is-warn { color: var(--warn); }
.editor { display: grid; gap: 6px; background: var(--surface-2); border-radius: 10px; padding: 10px; }
.editor .notice { margin: 0; }
.editor-row { display: grid; grid-template-columns: minmax(80px, 140px) minmax(0, 1fr); gap: 8px; }
.editor-actions { display: flex; flex-wrap: wrap; gap: 8px; justify-content: flex-end; }
.reset-zone { margin-top: 36px; padding-top: 16px; border-top: 1px solid var(--border); }

/* ---------------------------------------------------------------- pied, toast, dialogues */
.footer {
  max-width: 860px; margin: 0 auto; padding: 8px 16px 28px; display: flex; flex-wrap: wrap;
  justify-content: space-between; gap: 8px; font-size: .9rem;
}
.footer .btn-link { color: var(--muted); font-weight: 500; }
.toast {
  position: fixed; left: 50%; bottom: calc(110px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  z-index: 60; max-width: min(92vw, 520px); padding: 12px 16px; border-radius: 12px;
  background: var(--text); color: #fff; font-weight: 600; box-shadow: 0 8px 24px rgba(0,0,0,.2); text-align: center;
}
.toast[data-kind="success"] { background: var(--green); }
.toast[data-kind="error"] { background: var(--danger); }

.dialog {
  border: 0; border-radius: 16px; padding: 20px; width: min(92vw, 520px); max-height: 90vh;
  color: var(--text); background: var(--surface); box-shadow: 0 20px 60px rgba(0,0,0,.3);
}
.dialog::backdrop { background: rgba(20, 30, 24, .45); }
.dialog h2 { font-size: 1.15rem; margin-bottom: 10px; }
.dialog p { margin: 0 0 14px; color: var(--muted); }
.dialog textarea {
  width: 100%; border: 1px solid var(--border); border-radius: 10px; padding: 10px; font-size: 1rem;
  line-height: 1.6; background: #fbfbf7; resize: vertical;
}
.dialog-actions { display: flex; flex-wrap: wrap; gap: 8px; justify-content: flex-end; margin-top: 12px; }
.dialog-actions .btn { flex: 1 1 140px; }
.dialog-full { width: min(100vw, 980px); max-width: 100vw; height: 100vh; max-height: 100vh; margin: 0 auto; padding: 0; border-radius: 0; }
@media (min-width: 760px) { .dialog-full { height: 92vh; margin-top: 4vh; border-radius: 16px; } }

/* ---------------------------------------------------------------- gestion */
.admin { display: flex; flex-direction: column; height: 100%; }
.admin-head {
  display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 14px 16px;
  background: var(--green); color: #fff; position: sticky; top: 0; z-index: 2;
}
.admin-head h2 { margin: 0; font-size: 1.1rem; }
.admin-nav { display: flex; flex-wrap: wrap; gap: 6px; padding: 10px 16px; border-bottom: 1px solid var(--border); align-items: center; }
.admin-tab { min-height: 40px; padding: 6px 12px; border-radius: 8px; border: 1px solid var(--border); background: var(--surface); cursor: pointer; font-weight: 600; }
.admin-tab.is-active { background: var(--green); color: #fff; border-color: var(--green); }
.admin-leave { margin-left: auto; font-size: .9rem; }
.admin-body { padding: 14px 16px 32px; overflow-y: auto; flex: 1; }
.admin-login { display: grid; gap: 10px; max-width: 420px; }
.admin-login input, .admin-form input[type="text"], .admin-form select, .admin-form textarea, .admin-toolbar input, .admin-toolbar select {
  min-height: 44px; border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px; background: #fff; width: 100%; min-width: 0;
}
.admin-toolbar { display: grid; grid-template-columns: 1fr; gap: 8px; margin-bottom: 8px; }
@media (min-width: 640px) { .admin-toolbar { grid-template-columns: 2fr 1fr auto; } }
.admin-list h3 { font-size: .95rem; color: var(--green); margin: 16px 0 6px; }
.admin-products { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.admin-product {
  width: 100%; text-align: left; display: grid; gap: 2px; padding: 10px 12px; border-radius: 10px;
  border: 1px solid var(--border); background: var(--surface); cursor: pointer;
}
.admin-product:hover { border-color: var(--green-line); background: var(--green-soft); }
.ap-name { font-weight: 700; }
.ap-zh { font-size: .95rem; }
.ap-tags { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 4px; }
.tag { font-size: .75rem; padding: 2px 8px; border-radius: 10px; background: var(--surface-2); color: var(--muted); }
.tag-active { background: var(--green-soft); color: var(--green); }
.tag-to_confirm { background: var(--warn-soft); color: #4d3500; }
.tag-inactive { background: #eee; color: #555; }
.tag-human { background: #e6ecff; color: #1b3a8a; }
.admin-form { display: grid; gap: 14px; }
.admin-form-head { display: grid; gap: 4px; }
.admin-form fieldset { border: 1px solid var(--border); border-radius: 12px; padding: 12px; margin: 0; display: grid; gap: 10px; min-width: 0; }
.admin-form legend { font-weight: 700; color: var(--green); padding: 0 6px; }
.field { display: grid; gap: 4px; min-width: 0; }
.field label, .field .label { font-weight: 600; font-size: .9rem; }
.field-error { color: var(--danger); margin: 0; font-size: .88rem; font-weight: 600; }
.unit-checks { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 6px; }
.check { display: flex; align-items: center; gap: 6px; min-height: 40px; padding: 4px 8px; border: 1px solid var(--border); border-radius: 8px; background: #fff; font-weight: 500 !important; }
.check input { width: 20px; height: 20px; }
.admin-actions { display: flex; flex-wrap: wrap; gap: 8px; justify-content: flex-end; }
.admin-section { border: 1px solid var(--border); border-radius: 12px; padding: 14px; margin-bottom: 14px; display: grid; gap: 8px; justify-items: start; }
.admin-section input[type="file"] { max-width: 100%; }
.import-result { width: 100%; }
.preview { display: grid; gap: 8px; }
.diff { margin: 0; padding-left: 18px; font-size: .9rem; display: grid; gap: 6px; }
.diff code { background: var(--surface-2); padding: 1px 4px; border-radius: 4px; overflow-wrap: anywhere; }
.table-wrap { overflow-x: auto; max-width: 100%; }
.history { border-collapse: collapse; width: 100%; font-size: .85rem; }
.history th, .history td { border-bottom: 1px solid var(--border); padding: 6px 8px; text-align: left; vertical-align: top; }
.history .mono { overflow-wrap: anywhere; max-width: 260px; }
.admin-details summary { cursor: pointer; font-weight: 600; min-height: 40px; display: flex; align-items: center; }

@media (min-width: 700px) {
  .products { padding: 0 16px; }
  .product { grid-template-columns: minmax(0, 1fr) minmax(300px, 360px); align-items: center; column-gap: 16px; }
  .p-error { grid-column: 1 / -1; }
}
@media (max-width: 360px) {
  .tabs [role="tab"] { font-size: .85rem; }
  .p-controls { grid-template-columns: 1fr; }
}
@media (prefers-reduced-motion: reduce) { * { scroll-behavior: auto !important; } }
