/* ============================================================
   style.css — Covaltri Portail
   Thème clair / sombre (automatique + bouton), cartes à ombre
   légère, un seul accent vert. Mobile d'abord : 1 colonne sous
   640 px, cibles tactiles de 44 px, pas de défilement horizontal.
   ============================================================ */

/* ── Couleurs et mesures ─────────────────────────────────────── */
:root {
  --font: 'Inter', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;

  --bg:            #f4f6f2;
  --surface:       #ffffff;
  --surface-2:     #eef1ec;
  --border:        #e0e5dd;
  --border-strong: #c5ccc2;
  --text:          #131c17;
  --text-2:        #46534b;
  --text-3:        #5f6b64;

  --accent:        #0f7a4d;
  --accent-hover:  #0b6640;
  --accent-soft:   #e0f1e8;
  --on-accent:     #ffffff;

  --danger:        #b32d23;
  --danger-soft:   #fcebe8;
  --warn:          #8f5400;
  --warn-soft:     #fcf0d9;
  --info:          #1b4f8a;
  --info-soft:     #e5eefa;

  --aside-from:    #0a3524;
  --aside-to:      #0f7a4d;

  --shadow-sm: 0 1px 2px rgba(19, 28, 23, 0.06);
  --shadow-md: 0 2px 4px rgba(19, 28, 23, 0.05), 0 10px 28px rgba(19, 28, 23, 0.09);
  --shadow-lg: 0 24px 60px rgba(19, 28, 23, 0.25);

  --radius-sm: 8px;
  --radius:    12px;
  --radius-lg: 18px;

  --space-1: 0.25rem;
  --space-2: 0.5rem;
  --space-3: 0.75rem;
  --space-4: 1rem;
  --space-5: 1.5rem;
  --space-6: 2.5rem;

  --ease: 0.16s ease;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg:            #0c110f;
    --surface:       #141a17;
    --surface-2:     #1b231f;
    --border:        #26302b;
    --border-strong: #3a463f;
    --text:          #ecf1ee;
    --text-2:        #b0bcb5;
    --text-3:        #8a978f;

    --accent:        #3ecf8e;
    --accent-hover:  #5fdba3;
    --accent-soft:   rgba(62, 207, 142, 0.14);
    --on-accent:     #06150d;

    --danger:        #ff8478;
    --danger-soft:   rgba(255, 132, 120, 0.14);
    --warn:          #f0b254;
    --warn-soft:     rgba(240, 178, 84, 0.14);
    --info:          #86b6f2;
    --info-soft:     rgba(134, 182, 242, 0.14);

    --aside-from:    #07150f;
    --aside-to:      #0d4a31;

    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 2px 4px rgba(0, 0, 0, 0.3), 0 10px 28px rgba(0, 0, 0, 0.32);
    --shadow-lg: 0 24px 60px rgba(0, 0, 0, 0.6);
    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  --bg:            #0c110f;
  --surface:       #141a17;
  --surface-2:     #1b231f;
  --border:        #26302b;
  --border-strong: #3a463f;
  --text:          #ecf1ee;
  --text-2:        #b0bcb5;
  --text-3:        #8a978f;

  --accent:        #3ecf8e;
  --accent-hover:  #5fdba3;
  --accent-soft:   rgba(62, 207, 142, 0.14);
  --on-accent:     #06150d;

  --danger:        #ff8478;
  --danger-soft:   rgba(255, 132, 120, 0.14);
  --warn:          #f0b254;
  --warn-soft:     rgba(240, 178, 84, 0.14);
  --info:          #86b6f2;
  --info-soft:     rgba(134, 182, 242, 0.14);

  --aside-from:    #07150f;
  --aside-to:      #0d4a31;

  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 2px 4px rgba(0, 0, 0, 0.3), 0 10px 28px rgba(0, 0, 0, 0.32);
  --shadow-lg: 0 24px 60px rgba(0, 0, 0, 0.6);
  color-scheme: dark;
}

/* ── Base ────────────────────────────────────────────────────── */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html, body {
  min-height: 100vh;
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}
body { overflow-x: hidden; }
html.modal-open { overflow: hidden; }

button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
ul { list-style: none; }

.hidden { display: none !important; }
.accent { color: var(--accent); font-weight: 600; }

:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
}

@keyframes spin  { to { transform: rotate(360deg); } }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.35; } }
@keyframes rise  { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
@keyframes pop   { from { opacity: 0; transform: translateY(10px) scale(0.98); } to { opacity: 1; transform: none; } }
@keyframes fade  { from { opacity: 0; } to { opacity: 1; } }
@keyframes ring  {
  0%   { box-shadow: 0 0 0 0 currentColor; }
  70%  { box-shadow: 0 0 0 7px transparent; }
  100% { box-shadow: 0 0 0 0 transparent; }
}
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25%      { transform: translateX(-5px); }
  75%      { transform: translateX(5px); }
}

.spin-icon  { animation: spin 0.8s linear infinite; }
.shake      { animation: shake 0.3s ease; }
.opacity-25 { opacity: 0.25; }
.opacity-75 { opacity: 0.9; }

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

/* ── Marque ──────────────────────────────────────────────────── */
.brand {
  display: inline-flex;
  align-items: center;
  gap: 0.625rem;
}
.brand-link { color: inherit; text-decoration: none; border-radius: var(--radius-sm); }
.brand-mark {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2.25rem;
  height: 2.25rem;
  border-radius: 11px;
  background: var(--accent);
  color: var(--on-accent);
  flex-shrink: 0;
  box-shadow: 0 2px 6px rgba(15, 122, 77, 0.35);
}
.brand-name {
  font-size: 1.0625rem;
  font-weight: 700;
  letter-spacing: -0.01em;
  white-space: nowrap;
}
.brand-sub { font-weight: 500; color: var(--text-3); }
.brand-on-dark { position: relative; z-index: 1; }
.brand-on-dark .brand-mark { background: #ffffff; color: #0f7a4d; box-shadow: none; }
.brand-on-dark .brand-name { color: #ffffff; }

/* ── Boutons ─────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  min-height: 2.75rem;
  padding: 0 1.125rem;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  font-size: 0.9375rem;
  font-weight: 600;
  text-decoration: none;
  white-space: nowrap;
  transition: background var(--ease), border-color var(--ease), color var(--ease), box-shadow var(--ease);
}
.btn:disabled,
.btn[aria-disabled="true"] { opacity: 0.55; cursor: not-allowed; }
.btn-block { width: 100%; }
.btn-sm { min-height: 2.25rem; padding: 0 0.875rem; font-size: 0.875rem; }

.btn-primary { background: var(--accent); color: var(--on-accent); box-shadow: var(--shadow-sm); }
.btn-primary:hover:not(:disabled):not([aria-disabled="true"]) { background: var(--accent-hover); }

.btn-outline { background: var(--surface); border-color: var(--border-strong); color: var(--text); }
.btn-outline:hover:not(:disabled) { background: var(--surface-2); }

.btn-ghost { background: transparent; color: var(--text-2); }
.btn-ghost:hover:not(:disabled) { background: var(--surface-2); color: var(--text); }

.btn-danger { background: var(--surface); border-color: var(--border-strong); color: var(--danger); }
.btn-danger:hover:not(:disabled) { background: var(--danger-soft); border-color: var(--danger); }

.btn-danger-solid { background: var(--danger); color: #ffffff; }
.btn-danger-solid:hover:not(:disabled) { filter: brightness(0.92); }

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2.75rem;
  height: 2.75rem;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  background: transparent;
  color: var(--text-2);
  flex-shrink: 0;
  transition: background var(--ease), color var(--ease);
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); }

/* Bouton thème : soleil en sombre, lune en clair */
.theme-toggle .icon-sun { display: none; }
:root[data-theme="dark"] .theme-toggle .icon-sun  { display: block; }
:root[data-theme="dark"] .theme-toggle .icon-moon { display: none; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .theme-toggle .icon-sun  { display: block; }
  :root:not([data-theme="light"]) .theme-toggle .icon-moon { display: none; }
}

/* ── Formulaires ─────────────────────────────────────────────── */
.form-group { margin-bottom: 1rem; }
fieldset { border: 0; min-width: 0; }

.form-label {
  display: block;
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 0.375rem;
}
.form-hint {
  margin-top: 0.375rem;
  font-size: 0.8125rem;
  color: var(--text-3);
}

.input-field,
.input-select {
  width: 100%;
  min-height: 2.75rem;
  padding: 0 0.875rem;
  border-radius: var(--radius-sm);
  background: var(--surface);
  border: 1px solid var(--border-strong);
  color: var(--text);
  font-size: 0.9375rem;
  transition: border-color var(--ease), box-shadow var(--ease);
}
.input-area { padding: 0.625rem 0.875rem; resize: vertical; line-height: 1.5; }
.input-field::placeholder { color: var(--text-3); }
.input-field:hover,
.input-select:hover { border-color: var(--text-3); }
.input-field:focus,
.input-select:focus {
  outline: 2px solid transparent;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft), 0 0 0 4px var(--accent);
}
.input-field:read-only { background: var(--surface-2); color: var(--text-2); }

/* Champ mot de passe avec bouton œil */
.input-eye { position: relative; }
.input-eye .input-field { padding-right: 3rem; }
.eye-btn {
  position: absolute;
  top: 50%;
  right: 0.25rem;
  transform: translateY(-50%);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2.5rem;
  height: 2.5rem;
  border: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-2);
}
.eye-btn:hover { background: var(--surface-2); color: var(--text); }

.remember-block { margin: 0.25rem 0 1.25rem; }
.remember-label {
  display: flex;
  align-items: center;
  gap: 0.625rem;
  min-height: 2.25rem;
  font-size: 0.9375rem;
  color: var(--text);
  cursor: pointer;
  user-select: none;
}
.remember-block .form-hint { margin: 0 0 0 1.6875rem; }
.remember-checkbox,
.app-tile input {
  width: 1.1875rem;
  height: 1.1875rem;
  accent-color: var(--accent);
  cursor: pointer;
  flex-shrink: 0;
}
#setup-step-account .remember-label { margin: 0.25rem 0 1rem; }

.divider {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin: 1rem 0;
  font-size: 0.8125rem;
  color: var(--text-3);
}
.divider::before,
.divider::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--border);
}

/* ── Pastilles ───────────────────────────────────────────────── */
.pill {
  display: inline-flex;
  align-items: center;
  gap: 0.375rem;
  padding: 0.1875rem 0.625rem;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 600;
  background: var(--surface-2);
  color: var(--text-2);
  white-space: nowrap;
}
.pill-warn   { background: var(--warn-soft);   color: var(--warn); }
.pill-accent { background: var(--accent-soft); color: var(--accent); }

/* ── Messages ────────────────────────────────────────────────── */
#status-message,
#setup-status-message,
.apps-message {
  display: none;
  padding: 0.75rem 0.875rem;
  border-radius: var(--radius-sm);
  font-size: 0.875rem;
  font-weight: 500;
  background: var(--surface-2);
  color: var(--text-2);
}
#status-message.visible,
#setup-status-message.visible {
  display: block;
  margin-bottom: 1rem;
}
.apps-message { display: block; margin-top: 1rem; }

#status-message.error,
#setup-status-message.error,
.apps-message.error   { background: var(--danger-soft); color: var(--danger); }
#status-message.success,
#setup-status-message.success,
.apps-message.success { background: var(--accent-soft); color: var(--accent); }

/* ── Écrans de connexion ─────────────────────────────────────── */
.auth {
  min-height: 100vh;
  display: grid;
  grid-template-columns: minmax(0, 5fr) minmax(0, 6fr);
}

.auth-aside {
  position: relative;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 2rem;
  padding: 2.5rem 3rem;
  color: #ffffff;
  background:
    radial-gradient(48rem 26rem at 105% 105%, rgba(94, 224, 160, 0.22), transparent 62%),
    radial-gradient(34rem 22rem at -10% -10%, rgba(255, 255, 255, 0.08), transparent 60%),
    linear-gradient(160deg, var(--aside-from), var(--aside-to));
  overflow: hidden;
}
/* Motif décoratif (points + anneaux du logo) */
.auth-pattern {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

.auth-aside-body { position: relative; z-index: 1; max-width: 26rem; }
.auth-aside-title {
  font-size: clamp(1.75rem, 2.6vw, 2.375rem);
  font-weight: 700;
  line-height: 1.15;
  letter-spacing: -0.025em;
  text-wrap: balance;
}
.auth-aside-text {
  margin-top: 1rem;
  font-size: 1rem;
  line-height: 1.6;
  color: rgba(255, 255, 255, 0.82);
}
.auth-aside-foot {
  position: relative;
  z-index: 1;
  font-size: 0.8125rem;
  color: rgba(255, 255, 255, 0.72);
}

.auth-panel {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 3rem 1.5rem;
}
.auth-theme-toggle {
  position: absolute;
  top: 1.25rem;
  right: 1.25rem;
}
.auth-box {
  width: 100%;
  max-width: 25rem;
  animation: rise 0.35s ease both;
}
.brand-compact { display: none; margin-bottom: 2rem; }

.auth-title {
  font-size: 1.875rem;
  font-weight: 700;
  letter-spacing: -0.03em;
  line-height: 1.2;
}
.auth-box .pill { margin-bottom: 0.75rem; }
.auth-subtitle {
  margin-top: 0.375rem;
  margin-bottom: 1.75rem;
  color: var(--text-2);
}
.login-card {
  padding: 1.5rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
}

.fido2-zone {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
  padding: 1.5rem;
  margin-bottom: 1rem;
  border-radius: var(--radius);
  background: var(--surface-2);
  color: var(--accent);
  text-align: center;
}
.fido2-title { font-weight: 600; color: var(--text); }
.fido2-label { font-size: 0.875rem; color: var(--text-2); line-height: 1.55; }
#setup-step-fido2 .btn + .btn { margin-top: 0.625rem; }

@media (max-width: 860px) {
  .auth { grid-template-columns: 1fr; }
  .auth-aside { display: none; }
  .brand-compact { display: inline-flex; }
  .auth-panel { align-items: flex-start; padding-top: 4.5rem; }
}

/* ── Structure des pages connectées ──────────────────────────── */
.app-shell {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--border);
}
.topbar-inner {
  display: flex;
  align-items: center;
  gap: 1rem;
  max-width: 72rem;
  margin: 0 auto;
  padding: 0.625rem 1.5rem;
}
.topbar-actions {
  display: flex;
  align-items: center;
  gap: 0.25rem;
  margin-left: auto;
}

/* Champ de recherche de l'en-tête (ouvre la recherche rapide) */
.search-field {
  display: flex;
  align-items: center;
  gap: 0.625rem;
  flex: 1;
  max-width: 24rem;
  min-height: 2.75rem;
  margin: 0 auto 0 1rem;
  padding: 0 0.75rem;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text-3);
  text-align: left;
  transition: border-color var(--ease), box-shadow var(--ease);
}
.search-field:hover { border-color: var(--text-3); }
.search-field-text { flex: 1; font-size: 0.9375rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.search-kbd {
  padding: 0.0625rem 0.4375rem;
  border: 1px solid var(--border-strong);
  border-radius: 6px;
  background: var(--surface-2);
  font-family: var(--font);
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-2);
}

/* Menu utilisateur */
.user-menu { position: relative; }
.user-chip {
  display: flex;
  align-items: center;
  gap: 0.625rem;
  min-height: 2.75rem;
  padding: 0 0.5rem;
  border: 1px solid transparent;
  border-radius: var(--radius);
  background: transparent;
  text-align: left;
  transition: background var(--ease);
}
button.user-chip:hover,
button.user-chip[aria-expanded="true"] { background: var(--surface-2); }
.user-chip-static { cursor: default; }
.user-chip-caret { color: var(--text-3); }
.avatar {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2.25rem;
  height: 2.25rem;
  border-radius: 50%;
  background: var(--accent);
  color: var(--on-accent);
  font-size: 0.8125rem;
  font-weight: 700;
  flex-shrink: 0;
}
.user-chip-text { display: flex; flex-direction: column; line-height: 1.25; }
.user-chip-name { font-size: 0.875rem; font-weight: 600; max-width: 10rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-chip-role { font-size: 0.75rem; color: var(--text-3); }

.menu {
  position: absolute;
  top: calc(100% + 0.5rem);
  right: 0;
  z-index: 30;
  min-width: 15.5rem;
  padding: 0.375rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  animation: pop 0.14s ease both;
}
.menu-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  width: 100%;
  min-height: 2.75rem;
  padding: 0 0.75rem;
  border: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  font-size: 0.9375rem;
  text-align: left;
  color: var(--text);
}
.menu-item svg { color: var(--text-3); flex-shrink: 0; }
.menu-item:hover,
.menu-item:focus-visible { background: var(--surface-2); }
.menu-item-sep { margin-top: 0.375rem; position: relative; }
.menu-item-sep::before {
  content: '';
  position: absolute;
  top: -0.25rem;
  left: 0.25rem;
  right: 0.25rem;
  height: 1px;
  background: var(--border);
}

.page {
  flex: 1;
  width: 100%;
  max-width: 72rem;
  margin: 0 auto;
  padding: 2rem 1.5rem 3rem;
  animation: rise 0.35s ease both;
}
.page-head { margin-bottom: 1.75rem; }
.page-title {
  font-size: clamp(1.625rem, 3vw, 2.25rem);
  font-weight: 700;
  letter-spacing: -0.03em;
  line-height: 1.15;
}
.page-subtitle { margin-top: 0.375rem; color: var(--text-2); }
.page-meta { margin-top: 0.125rem; font-size: 0.875rem; color: var(--text-3); }

.section + .section { margin-top: 2.5rem; }
.section-title {
  margin-bottom: 0.875rem;
  font-size: 0.8125rem;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--text-2);
}

.page-footer {
  padding: 1.25rem 1.5rem 1.75rem;
  text-align: center;
  font-size: 0.8125rem;
  color: var(--text-3);
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
}
.card.pad { padding: 1.25rem; }
.card-title { font-size: 1.0625rem; font-weight: 700; letter-spacing: -0.01em; }
.card-sub { margin: 0.125rem 0 1rem; font-size: 0.875rem; color: var(--text-2); }
.card-title + .announce-list { margin-top: 0.875rem; }

/* ── Annonces (accueil et aperçu administration) ─────────────── */
.announce-bar { display: grid; gap: 0.625rem; }
.announce-bar:not(:empty) { margin-bottom: 1.5rem; }

.announce {
  display: flex;
  align-items: flex-start;
  gap: 0.75rem;
  padding: 0.875rem 1rem;
  border: 1px solid transparent;
  border-radius: var(--radius);
  background: var(--info-soft);
  color: var(--info);
  animation: rise 0.25s ease both;
}
.announce > svg { margin-top: 0.125rem; flex-shrink: 0; }
.announce-text { flex: 1; min-width: 0; font-size: 0.9375rem; font-weight: 500; overflow-wrap: anywhere; white-space: pre-line; }
.announce-warning { background: var(--warn-soft);   color: var(--warn); }
.announce-danger  { background: var(--danger-soft); color: var(--danger); border-color: var(--danger); }
.announce-info    { border-color: color-mix(in srgb, var(--info) 30%, transparent); }
.announce-warning { border-color: color-mix(in srgb, var(--warn) 35%, transparent); }
.announce-close {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2.75rem;
  height: 2.75rem;
  margin: -0.625rem -0.75rem -0.625rem 0;
  border: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  color: inherit;
  flex-shrink: 0;
}
.announce-close:hover { background: rgba(127, 127, 127, 0.16); }

/* ── Cartes d'applications ───────────────────────────────────── */
.apps-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(19rem, 1fr));
  gap: 1rem;
}

.app-card {
  position: relative;
  display: flex;
  flex-direction: column;
  padding: 1.25rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-top: 4px solid var(--app-color, var(--accent));
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  transition: box-shadow var(--ease), border-color var(--ease), transform var(--ease);
}
.app-card.app-running:hover {
  box-shadow: var(--shadow-md);
  transform: translateY(-2px);
}
.app-card:has(.app-open:focus-visible) {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
}
.app-card:has(.app-open:focus-visible) .app-open { outline: none; }

.app-card-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 0.875rem;
}
.app-card-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 3.25rem;
  height: 3.25rem;
  border-radius: 15px;
  background: var(--app-color, var(--accent));
  color: #ffffff;
  font-size: 1.5rem;
  flex-shrink: 0;
  box-shadow: 0 4px 12px color-mix(in srgb, var(--app-color, var(--accent)) 35%, transparent);
}

.app-fav {
  position: relative;
  z-index: 2;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2.75rem;
  height: 2.75rem;
  margin: -0.5rem -0.5rem 0 0;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--text-3);
  transition: background var(--ease), color var(--ease), transform var(--ease);
}
.app-fav:hover { background: var(--surface-2); color: var(--warn); }
.app-fav.is-fav { color: #e0a100; }
.app-fav.is-fav svg { fill: currentColor; }

.app-card-name {
  font-size: 1.1875rem;
  font-weight: 700;
  letter-spacing: -0.015em;
  line-height: 1.25;
}
.app-card-body { display: flex; flex-direction: column; align-items: flex-start; gap: 0.5rem; }
.app-card-desc {
  font-size: 0.9375rem;
  color: var(--text-2);
}
.app-card-detail {
  margin-top: 0.5rem;
  font-size: 0.8125rem;
  color: var(--danger);
  overflow-wrap: anywhere;
}
.app-card-health {
  margin-top: 0.5rem;
  font-size: 0.8125rem;
  color: var(--text-3);
}

/* État : voyant animé */
.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 0.4375rem;
  padding: 0.1875rem 0.625rem;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 600;
  white-space: nowrap;
  background: var(--accent-soft);
  color: var(--accent);
}
.app-status-dot {
  width: 0.5rem;
  height: 0.5rem;
  border-radius: 50%;
  background: currentColor;
}
.app-running .app-status-dot { animation: ring 1.8s ease-out infinite; }
.app-stopped .status-pill { background: var(--danger-soft); color: var(--danger); }
.app-unknown .status-pill { background: var(--surface-2); color: var(--text-2); }
.app-starting .status-pill,
.app-partial .status-pill { background: var(--warn-soft); color: var(--warn); }
.app-starting .app-status-dot,
.app-partial .app-status-dot { animation: pulse 1.2s ease-in-out infinite; }

/* Application arrêtée : carte grisée */
.app-card:not(.app-running):not(.app-starting) { background: var(--surface-2); border-top-color: var(--border-strong); }
.app-card:not(.app-running) .app-card-icon { filter: grayscale(1); opacity: 0.55; box-shadow: none; }
.app-card:not(.app-running) .app-card-name,
.app-card:not(.app-running) .app-card-desc { opacity: 0.7; }

.app-card-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  flex-wrap: wrap;
  margin-top: auto;
  padding-top: 1.25rem;
}
/* La carte entière est cliquable : le lien « Ouvrir » s'étend sur toute la carte */
.app-open::after {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: var(--radius-lg);
}
.app-card-actions {
  position: relative;
  z-index: 2;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}
.app-btn-wait { font-size: 0.875rem; color: var(--text-3); }

.apps-empty {
  padding: 2.5rem 1rem;
  border-radius: var(--radius-lg);
  border: 1px dashed var(--border-strong);
  color: var(--text-2);
  text-align: center;
  line-height: 1.6;
}

/* ── Raccourcis du compte ────────────────────────────────────── */
.tools-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(19rem, 1fr));
  gap: 1rem;
}
.tool-card {
  display: flex;
  align-items: center;
  gap: 0.875rem;
  min-height: 4.25rem;
  padding: 0.875rem 1rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  text-align: left;
  transition: border-color var(--ease), background var(--ease), box-shadow var(--ease);
}
.tool-card:hover { border-color: var(--border-strong); box-shadow: var(--shadow-md); }
.tool-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2.5rem;
  height: 2.5rem;
  border-radius: 11px;
  background: var(--accent-soft);
  color: var(--accent);
  flex-shrink: 0;
}
.tool-info { display: flex; flex-direction: column; min-width: 0; }
.tool-name { font-size: 0.9375rem; font-weight: 600; }
.tool-desc { font-size: 0.8125rem; color: var(--text-2); }

/* ── Administration : onglets et barre d'outils ──────────────── */
.tabs {
  display: flex;
  gap: 0.25rem;
  margin-bottom: 1.5rem;
  border-bottom: 1px solid var(--border);
}
.tab {
  flex: 0 1 auto;
  min-height: 2.75rem;
  padding: 0 1.125rem;
  margin-bottom: -1px;
  border: 0;
  border-bottom: 3px solid transparent;
  background: transparent;
  font-size: 0.9375rem;
  font-weight: 600;
  color: var(--text-2);
  transition: color var(--ease), border-color var(--ease);
}
.tab:hover { color: var(--text); }
.tab[aria-selected="true"] { color: var(--accent); border-bottom-color: var(--accent); }

.toolbar {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.75rem;
  margin-bottom: 0.875rem;
}
.toolbar-search { position: relative; flex: 1 1 14rem; min-width: 0; }
.toolbar-search svg {
  position: absolute;
  top: 50%;
  left: 0.875rem;
  transform: translateY(-50%);
  color: var(--text-3);
  pointer-events: none;
}
.toolbar-search .input-field { padding-left: 2.5rem; }
.toolbar-select { flex: 0 1 13rem; width: auto; }
.list-count { margin-bottom: 0.625rem; font-size: 0.8125rem; color: var(--text-3); min-height: 1.25rem; }
.list-empty { padding: 1.5rem 1rem; text-align: center; color: var(--text-2); }
.load-more-row { display: flex; justify-content: center; margin-top: 1.25rem; }

.soon {
  padding: 2.5rem 1rem;
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius-lg);
  text-align: center;
  color: var(--text-2);
}

/* ── Administration : tableau des comptes ────────────────────── */
.table-card { overflow: hidden; }

.users-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.875rem;
}
.users-table th {
  padding: 0.75rem 1rem;
  text-align: left;
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text-2);
  background: var(--surface-2);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.users-table td {
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
  color: var(--text-2);
}
.users-table tbody tr:last-child td { border-bottom: none; }
.users-table tbody tr.is-clickable { cursor: pointer; transition: background var(--ease); }
.users-table tbody tr.is-clickable:hover { background: var(--surface-2); }
.users-table tbody tr.is-clickable:focus-visible { outline-offset: -3px; }
.users-table .cell-strong { font-weight: 600; color: var(--text); }
.users-table .cell-muted  { color: var(--text-2); white-space: nowrap; }
.users-table .cell-alert,
.cell-alert { color: var(--danger); }
.users-table .cell-center { text-align: center; padding: 2rem 1rem; }
.cell-muted-text { font-size: 0.8125rem; color: var(--text-3); overflow-wrap: anywhere; }

.user-cell { display: flex; align-items: center; gap: 0.75rem; min-width: 0; }
.user-cell-info { min-width: 0; }
.user-cell-name { display: flex; align-items: center; flex-wrap: wrap; gap: 0.375rem; }

.role-badge {
  display: inline-block;
  padding: 0.0625rem 0.5rem;
  border-radius: 999px;
  font-size: 0.6875rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  background: var(--surface-2);
  color: var(--text-2);
}
.role-badge.admin { background: var(--accent-soft); color: var(--accent); }
.key-badge { display: inline-flex; color: var(--accent); }

.app-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.375rem;
  margin: 0.125rem 0.25rem 0.125rem 0;
  padding: 0.125rem 0.625rem 0.125rem 0.5rem;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 600;
  white-space: nowrap;
  background: color-mix(in srgb, var(--chip, var(--text-3)) 14%, var(--surface));
  color: var(--text);
}
.app-chip-dot {
  width: 0.5rem;
  height: 0.5rem;
  border-radius: 50%;
  background: var(--chip, var(--text-3));
  flex-shrink: 0;
}

/* Comptes : cartes empilées sur mobile */
@media (max-width: 720px) {
  .users-table thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
  .users-table, .users-table tbody { display: block; }
  .users-table tbody tr {
    display: block;
    padding: 0.875rem 1rem;
    border-bottom: 1px solid var(--border);
  }
  .users-table tbody tr:last-child { border-bottom: none; }
  .users-table td { display: block; padding: 0.25rem 0; border: 0; }
  .users-table td[data-label]:not(.cell-user)::before {
    content: attr(data-label) ' : ';
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-3);
  }
  .users-table td.cell-user { padding-bottom: 0.5rem; }
  .users-table td.cell-user::before { content: none; }
  .users-table .cell-center { text-align: center; padding: 1.5rem 0; }
}

/* ── Administration : journal ────────────────────────────────── */
.journal-day + .journal-day { margin-top: 1.5rem; }
.journal-day-title {
  margin-bottom: 0.5rem;
  font-size: 0.8125rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text-2);
}
.journal-list {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}
.journal-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--border);
}
.journal-item:last-child { border-bottom: none; }
.journal-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2rem;
  height: 2rem;
  border-radius: 50%;
  background: var(--surface-2);
  color: var(--text-2);
  flex-shrink: 0;
}
.journal-main { flex: 1; min-width: 0; }
.journal-label { font-size: 0.9375rem; font-weight: 600; overflow-wrap: anywhere; }
.journal-meta { font-size: 0.8125rem; color: var(--text-3); overflow-wrap: anywhere; }
.journal-time { font-size: 0.8125rem; color: var(--text-3); white-space: nowrap; }
.journal-item.tone-ok    .journal-icon { background: var(--accent-soft); color: var(--accent); }
.journal-item.tone-warn  .journal-icon { background: var(--warn-soft);   color: var(--warn); }
.journal-item.tone-alert { background: color-mix(in srgb, var(--danger-soft) 55%, transparent); }
.journal-item.tone-alert .journal-icon { background: var(--danger-soft); color: var(--danger); }
.journal-item.tone-alert .journal-label { color: var(--danger); }

/* ── Administration : annonces ───────────────────────────────── */
.announce-admin { display: grid; gap: 1.25rem; grid-template-columns: minmax(0, 1fr); }
@media (min-width: 960px) {
  .announce-admin { grid-template-columns: minmax(0, 1.1fr) minmax(0, 1fr); align-items: start; }
}
.level-options { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 0.625rem; }
.level-option {
  position: relative;
  display: flex;
  align-items: center;
  gap: 0.625rem;
  min-height: 3.25rem;
  padding: 0.5rem 0.75rem;
  border: 2px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  cursor: pointer;
  transition: border-color var(--ease), background var(--ease);
}
.level-option input { position: absolute; opacity: 0; pointer-events: none; }
.level-option.level-info    { color: var(--info); }
.level-option.level-warning { color: var(--warn); }
.level-option.level-danger  { color: var(--danger); }
.level-option:has(input:checked) { border-color: currentColor; background: color-mix(in srgb, currentColor 10%, var(--surface)); }
.level-option:has(input:focus-visible) { outline: 3px solid var(--accent); outline-offset: 2px; }
.level-text { display: flex; flex-direction: column; line-height: 1.25; }
.level-name { font-size: 0.9375rem; font-weight: 700; }
.level-hint { font-size: 0.75rem; color: var(--text-2); }
#announce-date { margin-top: 0.625rem; }

.announce-list { display: grid; gap: 0.875rem; }
.announce-item-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  flex-wrap: wrap;
  margin-top: 0.5rem;
}

/* ── Fenêtres (<dialog>) ─────────────────────────────────────── */
dialog.modal {
  position: fixed;
  inset: 0;
  margin: auto;
  width: min(32rem, calc(100% - 1.5rem));
  max-width: none;
  max-height: calc(100dvh - 1.5rem);
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--text);
  overflow: visible;
}
dialog.modal.modal-wide { width: min(40rem, calc(100% - 1.5rem)); }
dialog.modal::backdrop { background: rgba(8, 14, 11, 0.6); backdrop-filter: blur(2px); animation: fade 0.18s ease both; }
/* Repli si <dialog> n'est pas géré : fond sombre simulé */
dialog.modal:not(:modal) { z-index: 100; box-shadow: 0 0 0 100vmax rgba(8, 14, 11, 0.6); }

.modal-card {
  display: flex;
  flex-direction: column;
  max-height: calc(100dvh - 1.5rem);
  overflow-y: auto;
  padding: 1.5rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  scrollbar-width: thin;
  animation: pop 0.18s ease both;
}
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 1.25rem;
}
.modal-header .icon-btn { margin: -0.5rem -0.5rem -0.5rem 0; }
.modal-title { font-size: 1.1875rem; font-weight: 700; letter-spacing: -0.015em; }
.confirm-text { color: var(--text-2); }

.modal-error {
  display: none;
  margin-top: 0.75rem;
  padding: 0.75rem 0.875rem;
  border-radius: var(--radius-sm);
  background: var(--danger-soft);
  color: var(--danger);
  font-size: 0.875rem;
  font-weight: 500;
}

.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0 1rem;
}
.form-grid .form-group.full { grid-column: 1 / -1; }

.app-tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(10.5rem, 1fr)); gap: 0.5rem; }
.app-tile {
  display: flex;
  align-items: center;
  gap: 0.625rem;
  min-height: 2.75rem;
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  font-size: 0.9375rem;
  cursor: pointer;
  transition: border-color var(--ease), background var(--ease);
}
.app-tile:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); }
.app-tile:has(input:disabled) { cursor: default; opacity: 0.8; }
.app-tile-name { min-width: 0; overflow-wrap: anywhere; font-weight: 500; }
.apps-hint { margin-top: 0.5rem; font-size: 0.8125rem; color: var(--text-3); }

.pw-tools { display: flex; flex-wrap: wrap; gap: 0.5rem; margin-top: 0.625rem; }

/* Jauge de robustesse */
.strength { margin-top: 0.5rem; }
.strength-bar { height: 0.375rem; border-radius: 999px; background: var(--surface-2); overflow: hidden; }
.strength-fill { height: 100%; width: 0; border-radius: 999px; background: var(--text-3); transition: width var(--ease), background var(--ease); }
.strength[data-level="weak"] .strength-fill { background: var(--danger); }
.strength[data-level="mid"]  .strength-fill { background: #d98a00; }
.strength[data-level="good"] .strength-fill { background: var(--accent); }
.strength-text { margin-top: 0.25rem; min-height: 1.25rem; font-size: 0.8125rem; color: var(--text-2); }
.match-hint.is-ok  { color: var(--accent); }
.match-hint.is-bad { color: var(--danger); }

.success-box {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.75rem;
  text-align: center;
  color: var(--accent);
}
.success-box p { color: var(--text); font-weight: 500; }
.success-box .btn-row { width: 100%; justify-content: center; }

.btn-row {
  display: flex;
  justify-content: flex-end;
  gap: 0.625rem;
  flex-wrap: wrap;
  margin-top: 1.5rem;
}
.btn-row .btn-danger { margin-right: auto; }

/* ── Recherche rapide ────────────────────────────────────────── */
.palette-input { margin-bottom: 0.75rem; }
.palette-list { max-height: min(22rem, 50dvh); overflow-y: auto; margin: 0 -0.5rem; padding: 0 0.5rem; }
.palette-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  min-height: 2.75rem;
  padding: 0.375rem 0.625rem;
  border-radius: var(--radius-sm);
  cursor: pointer;
}
.palette-item.is-active { background: var(--accent-soft); }
.palette-item.is-off .palette-label { color: var(--text-3); }
.palette-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.875rem;
  height: 1.875rem;
  border-radius: 9px;
  background: var(--surface-2);
  color: var(--text-2);
  font-size: 1rem;
  flex-shrink: 0;
}
.palette-item .palette-icon[style*="background"] { color: #ffffff; }
.palette-label { flex: 1; min-width: 0; font-size: 0.9375rem; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.palette-hint { max-width: 45%; font-size: 0.8125rem; color: var(--text-3); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.palette-empty { padding: 1.25rem; text-align: center; color: var(--text-2); }

/* ── Messages courts (toast) ─────────────────────────────────── */
.toast-box {
  position: fixed;
  left: 50%;
  bottom: 1.25rem;
  z-index: 200;
  display: grid;
  gap: 0.5rem;
  width: min(26rem, calc(100% - 1.5rem));
  transform: translateX(-50%);
  pointer-events: none;
}
.toast {
  padding: 0.75rem 1rem;
  border-radius: var(--radius);
  background: var(--text);
  color: var(--bg);
  font-size: 0.9375rem;
  font-weight: 500;
  box-shadow: var(--shadow-lg);
  animation: rise 0.2s ease both;
}
.toast-success { border-left: 4px solid #3ecf8e; }
.toast-error   { border-left: 4px solid #ff8478; }
.toast-warning { border-left: 4px solid #f0b254; }
.toast-out { opacity: 0; transition: opacity 0.25s ease; }

/* ── Petits écrans ───────────────────────────────────────────── */
@media (max-width: 760px) {
  .search-field { flex: 0 0 auto; width: 2.75rem; margin-left: auto; justify-content: center; padding: 0; }
  .search-field-text,
  .search-kbd { display: none; }
  .topbar-actions { margin-left: 0; }
  .user-chip-text,
  .user-chip-caret { display: none; }
}

@media (max-width: 640px) {
  .topbar-inner { padding: 0.5rem 0.875rem; gap: 0.5rem; }
  .page { padding: 1.5rem 1rem 2.5rem; }
  .brand-sub { display: none; }
  .apps-grid,
  .tools-grid { grid-template-columns: 1fr; }
  .form-grid { grid-template-columns: 1fr; }
  .btn-sm { min-height: 2.75rem; }
  .btn-row .btn { flex: 1 1 auto; }
  .btn-row .btn-danger { margin-right: 0; }
  .toolbar-select,
  #btn-new-user { flex: 1 1 100%; width: 100%; }
  .level-options { grid-template-columns: 1fr; }
  .tab { flex: 1; padding: 0 0.5rem; }
  .modal-card { padding: 1.125rem; }
  .login-card { padding: 1.25rem; }
  .menu { right: -0.25rem; max-width: calc(100vw - 1.5rem); }
  .topbar-actions .btn span { display: none; }
  .topbar-actions .btn { padding: 0 0.625rem; }
}
