/* ==========================================================
   WM-SCHOOL Finance Monitoring Portal — Stylesheet
   Design: sobre, "command center" financier, identité
   personnalisable via variables CSS (--wm-primary / --wm-accent)
   injectées depuis index.php selon l'établissement.
   ========================================================== */

:root {
  --wm-primary: #0F2C4C;
  --wm-accent: #C9A24B;
  --wm-bg: #F4F6F9;
  --wm-surface: #FFFFFF;
  --wm-border: #E4E8EF;
  --wm-text: #16202C;
  --wm-text-mute: #667085;
  --wm-radius: 14px;
  --wm-shadow: 0 1px 2px rgba(16,24,40,.05), 0 4px 14px rgba(16,24,40,.04);

  --wm-green: #1B8A5A;
  --wm-red: #C2382C;
  --wm-amber: #B9770E;
}

* { box-sizing: border-box; }
html, body {
  margin: 0; padding: 0;
  font-family: -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--wm-bg);
  color: var(--wm-text);
}

.wm-shell { display: flex; min-height: 100vh; }

/* ---------------- Sidebar ---------------- */
.wm-sidebar {
  width: 250px;
  background: var(--wm-primary);
  color: #fff;
  display: flex;
  flex-direction: column;
  padding: 22px 16px;
  flex-shrink: 0;
}
.wm-brand { display: flex; align-items: center; gap: 10px; padding: 0 8px 24px; }
.wm-brand-mark {
  width: 36px; height: 36px; border-radius: 10px;
  background: var(--wm-accent); color: var(--wm-primary);
  display: flex; align-items: center; justify-content: center;
  font-weight: 700;
}
.wm-brand-logo { width: 36px; height: 36px; border-radius: 10px; object-fit: cover; background: #fff; flex-shrink: 0; }
.wm-brand-text { display: flex; flex-direction: column; line-height: 1.2; }
.wm-brand-name { font-weight: 700; font-size: 14px; letter-spacing: .04em; }
.wm-brand-sub { font-size: 11px; color: rgba(255,255,255,.6); }

.wm-nav { display: flex; flex-direction: column; gap: 2px; flex: 1; }
.wm-nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px; border-radius: 10px;
  color: rgba(255,255,255,.75); text-decoration: none;
  font-size: 13.5px; position: relative;
  transition: background .15s ease;
}
.wm-nav-item .wm-ico { font-size: 15px; width: 18px; text-align: center; }
.wm-nav-item:hover { background: rgba(255,255,255,.08); color: #fff; }
.wm-nav-item.active { background: rgba(255,255,255,.14); color: #fff; font-weight: 600; }
.wm-badge {
  margin-left: auto; background: var(--wm-red); color: #fff;
  font-size: 10.5px; padding: 1px 7px; border-radius: 999px;
}

.wm-ai-launcher {
  margin-top: 16px; border: 1px solid rgba(255,255,255,.18);
  background: rgba(255,255,255,.06); color: #fff;
  padding: 11px 12px; border-radius: 10px; cursor: pointer;
  font-size: 13px; display: flex; align-items: center; gap: 8px;
}
.wm-ai-launcher:hover { background: rgba(255,255,255,.14); }
.wm-ai-launcher-disabled { opacity: .45; cursor: not-allowed; }
.wm-ai-launcher-disabled:hover { background: rgba(255,255,255,.06); }

/* ---------------- Main ---------------- */
.wm-main { flex: 1; padding: 26px 32px 40px; max-width: 1400px; }

.wm-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 22px;
}
.wm-header h1 { margin: 0 0 4px; font-size: 22px; }
.wm-subtitle { margin: 0; color: var(--wm-text-mute); font-size: 13px; }
.wm-header-actions { display: flex; align-items: center; gap: 12px; }
.wm-icon-btn {
  width: 38px; height: 38px; border-radius: 10px; border: 1px solid var(--wm-border);
  background: var(--wm-surface); cursor: pointer; position: relative; font-size: 15px;
}
.wm-dot { position: absolute; top: 7px; right: 8px; width: 7px; height: 7px; border-radius: 50%; background: var(--wm-red); }
.wm-user { display: flex; align-items: center; gap: 10px; }
.wm-avatar {
  width: 36px; height: 36px; border-radius: 50%; background: var(--wm-primary); color: #fff;
  display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 13px;
}
.wm-user-name { font-size: 13px; font-weight: 600; }
.wm-user-role { font-size: 11px; color: var(--wm-text-mute); }

/* ---------------- Grids ---------------- */
.wm-grid { display: grid; gap: 18px; margin-bottom: 18px; }
.wm-grid-hero { grid-template-columns: 1.1fr 2fr; }
.wm-grid-charts { grid-template-columns: 1.5fr 1fr; }
.wm-grid-two { grid-template-columns: 1fr 1fr; }
@media (max-width: 1100px) {
  .wm-grid-hero, .wm-grid-charts, .wm-grid-two { grid-template-columns: 1fr; }
}

/* ---------------- Hero card ---------------- */
.wm-hero-card {
  background: linear-gradient(135deg, var(--wm-primary), #1a3f66);
  color: #fff; border-radius: var(--wm-radius); padding: 22px;
  display: flex; flex-direction: column; justify-content: space-between;
  box-shadow: var(--wm-shadow);
}
.wm-hero-top { display: flex; justify-content: space-between; align-items: center; margin-bottom: 14px; }
.wm-hero-tag {
  font-size: 11px; background: rgba(255,255,255,.15); padding: 4px 10px; border-radius: 999px;
}
.wm-hero-card h2 { margin: 0 0 4px; font-size: 19px; }
.wm-hero-slogan { margin: 0 0 20px; font-size: 12.5px; color: rgba(255,255,255,.7); font-style: italic; }
.wm-hero-bottom { display: flex; justify-content: space-between; align-items: flex-end; }
.wm-hero-label { display: block; font-size: 11px; color: rgba(255,255,255,.65); margin-bottom: 4px; }
.wm-hero-amount { font-size: 22px; font-weight: 700; }
.wm-hero-meta { display: flex; flex-direction: column; align-items: flex-end; gap: 4px; font-size: 11px; color: rgba(255,255,255,.7); }

/* ---------------- KPI tiles ---------------- */
.wm-kpi-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 14px; }
.wm-kpi-tile {
  background: var(--wm-surface); border-radius: var(--wm-radius); padding: 16px 18px;
  box-shadow: var(--wm-shadow); display: flex; flex-direction: column; gap: 6px;
}
.wm-kpi-label { font-size: 12px; color: var(--wm-text-mute); }
.wm-kpi-value { font-size: 18px; font-weight: 700; }
.wm-kpi-trend { font-size: 11.5px; font-weight: 600; width: fit-content; }
.wm-kpi-trend.up { color: var(--wm-green); }
.wm-kpi-trend.down { color: var(--wm-red); }

.wm-kpi-gauge { align-items: center; justify-content: center; }
.wm-gauge { position: relative; width: 110px; }
.wm-gauge svg { width: 100%; }
.wm-gauge-bg { fill: none; stroke: var(--wm-border); stroke-width: 10; }
.wm-gauge-fill { fill: none; stroke-width: 10; stroke-linecap: round; transition: stroke-dashoffset .6s ease; }
.wm-gauge-excellent { stroke: var(--wm-green); }
.wm-gauge-bon { stroke: #3E7CB1; }
.wm-gauge-faible { stroke: var(--wm-amber); }
.wm-gauge-critique { stroke: var(--wm-red); }
.wm-gauge-value {
  position: absolute; left: 50%; bottom: -2px; transform: translateX(-50%);
  font-weight: 700; font-size: 15px;
}

/* ---------------- Cards ---------------- */
.wm-card {
  background: var(--wm-surface); border-radius: var(--wm-radius);
  padding: 18px 20px; box-shadow: var(--wm-shadow);
}
.wm-card-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.wm-card-head h3 { margin: 0; font-size: 14.5px; }
.wm-select {
  border: 1px solid var(--wm-border); border-radius: 8px; padding: 5px 10px; font-size: 12px;
  background: var(--wm-surface); color: var(--wm-text);
}
.wm-link { font-size: 12px; color: var(--wm-primary); text-decoration: none; font-weight: 600; }

/* Donut */
.wm-donut-wrap { display: flex; align-items: center; gap: 22px; }
.wm-legend { list-style: none; margin: 0; padding: 0; flex: 1; }
.wm-legend li { display: flex; align-items: center; gap: 8px; font-size: 12.5px; padding: 5px 0; }
.wm-legend-label { flex: 1; color: var(--wm-text-mute); }
.wm-legend-value { font-weight: 700; }
.wm-legend-dot { width: 9px; height: 9px; border-radius: 3px; display: inline-block; }
.wm-c0 { background: var(--wm-primary); }
.wm-c1 { background: var(--wm-accent); }
.wm-c2 { background: #3E7CB1; }
.wm-c3 { background: #8FB3D9; }
.wm-c4 { background: #C7D3E0; }

/* Alerts */
.wm-alert-list, .wm-activity-list { list-style: none; margin: 0; padding: 0; }
.wm-alert, .wm-activity-list li {
  display: flex; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--wm-border);
}
.wm-alert:last-child, .wm-activity-list li:last-child { border-bottom: none; }
.wm-alert p, .wm-activity-list p { margin: 0 0 2px; font-size: 13px; }
.wm-alert-time, .wm-activity-time { font-size: 11px; color: var(--wm-text-mute); }
.wm-alert-dot, .wm-activity-dot { width: 8px; height: 8px; border-radius: 50%; margin-top: 5px; flex-shrink: 0; }
.wm-alert-critique .wm-alert-dot { background: var(--wm-red); }
.wm-alert-attention .wm-alert-dot { background: var(--wm-amber); }
.wm-alert-info .wm-alert-dot { background: #3E7CB1; }
.wm-activity-dot { background: var(--wm-accent); }

/* Table */
.wm-table { width: 100%; border-collapse: collapse; margin-top: 4px; }
.wm-table th {
  text-align: left; font-size: 11.5px; text-transform: uppercase; letter-spacing: .03em;
  color: var(--wm-text-mute); padding: 10px 12px; border-bottom: 1px solid var(--wm-border);
}
.wm-table td { padding: 12px; font-size: 13px; border-bottom: 1px solid var(--wm-border); }
.wm-table tr:last-child td { border-bottom: none; }
.wm-status { font-size: 11px; font-weight: 700; padding: 4px 10px; border-radius: 999px; }
.wm-status-paid { background: #E3F5EC; color: var(--wm-green); }
.wm-status-pending { background: #FDF3DF; color: var(--wm-amber); }
.wm-status-late { background: #FBE7E5; color: var(--wm-red); }

.wm-footer { text-align: center; color: var(--wm-text-mute); font-size: 11.5px; margin-top: 26px; }

/* ---------------- AI Assistant panel ---------------- */
.wm-ai-panel {
  position: fixed; top: 0; right: -400px; width: 380px; height: 100vh;
  background: var(--wm-surface); box-shadow: -8px 0 30px rgba(0,0,0,.12);
  display: flex; flex-direction: column; transition: right .25s ease; z-index: 40;
}
.wm-ai-panel.open { right: 0; }
.wm-ai-head { display: flex; justify-content: space-between; align-items: center; padding: 18px 20px; border-bottom: 1px solid var(--wm-border); }
.wm-ai-head h3 { margin: 0; font-size: 15px; }
.wm-ai-head button { border: none; background: none; font-size: 20px; cursor: pointer; color: var(--wm-text-mute); }
.wm-ai-messages { flex: 1; padding: 16px 20px; overflow-y: auto; display: flex; flex-direction: column; gap: 12px; }
.wm-ai-msg { max-width: 88%; padding: 10px 13px; border-radius: 12px; font-size: 13px; line-height: 1.45; }
.wm-ai-msg.bot { background: var(--wm-bg); align-self: flex-start; }
.wm-ai-msg.user { background: var(--wm-primary); color: #fff; align-self: flex-end; }
.wm-ai-suggestions { display: flex; flex-direction: column; gap: 6px; padding: 0 20px 12px; }
.wm-suggestion {
  text-align: left; border: 1px solid var(--wm-border); background: var(--wm-surface);
  border-radius: 8px; padding: 8px 10px; font-size: 12px; cursor: pointer; color: var(--wm-text);
}
.wm-suggestion:hover { background: var(--wm-bg); }
.wm-ai-input { display: flex; gap: 8px; padding: 14px 20px; border-top: 1px solid var(--wm-border); }
.wm-ai-input input {
  flex: 1; border: 1px solid var(--wm-border); border-radius: 10px; padding: 10px 12px; font-size: 13px;
}
.wm-ai-input button {
  width: 40px; border: none; border-radius: 10px; background: var(--wm-primary); color: #fff; cursor: pointer;
}

.wm-overlay {
  position: fixed; inset: 0; background: rgba(15,44,76,.25); opacity: 0; pointer-events: none;
  transition: opacity .2s ease; z-index: 30;
}
.wm-overlay.show { opacity: 1; pointer-events: auto; }

/* ---------------- Dark mode ---------------- */
body.wm-dark {
  --wm-bg: #0E1420;
  --wm-surface: #161D2B;
  --wm-border: #262F42;
  --wm-text: #EAEEF5;
  --wm-text-mute: #8A93A6;
}

/* ---------------- Header layout helpers ---------------- */
.wm-header-left { display: flex; align-items: center; gap: 12px; }
.wm-hamburger {
  display: none;
  width: 38px; height: 38px; border-radius: 10px; border: 1px solid var(--wm-border);
  background: var(--wm-surface); cursor: pointer; font-size: 17px; flex-shrink: 0;
}
.wm-sidebar-close { display: none; margin-left: auto; background: none; border: none; color: #fff; font-size: 22px; cursor: pointer; }
.wm-logout-link {
  display: flex; align-items: center; gap: 8px; margin-top: 10px; padding: 10px 12px;
  color: rgba(255,255,255,.65); text-decoration: none; font-size: 13px; border-radius: 10px;
}
.wm-logout-link:hover { background: rgba(255,255,255,.08); color: #fff; }

/* ---------------- Table horizontal scroll wrapper ---------------- */
.wm-table-scroll { width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch; }

/* ---------------- Placeholder view ---------------- */
.wm-placeholder { text-align: center; padding: 56px 24px; }
.wm-placeholder-icon { font-size: 30px; margin-bottom: 10px; }
.wm-placeholder h3 { margin: 0 0 8px; font-size: 16px; }
.wm-placeholder p { margin: 0 auto; max-width: 440px; color: var(--wm-text-mute); font-size: 13px; line-height: 1.6; }

/* ---------------- Login / identification page ---------------- */
.wm-login-body {
  display: flex; align-items: center; justify-content: center;
  min-height: 100vh; background: linear-gradient(160deg, #0F2C4C, #1a3f66 60%, #0F2C4C);
  padding: 20px;
}
.wm-login-wrap { width: 100%; max-width: 420px; }
.wm-login-card {
  background: var(--wm-surface); border-radius: 18px; padding: 34px 30px;
  box-shadow: 0 20px 60px rgba(0,0,0,.25);
}
.wm-login-brand { text-align: center; margin-bottom: 18px; }
.wm-brand-mark-lg {
  width: 52px; height: 52px; border-radius: 14px; background: var(--wm-accent, #C9A24B);
  color: var(--wm-primary, #0F2C4C); display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 22px; margin: 0 auto 12px;
}
.wm-login-brand h1 { margin: 0; font-size: 19px; letter-spacing: .03em; }
.wm-login-brand p { margin: 2px 0 0; font-size: 12.5px; color: var(--wm-text-mute); }
.wm-login-intro { font-size: 13px; color: var(--wm-text-mute); text-align: center; margin: 0 0 22px; line-height: 1.6; }
.wm-login-form { display: flex; flex-direction: column; gap: 8px; }
.wm-login-form label { font-size: 12.5px; font-weight: 600; }
.wm-login-form input {
  border: 1px solid var(--wm-border); border-radius: 10px; padding: 12px 14px; font-size: 14px;
  background: var(--wm-bg); color: var(--wm-text);
}
.wm-login-form button {
  margin-top: 10px; border: none; border-radius: 10px; padding: 12px; font-size: 14px; font-weight: 600;
  background: var(--wm-primary, #0F2C4C); color: #fff; cursor: pointer;
}
.wm-login-form button:hover { opacity: .92; }
.wm-login-error {
  background: #FBE7E5; color: #8A2A22; border-radius: 10px; padding: 10px 12px;
  font-size: 12.5px; margin-bottom: 16px;
}
.wm-login-hint { text-align: center; font-size: 11.5px; color: var(--wm-text-mute); margin: 18px 0 0; }
.wm-login-hint code { background: var(--wm-bg); padding: 2px 6px; border-radius: 6px; }

/* ==========================================================
   RESPONSIVE / MEDIA QUERIES
   Breakpoints : 1100px (grilles), 900px (sidebar off-canvas),
   560px (compaction mobile)
   ========================================================== */

/* Tablette large : sidebar reste visible mais rétrécie */
@media (max-width: 1100px) {
  .wm-sidebar { width: 210px; }
  .wm-main { padding: 22px 20px 36px; }
}

/* Tablette / mobile : sidebar devient un panneau off-canvas */
@media (max-width: 900px) {
  .wm-sidebar {
    position: fixed; top: 0; left: 0; height: 100vh; z-index: 60;
    width: 260px; max-width: 82vw;
    transform: translateX(-100%);
    transition: transform .25s ease;
    box-shadow: 8px 0 30px rgba(0,0,0,.18);
  }
  .wm-sidebar.open { transform: translateX(0); }
  .wm-sidebar-close { display: block; }
  .wm-hamburger { display: inline-flex; align-items: center; justify-content: center; }
  .wm-overlay { position: fixed; }
  body.wm-sidebar-open .wm-overlay { opacity: 1; pointer-events: auto; z-index: 55; }

  .wm-main { padding: 18px 16px 32px; }
  .wm-header { align-items: flex-start; }
  .wm-header h1 { font-size: 19px; }
  .wm-user-info { display: none; }
}

/* Mobile */
@media (max-width: 640px) {
  .wm-header { flex-direction: row; flex-wrap: wrap; gap: 12px; }
  .wm-header-actions { gap: 8px; }
  .wm-kpi-grid { grid-template-columns: 1fr; }
  .wm-hero-card { padding: 18px; }
  .wm-hero-amount { font-size: 19px; }
  .wm-card { padding: 15px 14px; }
  .wm-card-head { flex-wrap: wrap; gap: 8px; }
  .wm-donut-wrap { flex-direction: column; align-items: flex-start; }

  /* Table -> cartes empilées sur très petit écran */
  .wm-table thead { display: none; }
  .wm-table, .wm-table tbody, .wm-table tr, .wm-table td { display: block; width: 100%; }
  .wm-table tr {
    border: 1px solid var(--wm-border); border-radius: 10px; margin-bottom: 10px; padding: 6px 12px;
  }
  .wm-table td {
    border-bottom: none; display: flex; justify-content: space-between; align-items: center;
    padding: 8px 0; font-size: 12.5px;
  }
  .wm-table td::before {
    content: attr(data-label); color: var(--wm-text-mute); font-weight: 600; margin-right: 10px;
  }

  .wm-ai-panel { width: 100%; right: -100%; }
  .wm-ai-panel.open { right: 0; }

  .wm-login-card { padding: 26px 20px; }
}

@media (max-width: 400px) {
  .wm-main { padding: 14px 12px 28px; }
  .wm-hero-bottom { flex-direction: column; align-items: flex-start; gap: 10px; }
  .wm-hero-meta { align-items: flex-start; }
}
