:root {
  --bg: #f1f5f9;
  --surface: #ffffff;
  --text: #0f172a;
  --muted: #64748b;
  --border: #e2e8f0;
  --primary: #0f172a;
  --primary-text: #ffffff;
  --accent: #2563eb;
}

:root[data-theme="dark"] {
  --bg: #0b1120;
  --surface: #131c2e;
  --text: #e2e8f0;
  --muted: #94a3b8;
  --border: #1e293b;
  --primary: #e2e8f0;
  --primary-text: #0b1120;
  --accent: #60a5fa;
}

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

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: 'Segoe UI', system-ui, -apple-system, Roboto, Arial, sans-serif;
  font-size: 14px;
}

h1 { font-size: 22px; margin: 8px 0 6px; }
h2 { font-size: 15px; margin: 0 0 6px; }
code { background: var(--bg); padding: 1px 5px; border-radius: 4px; font-size: 12px; }
.muted { color: var(--muted); line-height: 1.5; margin: 0 0 14px; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 20px;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  border-radius: 8px;
  padding: 9px 16px;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
}

.btn.primary { background: var(--primary); color: var(--primary-text); border-color: var(--primary); }
.btn.ghost:hover { background: var(--bg); }

label { display: block; font-weight: 600; font-size: 12px; color: var(--muted); }

input, textarea {
  display: block;
  width: 100%;
  margin-top: 5px;
  padding: 9px 11px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 14px;
}

input:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: 0; border-color: transparent; }

.stack { display: flex; flex-direction: column; gap: 12px; }
.stack .btn { align-self: flex-start; }

/* Connexion */
.login { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 16px; }
.login-card { width: 100%; max-width: 380px; display: flex; flex-direction: column; gap: 14px; }
.badge { align-self: flex-start; font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.6px; color: var(--accent); }
.error { color: #dc2626; margin: 0; }

/* Console */
.bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  padding: 16px 24px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.bar-title { font-weight: 700; font-size: 16px; }
.bar-sub { color: var(--muted); font-size: 12px; }
.bar-actions { display: flex; gap: 8px; }

.grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
  max-width: 1040px;
  margin: 0 auto;
  padding: 24px 16px 48px;
}

.span-2 { grid-column: span 2; }

.modules { display: flex; flex-direction: column; gap: 10px; }

.module {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 12px;
}

.module img { width: 46px; height: 46px; object-fit: contain; border-radius: 10px; background: var(--bg); padding: 4px; }
.module.not-deployed { opacity: 0.6; }
.module-info { flex: 1; min-width: 0; }
.module-name { font-weight: 700; font-size: 15px; }
.module-url { color: var(--muted); font-size: 12px; margin-top: 2px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.tags { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 4px; }
.tag { font-size: 11px; font-weight: 600; padding: 2px 8px; border-radius: 999px; }
.tag.green { background: #dcfce7; color: #166534; }
.tag.red { background: #fee2e2; color: #b91c1c; }
.tag.blue { background: #dbeafe; color: #1d4ed8; }
.tag.grey { background: var(--bg); color: var(--muted); }

/* Interrupteur */
.switch { position: relative; width: 46px; height: 26px; flex-shrink: 0; cursor: pointer; }
.switch input { opacity: 0; width: 0; height: 0; margin: 0; position: absolute; }
.slider { position: absolute; inset: 0; background: #cbd5e1; border-radius: 999px; transition: background 0.15s; }
.slider::before { content: ''; position: absolute; width: 20px; height: 20px; left: 3px; top: 3px; background: #fff; border-radius: 50%; transition: transform 0.15s; }
.switch input:checked + .slider { background: #16a34a; }
.switch input:checked + .slider::before { transform: translateX(20px); }
.switch input:focus-visible + .slider { outline: 2px solid var(--accent); outline-offset: 2px; }
.switch input:disabled + .slider { cursor: not-allowed; opacity: 0.5; }

.history-filter { display: flex; align-items: flex-end; gap: 12px; flex-wrap: wrap; margin-bottom: 14px; }
.history-filter label { width: 160px; }
.history-filter .muted { margin: 0 0 10px; }

.history { list-style: none; margin: 0; padding: 0; max-height: 320px; overflow-y: auto; }
.history li { display: flex; gap: 14px; padding: 8px 0; border-top: 1px solid var(--border); }
.history li:first-child { border-top: none; }
.when { color: var(--muted); white-space: nowrap; font-variant-numeric: tabular-nums; }

.toast {
  position: fixed;
  right: 16px;
  bottom: 16px;
  max-width: 420px;
  padding: 12px 16px;
  border-radius: 10px;
  background: #166534;
  color: #fff;
  font-weight: 600;
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.15);
}

.toast.error { background: #dc2626; }

@media (max-width: 760px) {
  .grid { grid-template-columns: 1fr; }
  .span-2 { grid-column: span 1; }
  .bar { padding: 14px 16px; }
  .history li { flex-direction: column; gap: 2px; }
}

.login-top { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.btn.small { padding: 5px 10px; font-size: 12px; }

.company-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.company-grid .span-2 { grid-column: span 2; }
.logo-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.logo-row img { height: 52px; max-width: 160px; object-fit: contain; border: 1px solid var(--border); border-radius: 8px; background: #fff; padding: 4px; }
.file-btn { cursor: pointer; color: var(--text); font-size: 12px; font-weight: 600; }
.company-foot { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
@media (max-width: 760px) { .company-grid { grid-template-columns: 1fr; } .company-grid .span-2 { grid-column: span 1; } }
