/* Atelier Favoris — feuille de style
   Système d'interface commun aux applis « Atelier » (docs/atelier-ui-memo.json) :
   tout passe par des variables ; les couleurs et formes viennent de themes.css. */

:root {
  --font-body: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  --radius-sm: 10px;
  --radius-md: 16px;
  --radius-lg: 20px;
  --radius-sheet: 20px 20px 0 0;
  --code-bg: #101826;
  --nav-h: 68px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg); color: var(--text);
  font: 400 13.5px/1.45 var(--font-body);
  -webkit-font-smoothing: antialiased;
}
[hidden] { display: none !important; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--accent); }
svg { width: 18px; height: 18px; flex-shrink: 0; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.muted { color: var(--text-muted); }
.small { font-size: 12px; }
.center { text-align: center; }

/* ---------- App shell : seule la zone .view défile */
#app {
  max-width: 480px; margin: 0 auto; position: relative;
  height: var(--app-height, 100dvh); display: flex; flex-direction: column; overflow: hidden;
  background: var(--bg);
}
.page:not(.on) { display: none; }
.view { flex: 1; min-height: 0; overflow-y: auto; padding: 12px 18px 84px; overscroll-behavior: contain; }

/* ---------- Barre du haut */
.topbar {
  flex: none; display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: calc(16px + env(safe-area-inset-top)) 18px 12px; background: var(--bg); border-bottom: 1px solid var(--border);
}
.app-name { font: 700 21px/1.15 var(--font-display); letter-spacing: -.01em; margin: 0; }
.app-sub {
  display: flex; align-items: center; gap: 6px; margin-top: 3px;
  font-size: 11px; color: var(--text-secondary); text-transform: uppercase; letter-spacing: .05em;
}
.logo-dot { color: var(--accent); display: inline-flex; }
.logo-dot svg { width: 14px; height: 14px; }

/* ---------- Barre du bas */
.bottomnav {
  flex: none; display: grid; grid-template-columns: repeat(4, 1fr);
  height: calc(var(--nav-h) + env(safe-area-inset-bottom)); padding-bottom: env(safe-area-inset-bottom);
  background: var(--card); border-top: var(--border-width) solid var(--border-strong);
}
.nav-item {
  border: 0; background: none; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px;
  color: var(--text-muted); font-size: 9.5px;
}
.nav-item svg { width: 19px; height: 19px; }
.nav-item.active { color: var(--accent); font-weight: 600; }

/* ---------- Titres d'écran */
.screen-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin: 4px 0 14px; min-height: 34px; }
.screen-title { font: 600 17px/1.25 var(--font-display); margin: 0; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.head-tools { display: flex; gap: 6px; flex: none; }
.kicker { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; color: var(--text-muted); margin: 18px 0 8px; }

/* ---------- Boutons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 42px; padding: 0 16px; border-radius: var(--radius-control);
  border: var(--border-width) solid var(--accent); background: transparent; color: var(--accent);
  font-size: 13.5px; font-weight: 600; text-decoration: none; white-space: nowrap;
}
.btn svg { width: 17px; height: 17px; }
.btn.solid { background: var(--accent); color: var(--accent-contrast); }
.btn.block { width: 100%; }
.btn.neutral { border-color: var(--border-strong); color: var(--text); background: var(--card); }
.btn.danger { border-color: var(--warning-text); color: var(--warning-text); }
.btn.wa { background: #25D366; border-color: #25D366; color: #06311A; }
.btn:disabled { opacity: .5; }
.btn-row { display: flex; gap: 8px; margin-top: 16px; }
.btn-row .btn { flex: 1; }

.icon-btn {
  width: 34px; height: 34px; border-radius: 50%; flex: none;
  display: inline-grid; place-items: center;
  background: var(--card); border: var(--border-width) solid var(--border-strong); color: var(--text-secondary);
}
.icon-btn.sm { width: 28px; height: 28px; }
.icon-btn.sm svg { width: 15px; height: 15px; }
.icon-btn.ghost { background: none; border-color: transparent; }
.icon-btn.on { color: var(--accent); border-color: var(--accent); }
.sort-btn {
  height: 34px; padding: 0 12px; border-radius: var(--radius-pill); display: inline-flex; align-items: center; gap: 5px;
  background: var(--card); border: var(--border-width) solid var(--border-strong); color: var(--text-secondary); font-size: 12px; font-weight: 600;
}
.sort-btn svg { width: 15px; height: 15px; }

/* ---------- Champs */
.field-label { display: block; font-size: 11px; color: var(--text-secondary); margin: 14px 0 5px; }
.input, .textarea, .picker {
  width: 100%; min-height: 40px; padding: 9px 12px; border-radius: var(--radius-control);
  border: var(--border-width) solid var(--border-strong); background: var(--card); color: var(--text); font-size: 13.5px; outline: none;
}
.textarea { resize: vertical; line-height: 1.5; }
.input:focus, .textarea:focus { border-color: var(--accent); }
.picker { display: flex; align-items: center; justify-content: space-between; gap: 8px; text-align: left; }
.picker svg { color: var(--text-muted); width: 16px; height: 16px; }
.inline-error {
  display: flex; gap: 6px; align-items: flex-start; background: var(--card-alt); color: var(--warning-text);
  font-size: 12px; padding: 8px 10px; border-radius: var(--radius-sm); margin: 10px 0 0;
}

/* ---------- Cartes, badges, puces */
.card { background: var(--card); border: var(--border-width) solid var(--border-strong); border-radius: var(--radius-card); padding: 16px; }
.badge { display: inline-block; font-size: 10px; font-weight: 600; padding: 3px 10px; border-radius: var(--radius-pill); background: var(--accent-soft-bg); color: var(--accent-soft-text); white-space: nowrap; }
.badge.alt { background: var(--accent2-soft-bg); color: var(--accent2-soft-text); }
.badge.warn { background: var(--warning-bg); color: var(--warning-text); }

.chips { display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none; margin: 0 -18px 12px; padding: 0 18px; }
.chips::-webkit-scrollbar { display: none; }
.chips:empty { display: none; }
.chips.wrap { flex-wrap: wrap; overflow: visible; }
.chip {
  flex: none; display: inline-flex; align-items: center; gap: 5px; height: 32px; padding: 0 13px;
  border-radius: var(--radius-pill); background: var(--card); border: var(--border-width) solid var(--border-strong);
  color: var(--text); font-size: 12px; white-space: nowrap;
}
.chip.active { background: var(--accent-soft-bg); color: var(--accent-soft-text); border-color: transparent; font-weight: 600; }
.chip small { color: var(--text-muted); font-size: 10.5px; }
.chip.active small { color: inherit; opacity: .75; }
.chip svg { width: 13px; height: 13px; }

/* ---------- Lignes de liste */
.list { display: flex; flex-direction: column; gap: 8px; }
.row {
  display: flex; align-items: center; gap: 12px; width: 100%; text-align: left;
  padding: 10px 12px; background: var(--card); border: var(--border-width) solid var(--border); border-radius: var(--radius-control);
  color: var(--text);
}
.row-thumb {
  width: 42px; height: 42px; border-radius: var(--radius-sm); flex: none; overflow: hidden;
  background: var(--card-alt); color: var(--text-muted); display: grid; place-items: center; font-size: 19px;
}
.row-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.row-thumb svg { width: 44%; height: 44%; }
.row-main { flex: 1; min-width: 0; }
.row-title { font-size: 13px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row-sub { font-size: 12px; color: var(--text-secondary); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; margin-top: 1px; }
.row-excerpt { font-size: 12px; color: var(--text-secondary); margin-top: 3px; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.row-side { flex: none; font-size: 11px; font-weight: 600; color: var(--text-secondary); text-align: right; display: flex; align-items: center; gap: 6px; }
.row-side svg { width: 16px; height: 16px; color: var(--text-muted); }
.row.indent { margin-left: 22px; width: calc(100% - 22px); }
.row .bad { color: var(--warning-text); }
mark { background: var(--accent-soft-bg); color: var(--accent-soft-text); border-radius: 3px; padding: 0 2px; }

/* Grille de cartes */
.list.grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.tile { display: flex; flex-direction: column; padding: 0; overflow: hidden; text-align: left; background: var(--card); border: var(--border-width) solid var(--border); border-radius: var(--radius-control); color: var(--text); }
.tile-img { aspect-ratio: 1; background: var(--card-alt); color: var(--text-muted); display: grid; place-items: center; overflow: hidden; }
.tile-img img { width: 100%; height: 100%; object-fit: cover; }
.tile-img svg { width: 40%; height: 40%; }
.tile-body { padding: 8px 10px 10px; }
.tile .row-title { white-space: normal; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }

.empty-state { text-align: center; padding: 40px 20px; color: var(--text-secondary); }
.empty-state strong { display: block; color: var(--text); font-size: 14px; margin-bottom: 4px; }
.more-wrap { text-align: center; padding: 14px 0; }

/* ---------- Réglages repliables */
.settings-cat { background: var(--card); border: var(--border-width) solid var(--border-strong); border-radius: var(--radius-card); margin-bottom: 10px; overflow: hidden; }
.settings-head { display: flex; align-items: center; gap: 10px; width: 100%; padding: 14px 16px; background: none; border: 0; text-align: left; color: var(--text); }
.settings-head .t { font-size: 14.5px; font-weight: 700; flex: none; }
.settings-head .s { flex: 1; min-width: 0; text-align: right; font-size: 12px; color: var(--text-muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.settings-head .chev { transition: transform .15s ease; color: var(--text-muted); }
.settings-cat.open .chev { transform: rotate(90deg); }
.settings-body { display: none; background: var(--card-alt); padding: 6px 12px 12px; }
.settings-cat.open .settings-body { display: block; }
.settings-cat.danger { border-color: var(--warning-text); }
.settings-cat.danger .settings-head .t { color: var(--warning-text); }
.set-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; width: 100%; padding: 11px 4px; background: none; border: 0; border-bottom: 1px solid var(--border); color: var(--text); text-align: left; font-size: 13.5px; }
.set-row:last-child { border-bottom: 0; }
.set-row .v { color: var(--text-muted); font-size: 12px; display: inline-flex; align-items: center; gap: 4px; }
.set-row .v svg { width: 15px; height: 15px; }
.hint { font-size: 11px; color: var(--text-muted); margin: 6px 4px 0; }

/* Sélecteur de thème : mini-aperçus dessinés en CSS */
.theme-list { display: flex; flex-direction: column; gap: 8px; }
.theme-opt { display: flex; align-items: center; gap: 12px; width: 100%; padding: 8px 10px; background: var(--card); border: var(--border-width) solid var(--border); border-radius: var(--radius-control); color: var(--text); text-align: left; }
.theme-opt.active { border-color: var(--accent); }
.theme-opt .name { flex: 1; font-size: 13px; font-weight: 600; }
.theme-opt .name small { display: block; font-weight: 400; color: var(--text-muted); font-size: 11px; }
.theme-opt .tick { width: 22px; height: 22px; border-radius: 50%; display: grid; place-items: center; background: var(--accent); color: var(--accent-contrast); }
.theme-opt .tick svg { width: 13px; height: 13px; }
.mini { width: 72px; height: 50px; border-radius: 8px; flex: none; position: relative; overflow: hidden; border: 1px solid rgba(0,0,0,.08); }
.mini i { position: absolute; display: block; }
.mini .t { left: 6px; top: 5px; width: 26px; height: 4px; border-radius: 2px; }
.mini .c { left: 6px; right: 6px; top: 13px; height: 20px; border-radius: 5px; }
.mini .th { left: 9px; top: 16px; width: 14px; height: 14px; border-radius: 3px; }
.mini .l1 { left: 27px; top: 18px; width: 28px; height: 3px; border-radius: 2px; }
.mini .l2 { left: 27px; top: 24px; width: 18px; height: 3px; border-radius: 2px; }
.mini .p { right: 9px; top: 19px; width: 9px; height: 7px; border-radius: 4px; }
.mini .n { left: 0; right: 0; bottom: 0; height: 9px; }
.mini .n::after { content: ''; position: absolute; left: 50%; top: 3px; width: 6px; height: 3px; margin-left: -3px; border-radius: 2px; background: var(--mini-accent); }

/* Segmenté (lecture / édition) */
.seg { display: inline-flex; background: var(--card-alt); border-radius: var(--radius-pill); padding: 3px; gap: 2px; }
.seg button { border: 0; background: none; height: 28px; padding: 0 12px; border-radius: var(--radius-pill); font-size: 12px; color: var(--text-secondary); }
.seg button.on { background: var(--card); color: var(--text); font-weight: 600; box-shadow: 0 1px 3px rgba(0,0,0,.12); }

/* ---------- Loupe */
.search-fab {
  position: absolute; right: 18px; bottom: calc(var(--nav-h) + env(safe-area-inset-bottom) + 14px); z-index: 15;
  width: 50px; height: 50px; border-radius: 50%; border: 0; background: var(--accent); color: var(--accent-contrast);
  display: grid; place-items: center; box-shadow: 0 8px 20px rgba(0,0,0,.25);
}
.search-fab svg { width: 22px; height: 22px; }
.search-overlay { position: absolute; inset: 0 0 calc(var(--nav-h) + env(safe-area-inset-bottom)) 0; z-index: 29; display: flex; flex-direction: column; justify-content: flex-end; padding: 0 12px 12px; gap: 10px; animation: rise .16s ease; }
.search-scrim { position: absolute; inset: 0; background: rgba(0,0,0,.25); }
.search-results {
  position: relative; max-height: 62%; overflow-y: auto; background: var(--bg); border-radius: var(--radius-card);
  border: var(--border-width) solid var(--border-strong); padding: 6px 12px 12px; box-shadow: 0 12px 30px rgba(0,0,0,.22);
}
.search-results:empty { display: none; }
.search-results .kicker { margin: 10px 2px 6px; }
.search-bar {
  position: relative; z-index: 30; display: flex; align-items: center; gap: 8px; height: 50px; padding: 0 8px 0 16px;
  border-radius: var(--radius-pill); background: var(--card); border: 1.5px solid var(--accent); box-shadow: 0 12px 30px rgba(0,0,0,.22); color: var(--accent);
}
.search-bar input { flex: 1; min-width: 0; border: 0; outline: none; background: none; color: var(--text); font-size: 15px; }
.search-bar input::-webkit-search-cancel-button { display: none; }

/* ---------- Fiche détaillée (écran plein dans la colonne) */
.detail { position: absolute; inset: 0; z-index: 40; background: var(--bg); display: flex; flex-direction: column; animation: rise .16s ease; }
.detail-bar { flex: none; display: flex; align-items: center; gap: 8px; padding: calc(12px + env(safe-area-inset-top)) 14px 10px; border-bottom: 1px solid var(--border); }
.detail-bar .grow { flex: 1; font-size: 11px; color: var(--text-muted); text-align: right; padding-right: 4px; }
.detail-body { flex: 1; min-height: 0; overflow-y: auto; padding: 14px 18px calc(40px + env(safe-area-inset-bottom)); }
.hero { width: 100%; max-height: 240px; object-fit: cover; border-radius: var(--radius-card); display: block; margin-bottom: 14px; background: var(--card-alt); box-shadow: 0 8px 18px rgba(0,0,0,.18); }
.video { position: relative; padding-top: 56.25%; border-radius: var(--radius-card); overflow: hidden; margin-bottom: 14px; background: #000; }
.video iframe { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; }
.title-input { width: 100%; border: 0; background: none; color: var(--text); font: 700 20px/1.25 var(--font-display); padding: 2px 0; resize: none; overflow: hidden; outline: none; }
.url-pill { display: inline-flex; align-items: center; gap: 6px; max-width: 100%; margin: 6px 0 2px; padding: 5px 12px; border-radius: var(--radius-pill); background: var(--card); border: 1px solid var(--border-strong); font-size: 12px; color: var(--text-secondary); text-decoration: none; }
.url-pill span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.url-pill svg { width: 13px; height: 13px; color: var(--accent); }
.section-row { display: flex; align-items: center; justify-content: space-between; margin: 18px 0 8px; }
.section-row .kicker { margin: 0; }
.fmt-tools { display: flex; flex-wrap: wrap; gap: 4px; margin-bottom: 6px; }
.fmt-tools button { height: 30px; min-width: 32px; padding: 0 8px; border-radius: var(--radius-sm); border: 1px solid var(--border-strong); background: var(--card); color: var(--text-secondary); font-size: 12px; }
.note-src { min-height: 240px; font-family: var(--mono); font-size: 12.5px; }
.dates { color: var(--text-muted); font-size: 11px; margin-top: 18px; }
details.page-text { margin-top: 16px; }
details.page-text summary { cursor: pointer; font-size: 12px; color: var(--text-secondary); }
details.page-text div { white-space: pre-wrap; font-size: 12.5px; max-height: 50vh; overflow: auto; margin-top: 8px; padding: 12px; background: var(--card-alt); border-radius: var(--radius-sm); }

/* Tags dans un champ */
.tags-input { display: flex; flex-wrap: wrap; gap: 5px; align-items: center; min-height: 40px; padding: 5px 8px; border-radius: var(--radius-control); border: var(--border-width) solid var(--border-strong); background: var(--card); }
.tags-input:focus-within { border-color: var(--accent); }
.tags-input input { flex: 1; min-width: 110px; border: 0; outline: none; background: none; padding: 4px; font-size: 13.5px; }
.tags-input .badge { display: inline-flex; align-items: center; gap: 4px; font-size: 11px; }
.tags-input .badge button { border: 0; background: none; padding: 0; color: inherit; line-height: 1; font-size: 13px; }

/* Markdown */
.md { font-size: 13.5px; line-height: 1.6; overflow-wrap: anywhere; }
.md h1, .md h2, .md h3 { font-family: var(--font-display); line-height: 1.3; margin: 1.1em 0 .4em; }
.md h1 { font-size: 17px; } .md h2 { font-size: 15.5px; } .md h3 { font-size: 14px; }
.md > :first-child { margin-top: 0; }
.md ul, .md ol { padding-left: 1.3em; }
.md li:has(> input[type=checkbox]) { list-style: none; margin-left: -1.3em; }
.md input[type=checkbox] { width: 18px; height: 18px; vertical-align: -4px; margin-right: 7px; accent-color: var(--accent); }
.md blockquote { margin: .8em 0; padding: 8px 12px; background: var(--warning-bg); color: var(--warning-text); border-radius: var(--radius-sm); }
.md blockquote p { margin: 0; }
.md img { max-width: 100%; border-radius: var(--radius-sm); }
.md :not(pre) > code { font-family: var(--mono); font-size: .88em; background: var(--card-alt); padding: .1em .35em; border-radius: 4px; }
.code-wrap { position: relative; margin: .8em 0; }
.code-wrap pre { margin: 0; background: var(--code-bg); color: #DDE6EE; border-radius: var(--radius-sm); padding: 14px; overflow: auto; font-family: var(--mono); font-size: 12px; line-height: 1.5; }
.code-wrap pre code.hljs { background: none; padding: 0; }
.copy-btn { position: absolute; top: 6px; right: 6px; height: 26px; padding: 0 10px; border-radius: var(--radius-pill); border: 0; background: rgba(255,255,255,.15); color: #fff; font-size: 11px; font-weight: 600; }
.copy-btn.ok { background: var(--accent); color: var(--accent-contrast); }

/* ---------- Fenêtres du bas */
.modal-overlay { position: absolute; inset: 0; z-index: 50; background: rgba(0,0,0,.45); display: flex; align-items: flex-end; animation: fade .2s ease; }
.modal-sheet {
  width: 100%; max-height: 88%; overflow-y: auto; background: var(--bg); border-radius: var(--radius-sheet);
  padding: 8px 18px calc(18px + env(safe-area-inset-bottom)); animation: rise .16s ease;
}
.modal-sheet::before { content: ''; display: block; width: 38px; height: 4px; border-radius: 2px; background: var(--border-strong); margin: 2px auto 12px; }
.sheet-title { font: 700 17px/1.3 var(--font-display); margin: 0 0 4px; }
.sheet-sub { font-size: 12px; color: var(--text-secondary); margin: 0 0 8px; }
.pick-list { display: flex; flex-direction: column; gap: 6px; margin-top: 8px; }
.pick-item { display: flex; align-items: center; gap: 10px; width: 100%; padding: 11px 12px; text-align: left; background: var(--card); border: var(--border-width) solid var(--border); border-radius: var(--radius-control); color: var(--text); font-size: 13px; }
.pick-item .d { display: block; font-size: 12px; color: var(--text-secondary); }
.pick-item.active { border-color: var(--accent); color: var(--accent-soft-text); background: var(--accent-soft-bg); font-weight: 600; }
.pick-item svg { color: var(--text-secondary); }
.pick-item.danger { color: var(--warning-text); }
.pick-item.danger svg { color: var(--warning-text); }
.preview-box { display: grid; grid-template-columns: 48px 1fr; gap: 10px; align-items: center; margin-top: 10px; padding: 8px; background: var(--card-alt); border-radius: var(--radius-sm); }
.preview-box:empty { display: none; }
.preview-box img, .preview-box .ph { width: 48px; height: 48px; border-radius: 8px; object-fit: cover; background: var(--card); }
.preview-box strong { font-size: 12.5px; display: block; }
.preview-box .d { font-size: 11.5px; color: var(--text-secondary); overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }

/* ---------- Connexion */
.login { flex: 1; display: grid; place-items: center; padding: 18px; }
.login-card { width: 100%; text-align: center; }
.login-card img { border-radius: 16px; }
.login-card .app-name { margin: 10px 0 4px; }
.login-card .field-label, .login-card .input { text-align: left; }
.login-card .btn { margin-top: 14px; }

/* ---------- Divers */
.toast {
  position: absolute; left: 50%; transform: translateX(-50%); z-index: 60;
  bottom: calc(var(--nav-h) + env(safe-area-inset-bottom) + 76px);
  max-width: calc(100% - 36px); background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: var(--radius-control);
  font-size: 13px; display: flex; gap: 12px; align-items: center; box-shadow: 0 12px 30px rgba(0,0,0,.22);
}
.toast button { border: 0; background: none; color: var(--accent-soft-bg); font-weight: 700; }

@keyframes rise { from { opacity: 0; transform: translateY(16px); } to { opacity: 1; transform: none; } }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }

/* Grand écran : la colonne reste centrée, avec un léger contour */
@media (min-width: 560px) {
  body { background: var(--card-alt); }
  #app { border-left: 1px solid var(--border); border-right: 1px solid var(--border); }
}
