/* ==========================================================
   AGM-TECH — Portail
   ========================================================== */

:root {
  --bg: #f4f6fa;
  --surface: #ffffff;
  --surface-2: #eef1f6;
  --border: #dde2ea;
  --border-strong: #c5ccd8;
  --text: #16202f;
  --text-2: #4d5b70;
  --text-3: #7a879a;
  --accent: #1f5fd6;
  --accent-hover: #184fb5;
  --accent-soft: #e3ecfc;
  --accent-text: #174aa8;
  --on-accent: #ffffff;
  --danger: #c43d3d;
  --danger-soft: #fbe9e9;
  --success-soft: #e5f4ea;
  --success-text: #1f6a3a;
  --admin-soft: #eee9fb;
  --admin-text: #5a3fb0;
  --tile-hover: #f7f9fc;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
  --radius: 10px;
  --radius-lg: 14px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color-scheme: light;
}

:root[data-theme="dark"] {
  --bg: #0f1420;
  --surface: #171e2c;
  --surface-2: #1f2838;
  --border: #2a3446;
  --border-strong: #3a465c;
  --text: #e8edf5;
  --text-2: #aab5c6;
  --text-3: #7f8ba0;
  --accent: #5b8ff0;
  --accent-hover: #7aa5f5;
  --accent-soft: #1d2d4d;
  --accent-text: #a9c4fa;
  --on-accent: #0b1220;
  --danger: #f07777;
  --danger-soft: #3a1f24;
  --success-soft: #16322a;
  --success-text: #8fd9aa;
  --admin-soft: #2a2347;
  --admin-text: #c7b8f7;
  --tile-hover: #1c2433;
  --shadow: none;
  color-scheme: dark;
}

@media (prefers-color-scheme: dark) {
  :root[data-theme="auto"] {
    --bg: #0f1420;
    --surface: #171e2c;
    --surface-2: #1f2838;
    --border: #2a3446;
    --border-strong: #3a465c;
    --text: #e8edf5;
    --text-2: #aab5c6;
    --text-3: #7f8ba0;
    --accent: #5b8ff0;
    --accent-hover: #7aa5f5;
    --accent-soft: #1d2d4d;
    --accent-text: #a9c4fa;
    --on-accent: #0b1220;
    --danger: #f07777;
    --danger-soft: #3a1f24;
    --success-soft: #16322a;
    --success-text: #8fd9aa;
    --admin-soft: #2a2347;
    --admin-text: #c7b8f7;
    --tile-hover: #1c2433;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html { -webkit-text-size-adjust: 100%; scroll-padding-top: 72px; }

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 var(--font);
  padding-bottom: env(safe-area-inset-bottom);
}

a { color: var(--accent-text); }
h1 { font-size: 24px; font-weight: 650; margin: 8px 0 16px; }
h2 { font-size: 17px; font-weight: 650; margin: 0; }
h3 { font-size: 13px; font-weight: 600; margin: 0 0 8px; color: var(--text-2); text-transform: uppercase; letter-spacing: .04em; }
p { margin: 0 0 12px; }
code { font-size: 13px; background: var(--surface-2); padding: 1px 5px; border-radius: 5px; }
.muted { color: var(--text-2); }
.small { font-size: 13px; }
.i { flex: none; display: block; }

/* ===================== Barre du haut ===================== */
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px max(16px, env(safe-area-inset-right)) 10px max(16px, env(safe-area-inset-left));
  padding-top: max(10px, env(safe-area-inset-top));
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: saturate(1.4) blur(10px);
  -webkit-backdrop-filter: saturate(1.4) blur(10px);
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; color: var(--text); font-weight: 650; font-size: 16px; }
.brand img { border-radius: 8px; }
.topbar-actions { margin-left: auto; display: flex; align-items: center; gap: 4px; }

.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 38px; height: 38px; border-radius: 10px;
  border: 0; background: transparent; color: var(--text-2);
  cursor: pointer; text-decoration: none;
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); }
.icon-btn.small { width: 30px; height: 30px; border-radius: 8px; }
.icon-btn.danger:hover { color: var(--danger); background: var(--danger-soft); }

.when-dark { display: none; }
:root[data-theme="dark"] .when-dark { display: contents; }
:root[data-theme="dark"] .when-light { display: none; }
@media (prefers-color-scheme: dark) {
  :root[data-theme="auto"] .when-dark { display: contents; }
  :root[data-theme="auto"] .when-light { display: none; }
}

.avatar {
  display: inline-flex; align-items: center; justify-content: center;
  width: 34px; height: 34px; border-radius: 50%;
  background: var(--accent-soft); color: var(--accent-text);
  font-weight: 650; font-size: 14px; cursor: pointer; list-style: none; flex: none;
}
.avatar::-webkit-details-marker { display: none; }
.avatar.static { cursor: default; }

.user-menu { position: relative; margin-left: 4px; }
.user-menu-panel {
  position: absolute; right: 0; top: calc(100% + 8px); min-width: 220px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg);
  box-shadow: 0 10px 30px rgba(0, 0, 0, .15); padding: 12px; z-index: 30;
}
.user-menu-panel p { margin: 0; }
.user-menu-name { font-weight: 600; }
.user-menu-panel a, .user-menu-panel button {
  display: flex; align-items: center; gap: 10px; width: 100%;
  margin-top: 6px; padding: 8px 10px; border-radius: 8px;
  color: var(--text); text-decoration: none; font: inherit;
  background: none; border: 0; cursor: pointer; text-align: left;
}
.user-menu-panel a:first-of-type { margin-top: 12px; }
.user-menu-panel a:hover, .user-menu-panel button:hover { background: var(--surface-2); }

/* ===================== Messages ===================== */
.flashes { max-width: 1180px; margin: 12px auto 0; padding: 0 16px; }
.flash { margin: 0 0 8px; padding: 10px 14px; border-radius: var(--radius); background: var(--surface-2); border: 1px solid var(--border); }
.flash-success { background: var(--success-soft); color: var(--success-text); border-color: transparent; }
.flash-error { background: var(--danger-soft); color: var(--danger); border-color: transparent; }

.preview-banner {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  margin-top: 12px; padding: 10px 14px;
  border-radius: var(--radius); background: var(--admin-soft); color: var(--admin-text);
}
.preview-banner a { margin-left: auto; color: inherit; font-weight: 600; }

/* ===================== Accueil ===================== */
.portal { max-width: 1180px; margin: 0 auto; padding: 0 16px 48px; }

.hero { text-align: center; padding: 36px 0 20px; }
.clock { font-size: 56px; font-weight: 300; letter-spacing: .02em; line-height: 1.1; margin: 0; font-variant-numeric: tabular-nums; }
.date { color: var(--text-2); margin: 4px 0 24px; }

.search {
  position: relative; max-width: 620px; margin: 0 auto;
  display: flex; align-items: center;
  background: var(--surface); border: 1px solid var(--border); border-radius: 999px;
  box-shadow: var(--shadow); padding: 0 18px; gap: 10px; color: var(--text-3);
}
.search:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.search input[type="search"] {
  flex: 1; min-width: 0; height: 50px; padding: 0; border: 0; border-radius: 0; outline: 0; box-shadow: none;
  background: transparent; color: var(--text); font: inherit; font-size: 16px;
}
.search input::-webkit-search-cancel-button { cursor: pointer; }
.search-hint { min-height: 22px; margin: 8px 0 0; font-size: 13px; color: var(--text-3); }
.search-hint strong { color: var(--text-2); }

.chips {
  position: sticky; top: 58px; z-index: 10;
  display: flex; gap: 8px; overflow-x: auto; scrollbar-width: none;
  padding: 10px 0; margin-bottom: 8px; background: var(--bg);
}
.chips::-webkit-scrollbar { display: none; }
.chips a {
  flex: none; padding: 6px 12px; border-radius: 999px;
  background: var(--surface); border: 1px solid var(--border);
  color: var(--text-2); text-decoration: none; font-size: 14px; white-space: nowrap;
}
.chips a:hover { color: var(--text); border-color: var(--border-strong); }
.chips a span { color: var(--text-3); font-size: 12px; margin-left: 2px; }
body.searching .chips { display: none; }

.space { margin-top: 28px; }
.space-head { display: flex; align-items: center; gap: 12px; margin-bottom: 12px; }
.space-head h2 { display: flex; align-items: center; gap: 8px; }
.count { color: var(--text-3); font-weight: 500; font-size: 13px; }
.category { margin-bottom: 18px; }

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 10px; }

.tile-wrap { position: relative; min-width: 0; }
.tile {
  display: flex; align-items: center; gap: 12px; width: 100%; min-width: 0;
  padding: 10px 12px; border-radius: var(--radius);
  background: var(--surface); border: 1px solid var(--border); box-shadow: var(--shadow);
  color: var(--text); text-decoration: none; font: inherit; text-align: left; cursor: pointer;
  transition: border-color .15s, background .15s, transform .15s;
}
.tile:hover { border-color: var(--border-strong); background: var(--tile-hover); }
.tile:active { transform: scale(.98); }
.tile:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.tile-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 14px; }

.tile-icon {
  --hue: 215;
  flex: none; display: inline-flex; align-items: center; justify-content: center;
  width: 38px; height: 38px; border-radius: 10px; overflow: hidden;
  background: var(--tile-bg, var(--surface-2));
}
.tile-icon img { width: 28px; height: 28px; object-fit: contain; }
.tile-icon .letter {
  width: 100%; height: 100%; display: flex; align-items: center; justify-content: center;
  background: hsl(var(--hue) 65% 92%); color: hsl(var(--hue) 55% 32%); font-weight: 650; font-size: 17px;
}
:root[data-theme="dark"] .tile-icon .letter { background: hsl(var(--hue) 35% 24%); color: hsl(var(--hue) 70% 82%); }
@media (prefers-color-scheme: dark) {
  :root[data-theme="auto"] .tile-icon .letter { background: hsl(var(--hue) 35% 24%); color: hsl(var(--hue) 70% 82%); }
}
.tile-icon.small { width: 30px; height: 30px; border-radius: 8px; }
.tile-icon.small img { width: 22px; height: 22px; }
.tile-emoji { color: #fff; font-size: 20px; font-weight: 650; }

.badge {
  flex: none; font-size: 11px; line-height: 1; padding: 4px 7px; border-radius: 6px;
  background: var(--surface-2); color: var(--text-2); border: 1px solid var(--border);
}

.tile-add { border-style: dashed; box-shadow: none; background: transparent; color: var(--text-2); }
.tile-add .tile-icon { background: transparent; color: var(--text-3); }

.tile-tools { display: none; position: absolute; top: 6px; right: 6px; gap: 2px; background: var(--surface); border-radius: 8px; }
.tile-tools form { margin: 0; }
body.editing-shortcuts #raccourcis .tile-tools { display: flex; }
body.editing-shortcuts #raccourcis .tile-wrap .tile { border-style: dashed; }

.link-btn {
  display: inline-flex; align-items: center; gap: 4px;
  background: none; border: 0; padding: 4px 6px; margin-left: auto;
  color: var(--accent-text); font: inherit; font-size: 14px; cursor: pointer; text-decoration: none; border-radius: 6px;
}
.link-btn:hover { background: var(--accent-soft); }
.link-btn.danger { color: var(--danger); }
.link-btn.danger:hover { background: var(--danger-soft); }

.empty { text-align: center; color: var(--text-2); padding: 32px 0; }
.footer-note { text-align: center; color: var(--text-3); font-size: 13px; margin-top: 40px; }
.footer-note a { color: var(--text-2); }

/* Téléphone : grille d'icônes comme un écran d'accueil */
@media (max-width: 600px) {
  .hero { padding: 20px 0 12px; }
  .clock { font-size: 40px; }
  .date { margin-bottom: 16px; }
  .chips { top: 56px; }
  .grid { grid-template-columns: repeat(auto-fill, minmax(76px, 1fr)); gap: 8px 4px; }
  .tile {
    flex-direction: column; gap: 6px; padding: 8px 2px;
    background: transparent; border-color: transparent; box-shadow: none; text-align: center;
  }
  .tile:hover { background: transparent; border-color: transparent; }
  .tile-icon { width: 54px; height: 54px; border-radius: 14px; background: var(--tile-bg, var(--surface)); box-shadow: var(--shadow); border: 1px solid var(--border); }
  .tile-icon img { width: 34px; height: 34px; }
  .tile-name { width: 100%; font-size: 12px; line-height: 1.25; white-space: normal; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
  .tile .badge { position: absolute; top: 2px; right: 6px; padding: 2px 5px; font-size: 10px; }
  .tile-add .tile-icon { border-style: dashed; box-shadow: none; background: transparent; }
  body.editing-shortcuts #raccourcis .tile-wrap .tile { border-style: dashed; border-color: var(--border-strong); }
  .tile-tools { top: -4px; right: -2px; box-shadow: var(--shadow); }
  h3 { font-size: 12px; }
}

/* ===================== Pages ===================== */
.page { max-width: 1000px; margin: 0 auto; padding: 16px 16px 48px; }
.page.narrow, .narrow { max-width: 620px; }
.card.narrow { margin: 0; }
.back { display: inline-flex; align-items: center; gap: 6px; color: var(--text-2); text-decoration: none; font-size: 14px; margin-top: 8px; }
.back:hover { color: var(--text); }

.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg);
  box-shadow: var(--shadow); padding: 18px 20px; margin-bottom: 16px;
}
.card h2 { margin-bottom: 14px; }
.card-footer { display: flex; align-items: flex-end; gap: 12px; flex-wrap: wrap; margin-top: 14px; padding-top: 14px; border-top: 1px solid var(--border); }
.card-footer > form:first-child { flex: 1; }

.page-center main { max-width: 400px; margin: 0 auto; }
.page-center { display: flex; align-items: center; justify-content: center; padding: 16px; }
.page-center .flashes { position: fixed; top: max(12px, env(safe-area-inset-top)); left: 0; right: 0; max-width: 432px; }
.auth-card { width: 100%; text-align: center; padding: 32px 24px; }
.auth-card .form { text-align: left; margin-top: 20px; }
.auth-logo { margin: 0 auto 8px; display: block; }
.offline-icon { display: inline-flex; color: var(--text-3); margin-bottom: 8px; }

.passkey-login { margin-top: 20px; text-align: left; }
.divider { display: flex; align-items: center; gap: 12px; margin: 20px 0 0; color: var(--text-3); font-size: 13px; }
.divider::before, .divider::after { content: ""; flex: 1; border-top: 1px solid var(--border); }
.form-error { margin: 10px 0 0; padding: 8px 12px; border-radius: var(--radius); background: var(--danger-soft); color: var(--danger); font-size: 14px; text-align: left; }
.passkey-list { margin-bottom: 14px; }
.passkey-list .tile-icon { color: var(--text-2); }
.passkey-rename label { gap: 4px; }
.passkey-add { margin-top: 4px; }

.facts { display: grid; grid-template-columns: max-content 1fr; gap: 6px 16px; margin: 0; }
.facts dt { color: var(--text-2); }
.facts dd { margin: 0; }

/* ===================== Formulaires ===================== */
.form { display: flex; flex-direction: column; gap: 14px; }
label, legend { display: flex; flex-direction: column; gap: 6px; font-size: 14px; font-weight: 550; color: var(--text); }
fieldset { border: 0; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 8px; }
legend { margin-bottom: 8px; padding: 0; }
label.radio, label.checkbox { flex-direction: row; align-items: center; gap: 10px; font-weight: 400; }
.hint { font-weight: 400; font-size: 13px; color: var(--text-2); }

input[type="text"], input[type="password"], input[type="number"], input[type="search"], select {
  width: 100%; height: 42px; padding: 0 12px;
  border: 1px solid var(--border-strong); border-radius: var(--radius);
  background: var(--surface); color: var(--text); font: inherit; font-size: 16px; font-weight: 400;
}
input:focus, select:focus { outline: 0; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
input[type="color"] { width: 100%; height: 42px; padding: 3px; border: 1px solid var(--border-strong); border-radius: var(--radius); background: var(--surface); }
input[type="radio"], input[type="checkbox"] { width: 18px; height: 18px; accent-color: var(--accent); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 42px; padding: 0 16px; border-radius: var(--radius);
  border: 1px solid var(--border-strong); background: var(--surface); color: var(--text);
  font: inherit; font-weight: 550; cursor: pointer; text-decoration: none; white-space: nowrap;
}
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.btn.primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn.danger { color: var(--danger); border-color: var(--danger); background: transparent; }
.btn.danger:hover { background: var(--danger-soft); }
.btn.block { width: 100%; }

.form-actions, .dialog-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 6px; }
.danger-zone { margin-top: 20px; padding-top: 16px; border-top: 1px solid var(--border); }
.row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

.inline-form { display: flex; align-items: flex-end; gap: 10px; flex-wrap: wrap; flex: 1; margin: 0; }
.inline-form .grow { flex: 1 1 200px; }
.inline-form .narrow-field { width: 100px; }
.grow { flex: 1; }

.icon-preview { display: flex; align-items: center; gap: 10px; color: var(--text-2); font-size: 14px; margin: 0; }

/* ===================== Dialogue ===================== */
.dialog {
  width: min(460px, calc(100vw - 32px)); padding: 22px; border: 1px solid var(--border);
  border-radius: var(--radius-lg); background: var(--surface); color: var(--text);
}
.dialog::backdrop { background: rgba(10, 15, 25, .45); }
.dialog form { display: flex; flex-direction: column; gap: 14px; }

/* ===================== Gestion ===================== */
.tabs { display: flex; gap: 4px; overflow-x: auto; border-bottom: 1px solid var(--border); margin-bottom: 20px; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tabs a {
  display: inline-flex; align-items: center; gap: 8px; flex: none;
  padding: 10px 12px; color: var(--text-2); text-decoration: none; font-size: 14px;
  border-bottom: 2px solid transparent; margin-bottom: -1px;
}
.tabs a:hover { color: var(--text); }
.tabs a[aria-current="page"] { color: var(--accent-text); border-bottom-color: var(--accent); font-weight: 600; }

.toolbar { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; margin-bottom: 12px; }
.toolbar input[type="search"] { flex: 1 1 240px; width: auto; }
.toolbar p { margin: 0; }

.admin-space { margin-bottom: 28px; }
.admin-space > h2 { margin-bottom: 12px; }
.admin-category { margin-bottom: 16px; scroll-margin-top: 80px; }
.admin-category-head { display: flex; align-items: center; gap: 8px; }

.rows { list-style: none; margin: 0; padding: 0; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); overflow: hidden; }
.card .rows, .rows.card { border: 0; border-radius: 0; box-shadow: none; }
.rows.card { border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 0; }
.row-item { display: flex; align-items: center; gap: 12px; padding: 10px 14px; border-top: 1px solid var(--border); }
.row-item:first-child { border-top: 0; }
.row-item form { margin: 0; }
.row-main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.row-title { color: var(--text); font-weight: 550; text-decoration: none; }
.row-title:hover { color: var(--accent-text); }
.row-sub { color: var(--text-3); font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.card > .rows > .row-item { padding-inline: 0; }

.pill {
  display: inline-flex; align-items: center; gap: 4px; flex: none;
  font: inherit; font-size: 12px; font-weight: 600; line-height: 1; padding: 6px 9px; border-radius: 999px;
  border: 0; cursor: pointer;
}
span.pill { cursor: default; }
.pill-all { background: var(--success-soft); color: var(--success-text); }
.pill-admin { background: var(--admin-soft); color: var(--admin-text); }

@media (max-width: 600px) {
  .row-item { flex-wrap: wrap; }
  .row-main { flex-basis: calc(100% - 60px); }
  .inline-form .narrow-field { width: 90px; }
  .row { grid-template-columns: 1fr; }
}
