* { box-sizing: border-box; margin: 0; padding: 0; }
:root {
  --bg: #f5f5f7; --panel: #fff; --panel2: #f0f0f3; --text: #1d1d1f; --muted: #6e6e73;
  --border: rgba(0,0,0,.10); --input: #fff; --header: rgba(245,245,247,.82);
  --accent: #0071e3; --accent-fg: #fff; --danger: #ff453a;
  --shadow: 0 1px 2px rgba(0,0,0,.04), 0 6px 20px rgba(0,0,0,.06);
  --warnBg: #fff4e5; --warnFg: #9a5b00; --successBg: rgba(52,199,89,.12); --successFg: #1f8a3b;
  --font-base: 18px; --font-family: -apple-system, BlinkMacSystemFont, system-ui, "Segoe UI", sans-serif;
}
html, body { height: 100%; overflow: hidden; font-family: var(--font-family); font-size: var(--font-base); }
body { background: var(--bg); color: var(--text); display: flex; flex-direction: column; }
button { cursor: pointer; font: inherit; color: inherit; }
input, select { font: inherit; color: inherit; }
input:focus, select:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-thumb { background: rgba(0,0,0,.15); border-radius: 3px; }
.muted { color: var(--muted); } .small { font-size: .82em; } .accent { color: var(--accent); }
.badge-muted { font-size: .76em; color: var(--muted); }

/* Header */
.header { position: relative; z-index: 30; display: flex; align-items: center; gap: 10px; padding: 6px 12px; background: var(--header); backdrop-filter: blur(16px); border-bottom: 1px solid var(--border); flex: none; }
.logo { width: 26px; height: 26px; border-radius: 6px; background: var(--accent); color: var(--accent-fg); display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: .85em; flex: none; }
.shop-name { font-weight: 600; font-size: .95em; white-space: nowrap; }
.global-search { position: relative; width: 200px; flex: none; }
.search-results { position: absolute; top: calc(100% + 4px); left: 0; right: 0; background: var(--panel); border: 1px solid var(--border); border-radius: 9px; box-shadow: var(--shadow); max-height: 40vh; overflow: auto; display: none; z-index: 40; }
.search-results.show { display: block; }
.search-results .sr-group { padding: 5px 9px 2px; font-size: .68em; font-weight: 700; text-transform: uppercase; color: var(--muted); }
.search-results .sr-item { display: flex; align-items: center; gap: 5px; padding: 5px 9px; border: none; background: transparent; width: 100%; text-align: left; font-size: .82em; border-radius: 5px; }
.search-results .sr-item:hover { background: var(--panel2); }
.user-badge { display: flex; align-items: center; gap: 5px; padding: 4px 10px; background: var(--input); border: 1px solid var(--border); border-radius: 999px; font-size: .78em; font-weight: 600; flex: none; }

/* Tabs — now inside header */
.tabs { display: flex; gap: 2px; flex: 1; overflow-x: auto; margin: 0 10px; align-items: center; justify-content: center; border: none; padding: 0; background: none; }
.tab-btn { display: flex; align-items: center; gap: 4px; padding: 6px 10px; border: none; background: transparent; border-radius: 6px; font-weight: 500; font-size: .82em; color: var(--muted); white-space: nowrap; cursor: grab; user-select: none; border-bottom: none; margin: 0; }
.tab-btn.active { font-weight: 700; color: var(--text); background: var(--panel2); }
.tab-btn.dragging { opacity: .4; } .tab-btn.drop-target { border-left: 3px solid var(--accent); }

/* Main — no page scroll, only columns scroll */
main { flex: 1; padding: 8px; overflow: hidden; display: flex; flex-direction: column; }
.page { display: none; flex-direction: column; flex: 1; min-height: 0; overflow: hidden; }
.page.active { display: flex; }
.page-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 6px; gap: 8px; flex: none; }
.page-header h1 { font-size: 1.15em; font-weight: 700; }

/* Cards */
.card { background: var(--panel); border: 1px solid var(--border); border-radius: 9px; box-shadow: var(--shadow); overflow: hidden; display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.col-head { padding: 8px 10px; border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; gap: 5px; font-weight: 600; font-size: .92em; flex: none; }
.small-title { font-size: .74em; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .02em; }
.col-body { flex: 1; overflow-y: auto; overflow-x: hidden; min-height: 0; }
.col-footer { padding: 7px 9px; border-top: 1px solid var(--border); flex: none; }
.total-row { display: flex; align-items: center; justify-content: space-between; font-size: .95em; font-weight: 800; margin-bottom: 5px; }
.alert-box { padding: 7px 10px; background: var(--warnBg); color: var(--warnFg); border-radius: 7px; font-size: .82em; font-weight: 600; margin-bottom: 6px; flex: none; }

/* Panel row — splitter layout, all cards have explicit flex */
.panel-row { display: flex; flex: 1; gap: 0; min-height: 0; width: 100%; overflow: hidden; }
.panel-row > .card { flex: 0 0 auto; min-width: 50px; overflow: hidden; }
.panel-row > .card.flex-grow { flex: 1 1 0 !important; width: auto !important; min-width: 80px; }
.resize-handle { width: 6px; cursor: col-resize; background: transparent; flex: none; transition: background .15s; position: relative; }
.resize-handle::after { content:''; position:absolute; top:50%; left:50%; transform:translate(-50%,-50%); width:2px; height:24px; background:var(--border); border-radius:1px; transition:background .15s; }
.resize-handle:hover::after, .resize-handle.active::after { background: var(--accent); }
.resize-handle:hover, .resize-handle.active { background: rgba(0,113,227,.06); }

/* Table */
table { width: 100%; border-collapse: collapse; font-size: .9em; }
th { text-align: left; padding: 8px 10px; font-size: .75em; font-weight: 600; text-transform: uppercase; letter-spacing: .02em; color: var(--muted); border-bottom: 1px solid var(--border); white-space: nowrap; }
td { padding: 8px 10px; border-bottom: 1px solid var(--border); }
th.right, td.right { text-align: right; }
tr:hover { background: var(--panel2); } tr.active { background: var(--panel2); }
th.sortable { cursor: pointer; }

/* Buttons & inputs */
.btn { padding: 8px 13px; border-radius: 8px; border: none; font-weight: 700; font-size: .88em; }
.btn-primary { background: var(--accent); color: var(--accent-fg); }
.btn-outline { background: var(--input); border: 1px solid var(--border); font-weight: 600; }
.btn-danger { color: var(--danger); } .btn-sm { padding: 3px 7px; font-size: .76em; border-radius: 5px; }
.btn:disabled { opacity: .4; pointer-events: none; }
.input { border: 1px solid var(--border); background: var(--input); border-radius: 8px; padding: 8px 11px; width: 100%; font-size: .92em; }
.input-sm { padding: 5px 8px; font-size: .86em; border-radius: 6px; }
.field { display: flex; flex-direction: column; gap: 3px; margin-bottom: 9px; font-size: .78em; font-weight: 600; color: var(--muted); }
.chip { padding: 2px 8px; border-radius: 999px; border: 1px solid var(--border); background: transparent; color: var(--muted); font-size: .7em; font-weight: 600; white-space: nowrap; }
.chip.active { background: var(--accent); color: var(--accent-fg); border-color: var(--accent); }
.sidebar-item { display: block; width: 100%; padding: 8px 11px; border: none; border-bottom: 1px solid var(--border); background: transparent; text-align: left; font-size: .88em; cursor: pointer; }
.sidebar-item:hover { background: var(--panel2); }
.sidebar-item.active { background: var(--panel2); font-weight: 700; }
.sidebar-item.selected { background: rgba(0,113,227,.08); border-left: 3px solid var(--accent); }

/* Cart & bill */
.cart-line { display: flex; align-items: center; gap: 4px; padding: 5px 8px; border-bottom: 1px solid var(--border); }
.cart-line .name { font-weight: 600; font-size: .78em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cart-line .detail { font-size: .7em; color: var(--muted); }
.cart-line .line-total { font-size: .76em; font-weight: 700; color: var(--accent); }
.qty-btn { width: 20px; height: 20px; border-radius: 5px; border: 1px solid var(--border); background: var(--input); font-weight: 600; display: flex; align-items: center; justify-content: center; font-size: .82em; }
.bill-row { display: flex; align-items: center; justify-content: center; gap: 12px; padding: 5px 0; width: 100%; }
.bill-row .denom { min-width: 55px; font-weight: 700; font-size: .85em; text-align: right; }
.bill-row input { width: 50px; text-align: center; border: 1px solid var(--border); background: var(--input); border-radius: 6px; padding: 5px 4px; font-weight: 600; font-size: .85em; }
.bill-row .subtotal { font-size: .8em; color: var(--muted); min-width: 70px; text-align: left; }
.change-box { display: flex; align-items: center; justify-content: space-between; padding: 6px 8px; border-radius: 7px; font-weight: 700; font-size: .85em; }
.change-positive { background: var(--successBg); color: var(--successFg); }
.change-negative { background: rgba(255,69,58,.12); color: var(--danger); }
.low-stock { color: var(--warnFg); font-weight: 700; }
.price-cheap { color: var(--successFg); font-weight: 700; }

/* Custom alert (replaces browser alert/confirm) */
.custom-alert-overlay { position: fixed; inset: 0; z-index: 100; background: rgba(0,0,0,.4); display: flex; align-items: center; justify-content: center; animation: fadeIn .15s ease; }
.custom-alert { background: var(--panel); border-radius: 14px; padding: 24px; min-width: 300px; max-width: 400px; box-shadow: 0 20px 60px rgba(0,0,0,.3); animation: alertPop .2s ease; text-align: center; }
.custom-alert h3 { font-size: 1.1em; margin-bottom: 8px; }
.custom-alert p { font-size: .9em; color: var(--muted); margin-bottom: 16px; }
.custom-alert .alert-actions { display: flex; gap: 8px; justify-content: center; }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes alertPop { from { opacity: 0; transform: scale(.9); } to { opacity: 1; transform: none; } }

/* Context menu */
.ctx-menu { position: fixed; z-index: 80; min-width: 150px; background: var(--panel); border: 1px solid var(--border); border-radius: 9px; box-shadow: 0 8px 30px rgba(0,0,0,.18); padding: 3px; animation: ctxIn .1s ease; }
@keyframes ctxIn { from { opacity: 0; transform: scale(.95); } to { opacity: 1; transform: none; } }
.ctx-item { display: flex; align-items: center; gap: 6px; width: 100%; padding: 5px 9px; border: none; background: transparent; border-radius: 5px; text-align: left; font-size: .8em; font-weight: 500; }
.ctx-item:hover { background: var(--accent); color: var(--accent-fg); }
.ctx-danger { color: var(--danger); } .ctx-sep { height: 1px; background: var(--border); margin: 2px 6px; }

/* Toast */
.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); z-index: 70; padding: 8px 14px; background: var(--panel); border: 1px solid var(--border); border-radius: 8px; box-shadow: var(--shadow); font-weight: 600; font-size: .82em; display: none; }
.toast.show { display: flex; align-items: center; gap: 6px; animation: slideUp .2s ease; }
@keyframes slideUp { from { opacity: 0; transform: translate(-50%, 8px); } to { opacity: 1; transform: translate(-50%, 0); } }

/* Modal */
.modal-overlay { position: fixed; inset: 0; z-index: 50; background: rgba(0,0,0,.35); display: none; align-items: center; justify-content: center; padding: 12px; }
.modal-overlay.show { display: flex; }
.modal { width: 100%; max-width: 420px; max-height: 82vh; overflow: auto; background: var(--panel); border-radius: 13px; box-shadow: 0 20px 55px rgba(0,0,0,.28); }
.modal-head { padding: 12px 16px; border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; font-size: 1em; font-weight: 700; }
.modal-body { padding: 16px; }
.modal-foot { padding: 10px 16px; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: 6px; }

/* Print */
@media print { body > *:not(#print-area) { display: none !important; } #print-area { display: block !important; } @page { margin: 8mm; } }
#print-area { display: none; }

/* Settings color swatches */
.color-swatch { width: 28px; height: 28px; border-radius: 50%; border: 3px solid transparent; cursor: pointer; }
.color-swatch.active { border-color: var(--text); }
.theme-card { padding: 10px; border: 2px solid var(--border); border-radius: 9px; cursor: pointer; text-align: center; font-size: .8em; font-weight: 600; }
.theme-card.active { border-color: var(--accent); }

/* Stock cards (Trello style) */
.stock-card { padding: 8px 10px; margin: 4px 6px; background: var(--panel2); border: 1px solid var(--border); border-radius: 7px; cursor: grab; font-size: .88em; transition: box-shadow .15s, transform .15s, opacity .15s; }
.stock-card:hover { box-shadow: 0 2px 8px rgba(0,0,0,.1); }
.stock-card.dragging { opacity: .4; transform: rotate(3deg) scale(1.02); box-shadow: 0 8px 24px rgba(0,0,0,.15); }
.stock-card.highlight { border-color: var(--accent); background: rgba(0,113,227,.1); box-shadow: 0 0 0 2px rgba(0,113,227,.25), 0 2px 8px rgba(0,113,227,.15); transform: scale(1.02); }
.stock-card.dimmed { opacity: .35; filter: grayscale(.3); }
.stock-card .card-name { font-weight: 600; font-size: .85em; margin-bottom: 2px; }
.stock-card .card-qty { font-size: 1.1em; font-weight: 800; }
.stock-card .card-meta { font-size: .7em; color: var(--muted); }
.stock-slot { min-height: 60px; transition: background .15s; }
.stock-slot.drag-over { background: rgba(0,113,227,.06); border-radius: 6px; }
.stock-col-name { cursor: pointer; }
.stock-col-name:hover { text-decoration: underline; }

/* Zebra striping for lists */
.sidebar-item:nth-child(even) { background: rgba(0,0,0,.015); }
.sidebar-item:nth-child(even):hover { background: var(--panel2); }
.sidebar-item.active:nth-child(even) { background: var(--panel2); }
.cart-line:nth-child(even) { background: rgba(0,0,0,.015); }
.stock-card:nth-child(even) { background: rgba(0,0,0,.02); }
.stock-card:nth-child(even):hover { background: var(--panel2); }

/* Selected state (bold) */
.sidebar-item.selected, .sidebar-item.active { font-weight: 700; }

/* Draggable columns (ventes page) */
.ventes-col { transition: transform .2s ease, box-shadow .2s ease, opacity .2s ease; }
.ventes-col.col-dragging { opacity: .6; transform: scale(.97) rotate(1.5deg); box-shadow: 0 12px 36px rgba(0,0,0,.18); z-index: 10; }
.ventes-col.col-drop-target { border: 2px dashed var(--accent); }

/* Inline editable title */
.editable-title { cursor: text; border-bottom: 1px dashed transparent; transition: border-color .15s; }
.editable-title:hover { border-bottom-color: var(--muted); }

/* Responsive */
@media (max-width: 1024px) {
  .panel-row { flex-wrap: wrap; overflow: auto; }
  .panel-row > .card { min-width: 250px; min-height: 200px; flex: 1 1 45%; }
  .resize-handle { display: none; }
}
@media (max-width: 768px) {
  .header { flex-wrap: wrap; padding: 6px 8px; gap: 6px; }
  .tabs { order: 10; flex-basis: 100%; margin: 4px 0 0; justify-content: flex-start; }
  .global-search { width: 140px; }
  .panel-row { flex-direction: column !important; overflow: auto; }
  .panel-row > .card { width: 100% !important; min-height: 180px; max-height: 50vh; flex: none !important; }
  .tab-btn { padding: 5px 7px; font-size: .75em; }
  main { padding: 6px; }
}
@media (max-width: 480px) {
  .global-search { display: none; }
  .user-badge span:not(.user-icon) { display: none; }
  .shop-name { display: none; }
  .tabs { margin: 4px 0 0 0; }
  .tab-btn { padding: 4px 6px; font-size: .7em; gap: 2px; }
  .header { padding: 4px 6px; }
  .panel-row > .card { max-height: 40vh; }
  .btn { padding: 6px 10px; font-size: .82em; }
  .col-head { font-size: .85em; padding: 6px 8px; }
}
