:root {
  --bg: #0f1117;
  --surface: #181b24;
  --surface-raised: #1e2130;
  --border: #262938;
  --text: #eeeef0;
  --text-secondary: #9395a5;
  --text-tertiary: #5e6070;
  --accent: #6366f1;
  --accent-light: #818cf8;
  --accent-bg: rgba(99, 102, 241, 0.12);
  --green: #34d399;
  --green-bg: rgba(52, 211, 153, 0.12);
  --orange: #fb923c;
  --orange-bg: rgba(251, 146, 60, 0.12);
  --red: #f87171;
  --red-bg: rgba(248, 113, 113, 0.12);
  --radius: 14px;
  --radius-sm: 10px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { margin: 0; padding: 0; box-sizing: border-box; }

html, body {
  height: 100%;
  height: var(--app-height, 100%);
  overflow: hidden;
  position: fixed;
  width: 100%;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Text', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

/* ============================================= */
/* App shell                                     */
/* ============================================= */
.app {
  height: var(--app-height, 100%);
  display: flex;
  flex-direction: column;
  max-width: 480px;
  margin: 0 auto;
  position: relative;
  overflow: hidden;
}

/* ============================================= */
/* Screens                                       */
/* ============================================= */
.screen {
  display: none;
  flex-direction: column;
  flex: 1;
  min-height: 0;
}

.screen.active {
  display: flex;
  animation: fadeIn 0.25s ease;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

.screen-header {
  padding: 16px 20px 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
  padding-top: max(16px, env(safe-area-inset-top, 16px));
}

.screen-header h1 {
  font-size: 1.6rem;
  font-weight: 700;
  letter-spacing: -0.3px;
}

.period-label {
  font-size: 0.78rem;
  color: var(--text-secondary);
  margin-top: 2px;
}

.screen-body {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 0 16px;
  scrollbar-width: none;
}

.screen-body::-webkit-scrollbar { display: none; }

/* ============================================= */
/* Sub-tabs (Dashboard / Historique)             */
/* ============================================= */
.donnees-header {
  justify-content: center;
  padding: max(16px, env(safe-area-inset-top, 16px)) 16px 8px;
}

.sub-tabs-full {
  display: flex;
  width: 100%;
  background: var(--surface);
  border-radius: 10px;
  padding: 3px;
}

.sub-tab {
  flex: 1;
  padding: 8px 0;
  border: none;
  background: none;
  color: var(--text-tertiary);
  font-size: 0.82rem;
  font-weight: 600;
  font-family: inherit;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.2s;
  text-align: center;
}

.sub-tab.active {
  background: var(--accent);
  color: #fff;
}

.sub-content {
  display: none;
}

.sub-content.active {
  display: block;
}

.dash-period {
  margin-bottom: 12px;
  padding-top: 4px;
}

/* ============================================= */
/* Chat body — keyboard safe                     */
/* ============================================= */
.chat-body {
  display: flex;
  flex-direction: column;
  padding-bottom: 0 !important;
}

/* Prevent header from scrolling away on iOS keyboard */
#screen-chat {
  position: relative;
}

#screen-chat .screen-header {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--bg);
}

/* ============================================= */
/* Hero revenue card                             */
/* ============================================= */
.hero-card {
  background: linear-gradient(135deg, #1e2140 0%, #1a1d30 100%);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 22px 20px;
  margin-bottom: 12px;
}

.hero-row {
  display: flex;
  align-items: center;
}

.hero-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.hero-divider {
  width: 1px;
  height: 40px;
  background: var(--border);
  margin: 0 16px;
}

.hero-label {
  font-size: 0.72rem;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.8px;
  font-weight: 600;
}

.hero-value {
  font-size: 1.55rem;
  font-weight: 700;
  letter-spacing: -0.5px;
}

.hero-value.accent { color: var(--accent-light); }

/* ============================================= */
/* KPI chips                                     */
/* ============================================= */
.chip-row {
  display: flex;
  gap: 8px;
  margin-bottom: 24px;
}

.chip {
  flex: 1;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 14px 12px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
}

.chip-value {
  font-size: 1.05rem;
  font-weight: 700;
}

.chip-label {
  font-size: 0.68rem;
  color: var(--text-tertiary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  font-weight: 500;
}

/* ============================================= */
/* Section titles                                */
/* ============================================= */
.section-title {
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--text-tertiary);
  padding: 0 4px;
  margin-bottom: 10px;
}

/* ============================================= */
/* Stat cards (clients)                          */
/* ============================================= */
.card-row {
  display: flex;
  gap: 8px;
  margin-bottom: 24px;
}

.stat-card {
  flex: 1;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 16px;
  display: flex;
  align-items: center;
  gap: 14px;
}

.stat-icon {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.stat-icon.new { background: var(--green-bg); color: var(--green); }
.stat-icon.returning { background: var(--accent-bg); color: var(--accent-light); }

.stat-value {
  display: block;
  font-size: 1.3rem;
  font-weight: 700;
  line-height: 1.2;
}

.stat-label {
  display: block;
  font-size: 0.72rem;
  color: var(--text-secondary);
}

/* ============================================= */
/* Metrics card (taux)                           */
/* ============================================= */
.metrics-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden;
  margin-bottom: 24px;
}

.metric-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 13px 16px;
}

.metric-row + .metric-row {
  border-top: 1px solid var(--border);
}

.metric-name {
  font-size: 0.85rem;
  color: var(--text-secondary);
}

.metric-value {
  font-size: 0.9rem;
  font-weight: 600;
}

/* ============================================= */
/* List card (produits, collections)             */
/* ============================================= */
.list-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden;
  margin-bottom: 24px;
}

.list-item {
  display: flex;
  align-items: center;
  padding: 12px 16px;
  gap: 12px;
}

.list-item + .list-item {
  border-top: 1px solid var(--border);
}

.list-rank {
  width: 24px;
  height: 24px;
  border-radius: 6px;
  background: var(--accent-bg);
  color: var(--accent-light);
  font-size: 0.7rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.list-info {
  flex: 1;
  min-width: 0;
}

.list-title {
  font-size: 0.85rem;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.list-sub {
  font-size: 0.72rem;
  color: var(--text-tertiary);
}

.list-amount {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--accent-light);
  flex-shrink: 0;
}

.list-empty {
  padding: 20px 16px;
  text-align: center;
  color: var(--text-tertiary);
  font-size: 0.85rem;
}

/* ============================================= */
/* Bottom tab bar                                */
/* ============================================= */
.tab-bar {
  display: flex;
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding: 6px 0;
  padding-bottom: max(6px, var(--safe-bottom));
  flex-shrink: 0;
}

.tab-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  padding: 6px 0;
  background: none;
  border: none;
  color: var(--text-tertiary);
  cursor: pointer;
  transition: color 0.2s;
  font-family: inherit;
}

.tab-item span {
  font-size: 0.65rem;
  font-weight: 600;
  letter-spacing: 0.3px;
}

.tab-item.active { color: var(--accent-light); }
.tab-item:active { transform: scale(0.95); }

/* ============================================= */
/* Empty state                                   */
/* ============================================= */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 60px 20px;
  text-align: center;
}

.empty-icon {
  width: 72px;
  height: 72px;
  border-radius: 50%;
  background: var(--surface);
  border: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-tertiary);
  margin-bottom: 16px;
}

.empty-title {
  font-size: 1.05rem;
  font-weight: 600;
  margin-bottom: 6px;
}

.empty-sub {
  font-size: 0.82rem;
  color: var(--text-tertiary);
  margin-bottom: 24px;
  max-width: 240px;
}

.btn-primary {
  background: var(--accent);
  color: #fff;
  border: none;
  padding: 12px 28px;
  border-radius: 12px;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
  font-family: inherit;
}

.btn-primary:active { transform: scale(0.96); background: var(--accent-light); }

/* ============================================= */
/* History list                                  */
/* ============================================= */
.history-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.history-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 16px;
  transition: transform 0.15s;
}

.history-card:active { transform: scale(0.98); }

.history-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 12px;
}

.history-week {
  font-size: 0.85rem;
  font-weight: 600;
  line-height: 1.3;
}

.history-date {
  font-size: 0.7rem;
  color: var(--text-tertiary);
  flex-shrink: 0;
}

.history-stats {
  display: flex;
  gap: 16px;
}

.history-stat {
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.history-stat-value {
  font-size: 0.9rem;
  font-weight: 600;
}

.history-stat-label {
  font-size: 0.65rem;
  color: var(--text-tertiary);
  text-transform: uppercase;
  letter-spacing: 0.4px;
}

.history-notion {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  margin-top: 10px;
  font-size: 0.75rem;
  color: var(--accent-light);
  text-decoration: none;
}

.history-notion:active { opacity: 0.7; }

/* ============================================= */
/* Overlay (collecte)                            */
/* ============================================= */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 17, 23, 0.85);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  animation: fadeIn 0.2s ease;
}

.overlay.hidden { display: none; }

.overlay-content {
  text-align: center;
}

.spinner {
  width: 44px;
  height: 44px;
  border: 3px solid var(--border);
  border-top-color: var(--accent-light);
  border-radius: 50%;
  margin: 0 auto 20px;
  animation: spin 0.8s linear infinite;
}

.overlay-title {
  font-size: 1.05rem;
  font-weight: 600;
  margin-bottom: 6px;
}

.overlay-sub {
  font-size: 0.82rem;
  color: var(--text-secondary);
}

/* ============================================= */
/* Toast                                         */
/* ============================================= */
.toast {
  position: fixed;
  top: max(16px, env(safe-area-inset-top, 16px));
  left: 50%;
  transform: translateX(-50%) translateY(-100px);
  background: var(--surface-raised);
  border: 1px solid var(--border);
  padding: 12px 20px;
  border-radius: 12px;
  font-size: 0.85rem;
  font-weight: 500;
  z-index: 200;
  transition: transform 0.4s cubic-bezier(0.16, 1, 0.3, 1);
  max-width: 90%;
  text-align: center;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
}

.toast.visible {
  transform: translateX(-50%) translateY(0);
}

.toast.success { border-color: var(--green); color: var(--green); }
.toast.error { border-color: var(--red); color: var(--red); }

/* ============================================= */
/* Chat                                          */
/* ============================================= */
.chat-messages {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding-bottom: 8px;
}

.chat-msg-user {
  align-self: flex-end;
  background: var(--accent);
  color: #fff;
  padding: 10px 14px;
  border-radius: 16px 16px 4px 16px;
  font-size: 0.85rem;
  max-width: 85%;
  word-break: break-word;
  line-height: 1.4;
  animation: msgIn 0.2s ease;
}

.chat-msg-bot {
  align-self: flex-start;
  background: var(--surface);
  border: 1px solid var(--border);
  padding: 14px 16px;
  border-radius: 16px 16px 16px 4px;
  font-size: 0.85rem;
  max-width: 90%;
  line-height: 1.55;
  white-space: pre-line;
  animation: msgIn 0.25s ease;
}

.chat-msg-bot.error {
  border-color: var(--red);
  color: var(--red);
}

.chat-msg-bot.success {
  border-color: rgba(52, 211, 153, 0.3);
}

@keyframes msgIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

.chat-msg-typing {
  align-self: flex-start;
  display: flex;
  gap: 4px;
  padding: 12px 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px 16px 16px 4px;
  animation: msgIn 0.2s ease;
}

.typing-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--text-tertiary);
  animation: typingBounce 1.2s ease-in-out infinite;
}

.typing-dot:nth-child(2) { animation-delay: 0.15s; }
.typing-dot:nth-child(3) { animation-delay: 0.3s; }

@keyframes typingBounce {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
  30% { transform: translateY(-4px); opacity: 1; }
}

.chat-notion-link {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  margin-top: 10px;
  font-size: 0.75rem;
  color: var(--accent-light);
  text-decoration: none;
}

.chat-notion-link:active { opacity: 0.7; }

/* Action buttons (suggested by bot) */
.chat-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 12px;
  align-self: flex-start;
  animation: msgIn 0.3s ease;
}

.chat-action-btn {
  background: var(--accent-bg);
  color: var(--accent-light);
  border: 1px solid rgba(99, 102, 241, 0.25);
  padding: 9px 16px;
  border-radius: 20px;
  font-size: 0.8rem;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: all 0.15s;
  white-space: nowrap;
}

.chat-action-btn:active {
  transform: scale(0.95);
  background: var(--accent);
  color: #fff;
}

.chat-action-btn:disabled {
  opacity: 0.35;
  cursor: default;
}

/* Input bar */
.chat-input-bar {
  display: flex;
  gap: 8px;
  padding: 10px 16px;
  padding-bottom: 10px;
  border-top: 1px solid var(--border);
  background: var(--bg);
  flex-shrink: 0;
}

.chat-input {
  flex: 1;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 11px 16px;
  color: var(--text);
  font-size: 0.85rem;
  font-family: inherit;
  outline: none;
  transition: border-color 0.2s;
}

.chat-input::placeholder { color: var(--text-tertiary); }
.chat-input:focus { border-color: var(--accent); }

.chat-send-btn {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  border: none;
  background: var(--accent);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
  transition: all 0.15s;
}

.chat-send-btn:active { transform: scale(0.88); }
.chat-send-btn:disabled { opacity: 0.35; cursor: default; }

/* ============================================= */
/* Utilities                                     */
/* ============================================= */
.hidden { display: none !important; }
.bottom-spacer { height: 20px; }

/* Desktop: cap width, center */
@media (min-width: 481px) {
  .app {
    border-left: 1px solid var(--border);
    border-right: 1px solid var(--border);
  }
}
