/* Marconi — Inventaire. Design system aligne sur l'app Whisper PySide6
   (meme palette creme/orange, Inter + Source Serif + JetBrains Mono). */

:root {
  --bg: #F0EEE6;
  --surface: #FAF9F5;
  --surface-alt: #E8E6DC;
  --border: #DCD9CD;
  --border-strong: #C8C4B4;
  --text: #1F1E1C;
  --text-dim: #5C5B57;
  --text-faint: #8A8780;
  --accent: #C96442;
  --accent-hover: #B5573A;
  --accent-bg: #F4E4DA;
  --ok: #4A7B5C;
  --ok-bg: #E7EDE4;
  --warn: #C96442;
  --warn-bg: #F4E4DA;
  --ui: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --serif: "Source Serif 4", Georgia, serif;
  --mono: "JetBrains Mono", "SF Mono", ui-monospace, Menlo, monospace;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; height: 100%; background: var(--bg); color: var(--text); font-family: var(--ui); -webkit-font-smoothing: antialiased; }

.app { display: flex; height: 100vh; }

/* Scrollbars */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 5px; border: 2px solid var(--bg); }
::-webkit-scrollbar-thumb:hover { background: var(--border-strong); }

/* Sidebar */
.sidebar { width: 232px; background: var(--surface-alt); border-right: 1px solid var(--border); display: flex; flex-direction: column; padding: 14px 12px; flex-shrink: 0; }
.brand { display: flex; align-items: center; gap: 9px; padding: 4px 6px 14px; }
.brand-mark { width: 22px; height: 22px; border-radius: 5px; background: var(--accent); color: white; font-family: var(--mono); font-size: 11px; font-weight: 600; display: flex; align-items: center; justify-content: center; }
.brand-name { font-size: 13.5px; font-weight: 600; letter-spacing: -0.01em; }
.brand-v { margin-left: auto; color: var(--text-faint); font-size: 11px; font-family: var(--mono); }

.search { display: flex; align-items: center; gap: 8px; background: var(--surface); border: 1px solid var(--border); border-radius: 6px; padding: 6px 9px; margin-bottom: 14px; }
.search input { border: none; background: transparent; outline: none; font-family: var(--ui); font-size: 12.5px; color: var(--text); flex: 1; padding: 0; min-width: 0; }
.search input::placeholder { color: var(--text-faint); }
.search kbd { font-family: var(--mono); font-size: 10px; color: var(--text-faint); border: 1px solid var(--border); border-radius: 4px; padding: 1px 5px; background: var(--surface); }

.nav { display: flex; flex-direction: column; gap: 1px; }
.nav-item { display: flex; align-items: center; gap: 10px; padding: 6px 9px; border-radius: 5px; cursor: pointer; color: var(--text-dim); font-size: 13px; border: 1px solid transparent; transition: background 0.1s; }
.nav-item:hover { background: rgba(31,30,28,0.03); }
.nav-item.active { background: var(--surface); border-color: var(--border); color: var(--text); font-weight: 500; }
.nav-item .count { margin-left: auto; font-family: var(--mono); font-size: 11px; color: var(--text-faint); }
.nav-item svg { color: var(--text-faint); flex-shrink: 0; }
.nav-item.active svg { color: var(--text); }

.sidebar-footer { margin-top: auto; padding-top: 14px; border-top: 1px solid var(--border); display: flex; flex-direction: column; gap: 10px; }
.label-cap { font-size: 10.5px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--text-faint); font-weight: 500; }
.pulse-row { display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--text-dim); }
.pulse { position: relative; width: 8px; height: 8px; flex-shrink: 0; }
.pulse::before, .pulse::after { content: ''; position: absolute; border-radius: 50%; background: var(--ok); }
.pulse::before { inset: 0; }
.pulse::after { inset: -3px; opacity: 0.25; animation: pulse 2s ease-out infinite; }
@keyframes pulse { 0% { transform: scale(0.8); opacity: 0.4; } 100% { transform: scale(1.6); opacity: 0; } }
.pulse.warn::before, .pulse.warn::after { background: var(--warn); }
.mono-dim { font-family: var(--mono); font-size: 11px; color: var(--text-faint); }
.refresh-btn { display: flex; align-items: center; justify-content: center; gap: 6px; padding: 6px 10px; background: var(--surface); border: 1px solid var(--border); border-radius: 6px; font-size: 12px; color: var(--text-dim); cursor: pointer; font-family: var(--ui); transition: border-color 0.1s, color 0.1s; }
.refresh-btn:hover { border-color: var(--border-strong); color: var(--text); }
.refresh-btn:disabled { opacity: 0.5; cursor: wait; }
.refresh-btn.spinning svg { animation: spin 0.9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* Main content */
.main { flex: 1; display: flex; flex-direction: column; min-width: 0; background: var(--bg); overflow: hidden; }
.main > section { display: flex; flex-direction: column; min-height: 0; flex: 1; animation: fadeIn 0.15s ease-out; }
.topbar { height: 48px; border-bottom: 1px solid var(--border); display: flex; align-items: center; padding: 0 20px; gap: 14px; font-size: 13px; flex-shrink: 0; }
.topbar .crumb { font-weight: 500; cursor: pointer; }
.topbar .crumb.dim { color: var(--text-dim); font-weight: 400; }
.topbar .sep { color: var(--text-faint); }
.topbar-right { margin-left: auto; display: flex; align-items: center; gap: 10px; font-size: 12px; color: var(--text-dim); }
.topbar-right .mono { font-family: var(--mono); color: var(--text); }
.avatar { width: 22px; height: 22px; border-radius: 50%; background: var(--accent); color: white; display: flex; align-items: center; justify-content: center; font-size: 10px; font-weight: 600; flex-shrink: 0; }

.page-head { padding: 22px 24px 14px; flex-shrink: 0; }
.page-title { margin: 4px 0 0; font-size: 26px; font-weight: 500; letter-spacing: -0.02em; font-family: var(--serif); }

/* Filters */
.filter-row { padding: 0 24px 14px; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; flex-shrink: 0; }
.filter-search { display: flex; align-items: center; gap: 8px; background: var(--surface); border: 1px solid var(--border); border-radius: 6px; padding: 4px 10px; min-width: 260px; }
.filter-search input { border: none; background: transparent; outline: none; font-family: var(--ui); font-size: 12.5px; color: var(--text); flex: 1; min-width: 0; }
.filter-search svg { color: var(--text-faint); flex-shrink: 0; }
.filter-clear-x { cursor: pointer; color: var(--text-faint); display: flex; }

.pill { display: inline-flex; align-items: center; gap: 8px; border: 1px solid var(--border); background: var(--surface); border-radius: 6px; padding: 4px 10px; font-size: 12px; cursor: pointer; user-select: none; position: relative; transition: border-color 0.1s, background 0.1s; }
.pill:hover { border-color: var(--border-strong); }
.pill.active { border-color: var(--accent); background: var(--accent-bg); }
.pill .lbl { color: var(--text-faint); }
.pill .val { color: var(--text); font-weight: 500; max-width: 160px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pill .chev { color: var(--text-faint); display: flex; transition: transform 0.15s; }
.pill.open .chev { transform: rotate(180deg); }

.dropdown { position: absolute; top: calc(100% + 4px); left: 0; background: var(--surface); border: 1px solid var(--border); border-radius: 8px; box-shadow: 0 6px 20px rgba(0,0,0,0.08); min-width: 240px; max-width: 380px; max-height: 320px; overflow: auto; z-index: 30; padding: 4px; display: none; animation: fadeIn 0.15s ease-out; }
.pill.open .dropdown { display: block; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(-4px); } to { opacity: 1; transform: none; } }
.dd-item { padding: 7px 10px; font-size: 12.5px; cursor: pointer; border-radius: 5px; color: var(--text); display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.dd-item:hover { background: var(--surface-alt); }
.dd-item.sel { background: var(--surface-alt); }
.dd-item .check { color: var(--accent); font-size: 12px; }
.dd-item .n { color: var(--text-faint); font-family: var(--mono); font-size: 11px; }
.dd-item .lbl { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.clear-btn { border: none; background: transparent; color: var(--text-faint); padding: 4px 8px; font-size: 12px; font-family: var(--ui); cursor: pointer; display: inline-flex; align-items: center; gap: 4px; }
.clear-btn:hover { color: var(--text); }

.count-info { margin-left: auto; display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--text-dim); }
.count-info .mono { font-family: var(--mono); color: var(--text); }

/* Table */
.table-wrap { flex: 1; display: flex; gap: 12px; padding: 0 24px 24px; min-height: 0; }
.table-container { flex: 1; background: var(--surface); border: 1px solid var(--border); border-radius: 8px; overflow: auto; min-width: 0; }
table { width: 100%; border-collapse: collapse; font-size: 12.5px; }
thead tr { background: var(--surface-alt); position: sticky; top: 0; z-index: 1; }
th { text-align: left; padding: 9px 14px; font-size: 11px; font-weight: 500; color: var(--text-dim); text-transform: uppercase; letter-spacing: 0.06em; border-bottom: 1px solid var(--border); cursor: pointer; user-select: none; white-space: nowrap; }
th .sort-ind { color: var(--accent); font-size: 9px; margin-left: 4px; }
tbody tr { cursor: pointer; transition: background 0.08s; }
tbody tr:hover { background: rgba(31,30,28,0.03); }
tbody tr.selected { background: var(--accent-bg); }
tbody td { padding: 10px 14px; border-bottom: 1px solid var(--border); color: var(--text); vertical-align: middle; }
tbody tr:last-child td { border-bottom: none; }
td.mono { font-family: var(--mono); font-size: 12px; }
td.dim { color: var(--text-dim); }
td.date { font-family: var(--mono); font-size: 11.5px; color: var(--text-dim); white-space: nowrap; }

.chip { display: inline-flex; align-items: center; gap: 6px; padding: 2px 8px; font-size: 11.5px; font-weight: 500; border-radius: 999px; border: 1px solid var(--border); background: var(--surface-alt); color: var(--text-dim); line-height: 1.5; white-space: nowrap; }
.chip.warn { background: var(--warn-bg); border-color: #E5C9B8; color: var(--warn); }
.chip.ok { background: var(--ok-bg); border-color: #C9D6C3; color: var(--ok); }
.chip.tech { background: var(--accent-bg); border-color: #E5C9B8; color: var(--accent); }

.empty { padding: 56px 14px !important; text-align: center; color: var(--text-faint); font-size: 13px; border: none !important; }
.empty a { color: var(--accent); cursor: pointer; text-decoration: underline; }

/* Detail panel */
.detail { width: 320px; background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 18px; display: flex; flex-direction: column; gap: 14px; align-self: flex-start; animation: slideIn 0.18s ease-out; flex-shrink: 0; }
@keyframes slideIn { from { opacity: 0; transform: translateX(8px); } to { opacity: 1; transform: none; } }
.detail-head { display: flex; justify-content: space-between; align-items: flex-start; }
.detail-head .close { cursor: pointer; color: var(--text-faint); display: flex; padding: 2px; }
.detail-serial { font-family: var(--mono); font-size: 14px; line-height: 1.3; word-break: break-all; }
.detail-chips { display: flex; gap: 6px; flex-wrap: wrap; }
.kv-list { display: flex; flex-direction: column; gap: 9px; font-size: 12.5px; margin-top: 4px; }
.kv { display: flex; justify-content: space-between; gap: 12px; }
.kv .k { color: var(--text-faint); flex-shrink: 0; }
.kv .v { color: var(--text); text-align: right; overflow-wrap: anywhere; }
.kv .v.link { color: var(--accent); cursor: pointer; font-family: var(--mono); }
.kv .v.link:hover { text-decoration: underline; }

/* Stocks grid */
.stocks-grid { padding: 0 24px 24px; display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 12px; overflow: auto; min-height: 0; align-content: start; }
.box-card { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 16px; display: flex; flex-direction: column; gap: 10px; cursor: pointer; transition: border-color 0.1s, transform 0.1s; }
.box-card:hover { border-color: var(--border-strong); transform: translateY(-1px); }
.box-card .head { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.box-card .id { font-family: var(--mono); font-size: 14px; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.box-card .id.serif { font-family: var(--serif); font-size: 16px; letter-spacing: -0.01em; }
.box-card .sub { font-size: 12.5px; color: var(--text-dim); display: flex; align-items: center; gap: 6px; }
.box-card .count-row { display: flex; align-items: baseline; gap: 4px; flex-wrap: wrap; }
.box-card .count-row .big { font-size: 20px; font-family: var(--mono); font-weight: 500; }
.box-card .count-row .dim { font-size: 12px; color: var(--text-faint); font-family: var(--mono); }
.box-card .count-row .updated { font-size: 11.5px; color: var(--text-faint); margin-left: auto; }
.progress { height: 3px; background: var(--surface-alt); border-radius: 2px; overflow: hidden; }
.progress > div { height: 100%; background: var(--ok); transition: width 0.3s; }
.progress.warn > div { background: var(--warn); }

/* Box detail */
.back-btn { display: flex; color: var(--text-dim); cursor: pointer; padding: 4px; border-radius: 4px; }
.back-btn:hover { background: var(--surface-alt); }
.box-hero { padding: 22px 24px 10px; flex-shrink: 0; }
.box-hero h1 { margin: 4px 0 0; font-size: 26px; font-weight: 500; font-family: var(--mono); letter-spacing: -0.015em; word-break: break-word; }
.box-hero h1.serif { font-family: var(--serif); letter-spacing: -0.02em; }
.box-hero .sub-line { margin-top: 6px; font-size: 13px; color: var(--text-dim); display: inline-flex; align-items: center; gap: 8px; flex-wrap: wrap; }

.stats { padding: 12px 24px 4px; display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; flex-shrink: 0; }
.stat { border: 1px solid var(--border); background: var(--surface); border-radius: 8px; padding: 12px 14px; }
.stat .val { font-size: 22px; font-weight: 500; letter-spacing: -0.01em; margin-top: 6px; }
.stat .val.mono { font-family: var(--mono); }
.stat .hint { font-size: 11.5px; color: var(--text-dim); margin-top: 2px; }

.tabs { padding: 20px 24px 0; display: flex; gap: 2px; border-bottom: 1px solid var(--border); flex-shrink: 0; }
.tab { padding: 8px 14px; font-size: 12.5px; color: var(--text-dim); cursor: pointer; border-bottom: 1.5px solid transparent; margin-bottom: -1px; display: flex; align-items: center; gap: 7px; transition: color 0.1s; }
.tab:hover { color: var(--text); }
.tab.active { color: var(--text); font-weight: 500; border-bottom-color: var(--accent); }
.tab .c { font-family: var(--mono); font-size: 11px; color: var(--text-faint); }
.tab-panel { flex: 1; overflow: auto; padding: 16px 24px 24px; animation: fadeIn 0.15s ease-out; min-height: 0; }

/* Types bar (utilise dans l'onglet Types d'un stock) */
.types-bar { display: flex; align-items: center; gap: 8px; min-width: 140px; }
.types-bar .bar { flex: 1; max-width: 180px; height: 3px; background: var(--surface-alt); border-radius: 2px; overflow: hidden; }
.types-bar .bar > div { height: 100%; background: var(--accent); }
.types-bar .pct { font-family: var(--mono); font-size: 11px; color: var(--text-dim); width: 36px; }

/* Toasts */
.toasts { position: fixed; top: 16px; right: 16px; display: flex; flex-direction: column; gap: 8px; z-index: 100; pointer-events: none; }
.toast { background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 10px 14px; font-size: 12.5px; color: var(--text); box-shadow: 0 6px 20px rgba(0,0,0,0.08); animation: slideIn 0.2s ease-out; max-width: 280px; }
.toast.ok { border-color: #C9D6C3; background: var(--ok-bg); color: var(--ok); }
.toast.err { border-color: #E5C9B8; background: var(--warn-bg); color: var(--warn); }

.hidden { display: none !important; }

/* Mobile-only elements are hidden on desktop. They appear only in the
   @media (max-width: 900px) block below. */
.appbar, .tabbar, .sheet, .sheet-backdrop, .mobile-item-list { display: none; }

/* ════════════════════════════════════════════════════════════════════
   MOBILE  (viewport ≤ 900px)
   The desktop layout (sidebar + main + table) is replaced by a bottom
   tab bar, a sticky app bar with search, horizontal-scroll filter chips,
   card-based item list, and bottom sheets for filter + item detail.
   ════════════════════════════════════════════════════════════════════ */
@media (max-width: 900px) {

  html, body { overscroll-behavior: none; }

  /* Hide desktop chrome */
  .sidebar { display: none; }
  .topbar { display: none; }
  .page-head { display: none; }
  .table-container { display: none; }     /* mobile uses .mobile-item-list instead */
  .detail { display: none !important; }   /* mobile uses .sheet instead */

  /* Show mobile chrome */
  .appbar { display: block; }
  .tabbar { display: flex; }
  .mobile-item-list { display: flex; }
  .sheet { display: block; }
  .sheet-backdrop { display: block; }

  /* Global layout : full width, stacked, with padding-bottom for tabbar */
  .app { display: block; height: auto; min-height: 100vh; }
  .main { display: block; height: auto; overflow: visible; padding-bottom: calc(72px + var(--safe-bottom)); }
  .main > section { display: block; flex: unset; min-height: unset; animation: none; }

  /* ─── App bar ─── */
  .appbar {
    position: sticky; top: 0; z-index: 20;
    padding: calc(10px + var(--safe-top)) 14px 10px;
    background: var(--bg);
    border-bottom: 1px solid transparent;
    transition: border-color 0.2s, background 0.2s;
  }
  .appbar.scrolled {
    border-color: var(--border);
    background: rgba(240, 238, 230, 0.92);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
  }
  .appbar-row {
    display: flex; align-items: center; gap: 10px; min-height: 32px;
  }
  .appbar-back {
    display: none; width: 32px; height: 32px;
    align-items: center; justify-content: center;
    border-radius: 8px; cursor: pointer; color: var(--text);
    margin-left: -6px;
  }
  .appbar-back:active { background: var(--surface-alt); }
  .appbar-back.show { display: flex; }
  .appbar-title {
    font-family: var(--serif);
    font-size: 22px; font-weight: 500; letter-spacing: -0.015em;
    flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  }
  .appbar-title.mono { font-family: var(--mono); font-size: 19px; letter-spacing: -0.01em; }
  .appbar-action {
    width: 32px; height: 32px;
    display: flex; align-items: center; justify-content: center;
    border-radius: 8px; cursor: pointer; color: var(--text-dim);
  }
  .appbar-action:active { background: var(--surface-alt); }
  .appbar-action.spinning svg { animation: spin 0.9s linear infinite; }

  .appbar-search {
    margin-top: 10px;
    display: flex; align-items: center; gap: 8px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 8px 12px;
  }
  .appbar-search svg { color: var(--text-faint); flex-shrink: 0; }
  .appbar-search input {
    border: none; background: transparent; outline: none;
    font-family: var(--ui); font-size: 15px; color: var(--text);
    flex: 1; padding: 0; min-width: 0;
  }
  .appbar-search input::placeholder { color: var(--text-faint); }
  .appbar-search.hidden { display: none; }

  /* ─── Filter chips row (mobile override of .filter-row) ─── */
  .filter-row {
    display: flex; gap: 6px;
    padding: 12px 14px 6px;
    overflow-x: auto;
    scrollbar-width: none;
    flex-wrap: nowrap;
    align-items: center;
  }
  .filter-row::-webkit-scrollbar { display: none; }

  /* Hide the items-view filter-search (mobile uses appbar search for items).
     Boxes/Techs views keep their inline search — they don't have an appbar search. */
  #view-items .filter-row .filter-search { display: none; }
  #view-boxes .filter-row,
  #view-techs .filter-row {
    flex-wrap: wrap;
    padding: 10px 14px 6px;
    overflow: visible;
  }
  #view-boxes .filter-row .filter-search,
  #view-techs .filter-row .filter-search {
    flex: 1; min-width: 0;
  }
  #view-boxes .filter-row .count-info,
  #view-techs .filter-row .count-info {
    order: 0; margin-left: auto;
  }
  #view-boxes .filter-row .count-info span:not(.mono),
  #view-techs .filter-row .count-info span:not(.mono) { display: inline; }
  /* Move the inline count-info out of the chip row — put it below */
  .filter-row .count-info {
    order: 99; margin: 0; padding: 0 2px 0 6px;
    font-size: 12px; font-family: var(--mono);
    color: var(--text-dim); flex-shrink: 0;
    white-space: nowrap;
  }
  .filter-row .count-info span:not(.mono) { display: none; }

  /* Pill → chip */
  .pill {
    flex-shrink: 0;
    border-radius: 999px;
    padding: 6px 12px;
    font-size: 13px;
    gap: 6px;
    background: var(--surface);
  }
  .pill .lbl { color: var(--text-dim); font-weight: 400; }
  .pill .val { color: var(--text); font-weight: 500; max-width: 120px; }
  .pill.active { border-color: var(--accent); background: var(--accent-bg); }
  .pill.active .lbl { color: var(--text); }

  /* On mobile, desktop dropdowns are replaced by bottom sheets : hide them */
  .pill .dropdown { display: none !important; }
  .pill.open .dropdown { display: none !important; }

  .clear-btn { font-size: 12px; padding: 6px 10px; flex-shrink: 0; }

  /* ─── Mobile card-based item list ─── */
  .table-wrap { display: block; padding: 0; flex: unset; min-height: unset; }
  .mobile-item-list {
    flex-direction: column; gap: 6px;
    padding: 4px 12px 20px;
  }
  .mobile-item-list.empty-wrap {
    padding: 64px 24px; text-align: center;
    color: var(--text-faint); font-size: 14px;
    display: block;
  }
  .mobile-item-list.empty-wrap a {
    color: var(--accent); cursor: pointer; text-decoration: underline;
  }
  .item-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 12px 14px;
    display: flex; flex-direction: column; gap: 7px;
    cursor: pointer;
    transition: background 0.1s;
  }
  .item-card:active { background: var(--surface-alt); }
  .item-card .row1 {
    display: flex; justify-content: space-between; align-items: center; gap: 10px;
  }
  .item-card .item-serial {
    font-family: var(--mono); font-size: 14px; font-weight: 500;
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  }
  .item-card .item-type { font-size: 13px; color: var(--text-dim); }
  .item-card .row3 {
    display: flex; justify-content: space-between; align-items: center; gap: 8px;
  }
  .item-card .item-motif {
    font-size: 12.5px; color: var(--text-faint);
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  }
  .item-card .item-date {
    font-family: var(--mono); font-size: 11.5px; color: var(--text-faint);
    flex-shrink: 0;
  }
  .items-hidden-hint {
    padding: 20px; text-align: center; color: var(--text-faint);
    font-size: 12px;
  }

  /* ─── Stocks grid → single column ─── */
  .stocks-grid { padding: 0 12px 20px; grid-template-columns: 1fr; gap: 8px; overflow: visible; }
  .box-card { padding: 14px; border-radius: 12px; }
  .box-card:hover { transform: none; }
  .box-card .id { font-size: 16px; }
  .box-card .id.serif { font-size: 18px; }
  .box-card .count-row .big { font-size: 22px; }

  /* ─── Stock detail ─── */
  .box-hero { padding: 12px 14px 6px; }
  .box-hero h1 { font-size: 22px; }
  .stats { padding: 8px 14px 4px; gap: 8px; grid-template-columns: repeat(3, 1fr); }
  .stat { padding: 10px 12px; border-radius: 10px; }
  .stat .val { font-size: 18px; margin-top: 4px; }
  .stat .hint { font-size: 10.5px; }
  .tabs {
    margin: 14px 14px 0; padding: 0;
    display: flex; gap: 4px;
    background: var(--surface-alt);
    border: none; border-radius: 10px;
    padding: 3px; flex-shrink: 0;
  }
  .tab {
    flex: 1; text-align: center; justify-content: center;
    padding: 7px 0; font-size: 13px;
    border-radius: 8px; border-bottom: none; margin-bottom: 0;
    color: var(--text-dim); transition: background 0.12s, color 0.12s;
  }
  .tab.active {
    background: var(--surface); color: var(--text);
    border-bottom-color: transparent;
    box-shadow: 0 1px 2px rgba(0,0,0,0.04);
  }
  .tab-panel { padding: 10px 0 0; overflow: visible; flex: unset; }

  /* Types tab : list rows with progress bars (hide desktop table) */
  #stock-tab-panel .table-container { display: none; }
  #stock-tab-panel .filter-row {
    padding: 0 14px 8px !important;
    overflow: visible;
    flex-wrap: wrap;
  }
  #stock-tab-panel .filter-row .filter-search {
    display: flex !important; flex: 1; min-width: 100%; margin-bottom: 4px;
  }
  #stock-tab-panel .filter-row .count-info { order: 0; margin-left: auto; }
  #stock-tab-panel .filter-row .count-info span:not(.mono) { display: inline; }
  #stock-tab-panel .mobile-types-list {
    display: flex; flex-direction: column;
    padding: 0 14px 20px;
  }
  .type-row {
    padding: 10px 2px; border-bottom: 1px solid var(--border);
    display: flex; flex-direction: column; gap: 6px; cursor: pointer;
  }
  .type-row:last-child { border-bottom: none; }
  .type-row:active { background: var(--surface-alt); }
  .type-row .type-head {
    display: flex; justify-content: space-between; align-items: center;
  }
  .type-row .type-head .name { font-size: 14px; }
  .type-row .type-head .qty { font-family: var(--mono); font-size: 13px; color: var(--text-dim); }
  .type-row .type-bar { height: 3px; background: var(--surface-alt); border-radius: 2px; overflow: hidden; }
  .type-row .type-bar > div { height: 100%; background: var(--accent); }

  /* Stock hero "Voir dans l'inventaire" link inline */
  .sub-line { flex-wrap: wrap; }

  /* ─── Bottom tab bar ─── */
  .tabbar {
    position: fixed; bottom: 0; left: 0; right: 0;
    background: rgba(250, 249, 245, 0.95);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border-top: 1px solid var(--border);
    padding: 8px 8px calc(8px + var(--safe-bottom));
    justify-content: space-around;
    z-index: 30;
  }
  .tb-item {
    flex: 1; display: flex; flex-direction: column;
    align-items: center; gap: 2px;
    padding: 6px 0; cursor: pointer;
    color: var(--text-faint);
    transition: color 0.1s;
  }
  .tb-item.active { color: var(--accent); }
  .tb-item .lbl { font-size: 10.5px; font-weight: 500; }

  /* ─── Bottom sheet (shared for item detail + filter) ─── */
  .sheet-backdrop {
    position: fixed; inset: 0;
    background: rgba(31,30,28,0.3);
    z-index: 40; opacity: 0; pointer-events: none;
    transition: opacity 0.2s;
  }
  .sheet-backdrop.open { opacity: 1; pointer-events: auto; }
  .sheet {
    position: fixed; left: 0; right: 0; bottom: 0;
    transform: translateY(100%);
    background: var(--surface);
    border-radius: 20px 20px 0 0;
    z-index: 41;
    padding: 10px 18px calc(20px + var(--safe-bottom));
    max-height: 85vh; overflow-y: auto;
    transition: transform 0.28s cubic-bezier(0.32, 0.72, 0, 1);
    box-shadow: 0 -8px 32px rgba(0,0,0,0.12);
  }
  .sheet.open { transform: translateY(0); }
  .sheet-handle {
    width: 36px; height: 4px;
    background: var(--border-strong);
    border-radius: 3px;
    margin: 0 auto 14px;
  }
  .sheet-head {
    display: flex; flex-direction: column; gap: 4px;
    margin-bottom: 14px;
  }
  .sheet-serial {
    font-family: var(--mono); font-size: 17px; font-weight: 500;
    word-break: break-all;
  }
  .sheet-chips {
    display: flex; gap: 6px; flex-wrap: wrap; margin-top: 8px;
  }
  .sheet .kv-list {
    display: flex; flex-direction: column; gap: 11px;
    font-size: 14px; padding: 14px 0 0;
    border-top: 1px solid var(--border);
    margin-top: 0;
  }
  .sheet .kv { justify-content: space-between; }
  .sheet .kv .v { text-align: right; }

  /* Filter sheet specifics */
  #filter-sheet .filter-sheet-title {
    font-family: var(--serif);
    font-size: 20px; font-weight: 500;
    margin: 2px 0 12px;
  }
  #filter-sheet-content .filter-opt {
    display: flex; justify-content: space-between; align-items: center;
    padding: 12px 2px; font-size: 15px;
    border-bottom: 1px solid var(--border);
    cursor: pointer;
  }
  #filter-sheet-content .filter-opt:last-child { border-bottom: none; }
  #filter-sheet-content .filter-opt.sel { color: var(--accent); font-weight: 500; }
  #filter-sheet-content .filter-opt .n {
    font-family: var(--mono); font-size: 12px; color: var(--text-faint);
  }
  #filter-sheet-content .filter-opt.sel .n { color: var(--accent); }
  #filter-clear-btn {
    margin-top: 14px; width: 100%; padding: 12px;
    background: var(--surface-alt); border: 1px solid var(--border);
    border-radius: 10px; font-family: var(--ui); font-size: 14px;
    color: var(--text); cursor: pointer;
  }
  #filter-clear-btn:active { background: var(--border); }

  /* Filter-row pills : active tint */
  .pill { background: var(--surface); }

  /* Toasts : stick to bottom above tab bar on mobile */
  .toasts {
    top: auto; right: 14px; left: 14px;
    bottom: calc(88px + var(--safe-bottom));
    align-items: center;
  }
  .toast { max-width: 100%; width: 100%; text-align: center; }

  /* Stock detail : back button on topbar is invisible but we replicate on appbar */
  #stock-back { display: none; }

  /* Box hero : hide "Voir dans l'inventaire" inline link on mobile — keep clean */
  .box-hero .sub-line #goto-items {
    display: inline-flex; font-size: 13px;
  }
}

/* Very small devices : tighter paddings */
@media (max-width: 400px) {
  .appbar { padding-left: 12px; padding-right: 12px; }
  .mobile-item-list { padding-left: 10px; padding-right: 10px; }
  .stocks-grid { padding-left: 10px; padding-right: 10px; }
  .stats { padding-left: 10px; padding-right: 10px; }
  .stat .val { font-size: 17px; }
  .tabs { margin-left: 10px; margin-right: 10px; }
}

/* =======================================================================
   ALERTES (seuils de stock)
   ======================================================================= */

/* Dot rouge sur le nav-item Alertes (desktop) quand breached > 0 */
.nav-item .alert-dot {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--warn); margin-left: 6px; flex-shrink: 0;
  animation: pulse-dot 2s ease-out infinite;
}
@keyframes pulse-dot {
  0% { box-shadow: 0 0 0 0 rgba(201, 100, 66, 0.5); }
  70% { box-shadow: 0 0 0 6px rgba(201, 100, 66, 0); }
  100% { box-shadow: 0 0 0 0 rgba(201, 100, 66, 0); }
}
.nav-item .alert-dot.hidden { display: none; }
.nav-item[data-view="alerts"].has-breached .count { color: var(--warn); font-weight: 600; }

/* Badge compteur rouge sur le bottom tabbar mobile */
.tb-item { position: relative; }
.tb-badge {
  position: absolute; top: 4px; right: calc(50% - 18px);
  min-width: 16px; height: 16px; padding: 0 4px;
  border-radius: 8px; background: var(--warn); color: white;
  font-size: 10px; font-weight: 600; font-family: var(--mono);
  display: flex; align-items: center; justify-content: center;
  line-height: 1;
}
.tb-badge.hidden { display: none; }

/* Carte d'alerte (seuil depasse) */
.alert-card {
  background: var(--warn-bg); border: 1px solid #E5C9B8;
  border-left: 3px solid var(--warn);
  border-radius: 8px; padding: 14px 16px;
  display: flex; align-items: flex-start; gap: 14px;
  transition: border-color 0.1s, transform 0.1s;
}
.alert-card.ok {
  background: var(--surface); border-color: var(--border);
  border-left: 3px solid var(--ok);
}
.alert-card .ac-icon {
  flex-shrink: 0; width: 28px; height: 28px; border-radius: 6px;
  background: var(--warn); color: white;
  display: flex; align-items: center; justify-content: center;
}
.alert-card.ok .ac-icon { background: var(--ok); }
.alert-card .ac-body { flex: 1; min-width: 0; }
.alert-card .ac-type { font-weight: 600; font-size: 13.5px; margin-bottom: 3px; }
.alert-card .ac-scope { font-size: 12px; color: var(--text-dim); margin-bottom: 8px; }
.alert-card .ac-meta { display: flex; gap: 14px; font-size: 12px; color: var(--text-dim); flex-wrap: wrap; }
.alert-card .ac-meta .v { color: var(--text); font-family: var(--mono); font-weight: 500; }
.alert-card .ac-meta .v.warn { color: var(--warn); }
.alert-card .ac-meta .v.ok { color: var(--ok); }
.alert-card .ac-note { margin-top: 6px; font-size: 12px; color: var(--text-dim); font-style: italic; }
.alert-card .ac-actions {
  flex-shrink: 0; display: flex; gap: 6px;
}
.alert-card .ac-btn {
  display: flex; align-items: center; justify-content: center;
  width: 26px; height: 26px; border-radius: 5px;
  border: 1px solid var(--border); background: var(--surface);
  color: var(--text-dim); cursor: pointer; transition: all 0.1s;
}
.alert-card .ac-btn:hover { color: var(--text); border-color: var(--border-strong); }
.alert-card .ac-btn.danger:hover { color: var(--warn); border-color: var(--warn); }

/* Section header entre "Alertes actives" et "Tous les seuils" */
.alerts-section-title {
  font-size: 11px; text-transform: uppercase; letter-spacing: 0.08em;
  color: var(--text-faint); font-weight: 500;
  margin: 16px 0 8px; padding-bottom: 6px;
  border-bottom: 1px solid var(--border);
}
.alerts-section-title:first-child { margin-top: 0; }
.alerts-list { display: flex; flex-direction: column; gap: 8px; }

/* Formulaire inline de creation/edition d'un seuil */
.alerts-form {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 8px; padding: 16px; animation: slideIn 0.15s ease-out;
}
.alerts-form .form-head {
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: 12px;
}
.alerts-form .form-title { font-weight: 500; font-size: 14px; }
.alerts-form .form-grid {
  display: grid; grid-template-columns: 1fr 1fr; gap: 10px 12px;
}
.alerts-form .form-grid .full { grid-column: 1 / -1; }
.alerts-form label { display: block; font-size: 11px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--text-faint); font-weight: 500; margin-bottom: 4px; }
.alerts-form select,
.alerts-form input[type="text"],
.alerts-form input[type="number"] {
  width: 100%; padding: 7px 10px;
  border: 1px solid var(--border); background: var(--surface);
  border-radius: 6px; font-family: var(--ui); font-size: 12.5px;
  color: var(--text); outline: none;
}
.alerts-form select:focus,
.alerts-form input:focus { border-color: var(--accent); }
.alerts-form .form-actions {
  display: flex; justify-content: flex-end; gap: 8px; margin-top: 12px;
}
.alerts-form .btn {
  padding: 7px 14px; border-radius: 6px; font-size: 12.5px;
  font-family: var(--ui); cursor: pointer; border: 1px solid var(--border);
  background: var(--surface); color: var(--text-dim);
}
.alerts-form .btn:hover { color: var(--text); border-color: var(--border-strong); }
.alerts-form .btn.primary {
  background: var(--accent); color: white; border-color: var(--accent);
}
.alerts-form .btn.primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.alerts-form .btn:disabled { opacity: 0.5; cursor: not-allowed; }
.alerts-form .form-error {
  color: var(--warn); font-size: 12px; margin-top: 8px;
}

/* Mobile : une seule colonne dans le form, alert-cards plus compactes */
@media (max-width: 900px) {
  .alerts-form .form-grid { grid-template-columns: 1fr; }
  .alert-card { padding: 12px; gap: 10px; }
  .alert-card .ac-icon { width: 24px; height: 24px; }
  .alert-card .ac-meta { font-size: 11.5px; gap: 10px; }
  .alert-card .ac-actions { flex-direction: column; }
  #view-alerts .page-head { padding: 16px 14px 10px; }
  #view-alerts .filter-row { padding: 0 14px 12px; }
  #view-alerts #alerts-content { padding-left: 14px; padding-right: 14px; }
  #view-alerts #alerts-form-wrap { padding-left: 14px; padding-right: 14px; }
}
