:root {
  --bg: #f7f7f5;
  --surface: #ffffff;
  --text: #1c1c1a;
  --muted: #6b6b66;
  --border: #e3e3de;
  --accent: #1f4e78;
  --accent-text: #ffffff;
  --danger: #b42318;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #141413;
    --surface: #1d1d1b;
    --text: #ececea;
    --muted: #9a9a94;
    --border: #2e2e2b;
    --accent: #6ea8dc;
    --accent-text: #0d1b29;
    --danger: #f97066;
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", sans-serif;
}
main { max-width: 1200px; margin: 0 auto; padding: 24px 16px; }
h1 { font-size: 1.6rem; margin: 0 0 8px; }
h2 { font-size: 1.15rem; margin: 32px 0 12px; }
.muted { color: var(--muted); }
a { color: var(--accent); }

.topbar {
  display: flex; align-items: center; gap: 24px;
  padding: 12px 16px; background: var(--surface); border-bottom: 1px solid var(--border);
}
.topbar .brand { font-weight: 700; text-decoration: none; color: var(--text); }
.topbar nav { display: flex; gap: 16px; flex: 1; }
.topbar nav a { text-decoration: none; }
.logout { margin: 0; }

button {
  font: inherit; padding: 8px 16px; border: 0; border-radius: 6px;
  background: var(--accent); color: var(--accent-text); cursor: pointer;
}
button.link { background: none; color: var(--muted); padding: 0; }
input, select, textarea {
  font: inherit; padding: 8px 10px; border: 1px solid var(--border); border-radius: 6px;
  background: var(--surface); color: var(--text); width: 100%;
}
label { display: grid; gap: 4px; }

.login { max-width: 360px; margin: 10vh auto; }
.login form { display: grid; gap: 16px; padding: 24px; background: var(--surface); border: 1px solid var(--border); border-radius: 10px; }
.error { color: var(--danger); margin: 0; }

.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 12px; margin-top: 16px; }
.tile { display: grid; padding: 16px; background: var(--surface); border: 1px solid var(--border); border-radius: 10px; }
.tile .n { font-size: 1.8rem; font-weight: 700; font-variant-numeric: tabular-nums; }

table { width: 100%; border-collapse: collapse; background: var(--surface); border: 1px solid var(--border); }
th, td { padding: 8px 12px; border-bottom: 1px solid var(--border); text-align: left; }
th { font-weight: 600; color: var(--muted); font-size: 0.85rem; }
.num { text-align: right; font-variant-numeric: tabular-nums; }

.section-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-top: 32px; }
.section-head h2 { margin: 0; }
.section-head form { margin: 0; }

.topbar nav a.active { font-weight: 600; text-decoration: underline; text-underline-offset: 4px; }

/* table view */
.filters { display: flex; flex-wrap: wrap; gap: 12px; align-items: end; margin: 16px 0; }
.filters .grow { flex: 1 1 320px; }
.filters label { font-size: 0.8rem; color: var(--muted); }
.filters select, .filters input { width: auto; }
.filters input.narrow { width: 90px; }
.filters label.check { display: flex; align-items: center; gap: 6px; }
.filters label.check input { width: auto; }
.count { margin: 8px 0; }
.notice { padding: 8px 12px; border: 1px solid var(--border); border-radius: 6px; background: var(--surface); }
.notice.ok { border-color: #2e7d32; }
.table-wrap { overflow-x: auto; }
table.dossiers td { vertical-align: top; font-size: 0.9rem; }
table.dossiers td.main { min-width: 260px; }
table.dossiers td.main > a { font-weight: 600; text-decoration: none; }
table.dossiers .sub { color: var(--muted); font-size: 0.8rem; margin-top: 2px; }
.ellipsis { max-width: 160px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
th a { color: inherit; text-decoration: none; }
.status-select { width: auto; font-size: 0.85rem; padding: 4px 6px; }
.badge { display: inline-block; padding: 1px 6px; border-radius: 4px; font-size: 0.75rem; background: var(--bg); border: 1px solid var(--border); color: var(--muted); }
.badge-etude { border-color: var(--accent); color: var(--accent); }
.badge-zone { margin-left: 4px; }
.dldo-soon { color: #b54708; font-weight: 600; }
.dldo-urgent { color: var(--danger); font-weight: 700; }
.pager { display: flex; gap: 16px; justify-content: center; margin: 16px 0; }

/* kanban */
.board { display: grid; grid-auto-flow: column; grid-auto-columns: minmax(190px, 1fr); gap: 12px; overflow-x: auto; padding-bottom: 12px; }
.column { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 8px; min-height: 200px; }
.column.over { outline: 2px dashed var(--accent); }
.column h2 { font-size: 0.95rem; margin: 4px 4px 8px; display: flex; justify-content: space-between; }
.col-count { color: var(--muted); font-weight: 400; }
.cards { display: grid; gap: 8px; }
.card { background: var(--bg); border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px; cursor: grab; }
.card.dragging { opacity: 0.4; }
.card-title { font-weight: 600; text-decoration: none; display: block; }
.card .sub { color: var(--muted); font-size: 0.8rem; }
.card-meta { display: flex; flex-wrap: wrap; gap: 8px; font-size: 0.8rem; margin-top: 6px; align-items: center; }

/* dossier */
.dossier-head { display: flex; justify-content: space-between; gap: 16px; align-items: start; flex-wrap: wrap; }
.button-link { padding: 8px 16px; border-radius: 6px; background: var(--accent); color: var(--accent-text); text-decoration: none; }
.dossier-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 12px; margin: 16px 0; }
.panel { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 12px 16px; margin-bottom: 12px; }
.panel h2 { margin: 0 0 8px; font-size: 1rem; }
h2.inline { display: inline; }
.facts { display: grid; grid-template-columns: max-content 1fr; gap: 4px 16px; margin: 0; }
.facts dt { color: var(--muted); }
.facts dd { margin: 0; }
.reason, .prose { white-space: pre-wrap; }
.follow-up { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 12px; }
.follow-up .wide { grid-column: 1 / -1; }
.files { margin: 0; padding-left: 18px; }
.mail { border-top: 1px solid var(--border); padding: 8px 0; }
.mail summary { cursor: pointer; }

@media (max-width: 700px) {
  main { padding: 16px; }
  .filters select, .filters input { width: 100%; }
}
table.dossiers td.num, table.dossiers td:nth-child(7), table.dossiers td:nth-child(8) { white-space: nowrap; }
table.dossiers td.main > a, .card-title {
  display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden;
}

main.wide { max-width: none; }

/* dossier modal */
#dossier-modal {
  width: min(1100px, calc(100vw - 32px)); max-height: calc(100vh - 48px);
  padding: 0; border: 1px solid var(--border); border-radius: 12px;
  background: var(--bg); color: var(--text);
}
#dossier-modal::backdrop { background: rgb(0 0 0 / 0.45); }
.modal-bar {
  position: sticky; top: 0; z-index: 1; display: flex; justify-content: space-between; align-items: center;
  padding: 10px 16px; background: var(--surface); border-bottom: 1px solid var(--border);
}
#modal-body { padding: 16px; }
#modal-body .dossier-head h1 { font-size: 1.35rem; }
/* kanban: a long unbroken title must wrap inside its card, never widen the column */
.column { min-width: 0; }
.card { min-width: 0; overflow-wrap: anywhere; }
.badge-aj { border-color: #6941c6; color: #6941c6; font-weight: 600; }
.badge-mj { border-color: #027a48; color: #027a48; font-weight: 600; }
@media (prefers-color-scheme: dark) {
  .badge-aj { border-color: #b692f6; color: #b692f6; }
  .badge-mj { border-color: #6ce9a6; color: #6ce9a6; }
}
.section-head .links { display: flex; gap: 16px; }
.row-actions { display: flex; gap: 6px; align-items: center; }
button.dismiss {
  padding: 3px 8px; font-size: 0.75rem; border-radius: 5px;
  background: transparent; color: var(--danger); border: 1px solid var(--danger);
}
button.dismiss:hover { background: var(--danger); color: var(--surface); }
.card-meta button.dismiss { margin-left: auto; }
