:root {
  color-scheme: light dark;

  --bg: #f5f5f5;
  --card: #ffffff;
  --text: #111827;
  --muted: #6b7280;

  --primary: #2563eb;
  --blue: var(--primary);
  --primary-text: #ffffff;

  --secondary: #e5e7eb;
  --secondary-text: #111827;

  --field: #ffffff;
  --field-text: #111827;
  --panel: #f9fafb;
  --weather-panel: #fcfcfd;
  --danger: #b91c1c;
  --ok-color: #15803d;
  --success: #16a34a;
  --success-text: #ffffff;
  --new: #f97316;
  --new-text: #ffffff;
  --warn-color: #b45309;

  --disabled-bg: #f3f4f6;
  --disabled-text: #9ca3af;

  --shadow: 0 4px 10px rgba(0,0,0,0.05);
  --border: #e5e7eb;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b0f14;
    --card: #111827;
    --text: #e5e7eb;
    --muted: #9ca3af;

    --primary: #3b82f6;
    --blue: var(--primary);
    --primary-text: #ffffff;

    --secondary: #1f2937;
    --secondary-text: #e5e7eb;

    --field: #0f172a;
    --field-text: #e5e7eb;
    --panel: #0f172a;
    --weather-panel: #111827;
    --danger: #f87171;
    --ok-color: #4ade80;
    --success: #22c55e;
    --success-text: #052e16;
    --new: #fb923c;
    --new-text: #111827;
    --warn-color: #fbbf24;

    --disabled-bg: #0f172a;
    --disabled-text: #64748b;

    --shadow: 0 6px 16px rgba(0,0,0,0.45);
    --border: #243041;
  }
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

body {
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  max-width: 700px;
  margin: 40px auto;
  padding: 0 16px;
  background: var(--bg);
  color: var(--text);
}

h1 {
  text-align: center;
  font-size: 1.7rem;
  line-height: 1.18;
  margin: 0 0 14px;
  font-weight: 750;
}

h2,
h3 {
  line-height: 1.25;
  margin-top: 0;
}

.card {
  background: var(--card);
  padding: 20px;
  border-radius: 12px;
  box-shadow: var(--shadow);
  margin-bottom: 18px;
  border: 1px solid var(--border);
}

/* HOME */

.topnav {
  display: flex;
  gap: 8px;
  justify-content: center;
  flex-wrap: wrap;
  margin-bottom: 18px;
}

.topnav a {
  font-size: .9rem;
  text-decoration: none;
  color: var(--primary);
  background: color-mix(in srgb, var(--primary) 12%, transparent);
  padding: 6px 10px;
  border-radius: 999px;
  font-weight: 600;
}

.card-title {
  text-align: center;
  font-weight: 700;
  margin: 2px 0 12px;
  font-size: 1.05rem;
}

h2,
h3,
.title {
  color: var(--text);
}

.section {
  margin-top: 10px;
}

.section h2 {
  font-size: 0.95rem;
  margin: 14px 0 8px;
  color: var(--muted);
  padding-bottom: 4px;
  border-bottom: 1px dashed var(--border);
}

.menu {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
}

@media (min-width: 520px) {
  .menu {
    grid-template-columns: 1fr 1fr;
  }
}

a.button {
  display: block;
  text-align: center;
  padding: 11px 14px;
  border-radius: 999px;
  background: var(--primary);
  color: var(--primary-text);
  font-size: 0.98rem;
  text-decoration: none;
  font-weight: 600;
}

a.button:visited {
  color: var(--primary-text);
}

a.button.secondary {
  background: var(--secondary);
  color: var(--secondary-text);
  font-weight: 500;
}

a.button.success {
  background: var(--success);
  color: var(--success-text);
}

a.button.success:visited {
  color: var(--success-text);
}

a.button.new {
  background: var(--new);
  color: var(--new-text);
}

a.button.new:visited {
  color: var(--new-text);
}

/* BADGE MAJ DISCRET SUR BOUTONS
   Ne modifie pas la taille du bouton
   Ne décale pas le texte
*/

a.button.has-update,
a.button.has-update-recent,
a.button.has-new {
  position: relative;
  text-align: center;
  padding: 11px 14px;
  overflow: hidden;
}

a.button.has-update::after,
a.button.has-update-recent::after,
a.button.has-new::after {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  right: 13px;

  display: inline-flex;
  align-items: center;
  justify-content: center;

  height: 15px;
  padding: 0 6px;

  border-radius: 999px;
  background: rgba(255,255,255,0.92);
  color: #047857;
  border: 1px solid rgba(255,255,255,0.75);

  font-size: 0.52rem;
  font-weight: 800;
  line-height: 1;
  letter-spacing: 0.03em;

  box-shadow: 0 1px 2px rgba(0,0,0,0.12);
  pointer-events: none;
}

a.button.has-update::after {
  content: "MàJ";
}

a.button.has-update-recent::after {
  content: "RÉCENT";
}

a.button.has-new::after {
  content: "New!";
  color: #c2410c;
}

@media (max-width: 420px) {
  a.button.has-update::after,
  a.button.has-update-recent::after,
  a.button.has-new::after {
    right: 10px;
    height: 13px;
    padding: 0 5px;
    font-size: 0.48rem;
  }
}

a.button.disabled {
  background: var(--disabled-bg);
  color: var(--disabled-text);
  pointer-events: none;
  font-style: italic;
  border: 1px dashed var(--border);
}

/* FORMULAIRES */

label {
  display: block;
  margin-bottom: 6px;
  font-weight: 600;
  font-size: 0.95rem;
}

input[type="number"],
input[type="date"],
input[type="time"],
input[type="text"],
input[type="email"],
input[type="password"],
select,
textarea {
  width: 100%;
  box-sizing: border-box;
  padding: 8px 10px;
  border-radius: 8px;
  border: 1px solid var(--border);
  font-size: 0.95rem;
  margin-bottom: 10px;
  background: var(--field);
  color: var(--field-text);
}

textarea {
  min-height: 110px;
  resize: vertical;
}

input[type="file"] {
  display: block;
  margin-top: 6px;
  margin-bottom: 10px;
  font-size: 0.9rem;
}

input[type="range"] {
  width: 100%;
  margin: 8px 0 10px;
  accent-color: var(--primary);
}

/* ROW */

.row {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.row > div {
  flex: 1;
  min-width: 140px;
}

/* BOUTONS */

.buttons {
  margin-top: 8px;
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: center;
}

button {
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 8px 16px;
  font-size: 0.95rem;
  cursor: pointer;
  background: var(--secondary);
  color: var(--secondary-text);
}

.buttons:not(.segmented) button:first-child,
button.primary,
button.active {
  background: var(--primary);
  color: var(--primary-text);
  border-color: var(--primary);
}

button.secondary {
  background: var(--secondary);
  color: var(--secondary-text);
  border-color: var(--border);
}

.segmented {
  gap: 6px;
}

.segmented button {
  flex: 1;
  min-width: 110px;
}

.segmented button:not(.active) {
  background: var(--secondary);
  color: var(--secondary-text);
  border-color: var(--border);
}

button:disabled {
  opacity: 0.6;
  cursor: default;
}

/* RESULTATS */

#result {
  margin-top: 16px;
  font-size: 0.9rem;
}

#result p {
  margin: 4px 0;
}

#tableContainer {
  margin-top: 12px;
  overflow-x: auto;
}

/* TABLEAUX */

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.8rem;
}

th,
td {
  border-bottom: 1px solid var(--border);
  padding: 4px;
  text-align: center;
}

th {
  background: var(--secondary);
  font-weight: 600;
}

/* HINT */

.hint {
  margin-top: 14px;
  font-size: 0.8rem;
  color: var(--muted);
  text-align: center;
  line-height: 1.45;
}

.hint a {
  display: inline-block;
  margin-top: 4px;
  text-decoration: none;
  color: var(--primary);
}

.hint a:visited {
  color: var(--primary);
}

.site-footer {
  margin: 18px auto 0;
  padding-top: 2px;
  max-width: 58ch;
}

.site-footer a {
  margin: 0 0 4px;
}

/* METEO */

.station-title {
  text-align: center;
  font-size: 1.05rem;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 14px;
}

.station-description {
  margin: 6px 0 12px;
  font-size: 0.92rem;
  color: var(--muted);
  line-height: 1.35;
  text-align: center;
}

.station-description:empty {
  display: none;
}

.metric-box[style*="display: none"],
.chart-block[style*="display: none"] {
  display: none !important;
}

.status {
  text-align: center;
  font-size: 0.9rem;
  color: var(--muted);
  margin-bottom: 14px;
  min-height: 1.2em;
}

.summary-grid {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 18px;
}

.weather-layout {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-top: 18px;
}

.metric-box {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px;
  background: var(--weather-panel);
}

.metric-title {
  font-size: 0.95rem;
  font-weight: 600;
  margin-bottom: 6px;
}

.metric-current {
  font-size: 1.35rem;
  font-weight: 700;
  margin-bottom: 6px;
  color: var(--text);
}

.metric-details {
  font-size: 0.9rem;
  color: var(--muted);
  line-height: 1.5;
}

.charts {
  display: flex;
  flex-direction: column;
  gap: 16px;
  margin-top: 18px;
}

.chart-block h2 {
  margin: 0 0 8px;
  font-size: 1rem;
  text-align: center;
}

.chart-block {
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--weather-panel);
  padding: 10px;
}

.chart-wrap {
  position: relative;
  height: 220px;
  width: 100%;
}

/* PAS de style global canvas */

/* GRILLES */

.grid {
  margin-top: 10px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px 12px;
  font-size: 0.95rem;
}

.item {
  background: var(--panel);
  border: 1px solid var(--border);
  padding: 8px 10px;
  border-radius: 8px;
  text-align: center;
}

.item .val {
  font-weight: 700;
  font-size: 1.1rem;
  display: block;
  margin-top: 2px;
}

/* COULEURS ETATS */

.error,
.status.error {
  color: var(--danger);
  font-weight: 600;
  text-align: center;
}

.ok {
  color: var(--ok-color);
  font-weight: 700;
}

.warn {
  color: var(--warn-color);
  font-weight: 700;
}

.nok {
  color: var(--danger);
  font-weight: 700;
}

.muted,
.file-info,
.small-note,
.small,
.sub,
.subtitle,
.footer {
  color: var(--muted);
  font-size: 0.85rem;
}

.sub,
.subtitle,
.footer {
  text-align: center;
  line-height: 1.45;
}

.sub,
.subtitle {
  margin: 0 auto 14px;
  max-width: 58ch;
}

.footer {
  margin: 0;
}

.footer a {
  color: var(--primary);
  text-decoration: none;
}

.footer a:visited {
  color: var(--primary);
}

/* OUTILS DIVERS */

.result-grid {
  margin-top: 10px;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 6px 10px;
  font-size: 0.98rem;
  align-items: center;
}

.result-grid .label {
  font-weight: 600;
}

.result-grid .value {
  font-variant-numeric: tabular-nums;
}

.strong-line {
  font-size: 1.12rem;
  font-weight: 800;
}

.pill,
.chip,
.badge,
.tag,
.offline-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--secondary);
  color: var(--secondary-text);
  font-size: 0.85rem;
  line-height: 1.2;
  padding: 5px 9px;
}

.offline-badge {
  display: flex;
  width: fit-content;
  max-width: 100%;
  margin: 0 auto 14px;
  color: var(--muted);
}

.chips,
.quick-row,
.toolbar,
.mini-actions,
.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
  align-items: center;
  margin-top: 10px;
}

.chip,
.mode-btn,
.mini-btn {
  cursor: pointer;
}

.modes {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
  margin-bottom: 12px;
}

@media (min-width: 520px) {
  .modes {
    grid-template-columns: 1fr 1fr;
  }
}

.mode-btn {
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--panel);
  padding: 10px 12px;
}

.mode-btn strong,
.mode-btn span {
  display: block;
}

.mode-btn span {
  color: var(--muted);
  font-size: 0.85rem;
  margin-top: 3px;
}

.mode-btn.active {
  border-color: var(--primary);
  background: color-mix(in srgb, var(--primary) 14%, var(--card));
}

.chip:hover,
.mode-btn:hover,
.mini-btn:hover {
  border-color: color-mix(in srgb, var(--primary) 45%, var(--border));
}

.mini-btn {
  border-radius: 999px;
  padding: 6px 10px;
  font-size: 0.85rem;
}

.section-title,
.resultTitle,
.result-title,
.panel-title {
  margin: 0 0 10px;
  font-weight: 700;
  color: var(--text);
}

.result,
.panel,
.best,
.details,
.daikin-info,
.vrv-box,
.ue-box,
.cold-box,
.toggle-area,
.band-preview,
.formula,
.conv,
.result-list > div {
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--panel);
  padding: 10px 12px;
}

.band-preview,
.formula,
.cold-box,
.toggle-area {
  margin-top: 10px;
  text-align: center;
}

.conv {
  margin-top: 10px;
}

.conv .title,
.title {
  font-weight: 700;
  margin-bottom: 8px;
}

.hidden {
  display: none !important;
}

.readonly,
input:read-only {
  background: var(--disabled-bg);
  color: var(--disabled-text);
}

.danger {
  background: var(--danger);
  color: #ffffff;
  border-color: var(--danger);
}

.primary {
  background: var(--primary);
  color: var(--primary-text);
  border-color: var(--primary);
}

.dot {
  width: 8px;
  height: 8px;
  border-radius: 999px;
  background: var(--ok-color);
}

.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 8px;
  margin-top: 12px;
}

.stat,
.kv,
.kvline {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
  background: var(--panel);
}

.stat strong,
.k,
.result-label {
  display: block;
  font-weight: 700;
}

.v,
.value,
.result-main {
  font-variant-numeric: tabular-nums;
  font-weight: 700;
}

.flight-results {
  grid-template-columns: 1fr;
  gap: 10px;
  margin-top: 14px;
}

.flight-results .panel {
  display: grid;
  gap: 8px;
}

.flight-results .panel-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 0;
}

.flight-results .kvline {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 12px;
}

.flight-results .kvline > div:last-child {
  text-align: right;
}

.result-sub,
.detail {
  color: var(--muted);
  font-size: 0.88rem;
}

hr.sep {
  border: none;
  border-top: 1px solid var(--border);
  margin: 10px 0;
}

/* MER */

.trend {
  font-size: 0.9rem;
  margin-top: 6px;
  font-weight: 600;
  text-align: center;
}

.trend.up {
  color: var(--ok-color);
}

.trend.down {
  color: var(--danger);
}

.trend.flat {
  color: var(--muted);
}

.best {
  margin-top: 10px;
  border: 1px dashed var(--border);
  font-size: 0.98rem;
}

/* METEO / AIR */

.current,
.daily,
.advice,
.chart-container,
.pollen-box {
  margin-top: 12px;
  text-align: center;
}

.aqi-box,
.phase-box {
  display: block;
  max-width: 360px;
  margin: 12px auto 0;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--panel);
  padding: 14px 16px;
  text-align: center;
}

.aqi-box {
  max-width: 120px;
  font-size: 1.4rem;
  font-weight: 800;
}

.moon-emoji {
  font-size: 2.2rem;
  line-height: 1.1;
  margin-bottom: 6px;
}

.phase-name {
  font-weight: 800;
  margin-bottom: 6px;
}

.daily-line {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  padding: 6px 0;
  border-bottom: 1px solid var(--border);
}

.daily-line:last-child {
  border-bottom: 0;
}

.icon {
  font-weight: 700;
}

.chart-container canvas {
  max-width: 100%;
  height: auto;
}

.chart-legend {
  color: var(--muted);
  font-size: 0.8rem;
  margin-top: 6px;
}

.pollen-box {
  display: none;
}

.pollen-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
  margin-top: 10px;
}

.pollen-item {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px;
  background: var(--panel);
}

.pollen-level {
  display: block;
  font-weight: 700;
}

/* LED / DAIKIN */

.led-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(44px, 1fr));
  gap: 8px;
  margin: 14px 0;
}

.led-row button,
.led {
  min-height: 44px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--secondary);
  color: var(--secondary-text);
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  user-select: none;
}

.led-row button {
  padding: 8px;
  font-size: 1.25rem;
}

.led {
  cursor: pointer;
  font-size: 0.82rem;
}

.led:not(.off),
.led.on,
.led.active {
  background: #f59e0b;
  color: #111827;
  border-color: #d97706;
}

.led-value,
.daikin-info {
  text-align: center;
}

/* GCODE */

.drop {
  border: 1px dashed var(--border);
  border-radius: 8px;
  padding: 16px;
  text-align: center;
  background: color-mix(in srgb, var(--secondary) 55%, transparent);
  cursor: pointer;
}

.controls {
  justify-content: stretch;
}

.ctrl {
  width: 100%;
}

.viewer {
  position: relative;
  width: 100%;
  min-height: 320px;
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  background: #0f172a;
}

.viewer canvas {
  display: block;
  width: 100%;
  height: 320px;
}

.overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #e5e7eb;
  background: rgba(15, 23, 42, 0.72);
  pointer-events: none;
  z-index: 1;
}

/* TEXTE */

.app,
.page {
  max-width: 700px;
  margin: 0 auto;
}

.page .grid {
  grid-template-columns: 1fr;
  align-items: start;
}

.result-list {
  display: grid;
  gap: 10px;
}

.result-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
}

pre {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  margin: 10px 0 0;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--field);
  color: var(--field-text);
  padding: 10px;
  font: 0.9rem/1.45 ui-monospace, SFMono-Regular, Consolas, "Liberation Mono", monospace;
}

.special-zone {
  margin-top: 10px;
}

.toolbar {
  justify-content: center;
}

/* PANNE */

.scorebar {
  height: 8px;
  overflow: hidden;
  border-radius: 999px;
  background: var(--secondary);
  margin-top: 6px;
}

.scorebar > div {
  height: 100%;
  border-radius: inherit;
  background: var(--primary);
}

.vrv-title,
.ue-title {
  font-weight: 700;
  margin-bottom: 8px;
}

.dir {
  color: var(--muted);
  font-size: 0.9rem;
  margin-bottom: 8px;
}

/* HEIC */

#preview {
  margin-top: 20px;
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 120px;
  text-align: center;
  font-size: 0.9rem;
  color: var(--muted);
}

#preview img {
  max-width: 100%;
  max-height: 260px;
  border-radius: 8px;
  box-shadow: 0 4px 10px rgba(0,0,0,0.08);
}

.back-home {
  margin-bottom: 10px;
  font-size: 0.85rem;
  text-align: center;
}

.back-home a {
  text-decoration: none;
  color: var(--primary);
}

/* FILETAGES */

.thread-counter {
  margin-top: 10px;
  color: var(--muted);
  font-size: 0.85rem;
  text-align: center;
}

.thread-tabs {
  margin-top: 12px;
}

.thread-standard-grid {
  grid-template-columns: repeat(auto-fit, minmax(92px, 1fr));
}

.thread-standard {
  width: 100%;
  cursor: pointer;
  color: var(--text);
  text-align: center;
}

.thread-standard span {
  display: block;
  color: var(--muted);
  font-size: 0.82rem;
  margin-top: 2px;
}

.thread-table-wrap {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: 8px;
}

.thread-table {
  min-width: 760px;
  font-size: 0.82rem;
}

.thread-table th {
  position: sticky;
  top: 0;
  z-index: 1;
}

.thread-table th,
.thread-table td {
  text-align: left;
  vertical-align: top;
  padding: 8px;
}

.thread-table tbody tr {
  cursor: pointer;
}

.thread-table tbody tr:hover,
.thread-table tbody tr:focus {
  outline: none;
  background: color-mix(in srgb, var(--primary) 9%, transparent);
}

.thread-family,
.thread-table .result-sub {
  display: block;
  margin-top: 3px;
}

.thread-family {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 500;
}

.thread-detail {
  text-align: left;
}

.thread-detail-box {
  display: grid;
  gap: 6px;
  margin-top: 10px;
}

.thread-measure-results {
  display: grid;
  gap: 8px;
  margin-top: 12px;
}

.thread-match {
  width: 100%;
  border-radius: 8px;
  background: var(--panel);
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
  text-align: left;
}

.thread-match span {
  display: block;
}

.thread-match span span {
  color: var(--muted);
  font-size: 0.82rem;
  margin-top: 2px;
}

.thread-score {
  color: var(--muted);
  font-size: 0.8rem;
  text-align: right;
  font-variant-numeric: tabular-nums;
}

@media (max-width: 480px) {
  .thread-match {
    grid-template-columns: 1fr;
  }

  .thread-score {
    text-align: left;
  }
}

/* MOBILE */

@media (max-width: 480px) {
  body {
    margin: 24px auto;
    padding: 0 12px;
  }

  h1 {
    font-size: 1.45rem;
  }

  .card {
    padding: 16px;
  }

  .grid {
    grid-template-columns: 1fr;
  }
}
