/* =====================================================================
   Alpaw — administration
   ===================================================================== */
:root {
  --bg: #F4F2EE; --surface: #fff; --surface-2: #FAF8F5; --ink: #1B2A33; --ink-2: #394750; --muted: #6B7479;
  --line: #E5E0D7; --lake: #1F4A3A; --lake-2: #2C6150; --terra: #DD6326; --terra-2: #BF521C; --sand: #F2B48C;
  --success: #2F7A55; --success-bg: #E7F3EC; --warning: #9A6412; --warning-bg: #FBF1DC; --danger: #B3402A; --danger-bg: #FBE9E4; --info-bg: #E6EEF3;
  --radius: 12px; --font: system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
}
*, *::before, *::after { box-sizing: border-box; }
body { margin: 0; font-family: var(--font); font-size: 15px; line-height: 1.55; color: var(--ink); background: var(--bg); -webkit-font-smoothing: antialiased; }
a { color: var(--lake); }
a:hover { color: var(--terra); }
h1, h2 { font-weight: 600; line-height: 1.2; margin: 0 0 .8rem; }
h2 { font-size: 1.05rem; }
.sprite { display: none; }
.i { width: 20px; height: 20px; flex: none; }
[hidden] { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.right { text-align: right; }
.center { text-align: center; }
.nowrap { white-space: nowrap; }
.req { color: var(--terra); }
code { background: #EFEBE4; padding: .1em .35em; border-radius: 5px; }
:focus-visible { outline: 3px solid rgba(192, 99, 58, .5); outline-offset: 2px; }

/* Structure */
.admin-shell { display: grid; grid-template-columns: 250px 1fr; min-height: 100vh; }
.sidebar { background: var(--lake); color: #C6D6CE; display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; padding: 1.2rem .8rem; }
.sidebar__brand { color: #F7F4EE; text-decoration: none; font-family: var(--serif); font-size: 1.35rem; padding: .3rem .7rem 1.2rem; display: block; }
.sidebar__brand em { color: var(--sand); }
.sidebar__brand small { display: block; font-family: var(--font); font-size: .72rem; letter-spacing: .14em; text-transform: uppercase; color: #8FAA9D; }
.sidebar__brand:hover { color: #fff; }
.sidebar__nav { display: grid; gap: 2px; }
.sidebar__nav a { display: flex; align-items: center; gap: .7rem; padding: .62rem .75rem; border-radius: 9px; color: #D6E3DC; text-decoration: none; font-weight: 500; }
.sidebar__nav a:hover { background: rgba(255, 255, 255, .07); color: #fff; }
.sidebar__nav a.is-active { background: rgba(255, 255, 255, .13); color: #fff; }
.sidebar__nav .count { margin-left: auto; background: var(--terra); color: #fff; font-size: .72rem; min-width: 22px; height: 20px; border-radius: 10px; display: grid; place-items: center; padding: 0 6px; }
.sidebar__footer { margin-top: auto; display: grid; gap: .2rem; border-top: 1px solid rgba(255, 255, 255, .12); padding-top: .8rem; }
.sidebar__footer a, .sidebar__footer button { display: flex; gap: .6rem; align-items: center; padding: .55rem .75rem; color: #C6D6CE; text-decoration: none; background: none; border: 0; font: inherit; cursor: pointer; border-radius: 9px; width: 100%; text-align: left; }
.sidebar__footer a:hover, .sidebar__footer button:hover { background: rgba(255, 255, 255, .07); color: #fff; }
.sidebar__footer form { margin: 0; }
.sidebar__user { font-size: .82rem; padding: .6rem .75rem 0; margin: 0; color: #fff; }
.sidebar__user small { color: #8FAA9D; }
.admin-main { min-width: 0; }
.topbar { display: flex; align-items: center; gap: 1rem; padding: 1rem 2rem; background: rgba(244, 242, 238, .92); backdrop-filter: blur(8px); position: sticky; top: 0; z-index: 10; border-bottom: 1px solid var(--line); }
.topbar h1 { font-size: 1.35rem; margin: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pill-mode { margin-left: auto; font-size: .75rem; font-weight: 700; padding: .3rem .7rem; border-radius: 999px; background: var(--warning-bg); color: var(--warning); white-space: nowrap; }
.pill-mode--live { background: var(--success-bg); color: var(--success); }
.menu-btn { display: none; }
.admin-content { padding: 1.5rem 2rem 3rem; max-width: 1400px; }
.sidebar-backdrop { position: fixed; inset: 0; background: rgba(27, 42, 51, .45); z-index: 40; }

/* Composants */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: .4rem; min-height: 40px; padding: .5rem 1rem; border-radius: 9px; border: 1px solid var(--line); background: var(--surface); color: var(--ink); font: inherit; font-weight: 600; text-decoration: none; cursor: pointer; transition: background .15s, border-color .15s; }
.btn:hover { border-color: #CFC7B9; background: var(--surface-2); color: var(--ink); }
.btn--primary { background: var(--terra); border-color: var(--terra); color: #fff; }
.btn--primary:hover { background: var(--terra-2); border-color: var(--terra-2); color: #fff; }
.btn--danger { color: var(--danger); border-color: rgba(179, 64, 42, .3); }
.btn--danger:hover { background: var(--danger-bg); color: var(--danger); border-color: var(--danger); }
.btn--link { border-color: transparent; background: none; color: var(--lake); font-weight: 500; }
.btn--sm { min-height: 32px; padding: .25rem .7rem; font-size: .85rem; }
.btn--block { width: 100%; }
.btn.is-loading, .btn[disabled] { opacity: .6; cursor: wait; }
.btn.is-loading::before { content: ""; width: 14px; height: 14px; border-radius: 50%; border: 2px solid currentColor; border-right-color: transparent; animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.icon-btn { width: 40px; height: 40px; border: 0; background: none; border-radius: 50%; display: grid; place-items: center; cursor: pointer; color: var(--ink); }
.icon-btn:hover { background: #E9E4DB; }
form.inline { display: inline; margin: 0; }

.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 1.3rem; margin-bottom: 1.2rem; }
.panel--flush { padding: 0; overflow: hidden; }
.panel__head { display: flex; justify-content: space-between; align-items: center; gap: 1rem; margin-bottom: .8rem; }
.panel__head h2 { margin: 0; }
.panel__head a { font-size: .88rem; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 1.2rem; }
.grid-2 > .panel { margin-bottom: 1.2rem; }
.grid-main { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: 1.2rem; align-items: start; }
.grid-main--reverse { grid-template-columns: minmax(0, 1fr) 380px; }

.alert { display: flex; gap: .8rem; align-items: flex-start; padding: .8rem 1rem; border-radius: 10px; margin-bottom: 1rem; border: 1px solid transparent; }
.alert p, .alert ul { margin: 0; flex: 1; }
.alert ul { padding-left: 1.1rem; }
.alert--success { background: var(--success-bg); color: #1F5A3D; border-color: #C6E3D2; }
.alert--error { background: var(--danger-bg); color: #862F1F; border-color: #F1CFC6; }
.alert--warning { background: var(--warning-bg); color: #7A4F0E; border-color: #EFDDB5; }
.alert--info { background: var(--info-bg); color: #1F3F52; border-color: #CCDCE6; }
.alert__close { border: 0; background: none; cursor: pointer; color: inherit; opacity: .6; padding: 0; }

/* Formulaires */
input:not([type="checkbox"]):not([type="radio"]):not([type="file"]), select, textarea {
  width: 100%; min-height: 40px; padding: .5rem .7rem; border: 1px solid #D6CFC2; border-radius: 8px; background: #fff; font: inherit; color: inherit;
}
textarea { resize: vertical; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--lake); box-shadow: 0 0 0 3px rgba(30, 58, 76, .12); }
.field { margin-bottom: .9rem; }
.field label { display: block; font-weight: 600; font-size: .88rem; margin-bottom: .3rem; }
.field--highlight { background: var(--surface-2); border: 1px solid var(--line); border-radius: 10px; padding: .8rem; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: .8rem; }
.hint { color: var(--muted); font-size: .82rem; margin: .3rem 0 0; }
.checkbox, .radio { display: flex; align-items: center; gap: .5rem; margin: .45rem 0; cursor: pointer; font-size: .92rem; }
.checkbox input, .radio input { width: 17px; height: 17px; accent-color: var(--terra); }
.checkbox--danger { color: var(--danger); }
.form-narrow { max-width: 560px; }
.form-narrow h2 { margin-top: 1rem; }
.uppercase { text-transform: uppercase; }

/* Tableaux */
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; }
.table th, .table td { padding: .75rem .9rem; border-bottom: 1px solid var(--line); text-align: left; vertical-align: middle; }
.table th { font-size: .74rem; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); background: var(--surface-2); font-weight: 600; white-space: nowrap; }
.table th.right, .table td.right { text-align: right; }
.table tbody tr:hover { background: #FCFBF8; }
.table tr.is-muted td { opacity: .6; }
.table tfoot td { border-bottom: 0; padding: .4rem .9rem; }
.table tfoot tr.total td { font-weight: 700; font-size: 1.05rem; border-top: 1px solid var(--line); padding-top: .8rem; }
.table .empty { text-align: center; color: var(--muted); padding: 2rem; }
.row-link { cursor: pointer; }
.thumb { width: 56px; height: 56px; object-fit: cover; border-radius: 8px; background: #EFE9DE; }
.table--variants td { padding: .4rem; }
.table--variants input { min-height: 36px; }
.table--variants tr.is-deleted input:not([type="checkbox"]) { text-decoration: line-through; opacity: .5; }
.code { font-family: ui-monospace, Consolas, monospace; letter-spacing: .03em; }

.badge { display: inline-block; padding: .18rem .6rem; border-radius: 999px; font-size: .76rem; font-weight: 600; white-space: nowrap; background: #EEE; }
.badge--en_attente { background: #FBF1DC; color: #8A5A10; }
.badge--payee { background: #E6EEF3; color: #1F3F52; }
.badge--en_preparation { background: #EFE6F7; color: #5B3A7A; }
.badge--expediee { background: #E3F0F5; color: #1B5A73; }
.badge--terminee { background: var(--success-bg); color: #1F5A3D; }
.badge--annulee { background: #EFEDEA; color: #6B6660; }
.pay { font-size: .8rem; font-weight: 700; }
.pay--paye { color: var(--success); }
.pay--non_paye { color: var(--warning); }
.pay--echoue, .pay--rembourse { color: var(--danger); }
.stock-pill { display: inline-block; min-width: 34px; text-align: center; padding: .15rem .5rem; border-radius: 999px; background: var(--success-bg); color: var(--success); font-weight: 700; font-size: .85rem; }
.stock-pill.is-low { background: var(--warning-bg); color: var(--warning); }
.stock-pill.is-out { background: var(--danger-bg); color: var(--danger); }

.toolbar { display: flex; justify-content: space-between; gap: 1rem; align-items: center; margin-bottom: 1rem; flex-wrap: wrap; }
.toolbar__filters { display: flex; gap: .5rem; flex-wrap: wrap; flex: 1; }
.toolbar__filters input { max-width: 280px; }
.toolbar__filters select { width: auto; }
.chips { display: flex; gap: .4rem; flex-wrap: wrap; margin-bottom: 1rem; }
.chips a { padding: .35rem .8rem; border-radius: 999px; border: 1px solid var(--line); background: var(--surface); text-decoration: none; color: var(--ink-2); font-size: .88rem; font-weight: 500; }
.chips a b { color: var(--muted); font-weight: 600; margin-left: .2rem; }
.chips a.is-active { background: var(--lake); border-color: var(--lake); color: #fff; }
.chips a.is-active b { color: #C6D6CE; }
.pagination { display: flex; gap: .3rem; justify-content: center; margin-top: 1rem; flex-wrap: wrap; }
.pagination a { min-width: 36px; height: 36px; display: grid; place-items: center; border-radius: 8px; border: 1px solid var(--line); background: #fff; text-decoration: none; }
.pagination a.is-active { background: var(--lake); color: #fff; }

/* Tableau de bord */
.kpis { display: grid; grid-template-columns: repeat(4, 1fr); gap: 1.2rem; margin-bottom: 1.2rem; }
.kpi { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 1.1rem 1.2rem; display: grid; gap: .15rem; text-decoration: none; color: var(--ink); }
.kpi span { color: var(--muted); font-size: .85rem; }
.kpi strong { font-size: 1.6rem; font-weight: 700; letter-spacing: -.01em; }
.kpi small { color: var(--muted); font-size: .8rem; }
.kpi--accent { background: var(--lake); color: #fff; border-color: var(--lake); }
.kpi--accent span, .kpi--accent small { color: #BFD6CA; }
.kpi--link:hover { border-color: var(--terra); color: var(--ink); }
.bars { display: flex; align-items: flex-end; gap: 6px; height: 190px; padding-top: 10px; }
.bars__col { flex: 1; height: 100%; display: flex; flex-direction: column; justify-content: flex-end; align-items: center; gap: 4px; }
.bars__bar { width: 100%; max-width: 30px; background: linear-gradient(180deg, var(--sand), var(--terra)); border-radius: 5px 5px 2px 2px; min-height: 2px; transition: opacity .2s; }
.bars__col:hover .bars__bar { opacity: .75; }
.bars__col small { font-size: .7rem; color: var(--muted); }
.rank { margin: 0; padding-left: 1.2rem; display: grid; gap: .6rem; }
.rank li { display: grid; grid-template-columns: 1fr auto auto; gap: .8rem; align-items: baseline; }
.rank small { color: var(--muted); min-width: 90px; text-align: right; }
.stock-list { list-style: none; margin: 0; padding: 0; display: grid; gap: .55rem; }
.stock-list li { display: grid; grid-template-columns: auto 1fr auto; gap: .6rem; align-items: baseline; }
.stock-list b { font-size: .8rem; padding: .1rem .5rem; border-radius: 999px; }
.stock-list b.is-low { background: var(--warning-bg); color: var(--warning); }
.stock-list b.is-out { background: var(--danger-bg); color: var(--danger); }

/* Produit */
.image-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: .8rem; margin-bottom: 1rem; }
.image-card { border: 1px solid var(--line); border-radius: 10px; padding: .5rem; background: var(--surface-2); }
.image-card img { width: 100%; aspect-ratio: 1; object-fit: cover; border-radius: 7px; margin-bottom: .3rem; background: #EFE9DE; }
.image-card input:not([type]) { min-height: 32px; font-size: .82rem; }
.dropzone { position: relative; border: 2px dashed #CFC7B9; border-radius: 12px; padding: 1.3rem; text-align: center; background: var(--surface-2); transition: border-color .2s, background .2s; }
.dropzone.is-over { border-color: var(--terra); background: #FBF3EC; }
.dropzone input[type="file"] { position: absolute; inset: 0; opacity: 0; cursor: pointer; width: 100%; }
.dropzone label { display: grid; gap: .2rem; pointer-events: none; }
.dropzone label span { color: var(--muted); font-size: .85rem; }
.dropzone__preview { display: flex; flex-wrap: wrap; gap: .5rem; justify-content: center; margin-top: .6rem; }
.dropzone__preview img { width: 70px; height: 70px; object-fit: cover; border-radius: 8px; }

/* Commande */
.order-head { display: flex; justify-content: space-between; align-items: center; gap: 1rem; flex-wrap: wrap; margin-bottom: 1rem; }
.order-head > div { display: flex; gap: .7rem; align-items: center; flex-wrap: wrap; }
.order-head__total { font-size: 1.6rem; }
.timeline-admin { list-style: none; padding: 0; margin: 0; display: grid; gap: .5rem; font-size: .92rem; }
address { font-style: normal; line-height: 1.6; margin-bottom: .8rem; }
.note { background: var(--warning-bg); border-radius: 8px; padding: .7rem .8rem; font-size: .9rem; }
.dl { display: grid; grid-template-columns: auto 1fr; gap: .4rem 1rem; margin: 0; font-size: .92rem; }
.dl dt { color: var(--muted); }
.dl dd { margin: 0; word-break: break-all; }

/* Messages */
.message.is-unread { border-left: 4px solid var(--terra); }
.message__head { display: flex; justify-content: space-between; gap: 1rem; align-items: flex-start; flex-wrap: wrap; }
.message__body { background: var(--surface-2); border-radius: 10px; padding: 1rem; margin: 1rem 0; line-height: 1.7; }
.message p { margin: .6rem 0 0; }

/* Connexion */
.admin-login { min-height: 100vh; display: grid; place-items: center; padding: 1.5rem; background: radial-gradient(circle at 20% 10%, #2C6150, #1F4A3A 60%); }
.login-card { width: 100%; max-width: 400px; background: #fff; border-radius: 16px; padding: 2rem; box-shadow: 0 30px 60px -20px rgba(0, 0, 0, .4); }
.login-card h1 { font-size: 1.4rem; }
.login-card__brand { font-family: var(--serif); font-size: 1.5rem; margin: 0 0 .5rem; color: var(--lake); }
.login-card__brand em { color: var(--terra); }
.login-card__back { text-align: center; margin: 1.2rem 0 0; font-size: .9rem; }

/* Responsive */
@media (max-width: 1100px) {
  .kpis { grid-template-columns: repeat(2, 1fr); }
  .grid-2, .grid-main, .grid-main--reverse { grid-template-columns: 1fr; }
}
@media (max-width: 860px) {
  .admin-shell { grid-template-columns: 1fr; }
  .sidebar { position: fixed; left: 0; top: 0; bottom: 0; width: 270px; z-index: 50; transform: translateX(-100%); transition: transform .25s ease; }
  .sidebar.is-open { transform: none; }
  .menu-btn { display: grid; }
  .topbar { padding: .7rem 1rem; }
  .admin-content { padding: 1rem 1rem 3rem; }
  .field-row { grid-template-columns: 1fr; gap: 0; }
  .toolbar__filters input { max-width: none; }
}
@media (max-width: 520px) {
  .kpis { grid-template-columns: 1fr; }
  .pill-mode { display: none; }
}

/* Fournisseur & import */
.kpi--warn { border-color: #EFDDB5; background: var(--warning-bg); }
.error-row { display: flex; justify-content: space-between; gap: 1rem; align-items: flex-start; padding: .7rem 0; border-bottom: 1px solid var(--line); }
.error-row:last-child { border-bottom: 0; }
.chips--suggest { margin: .8rem 0 .4rem; }
.import-by-id { margin-top: 1rem; }
.import-by-id summary { cursor: pointer; font-weight: 600; margin-bottom: .6rem; }
.import-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 1rem; }
.import-card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; display: flex; flex-direction: column; }
.import-card img { width: 100%; aspect-ratio: 1; object-fit: cover; background: #EFE9DE; }
.import-card__body { padding: .8rem; display: grid; gap: .5rem; }
.import-card__body h3 { font-size: .9rem; font-weight: 600; margin: 0; line-height: 1.35; }
.import-card__prices { font-size: .82rem; color: var(--ink-2); margin: 0; }
.import-card form { display: grid; gap: .4rem; }
.supplier-box { background: var(--surface-2); border: 1px solid var(--line); border-radius: 10px; padding: .8rem 1rem; margin-bottom: 1rem; font-size: .92rem; }
.margin-pos { color: var(--success); font-weight: 600; }
.margin-neg { color: var(--danger); font-weight: 600; }
.sup { font-size: .76rem; font-weight: 700; padding: .15rem .55rem; border-radius: 999px; white-space: nowrap; background: #EEE; color: #555; }
.sup--a_envoyer { background: var(--warning-bg); color: var(--warning); }
.sup--envoye { background: var(--info-bg); color: #1F3F52; }
.sup--expedie, .sup--livre { background: var(--success-bg); color: var(--success); }
.sup--erreur { background: var(--danger-bg); color: var(--danger); }

.bulk-tools { background: #FFF8EC; border: 1px dashed #E8C98F; border-radius: 10px; padding: .9rem 1rem .4rem; margin: .4rem 0 1rem; }
.bulk-tools .field { margin-bottom: .5rem; }
