:root {
  --navy-950: #071b33;
  --navy-900: #0a2d55;
  --blue-700: #0b4f91;
  --blue-600: #145da0;
  --blue-100: #dcecff;
  --blue-50: #f2f8ff;
  --ink: #111827;
  --muted: #64748b;
  --line: #dce4ee;
  --surface: #ffffff;
  --canvas: #f4f7fb;
  --danger: #b42318;
  --success: #15803d;
  --warning: #b45309;
  --shadow: 0 18px 55px rgba(7, 27, 51, .11);
}

* { box-sizing: border-box; }
html { font-family: Inter, system-ui, sans-serif; color: var(--ink); background: var(--canvas); }
body { margin: 0; min-height: 100vh; }
button, input, textarea, select { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }
a { color: inherit; text-decoration: none; }
[hidden] { display: none !important; }

.auth-page {
  min-height: 100vh;
  display: grid;
  grid-template-columns: minmax(360px, .85fr) minmax(430px, 1.15fr);
  background: #fff;
}
.auth-visual {
  position: relative;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  min-height: 100vh;
  padding: clamp(32px, 6vw, 80px);
  color: #fff;
  overflow: hidden;
  background: radial-gradient(circle at 80% 18%, rgba(70, 155, 255, .42), transparent 30%), linear-gradient(145deg, var(--navy-950), var(--blue-700));
}
.auth-visual::after {
  content: "";
  position: absolute;
  width: 520px;
  height: 520px;
  border: 1px solid rgba(255, 255, 255, .18);
  border-radius: 50%;
  right: -260px;
  bottom: -210px;
  box-shadow: 0 0 0 80px rgba(255,255,255,.035), 0 0 0 160px rgba(255,255,255,.025);
}
.auth-brand { position: relative; z-index: 1; font-weight: 900; letter-spacing: -.03em; }
.auth-copy { position: relative; z-index: 1; max-width: 620px; }
.auth-copy h1 { margin: 0 0 20px; font-size: clamp(2.5rem, 5vw, 5.5rem); line-height: .95; letter-spacing: -.075em; }
.auth-copy p { margin: 0; max-width: 540px; color: rgba(255,255,255,.75); font-size: 1.05rem; }
.auth-panel { display: grid; place-items: center; padding: 32px; }
.auth-card { width: min(440px, 100%); }
.auth-card h2 { margin: 0 0 10px; font-size: 2rem; letter-spacing: -.04em; color: var(--navy-950); }
.auth-card > p { color: var(--muted); margin: 0 0 32px; }
.back-link { display: inline-flex; margin-bottom: 32px; color: var(--blue-700); font-weight: 800; }

.field { display: grid; gap: 8px; margin-bottom: 18px; }
.field label { font-size: .9rem; font-weight: 800; color: #334155; }
.field input, .field textarea, .field select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 13px 14px;
  color: var(--ink);
  background: #fff;
  outline: none;
  transition: border-color .2s, box-shadow .2s;
}
.field textarea { min-height: 120px; resize: vertical; }
.field input:focus, .field textarea:focus, .field select:focus { border-color: var(--blue-600); box-shadow: 0 0 0 4px rgba(20,93,160,.1); }
.field small { color: var(--muted); }
.field-row { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.field-row.three { grid-template-columns: repeat(3, minmax(0, 1fr)); }

.button {
  border: 0;
  border-radius: 14px;
  min-height: 46px;
  padding: 0 18px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 9px;
  cursor: pointer;
  font-weight: 850;
  transition: transform .18s, box-shadow .18s, opacity .18s;
}
.button:hover { transform: translateY(-1px); }
.button:disabled { opacity: .55; cursor: not-allowed; transform: none; }
.button-primary { color: #fff; background: linear-gradient(135deg, var(--navy-900), var(--blue-600)); box-shadow: 0 12px 28px rgba(20,93,160,.22); }
.button-secondary { color: var(--navy-900); background: var(--blue-50); border: 1px solid var(--blue-100); }
.button-ghost { color: #334155; background: #fff; border: 1px solid var(--line); }
.button-danger { color: var(--danger); background: #fff1f0; border: 1px solid #ffd5d2; }
.button-block { width: 100%; }

.message { padding: 12px 14px; border-radius: 12px; margin: 16px 0; font-weight: 700; font-size: .92rem; }
.message.error { color: var(--danger); background: #fff1f0; }
.message.success { color: var(--success); background: #ecfdf3; }
.message.info { color: var(--blue-700); background: var(--blue-50); }

.app-layout { min-height: 100vh; display: grid; grid-template-columns: 260px minmax(0, 1fr); }
.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  padding: 24px 18px;
  color: #fff;
  background: linear-gradient(180deg, var(--navy-950), #092846);
  display: flex;
  flex-direction: column;
  z-index: 20;
}
.app-brand { padding: 8px 12px 26px; font-weight: 900; letter-spacing: -.04em; font-size: 1.15rem; }
.app-brand small { display: block; margin-top: 4px; color: rgba(255,255,255,.52); font-weight: 650; font-size: .72rem; letter-spacing: .03em; text-transform: uppercase; }
.side-label { margin: 22px 12px 8px; color: rgba(255,255,255,.42); text-transform: uppercase; letter-spacing: .12em; font-size: .68rem; font-weight: 900; }
.side-nav { display: grid; gap: 5px; }
.side-nav a { display: flex; align-items: center; gap: 12px; padding: 11px 12px; border-radius: 12px; color: rgba(255,255,255,.72); font-weight: 750; }
.side-nav a:hover, .side-nav a.active { color: #fff; background: rgba(255,255,255,.1); }
.side-icon { width: 26px; text-align: center; }
.sidebar-footer { margin-top: auto; display: grid; gap: 8px; }
.sidebar-footer button, .sidebar-footer a { width: 100%; color: rgba(255,255,255,.7); background: transparent; border: 0; text-align: left; cursor: pointer; padding: 10px 12px; border-radius: 10px; font-weight: 750; }
.sidebar-footer button:hover, .sidebar-footer a:hover { background: rgba(255,255,255,.08); color: #fff; }

.mobile-topbar { display: none; }
.app-main { min-width: 0; }
.app-content { width: min(1240px, calc(100% - 48px)); margin: 0 auto; padding: 42px 0 80px; }
.page-heading { display: flex; align-items: flex-end; justify-content: space-between; gap: 24px; margin-bottom: 30px; }
.page-heading h1 { margin: 0 0 7px; color: var(--navy-950); font-size: clamp(2rem, 4vw, 3.3rem); letter-spacing: -.06em; line-height: 1; }
.page-heading p { margin: 0; color: var(--muted); }
.heading-actions { display: flex; flex-wrap: wrap; gap: 10px; }

.stat-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 16px; margin-bottom: 26px; }
.stat-card, .panel, .course-card, .exercise-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 20px;
  box-shadow: 0 8px 30px rgba(7,27,51,.045);
}
.stat-card { padding: 20px; }
.stat-card span { display: block; color: var(--muted); font-size: .82rem; font-weight: 750; margin-bottom: 8px; }
.stat-card strong { display: block; color: var(--navy-950); font-size: 1.55rem; letter-spacing: -.035em; }
.stat-card small { color: var(--muted); }
.panel { padding: 24px; }
.panel + .panel { margin-top: 18px; }
.panel-header { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 20px; }
.panel-header h2, .panel-header h3 { margin: 0; color: var(--navy-950); letter-spacing: -.035em; }
.panel-header p { margin: 4px 0 0; color: var(--muted); font-size: .92rem; }
.two-column { display: grid; grid-template-columns: minmax(0, 1.45fr) minmax(300px, .75fr); gap: 20px; align-items: start; }
.three-column { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 18px; }
.cards-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px; }

.course-card { padding: 23px; transition: transform .18s, box-shadow .18s; }
.course-card:hover { transform: translateY(-2px); box-shadow: var(--shadow); }
.course-code { display: inline-flex; padding: 6px 9px; border-radius: 8px; color: var(--blue-700); background: var(--blue-50); font-size: .76rem; font-weight: 900; letter-spacing: .06em; }
.course-card h2 { margin: 16px 0 8px; color: var(--navy-950); letter-spacing: -.035em; }
.course-card p { color: var(--muted); margin: 0 0 18px; }
.meta-row { display: flex; flex-wrap: wrap; gap: 8px; color: var(--muted); font-size: .84rem; font-weight: 700; }
.meta-pill { padding: 6px 9px; border-radius: 999px; background: #f5f7fa; }

.tabs { display: flex; gap: 6px; padding: 6px; margin-bottom: 22px; border: 1px solid var(--line); border-radius: 15px; background: #fff; overflow-x: auto; }
.tabs button, .tabs a { border: 0; background: transparent; white-space: nowrap; padding: 10px 14px; border-radius: 10px; color: var(--muted); font-weight: 800; cursor: pointer; }
.tabs button.active, .tabs a.active { background: var(--navy-900); color: #fff; }

.period-toolbar { display: flex; align-items: center; flex-wrap: wrap; gap: 9px; margin: -4px 0 22px; }
.period-toolbar input[type="month"] { min-height: 46px; padding: 0 14px; border: 1px solid var(--line); border-radius: 14px; color: var(--navy-950); background: #fff; font-weight: 800; }
.period-toolbar input.year-mode { border-color: var(--blue-600); background: var(--blue-50); }
.period-arrow { width: 46px; padding: 0; font-size: 1.15rem; }
.balance-panel { margin-bottom: 20px; }
.balance-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px; }
.balance-card { position: relative; overflow: hidden; padding: 20px; border: 1px solid var(--line); border-radius: 17px; background: #f9fbfe; }
.balance-card::before { content: ""; position: absolute; inset: 0 auto 0 0; width: 5px; background: var(--blue-600); }
.balance-card.cash::before { background: #d97706; }
.balance-card.total::before { background: var(--success); }
.balance-card span { display: block; margin-bottom: 8px; color: var(--muted); font-size: .82rem; font-weight: 800; }
.balance-card strong { display: block; color: var(--navy-950); font-size: 1.65rem; letter-spacing: -.04em; }
.balance-card small { display: block; margin-top: 6px; color: var(--muted); }
.account-badge { display: inline-flex; align-items: center; padding: 5px 9px; border-radius: 999px; color: var(--blue-700); background: var(--blue-50); font-size: .77rem; font-weight: 850; white-space: nowrap; }
.account-badge.cash { color: #9a5604; background: #fff7e8; }
.account-setting { margin: 0 0 16px; padding: 16px; border: 1px solid var(--line); border-radius: 16px; }
.account-setting legend { padding: 0 8px; color: var(--navy-950); font-weight: 900; }
.account-setting .field { margin-bottom: 0; }
.month-link { border: 0; padding: 0; color: var(--blue-700); background: transparent; font-weight: 850; text-transform: capitalize; cursor: pointer; }
.month-link:hover { text-decoration: underline; }

.list { display: grid; gap: 10px; }
.list-row { display: flex; justify-content: space-between; align-items: center; gap: 16px; padding: 15px 16px; border: 1px solid var(--line); border-radius: 14px; background: #fff; }
.list-row-main { min-width: 0; }
.list-row strong { display: block; color: var(--navy-950); }
.list-row small { color: var(--muted); }
.row-actions { display: flex; gap: 8px; flex: 0 0 auto; }

.empty-state { padding: 38px 20px; text-align: center; color: var(--muted); border: 1px dashed #cbd5e1; border-radius: 16px; background: #fafcff; }
.empty-state strong { display: block; color: var(--navy-950); margin-bottom: 6px; }
.loader { min-height: 180px; display: grid; place-items: center; color: var(--muted); font-weight: 700; }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 13px 12px; text-align: left; border-bottom: 1px solid var(--line); }
th { color: var(--muted); text-transform: uppercase; letter-spacing: .06em; font-size: .72rem; }
td { font-size: .92rem; }
.amount-income { color: var(--success); font-weight: 900; }
.amount-expense { color: var(--danger); font-weight: 900; }
.table-subtitle { display: block; margin-top: 4px; color: var(--muted); }
.row-muted { opacity: .58; }
.status-pill { border: 1px solid var(--line); border-radius: 999px; padding: 6px 10px; color: var(--muted); background: #f8fafc; font-size: .78rem; font-weight: 850; cursor: pointer; }
.status-pill.active { color: var(--success); border-color: #bbdfc7; background: #ecfdf3; }
.account-dot { display: inline-block; width: 9px; height: 9px; margin-right: 8px; border-radius: 50%; }
.account-maman { border-top: 4px solid #8b5cf6; }
.account-livret { border-top: 4px solid var(--blue-600); }
.savings-layout { grid-template-columns: minmax(0, 1.6fr) minmax(280px, .6fr); }

.bar-list { display: grid; gap: 15px; }
.bar-head { display: flex; justify-content: space-between; gap: 10px; font-size: .85rem; font-weight: 750; }
.bar-track { height: 9px; margin-top: 7px; overflow: hidden; border-radius: 999px; background: #eaf0f6; }
.bar-fill { height: 100%; border-radius: inherit; background: linear-gradient(90deg, var(--blue-600), #4c9df0); }
.bar-fill.negative { background: linear-gradient(90deg, #dc2626, #fb7185); }

.quiz-stage { max-width: 800px; margin: 0 auto; }
.quiz-progress { height: 8px; margin: 14px 0 28px; background: #e5edf6; border-radius: 999px; overflow: hidden; }
.quiz-progress span { display: block; height: 100%; background: var(--blue-600); transition: width .2s; }
.question-card { padding: clamp(22px, 4vw, 38px); background: #fff; border: 1px solid var(--line); border-radius: 24px; box-shadow: var(--shadow); }
.question-card h2 { margin: 10px 0 24px; color: var(--navy-950); font-size: clamp(1.3rem, 3vw, 1.85rem); letter-spacing: -.035em; }
.answers { display: grid; gap: 11px; }
.answer-option { display: flex; align-items: flex-start; gap: 11px; padding: 14px; border: 1px solid var(--line); border-radius: 14px; cursor: pointer; }
.answer-option:hover { background: var(--blue-50); border-color: #aacbf0; }
.answer-option input { margin-top: 4px; }
.quiz-footer { display: flex; justify-content: space-between; align-items: center; gap: 16px; margin-top: 22px; }
.correction { margin-top: 18px; padding: 16px; border-radius: 14px; background: #f6f9fc; border-left: 4px solid var(--blue-600); }

.exercise-card { padding: 22px; }
.exercise-card h3 { margin: 10px 0; color: var(--navy-950); }
.exercise-statement { color: #334155; white-space: pre-wrap; }
.exercise-correction { padding: 16px; margin-top: 16px; border-radius: 14px; background: #eefbf3; border: 1px solid #ccebd7; white-space: pre-wrap; }
.difficulty { font-size: .76rem; font-weight: 900; color: var(--warning); text-transform: uppercase; letter-spacing: .06em; }

.manage-grid { display: grid; grid-template-columns: 260px minmax(0, 1fr); gap: 20px; align-items: start; }
.manage-menu { position: sticky; top: 24px; display: grid; gap: 6px; padding: 8px; border: 1px solid var(--line); border-radius: 16px; background: #fff; }
.manage-menu button { border: 0; text-align: left; padding: 11px 12px; border-radius: 10px; background: transparent; color: var(--muted); font-weight: 800; cursor: pointer; }
.manage-menu button.active { color: #fff; background: var(--navy-900); }
.option-builder { display: grid; gap: 10px; }
.option-row { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; gap: 10px; align-items: center; }
.option-row input[type="text"] { border: 1px solid var(--line); border-radius: 11px; padding: 10px 12px; }

.modal-backdrop { position: fixed; inset: 0; z-index: 100; display: grid; place-items: center; padding: 20px; background: rgba(7,27,51,.64); backdrop-filter: blur(8px); }
.modal { width: min(650px, 100%); max-height: 90vh; overflow: auto; padding: 24px; border-radius: 22px; background: #fff; box-shadow: var(--shadow); }
.modal h2 { margin-top: 0; color: var(--navy-950); }

@media (max-width: 1050px) {
  .stat-grid { grid-template-columns: repeat(2, 1fr); }
  .balance-grid { grid-template-columns: repeat(2, 1fr); }
  .balance-card.total { grid-column: 1 / -1; }
  .three-column { grid-template-columns: 1fr 1fr; }
  .two-column { grid-template-columns: 1fr; }
}

@media (max-width: 780px) {
  .auth-page { grid-template-columns: 1fr; }
  .auth-visual { display: none; }
  .auth-panel { min-height: 100vh; padding: 24px; }
  .app-layout { display: block; }
  .sidebar { position: fixed; inset: 0 auto 0 0; width: 270px; transform: translateX(-100%); transition: transform .2s; box-shadow: var(--shadow); }
  .sidebar.open { transform: translateX(0); }
  .mobile-topbar { display: flex; align-items: center; justify-content: space-between; position: sticky; top: 0; z-index: 15; height: 64px; padding: 0 18px; background: rgba(255,255,255,.92); backdrop-filter: blur(14px); border-bottom: 1px solid var(--line); }
  .mobile-topbar strong { color: var(--navy-950); }
  .menu-button { border: 0; width: 42px; height: 42px; border-radius: 11px; background: var(--blue-50); color: var(--navy-900); font-size: 1.3rem; cursor: pointer; }
  .app-content { width: min(100% - 28px, 1240px); padding-top: 26px; }
  .page-heading { align-items: flex-start; flex-direction: column; }
  .cards-grid, .manage-grid, .three-column { grid-template-columns: 1fr; }
  .manage-menu { position: static; grid-template-columns: repeat(2, 1fr); }
  .field-row, .field-row.three { grid-template-columns: 1fr; gap: 0; }
}

@media (max-width: 500px) {
  .stat-grid { grid-template-columns: 1fr; }
  .balance-grid { grid-template-columns: 1fr; }
  .balance-card.total { grid-column: auto; }
  .period-toolbar { display: grid; grid-template-columns: 46px minmax(0, 1fr) 46px; }
  .period-toolbar .button:not(.period-arrow) { grid-column: span 3; }
  .period-toolbar input[type="month"] { min-width: 0; width: 100%; }
  .panel { padding: 18px; }
  .list-row { align-items: flex-start; flex-direction: column; }
  .row-actions { width: 100%; }
  .row-actions .button { flex: 1; }
  .quiz-footer { align-items: stretch; flex-direction: column; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition-duration: .01ms !important; }
}
