:root {
  --bg: #f5f5f7;
  --sidebar-bg: #fbfbfd;
  --panel-bg: #ffffff;
  --input-bg: #ffffff;
  --border: rgba(0, 0, 0, 0.07);
  --text: #1d1d1f;
  --text-secondary: #6e6e73;

  --accent: #0071e3;
  --accent-hover: #0077ed;
  --green: #34c759;
  --green-text: #1a9c46;
  --red: #ff3b30;
  --orange: #ff9500;
  --purple: #af52de;
  --teal: #30b0c7;

  --radius-lg: 20px;
  --radius-md: 14px;
  --radius-sm: 10px;
  --shadow-card: 0 1px 2px rgba(0, 0, 0, 0.04), 0 8px 24px rgba(0, 0, 0, 0.04);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #000000;
    --sidebar-bg: #1c1c1e;
    --panel-bg: #1c1c1e;
    --input-bg: #2c2c2e;
    --border: rgba(255, 255, 255, 0.09);
    --text: #f5f5f7;
    --text-secondary: #98989d;
    --shadow-card: 0 1px 2px rgba(0, 0, 0, 0.3), 0 8px 24px rgba(0, 0, 0, 0.3);
  }
}
:root[data-theme="dark"] {
  --bg: #000000;
  --sidebar-bg: #1c1c1e;
  --panel-bg: #1c1c1e;
  --input-bg: #2c2c2e;
  --border: rgba(255, 255, 255, 0.09);
  --text: #f5f5f7;
  --text-secondary: #98989d;
  --shadow-card: 0 1px 2px rgba(0, 0, 0, 0.3), 0 8px 24px rgba(0, 0, 0, 0.3);
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  font-family: "Inter", -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

a { color: inherit; }

/* Layout */

.app-shell {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  width: 250px;
  flex-shrink: 0;
  background: var(--sidebar-bg);
  border-right: 1px solid var(--border);
  padding: 20px 14px;
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px 22px;
}

.brand-mark {
  width: 34px;
  height: 34px;
  border-radius: 9px;
  background: linear-gradient(135deg, var(--accent), #5ac8fa);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  box-shadow: 0 3px 8px rgba(0, 113, 227, 0.35);
}
.brand-mark svg { width: 18px; height: 18px; }

.brand-text { display: flex; flex-direction: column; line-height: 1.25; min-width: 0; }
.brand-title { font-weight: 700; font-size: 14.5px; letter-spacing: -0.01em; }
.brand-subtitle { font-size: 12px; color: var(--text-secondary); }

.sidebar-nav { display: flex; flex-direction: column; gap: 2px; flex: 1; }
.sidebar-nav-bottom { flex: 0 0 auto; }

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  border-radius: 10px;
  text-decoration: none;
  font-size: 14px;
  font-weight: 500;
  color: var(--text);
  transition: background 0.15s ease, color 0.15s ease;
}
.nav-item:hover { background: rgba(0, 0, 0, 0.045); }
.nav-item.active { background: var(--accent); color: #fff; }
.nav-icon { width: 18px; height: 18px; flex-shrink: 0; }

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .nav-item:hover { background: rgba(255, 255, 255, 0.07); }
}
:root[data-theme="dark"] .nav-item:hover { background: rgba(255, 255, 255, 0.07); }

.sidebar-footer {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px 4px;
  font-size: 11.5px;
  color: var(--text-secondary);
}
.local-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--green);
  flex-shrink: 0;
  box-shadow: 0 0 0 3px rgba(52, 199, 89, 0.18);
}

.content { flex: 1; min-width: 0; }
.content-inner {
  max-width: 960px;
  margin: 0 auto;
  padding: 44px 32px 80px;
}

/* Typography */

.page-header { margin-bottom: 28px; }
h1 { font-size: 28px; font-weight: 800; letter-spacing: -0.02em; margin: 0 0 4px; }
h2 { font-size: 17px; font-weight: 700; margin: 0; letter-spacing: -0.01em; }
.page-subtitle { color: var(--text-secondary); font-size: 15px; margin: 0; }

code {
  background: rgba(0, 0, 0, 0.055);
  padding: 2px 6px;
  border-radius: 5px;
  font-size: 0.85em;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) code { background: rgba(255, 255, 255, 0.09); }
}
:root[data-theme="dark"] code { background: rgba(255, 255, 255, 0.09); }

/* Hero card */

.hero-card {
  position: relative;
  overflow: hidden;
  background: var(--panel-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-card);
  padding: 28px 32px;
  margin-bottom: 20px;
}
.hero-card::before {
  content: "";
  position: absolute;
  inset: 0;
  opacity: 0.1;
  pointer-events: none;
}
.hero-positive::before { background: linear-gradient(135deg, var(--green), transparent 60%); }
.hero-negative::before { background: linear-gradient(135deg, var(--red), transparent 60%); }

.hero-label {
  position: relative;
  font-size: 12.5px;
  font-weight: 700;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.hero-value {
  position: relative;
  font-size: 46px;
  font-weight: 800;
  letter-spacing: -0.02em;
  margin-top: 6px;
  font-variant-numeric: tabular-nums;
}
.hero-positive .hero-value { color: var(--green-text); }
.hero-negative .hero-value { color: var(--red); }
.hero-currency { font-size: 17px; font-weight: 600; color: var(--text-secondary); margin-left: 8px; }
.hero-sub { position: relative; font-size: 13px; color: var(--text-secondary); margin-top: 6px; }

/* Stat grid */

.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 14px;
  margin-bottom: 18px;
}

.stat-card {
  background: var(--panel-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 18px;
  box-shadow: var(--shadow-card);
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}
.stat-card:hover { transform: translateY(-2px); box-shadow: 0 6px 18px rgba(0, 0, 0, 0.08); }

.stat-icon {
  width: 34px;
  height: 34px;
  border-radius: 9px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 12px;
}
.stat-icon svg { width: 18px; height: 18px; }
.icon-blue { background: rgba(0, 113, 227, 0.12); color: var(--accent); }
.icon-orange { background: rgba(255, 149, 0, 0.15); color: var(--orange); }
.icon-red { background: rgba(255, 59, 48, 0.12); color: var(--red); }
.icon-green { background: rgba(52, 199, 89, 0.15); color: var(--green); }
.icon-purple { background: rgba(175, 82, 222, 0.14); color: var(--purple); }
.icon-teal { background: rgba(48, 176, 199, 0.15); color: var(--teal); }

.stat-label { font-size: 12.5px; color: var(--text-secondary); font-weight: 500; }
.stat-value {
  font-size: 21px;
  font-weight: 700;
  margin-top: 3px;
  letter-spacing: -0.01em;
  font-variant-numeric: tabular-nums;
}

/* Chart */

.chart {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  height: 200px;
  padding: 10px 4px 0;
  overflow-x: auto;
}
.chart-col {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  flex: 1;
  min-width: 42px;
}
.chart-bars {
  display: flex;
  align-items: flex-end;
  justify-content: center;
  gap: 4px;
  height: 160px;
  width: 100%;
}
.chart-bar {
  width: 13px;
  border-radius: 4px 4px 0 0;
  min-height: 2px;
  transition: height 0.3s ease;
}
.chart-bar-revenue { background: var(--green); }
.chart-bar-expense { background: var(--red); }
.chart-label {
  font-size: 11px;
  color: var(--text-secondary);
  white-space: nowrap;
}
.chart-legend {
  display: flex;
  gap: 20px;
  margin-top: 16px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
  font-size: 12.5px;
  color: var(--text-secondary);
}
.legend-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  margin-right: 6px;
}
.legend-revenue { background: var(--green); }
.legend-expense { background: var(--red); }

.hint-text {
  font-size: 12.5px;
  color: var(--text-secondary);
  line-height: 1.5;
  max-width: 640px;
  margin: -4px 0 26px;
}

/* Panels */

.panel {
  background: var(--panel-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-card);
  padding: 24px 28px;
  margin-bottom: 20px;
}
.panel-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 14px;
}
.panel-subtitle {
  font-size: 13px;
  color: var(--text-secondary);
  margin: 6px 0 0;
  display: flex;
  align-items: center;
  gap: 7px;
}

.status-dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; flex-shrink: 0; }
.status-on { background: var(--green); box-shadow: 0 0 0 3px rgba(52, 199, 89, 0.18); }
.status-off { background: #c7c7cc; }

/* Buttons */

.btn-row { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 6px; }

.btn {
  border: none;
  border-radius: 980px;
  padding: 9px 18px;
  font-size: 13.5px;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
  transition: transform 0.12s ease, background 0.15s ease, opacity 0.15s ease;
}
.btn:active { transform: scale(0.96); }
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); }
.btn-secondary { background: rgba(0, 0, 0, 0.055); color: var(--text); }
.btn-secondary:hover { background: rgba(0, 0, 0, 0.09); }
.btn-sm { padding: 7px 14px; font-size: 12.5px; }

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .btn-secondary { background: rgba(255, 255, 255, 0.09); }
  :root:not([data-theme="light"]) .btn-secondary:hover { background: rgba(255, 255, 255, 0.15); }
}
:root[data-theme="dark"] .btn-secondary { background: rgba(255, 255, 255, 0.09); }
:root[data-theme="dark"] .btn-secondary:hover { background: rgba(255, 255, 255, 0.15); }

.btn-icon {
  border: none;
  background: transparent;
  color: var(--text-secondary);
  width: 30px;
  height: 30px;
  border-radius: 8px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
}
.btn-icon svg { width: 16px; height: 16px; }
.btn-icon:hover { background: rgba(255, 59, 48, 0.12); color: var(--red); }
.btn-share:hover { background: rgba(0, 113, 227, 0.12); color: var(--accent); }
.btn-share.btn-share-done { background: rgba(52, 199, 89, 0.15); color: var(--green-text); }

/* Table */

.table-wrap { overflow-x: auto; }

table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
th {
  text-align: left;
  padding: 10px 12px;
  color: var(--text-secondary);
  font-weight: 600;
  font-size: 11.5px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
td { padding: 12px; border-bottom: 1px solid var(--border); }
th.num, td.num { text-align: right; font-variant-numeric: tabular-nums; }
tbody tr { transition: background 0.1s ease; }
tbody tr:hover { background: rgba(0, 0, 0, 0.025); }
tbody tr.active-row { background: rgba(52, 199, 89, 0.08); font-weight: 600; }
tbody tr:last-child td { border-bottom: none; }
td.positive { color: var(--green-text); font-weight: 700; }
td.negative { color: var(--red); font-weight: 700; }
.muted-cell { color: var(--text-secondary); }
.action-cell {
  text-align: right;
  width: 1%;
  position: sticky;
  right: 0;
  background: var(--panel-bg);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) tbody tr:hover { background: rgba(255, 255, 255, 0.035); }
}
:root[data-theme="dark"] tbody tr:hover { background: rgba(255, 255, 255, 0.035); }

.tag {
  background: rgba(0, 113, 227, 0.1);
  color: var(--accent);
  padding: 4px 10px;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
}
.tag-green { background: rgba(52, 199, 89, 0.13); color: var(--green-text); }

.empty-state {
  color: var(--text-secondary);
  font-size: 14px;
  padding: 24px 0;
  text-align: center;
}

/* Forms */

.expense-form { display: flex; flex-direction: column; gap: 16px; }
.form-row { display: flex; gap: 16px; flex-wrap: wrap; }
.form-row label {
  display: flex;
  flex-direction: column;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text-secondary);
  gap: 6px;
}
.form-row label.grow { flex: 1; min-width: 260px; }

input, select, textarea {
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  font-size: 14px;
  font-family: inherit;
  background: var(--input-bg);
  color: var(--text);
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(0, 113, 227, 0.16);
}
textarea { width: 100%; resize: vertical; font-family: inherit; }

/* Invoice status pills */
.status-select {
  border: none;
  border-radius: 980px;
  padding: 5px 10px 5px 12px;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
  background: rgba(0, 0, 0, 0.06);
  color: var(--text);
}
.status-select.status-accepte,
.status-select.status-payee { background: rgba(52, 199, 89, 0.15); color: var(--green-text); }
.status-select.status-envoye,
.status-select.status-envoyee { background: rgba(0, 113, 227, 0.12); color: var(--accent); }
.status-select.status-refuse { background: rgba(255, 59, 48, 0.12); color: var(--red); }
.status-select.status-brouillon { background: rgba(0, 0, 0, 0.06); color: var(--text-secondary); }

/* Stand / quick sale */

.amount-input-lg {
  font-size: 42px;
  font-weight: 800;
  text-align: center;
  padding: 20px 12px;
  letter-spacing: -0.01em;
  font-variant-numeric: tabular-nums;
}

.btn-lg {
  padding: 16px 24px;
  font-size: 17px;
  border-radius: 16px;
  width: 100%;
}

.stand-total-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}
.stand-total-card .hero-value { font-size: 34px; }

.sale-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
}
.sale-row:last-child { border-bottom: none; }
.sale-row-info { display: flex; flex-direction: column; gap: 2px; }
.sale-row-amount {
  font-size: 16px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--green-text);
}

.customer-details {
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 10px 14px;
}
.customer-details summary {
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
  list-style: none;
}
.customer-details summary::-webkit-details-marker { display: none; }
.customer-details[open] summary { margin-bottom: 4px; color: var(--text); }

.color-field { display: flex; align-items: center; gap: 10px; }
.color-swatch {
  padding: 0;
  width: 44px;
  height: 36px;
  border-radius: 8px;
  cursor: pointer;
  background: none;
}
.color-swatch::-webkit-color-swatch-wrapper { padding: 3px; }
.color-swatch::-webkit-color-swatch { border-radius: 6px; border: none; }

/* Flash messages */

.flash-list { margin-bottom: 22px; }
.flash {
  padding: 12px 16px;
  border-radius: 12px;
  margin-bottom: 8px;
  font-size: 13.5px;
  font-weight: 500;
}
.flash-success { background: rgba(52, 199, 89, 0.13); color: var(--green-text); }
.flash-error { background: rgba(255, 59, 48, 0.11); color: #d70015; }

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .flash-error { color: #ff6961; }
}
:root[data-theme="dark"] .flash-error { color: #ff6961; }

/* Share summary fallback */

.share-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 20px;
}
.share-modal {
  background: var(--panel-bg);
  border-radius: var(--radius-lg);
  padding: 24px;
  max-width: 420px;
  width: 100%;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
}
.share-modal h3 { margin: 0 0 12px; font-size: 15px; font-weight: 700; }
.share-modal textarea {
  width: 100%;
  min-height: 160px;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--input-bg);
  color: var(--text);
  font-family: inherit;
  font-size: 13.5px;
  resize: vertical;
  margin-bottom: 14px;
}

/* Responsive */

@media (max-width: 760px) {
  .app-shell { flex-direction: column; }
  .sidebar {
    width: 100%;
    height: auto;
    position: static;
    flex-direction: row;
    align-items: center;
    padding: 12px 16px;
    gap: 16px;
  }
  .sidebar-brand { padding: 0; }
  .sidebar-nav { flex-direction: row; flex: none; }
  .sidebar-footer { display: none; }
  .content-inner { padding: 24px 18px 60px; }
  .hero-value { font-size: 34px; }
}

/* ---- Tickets de caisse --------------------------------------------------- */
.dropzone {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px;
  padding: 30px 20px; border: 2px dashed var(--accent); border-radius: var(--radius-lg);
  background: color-mix(in srgb, var(--accent) 6%, transparent); text-align: center; cursor: pointer;
  transition: background 0.15s, transform 0.15s;
}
.dropzone:hover, .dropzone.over { background: color-mix(in srgb, var(--accent) 14%, transparent); transform: scale(1.005); }
.dropzone b { font-size: 16px; }
.dropzone small { color: var(--text-secondary); font-size: 13px; }
.dropzone.busy { opacity: 0.7; pointer-events: none; }
.dropzone input[type=file] { display: none; }
.tag-warn { background: rgba(255, 149, 0, 0.16); color: #b36200; font-weight: 700; }
.receipt-link { font-size: 12.5px; color: var(--accent); text-decoration: none; font-weight: 600; white-space: nowrap; }
.receipt-preview { max-width: 100%; max-height: 520px; border-radius: var(--radius-md); border: 1px solid var(--border); }
.edit-grid { display: grid; grid-template-columns: minmax(280px, 380px) 1fr; gap: 24px; align-items: start; }
@media (max-width: 820px) { .edit-grid { grid-template-columns: 1fr; } }

/* ---- Authentification ---------------------------------------------------- */
.auth-page { background: #eaeffc; }
.auth-wrap { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.auth-card { width: 100%; max-width: 410px; background: var(--panel-bg); border: 1px solid var(--border); border-radius: 24px; padding: 30px 28px; box-shadow: var(--shadow-card); }
.auth-brand { font-weight: 800; color: var(--accent); font-size: 15px; margin-bottom: 14px; }
.auth-card h1 { font-size: 24px; margin: 0 0 6px; letter-spacing: -0.02em; }
.auth-sub { color: var(--text-secondary); font-size: 13.5px; line-height: 1.5; margin: 0 0 14px; }
.auth-form { display: grid; gap: 14px; }
.auth-form label { display: grid; gap: 6px; font-size: 13px; font-weight: 600; }
.auth-form input { padding: 12px 14px; border: 1px solid var(--border); border-radius: 12px; background: var(--input-bg); color: var(--text); font: inherit; }
.auth-err { color: #c0262d; margin: 0; font-size: 13px; }
.auth-qr { display: grid; place-items: center; margin: 10px 0; } .auth-qr img { border-radius: 12px; background: #fff; padding: 6px; }
.auth-secret { word-break: break-all; font-size: 12px; user-select: all; }
.auth-codes { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin: 12px 0 16px; } .auth-codes code { background: var(--bg); padding: 9px; border-radius: 10px; text-align: center; font-size: 14px; user-select: all; }
.auth-link { background: none; border: 0; color: var(--text-secondary); cursor: pointer; margin-top: 12px; font: inherit; font-size: 13px; }
.btn-block { width: 100%; justify-content: center; display: inline-flex; }
