﻿/* ============================================================
   SmartCof UI — mobile-first design system (Kendo-free)
   ============================================================ */
:root {
  --brand: #185FA5;
  --brand-dark: #0C447C;
  --brand-light: #E6F1FB;
  --accent: #8EB703;
  --accent-dark: #3B6D11;
  --accent-light: #EAF3DE;
  --success: #16a34a;
  --danger: #dc2626;
  --danger-light: #FCEBEB;
  --warning: #d97706;
  --warning-light: #FAEEDA;
  --text-1: #111827;
  --text-2: #6b7280;
  --text-3: #9ca3af;
  --surface: #ffffff;
  --surface-alt: #f5f6f8;
  --border: #e5e7eb;
  --radius: 12px;
  --radius-sm: 8px;
  --tap: 44px;
  --nav-h: 60px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

/* Manual theme: html[data-theme="dark"] wins; otherwise follow the phone setting */
html[data-theme="dark"] {
  --brand-light: #0C2C4A;
  --accent-light: #1d2b0e;
  --danger-light: #3a1414;
  --warning-light: #3a2a0e;
  --text-1: #f3f4f6;
  --text-2: #9ca3af;
  --text-3: #6b7280;
  --surface: #1c1e22;
  --surface-alt: #121417;
  --border: #2c2f36;
}
@media (prefers-color-scheme: dark) {
  html:not([data-theme="light"]) {
    --brand-light: #0C2C4A;
    --accent-light: #1d2b0e;
    --danger-light: #3a1414;
    --warning-light: #3a2a0e;
    --text-1: #f3f4f6;
    --text-2: #9ca3af;
    --text-3: #6b7280;
    --surface: #1c1e22;
    --surface-alt: #121417;
    --border: #2c2f36;
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  font-family: var(--font);
  color: var(--text-1);
  background: var(--surface-alt);
  font-size: 15px;
  -webkit-tap-highlight-color: transparent;
  -webkit-font-smoothing: antialiased;
}

/* ---------- Layout shell ---------- */
.sc-page {
  max-width: 640px;
  margin: 0 auto;
  padding: 12px 14px calc(var(--nav-h) + 24px);
}
.sc-topbar {
  position: sticky;
  top: 0;
  z-index: 50;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 10px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.sc-topbar .brand { display: flex; align-items: center; gap: 8px; }
.sc-topbar .brand img { width: 32px; height: 32px; }
.sc-topbar .brand b { font-size: 16px; color: var(--text-1); }
.sc-topbar .brand b span { color: var(--accent); }
.sc-topbar .right { display: flex; align-items: center; gap: 8px; }
.sc-codechip {
  display: inline-flex; align-items: center; gap: 6px;
  background: var(--brand-light); color: var(--brand);
  border: none; border-radius: 999px; cursor: pointer;
  padding: 7px 12px; font-family: var(--font);
  font-weight: 700; font-size: 12.5px; letter-spacing: .3px;
  max-width: 150px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.sc-iconbtn {
  width: 36px; height: 36px; border-radius: 50%;
  background: transparent; border: 1px solid var(--border);
  color: var(--text-2); cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  font-size: 16px; line-height: 1;
}
.sc-iconbtn:active { transform: scale(0.92); }

/* ---------- Bottom navigation ---------- */
.sc-bottomnav {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  z-index: 100;
  height: calc(var(--nav-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: var(--surface);
  border-top: 1px solid var(--border);
  display: grid;
  grid-template-columns: repeat(5, 1fr);
}
.sc-bottomnav a {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 2px; text-decoration: none;
  color: var(--text-3); font-size: 10.5px; font-weight: 500;
}
.sc-bottomnav a svg { width: 22px; height: 22px; }
.sc-bottomnav a.active { color: var(--brand); }
.sc-bottomnav a:active { transform: scale(0.94); }

/* ---------- Cards & KPIs ---------- */
.sc-card {
  background: var(--surface);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  padding: 14px 16px;
  margin-bottom: 12px;
}
.sc-kpi-hero {
  background: var(--brand);
  color: #fff;
  border-radius: var(--radius);
  padding: 16px 18px;
  margin-bottom: 12px;
}
.sc-kpi-hero .label { font-size: 12px; opacity: .85; }
.sc-kpi-hero .value { font-size: 30px; font-weight: 700; margin-top: 2px; font-variant-numeric: tabular-nums; }
.sc-kpi-hero .value small { font-size: 14px; font-weight: 500; opacity: .85; }
.sc-kpi-hero .meta { display: flex; gap: 16px; margin-top: 10px; font-size: 12px; opacity: .9; }

.sc-kpi-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 12px; }
.sc-kpi {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 12px 14px;
}
.sc-kpi .label { font-size: 12px; color: var(--text-2); }
.sc-kpi .value { font-size: 19px; font-weight: 700; margin-top: 2px; font-variant-numeric: tabular-nums; }
.sc-kpi.green .value { color: var(--success); }
.sc-kpi.red .value { color: var(--danger); }
.sc-kpi.blue .value { color: var(--brand); }

/* ---------- Lists ---------- */
.sc-section-head {
  display: flex; justify-content: space-between; align-items: baseline;
  margin: 16px 2px 8px;
}
.sc-section-head h2 { font-size: 15px; font-weight: 600; margin: 0; }
.sc-section-head .muted { font-size: 12px; color: var(--text-2); }

.sc-list { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.sc-row {
  display: flex; justify-content: space-between; align-items: center;
  gap: 12px; padding: 12px 14px; min-height: var(--tap);
  border-top: 1px solid var(--border);
}
.sc-row:first-child { border-top: none; }
.sc-row .main { min-width: 0; flex: 1; }
.sc-row .title { font-size: 14px; font-weight: 600; }
.sc-row .title .num { color: var(--brand); }
.sc-row .sub {
  font-size: 12.5px; color: var(--text-2); margin-top: 2px;
  overflow: hidden; text-overflow: ellipsis; display: -webkit-box;
  -webkit-line-clamp: 1; -webkit-box-orient: vertical;
}
.sc-row.expanded .sub { -webkit-line-clamp: unset; }
.sc-row .amount { font-size: 14.5px; font-weight: 700; white-space: nowrap; font-variant-numeric: tabular-nums; }
.sc-row .time { font-size: 11.5px; color: var(--text-3); text-align: right; }

/* ---------- Badges ---------- */
.sc-badge {
  display: inline-block; padding: 3px 10px; border-radius: 999px;
  font-size: 12px; font-weight: 600; font-variant-numeric: tabular-nums;
}
.sc-badge.ok    { background: var(--accent-light); color: var(--accent-dark); }
.sc-badge.low   { background: var(--warning-light); color: var(--warning); }
.sc-badge.out   { background: var(--danger-light); color: var(--danger); }
.sc-badge.brand { background: var(--brand-light); color: var(--brand); }

/* ---------- Buttons & inputs ---------- */
.sc-btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: var(--tap); padding: 0 20px; width: 100%;
  border: none; border-radius: 10px; cursor: pointer;
  font-family: var(--font); font-size: 15px; font-weight: 600;
  transition: transform .12s ease, opacity .12s ease;
}
.sc-btn:active { transform: scale(0.98); }
.sc-btn.primary { background: var(--brand); color: #fff; }
.sc-btn.ghost   { background: transparent; color: var(--brand); border: 1px solid var(--border); }
.sc-btn.danger  { background: var(--danger); color: #fff; }
.sc-btn.small   { min-height: 36px; width: auto; font-size: 13.5px; padding: 0 14px; }

.sc-input, .sc-select {
  width: 100%; min-height: var(--tap);
  padding: 10px 14px;
  border: 1px solid var(--border); border-radius: 10px;
  background: var(--surface); color: var(--text-1);
  font-family: var(--font); font-size: 15px;
  appearance: none; -webkit-appearance: none;
}
.sc-input:focus, .sc-select:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-light); }
.sc-select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' fill='none'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%236b7280' stroke-width='2' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 14px center;
  padding-right: 38px;
}
.sc-field { margin-bottom: 14px; }
.sc-field label { display: block; font-size: 13px; font-weight: 600; color: var(--text-2); margin-bottom: 6px; }
.sc-error { color: var(--danger); font-size: 12.5px; margin-top: 4px; min-height: 16px; }

.sc-search { position: sticky; top: 58px; z-index: 40; padding: 4px 0 10px; background: var(--surface-alt); }

/* ---------- Segmented control ---------- */
.sc-seg {
  display: grid; grid-auto-flow: column; gap: 4px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 10px; padding: 4px; margin-bottom: 12px;
}
.sc-seg button {
  border: none; background: transparent; border-radius: 8px;
  min-height: 36px; font-family: var(--font); font-size: 13px; font-weight: 600;
  color: var(--text-2); cursor: pointer;
}
.sc-seg button.active { background: var(--brand); color: #fff; }

/* ---------- Chips ---------- */
.sc-chips { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 6px; margin-bottom: 8px; scrollbar-width: none; }
.sc-chips::-webkit-scrollbar { display: none; }
.sc-chip {
  flex: 0 0 auto; padding: 8px 16px; border-radius: 999px;
  background: var(--surface); border: 1px solid var(--border);
  color: var(--text-2); font-size: 13px; font-weight: 600; cursor: pointer; font-family: var(--font);
}
.sc-chip.active { background: var(--brand); border-color: var(--brand); color: #fff; }

/* ---------- Bottom sheet ---------- */
.sc-sheet-backdrop {
  position: fixed; inset: 0; z-index: 200;
  background: rgba(0,0,0,.45);
  opacity: 0; pointer-events: none; transition: opacity .2s ease;
}
.sc-sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 201;
  background: var(--surface);
  border-radius: 18px 18px 0 0;
  max-height: 88vh; overflow-y: auto;
  padding: 8px 18px calc(20px + env(safe-area-inset-bottom));
  transform: translateY(105%); transition: transform .25s cubic-bezier(.32,.72,.35,1);
}
.sc-sheet-open .sc-sheet-backdrop { opacity: 1; pointer-events: auto; }
.sc-sheet-open .sc-sheet { transform: translateY(0); }
.sc-sheet .grabber { width: 40px; height: 4px; border-radius: 2px; background: var(--border); margin: 6px auto 12px; }
.sc-sheet h3 { font-size: 17px; font-weight: 700; margin: 0 0 14px; }

/* ---------- Toast ---------- */
.sc-toast {
  position: fixed; left: 50%; bottom: calc(var(--nav-h) + 20px); z-index: 300;
  transform: translate(-50%, 20px);
  background: var(--text-1); color: var(--surface);
  padding: 12px 20px; border-radius: 999px;
  font-size: 14px; font-weight: 500;
  opacity: 0; pointer-events: none; transition: all .25s ease;
  max-width: 90vw; text-align: center;
}
.sc-toast.show { opacity: 1; transform: translate(-50%, 0); }
.sc-toast.error { background: var(--danger); color: #fff; }
.sc-toast.success { background: var(--success); color: #fff; }

/* ---------- Skeleton loaders ---------- */
@keyframes sc-shimmer { 0% { background-position: -400px 0; } 100% { background-position: 400px 0; } }
.sc-skel {
  border-radius: var(--radius-sm);
  background: linear-gradient(90deg, var(--border) 25%, var(--surface-alt) 37%, var(--border) 63%);
  background-size: 800px 100%;
  animation: sc-shimmer 1.3s infinite linear;
}
.sc-skel.row { height: 58px; margin-bottom: 8px; }
.sc-skel.hero { height: 108px; margin-bottom: 12px; border-radius: var(--radius); }

/* ---------- Empty state ---------- */
.sc-empty { text-align: center; padding: 44px 20px; color: var(--text-2); }
.sc-empty .icon { font-size: 40px; margin-bottom: 10px; }
.sc-empty .msg { font-size: 14.5px; font-weight: 500; }

/* ---------- Category / product tiles ---------- */
.sc-tiles { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.sc-tile {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); overflow: hidden; position: relative;
}
.sc-tile img { width: 100%; height: 110px; object-fit: cover; display: block; background: var(--surface-alt); }
.sc-tile .body { padding: 10px 12px; }
.sc-tile .name { font-size: 14px; font-weight: 600; }
.sc-tile .count { font-size: 12px; color: var(--text-2); margin-top: 2px; }
.sc-tile .price { font-size: 13.5px; font-weight: 700; color: var(--brand); margin-top: 2px; font-variant-numeric: tabular-nums; }
.sc-tile .old { color: var(--text-3); text-decoration: line-through; font-weight: 500; font-size: 12px; margin-right: 6px; }
.sc-tile .actions { display: flex; border-top: 1px solid var(--border); }
.sc-tile .actions button {
  flex: 1; min-height: 40px; border: none; background: transparent;
  font-family: var(--font); font-size: 12.5px; font-weight: 600; cursor: pointer; color: var(--text-2);
}
.sc-tile .actions button + button { border-left: 1px solid var(--border); }
.sc-tile .actions button.edit { color: var(--brand); }
.sc-tile .actions button.del { color: var(--danger); }
.sc-tile .flag {
  position: absolute; top: 8px; left: 8px;
}

/* ---------- FAB ---------- */
.sc-fab {
  position: fixed; right: 18px; bottom: calc(var(--nav-h) + 18px + env(safe-area-inset-bottom)); z-index: 90;
  width: 54px; height: 54px; border-radius: 50%;
  background: var(--brand); color: #fff; border: none;
  font-size: 26px; line-height: 1; cursor: pointer;
  box-shadow: 0 4px 14px rgba(24,95,165,.4);
  transition: transform .12s ease;
}
.sc-fab:active { transform: scale(0.92); }

/* ---------- Pull to refresh hint ---------- */
.sc-ptr { text-align: center; font-size: 12px; color: var(--text-3); height: 0; overflow: hidden; transition: height .2s; }
.sc-ptr.visible { height: 28px; padding-top: 6px; }

/* ---------- Revenue detail rows ---------- */
.sc-kv { display: flex; justify-content: space-between; padding: 10px 0; border-top: 1px solid var(--border); font-size: 14px; }
.sc-kv:first-child { border-top: none; }
.sc-kv .k { color: var(--text-2); }
.sc-kv .v { font-weight: 700; font-variant-numeric: tabular-nums; }

/* ---------- Frozen header + inner scroll (Historique) ---------- */
.sc-frozen {
  position: sticky; top: 58px; z-index: 45;
  background: var(--surface-alt);
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 10px;
}
.sc-innerscroll {
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  padding-bottom: 12px;
  cursor: grab;
}
.sc-innerscroll.dragging { cursor: grabbing; user-select: none; }

/* ---------- Utility ---------- */
.sc-muted { color: var(--text-2); font-size: 12.5px; }
.sc-center { text-align: center; }
.sc-mt { margin-top: 14px; }
.sc-updated { text-align: center; font-size: 12px; color: var(--text-3); margin: 6px 0 12px; }
.sc-hidden { display: none !important; }

/* Desktop: widen and center */
@media (min-width: 900px) {
  .sc-page { max-width: 760px; }
  .sc-tiles { grid-template-columns: repeat(3, 1fr); }
}

/* ---------- Bottom-nav alert dot (e.g. low stock on Plus) ---------- */
.sc-bottomnav a { position: relative; }
.sc-navdot {
  position: absolute; top: 6px; right: calc(50% - 18px);
  min-width: 16px; height: 16px; padding: 0 4px; border-radius: 999px;
  background: var(--danger); color: #fff; font-size: 10px; font-weight: 700;
  display: none; align-items: center; justify-content: center; line-height: 1;
}
.sc-navdot.show { display: flex; }
