/* ==========================================================================
   KDPika Notes — styles
   Minimal, neutral, light & dark, LTR & RTL (logical properties throughout)
   ========================================================================== */

:root {
  --font: ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI Variable Text", "Segoe UI", Roboto,
          "Helvetica Neue", Arial, "Noto Sans", "Noto Sans Arabic", "Geeza Pro", Tahoma, sans-serif;
  --font-ar: "Noto Sans Arabic", "Segoe UI", "Geeza Pro", "SF Arabic", Tahoma, sans-serif;

  --sidebar-w: 248px;
  --sidebar-collapsed-w: 64px;
  --list-w: 320px;

  --radius-lg: 14px;
  --radius: 10px;
  --radius-sm: 7px;

  --ease: cubic-bezier(.2, .7, .2, 1);
  --dur: 180ms;
}

/* ---------- Light theme ---------- */
:root,
[data-theme="light"] {
  --bg: #F7F6F3;
  --surface: #FFFFFF;
  --surface-2: #FBFAF8;
  --hover: rgba(29, 28, 26, .045);
  --active: rgba(29, 28, 26, .075);
  --selected: #F1EFEA;
  --border: #ECEAE4;
  --border-strong: #DEDBD3;
  --text: #1D1C1A;
  --text-2: #5E5B55;
  --text-3: #9C988F;
  --primary: #1D1C1A;
  --primary-hover: #34322E;
  --primary-text: #FAFAF8;
  --accent: #C98A3D;          /* "temporary" indicator */
  --accent-soft: rgba(201, 138, 61, .12);
  --danger: #BF3F2C;
  --danger-soft: rgba(191, 63, 44, .09);
  --focus: rgba(29, 28, 26, .28);
  --shadow-pop: 0 14px 34px -14px rgba(32, 26, 16, .22), 0 2px 6px rgba(32, 26, 16, .06);
  --shadow-drawer: 0 0 40px rgba(32, 26, 16, .14);
  --overlay: rgba(24, 22, 18, .28);
  color-scheme: light;
}

/* ---------- Dark theme ---------- */
[data-theme="dark"] {
  --bg: #121211;
  --surface: #181817;
  --surface-2: #161615;
  --hover: rgba(255, 255, 255, .05);
  --active: rgba(255, 255, 255, .085);
  --selected: #232321;
  --border: #252523;
  --border-strong: #33322F;
  --text: #ECEAE5;
  --text-2: #A9A59D;
  --text-3: #6E6B65;
  --primary: #ECEAE5;
  --primary-hover: #FFFFFF;
  --primary-text: #161615;
  --accent: #DDA25A;
  --accent-soft: rgba(221, 162, 90, .13);
  --danger: #E57562;
  --danger-soft: rgba(229, 117, 98, .12);
  --focus: rgba(236, 234, 229, .35);
  --shadow-pop: 0 16px 40px -14px rgba(0, 0, 0, .7), 0 2px 6px rgba(0, 0, 0, .3);
  --shadow-drawer: 0 0 48px rgba(0, 0, 0, .55);
  --overlay: rgba(0, 0, 0, .5);
  color-scheme: dark;
}

/* ---------- Base ---------- */
*, *::before, *::after { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
  overflow: hidden;
}

html[lang="ar"] body { font-family: var(--font-ar); }
html[lang="ar"] * { letter-spacing: 0 !important; }

button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; background: none; border: 0; padding: 0; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }

.sprite { position: absolute; width: 0; height: 0; overflow: hidden; }

.ic {
  width: 18px; height: 18px; flex: none;
  fill: none; stroke: currentColor; stroke-width: 1.6;
  stroke-linecap: round; stroke-linejoin: round;
}
.ic-sm { width: 16px; height: 16px; }
.ic-xs { width: 13px; height: 13px; stroke-width: 1.8; }

[dir="rtl"] .flip-rtl { transform: scaleX(-1); }

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

:focus { outline: none; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; border-radius: var(--radius-sm); }

.spacer { flex: 1; }
.mobile-only { display: none !important; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 36px; padding-inline: 14px;
  border-radius: var(--radius);
  font-weight: 500; font-size: 13.5px; white-space: nowrap;
  transition: background var(--dur) var(--ease), color var(--dur) var(--ease),
              border-color var(--dur) var(--ease), transform var(--dur) var(--ease);
}
.btn:active { transform: scale(.98); }
.btn-primary { background: var(--primary); color: var(--primary-text); }
.btn-primary:hover { background: var(--primary-hover); }
.btn-secondary { background: var(--surface); border: 1px solid var(--border-strong); color: var(--text); }
.btn-secondary:hover { background: var(--hover); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { filter: brightness(1.06); }

.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 34px; height: 34px; border-radius: var(--radius-sm);
  color: var(--text-2);
  transition: background var(--dur) var(--ease), color var(--dur) var(--ease);
}
.icon-btn:hover { background: var(--hover); color: var(--text); }
.icon-btn-danger:hover { background: var(--danger-soft); color: var(--danger); }

/* ==========================================================================
   App layout
   ========================================================================== */
.app {
  display: grid;
  grid-template-columns: var(--sidebar-w) var(--list-w) minmax(0, 1fr);
  height: 100vh;
  height: 100dvh;
  transition: grid-template-columns 240ms var(--ease);
}

/* ---------- Sidebar ---------- */
.sidebar {
  display: flex; flex-direction: column; gap: 6px;
  min-width: 0;
  padding: 16px 12px 14px;
  background: var(--bg);
  border-inline-end: 1px solid var(--border);
  overflow: hidden;
}

.sidebar-top { display: flex; align-items: center; justify-content: space-between; height: 36px; margin-bottom: 14px; padding-inline: 6px; }

.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand-mark { display: inline-flex; width: 26px; height: 26px; flex: none; }
.brand-mark svg { width: 100%; height: 100%; }
.brand-mark-bg { fill: var(--primary); }
.brand-mark-lines { stroke: var(--primary-text); stroke-width: 1.9; stroke-linecap: round; fill: none; }
.brand-name { font-weight: 650; font-size: 15px; letter-spacing: -.01em; white-space: nowrap; }
.brand-sub { font-weight: 450; color: var(--text-2); }

.drawer-close { display: none; }

.new-note-btn { width: 100%; justify-content: flex-start; padding-inline: 12px; margin-bottom: 10px; }

.nav { display: flex; flex-direction: column; gap: 2px; }

.nav-item {
  display: flex; align-items: center; gap: 10px;
  width: 100%; height: 36px; padding-inline: 10px;
  border-radius: var(--radius-sm);
  color: var(--text-2); font-size: 13.5px; font-weight: 500; text-align: start;
  white-space: nowrap;
  transition: background var(--dur) var(--ease), color var(--dur) var(--ease);
}
.nav-item:hover { background: var(--hover); color: var(--text); }
.nav-item.is-active { background: var(--active); color: var(--text); }
.nav-item .label { flex: 1; overflow: hidden; text-overflow: ellipsis; }

.nav-badge {
  min-width: 22px; height: 20px; padding-inline: 6px;
  display: inline-flex; align-items: center; justify-content: center;
  border-radius: 999px; background: var(--surface); border: 1px solid var(--border);
  font-size: 11.5px; font-weight: 600; color: var(--text-2); font-variant-numeric: tabular-nums;
}

.session-card {
  margin-top: auto;
  margin-bottom: 8px;
  padding: 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
}
.session-head { display: flex; align-items: center; gap: 8px; font-size: 12px; font-weight: 600; color: var(--text); }
.session-count { margin: 8px 0 4px; font-size: 13px; color: var(--text); font-variant-numeric: tabular-nums; }
.session-note { margin: 0; font-size: 12px; line-height: 1.55; color: var(--text-3); }

.live-dot {
  position: relative; width: 7px; height: 7px; flex: none; border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.sidebar-footer { display: flex; flex-direction: column; gap: 2px; padding-top: 8px; border-top: 1px solid var(--border); }

.lang-row {
  position: relative; display: flex; align-items: center; gap: 10px;
  height: 36px; padding-inline: 10px; border-radius: var(--radius-sm); color: var(--text-2);
  transition: background var(--dur) var(--ease);
}
.lang-row:hover { background: var(--hover); color: var(--text); }
.lang-select {
  appearance: none; -webkit-appearance: none;
  position: absolute; inset: 0; width: 100%;
  padding-inline-start: 38px; padding-inline-end: 28px;
  background: transparent; border: 0; border-radius: var(--radius-sm);
  font-size: 13.5px; font-weight: 500; color: inherit; cursor: pointer;
}
.lang-select option { color: var(--text); background: var(--surface); }
.lang-chevron { position: absolute; inset-inline-end: 10px; pointer-events: none; }
.lang-row > .ic:first-child { pointer-events: none; position: relative; z-index: 1; }
.lang-cycle { display: none; }
.lang-code { width: 18px; text-align: center; font-size: 11px; font-weight: 700; letter-spacing: .03em; }

/* ---------- Collapsed sidebar (desktop / tablet) ---------- */
@media (min-width: 721px) {
  .app.sidebar-collapsed { grid-template-columns: var(--sidebar-collapsed-w) var(--list-w) minmax(0, 1fr); }
  .sidebar-collapsed .sidebar { padding-inline: 10px; align-items: center; }
  .sidebar-collapsed .sidebar-top { padding-inline: 0; justify-content: center; }
  .sidebar-collapsed .brand-name,
  .sidebar-collapsed .label,
  .sidebar-collapsed .nav-badge,
  .sidebar-collapsed .session-card,
  .sidebar-collapsed .lang-row { display: none; }
  .sidebar-collapsed .nav, .sidebar-collapsed .sidebar-footer { width: 100%; align-items: center; }
  .sidebar-collapsed .sidebar-footer { margin-top: auto; }
  .sidebar-collapsed .new-note-btn,
  .sidebar-collapsed .nav-item { width: 40px; height: 40px; padding: 0; justify-content: center; }
  .sidebar-collapsed .lang-cycle { display: flex; }
  .sidebar-collapsed .collapse-btn .ic { transform: scaleX(-1); }
  [dir="rtl"] .sidebar-collapsed .collapse-btn .ic { transform: none; }
}
[dir="rtl"] .collapse-btn .ic { transform: scaleX(-1); }

/* ---------- Notes list ---------- */
.list-pane {
  display: flex; flex-direction: column; min-width: 0; min-height: 0;
  background: var(--surface-2);
  border-inline-end: 1px solid var(--border);
}

.list-header { display: flex; align-items: center; gap: 8px; height: 64px; padding: 16px 20px 8px; flex: none; }
.list-title { margin: 0; font-size: 17px; font-weight: 650; letter-spacing: -.015em; white-space: nowrap; }
.list-count { font-size: 12.5px; color: var(--text-3); font-variant-numeric: tabular-nums; }

.search { position: relative; margin: 4px 16px 10px; flex: none; }
.search-icon { position: absolute; inset-inline-start: 11px; top: 50%; transform: translateY(-50%); color: var(--text-3); pointer-events: none; }
.search-input {
  width: 100%; height: 36px;
  padding-inline: 34px 32px;
  border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--surface); color: var(--text); font-size: 13.5px;
  transition: border-color var(--dur) var(--ease), box-shadow var(--dur) var(--ease);
}
.search-input::placeholder { color: var(--text-3); }
.search-input:focus { border-color: var(--border-strong); box-shadow: 0 0 0 3px var(--hover); }
.search-input::-webkit-search-cancel-button { display: none; }
.search-clear {
  position: absolute; inset-inline-end: 5px; top: 50%; transform: translateY(-50%);
  width: 26px; height: 26px; display: inline-flex; align-items: center; justify-content: center;
  border-radius: 6px; color: var(--text-3);
}
.search-clear:hover { background: var(--hover); color: var(--text); }

.note-list { list-style: none; margin: 0; padding: 2px 10px 16px; overflow-y: auto; flex: 1; min-height: 0; }
.note-list li + li { margin-top: 2px; }

.note-item {
  display: block; width: 100%; padding: 11px 12px 12px;
  border-radius: var(--radius); text-align: start;
  border: 1px solid transparent;
  transition: background var(--dur) var(--ease), border-color var(--dur) var(--ease);
}
.note-item:hover { background: var(--hover); }
.note-item.is-active { background: var(--surface); border-color: var(--border); box-shadow: 0 1px 2px rgba(0,0,0,.03); }
[data-theme="dark"] .note-item.is-active { background: var(--selected); }

.note-item-row { display: flex; align-items: baseline; gap: 10px; }
.note-item-title {
  flex: 1; min-width: 0; font-weight: 600; font-size: 13.5px; color: var(--text);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.note-item-title.is-placeholder { color: var(--text-2); font-weight: 500; }
.note-item-time { flex: none; font-size: 11.5px; color: var(--text-3); font-variant-numeric: tabular-nums; }
.note-item-preview {
  margin-top: 3px; font-size: 12.8px; line-height: 1.5; color: var(--text-2);
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
  word-break: break-word;
}
.note-item-preview.is-placeholder { color: var(--text-3); }

.list-empty { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; padding: 32px 28px 64px; }
.list-empty-icon {
  width: 42px; height: 42px; border-radius: 12px; display: inline-flex; align-items: center; justify-content: center;
  background: var(--surface); border: 1px solid var(--border); color: var(--text-3); margin-bottom: 14px;
}
.list-empty-title { margin: 0; font-weight: 600; font-size: 14px; }
.list-empty-body { margin: 6px 0 0; font-size: 13px; color: var(--text-3); max-width: 230px; }
.list-empty .btn { margin-top: 18px; }

/* ---------- Editor pane ---------- */
.editor-pane { display: flex; flex-direction: column; min-width: 0; min-height: 0; background: var(--surface); position: relative; }

.editor-empty { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; padding: 40px 24px 80px; animation: fade-in 300ms var(--ease); }
.editor-empty-title { margin: 26px 0 0; font-size: 20px; font-weight: 650; letter-spacing: -.02em; }
.editor-empty-body { margin: 8px 0 22px; font-size: 14px; color: var(--text-2); max-width: 360px; line-height: 1.6; }

.editor-empty-art { position: relative; width: 92px; height: 104px; }
.sheet { position: absolute; width: 74px; height: 92px; border-radius: 10px; border: 1px solid var(--border-strong); background: var(--surface); }
.sheet-back { inset-inline-start: 18px; top: 0; transform: rotate(7deg); background: var(--bg); }
.sheet-front { inset-inline-start: 0; top: 10px; transform: rotate(-4deg); padding: 18px 14px; display: flex; flex-direction: column; gap: 9px; box-shadow: var(--shadow-pop); }
.sheet-front i { display: block; height: 3px; border-radius: 3px; background: var(--border-strong); }
.sheet-front i:nth-child(1) { width: 70%; background: var(--text-3); opacity: .55; }
.sheet-front i:nth-child(3) { width: 55%; }

.editor-wrap { flex: 1; display: flex; flex-direction: column; min-height: 0; animation: fade-in 220ms var(--ease); }

.editor-header { display: flex; align-items: center; gap: 10px; height: 56px; padding: 10px 20px 0; flex: none; }

.temp-pill {
  display: inline-flex; align-items: center; gap: 8px;
  height: 26px; padding-inline: 10px;
  border-radius: 999px; background: var(--accent-soft);
  font-size: 12px; font-weight: 500; color: var(--text-2); white-space: nowrap;
}
.temp-pill .live-dot { box-shadow: none; }

.back-btn {
  display: inline-flex; align-items: center; gap: 4px; height: 34px; padding-inline: 4px 10px;
  border-radius: var(--radius-sm); color: var(--text); font-weight: 500; font-size: 14px;
}
.back-btn:hover { background: var(--hover); }

/* Toolbar */
.toolbar {
  display: flex; align-items: center; gap: 4px;
  margin: 8px 20px 0; padding: 4px;
  border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--surface);
  overflow-x: auto; scrollbar-width: none; flex: none;
}
.toolbar::-webkit-scrollbar { display: none; }
.tb-group { display: flex; align-items: center; gap: 2px; flex: none; }
.tb-sep { width: 1px; height: 18px; background: var(--border); flex: none; margin-inline: 3px; }

.tb-btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 32px; min-width: 32px; padding-inline: 7px;
  border-radius: var(--radius-sm); color: var(--text-2); font-size: 13px; font-weight: 500;
  transition: background var(--dur) var(--ease), color var(--dur) var(--ease);
}
.tb-btn:hover { background: var(--hover); color: var(--text); }
.tb-btn[aria-pressed="true"], .tb-btn[aria-expanded="true"] { background: var(--active); color: var(--text); }
.tb-btn:disabled { opacity: .35; cursor: default; background: none; }
.tb-menu-label { min-width: 84px; text-align: start; white-space: nowrap; }
.tb-menu-btn .ic-xs { color: var(--text-3); margin-inline-start: -2px; }

/* Writing surface */
.editor-scroll { flex: 1; min-height: 0; overflow-y: auto; scroll-behavior: smooth; }
.editor-inner { max-width: 760px; margin: 0 auto; padding: 36px 56px 30vh; }

.title-input {
  display: block; width: 100%; padding: 0; margin: 0 0 14px;
  border: 0; background: transparent; color: var(--text);
  font-size: 30px; font-weight: 700; line-height: 1.25; letter-spacing: -.025em;
}
.title-input::placeholder { color: var(--text-3); opacity: .7; }

.editor {
  position: relative; min-height: 50vh;
  font-size: 16px; line-height: 1.75; color: var(--text);
  overflow-wrap: break-word; word-break: break-word;
  caret-color: var(--text);
}
html[lang="ar"] .editor { font-size: 16.5px; line-height: 1.9; }
.editor:focus-visible { outline: none; }
.editor.is-empty::before {
  content: attr(data-placeholder);
  position: absolute; inset-inline-start: 0; top: 0;
  color: var(--text-3); pointer-events: none;
}

.editor > :first-child { margin-top: 0; }
.editor p, .editor div { margin: 0; }
.editor h1 { font-size: 1.6em; line-height: 1.3; font-weight: 700; letter-spacing: -.02em; margin: 1.1em 0 .4em; }
.editor h2 { font-size: 1.25em; line-height: 1.35; font-weight: 650; letter-spacing: -.012em; margin: 1em 0 .35em; }
.editor ul, .editor ol { margin: .3em 0; padding-inline-start: 1.5em; }
.editor li { padding-inline-start: .2em; }
.editor li::marker { color: var(--text-3); }
.editor u { text-underline-offset: 3px; text-decoration-thickness: 1px; }
.editor b, .editor strong { font-weight: 650; }

/* Checklist */
.editor ul.checklist { list-style: none; padding-inline-start: 0; }
.editor ul.checklist ul.checklist { padding-inline-start: 1.6em; }
.editor ul.checklist > li { position: relative; padding-inline-start: 30px; margin: .1em 0; }
.editor ul.checklist > li::before {
  content: ""; position: absolute; inset-inline-start: 2px; top: .38em;
  width: 17px; height: 17px; box-sizing: border-box;
  border: 1.5px solid var(--border-strong); border-radius: 5px; background: var(--surface);
  cursor: pointer;
  transition: background var(--dur) var(--ease), border-color var(--dur) var(--ease);
}
html[lang="ar"] .editor ul.checklist > li::before { top: .5em; }
.editor ul.checklist > li:hover::before { border-color: var(--text-3); }
.editor ul.checklist > li[data-checked="true"]::before {
  background: var(--primary) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23FAFAF8' stroke-width='3' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M5.5 12.5l4.2 4.2 8.8-9.2'/%3E%3C/svg%3E") center / 12px no-repeat;
  border-color: var(--primary);
}
[data-theme="dark"] .editor ul.checklist > li[data-checked="true"]::before {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23161615' stroke-width='3' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M5.5 12.5l4.2 4.2 8.8-9.2'/%3E%3C/svg%3E");
}
.editor ul.checklist > li[data-checked="true"] { color: var(--text-3); text-decoration: line-through; text-decoration-color: var(--text-3); }

/* ---------- Popover menus ---------- */
.popover {
  position: fixed; z-index: 60; min-width: 188px; padding: 5px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow-pop);
  animation: pop-in 140ms var(--ease);
  transform-origin: top;
}
.menu-item {
  display: flex; align-items: center; gap: 10px; width: 100%;
  min-height: 34px; padding: 6px 10px; border-radius: var(--radius-sm);
  text-align: start; color: var(--text); font-size: 13.5px;
}
.menu-item:hover, .menu-item:focus-visible { background: var(--hover); outline: none; }
.menu-item > span { flex: 1; }
.menu-item > .ic:first-child { color: var(--text-2); }
.menu-check { opacity: 0; color: var(--text); }
.menu-item[aria-checked="true"] .menu-check { opacity: 1; }
.sample-h1 { font-size: 17px; font-weight: 700; letter-spacing: -.015em; }
.sample-h2 { font-size: 15px; font-weight: 650; }

/* ---------- Modal ---------- */
.modal { position: fixed; inset: 0; z-index: 80; display: flex; align-items: center; justify-content: center; padding: 16px; }
.modal-backdrop { position: absolute; inset: 0; background: var(--overlay); backdrop-filter: blur(2px); animation: fade-in 160ms var(--ease); }
.modal-dialog {
  position: relative; width: min(380px, 100%); padding: 22px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg);
  box-shadow: var(--shadow-pop); animation: pop-in 180ms var(--ease);
}
.modal-icon { width: 36px; height: 36px; border-radius: 10px; display: inline-flex; align-items: center; justify-content: center; background: var(--danger-soft); color: var(--danger); }
.modal-title { margin: 14px 0 6px; font-size: 16px; font-weight: 650; letter-spacing: -.01em; }
.modal-body { margin: 0; color: var(--text-2); font-size: 13.5px; line-height: 1.6; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 22px; }

.backdrop { display: none; }

/* ---------- Animations ---------- */
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes pop-in { from { opacity: 0; transform: translateY(-4px) scale(.98); } to { opacity: 1; transform: none; } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 1ms !important; transition-duration: 1ms !important; }
}

/* ==========================================================================
   Responsive
   ========================================================================== */

/* Laptop / small desktop */
@media (max-width: 1180px) {
  :root { --list-w: 288px; }
  .editor-inner { padding-inline: 40px; }
}

/* Tablet */
@media (max-width: 960px) {
  :root { --list-w: 260px; }
  .editor-inner { padding: 28px 28px 30vh; }
  .title-input { font-size: 26px; }
  .tb-menu-label { display: none; }
  .temp-pill { font-size: 0; gap: 0; width: 26px; padding: 0; justify-content: center; }
  .temp-pill .live-dot { box-shadow: 0 0 0 3px var(--accent-soft); }
}

/* Mobile: list screen  ⟷  full-screen editor */
@media (max-width: 720px) {
  body { font-size: 15px; }
  .app { grid-template-columns: minmax(0, 1fr); grid-template-rows: minmax(0, 1fr); }
  .mobile-only { display: inline-flex !important; }

  .sidebar {
    position: fixed; z-index: 50; inset-block: 0; inset-inline-start: 0;
    width: min(300px, 86vw);
    padding-top: calc(16px + env(safe-area-inset-top));
    padding-bottom: calc(14px + env(safe-area-inset-bottom));
    transform: translateX(-100%);
    transition: transform 260ms var(--ease), visibility 0s linear 260ms;
    visibility: hidden;
    box-shadow: none;
  }
  [dir="rtl"] .sidebar { transform: translateX(100%); }
  .app.drawer-open .sidebar { transform: none; visibility: visible; transition: transform 260ms var(--ease); box-shadow: var(--shadow-drawer); }
  .drawer-close { display: inline-flex; }
  .collapse-btn { display: none; }

  .backdrop {
    display: block; position: fixed; inset: 0; z-index: 45; background: var(--overlay);
    opacity: 0; pointer-events: none; transition: opacity 220ms var(--ease);
  }
  .app.drawer-open .backdrop { opacity: 1; pointer-events: auto; }

  .list-pane, .editor-pane { grid-column: 1; grid-row: 1; border: 0; }
  .list-pane { background: var(--surface); }
  .editor-pane { display: none; }
  .app.view-editor .editor-pane { display: flex; }
  .app.view-editor .list-pane { display: none; }

  .list-header { height: auto; padding: calc(12px + env(safe-area-inset-top)) 12px 6px; }
  .list-title { font-size: 20px; margin-inline-start: 4px; }
  .search { margin: 6px 16px 10px; }
  .search-input { height: 40px; font-size: 16px; } /* 16px avoids iOS zoom */
  .note-list { padding-inline: 8px; padding-bottom: calc(24px + env(safe-area-inset-bottom)); }
  .note-item { padding: 13px 12px 14px; }
  .note-item.is-active { background: transparent; border-color: transparent; box-shadow: none; }
  .note-list li + li .note-item { border-top-color: var(--border); border-radius: 0; }
  .note-item:hover { border-radius: var(--radius); }

  .editor-empty { display: none; }
  .editor-header { height: auto; padding: calc(8px + env(safe-area-inset-top)) 10px 0; }
  .temp-pill { font-size: 12px; gap: 8px; width: auto; padding-inline: 10px; }
  .temp-pill .live-dot { box-shadow: none; }
  .toolbar { margin: 8px 0 0; padding: 4px 6px; gap: 0; border-radius: 0; border-inline: 0; justify-content: space-between; }
  .tb-group { gap: 0; }
  .tb-sep { margin-inline: 2px; }
  .tb-btn { height: 38px; min-width: 31px; padding-inline: 4px; }
  .tb-sep { margin-inline: 1px; }
  .editor-inner { padding: 22px 20px 40vh; }
  .title-input { font-size: 24px; }
  .editor { font-size: 16.5px; }
}

@media (max-width: 380px) {
  .temp-pill { font-size: 0; gap: 0; width: 26px; padding: 0; justify-content: center; }
}
