/* MyNotes : feuille de style. Mobile d'abord, trois volets sur grand écran, thème clair/sombre automatique. */

:root {
  --bg: #f6f7f9;
  --bg-elev: #ffffff;
  --bg-sunken: #eceef2;
  --fg: #101828;
  --fg-muted: #667085;
  --border: #e4e7ec;
  --accent: #1d4ed8;
  --accent-fg: #ffffff;
  --accent-soft: #e8efff;
  --danger: #b42318;
  --danger-soft: #fee4e2;
  --ok: #12b76a;
  --warn: #f79009;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .1);
  --radius: 10px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b1220;
    --bg-elev: #111a2b;
    --bg-sunken: #0e1626;
    --fg: #e6eaf2;
    --fg-muted: #94a3b8;
    --border: #23304a;
    --accent: #5b8def;
    --accent-fg: #0b1220;
    --accent-soft: #172a52;
    --danger: #f97066;
    --danger-soft: #3b1512;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4);
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: var(--font);
  font-size: 16px; /* 16px minimum : évite le zoom automatique d'iOS sur les champs */
  color: var(--fg);
  background: var(--bg);
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}
#app { height: 100%; }
.hidden { display: none !important; }
.muted { color: var(--fg-muted); }
.small { font-size: 13px; }
.center { text-align: center; }
.error { color: var(--danger); font-size: 14px; margin: 4px 0 8px; }
a { color: var(--accent); }
h1, h2, h3 { margin: 0 0 8px; }
h1 { font-size: 22px; }
h2 { font-size: 20px; }
p { margin: 0 0 12px; line-height: 1.45; }

/* ---------- écrans centrés ---------- */
.screen { height: 100%; }
.screen-center {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: calc(16px + var(--safe-top)) 16px calc(16px + var(--safe-bottom));
}
.card {
  width: 100%; max-width: 420px; background: var(--bg-elev); border: 1px solid var(--border);
  border-radius: 14px; padding: 22px; box-shadow: var(--shadow);
}
.brand { display: flex; align-items: center; gap: 12px; margin-bottom: 14px; }
.brand img { border-radius: 12px; }
label { display: block; font-size: 14px; color: var(--fg-muted); margin: 10px 0 4px; }
label.check { display: flex; align-items: center; gap: 8px; color: var(--fg); margin: 12px 0; }
input[type="password"], input[type="text"], input[type="search"], select {
  width: 100%; font: inherit; font-size: 16px; color: var(--fg); background: var(--bg-sunken);
  border: 1px solid var(--border); border-radius: 8px; padding: 10px 12px; outline: none;
}
input:focus, select:focus, textarea:focus { border-color: var(--accent); }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  font: inherit; font-size: 15px; font-weight: 600; cursor: pointer; text-decoration: none;
  color: var(--fg); background: var(--bg-elev); border: 1px solid var(--border);
  border-radius: 9px; padding: 10px 14px; min-height: 42px;
}
.btn:hover { background: var(--bg-sunken); }
.btn:disabled { opacity: .5; cursor: default; }
.btn-primary { color: var(--accent-fg); background: var(--accent); border-color: var(--accent); }
.btn-primary:hover { filter: brightness(1.05); background: var(--accent); }
.btn-danger { color: #fff; background: var(--danger); border-color: var(--danger); }
.btn-block { width: 100%; margin: 12px 0 8px; }
.row { display: flex; gap: 8px; margin: 8px 0; }
.row .btn { flex: 1; }
.strength { height: 4px; background: var(--bg-sunken); border-radius: 2px; margin: 6px 0 2px; overflow: hidden; }
.strength span { display: block; height: 100%; width: 0; background: var(--danger); transition: width .2s, background .2s; }
.strength.s2 span { width: 45%; background: var(--warn); }
.strength.s3 span { width: 75%; background: var(--ok); }
.strength.s4 span { width: 100%; background: var(--ok); }
.strength.s1 span { width: 20%; }

.recovery-code {
  font-family: var(--mono); font-size: 18px; letter-spacing: 1px; line-height: 1.6; text-align: center;
  background: var(--bg-sunken); border: 1px dashed var(--border); border-radius: 10px; padding: 14px; margin: 12px 0;
  user-select: all; -webkit-user-select: all; word-break: normal; overflow-wrap: normal;
}

/* ---------- application ---------- */
#screen-main { display: flex; flex-direction: column; }
.topbar {
  display: flex; align-items: center; gap: 8px; padding: calc(6px + var(--safe-top)) 10px 6px;
  background: var(--bg-elev); border-bottom: 1px solid var(--border); min-height: 48px;
}
.topbar-title { flex: 1; font-weight: 700; font-size: 17px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.icon-btn {
  font: inherit; font-size: 20px; line-height: 1; color: var(--fg); background: transparent; border: 0;
  border-radius: 8px; width: 38px; height: 38px; cursor: pointer; display: inline-flex; align-items: center; justify-content: center;
}
.icon-btn:hover { background: var(--bg-sunken); }
.pill {
  display: inline-flex; align-items: center; gap: 6px; font: inherit; font-size: 12px; color: var(--fg-muted);
  background: var(--bg-sunken); border: 1px solid var(--border); border-radius: 999px; padding: 4px 10px; cursor: pointer; max-width: 46vw;
}
.pill .pill-text { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pill .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--fg-muted); flex: none; }
.pill.ok .dot { background: var(--ok); }
.pill.syncing .dot { background: var(--accent); animation: pulse 1s infinite; }
.pill.pending .dot { background: var(--warn); }
.pill.offline .dot { background: var(--fg-muted); }
.pill.error .dot, .pill.auth .dot { background: var(--danger); }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: .3; } }

.panes { flex: 1; min-height: 0; min-width: 0; display: grid; grid-template-columns: 240px 320px minmax(0, 1fr); }
.pane { min-height: 0; min-width: 0; display: flex; flex-direction: column; background: var(--bg); }
.pane-folders { background: var(--bg-elev); border-right: 1px solid var(--border); }
.pane-list { border-right: 1px solid var(--border); }
.pane-head { display: flex; align-items: center; gap: 6px; padding: 8px 8px 8px 12px; border-bottom: 1px solid var(--border); min-height: 46px; }
.pane-head-title { flex: 1; font-weight: 600; font-size: 14px; color: var(--fg-muted); text-transform: uppercase; letter-spacing: .04em; }
.search-wrap { flex: 1; min-width: 0; }
.search-wrap input { padding: 8px 10px; font-size: 16px; min-width: 0; }

/* arbre des dossiers */
.tree { overflow: auto; padding: 6px 6px calc(12px + var(--safe-bottom)); }
.tree-item {
  display: flex; align-items: center; gap: 4px; padding: 7px 8px; border-radius: 8px; cursor: pointer; font-size: 15px;
  user-select: none; -webkit-user-select: none;
}
.tree-item:hover { background: var(--bg-sunken); }
.tree-item.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.tree-item .caret { width: 18px; text-align: center; font-size: 11px; color: var(--fg-muted); flex: none; transition: transform .15s; }
.tree-item .caret.open { transform: rotate(90deg); }
.tree-item .caret.empty { visibility: hidden; }
.tree-item .name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tree-item .count { font-size: 12px; color: var(--fg-muted); }
.tree-item .more { opacity: 0; font-size: 16px; padding: 0 4px; border-radius: 6px; }
.tree-item:hover .more, .tree-item.active .more { opacity: 1; }
.tree-children { margin-left: 14px; }
.tree-children.collapsed { display: none; }
.tree-sep { height: 1px; background: var(--border); margin: 6px 4px; }

/* liste */
.list-context { padding: 6px 12px; font-size: 13px; color: var(--fg-muted); border-bottom: 1px solid var(--border); display: flex; align-items: center; gap: 8px; }
.list-context:empty { display: none; }
.list { overflow: auto; flex: 1; padding-bottom: calc(12px + var(--safe-bottom)); }
.list-item { padding: 10px 14px; border-bottom: 1px solid var(--border); cursor: pointer; }
.list-item:hover { background: var(--bg-sunken); }
.list-item.active { background: var(--accent-soft); }
.list-item .title { font-weight: 600; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.list-item .snippet { font-size: 13px; color: var(--fg-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-top: 2px; }
.list-item .path { font-size: 12px; color: var(--accent); margin-top: 2px; }
.list-item.folder .title::before { content: "▸ "; color: var(--fg-muted); }
.list-empty { padding: 30px 16px; text-align: center; color: var(--fg-muted); font-size: 14px; }
mark { background: #fde68a; color: inherit; border-radius: 2px; }
@media (prefers-color-scheme: dark) { mark { background: #7c5a00; } }

/* barre de mise en forme */
.fmt-bar { display: flex; gap: 4px; padding: 4px 12px 6px; overflow-x: auto; scrollbar-width: none; border-bottom: 1px solid var(--border); }
.fmt-bar::-webkit-scrollbar { display: none; }
.fmt-btn {
  font: inherit; font-size: 13px; color: var(--fg); background: var(--bg-sunken); border: 1px solid var(--border);
  border-radius: 7px; padding: 5px 9px; cursor: pointer; white-space: nowrap; min-height: 32px;
}
.fmt-btn:hover { border-color: var(--accent); color: var(--accent); }
.fmt-btn.active { border-color: var(--accent); color: var(--accent); background: var(--accent-soft); }
.fmt-copy { color: var(--accent); font-weight: 600; }
.icon-btn.small-label { font-size: 12px; font-weight: 700; letter-spacing: .02em; }
.icon-btn.small-label.active { color: var(--accent); background: var(--accent-soft); }

/* éditeur visuel (contenteditable) */
.visual { outline: none; caret-color: var(--accent); }
.visual:empty::before, .visual > p:only-child:empty::before { content: attr(data-placeholder); color: var(--fg-muted); }
.visual code { cursor: text; }
.visual pre { cursor: text; }
.visual input[type="checkbox"] { width: 16px; height: 16px; vertical-align: -2px; margin-right: 6px; accent-color: var(--accent); }
.visual li { margin: 2px 0; }
.visual a { pointer-events: auto; }
.visual.masked code { filter: blur(5px); }
.visual.masked code:hover, .visual.masked code:focus-within { filter: none; }

/* éditeur */
.pane-editor { background: var(--bg-elev); }
.editor-empty { flex: 1; display: flex; align-items: center; justify-content: center; }
.editor { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.editor-bar { display: flex; align-items: center; gap: 4px; padding: 6px 8px 0 12px; }
.editor-title {
  flex: 1; font: inherit; font-size: 20px; font-weight: 700; color: var(--fg); background: transparent; border: 0; outline: none; padding: 8px 4px; min-width: 0;
}
.editor-meta { padding: 0 16px 4px; }
.editor-body {
  flex: 1; min-height: 0; resize: none; font: 15px/1.5 var(--mono); color: var(--fg); background: transparent; border: 0; outline: none;
  padding: 8px 16px calc(16px + var(--safe-bottom)); -webkit-overflow-scrolling: touch;
}
.preview { flex: 1; overflow: auto; padding: 8px 16px calc(16px + var(--safe-bottom)); line-height: 1.55; }
.preview h1 { font-size: 22px; margin: 16px 0 8px; } .preview h2 { font-size: 19px; margin: 14px 0 6px; } .preview h3 { font-size: 16px; margin: 12px 0 6px; }
.preview p { margin: 0 0 10px; }
.preview ul, .preview ol { margin: 0 0 10px; padding-left: 22px; }
.preview code { font-family: var(--mono); font-size: 14px; background: var(--bg-sunken); border: 1px solid var(--border); border-radius: 5px; padding: 1px 6px; cursor: copy; }
.preview pre { background: var(--bg-sunken); border: 1px solid var(--border); border-radius: 8px; padding: 10px 12px; overflow: auto; cursor: copy; }
.preview pre code { background: transparent; border: 0; padding: 0; }
.preview blockquote { margin: 0 0 10px; padding: 4px 12px; border-left: 3px solid var(--accent); color: var(--fg-muted); }
.preview hr { border: 0; border-top: 1px solid var(--border); margin: 14px 0; }
.preview a { word-break: break-all; }
.preview.masked code { filter: blur(5px); }
.preview.masked code:hover, .preview.masked code:active { filter: none; }

/* dialogue */
dialog {
  border: 1px solid var(--border); border-radius: 14px; background: var(--bg-elev); color: var(--fg); padding: 0;
  width: min(92vw, 440px); box-shadow: 0 10px 40px rgba(0, 0, 0, .3);
}
dialog::backdrop { background: rgba(0, 0, 0, .35); }
#dlg-body { padding: 18px 18px 6px; }
#dlg-body h3 { font-size: 17px; margin-bottom: 8px; }
#dlg-body p { font-size: 14px; }
.dlg-actions { display: flex; gap: 8px; justify-content: flex-end; padding: 10px 18px 16px; flex-wrap: wrap; }
.dlg-actions .btn { min-width: 90px; }
.menu-list { display: flex; flex-direction: column; gap: 2px; margin: 4px 0; }
.menu-list .btn { justify-content: flex-start; border: 0; background: transparent; font-weight: 500; padding: 10px 8px; }
.menu-list .btn:hover { background: var(--bg-sunken); }
.menu-list .btn.danger { color: var(--danger); }
.menu-sep { height: 1px; background: var(--border); margin: 6px 0; }
.kv { font-size: 13px; color: var(--fg-muted); }
.kv b { color: var(--fg); }

/* toast */
.toast {
  position: fixed; left: 50%; bottom: calc(18px + var(--safe-bottom)); transform: translateX(-50%);
  background: var(--fg); color: var(--bg); padding: 10px 14px; border-radius: 10px; font-size: 14px; max-width: 90vw; z-index: 50;
  box-shadow: var(--shadow);
}
.toast.error { background: var(--danger); color: #fff; }

.only-mobile { display: none; }

/* ---------- mobile : un volet à la fois ---------- */
@media (max-width: 899px) {
  .only-mobile { display: inline-flex; }
  .panes { grid-template-columns: minmax(0, 1fr); }
  .pane { display: none; }
  #app[data-view="folders"] .pane-folders { display: flex; }
  #app[data-view="list"] .pane-list { display: flex; }
  #app[data-view="editor"] .pane-editor { display: flex; }
  #app[data-view="folders"] #btn-back { visibility: hidden; }
  .pane-folders, .pane-list { border-right: 0; }
  .tree-item .more { opacity: 1; }
  .editor-body { font-size: 16px; }
  .pill { max-width: 40vw; }
}
@media (min-width: 900px) and (max-width: 1100px) {
  .panes { grid-template-columns: 200px 260px minmax(0, 1fr); }
}

/* ---------- impression : feuille de secours seule ---------- */
@media print {
  body { background: #fff; color: #000; }
  #app > * { display: none !important; }
  #screen-recovery { display: block !important; height: auto; }
  #screen-recovery .card { border: 1px solid #000; box-shadow: none; max-width: none; }
  .no-print { display: none !important; }
  .recovery-code { border: 1px dashed #000; font-size: 20px; }
}
