:root {
  --bg: #f7f9fc;
  --surface: #ffffff;
  --border: #dde3ea;
  --text: #1a2028;
  --text-2: #5f6b7a;
  --text-3: #8893a1;
  --accent: #5b7cfa;
  --accent-h: #4766da;
  --accent-s: rgba(91, 124, 250, 0.1);
  --accent-b: rgba(91, 124, 250, 0.22);
  --danger: #d64545;
  --radius: 14px;
  --radius-sm: 10px;
  --shadow-sm: 0 1px 2px rgba(16, 24, 40, 0.04), 0 1px 1px rgba(16, 24, 40, 0.03);
  --shadow-md: 0 8px 20px rgba(16, 24, 40, 0.08);
}

* { box-sizing: border-box; }

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

body {
  margin: 0;
  font-family: -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

a { color: inherit; }

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

input[type="checkbox"] { accent-color: var(--accent); width: 16px; height: 16px; }

/* --- Structure ------------------------------------------------------------ */

.topbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 20px;
  padding: 12px 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}

.brand {
  font-weight: 800;
  font-size: 15px;
  color: var(--text);
  text-decoration: none;
  display: flex;
  align-items: center;
  gap: 8px;
  white-space: nowrap;
}
.brand img { width: 36px; height: 36px; border-radius: 10px; flex-shrink: 0; }

.menu-toggle {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  margin-left: auto;
  border: none;
  border-radius: var(--radius-sm);
  background: none;
  color: var(--text);
  cursor: pointer;
  flex-shrink: 0;
}
.menu-toggle:hover { background: var(--accent-s); color: var(--accent); }

.topbar-panel {
  display: none;
  flex-direction: column;
  gap: 4px;
  flex: 0 0 100%;
  order: 4;
  padding-top: 10px;
  margin-top: 10px;
  border-top: 1px solid var(--border);
}
.topbar-panel.open { display: flex; }

.topbar-panel nav { display: flex; flex-direction: column; gap: 2px; }
.topbar-panel nav a {
  color: var(--text-2);
  text-decoration: none;
  font-size: 14px;
  font-weight: 700;
  padding: 12px 10px;
  border-radius: var(--radius-sm);
  transition: 0.15s;
}
.topbar-panel nav a:hover { color: var(--accent); background: var(--accent-s); }

.logout-form {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding-top: 8px;
  margin-top: 4px;
  border-top: 1px solid var(--border);
}
.whoami { font-size: 13px; color: var(--text-2); font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

@media (min-width: 640px) {
  .topbar { padding: 14px 28px; }
  .brand { font-size: 16px; }
  .menu-toggle { display: none; }
  .topbar-panel {
    display: flex !important;
    flex-direction: row;
    align-items: center;
    flex: 1 1 auto;
    order: 0;
    padding-top: 0;
    margin-top: 0;
    border-top: none;
  }
  .topbar-panel nav { flex-direction: row; flex: 1; gap: 4px; }
  .topbar-panel nav a { padding: 8px 12px; border-radius: 999px; white-space: nowrap; }
  .logout-form { padding-top: 0; margin-top: 0; margin-left: auto; border-top: none; }
}

.content { max-width: 960px; margin: 0 auto; padding: 20px 16px 40px; }
@media (min-width: 640px) {
  .content { padding: 32px 24px 48px; }
}

h1 { font-size: 20px; font-weight: 800; margin: 0 0 16px; letter-spacing: -0.01em; }
h2 { font-size: 15px; font-weight: 800; margin: 0 0 14px; }
@media (min-width: 640px) {
  h1 { font-size: 22px; margin-bottom: 18px; }
}

/* --- Auth (login / attente) ------------------------------------------------ */

.auth-card {
  max-width: 380px;
  margin: 40px auto;
  padding: 28px 24px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  text-align: center;
}
@media (min-width: 640px) {
  .auth-card { margin: 64px auto; padding: 32px; }
}
.auth-logo { width: 88px; height: 88px; border-radius: 22px; margin-bottom: 16px; box-shadow: var(--shadow-sm); }
.subtitle { color: var(--text-2); font-size: 13px; margin-bottom: 18px; line-height: 1.6; }

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

.stack-form { display: flex; flex-direction: column; gap: 8px; text-align: left; }
.stack-form label { font-size: 12px; font-weight: 700; color: var(--text-2); margin-top: 6px; }
.stack-form input[type="text"],
.stack-form input[type="email"],
.stack-form input[type="password"],
.stack-form select {
  width: 100%;
  height: 44px;
  padding: 0 12px;
  border-radius: var(--radius-sm);
  border: 1.5px solid var(--border);
  font: inherit;
  font-size: 15px;
  background: var(--surface);
  transition: 0.15s;
}
.stack-form select { appearance: none; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='none' stroke='%238893A1' stroke-width='2' viewBox='0 0 24 24'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 12px center; padding-right: 34px; cursor: pointer; }
.stack-form input:focus, .stack-form select:focus { border-color: var(--accent); box-shadow: 0 0 0 4px var(--accent-s); }
.stack-form input.input-narrow { width: 76px; }
.checkbox-row { display: flex; align-items: center; gap: 8px; font-weight: 600; font-size: 13px; padding: 4px 0; }

.field-row { display: flex; flex-direction: row; justify-content: flex-start; align-items: flex-start; gap: 24px; flex-wrap: wrap; }
.field-row > div { display: flex; flex-direction: column; gap: 8px; align-items: center; }
.field-row .field-row-icon,
.field-row .field-row-logo { flex: 0 0 auto; }

/* Case partagee 64x64 : logo et icone sont deux instances de la meme classe de
   base, pour garantir qu'elles fassent exactement la meme taille (au lieu de
   viser une correspondance entre un <input> et un <div>, fragile a l'usage). */
.field-preview {
  width: 64px;
  height: 64px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-sm);
  border: 1.5px solid var(--border);
  background: var(--surface);
  overflow: hidden;
  box-sizing: border-box;
}
/* Le bouton Logo est un <label> (pour declencher le picker fichier au clic) et
   herite donc de ".stack-form label { margin-top: 6px }" comme n'importe quel
   label du formulaire. C'est ce qui decalait sa case vers le bas par rapport a
   celle de l'Icone (un simple <div>, jamais touche par cette regle). */
.stack-form label.field-preview { margin-top: 0; }
.stack-form input.icon-preview-input {
  width: 100%;
  height: 100%;
  border: none;
  border-radius: 0;
  background: transparent;
  text-align: center;
  font-size: 26px;
  padding: 0;
}
.stack-form input.icon-preview-input:focus { outline: none; border: none; box-shadow: inset 0 0 0 2px var(--accent-b); }

.tech-fields {
  display: flex;
  flex-direction: column;
  gap: 8px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 14px;
  margin: 4px 0;
}
.tech-fields-title {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-3);
  margin: 0;
}

/* --- Boutons ---------------------------------------------------------------- */

.btn-primary {
  display: flex;
  align-items: center;
  justify-content: center;
  margin-top: 12px;
  height: 44px;
  padding: 0 16px;
  border: none;
  border-radius: var(--radius-sm);
  background: var(--accent);
  color: #fff;
  font-weight: 700;
  font-size: 14px;
  cursor: pointer;
  text-decoration: none;
  box-sizing: border-box;
  transition: 0.15s;
}
.btn-primary:hover { background: var(--accent-h); }
.btn-primary:active { transform: scale(0.98); }
.btn-primary:disabled { background: var(--border); color: var(--text-2); cursor: default; transform: none; }

.btn-secondary {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 44px;
  padding: 0 16px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text-2);
  font-weight: 700;
  font-size: 14px;
  cursor: pointer;
  text-decoration: none;
  box-sizing: border-box;
  transition: 0.15s;
}
.btn-secondary:hover { border-color: var(--accent); color: var(--accent-h); background: var(--accent-s); }
.btn-secondary.danger { color: var(--danger); }
.btn-secondary.danger:hover { border-color: var(--danger); background: rgba(214, 69, 69, 0.06); }
.btn-sm { margin-top: 0; height: 34px; padding: 0 14px; font-size: 12px; }

.dropdown { position: relative; }
.dropdown-menu {
  display: none;
  flex-direction: column;
  gap: 2px;
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  min-width: 180px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-md);
  padding: 6px;
  z-index: 20;
}
.dropdown-menu.open { display: flex; }
.dropdown-menu a, .dropdown-menu button {
  display: block;
  width: 100%;
  text-align: left;
  padding: 9px 10px;
  border-radius: 8px;
  border: none;
  background: none;
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-2);
  text-decoration: none;
  cursor: pointer;
}
.dropdown-menu a:hover, .dropdown-menu button:hover { background: var(--accent-s); color: var(--accent-h); }
.dropdown-menu button.danger { color: var(--danger); }
.dropdown-menu button.danger:hover { background: rgba(214, 69, 69, 0.06); }

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

.btn-google {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  height: 46px;
  border-radius: var(--radius-sm);
  border: 1.5px solid rgba(215, 222, 230, 0.95);
  background: #fff;
  color: #1f1f1f;
  font-weight: 600;
  font-size: 14px;
  text-decoration: none;
  transition: 0.15s;
  box-shadow: var(--shadow-sm);
}
.btn-google:hover {
  border-color: rgba(91, 124, 250, 0.35);
  box-shadow: var(--shadow-md);
  transform: translateY(-1px);
}
.btn-google:active { transform: translateY(0); }
.btn-google svg { flex-shrink: 0; }

.link-btn {
  border: none;
  background: none;
  color: var(--text-2);
  cursor: pointer;
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  text-decoration: underline;
  padding: 6px 0;
}

/* --- Alertes / badges -------------------------------------------------------- */

.alert {
  background: rgba(214, 69, 69, 0.08);
  color: var(--danger);
  border: 1px solid rgba(214, 69, 69, 0.25);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  font-size: 13px;
  margin-bottom: 14px;
  text-align: left;
}

.badge {
  display: inline-block;
  font-size: 11px;
  font-weight: 700;
  color: var(--text-2);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 3px 9px;
  margin-top: 8px;
}
.badge-google {
  margin-top: 0;
  color: #1a73e8;
  background: rgba(66, 133, 244, 0.08);
  border-color: rgba(66, 133, 244, 0.25);
}
.badge-you { margin-top: 0; color: var(--accent-h); background: var(--accent-s); border-color: var(--accent-b); }
.app-card-badge { position: absolute; top: 12px; right: 12px; margin-top: 0; }
.app-card-badge.badge-public { color: var(--accent-h); background: var(--accent-s); border-color: var(--accent-b); }

.empty, .muted { color: var(--text-2); font-size: 13px; }

.loading-dots { display: inline-flex; gap: 3px; vertical-align: middle; margin-left: 2px; }
.loading-dots span {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: currentColor;
  opacity: 0.3;
  animation: loading-dot-pulse 1.2s infinite ease-in-out;
}
.loading-dots span:nth-child(2) { animation-delay: 0.2s; }
.loading-dots span:nth-child(3) { animation-delay: 0.4s; }
@keyframes loading-dot-pulse {
  0%, 80%, 100% { opacity: 0.3; transform: scale(0.8); }
  40% { opacity: 1; transform: scale(1); }
}
.hint {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  color: var(--accent-h);
  font-size: 12px;
  line-height: 1.55;
  background: var(--accent-s);
  border: 1px solid var(--accent-b);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  margin: 4px 0 12px;
}
.hint::before {
  content: "ⓘ";
  flex-shrink: 0;
  font-weight: 700;
  font-size: 13px;
  line-height: 1.4;
}

/* Version compacte du même langage visuel (icône + teinte accent), pour une
   précision sous un champ de formulaire plutôt qu'un paragraphe autonome. */
.field-hint {
  display: flex;
  align-items: flex-start;
  gap: 5px;
  color: var(--text-3);
  font-size: 11.5px;
  font-weight: 600;
  line-height: 1.5;
  margin: -2px 0 2px;
}
.field-hint::before {
  content: "ⓘ";
  color: var(--accent);
  flex-shrink: 0;
}

/* --- Champ fichier stylé ------------------------------------------------------ */

.file-field { display: flex; flex-direction: column; align-items: center; gap: 6px; }
.file-field-input {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}
.file-field-name { font-size: 12px; color: var(--text-3); overflow-wrap: anywhere; }
.app-row-icon { width: 22px; height: 22px; border-radius: 6px; object-fit: cover; vertical-align: middle; }

.logo-upload {
  position: relative;
  flex-shrink: 0;
  border-style: dashed;
  background-size: cover;
  background-position: center;
  color: var(--text-3);
  font-size: 26px;
  line-height: 1;
  cursor: pointer;
  transition: 0.15s;
}
.logo-upload:hover { border-color: var(--accent); color: var(--accent-h); }
.logo-upload.has-image { border-style: solid; }
.logo-upload.has-image .logo-upload-plus { display: none; }
.logo-upload-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(20, 24, 32, 0.6);
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  text-align: center;
  opacity: 0;
  transition: 0.15s;
}
.logo-upload.has-image:hover .logo-upload-overlay { opacity: 1; }

.logo-preview-wrap { position: relative; display: inline-flex; }
.logo-remove-btn {
  position: absolute;
  top: -6px;
  right: -6px;
  width: 20px;
  height: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-3);
  box-shadow: var(--shadow-sm);
  cursor: pointer;
  padding: 0;
  transition: 0.15s;
}
.logo-remove-btn:hover { border-color: var(--danger); color: var(--danger); }
.logo-remove-btn.active { background: var(--danger); border-color: var(--danger); color: #fff; }
.field-row-logo.pending-remove .logo-upload { opacity: 0.35; }

/* --- Panels / cartes ---------------------------------------------------------- */

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  padding: 18px;
  margin-bottom: 18px;
}
@media (min-width: 640px) {
  .panel { padding: 22px; margin-bottom: 20px; }
}

.dashed-divider { border: none; border-top: 1.5px dashed var(--border); margin: 4px 0 20px; }

.panel-pending { border-color: rgba(214, 69, 69, 0.3); background: rgba(214, 69, 69, 0.03); }

.panel-collapsible > summary {
  cursor: pointer;
  list-style: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.panel-collapsible > summary::-webkit-details-marker { display: none; }
.panel-collapsible > summary h2 { margin: 0; }
.panel-collapsible > summary::after {
  content: "+";
  flex-shrink: 0;
  font-size: 22px;
  font-weight: 400;
  line-height: 1;
  color: var(--accent);
  transition: transform 0.2s;
}
.panel-collapsible[open] > summary::after { transform: rotate(45deg); }
.panel-collapsible[open] > summary { margin-bottom: 16px; }
.panel-collapsible > summary:hover::after { color: var(--accent-h); }

.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 14px;
}
@media (min-width: 640px) {
  .card-grid { grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 16px; }
}

.app-card {
  position: relative;
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  padding: 20px;
  text-align: center;
  transition: 0.18s;
}
.app-card:has(a.btn-primary):hover { box-shadow: var(--shadow-md); transform: translateY(-2px); }
.app-icon-wrap { height: 56px; display: flex; align-items: center; justify-content: center; margin-bottom: 8px; }
.app-icon { font-size: 36px; line-height: 1; }
.app-icon-image { width: 56px; height: 56px; border-radius: 14px; object-fit: cover; }
@media (min-width: 640px) {
  .app-icon-wrap { height: 64px; }
  .app-icon { font-size: 40px; }
  .app-icon-image { width: 64px; height: 64px; border-radius: 16px; }
}
.app-card h2 {
  font-size: 15px;
  margin: 0 0 4px;
  min-height: 38px;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.app-card p {
  color: var(--text-2);
  font-size: 13px;
  line-height: 1.5;
  min-height: 39px;
  margin: 0;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.app-card .app-owner { color: var(--text-3); font-size: 11px; min-height: 16px; margin: 4px 0 0; font-style: italic; -webkit-line-clamp: 1; }
.app-card .btn-primary { display: flex; width: 100%; text-decoration: none; margin-top: 14px; }

/* --- Tables (desktop) / cartes empilées (mobile) ------------------------------ */

.admin-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.admin-table th, .admin-table td { text-align: left; padding: 10px 8px; border-bottom: 1px solid var(--border); }
.admin-table th { color: var(--text-2); font-size: 11px; text-transform: uppercase; letter-spacing: 0.04em; font-weight: 700; }
.row-actions { display: flex; gap: 14px; align-items: center; flex-wrap: wrap; }

.current-user-row td:first-child { border-left: 3px solid var(--accent); padding-left: 9px; }

@media (max-width: 639px) {
  .admin-table thead { display: none; }
  .admin-table, .admin-table tbody, .admin-table tr, .admin-table td { display: block; width: 100%; }
  .admin-table tr {
    margin-bottom: 12px;
    border: 1.5px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 4px 12px;
    background: var(--bg);
    box-shadow: var(--shadow-sm);
  }
  .admin-table tr:last-child { margin-bottom: 0; }
  .admin-table td {
    padding: 9px 0;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    border-bottom: 1px solid var(--border);
  }
  .admin-table td:last-child { border-bottom: none; }
  .admin-table td::before {
    content: attr(data-label);
    font-weight: 700;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--text-3);
    flex-shrink: 0;
  }
  .admin-table td.row-actions { justify-content: flex-start; }
  .admin-table td.row-actions::before { display: none; }
  .admin-table tr.current-user-row { border-color: var(--accent); background: var(--accent-s); }
  .current-user-row td:first-child { border-left: none; padding-left: 0; }
}

/* --- Accordéon (fiches app admin) --------------------------------------------- */

.app-row {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 4px 14px;
  margin-bottom: 8px;
  background: var(--surface);
}
.app-row summary {
  cursor: pointer;
  font-size: 14px;
  list-style: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 0;
}
.app-row summary::-webkit-details-marker { display: none; }
.app-row summary::after {
  content: "›";
  font-size: 20px;
  color: var(--text-3);
  transform: rotate(90deg);
  transition: transform 0.2s;
  flex-shrink: 0;
}
.app-row[open] summary::after { transform: rotate(-90deg); }
.app-row .stack-form { margin-top: 4px; padding-bottom: 14px; }
.app-row .row-actions { justify-content: space-between; margin-bottom: 14px; }

/* --- Liste d'accès ------------------------------------------------------------- */

.access-list { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 4px; }
.access-list li { padding: 6px 0; border-bottom: 1px solid var(--border); }
.access-list li:last-child { border-bottom: none; }
.inline-form { display: inline; }
