/* Expert Pare-Brise Claye — Admin cockpit, mobile-first
   Charte ECW slate + emerald. Préserve IDs/classes JS. */

:root {
  --c-bg: #0b1220;
  --c-bg-2: #0f172a;
  --c-panel: #1a2332;
  --c-panel-2: #1e293b;
  --c-surface: #263244;
  --c-border: #334155;
  --c-text: #e2e8f0;
  --c-muted: #94a3b8;
  --c-muted-2: #64748b;
  --c-primary: #047857;
  --c-primary-bright: #10b981;
  --c-accent: #34d399;
  --c-glow: rgba(52, 211, 153, 0.16);
  --c-danger: #ef4444;
  --c-warning: #f59e0b;
  --c-info: #38bdf8;
  --shadow-sm: 0 1px 2px rgba(0,0,0,.2);
  --shadow: 0 8px 24px rgba(0,0,0,.28);
  --shadow-lg: 0 18px 50px rgba(0,0,0,.36);
  --radius-sm: 10px;
  --radius: 14px;
  --radius-lg: 18px;
  --safe-top: env(safe-area-inset-top, 0);
  --safe-bot: env(safe-area-inset-bottom, 0);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, ui-sans-serif, system-ui, sans-serif;
  color-scheme: dark;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; height: 100%; }
body {
  background: radial-gradient(ellipse at top, #15243a 0%, var(--c-bg) 60%);
  color: var(--c-text);
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  padding-bottom: calc(20px + var(--safe-bot));
}

button, input, select, textarea { font: inherit; color: inherit; }
button {
  border: 0; border-radius: var(--radius);
  padding: 12px 18px; min-height: 44px;
  background: linear-gradient(135deg, var(--c-primary), var(--c-primary-bright));
  color: #fff; font-weight: 700; cursor: pointer;
  transition: filter .15s, transform .1s;
}
button:hover { filter: brightness(1.08); }
button:active { transform: scale(.97); }
button.ghost {
  background: transparent;
  border: 1px solid var(--c-border);
  color: var(--c-text);
}
button.danger {
  color: #fecaca;
  border-color: rgba(239,68,68,.4);
  background: rgba(239,68,68,.08);
}
button[hidden] { display: none !important; }

input, select, textarea {
  width: 100%;
  background: var(--c-bg-2);
  border: 1px solid var(--c-border);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  min-height: 44px;
  font-size: 16px; /* prevent iOS zoom on focus */
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}
textarea { min-height: 80px; resize: vertical; }
input:focus, select:focus, textarea:focus {
  border-color: var(--c-accent);
  box-shadow: 0 0 0 3px var(--c-glow);
}
input[type="checkbox"], input[type="radio"] {
  width: auto; min-height: 0; transform: scale(1.3); margin-right: 8px;
}

/* Topbar — mobile-first, actions principales visibles, overflow ⋮ pour le reste */
.topbar {
  position: sticky; top: 0; z-index: 30;
  display: grid;
  grid-template-columns: 1fr auto;
  grid-template-rows: auto auto;
  align-items: center; gap: 8px 10px;
  padding: calc(12px + var(--safe-top)) 14px 12px;
  background: rgba(11,18,32,.92);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--c-border);
}
.topbar-title { grid-column: 1; min-width: 0; }
.user-badge {
  grid-column: 2; grid-row: 1;
  display: inline-block;
  border: 1px solid var(--c-border);
  border-radius: 999px; padding: 6px 10px;
  color: var(--c-muted); font-size: 12px;
  text-align: center; white-space: nowrap;
  max-width: 140px; overflow: hidden; text-overflow: ellipsis;
}
.primary-cta {
  grid-column: 1; grid-row: 2;
  font-size: 15px; padding: 12px 14px;
  min-height: 44px;
  background: linear-gradient(135deg, var(--c-primary), var(--c-primary-bright));
  box-shadow: 0 4px 14px var(--c-glow);
}
.overflow-wrap {
  grid-column: 2; grid-row: 2;
  position: relative;
}
.overflow-btn {
  width: 44px; height: 44px; padding: 0; min-height: 0;
  font-size: 24px; line-height: 1; font-weight: 700;
  background: transparent;
  border: 1px solid var(--c-border);
  color: var(--c-text);
  border-radius: var(--radius-sm);
}
.overflow-menu {
  display: none;
  position: absolute; top: calc(100% + 6px); right: 0;
  min-width: 200px;
  background: var(--c-panel);
  border: 1px solid var(--c-border);
  border-radius: var(--radius);
  box-shadow: 0 12px 32px rgba(0,0,0,.5);
  padding: 8px;
  z-index: 50;
  flex-direction: column; gap: 4px;
}
.overflow-menu.open { display: flex; }
.overflow-menu button {
  width: 100%; justify-content: flex-start;
  text-align: left;
  padding: 12px 14px;
  min-height: 44px;
  font-weight: 500;
  border-radius: var(--radius-sm);
}
.overflow-menu button[hidden] { display: none !important; }

.eyebrow {
  color: var(--c-accent); font-weight: 800;
  text-transform: uppercase; font-size: 11px;
  letter-spacing: .12em; margin: 0 0 2px;
}
h1 { font-size: 17px; font-weight: 700; margin: 0; letter-spacing: -0.01em; }
h2 { font-size: 17px; font-weight: 700; margin: 0; letter-spacing: -0.01em; }
h3 { font-size: 14px; font-weight: 600; margin: 0; }
p { margin: 0; color: var(--c-muted); font-size: 14px; }

/* Main layout */
main { padding: 16px; display: grid; gap: 16px; }

/* KPI */
.kpis {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 10px;
}
.kpi {
  background: linear-gradient(180deg, rgba(255,255,255,.04), rgba(255,255,255,.01));
  border: 1px solid var(--c-border);
  border-radius: var(--radius);
  padding: 14px;
}
.kpi strong { display: block; font-size: 24px; font-weight: 700; margin-bottom: 2px; color: var(--c-text); }
.kpi span { color: var(--c-muted); font-size: 12px; }

/* Panels */
.panel {
  background: var(--c-panel);
  border: 1px solid var(--c-border);
  border-radius: var(--radius-lg);
  padding: 16px;
  box-shadow: var(--shadow);
}
.panel-head {
  display: flex; flex-direction: column; gap: 12px;
  margin-bottom: 14px;
}
.panel-head h2 { color: var(--c-accent); }
.panel-head p { font-size: 13px; }
.panel-head > div { min-width: 0; }
#searchInput { max-width: 100%; }

/* Priority list */
.priority-list { display: grid; gap: 10px; }
.priority {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
  background: var(--c-bg-2);
  border: 1px solid var(--c-border);
  padding: 12px 14px;
  border-radius: var(--radius);
}

/* Badges */
.badge {
  display: inline-block;
  border-radius: 999px; padding: 4px 10px;
  font-size: 11px; font-weight: 700;
  background: rgba(56,189,248,.16); color: #bae6fd;
  white-space: nowrap;
  letter-spacing: .02em;
}
.badge.red { background: rgba(239,68,68,.18); color: #fca5a5; }
.badge.orange { background: rgba(245,158,11,.18); color: #fcd34d; }
.badge.green { background: rgba(52,211,153,.18); color: #6ee7b7; }

/* Two-column layout */
.grid-two { display: grid; gap: 16px; }

/* Kanban — swipe horizontal sur mobile */
.kanban {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: 85%;
  gap: 10px;
  overflow-x: auto;
  scroll-snap-type: x mandatory;
  padding: 4px 4px 12px;
  margin: 0 -4px;
}
.kanban::-webkit-scrollbar { height: 6px; }
.kanban::-webkit-scrollbar-thumb { background: var(--c-border); border-radius: 3px; }
.column {
  scroll-snap-align: start;
  min-height: 180px;
  background: var(--c-bg-2);
  border: 1px solid var(--c-border);
  border-radius: var(--radius);
  padding: 12px;
}
.column h3 {
  margin: 0 0 10px; font-size: 13px;
  color: var(--c-muted); display: flex;
  justify-content: space-between; gap: 8px;
  text-transform: uppercase; letter-spacing: .08em;
}

/* Cards */
.card {
  background: var(--c-panel-2);
  border: 1px solid var(--c-border);
  border-radius: var(--radius);
  padding: 12px;
  margin-bottom: 8px;
  cursor: pointer;
  transition: border-color .15s, transform .1s;
}
.card:hover, .card:active { border-color: var(--c-accent); }
.card:active { transform: scale(.99); }
.card strong { display: block; margin-bottom: 3px; font-size: 15px; }
.card small { color: var(--c-muted); display: block; line-height: 1.4; font-size: 13px; }

/* Case list */
.case-list {
  display: grid; gap: 8px;
  max-height: none;
  overflow: visible;
}
.case-row {
  border: 1px solid var(--c-border);
  border-radius: var(--radius);
  padding: 12px;
  background: var(--c-bg-2);
  cursor: pointer;
  transition: border-color .15s, transform .1s;
}
.case-row:hover, .case-row:active { border-color: var(--c-accent); }
.case-row:active { transform: scale(.99); }
.meta { color: var(--c-muted); font-size: 13px; margin-top: 4px; }

/* Dialogs — robust fullscreen on phone/small tablet */
dialog {
  margin: 0; padding: 0;
  inset: 0;
  width: 100vw; max-width: 100vw;
  height: 100dvh; max-height: 100dvh;
  border: 0;
  background: var(--c-bg);
  color: var(--c-text);
}
dialog[open] { display: flex; flex-direction: column; }
dialog::backdrop { background: rgba(0,0,0,.7); }

/* Auth dialog & users dialog: centered card even on mobile */
#authDialog, #usersDialog {
  inset: auto;
  margin: auto;
  width: min(440px, calc(100vw - 24px));
  height: auto; max-height: min(92dvh, 720px);
  border-radius: 18px;
  border: 1px solid var(--c-border);
  box-shadow: var(--shadow-lg);
}

.dialog-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 10px; padding: calc(12px + var(--safe-top)) 16px 12px;
  border-bottom: 1px solid var(--c-border);
  background: var(--c-panel);
  position: sticky; top: 0; z-index: 5;
  flex-shrink: 0;
}
#authDialog .dialog-head, #usersDialog .dialog-head {
  padding-top: 14px;
}
.dialog-head h2 { font-size: 16px; }
.dialog-actions {
  display: flex; flex-wrap: wrap; gap: 10px;
  align-items: center; justify-content: stretch;
  padding: 12px 16px calc(16px + var(--safe-bot));
  border-top: 1px solid var(--c-border);
  background: var(--c-panel);
  position: sticky; bottom: 0; z-index: 5;
  flex-shrink: 0;
}
#authDialog .dialog-actions, #usersDialog .dialog-actions {
  padding-bottom: 14px;
}
.dialog-actions > * { flex: 1; min-width: 0; }
.dialog-actions .meta { flex-basis: 100%; text-align: center; }
.icon-btn {
  width: 40px; height: 40px; padding: 0; min-height: 0;
  font-size: 20px; line-height: 1;
  background: transparent;
  border: 1px solid var(--c-border);
  color: var(--c-text);
}

/* Case form scrollable area */
.case-form, .auth-form {
  display: flex; flex-direction: column;
  flex: 1; min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}
.case-form > * { flex-shrink: 0; }
.case-form > .dialog-head,
.case-form > .dialog-actions { flex-shrink: 0; }

/* Fieldsets */
fieldset {
  border: 1px solid var(--c-border);
  border-radius: var(--radius);
  padding: 14px;
  margin: 14px 16px 0;
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
}
fieldset:last-of-type { margin-bottom: 12px; }
fieldset legend {
  color: var(--c-accent);
  font-weight: 700; font-size: 13px;
  padding: 0 8px;
  text-transform: uppercase; letter-spacing: .06em;
}
label {
  color: var(--c-muted);
  font-size: 13px;
  display: grid;
  gap: 6px;
  font-weight: 500;
}
label input, label select, label textarea {
  font-weight: 400;
  color: var(--c-text);
}
.check-grid { display: grid; gap: 8px; }
.check-grid label {
  display: flex; flex-direction: row; align-items: center;
  color: var(--c-text); padding: 8px 10px;
  background: var(--c-bg-2); border-radius: var(--radius-sm);
  border: 1px solid var(--c-border);
  cursor: pointer; min-height: 44px;
}

/* Followups */
.followups-list { display: grid; gap: 6px; padding: 0 16px; }
.followup {
  display: flex; justify-content: space-between; align-items: center;
  gap: 10px; padding: 12px;
  border: 1px solid var(--c-border);
  border-radius: var(--radius-sm);
  background: var(--c-bg-2);
  min-height: 48px;
}
.followup.done { opacity: .6; }
.followup.overdue { border-color: var(--c-danger); }
.followup label {
  display: flex; align-items: center; gap: 8px;
  color: var(--c-text); flex-direction: row; flex: 1;
}
.followup .meta { margin: 0; font-size: 12px; }

/* Doc dialog */
.doc-tabs {
  display: flex; flex-wrap: wrap; gap: 6px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--c-border);
  background: var(--c-panel);
}
.doc-tabs button { font-size: 12px; padding: 8px 12px; min-height: 36px; flex: 1; }
#documentOutput {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 13px; line-height: 1.45;
  min-height: 50dvh;
  border-radius: 0;
  border: 0; border-top: 1px solid var(--c-border);
  background: var(--c-bg-2);
  flex: 1;
}

/* Empty state */
.empty {
  color: var(--c-muted); padding: 14px;
  border: 1px dashed var(--c-border);
  border-radius: var(--radius);
  text-align: center; font-size: 13px;
}

/* Portail share section in case form */
.share-block {
  display: flex; flex-wrap: wrap; gap: 8px;
}
.share-block button { flex: 1 1 calc(50% - 4px); }

/* Tablet 700-1100px */
@media (min-width: 700px) {
  main { padding: 24px clamp(20px, 4vw, 36px); }
  .topbar { padding: 22px clamp(20px, 4vw, 36px); }
  h1 { font-size: 24px; }
  h2 { font-size: 20px; }
  .topbar {
    grid-template-columns: 1fr auto auto auto;
    grid-template-rows: auto;
  }
  .topbar-title { grid-column: 1; grid-row: 1; }
  .user-badge { grid-column: 2; grid-row: 1; max-width: none; font-size: 13px; padding: 8px 12px; }
  .primary-cta { grid-column: 3; grid-row: 1; }
  .overflow-wrap { grid-column: 4; grid-row: 1; }
  h1 { font-size: 20px; }
  .panel-head { flex-direction: row; align-items: center; justify-content: space-between; }
  #searchInput { max-width: 360px; }
  .priority {
    grid-template-columns: 1fr auto auto;
    align-items: center;
  }
  .kanban {
    grid-auto-flow: row;
    grid-template-columns: repeat(2, 1fr);
    grid-auto-columns: auto;
    scroll-snap-type: none;
  }
  fieldset {
    grid-template-columns: repeat(2, 1fr);
    margin-left: clamp(20px, 4vw, 36px);
    margin-right: clamp(20px, 4vw, 36px);
  }
  textarea, .docs-fieldset { grid-column: 1 / -1; }
  .check-grid { grid-template-columns: repeat(2, 1fr); }
  /* Desktop only (≥ 900px) : dialogs deviennent des cards centrées */
}
@media (min-width: 900px) {
  #caseDialog, #documentsDialog {
    inset: auto;
    width: min(900px, calc(100vw - 32px));
    height: auto; max-height: 92dvh;
    margin: auto;
    border-radius: 18px;
    border: 1px solid var(--c-border);
    box-shadow: var(--shadow-lg);
  }
  #authDialog { width: min(440px, calc(100vw - 32px)); }
  #usersDialog { width: min(640px, calc(100vw - 32px)); }
}

/* Desktop ≥ 1100px */
@media (min-width: 1100px) {
  main { padding: 28px clamp(28px, 4vw, 52px); }
  .topbar { padding: 26px clamp(28px, 4vw, 52px); }
  h1 { font-size: clamp(24px, 3vw, 36px); letter-spacing: -0.03em; }
  .kpis { grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); }
  .grid-two { grid-template-columns: minmax(0, 1.25fr) minmax(380px, .75fr); align-items: start; }
  .kanban { grid-template-columns: repeat(4, 1fr); }
  fieldset { grid-template-columns: repeat(4, 1fr); }
  .check-grid { grid-template-columns: repeat(3, 1fr); }
}

/* Print */
@media print {
  body * { visibility: hidden; }
  #documentsDialog, #documentsDialog * { visibility: visible; }
  #documentsDialog {
    position: absolute; inset: 0;
    width: 100%; max-width: 100%;
    border: 0; box-shadow: none;
    background: white; color: black;
  }
  #documentOutput {
    color: black; background: white;
    border: 0; width: 100%; height: auto;
  }
  .dialog-head, .doc-tabs, .dialog-actions { display: none; }
}
