/*
 * MMBT Scolarité - Feuille de style principale
 * Auteur : Maabadi Ben Tamou (MMBT)
 * Copyright (c) 2026 MMBT
 */

:root,
html[data-theme="light"] {
  --bg-deep: #f1f5f9;
  --bg-surface: #ffffff;
  --bg-elevated: #f8fafc;
  --bg-hover: #eff6ff;
  --header-bg: #ffffff;

  --text-main: #0f172a;
  --text-muted: #475569;
  --table-head-bg: #f8fafc;
  --table-border: #e2e8f0;

  --border-subtle: #cbd5e1;
  --border-strong: var(--accent);

  --shadow-card: 0 4px 16px rgba(15, 23, 42, 0.06);

  --green-paid: #16a34a;
  --green-bg: #dcfce7;
  --green-text: #166534;

  --orange-partial: #ea580c;
  --orange-bg: #ffedd5;
  --orange-text: #9a3412;

  --red-late: #dc2626;
  --red-bg: #fee2e2;
  --red-text: #991b1b;

  --gray-upcoming: #94a3b8;
  --gray-bg: #f1f5f9;
  --gray-text: #64748b;

  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
}

html[data-theme="dark"] {
  --bg-deep: #0b0f17;
  --bg-surface: #131b2a;
  --bg-elevated: #1c263b;
  --bg-hover: #24304a;
  --header-bg: #111826;

  --text-main: #f8fafc;
  --text-muted: #94a3b8;
  --table-head-bg: #172033;
  --table-border: rgba(255, 255, 255, 0.08);

  --border-subtle: rgba(148, 163, 184, 0.22);
  --border-strong: var(--accent);

  --shadow-card: 0 10px 30px rgba(0, 0, 0, 0.45);

  --green-paid: #2e7d32;
  --green-bg: rgba(46, 125, 50, 0.22);
  --green-text: #86efac;

  --orange-partial: #ef6c00;
  --orange-bg: rgba(239, 108, 0, 0.22);
  --orange-text: #fdba74;

  --red-late: #c62828;
  --red-bg: rgba(198, 40, 40, 0.25);
  --red-text: #fca5a5;

  --gray-upcoming: #475569;
  --gray-bg: rgba(148, 163, 184, 0.12);
  --gray-text: #94a3b8;
}

html[data-theme="dark"][data-palette="gold"] {
  --bg-deep: #0a0a08;
  --bg-surface: #121210;
  --bg-elevated: #1b1b17;
  --bg-hover: #24241e;
  --header-bg: #141411;
  --table-head-bg: #171713;
}

:root,
html[data-palette="blue"] {
  --accent: #2563eb;
  --accent-light: #3b82f6;
  --accent-contrast: #ffffff;
  --accent-dim: rgba(37, 99, 235, 0.12);
}

html[data-palette="emerald"] {
  --accent: #059669;
  --accent-light: #10b981;
  --accent-contrast: #ffffff;
  --accent-dim: rgba(5, 150, 105, 0.12);
}

html[data-palette="indigo"] {
  --accent: #4f46e5;
  --accent-light: #6366f1;
  --accent-contrast: #ffffff;
  --accent-dim: rgba(79, 70, 229, 0.12);
}

html[data-palette="burgundy"] {
  --accent: #be123c;
  --accent-light: #e11d48;
  --accent-contrast: #ffffff;
  --accent-dim: rgba(190, 18, 60, 0.12);
}

html[data-palette="gold"] {
  --accent: #b59822;
  --accent-light: #c2ad4a;
  --accent-contrast: #0a0a08;
  --accent-dim: rgba(194, 173, 74, 0.16);
}

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

body {
  background-color: var(--bg-deep);
  color: var(--text-main);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
  line-height: 1.5;
  min-height: 100vh;
  transition: background-color 0.2s ease, color 0.2s ease;
  -webkit-font-smoothing: antialiased;
}

.app-header {
  background: var(--header-bg);
  border-bottom: 1px solid var(--border-subtle);
  position: sticky;
  top: 0;
  z-index: 50;
  padding: 0.8rem 1.5rem;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.04);
}

.header-inner {
  max-width: 1440px;
  margin: 0 auto;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.9rem;
}

.brand-block {
  display: flex;
  align-items: center;
  gap: 0.85rem;
}

.brand-monogram {
  width: 46px;
  height: 46px;
  border-radius: 12px;
  background: var(--accent);
  color: var(--accent-contrast);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: 0.92rem;
  letter-spacing: 0.05em;
  box-shadow: 0 4px 12px var(--accent-dim);
  flex-shrink: 0;
}

.brand-titles h1 {
  font-size: 1.12rem;
  font-weight: 800;
  color: var(--text-main);
  letter-spacing: -0.01em;
}

.brand-titles p {
  font-size: 0.76rem;
  color: var(--accent);
  font-weight: 600;
}

.header-controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.55rem;
}

.theme-switcher-bar {
  display: inline-flex;
  align-items: center;
  gap: 0.38rem;
  background: var(--bg-elevated);
  border: 1px solid var(--border-subtle);
  padding: 0.28rem 0.55rem;
  border-radius: 999px;
}

.theme-mode-btn {
  background: var(--bg-surface);
  color: var(--text-main);
  border: 1px solid var(--border-subtle);
  border-radius: 999px;
  padding: 0.22rem 0.6rem;
  font-size: 0.75rem;
  font-weight: 700;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  transition: all 0.15s ease;
}

.theme-mode-btn:hover {
  border-color: var(--accent);
}

.color-swatch {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  border: 2px solid transparent;
  cursor: pointer;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.color-swatch:hover {
  transform: scale(1.15);
}

.color-swatch.active {
  border-color: var(--text-main);
  box-shadow: 0 0 0 2px var(--bg-surface);
  transform: scale(1.12);
}

.custom-color-input {
  width: 22px;
  height: 22px;
  border: none;
  padding: 0;
  background: transparent;
  cursor: pointer;
  border-radius: 50%;
}

.network-pill {
  display: inline-flex;
  align-items: center;
  gap: 0.42rem;
  padding: 0.34rem 0.7rem;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 600;
  background: var(--bg-elevated);
  border: 1px solid var(--border-subtle);
}

.network-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--green-paid);
  box-shadow: 0 0 6px var(--green-paid);
}

.network-pill.offline .network-dot {
  background: var(--orange-partial);
  box-shadow: 0 0 6px var(--orange-partial);
}

.control-group {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  background: var(--bg-elevated);
  border: 1px solid var(--border-subtle);
  padding: 0.28rem 0.6rem;
  border-radius: var(--radius-sm);
  font-size: 0.78rem;
}

.control-group label {
  color: var(--text-muted);
  font-weight: 600;
}

.control-group select,
.control-group input {
  background: transparent;
  border: none;
  color: var(--accent);
  font-weight: 700;
  font-size: 0.82rem;
  outline: none;
  cursor: pointer;
}

.control-group select option {
  background: var(--bg-surface);
  color: var(--text-main);
}

.control-group input[type="number"] {
  width: 11ch;
  min-width: 96px;
  text-align: right;
  border-bottom: 1px dashed var(--accent);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.42rem;
  padding: 0.5rem 0.9rem;
  border-radius: var(--radius-sm);
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
  border: 1px solid transparent;
  transition: all 0.16s ease;
  text-decoration: none;
  white-space: nowrap;
}

.btn-gold {
  background: var(--accent);
  color: var(--accent-contrast);
  border-color: var(--accent);
  box-shadow: 0 3px 10px var(--accent-dim);
}

.btn-gold:hover {
  filter: brightness(1.08);
  transform: translateY(-1px);
}

.btn-outline-gold {
  background: var(--accent-dim);
  color: var(--accent);
  border-color: var(--accent);
}

.btn-outline-gold:hover {
  background: var(--accent);
  color: var(--accent-contrast);
}

.btn-whatsapp {
  background: #16a34a;
  color: #ffffff;
  border-color: #15803d;
}

.btn-whatsapp:hover {
  background: #15803d;
  transform: translateY(-1px);
}

.btn-danger {
  background: var(--red-bg);
  color: var(--red-text);
  border-color: var(--red-late);
}

.btn-ghost {
  background: var(--bg-elevated);
  color: var(--text-muted);
  border-color: var(--border-subtle);
}

.btn-ghost:hover {
  color: var(--text-main);
  border-color: var(--accent);
}

.btn-sm {
  padding: 0.32rem 0.65rem;
  font-size: 0.76rem;
}

.main-container {
  max-width: 1440px;
  margin: 0 auto;
  padding: 1.25rem 1.5rem 3rem;
}

.nav-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 0.55rem;
  margin-bottom: 1.25rem;
  border-bottom: 1px solid var(--border-subtle);
  padding-bottom: 0.8rem;
}

.tab-btn {
  background: var(--bg-surface);
  color: var(--text-muted);
  border: 1px solid var(--border-subtle);
  padding: 0.6rem 1.1rem;
  border-radius: var(--radius-sm);
  font-size: 0.86rem;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 0.48rem;
  transition: all 0.15s ease;
}

.tab-btn:hover {
  color: var(--text-main);
  border-color: var(--accent);
}

.tab-btn.active {
  background: var(--accent);
  color: var(--accent-contrast);
  border-color: var(--accent);
  box-shadow: 0 3px 10px var(--accent-dim);
}

.badge-count {
  padding: 0.12rem 0.48rem;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 700;
  background: var(--bg-elevated);
  color: var(--text-main);
}

.tab-btn.active .badge-count {
  background: rgba(255, 255, 255, 0.22);
  color: var(--accent-contrast);
}

.badge-count.alert {
  background: var(--red-late);
  color: #fff;
}

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(265px, 1fr));
  gap: 1rem;
  margin-bottom: 1.25rem;
}

.kpi-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 1.15rem 1.25rem;
  box-shadow: var(--shadow-card);
  position: relative;
  overflow: hidden;
}

.kpi-card::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  width: 4px;
  height: 100%;
  background: var(--accent);
}

.kpi-card.kpi-collected::before {
  background: var(--green-paid);
}

.kpi-card.kpi-remaining::before {
  background: var(--red-late);
}

.kpi-label {
  font-size: 0.76rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  font-weight: 700;
  margin-bottom: 0.4rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.kpi-value-kmf {
  font-size: 1.55rem;
  font-weight: 800;
  color: var(--text-main);
  letter-spacing: -0.01em;
}

.kpi-card.kpi-collected .kpi-value-kmf {
  color: var(--green-text);
}

.kpi-card.kpi-remaining .kpi-value-kmf {
  color: var(--red-text);
}

.kpi-value-eur {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--accent);
  margin-top: 0.2rem;
}

.kpi-sub {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 0.45rem;
}

.gauge-wrapper {
  margin-top: 0.65rem;
}

.gauge-bar-bg {
  width: 100%;
  height: 12px;
  background: var(--bg-deep);
  border-radius: 999px;
  overflow: hidden;
  border: 1px solid var(--border-subtle);
}

.gauge-bar-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--accent) 0%, var(--green-paid) 100%);
  border-radius: 999px;
  transition: width 0.35s ease;
}

.toolbar-panel {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 0.9rem 1.15rem;
  margin-bottom: 1.15rem;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.9rem;
  box-shadow: var(--shadow-card);
}

.class-pills {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}

.class-pill {
  background: var(--bg-elevated);
  color: var(--text-muted);
  border: 1px solid var(--border-subtle);
  padding: 0.35rem 0.75rem;
  border-radius: 999px;
  font-size: 0.79rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s ease;
}

.class-pill.is-empty:not(.active) { opacity: 0.55; }
.class-pill:hover {
  color: var(--text-main);
  border-color: var(--accent);
}

.class-pill.active {
  background: var(--accent);
  color: var(--accent-contrast);
  border-color: var(--accent);
}

.search-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.6rem;
}

.search-input {
  background: var(--bg-elevated);
  border: 1px solid var(--border-subtle);
  color: var(--text-main);
  padding: 0.48rem 0.85rem;
  border-radius: var(--radius-sm);
  font-size: 0.84rem;
  min-width: 240px;
}

.search-input:focus {
  outline: none;
  border-color: var(--accent);
}

.status-legend {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 1rem;
  font-size: 0.79rem;
  color: var(--text-muted);
  margin-bottom: 0.75rem;
}

.legend-item {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  font-weight: 600;
}

.legend-dot {
  width: 11px;
  height: 11px;
  border-radius: 50%;
  display: inline-block;
}

.legend-dot.paid { background: var(--green-paid); }
.legend-dot.partial { background: var(--orange-partial); }
.legend-dot.late { background: var(--red-late); }
.legend-dot.upcoming { background: var(--gray-upcoming); }

.table-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-card);
  overflow-x: auto;
}

.mmbt-table {
  width: 100%;
  border-collapse: collapse;
  min-width: 1080px;
}

.mmbt-table th,
.mmbt-table td {
  padding: 0.75rem 0.65rem;
  text-align: left;
  border-bottom: 1px solid var(--table-border);
  vertical-align: middle;
}

.mmbt-table th {
  background: var(--table-head-bg);
  color: var(--text-muted);
  font-size: 0.73rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  white-space: nowrap;
}

.mmbt-table th.month-col,
.mmbt-table td.month-col {
  text-align: center;
  padding: 0.55rem 0.28rem;
}

.mmbt-table th.active-month-col {
  background: var(--accent-dim);
  color: var(--accent);
  border-bottom: 2px solid var(--accent);
}

.mmbt-table tbody tr:hover {
  background: var(--bg-hover);
}

.student-matricule {
  font-family: "Courier New", Courier, monospace;
  font-size: 0.74rem;
  color: var(--accent);
  font-weight: 700;
  background: var(--accent-dim);
  padding: 0.14rem 0.45rem;
  border-radius: 4px;
  display: inline-block;
}

.student-name {
  font-weight: 700;
  font-size: 0.9rem;
  color: var(--text-main);
  margin-top: 0.15rem;
}

.student-parent {
  font-size: 0.75rem;
  color: var(--text-muted);
}

.class-badge {
  display: inline-block;
  padding: 0.2rem 0.55rem;
  border-radius: 6px;
  background: var(--bg-elevated);
  border: 1px solid var(--border-subtle);
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--accent);
}

.fee-amount {
  font-weight: 700;
  font-size: 0.88rem;
  color: var(--text-main);
}

.fee-discount {
  font-size: 0.72rem;
  color: var(--green-text);
  font-weight: 600;
  display: block;
}

.month-pill {
  width: 62px;
  min-height: 36px;
  border-radius: 8px;
  border: 1px solid transparent;
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 0.7rem;
  font-weight: 700;
  padding: 0.2rem 0.25rem;
  transition: transform 0.12s ease, filter 0.12s ease;
  user-select: none;
}

.month-pill:hover {
  transform: scale(1.07);
  filter: brightness(0.97);
}

.month-pill.status-paid {
  background: var(--green-bg);
  color: var(--green-text);
  border-color: var(--green-paid);
}

.month-pill.status-partial {
  background: var(--orange-bg);
  color: var(--orange-text);
  border-color: var(--orange-partial);
}

.month-pill.status-late {
  background: var(--red-bg);
  color: var(--red-text);
  border-color: var(--red-late);
}

.month-pill.status-upcoming {
  background: var(--gray-bg);
  color: var(--gray-text);
  border-color: var(--border-subtle);
}

.month-pill .pill-sub {
  font-size: 0.62rem;
  opacity: 0.9;
  font-weight: 600;
}

.view-section {
  display: none;
}

.view-section.active {
  display: block;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.65);
  backdrop-filter: blur(4px);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 1rem;
  overflow-y: auto;
}

.modal-backdrop.open {
  display: flex;
}

.modal-box {
  background: var(--bg-surface);
  border: 2px solid var(--accent);
  border-radius: var(--radius-lg);
  width: 100%;
  max-width: 580px;
  padding: 1.4rem 1.5rem;
  box-shadow: 0 20px 55px rgba(0, 0, 0, 0.35);
  max-height: 92vh;
  overflow-y: auto;
}

.modal-box.modal-wide {
  max-width: 780px;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--border-subtle);
  padding-bottom: 0.85rem;
  margin-bottom: 1.1rem;
}

.modal-header h2 {
  font-size: 1.08rem;
  color: var(--text-main);
}

.close-btn {
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 1.4rem;
  cursor: pointer;
  line-height: 1;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 0.9rem;
}

.form-field {
  display: flex;
  flex-direction: column;
  gap: 0.32rem;
}

.form-field label {
  font-size: 0.78rem;
  color: var(--text-muted);
  font-weight: 600;
}

.form-field input,
.form-field select {
  background: var(--bg-elevated);
  border: 1px solid var(--border-subtle);
  color: var(--text-main);
  padding: 0.55rem 0.75rem;
  border-radius: var(--radius-sm);
  font-size: 0.88rem;
}

.form-field input:focus,
.form-field select:focus {
  outline: none;
  border-color: var(--accent);
}

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 0.65rem;
  margin-top: 1.25rem;
  padding-top: 0.9rem;
  border-top: 1px solid var(--border-subtle);
}

.receipt-paper {
  background: #ffffff;
  color: #111111;
  border: 2px solid var(--accent);
  border-radius: 10px;
  padding: 1.25rem;
  font-family: "Segoe UI", Roboto, sans-serif;
  margin: 0 auto;
  transition: max-width 0.2s ease;
}

.receipt-paper.format-a5 {
  max-width: 680px;
}

.receipt-paper.format-80mm {
  max-width: 315px;
  font-size: 0.82rem;
  padding: 0.9rem;
}

.receipt-top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  border-bottom: 2px solid #111;
  padding-bottom: 0.75rem;
  margin-bottom: 0.85rem;
  gap: 0.75rem;
}

.receipt-paper.format-80mm .receipt-top {
  flex-direction: column;
  align-items: center;
  text-align: center;
}

.receipt-school-title {
  font-size: 1.08rem;
  font-weight: 800;
  text-transform: uppercase;
  color: #0f172a;
}

.receipt-meta-box {
  text-align: right;
  font-size: 0.8rem;
}

.receipt-paper.format-80mm .receipt-meta-box {
  text-align: center;
}

.receipt-body-grid {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 1rem;
  align-items: center;
}

.receipt-paper.format-80mm .receipt-body-grid {
  grid-template-columns: 1fr;
  justify-items: center;
}

.receipt-lines {
  width: 100%;
  border-collapse: collapse;
}

.receipt-lines td {
  padding: 0.34rem 0;
  border-bottom: 1px dashed #ccc;
  font-size: 0.86rem;
}

.receipt-lines td:last-child {
  font-weight: 700;
  text-align: right;
}

.receipt-qr-box {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  border: 1px solid #222;
  padding: 0.45rem;
  border-radius: 6px;
  background: #fff;
}

.receipt-hash-banner {
  margin-top: 0.85rem;
  padding: 0.45rem 0.65rem;
  background: #f8fafc;
  border: 1px solid #94a3b8;
  border-radius: 6px;
  font-family: "Courier New", Courier, monospace;
  font-size: 0.75rem;
  color: #111;
  display: flex;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 0.4rem;
}

.toast-container {
  position: fixed;
  bottom: 1.25rem;
  right: 1.25rem;
  z-index: 200;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.toast {
  background: var(--bg-surface);
  color: var(--text-main);
  border-left: 4px solid var(--accent);
  border-top: 1px solid var(--border-subtle);
  border-right: 1px solid var(--border-subtle);
  border-bottom: 1px solid var(--border-subtle);
  padding: 0.75rem 1.1rem;
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-card);
  font-size: 0.84rem;
  font-weight: 600;
}

@media print {
  body {
    background: #ffffff !important;
    color: #000000 !important;
  }

  .app-header,
  .nav-tabs,
  .main-container,
  .modal-header,
  .modal-footer,
  .no-print,
  .toast-container {
    display: none !important;
  }

  .modal-backdrop {
    position: static !important;
    background: transparent !important;
    display: block !important;
    padding: 0 !important;
  }

  .modal-box {
    border: none !important;
    box-shadow: none !important;
    max-width: 100% !important;
    max-height: none !important;
    padding: 0 !important;
    background: #ffffff !important;
  }

  .receipt-paper {
    border: 1.5px solid #000000 !important;
    box-shadow: none !important;
    margin: 0 !important;
  }
}

@media (max-width: 768px) {
  .app-header {
    padding: 0.75rem 1rem;
  }
  .main-container {
    padding: 1rem;
  }
  .kpi-value-kmf {
    font-size: 1.3rem;
  }
}
