/* mysqlite — shell styles. Phase 1 : login + sélecteur de fichier. */

:root {
  --mp-bg:        #f4f5f7;
  --mp-surface:   #ffffff;
  --mp-surface-2: #eef0f3;
  --mp-border:    #d5d9e0;
  --mp-text:      #1c2430;
  --mp-text-dim:  #61708a;
  --mp-accent:    #0b6a8f;   /* sqlite blue */
  --mp-accent-fg: #ffffff;
  --mp-hover:     #e6eef2;
  --mp-danger:    #c0392b;
  --mp-ok:        #2e7d46;
  --mp-radius:    7px;
  --mp-mono:      ui-monospace, "SF Mono", "DejaVu Sans Mono", Menlo, Consolas, monospace;
  --mp-sans:      system-ui, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  /* ombre du macaron : sombre en thème clair */
  --badge-shadow:       0 1px 2px rgba(0, 0, 0, .32), 0 3px 8px -2px rgba(0, 0, 0, .24);
  --badge-shadow-hover: 0 1px 3px rgba(0, 0, 0, .40), 0 5px 14px -3px rgba(0, 0, 0, .32);
}

html[data-theme="dark"] {
  --mp-bg:        #141821;
  --mp-surface:   #1c222d;
  --mp-surface-2: #232b39;
  --mp-border:    #313b4d;
  --mp-text:      #dfe6f0;
  --mp-text-dim:  #8a97ac;
  --mp-accent:    #4aa6c4;
  --mp-accent-fg: #0d1117;
  --mp-hover:     #2a3444;
  --mp-danger:    #e06c5e;
  --mp-ok:        #6cc487;
  /* ombre du macaron : claire (halo) en thème sombre */
  --badge-shadow:       0 1px 2px rgba(255, 255, 255, .28), 0 3px 9px -2px rgba(255, 255, 255, .18);
  --badge-shadow-hover: 0 1px 3px rgba(255, 255, 255, .40), 0 5px 15px -3px rgba(255, 255, 255, .26);
}

* { box-sizing: border-box; }
html, body { height: 100%; overflow-x: hidden; }

body {
  margin: 0;
  font-family: var(--mp-sans);
  font-size: 14px;
  line-height: 1.45;
  color: var(--mp-text);
  background: var(--mp-bg);
}

#app { height: 100%; }

.logo {
  display: inline-grid;
  place-items: center;
  width: 1.5em; height: 1.5em;
  background: var(--mp-accent);
  color: var(--mp-accent-fg);
  border-radius: 5px;
  font-family: var(--mp-mono);
  font-size: 0.72em;
  font-weight: 700;
  vertical-align: middle;
}

/* ---------- login ---------- */

.login-wrap { height: 100%; display: grid; place-items: center; padding: 24px; }

.login-card {
  position: relative;
  width: 340px;
  max-width: 100%;
  background: var(--mp-surface);
  border: 1px solid var(--mp-border);
  border-radius: var(--mp-radius);
  padding: 28px 26px 24px;
  box-shadow: 0 10px 40px -18px rgba(0, 0, 0, .35);
}

.login-top {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 6px;
  margin: -6px 0 12px;
}

.login-top .btn-ghost {
  width: auto; margin: 0; padding: 4px 8px; font-weight: 400;
  color: var(--mp-text-dim); background: transparent;
}
.login-top .btn-ghost:hover { color: var(--mp-text); background: var(--mp-hover); }

/* macaron purement décoratif sur l'écran de connexion (pas de changelog avant
   authentification) ; neutralise aussi le sélecteur générique « .login-card button » */
.login-top .version-badge {
  width: auto; margin: 0; padding: 4px; font-weight: 400;
  color: inherit; cursor: default;
  background: color-mix(in srgb, var(--mp-accent) 12%, var(--mp-surface));
  border: 1px solid color-mix(in srgb, var(--mp-accent) 35%, transparent);
  border-radius: 50%;
  box-shadow: var(--badge-shadow);
  transform: none;
}

.login-card h1 { margin: 0 0 2px; font-size: 21px; display: flex; align-items: center; gap: 9px; }
.login-card .sub { margin: 0 0 18px; color: var(--mp-text-dim); font-size: 13px; }
.login-card label { display: block; margin-bottom: 11px; font-size: 12px; color: var(--mp-text-dim); }

.login-card input {
  display: block; width: 100%; margin-top: 3px; padding: 8px 10px;
  font: inherit; color: var(--mp-text); background: var(--mp-bg);
  border: 1px solid var(--mp-border); border-radius: 5px;
}
.login-card input:focus { outline: 2px solid var(--mp-accent); outline-offset: -1px; border-color: var(--mp-accent); }

.password-field { position: relative; display: block; }
.password-field input { padding-right: 44px; }
/* spécificité > « .login-card button » (générique, plus loin dans la feuille)
   qui sinon repasse ce bouton en pleine largeur sous le champ au lieu de le
   positionner dedans, à droite. */
.login-card .password-toggle-btn {
  position: absolute; top: 50%; right: 4px; transform: translateY(-50%);
  width: 34px; height: 34px; margin: 0; padding: 0;
  display: flex; align-items: center; justify-content: center;
  border: none; border-radius: 50%; background: transparent;
  color: var(--mp-text-dim); cursor: pointer;
}
.login-card .password-toggle-btn:hover { color: var(--mp-text); }

.login-card button {
  width: 100%; margin-top: 6px; padding: 9px 14px; font: inherit; font-weight: 600;
  color: var(--mp-accent-fg); background: var(--mp-accent); border: 0; border-radius: 5px; cursor: pointer;
}
.login-card button:disabled { opacity: .6; cursor: progress; }

.login-card .err, .pane .err-box {
  margin: 12px 0 0; padding: 8px 10px; font-size: 12.5px;
  color: var(--mp-danger);
  background: color-mix(in srgb, var(--mp-danger) 12%, transparent);
  border: 1px solid color-mix(in srgb, var(--mp-danger) 35%, transparent);
  border-radius: 5px; white-space: pre-wrap;
}
.login-card .ok {
  margin: 12px 0 0; padding: 8px 10px; font-size: 12.5px;
  color: var(--mp-ok);
  background: color-mix(in srgb, var(--mp-ok) 12%, transparent);
  border: 1px solid color-mix(in srgb, var(--mp-ok) 35%, transparent);
  border-radius: 5px; white-space: pre-wrap;
}
.login-card .login-switch {
  margin: 14px 0 0; font-size: 12.5px; color: var(--mp-text-dim); text-align: center;
}
.login-card .link-btn {
  background: none; border: 0; padding: 0; margin: 0; width: auto;
  color: var(--mp-accent); font: inherit; font-weight: 600; cursor: pointer; text-decoration: underline;
}
.login-card.request-card { margin-top: 14px; }

/* ---------- shell ---------- */

#app:has(.workspace) { display: flex; flex-direction: column; }

.topbar {
  display: flex; align-items: center; gap: 10px;
  padding: 0 12px; height: 46px;
  background: var(--mp-surface); border-bottom: 1px solid var(--mp-border);
  flex: 0 0 auto;
  /* trop de boutons pour un écran étroit ne doivent jamais forcer la largeur
     de #app/body au-delà du viewport (débordement flexbox classique).
     PAS de overflow:auto/hidden ici (essayé en Xagobah-0024) : ça coupe aussi
     tout ce qui s'affiche SOUS la barre par positionnement absolu (popover
     empreintes, tooltip du macaron) — invisibles bien qu'ouverts. La barre
     passe sur 2 lignes sur mobile (Xagobah-0025) et `overflow-x:hidden` sur
     html/body (ci-dessous) suffit comme garde-fou anti-débordement. */
  min-width: 0;
}
.topbar > * { flex-shrink: 0; }

.version-badge {
  display: inline-flex; align-items: center; justify-content: center; flex: 0 0 auto;
  width: auto; margin: 0; padding: 4px;
  background: color-mix(in srgb, var(--mp-accent) 12%, var(--mp-surface));
  border: 1px solid color-mix(in srgb, var(--mp-accent) 35%, transparent);
  border-radius: 50%; cursor: pointer;
  box-shadow: var(--badge-shadow);
  transition: box-shadow .15s ease, background .15s ease, transform .15s ease;
}
.version-badge img { display: block; }
.version-badge:hover {
  background: color-mix(in srgb, var(--mp-accent) 20%, var(--mp-surface));
  box-shadow: var(--badge-shadow-hover);
  transform: translateY(-1px);
}
.version-badge:active { transform: translateY(0); box-shadow: var(--badge-shadow); }
/* décoratif sur le login : pas de réaction au survol */
.login-top .version-badge:hover {
  background: color-mix(in srgb, var(--mp-accent) 12%, var(--mp-surface));
  box-shadow: var(--badge-shadow);
  transform: none;
}

.version-badge-wrap { position: relative; display: inline-flex; flex: 0 0 auto; }

.version-tooltip {
  position: absolute; top: calc(100% + 6px); left: 0; z-index: 40;
  display: flex; flex-direction: column; gap: 2px;
  padding: 8px 11px;
  background: var(--mp-surface); border: 1px solid var(--mp-border);
  border-radius: 7px; box-shadow: 0 10px 30px -12px rgba(0, 0, 0, .4);
  font-size: 11.5px; font-weight: 400; letter-spacing: normal;
  color: var(--mp-text); white-space: nowrap;
  opacity: 0; visibility: hidden; transform: translateY(-4px);
  transition: opacity .15s ease, transform .15s ease, visibility .15s ease;
  pointer-events: none;
}
.version-tooltip--right { left: auto; right: 0; }
.version-badge-wrap:hover .version-tooltip,
.version-badge-wrap:focus-within .version-tooltip {
  opacity: 1; visibility: visible; transform: translateY(0);
}
.version-tooltip-title { font-weight: 700; font-size: 12.5px; }
.version-tooltip-ver { color: var(--mp-accent); font-weight: 600; }
.version-tooltip-theme { color: var(--mp-text-dim); }
.version-tooltip-hint { margin-top: 3px; font-size: 10px; color: var(--mp-text-dim); }

.topbar .conn-info {
  font-size: 12.5px; color: var(--mp-text-dim); font-family: var(--mp-mono);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.topbar .conn-info b { color: var(--mp-text); font-weight: 600; }
.topbar .conn-info .ro { color: var(--mp-danger); }
.topbar .conn-info .engine { color: var(--mp-text); }
.topbar .conn-info .sep { opacity: .5; margin: 0 .15em; }

/* ---------- connexion par empreinte digitale (WebAuthn) ---------- */

.webauthn-divider {
  display: flex; align-items: center; gap: 10px; margin: 16px 0;
  color: var(--mp-text-dim); font-size: 12px;
}
.webauthn-divider::before, .webauthn-divider::after {
  content: ''; flex: 1; height: 1px; background: var(--mp-border);
}
.webauthn-login-btn {
  width: 100%; display: flex; align-items: center; justify-content: center; gap: 8px;
  border: 1px solid var(--mp-border); background: var(--mp-surface-2); color: var(--mp-text);
  padding: 9px 14px; border-radius: var(--mp-radius); font: inherit; font-weight: 600; cursor: pointer;
}
.webauthn-login-btn:hover { background: var(--mp-hover); }

.webauthn-manage-wrap { position: relative; display: inline-flex; }
.webauthn-manage-popover {
  position: absolute; top: calc(100% + 8px); right: 0;
  min-width: 240px; width: max-content; max-width: 90vw;
  background: var(--mp-surface); border: 1px solid var(--mp-border); border-radius: var(--mp-radius);
  box-shadow: 0 4px 16px rgba(0, 0, 0, .18); padding: 10px 12px; font-size: 12.5px; z-index: 60;
}
.webauthn-manage-title { font-weight: 700; margin-bottom: 6px; }
#webauthn-cred-list { list-style: none; margin: 0; padding: 0; }
#webauthn-cred-list li {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 5px 0; border-bottom: 1px solid var(--mp-border);
}
#webauthn-cred-list li:last-child { border-bottom: none; }
#webauthn-cred-list li.sub { color: var(--mp-text-dim); }
#webauthn-cred-list .wa-cred-meta { color: var(--mp-text-dim); font-size: 11.5px; }
#webauthn-cred-list .wa-cred-del {
  border: none; background: transparent; color: var(--mp-danger); cursor: pointer;
  font-size: 13px; padding: 2px 4px;
}
#webauthn-manage-err { margin: 8px 0 0; color: var(--mp-danger); font-size: 12px; }
.topbar .spacer { flex: 1; }

.btn-ghost {
  font: inherit; color: var(--mp-text-dim);
  background: transparent; border: 1px solid transparent; border-radius: 5px;
  padding: 5px 9px; cursor: pointer;
}
.btn-ghost:hover { color: var(--mp-text); background: var(--mp-hover); }
.topbar .btn-ghost.is-active,
.topbar .btn-ghost.is-active:hover { color: var(--mp-accent-fg); background: var(--mp-accent); border-color: transparent; }

#app:has(.topbar) { display: flex; flex-direction: column; height: 100%; }
.workspace { flex: 1; display: flex; min-height: 0; overflow: hidden; }
.pane { flex: 1; min-width: 0; padding: 26px 30px 60px; overflow: auto; }
.pane:has(.pane-frame) { padding: 0; display: flex; overflow: hidden; }
.pane .pane-frame { flex: 1; width: 100%; border: 0; background: var(--mp-bg); }
.pane .pane-inner { max-width: 900px; margin: 0 auto; }

.pane h2 { margin: 0 0 4px; font-size: 18px; }
.pane .muted { color: var(--mp-text-dim); font-size: 13px; margin: 0 0 20px; }

/* ---------- file picker ---------- */

.picker-tools { display: flex; gap: 8px; margin: 0 0 14px; }
.picker-filter {
  flex: 1; padding: 8px 11px; font: inherit;
  color: var(--mp-text); background: var(--mp-surface);
  border: 1px solid var(--mp-border); border-radius: 6px;
}
.picker-filter:focus { outline: 2px solid var(--mp-accent); outline-offset: -1px; }

.file-list { display: flex; flex-direction: column; border: 1px solid var(--mp-border); border-radius: 8px; overflow: hidden; }
.file-group { background: var(--mp-surface-2); font: 11px var(--mp-mono); color: var(--mp-text-dim);
  padding: 6px 12px; border-top: 1px solid var(--mp-border); }
.file-group:first-child { border-top: 0; }

.file-row {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 12px; background: var(--mp-surface);
  border-top: 1px solid var(--mp-border); cursor: pointer; text-align: left;
  font: inherit; color: var(--mp-text); width: 100%;
}
.file-row:hover { background: var(--mp-hover); }
.file-row .fname { font-weight: 600; }
.file-row .fmeta { margin-left: auto; font: 11.5px var(--mp-mono); color: var(--mp-text-dim); white-space: nowrap; }
.file-row .flag-ro { color: var(--mp-danger); font-size: 11px; border: 1px solid currentColor; border-radius: 4px; padding: 1px 5px; }

.pane .empty { padding: 30px; text-align: center; color: var(--mp-text-dim); }

/* ---------- open-file card ---------- */

.dbcard {
  border: 1px solid var(--mp-border); border-radius: 10px;
  background: var(--mp-surface); padding: 20px 22px; margin: 0 0 22px;
}
.dbcard h3 { margin: 0 0 3px; font: 600 15px var(--mp-mono); word-break: break-all; }
.dbcard .path { font: 12px var(--mp-mono); color: var(--mp-text-dim); word-break: break-all; margin: 0 0 16px; }

.kv { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px 20px; }
.kv div { font-size: 13px; }
.kv dt { color: var(--mp-text-dim); font-size: 11px; text-transform: uppercase; letter-spacing: .03em; }
.kv dd { margin: 2px 0 0; font-family: var(--mp-mono); }

.ro-warn {
  margin: 16px 0 0; padding: 8px 11px; font-size: 12.5px;
  color: var(--mp-danger);
  background: color-mix(in srgb, var(--mp-danger) 10%, transparent);
  border: 1px solid color-mix(in srgb, var(--mp-danger) 30%, transparent);
  border-radius: 6px;
}

.next-note {
  margin: 8px 0 0; padding: 14px 16px; border-radius: 8px;
  background: var(--mp-surface-2); border: 1px dashed var(--mp-border);
  font-size: 13px; color: var(--mp-text-dim);
}

/* ---------- confirm / frame modal ---------- */

.mp-modal-back {
  position: fixed; inset: 0; z-index: 1100; display: grid; place-items: center;
  padding: 20px; background: rgba(8, 12, 20, .48);
}
.mp-modal {
  width: 400px; max-width: 100%;
  background: var(--mp-surface); border: 1px solid var(--mp-border);
  border-radius: 10px; padding: 20px 22px 18px;
  box-shadow: 0 20px 60px -16px rgba(0, 0, 0, .5);
}
.mp-modal h3 { margin: 0 0 8px; font-size: 15px; }
.mp-modal p { margin: 0 0 18px; color: var(--mp-text-dim); line-height: 1.5; white-space: pre-line; }
.mp-modal-actions { display: flex; justify-content: flex-end; gap: 8px; }
.mp-modal-actions button {
  font: inherit; padding: 7px 14px; border-radius: 6px;
  border: 1px solid var(--mp-border); background: var(--mp-surface-2);
  color: var(--mp-text); cursor: pointer;
}
.mp-modal-actions button:hover { background: var(--mp-hover); }
.mp-modal-actions button.primary { border-color: transparent; background: var(--mp-accent); color: var(--mp-accent-fg); font-weight: 600; }

.mp-modal--frame {
  width: min(720px, 92vw); height: min(80vh, 720px);
  padding: 0; display: flex; flex-direction: column; overflow: hidden;
}
.mp-modal-frame-head {
  display: flex; align-items: center; justify-content: space-between; flex: 0 0 auto;
  padding: 10px 8px 10px 16px; border-bottom: 1px solid var(--mp-border);
}
.mp-modal-frame-head h3 { margin: 0; font-size: 14px; }
.mp-modal-close {
  font: 20px/1 var(--mp-sans); padding: 3px 9px; border: 0; border-radius: 6px;
  background: transparent; color: var(--mp-text-dim); cursor: pointer;
}
.mp-modal-close:hover { background: var(--mp-hover); color: var(--mp-text); }
.mp-modal-frame-body { flex: 1; width: 100%; border: 0; background: var(--mp-bg); }

/* ---------- workspace : sidebar (magictree) + detail iframe ---------- */

#app.has-file { display: flex; flex-direction: column; }

.sidebar {
  width: 280px;
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  background: var(--mp-surface);
  border-right: 1px solid var(--mp-border);
  min-height: 0;
  overflow: hidden;
}
.sidebar .magictree-container { flex: 1; min-height: 0; display: flex; }
.sidebar .magictree-wrapper {
  flex: 1; min-height: 0;
  margin: 0 !important; border: 0 !important; border-radius: 0 !important; box-shadow: none !important;
}

.resizer {
  width: 5px; margin: 0 -2px; cursor: col-resize;
  background: transparent; z-index: 5; flex: 0 0 auto;
}
.resizer:hover, .resizer.active { background: var(--mp-accent); }

.detail { flex: 1; min-width: 0; position: relative; background: var(--mp-bg); }
.detail .placeholder {
  position: absolute; inset: 0; overflow: auto;
  padding: 28px 32px 48px; color: var(--mp-text);
}
.detail .placeholder .muted { color: var(--mp-text-dim); }
.detail-frame { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; }

/* ---------- menu contextuel (clic droit sur l'arbre) ---------- */

.ctx-menu {
  position: fixed;
  z-index: 1000;
  min-width: 200px;
  padding: 4px;
  background: var(--mp-surface);
  border: 1px solid var(--mp-border);
  border-radius: 8px;
  box-shadow: 0 12px 40px -10px rgba(0, 0, 0, .45);
  font-size: 13px;
}
.ctx-head {
  padding: 5px 8px 6px;
  font: 11px var(--mp-mono);
  color: var(--mp-text-dim);
  border-bottom: 1px solid var(--mp-border);
  margin-bottom: 4px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.ctx-item {
  display: block;
  width: 100%;
  text-align: left;
  padding: 7px 9px;
  font: inherit;
  color: var(--mp-text);
  background: transparent;
  border: 0;
  border-radius: 5px;
  cursor: pointer;
}
.ctx-item:hover, .ctx-item:focus-visible { background: var(--mp-hover); outline: none; }
.ctx-item.danger { color: var(--mp-danger); }
.ctx-item.danger:hover { background: color-mix(in srgb, var(--mp-danger) 14%, transparent); }
.ctx-sep { height: 1px; margin: 4px 2px; background: var(--mp-border); }

.tree-toggle-btn { display: none; }
.workspace-scrim { display: none; }

@media (max-width: 720px) {
  .topbar .conn-info { display: none; }
  .pane { padding: 20px 16px 48px; }
}

/* ---------- workspace en tiroir sur mobile ---------- */

@media (max-width: 860px) {
  /* trop de boutons pour une seule ligne sur smartphone : on passe sur 2
     lignes (macaron + infos en haut, actions en dessous) plutôt que de
     scroller horizontalement — le `.spacer` forcé en pleine largeur sert
     de saut de ligne entre les deux groupes. */
  .topbar {
    flex-wrap: wrap;
    height: auto;
    min-height: 46px;
    row-gap: 6px;
    padding: 8px;
    overflow-x: visible;
  }
  .topbar .spacer { flex: 0 0 100%; height: 0; }
  .topbar .btn-ghost { padding: 6px 8px; font-size: 12.5px; }

  .tree-toggle-btn { display: inline-flex; }

  .workspace { position: relative; }

  .sidebar {
    position: absolute;
    inset: 0 auto 0 0;
    z-index: 45;
    width: min(86vw, 340px) !important;
    max-width: 86vw;
    box-shadow: 10px 0 28px -10px rgba(0, 0, 0, .5);
    transform: translateX(-100%);
    transition: transform .2s ease;
  }
  .sidebar.is-open { transform: translateX(0); }

  .resizer { display: none; }

  .detail { width: 100%; }

  .workspace-scrim {
    display: block;
    position: absolute; inset: 0;
    background: rgba(10, 14, 20, .38);
    z-index: 40;
    opacity: 0;
    visibility: hidden;
    transition: opacity .2s ease, visibility .2s ease;
  }
  .workspace-scrim.is-visible { opacity: 1; visibility: visible; }
}
