/* Courtlien — styles (sans dépendance externe) */

:root {
  --brand: #0b6e69;
  --brand-600: #095a56;
  --brand-700: #074541;
  --brand-50: #e7f3f2;
  --accent: #fbbf24;
  --bg: #f4f7f6;
  --surface: #ffffff;
  --text: #13211f;
  --muted: #5b6e6a;
  --line: #dfe7e5;
  --line-strong: #c4d3d0;
  --danger: #b42318;
  --sidebar: #0f2d2a;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(19, 33, 31, .05), 0 4px 16px rgba(19, 33, 31, .04);
  color-scheme: light;
}

*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 15px;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
}

h1, h2, h3 { line-height: 1.25; }
h1 { font-size: 1.6rem; margin: 0; letter-spacing: -.01em; }
h2 { font-size: 1.05rem; margin: 0 0 12px; }
h3 { font-size: 1rem; margin: 0 0 8px; }
p { margin: 0 0 10px; }
a { color: var(--brand); }
small, .muted { color: var(--muted); }
code, .mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: .92em; }

:focus-visible { outline: 3px solid rgba(11, 110, 105, .35); outline-offset: 2px; }

.skip-link {
  position: absolute; left: -9999px; top: 8px; background: var(--brand); color: #fff;
  padding: 8px 12px; border-radius: 8px; z-index: 50;
}
.skip-link:focus { left: 8px; }

[hidden], .hidden { display: none !important; }

/* ---------- Mise en page ---------- */

.app {
  display: grid;
  grid-template-columns: 248px minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 18px 14px;
  background: var(--sidebar);
  color: #d4e6e3;
  overflow-y: auto;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 4px 8px 16px;
  text-decoration: none;
  color: #fff;
}
.brand-text { display: grid; line-height: 1.2; }
.brand-text strong { font-size: 1.05rem; letter-spacing: -.01em; }
.brand-text small { color: #8fb3ad; font-size: .72rem; }

.nav { display: grid; gap: 2px; }
.nav-heading {
  margin: 14px 10px 6px;
  font-size: .7rem;
  text-transform: uppercase;
  letter-spacing: .09em;
  color: #7fa39d;
}
.nav a {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 10px;
  border-radius: 10px;
  color: #c9ddd9;
  text-decoration: none;
  font-weight: 500;
}
.nav a:hover { background: rgba(255, 255, 255, .06); color: #fff; }
.nav a.active { background: rgba(255, 255, 255, .12); color: #fff; font-weight: 600; }
.nav a .count {
  margin-left: auto;
  font-size: .72rem;
  background: rgba(255, 255, 255, .14);
  padding: 1px 8px;
  border-radius: 999px;
}

.sidebar-foot {
  margin-top: auto;
  padding: 12px 10px 4px;
  font-size: .78rem;
  color: #8fb3ad;
  border-top: 1px solid rgba(255, 255, 255, .08);
}
.sidebar-foot .demo-note { color: var(--accent); font-weight: 600; }

.main { min-width: 0; display: flex; flex-direction: column; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 24px;
  background: rgba(244, 247, 246, .92);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
}

.search-trigger {
  flex: 1;
  max-width: 520px;
  display: flex;
  align-items: center;
  gap: 10px;
  height: 42px;
  padding: 0 12px;
  border: 1px solid var(--line-strong);
  background: var(--surface);
  border-radius: 12px;
  color: var(--muted);
  font: inherit;
  cursor: pointer;
  text-align: left;
}
.search-trigger:hover { border-color: var(--brand); color: var(--text); }
.search-trigger svg { width: 18px; height: 18px; flex: none; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; }
.search-trigger span:nth-child(2) { flex: 1; }
.kbd-group { display: flex; gap: 4px; }
kbd {
  font: 600 .72rem/1 ui-monospace, Menlo, Consolas, monospace;
  padding: 4px 6px;
  border: 1px solid var(--line-strong);
  border-bottom-width: 2px;
  border-radius: 6px;
  background: #f7faf9;
  color: var(--muted);
}

.topbar-right { margin-left: auto; display: flex; align-items: center; gap: 10px; }
.mode-pill {
  font-size: .78rem;
  font-weight: 600;
  padding: 5px 10px;
  border-radius: 999px;
  background: #fff7e6;
  color: #8a5a00;
  border: 1px solid #f5d48a;
  white-space: nowrap;
}

.view {
  width: 100%;
  max-width: 1180px;
  margin: 0 auto;
  padding: 24px;
  outline: none;
}

.loading { color: var(--muted); padding: 40px 0; text-align: center; }

.scrim {
  position: fixed;
  inset: 0;
  background: rgba(10, 30, 28, .4);
  z-index: 15;
}

/* ---------- Composants de base ---------- */

.page-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 20px;
}
.page-head p { color: var(--muted); margin: 6px 0 0; }
.head-actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
  margin-bottom: 16px;
}
.card-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 14px;
}
.card-head h2 { margin: 0; }

.notice {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  padding: 12px 14px;
  border-radius: 12px;
  background: #fff7e6;
  border: 1px solid #f5d48a;
  color: #6b4500;
  margin-bottom: 16px;
  font-size: .92rem;
}
.notice.info { background: var(--brand-50); border-color: #bfe0dc; color: #0b4f4b; }
.notice strong { font-weight: 700; }

.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}
.stat {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px 18px;
  box-shadow: var(--shadow);
}
.stat .label { color: var(--muted); font-size: .86rem; font-weight: 500; }
.stat .value { font-size: 1.7rem; font-weight: 700; letter-spacing: -.02em; margin-top: 4px; font-variant-numeric: tabular-nums; }
.stat .hint { color: var(--muted); font-size: .8rem; margin-top: 2px; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  height: 40px;
  padding: 0 16px;
  border-radius: 10px;
  border: 1px solid transparent;
  font: 600 .92rem/1 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
  transition: background .15s, border-color .15s, color .15s;
}
.btn svg, .icon-btn svg { width: 17px; height: 17px; flex: none; }
.btn.primary { background: var(--brand); color: #fff; }
.btn.primary:hover { background: var(--brand-600); }
.btn.ghost { background: var(--surface); border-color: var(--line-strong); color: var(--text); }
.btn.ghost:hover { border-color: var(--brand); color: var(--brand); }
.btn.danger { background: var(--danger); color: #fff; }
.btn.danger:hover { background: #912018; }
.btn.small { height: 32px; padding: 0 10px; font-size: .84rem; }
.btn.block { width: 100%; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn.danger-text { color: var(--danger); border-color: #f3c5c1; }
.btn.danger-text:hover { background: #fef3f2; }

.icon-btn {
  width: 40px;
  height: 40px;
  display: inline-grid;
  place-items: center;
  border-radius: 10px;
  border: 1px solid var(--line-strong);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  flex: none;
}
.icon-btn:hover { border-color: var(--brand); color: var(--brand); }
.menu-btn { display: none; }

svg.i { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: .75rem;
  font-weight: 600;
  padding: 3px 9px;
  border-radius: 999px;
  background: #eef3f2;
  border: 1px solid var(--line);
  color: #33504b;
  white-space: nowrap;
}
.chip::before {
  content: "";
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--c, #8a9b98);
}
.chip.demo { background: #fff7e6; border-color: #f5d48a; color: #8a5a00; }
.chip.demo::before { display: none; }

.status { font-size: .74rem; font-weight: 700; padding: 3px 9px; border-radius: 999px; white-space: nowrap; }
.s-active { background: #dcfce7; color: #166534; }
.s-expired { background: #fee2e2; color: #991b1b; }
.s-archived { background: #e5e7eb; color: #374151; }

.empty {
  text-align: center;
  padding: 44px 20px;
  color: var(--muted);
  background: var(--surface);
  border: 1px dashed var(--line-strong);
  border-radius: var(--radius);
}
.empty h3 { color: var(--text); font-size: 1.05rem; }
.empty .btn { margin-top: 12px; }

/* ---------- Formulaires ---------- */

.field { display: grid; gap: 6px; margin-bottom: 14px; }
.field > span, .field > .label-text { font-weight: 600; font-size: .88rem; }
input, select, textarea {
  width: 100%;
  height: 42px;
  padding: 0 12px;
  border: 1px solid var(--line-strong);
  border-radius: 10px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
}
input:focus, select:focus, textarea:focus { border-color: var(--brand); outline: 3px solid rgba(11, 110, 105, .15); }
input[type="color"] { padding: 4px; width: 56px; height: 42px; cursor: pointer; }
.field.invalid input, .field.invalid select { border-color: var(--danger); }
.err { color: var(--danger); font-size: .82rem; min-height: 0; }
.err:empty { display: none; }
.field small { color: var(--muted); font-size: .8rem; }

.prefix { display: flex; }
.prefix > span {
  display: grid;
  place-items: center;
  padding: 0 10px;
  height: 42px;
  border: 1px solid var(--line-strong);
  border-right: 0;
  border-radius: 10px 0 0 10px;
  background: #f1f5f4;
  color: var(--muted);
  font-weight: 500;
  white-space: nowrap;
  max-width: 55%;
  overflow: hidden;
  text-overflow: ellipsis;
}
.prefix input { border-radius: 0 10px 10px 0; }

.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 14px; }
.options {
  margin: 4px 0 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px 14px 4px;
  background: #fbfdfc;
}
.options summary { cursor: pointer; font-weight: 600; color: var(--brand); padding: 4px 0 10px; }

.form-error {
  color: var(--danger);
  background: #fef3f2;
  border: 1px solid #fecdca;
  padding: 10px 12px;
  border-radius: 10px;
  font-size: .9rem;
  margin-bottom: 12px;
}

.toolbar { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin-bottom: 16px; }
.toolbar input[type="search"] { flex: 1 1 240px; max-width: 380px; }
.toolbar select { width: auto; min-width: 180px; }

.range { display: flex; flex-wrap: wrap; gap: 10px 14px; align-items: center; }
.seg {
  display: inline-flex;
  flex-wrap: wrap;
  gap: 2px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 3px;
}
.seg button {
  border: 0;
  background: transparent;
  padding: 7px 12px;
  border-radius: 9px;
  font: 500 .88rem/1 system-ui, sans-serif;
  color: var(--muted);
  cursor: pointer;
}
.seg button:hover { color: var(--text); }
.seg button.active { background: var(--brand-50); color: var(--brand-700); font-weight: 700; }
.range-dates { display: flex; flex-wrap: wrap; gap: 10px; }
.range-dates label { display: flex; align-items: center; gap: 6px; color: var(--muted); font-size: .88rem; }
.range-dates input { width: auto; height: 36px; }
.range-label { color: var(--muted); font-size: .88rem; }

/* ---------- Cartes de liens ---------- */

.link-list { display: grid; gap: 12px; }
.link-card {
  display: flex;
  justify-content: space-between;
  gap: 18px;
  padding: 18px 20px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.link-main { min-width: 0; flex: 1; display: grid; gap: 6px; }
.link-tags { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.link-title { font-weight: 650; font-size: 1.02rem; color: var(--text); text-decoration: none; overflow-wrap: anywhere; }
.link-title:hover { color: var(--brand); }
.short-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.short { font: 600 .9rem/1.2 ui-monospace, Menlo, Consolas, monospace; color: var(--brand); overflow-wrap: anywhere; }
.btn-xs {
  display: inline-flex; align-items: center; gap: 5px;
  height: 26px; padding: 0 8px; border-radius: 8px;
  border: 1px solid var(--line-strong); background: var(--surface);
  font: 600 .76rem/1 system-ui, sans-serif; color: var(--muted); cursor: pointer;
}
.btn-xs:hover { color: var(--brand); border-color: var(--brand); }
.btn-xs svg { width: 13px; height: 13px; }
.long {
  color: var(--muted);
  font-size: .85rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.meta { display: flex; gap: 4px 16px; flex-wrap: wrap; color: var(--muted); font-size: .84rem; }
.meta b { color: var(--text); font-variant-numeric: tabular-nums; }
.link-actions { display: flex; flex-direction: column; gap: 6px; min-width: 148px; }

/* ---------- Graphique ---------- */

.chart svg { width: 100%; height: auto; display: block; }
.chart .grid { stroke: #e6eeec; stroke-width: 1; }
.chart .axis { fill: var(--muted); font-size: 11px; font-family: system-ui, sans-serif; }
.chart .bar { fill: var(--brand); opacity: .88; transition: opacity .15s; }
.chart .bar:hover { opacity: 1; fill: #0f8a84; }

/* ---------- Répartitions ---------- */

.split { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.bar-row {
  display: grid;
  grid-template-columns: minmax(90px, 150px) 1fr 56px;
  gap: 10px;
  align-items: center;
  padding: 7px 0;
  font-size: .9rem;
}
.bar-row .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar-row .num { text-align: right; font-variant-numeric: tabular-nums; font-weight: 600; }
.track { height: 8px; background: #edf3f2; border-radius: 999px; overflow: hidden; }
.track > i { display: block; height: 100%; background: var(--brand); border-radius: 999px; }
.note {
  font-size: .8rem;
  color: var(--muted);
  background: #f7faf9;
  border: 1px dashed var(--line-strong);
  border-radius: 10px;
  padding: 8px 10px;
  margin-top: 10px;
}

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: .9rem; }
th, td { text-align: left; padding: 10px 8px; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { color: var(--muted); font-weight: 600; font-size: .76rem; text-transform: uppercase; letter-spacing: .05em; white-space: nowrap; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
td.wrap { overflow-wrap: anywhere; max-width: 320px; }
tr:last-child td { border-bottom: 0; }

/* ---------- Modale & notifications ---------- */

dialog.modal {
  width: min(580px, calc(100vw - 24px));
  max-height: calc(100vh - 32px);
  padding: 0;
  border: 0;
  border-radius: 18px;
  box-shadow: 0 30px 80px rgba(0, 0, 0, .25);
  color: var(--text);
  overflow: hidden;
}
dialog.modal::backdrop { background: rgba(15, 45, 42, .45); backdrop-filter: blur(2px); }
dialog.modal[open] { display: flex; flex-direction: column; }
dialog.modal.modal-sm { width: min(440px, calc(100vw - 24px)); }
.modal-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 16px 18px 14px 20px;
  border-bottom: 1px solid var(--line);
}
.modal-head h2 { margin: 0; font-size: 1.1rem; }
.modal-body { padding: 18px 20px; overflow-y: auto; }
.modal-foot {
  display: flex;
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: 10px;
  padding: 14px 20px;
  border-top: 1px solid var(--line);
  background: #fafcfb;
}

.result-box {
  background: #f0faf8;
  border: 1px solid #bfe3dd;
  border-radius: 12px;
  padding: 14px;
}
.copy-row { display: flex; gap: 8px; align-items: center; }
.copy-row input { font: 600 .95rem/1 ui-monospace, Menlo, Consolas, monospace; color: var(--brand-700); }
.copy-row .btn { height: 42px; }

.toasts {
  position: fixed;
  left: 50%;
  bottom: 20px;
  transform: translateX(-50%);
  display: grid;
  gap: 8px;
  z-index: 100;
  width: min(440px, calc(100vw - 24px));
  pointer-events: none;
}
.toast {
  background: var(--sidebar);
  color: #fff;
  padding: 11px 16px;
  border-radius: 12px;
  box-shadow: 0 12px 30px rgba(0, 0, 0, .2);
  font-size: .92rem;
  animation: rise .18s ease-out;
}
.toast.error { background: var(--danger); }
@keyframes rise { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

.checklist { padding-left: 20px; margin: 8px 0 0; }
.checklist li { margin: 6px 0; }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 8px 16px; font-size: .92rem; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; overflow-wrap: anywhere; }
.swatches { display: flex; gap: 8px; flex-wrap: wrap; }

/* ---------- Responsive ---------- */

@media (max-width: 920px) {
  .app { grid-template-columns: minmax(0, 1fr); }
  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: 272px;
    height: auto;
    z-index: 20;
    transform: translateX(-102%);
    transition: transform .22s ease;
    box-shadow: 0 0 40px rgba(0, 0, 0, .3);
  }
  body.nav-open .sidebar { transform: none; }
  .menu-btn { display: inline-grid; }
  .topbar { padding: 10px 14px; }
  .search-trigger span:nth-child(2) { font-size: .92rem; }
  .view { padding: 16px 14px 90px; }
  .split { grid-template-columns: 1fr; }
  .link-card { flex-direction: column; }
  .link-actions { flex-direction: row; flex-wrap: wrap; min-width: 0; }
  .link-actions .btn { flex: 1 1 auto; }
  .topbar-right { display: none; }
}

@media (max-width: 640px) {
  .form-grid { grid-template-columns: 1fr; }
  .kbd-group { display: none; }
  .search-trigger { height: 40px; }
  h1 { font-size: 1.35rem; }
  .stat .value { font-size: 1.4rem; }
  .bar-row { grid-template-columns: 96px 1fr 48px; }
  .toolbar select, .toolbar input[type="search"] { max-width: none; width: 100%; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

/* ---- Accès, comptes et administration ---- */
body.auth-mode .app { display: block; }
body.auth-mode .sidebar,
body.auth-mode .topbar,
body.auth-mode .scrim { display: none !important; }

.auth-wrap {
  min-height: 100vh; display: grid; place-items: center;
  padding: 24px 16px; box-sizing: border-box; background: var(--bg);
}
.auth-card {
  width: 100%; max-width: 420px; background: var(--surface);
  border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 28px 24px; box-sizing: border-box;
}
.auth-card h1 { font-size: 1.4rem; margin: 0 0 6px; }
.auth-card > .muted { color: var(--muted); margin: 0 0 18px; line-height: 1.5; }
.auth-brand { display: flex; align-items: center; gap: 10px; margin-bottom: 18px; font-size: 1.05rem; }
.auth-card .btn.block { margin-top: 4px; }

.form-banner {
  background: #fef3f2; color: var(--danger); border: 1px solid #f3c5c1;
  border-radius: 10px; padding: 10px 12px; margin-bottom: 14px; font-size: .92rem;
}
.note.center { text-align: center; }
.link-btn {
  background: none; border: 0; color: var(--brand); font: inherit;
  font-weight: 600; cursor: pointer; padding: 4px; min-height: 32px;
}
.link-btn:hover { text-decoration: underline; }
.sub { font-size: 1rem; margin: 24px 0 6px; }

.who { display: grid; gap: 2px; font-size: .86rem; margin: 10px 0 6px; }
.who span { opacity: .75; }
.host { font-size: .8rem; opacity: .7; margin-bottom: 10px; overflow-wrap: anywhere; }
.sr-only {
  position: absolute; width: 1px; height: 1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap;
}

.users-table { width: 100%; border-collapse: collapse; font-size: .92rem; }
.users-table th, .users-table td {
  text-align: left; padding: 10px 8px; border-bottom: 1px solid var(--line); vertical-align: top;
}
.users-table th {
  color: var(--muted); font-weight: 600; font-size: .78rem;
  text-transform: uppercase; letter-spacing: .03em;
}
.users-table select {
  height: 34px; border: 1px solid var(--line-strong); border-radius: 8px;
  padding: 0 8px; background: var(--surface); font: inherit;
}
.users-table select:disabled { opacity: .6; }
.row-actions { white-space: nowrap; }
.row-actions .btn + .btn { margin-left: 6px; }
.chip.off { background: #fef3f2; border-color: #f3c5c1; color: var(--danger); }

.inline-form { display: flex; flex-wrap: wrap; gap: 12px; align-items: flex-end; }
.inline-form .field { flex: 1 1 180px; margin-bottom: 0; }
.inline-form .btn { margin-bottom: 14px; }

.temp-password {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 1.35rem; letter-spacing: .04em; text-align: center; user-select: all;
  background: var(--brand-50); border: 1px dashed var(--brand); border-radius: 12px; padding: 14px;
}
#pwForm + .head-actions { margin-top: 14px; }
