/* ===========================
   CSS Variables — Dark Theme
   =========================== */
:root {
  --bg:            #0d1117;
  --bg-2:          #161b22;
  --surface:       #1c2333;
  --surface-2:     #243047;
  --primary:       #818cf8;
  --primary-dark:  #6366f1;
  --primary-glow:  rgba(129, 140, 248, 0.2);
  --primary-light: rgba(129, 140, 248, 0.08);
  --danger:        #f87171;
  --danger-light:  rgba(248, 113, 113, 0.1);
  --success:       #34d399;
  --success-light: rgba(52, 211, 153, 0.1);
  --text:          #e2e8f0;
  --text-muted:    #64748b;
  --text-dim:      #94a3b8;
  --border:        #2d3748;
  --border-bright: #3d4f6b;
  --shadow:        0 1px 3px 0 rgb(0 0 0 / 0.4), 0 1px 2px -1px rgb(0 0 0 / 0.4);
  --shadow-md:     0 4px 16px rgb(0 0 0 / 0.4);
  --shadow-glow:   0 0 20px rgba(129, 140, 248, 0.15);
  --radius:        16px;
  --radius-sm:     10px;
  --font:          -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', sans-serif;
}

/* ===========================
   Reset & Base
   =========================== */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
  color-scheme: dark;
}

body {
  background: var(--bg);
  font-family: var(--font);
  color: var(--text);
  min-height: 100vh;
  padding-bottom: calc(40px + env(safe-area-inset-bottom));
  padding-left: env(safe-area-inset-left);
  padding-right: env(safe-area-inset-right);
}

button, a, input {
  -webkit-tap-highlight-color: transparent;
}

/* ===========================
   Auth — PIN Screen
   =========================== */
.auth-screen {
  position: fixed;
  inset: 0;
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10000;
  padding: 24px;
}

.auth-box {
  width: 100%;
  max-width: 320px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0;
}

.auth-emoji {
  font-size: 3rem;
  margin-bottom: 16px;
}

.auth-title {
  font-size: 1.3rem;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 8px;
}

.auth-subtitle {
  font-size: 0.88rem;
  color: var(--text-muted);
  text-align: center;
  margin-bottom: 28px;
  min-height: 1.2em;
}

.pin-dots {
  display: flex;
  gap: 16px;
  margin-bottom: 12px;
}

.pin-dot {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  border: 2px solid var(--border-bright);
  background: transparent;
  transition: background 0.15s, border-color 0.15s, transform 0.1s;
}

.pin-dot.filled {
  background: var(--primary);
  border-color: var(--primary);
  transform: scale(1.1);
}

.auth-error {
  font-size: 0.82rem;
  color: var(--danger);
  height: 1.1em;
  margin-bottom: 20px;
  text-align: center;
}

.numpad {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  width: 100%;
}

.numpad-btn {
  height: 64px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 1.4rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.12s, transform 0.08s;
  font-family: var(--font);
}

.numpad-btn:hover  { background: var(--surface-2); }
.numpad-btn:active { transform: scale(0.93); background: var(--primary-light); }

.numpad-empty  { background: transparent; border-color: transparent; cursor: default; }
.numpad-empty:hover { background: transparent; }

.numpad-delete { color: var(--text-dim); font-size: 1.2rem; }

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20%       { transform: translateX(-8px); }
  40%       { transform: translateX(8px); }
  60%       { transform: translateX(-6px); }
  80%       { transform: translateX(6px); }
}

.shake { animation: shake 0.4s ease; }

/* ===========================
   Loader
   =========================== */
.loader {
  position: fixed;
  inset: 0;
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9999;
}

.loader-box {
  width: 280px;
  text-align: center;
}

.loader-emoji {
  font-size: 3rem;
  margin-bottom: 16px;
  display: block;
  animation: pulse 2s ease-in-out infinite;
}

.loader-text {
  color: var(--text-dim);
  font-size: 0.9rem;
  margin-bottom: 24px;
  font-weight: 500;
}

.progress-container {
  width: 100%;
  height: 4px;
  background: var(--surface);
  border-radius: 99px;
  overflow: hidden;
}

.progress-bar {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--primary-dark), var(--primary));
  border-radius: 99px;
  transition: width 0.4s ease;
  box-shadow: 0 0 8px var(--primary-glow);
}

@keyframes pulse {
  0%, 100% { transform: scale(1); opacity: 1; }
  50%       { transform: scale(1.12); opacity: 0.7; }
}

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

.app-icon { font-size: 1.4rem; }

.app-name {
  font-size: 1.1rem;
  font-weight: 700;
  background: linear-gradient(135deg, var(--primary), #c4b5fd);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  letter-spacing: -0.3px;
}

/* ===========================
   Pages
   =========================== */
.page { display: none; animation: fadeIn 0.2s ease; }
.page.active { display: block; }

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

/* ===========================
   Page Header
   =========================== */
.page-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px 16px 10px;
}

.page-header h2 {
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--text);
}

.btn-back {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-dim);
  cursor: pointer;
  flex-shrink: 0;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}

.btn-back:hover {
  background: var(--primary-light);
  color: var(--primary);
  border-color: var(--primary-dark);
}

/* ===========================
   Navigation Page
   =========================== */
.nav-container {
  max-width: 520px;
  margin: 0 auto;
  padding: 28px 16px;
}

.nav-subtitle {
  color: var(--text-muted);
  font-size: 0.8rem;
  margin-bottom: 20px;
  text-align: center;
  text-transform: uppercase;
  letter-spacing: 0.8px;
}

.nav-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.nav-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 28px 16px 24px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 6px;
  transition: transform 0.15s, box-shadow 0.2s, border-color 0.2s, background 0.2s;
  position: relative;
  overflow: hidden;
}

.nav-card::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 3px;
  background: linear-gradient(90deg, var(--primary-dark), var(--primary));
  opacity: 0;
  transition: opacity 0.2s;
}

.nav-card:hover               { transform: translateY(-3px); border-color: var(--border-bright); background: var(--surface-2); box-shadow: var(--shadow-glow); }
.nav-card:hover::before       { opacity: 1; }
.nav-card:active              { transform: translateY(0); }
.nav-card--wide               { grid-column: 1 / -1; padding: 22px 16px; flex-direction: row; justify-content: center; gap: 14px; }
.nav-card--wide .nav-card-desc { text-align: left; }

.nav-card-icon  { font-size: 2.2rem; margin-bottom: 4px; }
.nav-card--wide .nav-card-icon { font-size: 1.8rem; margin-bottom: 0; }
.nav-card-title { font-size: 1rem; font-weight: 700; color: var(--text); }
.nav-card-desc  { font-size: 0.78rem; color: var(--text-muted); line-height: 1.3; }

/* ===========================
   Form Card
   =========================== */
.form-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px 20px;
  margin: 8px 16px 20px;
  max-width: 520px;
  box-shadow: var(--shadow);
}

@media (min-width: 560px) {
  .form-card { margin-left: auto; margin-right: auto; }
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 7px;
  margin-bottom: 18px;
}

.form-group label {
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.7px;
}

.form-group input {
  padding: 12px 14px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 1rem;
  font-family: var(--font);
  color: var(--text);
  background: var(--bg-2);
  transition: border-color 0.15s, box-shadow 0.15s;
  width: 100%;
}

.form-group input:focus {
  outline: none;
  border-color: var(--primary-dark);
  box-shadow: 0 0 0 3px var(--primary-glow);
}

.form-group input::-webkit-calendar-picker-indicator { filter: invert(0.7); }

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

/* ===========================
   Form Message
   =========================== */
.form-message {
  font-size: 0.88rem;
  border-radius: var(--radius-sm);
  margin-bottom: 18px;
  line-height: 1.6;
  display: none;
}

.form-message:not(:empty) {
  display: block;
  padding: 12px 14px;
}

/* ===========================
   Primary Button
   =========================== */
.btn-primary {
  width: 100%;
  padding: 14px;
  background: linear-gradient(135deg, var(--primary-dark), var(--primary));
  color: white;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 1rem;
  font-weight: 600;
  font-family: var(--font);
  cursor: pointer;
  transition: opacity 0.15s, transform 0.1s, box-shadow 0.15s;
  letter-spacing: 0.2px;
  box-shadow: 0 2px 12px rgba(99, 102, 241, 0.35);
}

.btn-primary:hover  { opacity: 0.9; box-shadow: 0 4px 20px rgba(99, 102, 241, 0.5); }
.btn-primary:active { transform: scale(0.98); }

/* ===========================
   Filters Bar
   =========================== */
.filters-bar {
  display: flex;
  gap: 10px;
  padding: 12px 16px;
  background: var(--bg-2);
  border-top: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  margin-bottom: 12px;
}

.filter-field {
  display: flex;
  flex-direction: column;
  gap: 5px;
  flex: 1;
}

.filter-field label {
  font-size: 0.7rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.month-btn {
  padding: 10px 14px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 0.95rem;
  font-family: var(--font);
  color: var(--text);
  background: var(--surface);
  width: 100%;
  text-align: left;
  cursor: pointer;
  text-transform: capitalize;
  transition: border-color 0.15s, background 0.15s;
}

.month-btn:hover {
  border-color: var(--primary-dark);
  background: var(--primary-light);
}

/* ===========================
   Month Picker
   =========================== */
.month-picker-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.65);
  display: none;
  align-items: flex-end;
  justify-content: center;
  z-index: 5000;
  backdrop-filter: blur(4px);
  padding-bottom: env(safe-area-inset-bottom);
}

.month-picker-overlay.open { display: flex; }

.month-picker-box {
  background: var(--surface);
  border: 1px solid var(--border-bright);
  border-radius: var(--radius) var(--radius) 0 0;
  padding: 20px 16px 28px;
  width: 100%;
  max-width: 480px;
  box-shadow: var(--shadow-md);
  animation: slideUp 0.22s ease;
}

@keyframes slideUp {
  from { transform: translateY(100%); opacity: 0; }
  to   { transform: translateY(0);    opacity: 1; }
}

.month-picker-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 18px;
}

.month-picker-header span {
  font-weight: 700;
  font-size: 1.1rem;
  color: var(--text);
}

.month-picker-nav {
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
  width: 38px;
  height: 38px;
  border-radius: 50%;
  font-size: 22px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s;
}

.month-picker-nav:hover  { background: var(--border-bright); }
.month-picker-nav:active { transform: scale(0.92); }

.month-picker-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
}

.month-cell {
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text-dim);
  border-radius: 10px;
  padding: 12px 4px;
  font-size: 0.88rem;
  font-weight: 500;
  cursor: pointer;
  text-align: center;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}

.month-cell:hover {
  background: var(--primary-light);
  color: var(--primary);
  border-color: var(--primary-dark);
}

.month-cell.selected {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
  font-weight: 700;
}

.month-cell.in-range {
  background: var(--primary-light);
  color: var(--primary);
  border-color: transparent;
}

/* ===========================
   Table
   =========================== */
.table-wrapper {
  background: var(--surface);
  border-radius: var(--radius);
  margin: 0 16px 20px;
  overflow-x: auto;
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 540px;
  font-size: 0.875rem;
}

thead th {
  background: var(--surface-2);
  color: var(--text-dim);
  padding: 12px 10px;
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.7px;
  white-space: nowrap;
  border: none;
  border-bottom: 1px solid var(--border-bright);
  text-align: center;
}

thead tr th:first-child { border-radius: 15px 0 0 0; }
thead tr th:last-child  { border-radius: 0 15px 0 0; }

tbody tr { border-bottom: 1px solid var(--border); transition: background 0.1s; }
tbody tr:last-child      { border-bottom: none; }
tbody tr:nth-child(odd)  { background: var(--surface); }
tbody tr:nth-child(even) { background: var(--bg-2); }
tbody tr:hover           { background: var(--primary-light); }

tbody td {
  padding: 10px;
  text-align: center;
  color: var(--text);
  border: none;
  border-right: 1px solid var(--border);
  white-space: nowrap;
}

tbody td:last-child { border-right: none; }

td.week-total { font-weight: 700; color: var(--primary); }

tfoot tr { border-top: 2px solid var(--border-bright); }

tfoot th {
  padding: 10px;
  text-align: center;
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--text);
  background: var(--surface-2);
  border: none;
  border-right: 1px solid var(--border);
  white-space: nowrap;
}

tfoot th:last-child { border-right: none; }

/* ===========================
   Table Action Buttons
   =========================== */
.btn-action {
  width: 44px;
  height: 44px;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  background-size: 18px;
  background-repeat: no-repeat;
  background-position: center;
  transition: background-color 0.15s, transform 0.1s;
  vertical-align: middle;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.btn-action + .btn-action { margin-left: 4px; }

.btn-modifier {
  background-color: rgba(129, 140, 248, 0.12);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23818cf8' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M11 4H4a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2v-7'/%3E%3Cpath d='M18.5 2.5a2.121 2.121 0 0 1 3 3L12 15l-4 1 1-4 9.5-9.5z'/%3E%3C/svg%3E");
}

.btn-modifier:hover { background-color: rgba(129, 140, 248, 0.25); transform: scale(1.08); }

.btn-supprimer {
  background-color: rgba(248, 113, 113, 0.1);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23f87171' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='3 6 5 6 21 6'/%3E%3Cpath d='M19 6l-1 14a2 2 0 0 1-2 2H8a2 2 0 0 1-2-2L5 6'/%3E%3Cpath d='M10 11v6M14 11v6'/%3E%3Cpath d='M9 6V4a1 1 0 0 1 1-1h4a1 1 0 0 1 1 1v2'/%3E%3C/svg%3E");
}

.btn-supprimer:hover { background-color: rgba(248, 113, 113, 0.22); transform: scale(1.08); }

/* ===========================
   Dashboard
   =========================== */
.dash-container {
  max-width: 520px;
  margin: 0 auto;
  padding: 8px 16px 24px;
}

.dash-period-nav {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  margin-bottom: 14px;
}

.dash-nav-btn {
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
  width: 36px;
  height: 36px;
  border-radius: 50%;
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s, transform 0.1s;
  flex-shrink: 0;
}

.dash-nav-btn:hover  { background: var(--border-bright); }
.dash-nav-btn:active { transform: scale(0.93); }

.dash-period {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.8px;
  text-align: center;
}

.dash-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.dash-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px 16px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  transition: transform 0.15s, box-shadow 0.2s, border-color 0.15s;
  position: relative;
  overflow: hidden;
  cursor: pointer;
}

.dash-card:hover {
  transform: translateY(-2px);
  border-color: var(--border-bright);
  box-shadow: var(--shadow-glow);
}

.dash-card:active { transform: scale(0.97); }

.dash-card::after {
  content: '';
  position: absolute;
  bottom: 0; left: 0; right: 0;
  height: 2px;
  background: var(--border);
}

.dash-card--accent {
  border-color: var(--primary-dark);
  background: linear-gradient(135deg, rgba(99, 102, 241, 0.15), rgba(129, 140, 248, 0.05));
}

.dash-card--accent::after {
  background: linear-gradient(90deg, var(--primary-dark), var(--primary));
}

.dash-card-label {
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.6px;
}

.dash-card-value {
  font-size: 2rem;
  font-weight: 800;
  color: var(--text);
  line-height: 1;
  letter-spacing: -1px;
}

.dash-card--accent .dash-card-value { color: var(--primary); }

.dash-trend {
  font-size: 0.75rem;
  font-weight: 500;
  min-height: 1em;
}

.dash-trend.up      { color: var(--success); }
.dash-trend.down    { color: var(--danger); }
.dash-trend.neutral { color: var(--text-muted); }

.dash-daily {
  margin-top: 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 12px 10px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

/* ===========================
   Chart Overlay
   =========================== */
.chart-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.65);
  display: none;
  align-items: flex-end;
  justify-content: center;
  z-index: 5000;
  backdrop-filter: blur(4px);
  padding-bottom: env(safe-area-inset-bottom);
}

.chart-overlay.open { display: flex; }

.chart-box {
  background: var(--surface);
  border: 1px solid var(--border-bright);
  border-radius: var(--radius) var(--radius) 0 0;
  padding: 20px 16px 24px;
  width: 100%;
  max-width: 480px;
  box-shadow: var(--shadow-md);
  animation: slideUp 0.22s ease;
}

.chart-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}

.chart-header h3 {
  font-size: 1rem;
  font-weight: 700;
  color: var(--text);
}

.chart-close {
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text-dim);
  width: 32px;
  height: 32px;
  border-radius: 50%;
  font-size: 14px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s;
}

.chart-close:hover { background: var(--border-bright); }
