:root {
  --bg: #0c0d10;
  --bg-2: #12141a;
  --panel: #161922;
  --panel-2: #1c2030;
  --border: rgba(255, 255, 255, 0.08);
  --text: #f4f1ea;
  --muted: #9aa0b4;
  --accent: #e8a05c;
  --accent-strong: #f0b87a;
  --accent-dim: rgba(232, 160, 92, 0.14);
  --danger: #f07178;
  --radius: 18px;
  --font: "DM Sans", system-ui, sans-serif;
  --display: "Instrument Serif", Georgia, serif;
  --shadow: 0 24px 60px rgba(0, 0, 0, 0.45);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
}

body {
  padding: 1.25rem 1.5rem 2.5rem;
  background:
    radial-gradient(900px 500px at 10% -10%, rgba(232, 160, 92, 0.12), transparent 55%),
    radial-gradient(700px 400px at 100% 0%, rgba(90, 120, 255, 0.08), transparent 50%),
    var(--bg);
}

body.is-logged-in #view-login { display: none !important; }
body:not(.is-logged-in) #view-app { display: none !important; }

h1, h2 { font-weight: 600; margin: 0; letter-spacing: -0.02em; }
h1 { font-family: var(--display); font-weight: 400; font-size: 1.85rem; }
.muted { color: var(--muted); font-size: 0.85rem; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 0.78rem; color: var(--muted); }
.right { text-align: right; font-weight: 700; }
.empty { text-align: center; color: var(--muted); font-style: italic; padding: 2rem !important; }
.name { font-weight: 600; }
.eyebrow {
  margin: 0;
  font-size: 0.72rem;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--accent);
  font-weight: 600;
}

.logo-mark {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2.75rem;
  height: 2.75rem;
  border-radius: 14px;
  background: linear-gradient(145deg, var(--accent), #c4783a);
  color: #1a1208;
  font-family: var(--display);
  font-size: 1.5rem;
  font-weight: 400;
  flex-shrink: 0;
}
.logo-mark.sm { width: 2.25rem; height: 2.25rem; font-size: 1.2rem; border-radius: 12px; }

.header {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 1rem;
  align-items: center;
  border-bottom: 1px solid var(--border);
  padding-bottom: 1.1rem;
  margin-bottom: 1.4rem;
}
.header-brand { display: flex; gap: 0.85rem; align-items: center; }
.header-actions { display: flex; flex-wrap: wrap; gap: 0.55rem; align-items: end; }
.brand-sub { color: var(--muted); font-size: 0.88rem; margin-top: 0.2rem; }
.inline-label {
  margin: 0;
  min-width: 180px;
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  font-size: 0.8rem;
  color: var(--muted);
}

.login-wrap {
  min-height: calc(100vh - 3rem);
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
}
.login-bg {
  position: absolute;
  inset: 0;
  background:
    radial-gradient(600px 320px at 50% 20%, rgba(232, 160, 92, 0.18), transparent 60%),
    linear-gradient(180deg, transparent, rgba(0,0,0,0.35));
  pointer-events: none;
}
.login-card {
  position: relative;
  width: 100%;
  max-width: 420px;
  background: rgba(22, 25, 34, 0.92);
  border: 1px solid var(--border);
  border-radius: 28px;
  padding: 2rem 1.75rem 1.5rem;
  box-shadow: var(--shadow);
  backdrop-filter: blur(12px);
}
.login-brand {
  display: flex;
  gap: 0.9rem;
  align-items: center;
  margin-bottom: 1rem;
  text-align: left;
}
.login-lead {
  color: var(--muted);
  font-size: 0.92rem;
  line-height: 1.45;
  margin: 0 0 1.4rem;
  text-align: left;
}
.login-foot { margin: 1rem 0 0; font-size: 0.78rem; text-align: left; }

label {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  text-align: left;
  font-size: 0.82rem;
  color: var(--muted);
  margin-bottom: 0.85rem;
}

input, select, button { font: inherit; }

input, select {
  background: var(--bg-2);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 12px;
  padding: 0.8rem 0.95rem;
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
input:focus, select:focus {
  border-color: rgba(232, 160, 92, 0.55);
  box-shadow: 0 0 0 3px var(--accent-dim);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--panel-2);
  color: var(--text);
  padding: 0.7rem 1rem;
  cursor: pointer;
  font-weight: 600;
  font-size: 0.88rem;
  transition: transform 0.12s ease, border-color 0.15s ease, background 0.15s ease;
}
.btn:hover { border-color: rgba(232, 160, 92, 0.45); transform: translateY(-1px); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }

.btn-primary {
  background: linear-gradient(145deg, var(--accent-strong), var(--accent));
  border-color: transparent;
  color: #1a1208;
  width: 100%;
  padding: 0.95rem;
  font-weight: 700;
}
.btn-primary:hover { filter: brightness(1.05); }
.btn-inline { width: auto; }
.btn-danger {
  border-color: rgba(240, 113, 120, 0.35);
  color: var(--danger);
  background: rgba(240, 113, 120, 0.08);
}

.error {
  color: var(--danger);
  font-size: 0.88rem;
  margin: 0.35rem 0 0.85rem;
  text-align: left;
  line-height: 1.4;
}

.banner-error {
  background: rgba(240, 113, 120, 0.1);
  border: 1px solid rgba(240, 113, 120, 0.35);
  color: #ffb4b8;
  padding: 0.9rem 1rem;
  border-radius: var(--radius);
  margin-bottom: 1rem;
  font-size: 0.9rem;
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  align-items: flex-end;
  margin-bottom: 1.25rem;
}
.toolbar label { margin: 0; min-width: 140px; }
.toggle-pii {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.85rem;
  color: var(--muted, #9a9590);
  cursor: pointer;
  min-width: auto !important;
  align-self: center;
  margin-bottom: 0.35rem;
}
.toggle-pii input { accent-color: #e8a05c; }

.kpis {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 0.85rem;
  margin-bottom: 1rem;
}
@media (min-width: 900px) {
  .kpis { grid-template-columns: repeat(4, 1fr); }
}

.kpi {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.05rem 1.1rem;
}
.kpi-accent {
  background: linear-gradient(160deg, rgba(232, 160, 92, 0.16), var(--panel) 55%);
  border-color: rgba(232, 160, 92, 0.25);
}
.kpi .label {
  color: var(--muted);
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-weight: 600;
}
.kpi .value {
  font-family: var(--display);
  font-size: 2rem;
  font-weight: 400;
  margin-top: 0.3rem;
  letter-spacing: -0.02em;
}
.kpi .value.accent { color: var(--accent-strong); }

.status-row {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 0.55rem;
  margin-bottom: 1.25rem;
}
@media (min-width: 700px) {
  .status-row { grid-template-columns: repeat(4, 1fr); }
}
.status-chip {
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 0.6rem 0.8rem;
  display: flex;
  justify-content: space-between;
  font-size: 0.9rem;
}

.charts {
  display: grid;
  gap: 1rem;
  margin-bottom: 1.25rem;
}
@media (min-width: 1000px) {
  .charts { grid-template-columns: 1.2fr 1fr 0.8fr; }
}
.chart-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.05rem;
}
.chart-card h2 { font-size: 0.95rem; margin-bottom: 0.75rem; }
.chart-wrap { position: relative; height: 260px; }

.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.2rem;
  margin-bottom: 1.25rem;
}
.panel-table { padding: 0; overflow: hidden; }
.panel-head { margin-bottom: 0.25rem; }
.panel-head h2 { margin-bottom: 0.25rem; }

.proof-grid {
  display: grid;
  gap: 1rem;
  margin-top: 1rem;
  font-size: 0.9rem;
}
@media (min-width: 800px) {
  .proof-grid { grid-template-columns: 1fr 1fr; }
}
.proof-gen { margin-top: 0.75rem; }
.proof-hash {
  display: block;
  overflow-wrap: anywhere;
  word-break: break-all;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 0.85rem;
  font-size: 0.72rem;
  margin-top: 0.4rem;
  line-height: 1.45;
}

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 0.88rem; }
th {
  text-align: left;
  color: var(--muted);
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 0.7rem 0.9rem;
  background: var(--panel-2);
}
td {
  padding: 0.7rem 0.9rem;
  border-top: 1px solid var(--border);
  vertical-align: top;
}
.table-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.95rem 1.1rem;
  border-bottom: 1px solid var(--border);
}

.loading {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.65rem;
  color: var(--muted);
  padding: 0.85rem;
  margin-bottom: 0.75rem;
}
/* display:flex gagne sinon sur l’attribut HTML hidden → spinner bloqué */
.loading[hidden] {
  display: none !important;
}
.spinner {
  width: 1rem;
  height: 1rem;
  border: 2px solid rgba(232, 160, 92, 0.25);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.note {
  color: var(--muted);
  font-size: 0.75rem;
  margin-top: 0.5rem;
}
.boot-error { padding: 2rem; font-family: var(--font); color: var(--danger); }

@media print {
  body {
    background: #fff;
    color: #000;
    padding: 0;
  }
  .no-print { display: none !important; }
  .panel, .kpi, .chart-card {
    background: #fff;
    border: 1px solid #000;
    color: #000;
    box-shadow: none;
  }
  .proof-hash { background: #f3f3f3; color: #000; }
}
