/* ===== Design tokens ================================================= */
:root {
  --color-teal: #0E7C66;
  --color-teal-dark: #0A5C4C;
  --color-teal-light: #E4F3EF;

  --color-green: #22C55E;
  --color-amber: #F59E0B;
  --color-red: #D32F2F;

  --color-bg: #F4F7F6;
  --color-surface: #FFFFFF;
  --color-border: #DCE5E2;
  --color-text: #172420;
  --color-text-muted: #5B6D67;

  --lcd-bg: #12271F;
  --lcd-bg-deep: #0B1B15;
  --lcd-shadow-rest: inset 0 0 0 1px rgba(255, 255, 255, 0.04), 0 6px 18px rgba(6, 20, 15, 0.28);
  --lcd-shadow-pulse: inset 0 0 0 1px rgba(255, 255, 255, 0.04), 0 0 26px 4px rgba(211, 47, 47, 0.55);

  --toast-bg: #172420;
  --toast-success-bg: #0A5C4C;
  --toast-danger-bg: #C62828;

  --alert-warning-bg: #FFF4E0;
  --alert-warning-fg: #92600A;
  --alert-danger-bg: #FDE7E7;
  --alert-danger-fg: #9E1F1F;

  --font-display: "Space Grotesk", "Inter", system-ui, sans-serif;
  --font-mono: "JetBrains Mono", ui-monospace, "SFMono-Regular", Menlo, monospace;
  --font-body: "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;

  --radius-md: 14px;
  --radius-lg: 20px;
  --shadow-card: 0 2px 10px rgba(15, 40, 33, 0.08);

  --nav-height: 64px;

  color-scheme: light;
}

/* ===== Theme sombre ====================================================
 * Le panneau LCD devient un ecran retroeclaire : fond vert plus lumineux,
 * halo qui deborde sur la page (contrairement au theme clair ou le panneau
 * "flotte" simplement au-dessus d'une carte blanche), segments a plus fort
 * contraste. Le reste de la palette passe sur un fond teal tres sombre
 * (jamais noir pur) avec des cartes legerement surelevees.
 */
:root[data-theme="dark"] {
  color-scheme: dark;

  --color-teal: #2FD9B3;
  --color-teal-dark: #8CF3D9;
  --color-teal-light: rgba(47, 217, 179, 0.14);

  --color-green: #34D399;
  --color-amber: #FBBF24;
  --color-red: #F87171;

  --color-bg: #0E1512;
  --color-surface: #172420;
  --color-border: #2A3B34;
  --color-text: #E7F3EE;
  --color-text-muted: #93AFA5;

  --lcd-bg: #1E5238;
  --lcd-bg-deep: #0F3322;
  --lcd-shadow-rest: inset 0 0 0 1px rgba(255, 255, 255, 0.07), 0 8px 28px rgba(0, 0, 0, 0.55),
    0 0 48px 6px rgba(52, 211, 153, 0.28);
  --lcd-shadow-pulse: inset 0 0 0 1px rgba(255, 255, 255, 0.09), 0 0 54px 12px rgba(248, 113, 113, 0.7);

  --toast-bg: #0B1512;

  --alert-warning-bg: rgba(251, 191, 36, 0.16);
  --alert-warning-fg: #FFD98A;
  --alert-danger-bg: rgba(248, 113, 113, 0.16);
  --alert-danger-fg: #FFB4B4;

  --shadow-card: 0 2px 14px rgba(0, 0, 0, 0.45), 0 0 0 1px rgba(255, 255, 255, 0.03);
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

body,
.card,
.lcd-panel,
.reading-row,
.period-switch,
.export-range-switch,
.bottom-nav,
.app-header,
.field input {
  transition: background-color 0.25s ease, color 0.25s ease, border-color 0.25s ease, box-shadow 0.25s ease;
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
    scroll-behavior: auto !important;
  }
}

html,
body {
  margin: 0;
  padding: 0;
  overflow-x: hidden;
}

body {
  background: var(--color-bg);
  color: var(--color-text);
  font-family: var(--font-body);
  -webkit-font-smoothing: antialiased;
  padding-bottom: calc(var(--nav-height) + env(safe-area-inset-bottom, 0px));
}

h1,
h2,
h3 {
  font-family: var(--font-display);
  margin: 0;
}

button {
  font-family: inherit;
}

/* ===== Header ========================================================= */
.app-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: calc(env(safe-area-inset-top, 0px) + 14px) 18px 12px;
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
  position: sticky;
  top: 0;
  z-index: 10;
}

.app-header-mark {
  width: 10px;
  height: 26px;
  border-radius: 4px;
  background: linear-gradient(180deg, var(--color-red) 0 33%, var(--color-amber) 33% 66%, var(--color-green) 66% 100%);
}

.app-header-title {
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--color-teal-dark);
  flex: 1;
}

.theme-toggle {
  border: none;
  background: transparent;
  color: var(--color-teal-dark);
  width: 44px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 10px;
  cursor: pointer;
  flex: none;
}

.theme-toggle:hover {
  background: var(--color-teal-light);
}

.theme-toggle .icon-sun {
  display: none;
}

:root[data-theme="dark"] .theme-toggle .icon-sun {
  display: block;
}

:root[data-theme="dark"] .theme-toggle .icon-moon {
  display: none;
}

/* ===== Banniere d'installation PWA ===================================== */
.install-banner {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 16px;
  background: var(--color-teal-light);
  color: var(--color-teal-dark);
  font-size: 0.82rem;
  font-weight: 500;
  line-height: 1.4;
}

.install-banner span {
  flex: 1;
}

.install-banner-actions {
  display: flex;
  align-items: center;
  gap: 2px;
  flex: none;
}

.btn-small {
  padding: 8px 14px;
  font-size: 0.82rem;
}

.install-dismiss {
  font-size: 1rem;
  line-height: 1;
}

/* ===== Layout ========================================================= */
.app-main {
  max-width: 560px;
  margin: 0 auto;
  padding: 16px 16px 32px;
}

.view {
  display: none;
}

.view.active {
  display: block;
}

.section-title {
  font-size: 1rem;
  font-weight: 600;
  color: var(--color-text);
  margin: 22px 0 10px;
}

.card {
  background: var(--color-surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-card);
  padding: 18px;
  margin-top: 14px;
}

/* ===== Panneau LCD ===================================================== */
.lcd-panel {
  display: flex;
  gap: 14px;
  background: radial-gradient(120% 140% at 20% 0%, var(--lcd-bg) 0%, var(--lcd-bg-deep) 100%);
  border-radius: var(--radius-lg);
  padding: 18px;
  box-shadow: var(--lcd-shadow-rest);
}

.lcd-panel-compact {
  padding: 14px;
  margin-bottom: 16px;
}

.lcd-risk-bar {
  display: flex;
  flex-direction: column;
  gap: 6px;
  width: 12px;
}

.lcd-risk-bar .zone {
  flex: 1;
  border-radius: 6px;
  opacity: 0.22;
  transition: opacity 0.25s ease, box-shadow 0.25s ease;
}

.lcd-risk-bar .zone-red {
  background: var(--color-red);
}

.lcd-risk-bar .zone-amber {
  background: var(--color-amber);
}

.lcd-risk-bar .zone-green {
  background: var(--color-green);
}

.lcd-risk-bar .zone.active {
  opacity: 1;
}

.lcd-risk-bar .zone-red.active {
  box-shadow: 0 0 12px 1px rgba(211, 47, 47, 0.7);
}

.lcd-risk-bar .zone-amber.active {
  box-shadow: 0 0 12px 1px rgba(245, 158, 11, 0.7);
}

.lcd-risk-bar .zone-green.active {
  box-shadow: 0 0 12px 1px rgba(34, 197, 94, 0.7);
}

.lcd-readout {
  flex: 1;
  min-width: 0;
}

.lcd-row {
  display: flex;
  align-items: baseline;
  gap: 6px;
}

.lcd-value {
  font-family: var(--font-mono);
  font-weight: 700;
  font-size: 2.6rem;
  line-height: 1;
  color: #9FE8D2;
  text-shadow: 0 0 10px rgba(159, 232, 210, 0.35);
}

.lcd-value-small {
  font-size: 1.3rem;
}

.lcd-sep {
  color: #6FA79A;
  font-family: var(--font-mono);
  font-size: 2rem;
}

.lcd-unit {
  color: #6FA79A;
  font-family: var(--font-mono);
  font-size: 0.8rem;
  align-self: flex-end;
  margin-bottom: 4px;
}

.lcd-row-secondary {
  margin-top: 4px;
}

.lcd-label {
  margin-top: 10px;
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 0.85rem;
  color: #C9E9DE;
}

.lcd-time {
  font-size: 0.72rem;
  color: #6FA79A;
  margin-top: 2px;
}

.lcd-panel.cat-elevated .lcd-value,
.lcd-panel.cat-elevated .lcd-label {
  color: #FFD48A;
  text-shadow: 0 0 10px rgba(255, 212, 138, 0.35);
}

.lcd-panel.cat-hypertension .lcd-value,
.lcd-panel.cat-hypertension .lcd-label {
  color: #FF9E9E;
  text-shadow: 0 0 10px rgba(255, 158, 158, 0.4);
}

.lcd-panel.crisis {
  animation: lcd-crisis-pulse 1.4s ease-in-out infinite;
}

@keyframes lcd-crisis-pulse {
  0%, 100% {
    box-shadow: var(--lcd-shadow-rest);
  }
  50% {
    box-shadow: var(--lcd-shadow-pulse);
  }
}

:root[data-theme="dark"] .lcd-value {
  color: #B9FBE4;
  text-shadow: 0 0 4px rgba(185, 251, 228, 0.85), 0 0 18px rgba(185, 251, 228, 0.5);
}

:root[data-theme="dark"] .lcd-sep,
:root[data-theme="dark"] .lcd-unit,
:root[data-theme="dark"] .lcd-time {
  color: #8FD9C3;
}

:root[data-theme="dark"] .lcd-label {
  color: #DFFBF0;
}

:root[data-theme="dark"] .lcd-panel.cat-elevated .lcd-value,
:root[data-theme="dark"] .lcd-panel.cat-elevated .lcd-label {
  color: #FFE1A3;
  text-shadow: 0 0 4px rgba(255, 225, 163, 0.85), 0 0 18px rgba(255, 225, 163, 0.5);
}

:root[data-theme="dark"] .lcd-panel.cat-hypertension .lcd-value,
:root[data-theme="dark"] .lcd-panel.cat-hypertension .lcd-label {
  color: #FFBFBF;
  text-shadow: 0 0 4px rgba(255, 191, 191, 0.9), 0 0 20px rgba(255, 191, 191, 0.55);
}

/* ===== Alertes ========================================================= */
.alert {
  margin-top: 14px;
  padding: 12px 14px;
  border-radius: var(--radius-md);
  font-size: 0.88rem;
  font-weight: 600;
}

.alert-warning {
  background: var(--alert-warning-bg);
  color: var(--alert-warning-fg);
}

.alert-danger {
  background: var(--alert-danger-bg);
  color: var(--alert-danger-fg);
}

/* ===== Boutons ========================================================= */
.btn {
  border: none;
  border-radius: var(--radius-md);
  padding: 12px 16px;
  min-height: 44px;
  font-size: 0.92rem;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.08s ease, opacity 0.15s ease;
}

.btn:active {
  transform: scale(0.98);
}

.btn-primary {
  background: var(--color-teal);
  color: #fff;
}

.btn-secondary {
  background: var(--color-teal-light);
  color: var(--color-teal-dark);
}

.btn-ghost {
  background: transparent;
  color: var(--color-text-muted);
}

.btn-block {
  width: 100%;
  margin-top: 16px;
}

.btn-danger {
  background: var(--alert-danger-bg);
  color: var(--alert-danger-fg);
}

.capture-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.capture-actions .btn {
  flex: 1;
  min-width: 140px;
}

.icon-btn {
  border: none;
  background: transparent;
  color: var(--color-teal-dark);
  font-size: 0.78rem;
  font-weight: 600;
  padding: 4px 10px;
  min-height: 44px;
  min-width: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  border-radius: 8px;
}

.icon-btn:hover {
  background: var(--color-teal-light);
}

.icon-btn-danger {
  color: var(--color-red);
}

.icon-btn-danger:hover {
  background: var(--alert-danger-bg);
}

/* ===== Capture / formulaire ============================================ */
.capture-hint {
  margin: 0 0 12px;
  font-size: 0.78rem;
  color: var(--color-text-muted);
}

.capture-preview-wrap {
  margin-top: 14px;
  border-radius: var(--radius-md);
  overflow: hidden;
  height: min(60vh, 420px);
  background: #0B0F0D;
  display: flex;
  align-items: center;
  justify-content: center;
}

.capture-preview-wrap img {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: contain;
}

.analyze-status,
.location-status {
  margin: 12px 0 0;
  font-size: 0.85rem;
  color: var(--color-text-muted);
}

.toggle-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 12px;
  font-size: 0.78rem;
  color: var(--color-text-muted);
  cursor: pointer;
}

.toggle-row input {
  flex: none;
  width: 16px;
  height: 16px;
  accent-color: var(--color-teal);
}

.reading-form {
  margin-top: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.field-row {
  display: flex;
  gap: 10px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 0.78rem;
  color: var(--color-text-muted);
  font-weight: 600;
  flex: 1;
}

.field input,
.field select {
  font-family: var(--font-mono);
  font-size: 1rem;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--color-border);
  background: var(--color-bg);
  color: var(--color-text);
}

.field input:focus,
.field select:focus {
  outline: 2px solid var(--color-teal);
  outline-offset: 1px;
}

.export-lang-field {
  margin-top: 14px;
}

.form-actions {
  display: flex;
  gap: 10px;
  margin-top: 4px;
}

.form-actions .btn {
  flex: 1;
}

/* ===== Listes de mesures =============================================== */
.reading-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.reading-row {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--color-surface);
  border-radius: var(--radius-md);
  padding: 12px 14px;
  box-shadow: var(--shadow-card);
}

.reading-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex: none;
  background: var(--color-green);
}

.reading-row.cat-elevated .reading-dot {
  background: var(--color-amber);
}

.reading-row.cat-hypertension .reading-dot {
  background: var(--color-red);
}

.reading-row.crisis .reading-dot {
  box-shadow: 0 0 0 4px rgba(211, 47, 47, 0.22);
}

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

.reading-values {
  font-family: var(--font-mono);
  font-weight: 600;
  font-size: 0.95rem;
}

.reading-meta {
  font-size: 0.75rem;
  color: var(--color-text-muted);
  margin-top: 2px;
}

.reading-actions {
  display: flex;
  gap: 2px;
  flex: none;
}

.history-day-heading {
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--color-text-muted);
  text-transform: capitalize;
  margin: 18px 0 8px;
}

.history-day-heading:first-child {
  margin-top: 0;
}

.empty-state {
  color: var(--color-text-muted);
  font-size: 0.88rem;
  text-align: center;
  padding: 18px 0;
}

/* ===== Courbes ========================================================= */
.period-switch,
.export-range-switch {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  background: var(--color-surface);
  padding: 6px;
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-card);
}

.period-btn,
.export-range-btn {
  flex: 1;
  min-width: 70px;
  min-height: 44px;
  border: none;
  background: transparent;
  padding: 9px 8px;
  border-radius: 9px;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--color-text-muted);
  cursor: pointer;
}

.period-btn.active,
.export-range-btn.active {
  background: var(--color-teal);
  color: #fff;
}

.chart-card {
  height: 320px;
  position: relative;
}

.chart-card canvas {
  max-height: 100%;
}

/* ===== Export =========================================================== */
.export-custom-range {
  display: flex;
  gap: 10px;
  margin-top: 12px;
}

.export-preview {
  overflow-x: auto;
}

.export-range-label {
  margin: 0 0 12px;
  font-size: 0.85rem;
  color: var(--color-text-muted);
}

.export-stats {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
  margin-bottom: 16px;
}

.export-stat {
  background: var(--color-teal-light);
  border-radius: 10px;
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.export-stat span {
  font-size: 0.7rem;
  color: var(--color-teal-dark);
  font-weight: 600;
}

.export-stat strong {
  font-family: var(--font-mono);
  font-size: 1rem;
  color: var(--color-teal-dark);
}

.export-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.78rem;
  min-width: 420px;
}

.export-table th,
.export-table td {
  text-align: left;
  padding: 7px 8px;
  border-bottom: 1px solid var(--color-border);
}

.export-table th {
  color: var(--color-text-muted);
  font-weight: 600;
}

/* ===== Navigation basse ================================================= */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  display: flex;
  background: var(--color-surface);
  border-top: 1px solid var(--color-border);
  padding: 8px 6px calc(8px + env(safe-area-inset-bottom, 0px));
  z-index: 20;
}

.nav-btn {
  flex: 1;
  border: none;
  background: transparent;
  padding: 8px 4px;
  min-height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--color-text-muted);
  cursor: pointer;
  border-radius: 10px;
}

.nav-btn.active {
  color: var(--color-teal);
  background: var(--color-teal-light);
}

/* ===== Toasts ============================================================ */
.toast-container {
  position: fixed;
  left: 0;
  right: 0;
  bottom: calc(var(--nav-height) + env(safe-area-inset-bottom, 0px) + 12px);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  pointer-events: none;
  z-index: 30;
}

.toast {
  background: var(--toast-bg);
  color: #fff;
  padding: 10px 16px;
  border-radius: 999px;
  font-size: 0.82rem;
  font-weight: 500;
  opacity: 0;
  transform: translateY(8px);
  transition: opacity 0.25s ease, transform 0.25s ease;
  max-width: 88%;
  text-align: center;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.18);
}

.toast.show {
  opacity: 1;
  transform: translateY(0);
}

.toast-success {
  background: var(--toast-success-bg);
}

.toast-danger {
  background: var(--toast-danger-bg);
}

/* ===== Import multiple (batch) ========================================== */
.batch-overlay {
  position: fixed;
  inset: 0;
  z-index: 50;
  background: var(--color-bg);
}

.batch-panel {
  display: flex;
  flex-direction: column;
  height: 100%;
  max-width: 640px;
  margin: 0 auto;
}

.batch-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: calc(env(safe-area-inset-top, 0px) + 14px) 18px 12px;
  border-bottom: 1px solid var(--color-border);
  background: var(--color-surface);
  flex: none;
}

.batch-panel-header h2 {
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--color-text);
}

.batch-progress {
  padding: 12px 18px 0;
  font-size: 0.85rem;
  color: var(--color-text-muted);
  flex: none;
}

.batch-rows {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 14px 18px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.batch-row {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  background: var(--color-surface);
  border-radius: var(--radius-md);
  padding: 10px;
  box-shadow: var(--shadow-card);
}

.batch-row-missing-date {
  box-shadow: 0 0 0 2px var(--color-red), var(--shadow-card);
}

.batch-row-duplicate {
  box-shadow: 0 0 0 2px var(--color-amber), var(--shadow-card);
}

.batch-row-excluded {
  opacity: 0.45;
}

.batch-row-thumb {
  width: 56px;
  height: 56px;
  border-radius: 8px;
  object-fit: cover;
  flex: none;
  background: #0B0F0D;
}

.batch-row-body {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.batch-row-numbers {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
}

.batch-input {
  font-family: var(--font-mono);
  font-size: 0.85rem;
  padding: 7px 6px;
  border-radius: 8px;
  border: 1px solid var(--color-border);
  background: var(--color-bg);
  color: var(--color-text);
  width: 100%;
  min-width: 0;
}

.batch-input-date {
  font-size: 0.78rem;
}

.batch-row-status {
  font-size: 0.7rem;
  color: var(--color-text-muted);
}

.batch-row-missing-date .batch-row-status {
  color: var(--color-red);
  font-weight: 600;
}

.batch-row-duplicate .batch-row-status {
  color: var(--color-amber);
  font-weight: 600;
}

.batch-row-exclude {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  min-width: 44px;
  min-height: 44px;
  padding: 4px;
  font-size: 0.66rem;
  color: var(--color-text-muted);
  flex: none;
  cursor: pointer;
}

.batch-row-exclude input {
  accent-color: var(--color-teal);
}

.batch-panel-footer {
  padding: 14px 18px calc(14px + env(safe-area-inset-bottom, 0px));
  border-top: 1px solid var(--color-border);
  background: var(--color-surface);
  flex: none;
}

.batch-panel-footer .btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* ===== Réglages ========================================================= */
.settings-subtitle {
  font-size: 0.95rem;
  font-weight: 600;
  margin: 0 0 8px;
}

.settings-status {
  font-size: 0.85rem;
  color: var(--color-text-muted);
  margin: 0 0 10px;
}

.settings-hint {
  font-size: 0.82rem;
  color: var(--color-text-muted);
  line-height: 1.5;
  margin: 0 0 4px;
}

.settings-card select {
  width: 100%;
  font-family: var(--font-mono);
  font-size: 1rem;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--color-border);
  background: var(--color-bg);
  color: var(--color-text);
}

/* ===== Responsive : desktop ============================================= */
@media (min-width: 720px) {
  .app-main {
    max-width: 640px;
  }

  .bottom-nav {
    max-width: 640px;
    margin: 0 auto;
    left: 0;
    right: 0;
    border-radius: 16px 16px 0 0;
  }
}
