/* =========================================================================
   Luna Hotel — tableau de bord actionnaires
   Thème clair par défaut, thème sombre via prefers-color-scheme.
   ========================================================================= */

:root {
  color-scheme: light;
  --bg: #f4f4f2;
  --surface: #fcfcfb;
  --surface-2: #f0efec;
  --border: #e2e1dc;
  --text: #0b0b0b;
  --text-secondary: #52514e;
  --muted: #6b6a66;
  --grid: #e7e6e1;
  --primary: #2a78d6;
  --primary-ink: #ffffff;
  --series-1: #2a78d6; /* terrasse / série principale */
  --series-2: #eb6834; /* hôtel / seconde série */
  --ok: #1f7a3a;
  --warn: #b25e00;
  --warn-bg: #fff3e0;
  --error: #c62828;
  --error-bg: #fdecea;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(0, 0, 0, .05);
}

@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --bg: #111110;
    --surface: #1a1a19;
    --surface-2: #232321;
    --border: #2e2e2b;
    --text: #f0efec;
    --text-secondary: #c3c2b7;
    --muted: #9b9a93;
    --grid: #2c2c2a;
    --primary: #3987e5;
    --series-1: #3987e5;
    --series-2: #d95926;
    --ok: #5cc27a;
    --warn: #f0a24a;
    --warn-bg: #3a2a12;
    --error: #ff7b72;
    --error-bg: #3b1715;
    --shadow: none;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

h1, h2 { margin: 0 0 .5rem; line-height: 1.25; }
h1 { font-size: 1.35rem; }
h2 { font-size: 1rem; font-weight: 600; }
code { font-size: .9em; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }

/* ---------- Boutons et champs ---------- */
.btn {
  font: inherit; font-weight: 500;
  border: 1px solid var(--border); border-radius: 8px;
  padding: .5rem .9rem; cursor: pointer;
  background: var(--surface); color: var(--text);
  white-space: nowrap;
}
.btn:hover { background: var(--surface-2); }
.btn:disabled { opacity: .6; cursor: progress; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: var(--primary-ink); }
.btn-primary:hover { background: var(--primary); filter: brightness(1.08); }
.btn-ghost { background: transparent; }
.btn-sm { padding: .3rem .6rem; font-size: .82rem; }

input, select {
  font: inherit; color: var(--text); background: var(--surface);
  border: 1px solid var(--border); border-radius: 8px; padding: .5rem .6rem;
  min-height: 2.4rem;
}
input:focus-visible, select:focus-visible, .btn:focus-visible, .tabs button:focus-visible, .segmented button:focus-visible {
  outline: 2px solid var(--primary); outline-offset: 2px;
}

.alert { padding: .6rem .8rem; border-radius: 8px; margin: .5rem 0; font-size: .9rem; }
.alert-error { background: var(--error-bg); color: var(--error); }
.alert-warn { background: var(--warn-bg); color: var(--warn); }

/* ---------- Connexion ---------- */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card {
  width: 100%; max-width: 380px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 14px;
  padding: 1.6rem; box-shadow: var(--shadow);
  display: flex; flex-direction: column; gap: .4rem;
}
.login-card label { font-size: .85rem; color: var(--text-secondary); margin-top: .4rem; }
.login-card .btn { margin-top: .9rem; padding: .7rem; }

.brand { font-weight: 700; font-size: 1.1rem; display: flex; align-items: center; gap: .4rem; }
.brand-mark { color: var(--primary); }

/* ---------- En-tête ---------- */
.topbar {
  background: var(--surface); border-bottom: 1px solid var(--border);
  padding: 12px 16px;
}
.topbar-row { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 10px; }
.topbar-actions { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.sync { font-size: .85rem; color: var(--muted); }
.sync.stale { color: var(--warn); font-weight: 600; }
.user-name { font-size: .85rem; }

.segmented { display: inline-flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.segmented button {
  font: inherit; font-size: .85rem; font-weight: 600; border: 0; padding: .4rem .8rem; cursor: pointer;
  background: transparent; color: var(--text-secondary);
}
.segmented button[aria-pressed="true"] { background: var(--primary); color: var(--primary-ink); }

.filters { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 10px; margin-top: 12px; }
.field { display: flex; flex-direction: column; gap: 2px; font-size: .8rem; color: var(--text-secondary); }
#rate-info { margin: 6px 0 0; }

/* ---------- Onglets ---------- */
.tabs {
  display: flex; gap: 4px; overflow-x: auto; padding: 8px 16px 0;
  border-bottom: 1px solid var(--border); background: var(--surface);
  position: sticky; top: 0; z-index: 5; scrollbar-width: thin;
}
.tabs button {
  font: inherit; font-size: .9rem; background: none; border: 0; cursor: pointer;
  padding: .55rem .8rem; color: var(--text-secondary); white-space: nowrap;
  border-bottom: 2px solid transparent;
}
.tabs button[aria-selected="true"] { color: var(--text); border-bottom-color: var(--primary); font-weight: 600; }

/* ---------- Contenu ---------- */
.content { padding: 16px; max-width: 1280px; margin: 0 auto; }
.page-alert { margin: 12px 16px 0; }
.loading { padding: 8px 16px; color: var(--muted); font-size: .9rem; }
.panel { display: flex; flex-direction: column; gap: 16px; }

.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 14px 16px; box-shadow: var(--shadow); min-width: 0;
}
.card-head { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 8px; margin-bottom: 8px; }
.card-head h2 { margin: 0; }
.actions { display: flex; gap: 6px; }
.grid-2 { display: grid; grid-template-columns: 1fr; gap: 16px; }

.chart-box { position: relative; height: 280px; }
.chart-tall { height: 360px; }

/* Indicateurs clés */
.kpis { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.kpi { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 14px; }
.kpi-label { font-size: .8rem; color: var(--text-secondary); }
.kpi-value { font-size: 1.3rem; font-weight: 700; margin-top: 2px; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.kpi-sub { font-size: .78rem; color: var(--muted); margin-top: 2px; }

/* Tableaux : défilement horizontal sur petit écran */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; border: 1px solid var(--border); border-radius: 8px; }
table { width: 100%; border-collapse: collapse; font-size: .88rem; }
th, td { padding: .5rem .65rem; text-align: left; border-bottom: 1px solid var(--border); white-space: nowrap; }
thead th { background: var(--surface-2); color: var(--text-secondary); font-weight: 600; position: sticky; top: 0; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: var(--surface-2); }
tfoot td { font-weight: 700; border-top: 2px solid var(--border); border-bottom: 0; }
.num { text-align: right; font-variant-numeric: tabular-nums; }
.neg { color: var(--error); font-weight: 600; }
.pos { color: var(--ok); }
.empty { color: var(--muted); padding: .6rem 0; margin: 0; }

.badge { display: inline-block; font-size: .75rem; font-weight: 600; padding: .1rem .5rem; border-radius: 999px; }
.badge-warn { background: var(--warn-bg); color: var(--warn); }

.alerts-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.alerts-list li { background: var(--warn-bg); color: var(--warn); border-radius: 8px; padding: .5rem .75rem; font-size: .9rem; }
.alerts-list li.none { background: transparent; color: var(--ok); padding-left: 0; }

.footer { text-align: center; padding: 16px 16px 24px; }

/* ---------- Tablette ---------- */
@media (min-width: 700px) {
  .kpis { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .grid-2 { grid-template-columns: 1fr 1fr; }
  .topbar, .tabs { padding-left: 24px; padding-right: 24px; }
  .content { padding: 20px 24px; }
}

/* ---------- Bureau ---------- */
@media (min-width: 1100px) {
  .kpis { grid-template-columns: repeat(6, minmax(0, 1fr)); }
}

/* ---------- Téléphone ---------- */
@media (max-width: 520px) {
  .filters .field { flex: 1 1 45%; }
  .filters .btn { flex: 1 1 45%; }
  .filters select, .filters input { width: 100%; }
  .kpi-value { font-size: 1.1rem; }
  .chart-box { height: 240px; }
}

/* Fenêtre « Changer mon mot de passe » */
.pw-dialog { border: 1px solid var(--border); border-radius: 12px; background: var(--surface); color: inherit; padding: 1.25rem; width: min(92vw, 380px); }
.pw-dialog::backdrop { background: rgb(0 0 0 / .45); }
.pw-form { display: flex; flex-direction: column; gap: .5rem; }
.pw-form h2 { margin: 0 0 .5rem; font-size: 1.1rem; }
.pw-form input { padding: .55rem .7rem; border: 1px solid var(--border); border-radius: 8px; background: var(--surface-2); color: inherit; }
.pw-actions { display: flex; justify-content: flex-end; gap: .5rem; margin-top: .5rem; }
