/* Accès dépôt — feuille de style unique, mobile d'abord. */

:root {
  --bg: #0f1115;
  --surface: #171a21;
  --surface-2: #1e222b;
  --border: #2a3040;
  --text: #e8ecf4;
  --muted: #98a2b6;
  --accent: #4f8cff;
  --accent-dark: #2f6fe0;
  --success: #2ecc8f;
  --danger: #ff5d6c;
  --warn: #ffb020;
  --radius: 14px;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Inter, sans-serif;
  font-size: 16px;
  line-height: 1.5;
  -webkit-text-size-adjust: 100%;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

h1, h2, h3 { line-height: 1.25; margin: 0 0 0.4em; }
h1 { font-size: 1.5rem; }
h2 { font-size: 1.15rem; }
h3 { font-size: 1rem; }

p { margin: 0 0 0.8em; }
.muted { color: var(--muted); font-size: 0.9rem; }
.small { font-size: 0.82rem; }
.mono { font-family: ui-monospace, "Cascadia Mono", Consolas, monospace; }

/* ---------------------------------------------------------------- structure */
.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 0.7rem 1rem;
  background: rgba(15, 17, 21, 0.92);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  font-weight: 650;
  letter-spacing: 0.2px;
}
.brand-mark {
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  border-radius: 9px;
  background: linear-gradient(145deg, var(--accent), #7a5cff);
  color: #fff;
  font-size: 0.95rem;
}

.nav {
  display: flex;
  align-items: center;
  gap: 0.9rem;
  margin-left: auto;
  flex-wrap: wrap;
  justify-content: flex-end;
}
.nav a, .nav button {
  color: var(--muted);
  font-size: 0.88rem;
  background: none;
  border: 0;
  padding: 0;
  cursor: pointer;
  font-family: inherit;
}
.nav a:hover, .nav button:hover { color: var(--text); text-decoration: none; }
.nav a.active { color: var(--text); font-weight: 600; }
.nav form { display: inline; }

.wrap {
  max-width: 900px;
  margin: 0 auto;
  padding: 1.2rem 1rem 4rem;
}

.page-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1rem;
  flex-wrap: wrap;
}

/* --------------------------------------------------------------- composants */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  margin-bottom: 1rem;
}

.flash {
  margin: 0 0 1rem;
  padding: 0.7rem 0.9rem;
  border-radius: 10px;
  font-size: 0.92rem;
  border: 1px solid transparent;
}
.flash.ok { background: rgba(46, 204, 143, 0.12); border-color: rgba(46, 204, 143, 0.4); }
.flash.err { background: rgba(255, 93, 108, 0.12); border-color: rgba(255, 93, 108, 0.4); }

.badge {
  display: inline-block;
  padding: 0.12rem 0.5rem;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 600;
  border: 1px solid var(--border);
  color: var(--muted);
}
.badge.ok { color: var(--success); border-color: rgba(46, 204, 143, 0.45); }
.badge.err { color: var(--danger); border-color: rgba(255, 93, 108, 0.45); }
.badge.warn { color: var(--warn); border-color: rgba(255, 176, 32, 0.45); }

/* ------------------------------------------------------------------ boutons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  min-height: 48px;
  padding: 0.6rem 1.1rem;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  font-size: 0.98rem;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: transform 0.05s ease, background 0.15s ease, border-color 0.15s ease;
}
.btn:hover { background: #262c38; }
.btn:active { transform: scale(0.985); }
.btn:disabled { opacity: 0.4; cursor: not-allowed; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent-dark); }
.btn.danger { background: rgba(255, 93, 108, 0.14); border-color: rgba(255, 93, 108, 0.5); color: var(--danger); }
.btn.ghost { background: transparent; }
.btn.small { min-height: 36px; padding: 0.3rem 0.7rem; font-size: 0.85rem; border-radius: 9px; }
.btn.block { width: 100%; }

/* ------------------------------------------------------------------ formulaires */
label { display: block; font-size: 0.85rem; color: var(--muted); margin: 0.7rem 0 0.25rem; }
input[type="text"], input[type="email"], input[type="password"],
input[type="number"], input[type="date"], input[type="time"], select {
  width: 100%;
  padding: 0.65rem 0.75rem;
  min-height: 46px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: #12151b;
  color: var(--text);
  font-size: 1rem;
  font-family: inherit;
}
input:focus, select:focus {
  outline: 2px solid rgba(79, 140, 255, 0.5);
  outline-offset: 1px;
  border-color: var(--accent);
}

.row { display: flex; gap: 0.7rem; flex-wrap: wrap; }
.row > * { flex: 1 1 180px; }

/* Filtres du journal : une seule ligne, « Du » et « Au » restent groupés */
.filters {
  display: grid;
  grid-template-columns: 1fr 0.85fr 0.85fr 1.6fr;
  gap: 0.7rem;
  align-items: end;
}
.filters .filter-dates {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.5rem;
}
@media (max-width: 780px) {
  .filters { grid-template-columns: 1fr 1fr; }
  .filters .filter-dates { grid-column: 1 / -1; }
}

.checks { display: flex; flex-wrap: wrap; gap: 0.4rem 0.9rem; margin: 0.35rem 0 0.6rem; }
.check { display: inline-flex; align-items: center; gap: 0.35rem; font-size: 0.9rem; color: var(--text); }
.check input { width: 18px; height: 18px; accent-color: var(--accent); }

/* Ligne de sélection d'un appareil (carte entière cliquable) */
.check-line {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  padding: 0.7rem 0.8rem;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  cursor: pointer;
}
.check-line input { width: 20px; height: 20px; flex: 0 0 auto; }
.check-line input:checked ~ span strong { color: var(--accent); }

/* ------------------------------------------------------------------ appareils */
.device {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  margin-bottom: 0.9rem;
}
.device-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.8rem;
}
.device-head h2 { margin: 0; font-size: 1.1rem; }

.state {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.25rem 0.6rem;
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: 650;
  border: 1px solid var(--border);
  color: var(--muted);
  white-space: nowrap;
}
.state.open { color: var(--warn); border-color: rgba(255, 176, 32, 0.45); background: rgba(255, 176, 32, 0.1); }
.state.closed { color: var(--success); border-color: rgba(46, 204, 143, 0.4); background: rgba(46, 204, 143, 0.08); }
.state.on { color: #ffe08a; border-color: rgba(255, 214, 102, 0.45); background: rgba(255, 214, 102, 0.1); }
.state.off { color: var(--muted); border-color: var(--border); background: transparent; }
.state.unknown { color: var(--muted); border-color: var(--border); background: transparent; }

.actions { display: grid; grid-template-columns: 1fr; gap: 0.7rem; margin-top: 0.9rem; }
.actions form { margin: 0; }

/* Tuile unique : une icône qui reflète l'état, et qui bascule au clic. */
.tile {
  position: relative;
  width: 100%;
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 0.85rem 1rem;
  border-radius: 16px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  font: inherit;
  text-align: left;
  cursor: pointer;
  transition: transform 0.12s ease, border-color 0.18s ease, background 0.18s ease;
}
.tile:hover:not(:disabled) { transform: translateY(-1px); }
.tile:active:not(:disabled) { transform: scale(0.985); }
.tile:disabled { opacity: 0.38; cursor: not-allowed; }
.tile.busy { opacity: 0.75; }
.tile.busy .glyph::after { animation: none; }

.tile .glyph {
  position: relative;
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.05);
  color: #8a94a8;
  transition: color 0.2s ease, background 0.2s ease;
}
.tile .glyph svg { width: 28px; height: 28px; }

.tile-text { display: flex; flex-direction: column; gap: 0.15rem; min-width: 0; }
.tile-state { font-size: 1.02rem; font-weight: 700; }
.tile-hint { font-size: 0.8rem; color: var(--muted); font-weight: 500; }

/* Allumé (prises, éclairages) : jaune clair, comme une ampoule allumée */
.tile.lit {
  border-color: rgba(255, 214, 102, 0.55);
  background: linear-gradient(135deg, rgba(255, 214, 102, 0.16), rgba(255, 214, 102, 0.04));
}
.tile.lit .glyph {
  color: #fff4cc;
  background: radial-gradient(circle at 32% 28%, rgba(255, 255, 255, 0.35), rgba(255, 210, 90, 0.45));
}
.tile.lit .glyph::after {
  content: "";
  position: absolute;
  inset: -7px;
  border-radius: 50%;
  border: 2px solid rgba(255, 214, 102, 0.5);
  animation: halo 2.6s ease-out infinite;
}

/* Portes et volets : même principe, en ambre */
.tile.lit.cover {
  border-color: rgba(255, 176, 32, 0.55);
  background: linear-gradient(135deg, rgba(255, 176, 32, 0.16), rgba(255, 176, 32, 0.04));
}
.tile.lit.cover .glyph {
  color: #ffe2ad;
  background: radial-gradient(circle at 32% 28%, rgba(255, 255, 255, 0.3), rgba(255, 176, 32, 0.4));
}
.tile.lit.cover .glyph::after { border-color: rgba(255, 176, 32, 0.5); }

@keyframes halo {
  0% { transform: scale(0.8); opacity: 0.9; }
  70% { transform: scale(1.35); opacity: 0; }
  100% { transform: scale(1.35); opacity: 0; }
}

@media (prefers-reduced-motion: reduce) {
  .tile.lit .glyph::after { animation: none; }
}

.hint {
  margin: 0.6rem 0 0;
  font-size: 0.82rem;
  color: var(--warn);
}

.led { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); display: inline-block; }
.led.on { background: var(--success); box-shadow: 0 0 0 3px rgba(46, 204, 143, 0.18); }
.led.off { background: var(--danger); }
.led.unknown { background: var(--muted); }

/* --------------------------------------------------------------------- tables */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 0.88rem; }
th, td { text-align: left; padding: 0.55rem 0.5rem; border-bottom: 1px solid var(--border); vertical-align: top; }
th { color: var(--muted); font-weight: 600; font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.04em; }
tr:last-child td { border-bottom: 0; }
td.nowrap, th.nowrap { white-space: nowrap; }

/* ------------------------------------------------------------------- divers */
.login-shell { max-width: 380px; margin: 8vh auto 0; padding: 0 1rem; }
.login-shell .card { padding: 1.4rem; box-shadow: var(--shadow); }

.stack > * + * { margin-top: 0.8rem; }
.inline { display: inline-flex; gap: 0.5rem; align-items: center; flex-wrap: wrap; }
.spacer { flex: 1; }
.pill-row { display: flex; gap: 0.4rem; flex-wrap: wrap; }

.secret {
  display: block;
  padding: 0.7rem 0.8rem;
  background: #12151b;
  border: 1px dashed var(--border);
  border-radius: 10px;
  font-size: 1.05rem;
  letter-spacing: 0.5px;
  word-break: break-all;
}

.kv { display: grid; grid-template-columns: max-content 1fr; gap: 0.35rem 1rem; font-size: 0.9rem; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; }

.pagination { display: flex; gap: 0.5rem; align-items: center; justify-content: center; margin-top: 1rem; }

.mt-1 { margin-top: 1rem; }
.mt-2 { margin-top: 2rem; }
.center { text-align: center; }

@media (max-width: 560px) {
  .wrap { padding: 1rem 0.75rem 3rem; }
  .nav { gap: 0.6rem; font-size: 0.85rem; }
  .device-head { align-items: flex-start; flex-direction: column; gap: 0.35rem; }
  h1 { font-size: 1.3rem; }
}
