:root{
    --bg-0:#0d141c;
    --bg-1:#131e29;
    --bg-2:#1b2733;
    --bg-3:#24313f;
    --bg-4:#2c3b4a;
    --line:#263442;
    --text-1:#eef2f5;
    --text-2:#aebcc9;
    --text-3:#78899a;
    --gold:#d4a24c;
    --gold-light:#e8be78;
    --gold-dim:rgba(212,162,76,.16);
    --danger:#e0664f;
    --danger-dim:rgba(224,102,79,.14);
    --success:#7fb88f;
    --radius-lg:18px;
    --radius-md:12px;
    --radius-sm:8px;
    --shadow-lg:0 20px 50px -12px rgba(0,0,0,.55);
    --shadow-sm:0 2px 10px rgba(0,0,0,.25);
    --font-ui:'Vazirmatn', Tahoma, sans-serif;
    --font-mono:'JetBrains Mono', 'Vazirmatn', ui-monospace, monospace;
    --ease:cubic-bezier(.22,.61,.36,1);
  }
  *{box-sizing:border-box;}
  html,body{height:100%;}
  body{
    margin:0;
    font-family:var(--font-ui);
    background:radial-gradient(1200px 800px at 85% -10%, var(--bg-1) 0%, var(--bg-0) 55%);
    color:var(--text-1);
    overflow:hidden;
    -webkit-tap-highlight-color:transparent;
    user-select:none; -webkit-user-select:none; -moz-user-select:none;
  }
  textarea, input, .content-area, .modal-input{
    user-select:text; -webkit-user-select:text; -moz-user-select:text;
  }
  ::selection{ background:var(--gold-dim); color:var(--gold-light); }
  html[data-theme="light"]{
    --bg-0:#f6f3ec;
    --bg-1:#ffffff;
    --bg-2:#f0ece2;
    --bg-3:#e8e2d4;
    --bg-4:#dcd4c1;
    --line:#e2dbc9;
    --text-1:#241d12;
    --text-2:#5c5340;
    --text-3:#8c8266;
    --gold:#b5793a;
    --gold-light:#8f5c26;
    --gold-dim:rgba(181,121,58,.14);
    --danger:#c94f38;
    --danger-dim:rgba(201,79,56,.12);
    --success:#3f8a5c;
  }
  html[data-theme="light"] body{ background:radial-gradient(1200px 800px at 85% -10%, #fdfbf5 0%, var(--bg-0) 55%); }
  html[data-theme="light"] .new-doc-btn, html[data-theme="light"] .btn.primary{ color:#fff; }

  ::-webkit-scrollbar{ width:9px; height:9px; }
  ::-webkit-scrollbar-track{ background:transparent; }
  ::-webkit-scrollbar-thumb{ background:var(--bg-4); border-radius:10px; }
  ::-webkit-scrollbar-thumb:hover{ background:#3a4a5b; }
  button{ font-family:inherit; cursor:pointer; }
  input, textarea{ font-family:inherit; }

  /* ---------- App shell ---------- */
  #app{ height:100dvh; display:flex; flex-direction:column; position:relative; }

  .topbar{
    display:flex; align-items:center; gap:10px;
    padding:10px 14px;
    background:linear-gradient(180deg, var(--bg-1), var(--bg-0));
    border-bottom:1px solid var(--line);
    flex:0 0 auto;
    flex-wrap:nowrap;
    z-index:20;
  }
  .brand{ display:flex; align-items:center; gap:9px; margin-inline-end:4px; flex-shrink:0; }
  .brand svg{ display:block; flex-shrink:0; }
  .brand-name{ font-weight:800; font-size:17px; letter-spacing:.2px; white-space:nowrap; }
  .icon-btn{
    width:38px; height:38px; border-radius:var(--radius-sm);
    display:flex; align-items:center; justify-content:center;
    background:transparent; border:1px solid transparent; color:var(--text-2);
    transition:background .15s var(--ease), color .15s var(--ease), border-color .15s var(--ease);
    flex:0 0 auto;
  }
  .icon-btn:hover{ background:var(--bg-3); color:var(--text-1); }
  .icon-btn:active{ transform:scale(.94); }
  .icon-btn.active{ background:var(--gold-dim); color:var(--gold-light); border-color:rgba(212,162,76,.3); }
  .icon-btn svg{ width:19px; height:19px; }

  .topbar-spacer{ flex:1 1 auto; min-width:4px; }
  .status-pill{
    display:flex; align-items:center; gap:6px;
    font-size:12px; color:var(--text-3);
    padding:6px 10px; border-radius:99px; background:var(--bg-2);
    border:1px solid var(--line);
    white-space:nowrap; overflow:hidden; min-width:0; flex-shrink:1;
  }
  .status-pill span{ overflow:hidden; text-overflow:ellipsis; white-space:nowrap; }
  .ink-dot{ width:7px; height:7px; border-radius:50%; background:var(--text-3); transition:background .3s, box-shadow .3s; flex:0 0 auto;}
  .ink-dot.writing{ background:var(--gold); box-shadow:0 0 0 3px var(--gold-dim); animation:pulse 1s ease-in-out infinite; }
  .ink-dot.saved{ background:var(--success); box-shadow:0 0 0 3px rgba(127,184,143,.18);}
  @keyframes pulse{ 0%,100%{ opacity:1;} 50%{ opacity:.45;} }

  /* ---------- Layout ---------- */
  .layout{ flex:1 1 auto; display:flex; min-height:0; position:relative; }

  .sidebar{
    position:fixed; top:0; bottom:0; right:0; width:86vw; max-width:340px; z-index:40;
    transform:translateX(110%); transition:transform .26s var(--ease);
    background:var(--bg-1);
    border-inline-start:1px solid var(--line);
    display:flex; flex-direction:column; min-height:0;
  }
  .sidebar.show{ transform:translateX(0); }
  .sidebar-topbar{ display:flex; align-items:center; justify-content:space-between; padding:12px 14px; border-bottom:1px solid var(--line); flex:0 0 auto; }
  .sidebar-topbar span{ font-size:14px; font-weight:700; color:var(--text-1); }
  .sidebar-head{ padding:14px 14px 10px; flex:0 0 auto; display:flex; flex-direction:column; gap:10px; }
  .new-doc-btn{
    width:100%; display:flex; align-items:center; justify-content:center; gap:8px;
    background:linear-gradient(180deg, var(--gold-light), var(--gold));
    color:#241a0a; font-weight:700; font-size:14px;
    border:none; border-radius:var(--radius-md); padding:11px 12px;
    box-shadow:0 8px 20px -8px rgba(212,162,76,.55);
    transition:transform .15s var(--ease), box-shadow .15s var(--ease), filter .15s;
  }
  .new-doc-btn:hover{ filter:brightness(1.05); transform:translateY(-1px); }
  .new-doc-btn:active{ transform:translateY(0) scale(.98); }
  .new-doc-btn svg{ width:17px; height:17px; }
  .quick-note-link{
    display:flex; align-items:center; justify-content:center; gap:6px;
    background:transparent; border:none; color:var(--gold);
    font-size:12px; font-weight:600; padding:2px 4px;
  }
  .quick-note-link svg{ width:14px; height:14px; }
  .quick-note-link:hover{ text-decoration:underline; }

  .search-wrap{ position:relative; }
  .search-wrap svg{ position:absolute; inset-inline-start:11px; top:50%; transform:translateY(-50%); width:15px; height:15px; color:var(--text-3); pointer-events:none;}
  .search-input{
    width:100%; background:var(--bg-2); border:1px solid var(--line); color:var(--text-1);
    border-radius:var(--radius-sm); padding:10px 32px 10px 12px; font-size:13.5px; outline:none;
    transition:border-color .15s;
  }
  .search-input:focus{ border-color:var(--gold); }
  .search-input::placeholder{ color:var(--text-3); }

  .doc-list{ flex:1 1 auto; overflow-y:auto; padding:8px 10px 16px; }
  .doc-card{
    padding:11px 12px; border-radius:var(--radius-md); margin-bottom:6px;
    cursor:pointer; border:1px solid transparent; position:relative;
    transition:background .15s var(--ease), border-color .15s var(--ease);
  }
  .doc-card:hover{ background:var(--bg-2); }
  .doc-card.active{ background:var(--gold-dim); border-color:rgba(212,162,76,.35); }
  .doc-card-top{ display:flex; align-items:center; gap:6px; }
  .doc-title{ font-size:13.5px; font-weight:600; color:var(--text-1); flex:1 1 auto; white-space:nowrap; overflow:hidden; text-overflow:ellipsis; }
  .doc-card.active .doc-title{ color:var(--gold-light); }
  .pin-ic{ width:13px; height:13px; color:var(--gold); flex:0 0 auto; }
  .doc-snippet{ font-size:12px; color:var(--text-3); margin-top:4px; white-space:nowrap; overflow:hidden; text-overflow:ellipsis; }
  .doc-meta{ font-size:11px; color:var(--text-3); margin-top:6px; display:flex; justify-content:space-between; }
  .doc-menu-btn{ position:absolute; inset-inline-end:8px; top:8px; width:26px; height:26px; border-radius:7px; display:none; align-items:center; justify-content:center; color:var(--text-3); background:transparent; }
  .doc-card:hover .doc-menu-btn, .doc-card.active .doc-menu-btn{ display:flex; }
  .doc-menu-btn:hover{ background:var(--bg-4); color:var(--text-1); }
  .doc-menu-btn svg{ width:15px; height:15px; }

  .empty-list{ display:flex; flex-direction:column; align-items:center; text-align:center; color:var(--text-3); font-size:12.5px; padding:34px 18px; line-height:2; }
  .empty-list svg{ width:34px; height:34px; color:var(--text-3); opacity:.55; margin-bottom:8px; }

  .sidebar-foot{ flex:0 0 auto; padding:10px 14px 14px; border-top:1px solid var(--line); display:flex; gap:8px; }
  .foot-btn{ flex:1 1 0; display:flex; align-items:center; justify-content:center; gap:6px; padding:9px 8px; border-radius:var(--radius-sm); background:var(--bg-2); border:1px solid var(--line); color:var(--text-2); font-size:12px; }
  .foot-btn:hover{ background:var(--bg-3); color:var(--text-1); }
  .foot-btn svg{ width:14px; height:14px; }

  /* ---------- Editor ---------- */
  .editor-pane{ flex:1 1 auto; display:flex; flex-direction:column; min-width:0; min-height:0; background:var(--bg-0); }
  .editor-toolbar{ display:flex; align-items:center; gap:8px; padding:12px 18px; border-bottom:1px solid var(--line); flex:0 0 auto; }
  .title-input{
    flex:1 1 auto; background:transparent; border:none; outline:none; color:var(--text-1);
    font-size:16.5px; font-weight:700; min-width:0;
  }
  .title-input::placeholder{ color:var(--text-3); font-weight:600; }
  .toolbar-divider{ width:1px; align-self:stretch; background:var(--line); margin:2px 2px; }

  .editor-scroll{ flex:1 1 auto; overflow-y:auto; min-height:0; }
  .editor-inner{ max-width:820px; margin:0 auto; padding:26px 30px 90px; min-height:100%; }
  .content-area{
    width:100%; min-height:60vh; resize:none; border:none; outline:none; background:transparent;
    color:var(--text-1); font-size:16px; line-height:2; font-family:var(--font-ui);
  }
  .content-area.mono{ font-family:var(--font-mono); font-size:14.5px; line-height:1.9; }
  .content-area::placeholder{ color:var(--text-3); }
  .content-area.ltr-mode{ direction:ltr; text-align:left; }

  .editor-statusbar{
    flex:0 0 auto; display:flex; align-items:center; gap:14px; padding:8px 18px;
    border-top:1px solid var(--line); font-size:11.5px; color:var(--text-3); background:var(--bg-1);
  }
  .editor-statusbar b{ color:var(--text-2); font-weight:600; }
  .statusbar-spacer{ flex:1 1 auto; }

  /* ---------- Empty editor state ---------- */
  .no-doc{ flex:1 1 auto; display:flex; flex-direction:column; align-items:center; justify-content:center; gap:14px; color:var(--text-3); padding:20px; text-align:center; }
  .no-doc svg{ width:64px; height:64px; color:var(--text-3); opacity:.5; }
  .no-doc h2{ color:var(--text-2); font-size:16px; margin:0; }
  .no-doc p{ margin:0; font-size:13px; max-width:280px; line-height:1.9; }

  /* ---------- Overlays / Drawer ---------- */
  .scrim{ position:fixed; inset:0; background:rgba(6,10,14,.55); backdrop-filter:blur(2px); opacity:0; pointer-events:none; transition:opacity .2s var(--ease); z-index:30; }
  .scrim.show{ opacity:1; pointer-events:auto; }

  /* ---------- Modal ---------- */
  .modal{
    position:fixed; inset:0; display:flex; align-items:center; justify-content:center; z-index:60;
    opacity:0; pointer-events:none; transition:opacity .18s var(--ease); padding:20px;
  }
  .modal.show{ opacity:1; pointer-events:auto; }
  /* این دو پنجره، گفت‌وگوهای عمومی مشترک هستند (تأیید حذف/عملیات، دریافت نام)
     که ممکن است از داخل هر پنجرهٔ دیگری هم فراخوانی شوند؛ برای اینکه همیشه روی
     پنجرهٔ فراخواننده نمایش داده شوند و نه پشت آن پنهان بمانند، باید صرف‌نظر از
     ترتیبشان در HTML، z-index بالاتری داشته باشند. */
  #nameModal, #confirmModal{ z-index:80; }
  .modal-card{
    width:100%; max-width:440px; background:var(--bg-1); border:1px solid var(--line); border-radius:var(--radius-lg);
    box-shadow:var(--shadow-lg); padding:22px; transform:translateY(10px) scale(.98); transition:transform .22s var(--ease);
    max-height:86vh; overflow-y:auto;
  }
  .modal.show .modal-card{ transform:translateY(0) scale(1); }
  .modal-title{ display:flex; align-items:center; gap:10px; font-size:15.5px; font-weight:700; margin:0 0 6px; }
  .modal-title svg{ width:19px; height:19px; color:var(--gold); }
  .modal-desc{ font-size:12.5px; color:var(--text-3); line-height:1.9; margin:0 0 16px; }
  .modal-field{ margin-bottom:14px; }
  .modal-field label{ display:block; font-size:12px; color:var(--text-2); margin-bottom:6px; font-weight:600; }
  .modal-input{ width:100%; background:var(--bg-2); border:1px solid var(--line); color:var(--text-1); border-radius:var(--radius-sm); padding:10px 12px; font-size:13.5px; outline:none; }
  .modal-input:focus{ border-color:var(--gold); }
  .modal-actions{ display:flex; gap:10px; margin-top:18px; }
  .btn{ flex:1 1 0; padding:10px 14px; border-radius:var(--radius-sm); border:1px solid var(--line); background:var(--bg-2); color:var(--text-1); font-size:13.5px; font-weight:600; transition:background .15s, border-color .15s; }
  .btn:hover{ background:var(--bg-3); }
  .btn.primary{ background:linear-gradient(180deg, var(--gold-light), var(--gold)); color:#241a0a; border-color:transparent; }
  .btn.primary:hover{ filter:brightness(1.05); }
  .btn.danger{ background:var(--danger-dim); color:#ffb3a3; border-color:rgba(224,102,79,.35); }
  .btn.danger:hover{ background:rgba(224,102,79,.22); }
  .btn.ghost{ background:transparent; }

  .settings-section{ margin-bottom:16px; }
  .settings-section h4{ font-size:11.5px; text-transform:uppercase; letter-spacing:.06em; color:var(--text-3); margin:0 0 9px; font-weight:700; }
  .seg{ display:flex; gap:6px; background:var(--bg-2); padding:4px; border-radius:var(--radius-sm); border:1px solid var(--line); }
  .seg button{ flex:1 1 0; background:transparent; border:none; color:var(--text-2); font-size:12.5px; padding:8px 6px; border-radius:7px; font-weight:600; transition:background .15s, color .15s; }
  .seg button.active{ background:var(--gold-dim); color:var(--gold-light); }
  .row-between{ display:flex; align-items:center; justify-content:space-between; padding:9px 2px; }
  .row-between span{ font-size:13px; color:var(--text-1); }
  .row-between small{ display:block; font-size:11px; color:var(--text-3); margin-top:2px; font-weight:400; }
  .switch{ width:42px; height:24px; border-radius:99px; background:var(--bg-4); position:relative; flex:0 0 auto; border:1px solid var(--line); transition:background .18s; }
  .switch::after{ content:''; position:absolute; top:2px; inset-inline-start:2px; width:18px; height:18px; border-radius:50%; background:var(--text-2); transition:inset-inline-start .18s var(--ease), background .18s; }
  .switch.on{ background:var(--gold-dim); border-color:rgba(212,162,76,.4); }
  .switch.on::after{ inset-inline-start:20px; background:var(--gold); }
  .range-row{ padding:8px 2px 2px; }
  .range-row input[type=range]{ width:100%; accent-color:var(--gold); }

  .backup-actions{ display:flex; flex-direction:column; gap:9px; }

  .feature-list{ display:flex; flex-direction:column; gap:14px; max-height:60vh; overflow-y:auto; padding-inline-end:4px; }
  .feature-item{ display:flex; gap:12px; align-items:flex-start; }
  .feature-item svg{ width:22px; height:22px; color:var(--gold); flex:0 0 auto; margin-top:2px; }
  .feature-item b{ display:block; font-size:13.5px; color:var(--text-1); margin-bottom:3px; }
  .feature-item span{ display:block; font-size:12px; color:var(--text-3); line-height:1.8; }
  .backup-btn{ display:flex; align-items:center; gap:10px; padding:12px 13px; border-radius:var(--radius-md); background:var(--bg-2); border:1px solid var(--line); color:var(--text-1); font-size:13px; font-weight:600; text-align:start; width:100%; }
  .backup-btn:hover{ background:var(--bg-3); }
  .backup-btn svg{ width:18px; height:18px; color:var(--gold); flex:0 0 auto; }
  .backup-btn .bwrap{ flex:1 1 auto; }
  .backup-btn small{ display:block; font-weight:400; color:var(--text-3); margin-top:2px; font-size:11.5px; }
  #restoreFileInput, #importFileInput{ display:none; }

  /* ---------- History drawer ---------- */
  .drawer{
    position:fixed; top:0; bottom:0; right:0; width:340px; max-width:88vw;
    background:var(--bg-1); border-inline-start:1px solid var(--line); z-index:50;
    transform:translateX(110%); transition:transform .26s var(--ease); display:flex; flex-direction:column;
    box-shadow:var(--shadow-lg);
  }
  .drawer.show{ transform:translateX(0); }
  .drawer-head{ padding:16px 18px; border-bottom:1px solid var(--line); display:flex; align-items:center; gap:10px; flex:0 0 auto; }
  .drawer-head h3{ margin:0; font-size:14.5px; font-weight:700; flex:1 1 auto; }
  .drawer-body{ flex:1 1 auto; overflow-y:auto; padding:12px 14px; }
  .ver-item{ padding:11px 12px; border-radius:var(--radius-md); border:1px solid var(--line); background:var(--bg-2); margin-bottom:8px; }
  .ver-top{ display:flex; align-items:center; justify-content:space-between; margin-bottom:5px; }
  .ver-time{ font-size:12.5px; font-weight:700; color:var(--text-1); }
  .ver-badge{ font-size:10.5px; color:var(--gold-light); background:var(--gold-dim); padding:2px 7px; border-radius:99px; }
  .ver-snip{ font-size:12px; color:var(--text-3); line-height:1.7; max-height:56px; overflow:hidden; margin-bottom:8px; }
  .ver-actions{ display:flex; gap:8px; }
  .ver-actions button{ flex:1 1 0; font-size:11.5px; padding:6px 8px; border-radius:7px; border:1px solid var(--line); background:var(--bg-3); color:var(--text-2); }
  .ver-actions button:hover{ background:var(--bg-4); color:var(--text-1); }
  .ver-actions button.restore{ color:var(--gold-light); border-color:rgba(212,162,76,.3); }

  /* ---------- Toast ---------- */
  .toast-wrap{ position:fixed; bottom:18px; inset-inline-start:50%; transform:translateX(-50%); z-index:80; display:flex; flex-direction:column; gap:8px; align-items:center; }
  html[dir="rtl"] .toast-wrap{ transform:translateX(50%); }
  .toast{ background:var(--bg-2); border:1px solid var(--line); color:var(--text-1); padding:10px 16px; border-radius:99px; font-size:12.5px; box-shadow:var(--shadow-sm); display:flex; align-items:center; gap:8px; animation:toastIn .25s var(--ease); }
  .toast svg{ width:15px; height:15px; color:var(--gold); }
  @keyframes toastIn{ from{ opacity:0; transform:translateY(8px);} to{ opacity:1; transform:translateY(0);} }

  /* ---------- Context menu ---------- */
  .ctx-menu{ position:fixed; z-index:70; background:var(--bg-2); border:1px solid var(--line); border-radius:var(--radius-md); box-shadow:var(--shadow-lg); padding:6px; min-width:170px; max-height:calc(100vh - 20px); overflow-y:auto; opacity:0; transform:scale(.96); pointer-events:none; transition:opacity .12s, transform .12s; transform-origin:top; }
  .ctx-menu.show{ opacity:1; transform:scale(1); pointer-events:auto; }
  .ctx-menu button{ width:100%; display:flex; align-items:center; gap:9px; text-align:start; background:transparent; border:none; color:var(--text-1); font-size:13px; padding:9px 10px; border-radius:8px; }
  .ctx-menu button:hover{ background:var(--bg-3); }
  .ctx-menu button svg{ width:15px; height:15px; color:var(--text-3); }
  .ctx-menu button.danger{ color:#ffb3a3; }
  .ctx-menu button.danger svg{ color:#ffb3a3; }
  .ctx-menu hr{ border:none; border-top:1px solid var(--line); margin:5px 2px; }

  .top-banner{
    display:flex; align-items:center; gap:10px; padding:0 14px;
    max-height:0; overflow:hidden; opacity:0;
    background:var(--gold-dim); border-bottom:1px solid transparent;
    transition:max-height .3s var(--ease), opacity .25s var(--ease), padding .3s var(--ease);
    flex:0 0 auto;
  }
  .top-banner.show{ max-height:56px; opacity:1; padding:10px 14px; border-bottom-color:rgba(212,162,76,.25); }
  .top-banner svg{ width:17px; height:17px; color:var(--gold); flex:0 0 auto; }
  .top-banner span{ flex:1 1 auto; font-size:12.5px; color:var(--text-1); min-width:0; }
  .top-banner .tb-action{ font-size:12px; font-weight:700; color:var(--gold-light); background:transparent; border:1px solid rgba(212,162,76,.35); border-radius:99px; padding:5px 12px; flex:0 0 auto; white-space:nowrap; }
  .top-banner .tb-close{ width:24px; height:24px; display:flex; align-items:center; justify-content:center; color:var(--text-3); background:transparent; border:none; flex:0 0 auto; }

  /* ---------- Lock screen ---------- */
  #lockScreen{
    position:fixed; inset:0; z-index:150; display:none; flex-direction:column; align-items:center; justify-content:center; gap:18px;
    background:radial-gradient(1200px 800px at 85% -10%, var(--bg-1) 0%, var(--bg-0) 55%); padding:20px; text-align:center;
  }
  #lockScreen.show{ display:flex; }
  #lockScreen svg{ filter:drop-shadow(0 10px 24px rgba(212,162,76,.25)); }
  .lock-title{ font-size:16px; font-weight:700; color:var(--text-1); }
  .lock-desc{ font-size:12.5px; color:var(--text-3); max-width:260px; }
  .pin-dots{ display:flex; gap:12px; margin:6px 0; }
  .pin-dot{ width:14px; height:14px; border-radius:50%; border:1.5px solid var(--bg-4); background:transparent; transition:background .12s, border-color .12s; }
  .pin-dot.filled{ background:var(--gold); border-color:var(--gold); }
  .pin-dot.err{ background:var(--danger); border-color:var(--danger); }
  .pin-pad{ display:grid; grid-template-columns:repeat(3, 64px); gap:12px; }
  .pin-key{ width:64px; height:64px; border-radius:50%; background:var(--bg-2); border:1px solid var(--line); color:var(--text-1); font-size:19px; font-weight:600; }
  .pin-key:active{ background:var(--bg-3); transform:scale(.96); }
  .pin-key.wide{ font-size:12px; color:var(--text-3); }
  .lock-forgot{ font-size:12px; color:var(--text-3); text-decoration:underline; background:none; border:none; margin-top:6px; }

  /* ---------- Folder / Tag chips ---------- */
  .chip-row{ display:flex; gap:6px; flex-wrap:wrap; }
  .chip{ font-size:11.5px; padding:5px 11px; border-radius:99px; background:var(--bg-2); border:1px solid var(--line); color:var(--text-2); display:flex; align-items:center; gap:5px; white-space:nowrap; }
  .chip.active{ background:var(--gold-dim); color:var(--gold-light); border-color:rgba(212,162,76,.35); }
  .chip svg{ width:11px; height:11px; }
  .chip.add-chip{ color:var(--gold); border-style:dashed; }
  .sort-row{ display:flex; align-items:center; gap:8px; }
  .sort-select{ flex:1 1 auto; background:var(--bg-2); border:1px solid var(--line); color:var(--text-2); border-radius:var(--radius-sm); padding:10px 12px; font-size:13.5px; outline:none; }
  .tag-badge{ font-size:10px; padding:2px 7px; border-radius:99px; background:var(--gold-dim); color:var(--gold-light); }
  .doc-tags{ display:flex; gap:4px; flex-wrap:wrap; margin-top:6px; }
  .folder-lock-ic{ width:12px; height:12px; color:var(--text-3); }

  /* ---------- Editor: Find&Replace bar ---------- */
  .findbar{ display:none; align-items:center; gap:8px; padding:9px 18px; border-bottom:1px solid var(--line); background:var(--bg-1); flex-wrap:wrap; }
  .findbar.show{ display:flex; }
  .findbar input{ background:var(--bg-2); border:1px solid var(--line); color:var(--text-1); border-radius:var(--radius-sm); padding:7px 10px; font-size:12.5px; outline:none; min-width:140px; flex:1 1 140px; }
  .findbar input:focus{ border-color:var(--gold); }
  .findbar .fb-count{ font-size:11.5px; color:var(--text-3); white-space:nowrap; }
  .findbar button{ font-size:12px; padding:7px 10px; border-radius:var(--radius-sm); background:var(--bg-2); border:1px solid var(--line); color:var(--text-2); white-space:nowrap; }
  .findbar button:hover{ background:var(--bg-3); color:var(--text-1); }
  .findbar button.primary{ background:var(--gold-dim); color:var(--gold-light); border-color:rgba(212,162,76,.3); }
  mark.fb-hit{ background:var(--gold-dim); color:inherit; border-radius:2px; }

  /* ---------- Focus / Zen mode ---------- */
  body.zen .topbar, body.zen .sidebar, body.zen .editor-toolbar, body.zen .editor-statusbar{ display:none !important; }
  body.zen .layout, body.zen .editor-pane{ height:100dvh; }
  body.zen .editor-inner{ max-width:700px; padding-top:8vh; }
  .zen-exit{ position:fixed; top:14px; inset-inline-end:14px; z-index:40; display:none; }
  body.zen .zen-exit{ display:flex; }

  /* ---------- Markdown preview ---------- */
  .split-view{ display:flex; gap:0; flex:1 1 auto; min-height:0; }
  .split-view .editor-scroll{ flex:1 1 50%; border-inline-end:1px solid var(--line); }
  .md-preview{ flex:1 1 50%; overflow-y:auto; padding:26px 30px; }
  .md-preview h1,.md-preview h2,.md-preview h3{ color:var(--text-1); margin:.6em 0 .3em; }
  .md-preview p{ color:var(--text-2); line-height:1.9; margin:.5em 0; }
  .md-preview code{ background:var(--bg-2); padding:2px 6px; border-radius:5px; font-family:var(--font-mono); font-size:.9em; }
  .md-preview pre{ background:var(--bg-2); padding:12px; border-radius:var(--radius-sm); overflow-x:auto; }
  .md-preview a{ color:var(--gold-light); }
  .md-preview blockquote{ border-inline-start:3px solid var(--gold); margin:.5em 0; padding-inline-start:12px; color:var(--text-3); }
  .md-preview ul, .md-preview ol{ color:var(--text-2); padding-inline-start:22px; }
  .md-preview del{ color:var(--text-3); text-decoration:line-through; text-decoration-color:var(--danger); }
  .md-spoiler{
    display:inline; border-radius:4px; padding:0 3px; cursor:pointer;
    color:transparent; user-select:none;
    background-image:repeating-linear-gradient(45deg, var(--bg-4) 0, var(--bg-4) 4px, var(--text-3) 4px, var(--text-3) 8px);
    background-size:200% 200%;
    transition:color .12s var(--ease), background-image .12s;
  }
  .md-spoiler.revealed{
    color:var(--text-1); user-select:text; cursor:text;
    background-image:none; background:var(--gold-dim);
  }

  /* ---------- Trash ---------- */
  .trash-banner{ display:flex; align-items:center; gap:8px; padding:10px 12px; margin:0 4px 8px; border-radius:var(--radius-md); background:var(--danger-dim); color:#ffb3a3; font-size:12px; }
  .trash-banner svg{ width:15px; height:15px; flex:0 0 auto; }

  /* ---------- Stats modal ---------- */
  .stats-chart{ width:100%; height:150px; display:block; }
  .stats-legend{ display:flex; justify-content:space-between; font-size:11px; color:var(--text-3); margin-top:6px; }
  .stats-total{ display:flex; gap:18px; margin-bottom:14px; }
  .stats-total .item{ flex:1 1 0; background:var(--bg-2); border:1px solid var(--line); border-radius:var(--radius-md); padding:12px; text-align:center; }
  .stats-total .item b{ display:block; font-size:19px; color:var(--gold-light); }
  .stats-total .item span{ font-size:11px; color:var(--text-3); }


  .sr-only{ position:absolute; width:1px; height:1px; padding:0; margin:-1px; overflow:hidden; clip:rect(0,0,0,0); white-space:nowrap; border:0; }

  /* ---------- Floating action button (quick new document) ---------- */
  .fab{
    position:absolute; bottom:78px; left:18px; z-index:25;
    width:56px; height:56px; border-radius:50%;
    background:linear-gradient(160deg, var(--gold-light), var(--gold));
    color:#241a0a; border:none;
    display:flex; align-items:center; justify-content:center;
    box-shadow:0 10px 26px -6px rgba(212,162,76,.6), 0 2px 8px rgba(0,0,0,.3);
    transition:transform .18s var(--ease), box-shadow .18s var(--ease);
  }
  .fab svg{ width:26px; height:26px; }
  .fab:hover{ transform:translateY(-2px) scale(1.04); box-shadow:0 14px 30px -6px rgba(212,162,76,.7), 0 4px 10px rgba(0,0,0,.35); }
  .fab:active{ transform:translateY(0) scale(.96); }
  body.zen .fab{ display:none; }
  .fab-mini{
    bottom:146px; left:23px; width:46px; height:46px;
    background:var(--bg-1); color:var(--gold);
    border:1.5px solid rgba(212,162,76,.4);
    box-shadow:0 8px 18px -6px rgba(0,0,0,.35);
  }
  .fab-mini svg{ width:20px; height:20px; }
  .fab-mini:hover{ box-shadow:0 10px 22px -6px rgba(0,0,0,.4); background:var(--bg-2); }

  /* ---------- Always phone-shaped layout ---------- */
  .editor-inner{ padding-top:20px; padding-bottom:90px; }
  .drawer{ width:100vw; max-width:100vw; }
  .split-view{ flex-direction:column; }
  .split-view .editor-scroll{ border-inline-end:none; border-bottom:1px solid var(--line); flex:1 1 50%; }
  .pin-pad{ grid-template-columns:repeat(3, 58px); gap:10px; }
  .pin-key{ width:58px; height:58px; }

  /* ---------- Desktop "phone frame" presentation ---------- */
  @media (min-width:481px){
    html, body{ overflow:visible; }
    body{
      display:flex; align-items:center; justify-content:center;
      background:
        radial-gradient(600px 600px at 50% 45%, rgba(212,162,76,.10), transparent 60%),
        #1a1f26;
      min-height:100vh;
      padding:24px 0;
      box-sizing:border-box;
    }
    #app{
      max-width:480px; width:100%; height:calc(100vh - 48px); max-height:860px;
      margin:0 auto; position:relative; overflow:hidden;
      box-shadow:0 30px 90px -16px rgba(0,0,0,.85), 0 0 0 1.5px rgba(212,162,76,.35), 0 0 0 8px rgba(255,255,255,.03);
      border-radius:22px;
    }
    #lockScreen{
      left:50%; right:auto; top:24px; bottom:24px; transform:translateX(-50%);
      width:100%; max-width:480px; height:auto; max-height:860px;
      border-radius:22px; overflow:hidden;
    }
    .sidebar, .drawer{ right:calc(50% - 240px); }
    .drawer{ width:100%; max-width:480px; }
    .brand-name{ display:inline; }
  }
  @media (max-width:480px){
    .brand-name{ display:none; }
  }
