:root {
  --bg: #0F172A;
  --surface: #1E293B;
  --surface-soft: #162032;
  --border: rgba(255,255,255,.08);
  --text: #EBEBEB;
  --muted: #94A3B8;
  --accent: #F97316;
  --accent-deep: #DE5E04;
  --success: #4ADE80;
  --danger: #F87171;
  --navy: #0B1120;
  --radius: 14px;
  --font: "Plus Jakarta Sans", system-ui, sans-serif;
  --bottom-nav-h: 0px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}
* { box-sizing: border-box; }
html, body {
  margin: 0; padding: 0; min-height: 100%;
  background: var(--bg); color: var(--text);
  font-family: var(--font);
  overflow-x: hidden;
}
button, input, select { font: inherit; }
a { color: var(--accent); }

.app-shell { display: flex; min-height: 100vh; min-height: 100dvh; }
.sidebar {
  width: 248px; background: linear-gradient(180deg, #0B1220 0%, var(--navy) 100%);
  border-right: 1px solid var(--border);
  padding: 16px 12px; display: flex; flex-direction: column; gap: 6px;
  flex-shrink: 0;
  position: sticky; top: 0; height: 100vh; height: 100dvh;
  overflow-y: auto;
}
.sidebar .brand {
  display: flex; align-items: center; justify-content: center;
  gap: 10px; margin-bottom: 10px; padding: 6px 4px 14px;
  border-bottom: 1px solid var(--border);
}
.sidebar .brand img,
.brand-logo {
  height: 64px; width: auto; max-width: 100%;
  object-fit: contain; display: block;
}
.brand-logo--login {
  width: auto;
  height: auto;
  max-width: min(220px, 70%);
  max-height: 120px;
  margin: 0 auto 8px;
  object-fit: contain;
}
.sidebar-spacer { flex: 1; min-height: 12px; }
.nav-list {
  display: flex; flex-direction: column; gap: 4px;
}
.nav-btn {
  display: flex; align-items: center; gap: 12px;
  width: 100%;
  text-align: left; background: transparent; border: 1px solid transparent;
  color: var(--muted); padding: 11px 12px; border-radius: 12px; cursor: pointer;
  white-space: nowrap; font-weight: 600; font-size: 14px;
  transition: background .15s ease, color .15s ease, border-color .15s ease;
}
.nav-btn .nav-ico {
  width: 22px; height: 22px; flex-shrink: 0;
  display: inline-flex; align-items: center; justify-content: center;
  color: inherit;
}
.nav-btn .nav-ico svg { width: 20px; height: 20px; display: block; }
.nav-btn .nav-label { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.nav-btn .nav-label-short { display: none; }
.nav-btn:hover {
  background: rgba(255,255,255,.04); color: var(--text);
}
.nav-btn.active {
  background: rgba(249,115,22,.14);
  color: #fff;
  border-color: rgba(249,115,22,.4);
  box-shadow: inset 3px 0 0 var(--accent);
}
.nav-btn.active .nav-ico { color: var(--accent); }
.nav-logout {
  margin-top: 4px;
  border-color: var(--border);
  color: var(--muted);
}
.nav-logout:hover {
  border-color: rgba(248,113,113,.45);
  color: var(--danger);
  background: rgba(248,113,113,.08);
}
.main { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 12px 20px; border-bottom: 1px solid var(--border);
  background: rgba(15,23,42,.9);
  backdrop-filter: blur(14px); position: sticky; top: 0; z-index: 10;
  flex-wrap: wrap;
}
.topbar-ctx, .topbar-status {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap; min-width: 0;
}
.pill-strong {
  color: var(--text);
  border-color: rgba(249,115,22,.35);
  background: rgba(249,115,22,.1);
  font-weight: 700;
}
.content { padding: 20px; flex: 1; }
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 16px;
}
.grid { display: grid; gap: 14px; }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
.grid-2 { grid-template-columns: repeat(2, 1fr); }
.muted { color: var(--muted); }
.stat-value { font-size: 28px; font-weight: 800; letter-spacing: -.5px; }
.btn {
  border: none; border-radius: 12px; padding: 10px 16px; cursor: pointer;
  font-weight: 700; color: #fff;
  background: linear-gradient(135deg, var(--accent), var(--accent-deep));
}
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn-ghost {
  background: transparent; border: 1px solid var(--border); color: var(--text);
  border-radius: 12px; padding: 10px 14px; cursor: pointer;
}
.btn-danger {
  border: none; border-radius: 12px; padding: 10px 16px; cursor: pointer;
  font-weight: 700; color: #fff;
  background: linear-gradient(135deg, #dc2626, #991b1b);
}
.trial-card .trial-dates { font-size: 14px; }
.trial-counter {
  display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap;
  padding: 10px 12px; border-radius: 10px;
  background: var(--surface-soft); border: 1px solid var(--border);
}
.trial-counter.trial-ok { border-color: color-mix(in srgb, var(--accent) 40%, var(--border)); }
.trial-counter.trial-ended { color: var(--danger, #dc2626); }
.link-forgot {
  display: block; width: 100%; margin: 2px 0 4px;
  background: none; border: none; padding: 0;
  color: var(--accent); font-weight: 600; font-size: 14px;
  text-align: right; cursor: pointer; text-decoration: underline;
  text-underline-offset: 3px;
}
.link-forgot:hover { color: #fb923c; }
.login-card .stack { text-align: left; }
.login-card > .muted { text-align: center; }
.input, .select {
  width: 100%; background: var(--surface-soft); color: var(--text);
  border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px;
}
.table-scroll {
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}
.table { width: 100%; border-collapse: collapse; min-width: 0; }
.table th, .table td { padding: 10px 8px; border-bottom: 1px solid var(--border); text-align: left; }
.table th { color: var(--muted); font-size: 12px; letter-spacing: .04em; }
.badge {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 10px; border-radius: 999px; font-size: 12px; font-weight: 700;
}
.badge.online { background: #052E16; color: var(--success); border: 1px solid rgba(74,222,128,.45); }
.badge.offline { background: #450A0A; color: var(--danger); border: 1px solid rgba(248,113,113,.45); }
.login-wrap {
  min-height: 100vh; min-height: 100dvh; display: grid; place-items: center; padding: 24px;
  background: radial-gradient(ellipse at top, #1E293B 0%, var(--bg) 55%);
}
.login-card {
  width: min(480px, 100%);
  text-align: center;
}
.login-card--wide { width: min(560px, 100%); }
.login-card h1 { margin: 8px 0 4px; font-size: 28px; text-align: center; }
.login-success {
  margin: 0;
  padding: 10px 12px;
  border-radius: 10px;
  background: rgba(74, 222, 128, 0.12);
  border: 1px solid rgba(74, 222, 128, 0.35);
  color: var(--success);
  font-size: 14px;
  font-weight: 600;
  text-align: left;
}
.ob-steps {
  display: flex;
  justify-content: center;
  gap: 8px;
  margin: 4px 0 8px;
}
.ob-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--border);
}
.ob-dot.active { background: var(--accent); }
.ob-dot.done { background: rgba(74, 222, 128, 0.7); }
.ob-actions {
  display: flex;
  gap: 10px;
  margin-top: 4px;
}
.ob-actions .btn,
.ob-actions .btn-ghost { flex: 1; }
.ob-error {
  margin: 0;
  color: var(--danger);
  font-size: 13px;
  text-align: left;
}
.ob-row {
  display: grid;
  gap: 8px;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface-soft);
  text-align: left;
}
.ob-row-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  font-weight: 700;
  color: var(--muted);
}
.ob-row-grid {
  display: grid;
  grid-template-columns: 1fr 1.4fr;
  gap: 8px;
}
.ob-remove {
  background: none;
  border: none;
  color: var(--danger);
  cursor: pointer;
  font-size: 12px;
  font-weight: 600;
  padding: 0;
}
.stack { display: flex; flex-direction: column; gap: 12px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.page-head {
  display: flex; justify-content: space-between; align-items: center;
  gap: 12px; flex-wrap: wrap; margin-bottom: 12px;
}
.page-head h2 { margin: 0; }
.cart-line {
  display: flex; justify-content: space-between; gap: 10px; align-items: center;
  padding: 10px 0; border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}
.toast {
  position: fixed; bottom: 20px; right: 20px; z-index: 100;
  background: var(--surface); border: 1px solid var(--border);
  padding: 12px 16px; border-radius: 12px; max-width: 360px;
  box-shadow: 0 12px 40px rgba(0,0,0,.4);
}
.update-banner {
  background: rgba(249,115,22,.15); border-bottom: 1px solid rgba(249,115,22,.35);
  padding: 10px 20px; display: flex; justify-content: space-between; align-items: center; gap: 12px;
  flex-wrap: wrap;
}
.install-banner {
  background: rgba(74,222,128,.1); border-bottom: 1px solid rgba(74,222,128,.35);
  padding: 10px 20px; display: flex; justify-content: space-between; align-items: center; gap: 12px;
  flex-wrap: wrap; font-size: 14px;
}
.install-banner-msg {
  display: inline-flex; align-items: center; gap: 10px; min-width: 0;
}
.pwa-install-btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 10px;
}
.pwa-install-btn:disabled {
  opacity: .55; cursor: not-allowed;
}
.pwa-install-ico {
  width: 28px; height: 28px; border-radius: 8px;
  object-fit: cover; flex-shrink: 0;
  background: #0F172A; border: 1px solid var(--border);
}
.pwa-ios-help {
  padding: 8px 10px; border-radius: 10px;
  background: rgba(255,255,255,.04); border: 1px solid var(--border);
}
.hidden { display: none !important; }
.pill {
  background: rgba(255,255,255,.06); border: 1px solid var(--border);
  border-radius: 999px; padding: 4px 10px; font-size: 12px; color: var(--muted);
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,.55); z-index: 80;
  display: grid; place-items: center; padding: 16px;
}
.modal {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 18px; width: min(520px, 100%);
  max-height: 90vh; max-height: 90dvh; overflow: auto;
}
.modal h3 { margin-top: 0; }
.filters { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 12px; }
.filters .input, .filters .select { width: auto; min-width: 140px; flex: 1; }
.tag-annulee { color: var(--danger); font-weight: 700; font-size: 12px; }
.drawer-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 10px; }
.mini { font-size: 12px; color: var(--muted); }
.cart-compact .cart-line {
  padding: 8px 0; gap: 8px;
}
.cart-compact .cart-line .qty-ctrl {
  display: inline-flex; align-items: center; gap: 4px;
}
.cart-compact .cart-line .qty-ctrl button {
  width: 32px; height: 32px; padding: 0; border-radius: 8px;
  border: 1px solid var(--border); background: var(--surface-soft);
  color: var(--text); cursor: pointer; font-weight: 700;
}
.cart-compact .cart-line .qty-ctrl button:hover { border-color: var(--accent); }
.cart-compact .cart-rm {
  border: none; background: transparent; color: var(--muted);
  cursor: pointer; font-size: 16px; padding: 4px 8px;
}
.cart-compact .cart-rm:hover { color: var(--danger); }
.cart-line-label { min-width: 0; flex: 1 1 120px; }
.cart-line-label .name {
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.cart-line-total { min-width: 4.5em; text-align: right; }
.collapse-toggle {
  width: 100%; text-align: left; background: transparent;
  border: 1px dashed var(--border); color: var(--muted);
  border-radius: 10px; padding: 8px 12px; cursor: pointer; font-weight: 600;
}
.collapse-toggle:hover { color: var(--text); border-color: rgba(249,115,22,.4); }
.collapse-panel {
  display: none; flex-direction: column; gap: 10px;
  padding-top: 4px;
}
.collapse-panel.open { display: flex; }
.usd-hint { font-size: 12px; color: var(--muted); font-weight: 600; }
.client-row { display: flex; gap: 8px; align-items: stretch; }
.client-row .select { flex: 1; min-width: 0; }
.btn-icon {
  border: 1px solid var(--border); background: var(--surface-soft);
  color: var(--text); border-radius: 10px; padding: 0 14px;
  cursor: pointer; font-weight: 700; white-space: nowrap;
}
.btn-icon:hover { border-color: var(--accent); color: var(--accent); }
.total-block {
  display: flex; justify-content: space-between; align-items: flex-end;
  padding: 8px 0 4px; border-top: 1px solid var(--border);
}
.total-block .stat-value { font-size: 22px; }

/* Caisse */
.caisse-layout { align-items: start; }
.caisse-list {
  margin-top: 12px;
  max-height: min(45vh, 420px);
  overflow: auto;
  -webkit-overflow-scrolling: touch;
}
.caisse-cart-card { position: relative; }
.caisse-validate {
  width: 100%;
}
.row-actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.row-actions-desktop { display: flex; gap: 8px; flex-wrap: wrap; }
.row-actions-mobile { display: none; }

/* Admin plateforme */
.admin-layout { min-height: 100vh; min-height: 100dvh; }
.admin-header {
  display: flex; justify-content: space-between; align-items: center; gap: 12px;
  padding: 14px 20px; border-bottom: 1px solid var(--border); background: var(--navy);
  flex-wrap: wrap;
}
.admin-header img { height: 48px; width: auto; object-fit: contain; }
.admin-content { padding: 20px; }
.split { display: grid; grid-template-columns: 1.1fr 1fr; gap: 14px; }
.boutique-item {
  width: 100%; text-align: left; margin-bottom: 8px;
  border: 1px solid var(--border); background: var(--surface-soft);
  border-radius: 12px; padding: 12px; color: var(--text); cursor: pointer;
}
.boutique-item.active { border-color: rgba(249,115,22,.55); background: rgba(222,94,4,.12); }
.boutique-item.is-suspended { opacity: .72; border-style: dashed; }
.boutique-item-head {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
}
.boutique-item-head strong { min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.status-badge {
  display: inline-flex; align-items: center;
  padding: 2px 8px; border-radius: 999px; font-size: 11px; font-weight: 700;
  border: 1px solid var(--border); white-space: nowrap;
}
.status-badge.ok {
  color: var(--success); background: #052E16;
  border-color: rgba(74,222,128,.4);
}
.status-badge.off {
  color: var(--danger); background: #450A0A;
  border-color: rgba(248,113,113,.4);
}
.btn-toggle-actif {
  flex-shrink: 0;
  font-size: 12px;
  padding: 6px 10px;
}
.secret-box {
  background: #052E16; border: 1px solid rgba(74,222,128,.4);
  border-radius: 12px; padding: 12px; font-size: 13px; word-break: break-all;
}
.pdv-add-row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.pdv-add-row .input { flex: 1; min-width: 100px; }
.pdv-add-row .input-code { max-width: 120px; flex: 0 1 120px; }

/* ========== Breakpoints ========== */
@media (max-width: 1100px) {
  .sidebar { width: 212px; padding: 14px 10px; }
  .sidebar .brand img,
  .brand-logo { height: 52px; }
  .nav-btn { padding: 10px; gap: 10px; font-size: 13px; }
  .grid-3 { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 960px) {
  .split { grid-template-columns: 1fr; }
}

@media (max-width: 768px) {
  :root { --bottom-nav-h: 64px; }

  .app-shell {
    flex-direction: column;
    width: 100%;
    max-width: 100vw;
  }

  /* Bottom tab bar — must reset desktop sticky/height/width:100% on buttons */
  .sidebar {
    position: fixed !important;
    top: auto !important;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 50;
    width: 100% !important;
    max-width: 100vw;
    height: calc(var(--bottom-nav-h) + var(--safe-bottom)) !important;
    max-height: calc(var(--bottom-nav-h) + var(--safe-bottom));
    margin: 0;
    padding: 4px 2px var(--safe-bottom);
    flex-direction: row;
    flex-wrap: nowrap;
    align-items: stretch;
    justify-content: stretch;
    gap: 0;
    border: none;
    border-top: 1px solid rgba(255,255,255,.12);
    border-radius: 0;
    overflow: hidden;
    background: rgba(11, 17, 32, .98);
    backdrop-filter: blur(16px);
    box-shadow: 0 -6px 24px rgba(0,0,0,.4);
  }
  .sidebar .brand,
  .sidebar-spacer { display: none !important; }

  .nav-list {
    display: flex;
    flex: 1 1 auto;
    flex-direction: row;
    align-items: stretch;
    justify-content: space-around;
    gap: 0;
    width: auto;
    min-width: 0;
    height: 100%;
    overflow-x: auto;
    overflow-y: hidden;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }
  .nav-list::-webkit-scrollbar { display: none; height: 0; }

  .sidebar .nav-btn {
    display: flex;
    flex: 1 1 0;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    gap: 2px;
    width: auto !important; /* override desktop width:100% */
    min-width: 0;
    max-width: none;
    height: 100%;
    margin: 0;
    padding: 6px 2px;
    text-align: center;
    font-size: 9px;
    line-height: 1.15;
    font-weight: 700;
    letter-spacing: 0;
    border: none !important;
    border-radius: 8px;
    box-shadow: none !important;
    white-space: nowrap;
    overflow: hidden;
  }
  .sidebar .nav-btn.active {
    background: rgba(249,115,22,.2);
    color: #fff;
  }
  .sidebar .nav-btn .nav-ico {
    width: 22px;
    height: 22px;
  }
  .sidebar .nav-btn .nav-ico svg {
    width: 20px;
    height: 20px;
  }
  .sidebar .nav-btn .nav-label {
    display: none !important;
  }
  .sidebar .nav-btn .nav-label-short {
    display: block !important;
    flex: 0 0 auto;
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  .sidebar .nav-logout {
    flex: 0 0 44px;
    width: 44px !important;
    min-width: 44px;
    max-width: 44px;
    margin: 0;
    padding: 6px 0;
    border: none !important;
  }
  .sidebar .nav-logout .nav-label,
  .sidebar .nav-logout .nav-label-short {
    display: none !important;
  }
  .sidebar .nav-logout .nav-ico { color: var(--danger); }

  .main {
    width: 100%;
    max-width: 100vw;
    min-width: 0;
    flex: 1;
    padding-bottom: calc(var(--bottom-nav-h) + var(--safe-bottom) + 10px);
  }
  .topbar {
    padding: 10px 12px;
    gap: 8px;
    width: 100%;
  }
  .topbar .pill { font-size: 11px; padding: 3px 8px; max-width: 42vw; }
  .topbar-ctx { flex: 1; min-width: 0; }
  .topbar-status { margin-left: auto; flex-shrink: 0; }
  .content { padding: 12px; width: 100%; max-width: 100%; }
  .grid-3, .grid-2 { grid-template-columns: 1fr; }

  .filters .input,
  .filters .select {
    width: 100%;
    min-width: 0;
    flex: 1 1 100%;
  }

  .caisse-list { max-height: min(32vh, 280px); }
  .caisse-cart-card {
    position: sticky;
    bottom: calc(var(--bottom-nav-h) + var(--safe-bottom) + 8px);
    z-index: 5;
  }
  .caisse-validate {
    position: sticky;
    bottom: 0;
    z-index: 2;
    margin-top: 4px;
    box-shadow: 0 -8px 20px rgba(0,0,0,.35);
  }

  .cart-compact .cart-line .qty-ctrl button,
  .btn-icon {
    min-width: 40px;
    min-height: 40px;
  }
  .cart-compact .cart-line .qty-ctrl button {
    width: 40px;
    height: 40px;
  }

  .row-actions-desktop { display: none; }
  .row-actions-mobile { display: inline-flex; }

  .toast {
    left: 12px;
    right: 12px;
    bottom: calc(var(--bottom-nav-h) + var(--safe-bottom) + 12px);
    max-width: none;
  }

  .update-banner {
    flex-direction: column;
    align-items: stretch;
    padding: 10px 12px;
  }

  .admin-content { padding: 12px; }
  .admin-header { padding: 12px; }
  .stat-value { font-size: 24px; }
  .table { min-width: 520px; }
  .table th, .table td { padding: 8px 6px; font-size: 13px; }
}

@media (max-width: 480px) {
  .login-wrap { padding: 16px; }
  .login-card h1 { font-size: 22px; }
  .brand-logo--login { max-width: min(180px, 65%); max-height: 96px; }
  .ob-row-grid { grid-template-columns: 1fr; }
  .content { padding: 10px; }
  .card { padding: 12px; }
  .client-row { flex-direction: column; }
  .client-row .btn-icon { width: 100%; min-height: 44px; }
  .pdv-add-row { flex-direction: column; align-items: stretch; }
  .pdv-add-row .input-code { max-width: none; width: 100%; }
  .pdv-add-row .btn { width: 100%; }
  .cart-line-label .name { white-space: normal; }
  .modal-backdrop { padding: 8px; align-items: end; }
  .modal {
    width: 100%;
    max-height: 92dvh;
    border-radius: 16px 16px 0 0;
  }
}
