:root {
  --bg: #f8fafc;
  --card: #ffffff;
  --ink: #111827;
  --muted: #6b7280;
  --line: #e5e7eb;
  --overdue: #b91c1c;
  --lastday: #c2410c;
  --tomorrow: #1d4ed8;
  --primary: #1f2937;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, Segoe UI, Roboto, Arial, sans-serif;
  font-size: 14px;
}

.topbar {
  display: flex; align-items: center; justify-content: space-between;
  background: var(--primary); color: #fff; padding: 12px 20px;
}
.brand { color: #fff; font-weight: 700; font-size: 18px; text-decoration: none; }
.topbar nav a { color: #cbd5e1; text-decoration: none; margin-left: 16px; }
.topbar nav a:hover { color: #fff; }

.container { max-width: 1200px; margin: 24px auto; padding: 0 20px; }

.dash-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; flex-wrap: wrap; gap: 12px; }
.kpis { display: flex; gap: 12px; }
.kpi { background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 12px 18px; min-width: 90px; text-align: center; }
.kpi .n { display: block; font-size: 28px; font-weight: 700; }
.kpi .l { display: block; font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.kpi-overdue .n { color: var(--overdue); }
.kpi-lastday .n { color: var(--lastday); }
.kpi-tomorrow .n { color: var(--tomorrow); }

.section-title { margin: 28px 0 10px; font-size: 18px; }
.section-title small { color: var(--muted); font-weight: 400; font-size: 13px; }
.section-overdue { color: var(--overdue); }
.section-lastship { color: var(--lastday); }

.table-wrap { overflow-x: auto; background: var(--card); border: 1px solid var(--line); border-radius: 10px; }
table { width: 100%; border-collapse: collapse; }
thead th { background: #f1f5f9; text-align: left; padding: 10px; font-size: 12px; text-transform: uppercase; color: var(--muted); white-space: nowrap; }
th.sort { cursor: pointer; user-select: none; }
th.sort:hover { background: #e2e8f0; }
th.sort::after { content: "↕"; opacity: .35; margin-left: 6px; font-size: 11px; }
th.sort.sorted-asc::after { content: "▲"; opacity: 1; }
th.sort.sorted-desc::after { content: "▼"; opacity: 1; }
tbody td { padding: 10px; border-top: 1px solid var(--line); }
tbody tr.urgency-overdue { background: #fef2f2; }
tbody tr.urgency-last_day { background: #fff7ed; }
.center { text-align: center; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; }
.small { font-size: 11px; }
.empty { color: var(--muted); padding: 16px; background: var(--card); border: 1px dashed var(--line); border-radius: 10px; }

.btn { background: #fff; border: 1px solid var(--line); border-radius: 8px; padding: 8px 14px; cursor: pointer; font-size: 13px; }
.btn:hover { background: #f1f5f9; }
.btn-primary { background: var(--primary); color: #fff; border-color: var(--primary); }
.btn-primary:hover { background: #374151; }
.btn-danger { color: var(--overdue); border-color: #fecaca; }
.btn-sm { padding: 5px 10px; font-size: 12px; }

.flash { padding: 10px 14px; border-radius: 8px; margin-bottom: 12px; }
.flash-success { background: #ecfdf5; color: #065f46; border: 1px solid #a7f3d0; }
.flash-error { background: #fef2f2; color: #991b1b; border: 1px solid #fecaca; }

.login-card { max-width: 360px; margin: 60px auto; background: var(--card); padding: 28px; border: 1px solid var(--line); border-radius: 12px; }
.login-card label, .grid-form label { display: block; margin-bottom: 12px; font-size: 13px; color: var(--muted); }
.login-card input, .grid-form input, .grid-form select { display: block; width: 100%; padding: 8px 10px; margin-top: 4px; border: 1px solid var(--line); border-radius: 8px; font-size: 14px; }

.add-form { margin-top: 16px; }
.add-form summary { cursor: pointer; color: var(--primary); font-weight: 600; padding: 8px 0; }
.grid-form { display: grid; grid-template-columns: 1fr 1fr; gap: 8px 16px; margin-top: 12px; align-items: end; }
.grid-form .wide { grid-column: 1 / -1; }
.grid-form label.inline { display: flex; align-items: center; gap: 6px; }
.grid-form label.inline input { width: auto; margin: 0; }

.actions { display: flex; gap: 6px; justify-content: center; flex-wrap: wrap; }
.actions form { margin: 0; display: inline; }
.wide-input { width: 100%; padding: 6px 8px; border: 1px solid var(--line); border-radius: 6px; }
.badge-todo { background: #fef9c3; color: #854d0e; font-size: 11px; padding: 2px 6px; border-radius: 4px; }
.delay { white-space: nowrap; }
.badge-late { background: #fee2e2; color: #991b1b; font-weight: 600; font-size: 12px; padding: 3px 8px; border-radius: 999px; }
.badge-today { background: #ffedd5; color: #9a3412; font-weight: 600; font-size: 12px; padding: 3px 8px; border-radius: 999px; }

section { margin-bottom: 32px; }
h1 { font-size: 22px; }
h2 { font-size: 17px; }

.muted { color: var(--muted); }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 4px; }

/* ---- Formulaire canal (page dédiée) ---- */
.conn-form { max-width: 520px; background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 24px; margin-top: 16px; }
.form-section { margin-bottom: 4px; }
.conn-form .field { display: block; margin-bottom: 18px; }
.conn-form .field-label { display: block; font-size: 13px; font-weight: 600; color: #374151; margin-bottom: 6px; }
.conn-form .req { color: var(--overdue); font-style: normal; }
.conn-form input[type=text],
.conn-form input[type=url],
.conn-form input[type=password],
.conn-form select {
  width: 100%; padding: 10px 12px; border: 1px solid #d1d5db; border-radius: 8px;
  font-size: 14px; background: #fff;
}
.conn-form input:focus, .conn-form select:focus { outline: none; border-color: #6b7280; box-shadow: 0 0 0 3px rgba(31,41,55,.08); }
.conn-form .field.inline { display: flex; align-items: center; gap: 8px; }
.conn-form .field.inline input { width: auto; }

/* fieldsets par type : seul le type choisi est visible */
.type-fields { border: none; padding: 0; margin: 0; }
.type-fields:not(.active) { display: none; }
.type-fields .hint { font-size: 12px; color: var(--muted); background: #f8fafc; border-left: 3px solid var(--line); padding: 8px 10px; border-radius: 4px; margin: 0 0 16px; }

.form-actions { display: flex; gap: 10px; margin-top: 8px; padding-top: 16px; border-top: 1px solid var(--line); }

.conn-form textarea {
  width: 100%; padding: 10px 12px; border: 1px solid #d1d5db; border-radius: 8px;
  font-size: 14px; font-family: inherit; resize: vertical;
}
.conn-form textarea:focus { outline: none; border-color: #6b7280; box-shadow: 0 0 0 3px rgba(31,41,55,.08); }

/* Champ secret masqué mais non-password (anti gestionnaires de mots de passe) */
.masked { -webkit-text-security: disc; text-security: disc; }

.checkbox-inline { display: flex; align-items: center; gap: 8px; font-size: 13px; color: #374151; font-weight: 400; cursor: pointer; }
.checkbox-inline input { width: auto !important; margin: 0; }

.checkbox-group { border: 1px solid var(--line); border-radius: 8px; padding: 12px 14px; margin-bottom: 18px; }
.checkbox-group legend { padding: 0 6px; }
.inline-form { display: flex; gap: 6px; align-items: center; margin: 0; }

.nav-user { color: #fff; font-weight: 600; margin-left: 16px; opacity: .85; }

.tag { display: inline-block; background: #e5e7eb; color: #374151; font-size: 11px; padding: 2px 8px; border-radius: 999px; }
.tag-late { background: #fee2e2; color: #991b1b; }
.tag-today { background: #ffedd5; color: #9a3412; }
.tag-admin { background: #dbeafe; color: #1e40af; }
