/* Theme: dark palette sampled from a Bear (iPad) screenshot; light palette derived from it.
   Font: Avenir Next when installed (iPhone/iPad/Mac), else bundled Nunito Sans (see fonts/fonts.css). */
:root, :root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #2e3234; --bg2: #2a2d2f; --bg3: #4a4e50; --field: #3a3e40;
  --fg: #a4a6a7; --fg-strong: #cbcfd2; --muted: #7d8184;
  --accent: #acbeca; --on-accent: #2e3234;
  --line: #464a4c; --pane: #232628; --sel: #323638; --sel2: #3a3f41;
  --tagbg: #444a4c; --bar: #9fb6c2; --danger: #e0766f; --codebg: #383c3e;
  --ev: #3b4043; --evnote: #3d4d57; --warn-bg: #4a4330; --warn-fg: #e8d9a0;
  --shadow: rgba(0, 0, 0, .35);
}
:root[data-theme="light"] {
  color-scheme: light;
  --bg: #ffffff; --bg2: #f4f5f6; --bg3: #e3e6e8; --field: #eceff1;
  --fg: #3c4043; --fg-strong: #202124; --muted: #80868b;
  --accent: #56778b; --on-accent: #ffffff;
  --line: #e0e3e5; --pane: #e0e3e5; --sel: #eef2f5; --sel2: #e3e9ed;
  --tagbg: #e6eaed; --bar: #9fb6c2; --danger: #c5443b; --codebg: #eef0f2;
  --ev: #eceff1; --evnote: #dce8ef; --warn-bg: #fff3cd; --warn-fg: #664d03;
  --shadow: rgba(0, 0, 0, .2);
}
:root {
  --font: "Avenir Next", "Avenir", "Nunito Sans", -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans Arabic", Tahoma, sans-serif;
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; background: var(--bg); color: var(--fg); font: 16px/1.5 var(--font); -webkit-font-smoothing: antialiased; }
.hidden { display: none !important; }
button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; }
::selection { background: color-mix(in srgb, var(--accent) 35%, transparent); }
a { color: var(--accent); }

/* login */
#login { height: 100%; display: grid; place-items: center; }
#loginForm { display: grid; gap: 12px; width: min(320px, 90vw); }
#loginForm h1 { margin: 0 0 8px; text-align: center; color: var(--fg-strong); font-weight: 800; }
#loginForm input { padding: 12px 14px; border: 0; border-radius: 12px; background: var(--field); outline: 0; }
#loginForm button { padding: 12px; border: 0; border-radius: 12px; background: var(--accent); color: var(--on-accent); font-weight: 700; }
.err { color: var(--danger); min-height: 1.2em; margin: 0; text-align: center; }

/* layout */
#app { height: 100%; display: grid; grid-template-columns: 230px 340px 1fr; }
#sidebar { background: var(--bg2); border-right: 1px solid var(--pane); display: flex; flex-direction: column; overflow: hidden; }
#list { border-right: 1px solid var(--pane); display: flex; flex-direction: column; min-width: 0; overflow: hidden; position: relative; }
#editor { display: flex; flex-direction: column; min-width: 0; overflow: hidden; position: relative; }

.brand { padding: 18px 20px 10px; font-weight: 800; font-size: 18px; color: var(--fg-strong); }
#nav a, #tags a, #folders a, #people a { display: flex; justify-content: space-between; padding: 8px 14px; cursor: pointer; border-radius: 10px; margin: 1px 10px; user-select: none; }
#nav a:hover, #tags a:hover, #folders a:hover, #people a:hover { background: var(--sel); }
#nav a.active, #tags a.active, #folders a.active, #people a.active { background: var(--sel2); color: var(--fg-strong); font-weight: 700; }
.count { color: var(--muted); font-size: 13px; }
.section-title { padding: 16px 20px 4px; font-size: 11px; text-transform: uppercase; letter-spacing: .9px; color: var(--muted); font-weight: 700; }
#sideScroll { overflow-y: auto; flex: 1; padding-bottom: 8px; }
#tags a span.t, #folders a span.t, #people a span.t { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sidebar-foot { padding: 10px 16px; border-top: 1px solid var(--pane); display: flex; gap: 14px; }
.link { background: none; border: 0; color: var(--muted); padding: 4px; }
.link:hover { color: var(--fg-strong); }

header { display: flex; align-items: center; gap: 8px; padding: 10px 14px; min-height: 60px; }
header .spacer { flex: 1; }
#search { flex: 1; padding: 9px 14px; border: 0; border-radius: 20px; background: var(--field); min-width: 0; outline: 0; color: var(--fg-strong); }
#search::placeholder { color: var(--muted); }
.icon { background: var(--bg3); border: 0; font-size: 18px; width: 40px; height: 40px; border-radius: 50%; color: var(--fg-strong); display: inline-grid; place-items: center; padding: 0; }
.icon:hover { filter: brightness(1.12); }
.tool { white-space: nowrap; background: var(--bg3); border: 0; border-radius: 20px; padding: 7px 14px; font-size: 13px; font-weight: 600; color: var(--fg-strong); }
.tool:hover { filter: brightness(1.12); }
.tool.accent { background: var(--accent); color: var(--on-accent); }
.tool.on { box-shadow: inset 0 0 0 2px var(--accent); color: var(--accent); }
.only-mobile { display: none; }
.status { color: var(--muted); font-size: 12px; margin-right: 6px; }

.fab { position: absolute; right: 24px; bottom: 26px; width: 58px; height: 58px; border-radius: 50%; border: 0; background: var(--accent); color: var(--on-accent); display: grid; place-items: center; box-shadow: 0 6px 18px var(--shadow); z-index: 5; }
.fab:hover { filter: brightness(1.06); }
.fab svg { width: 24px; height: 24px; }

.list-title { padding: 6px 24px 6px; font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .8px; font-weight: 700; }
#items { overflow-y: auto; flex: 1; padding: 0 8px 100px; }
.item { position: relative; padding: 14px 16px 14px; border-radius: 14px; cursor: pointer; }
.item::after { content: ''; position: absolute; left: 16px; right: 16px; bottom: 0; border-bottom: 1px solid var(--line); }
.item:hover { background: var(--sel); }
.item.active { background: var(--sel); }
.item.active::after { display: none; }
.item .t { font-weight: 700; font-size: 17px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.item .s { color: var(--fg); opacity: .8; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-top: 2px; }
.item .m { color: var(--muted); font-size: 13px; display: flex; gap: 8px; margin-top: 6px; align-items: center; }
.pill { background: var(--tagbg); border-radius: 12px; padding: 0 9px; color: var(--fg); }
.pill.todo { background: var(--accent); color: var(--on-accent); font-weight: 700; }
.day { padding: 12px 24px 2px; font-size: 12px; font-weight: 700; color: var(--muted); }
.event { padding: 10px 24px; border-bottom: 1px solid var(--line); display: grid; gap: 2px; }
.event .when { color: var(--muted); font-size: 13px; }
.event .who { color: var(--muted); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.event button { justify-self: start; margin-top: 6px; }
.notice { padding: 20px 24px; color: var(--muted); }

#text { flex: 1; width: 100%; border: 0; outline: 0; resize: none; padding: 20px max(28px, calc((100% - 700px) / 2)); background: var(--bg); color: var(--fg); caret-color: var(--accent); font: 17px/1.7 var(--font); tab-size: 2; }
#preview { flex: 1; overflow-y: auto; padding: 20px max(28px, calc((100% - 700px) / 2)); font-size: 17px; line-height: 1.7; }
#preview h1, #preview h2, #preview h3, #preview h4 { line-height: 1.25; font-weight: 800; margin: 1.1em 0 .45em; }
#preview h1 { font-size: 36px; margin-top: .3em; }
#preview h2 { font-size: 29px; }
#preview h3 { font-size: 23px; }
#preview strong { color: var(--fg-strong); }
#preview hr { border: 0; border-top: 1px solid var(--line); margin: 28px 0; }
#preview code { background: var(--codebg); padding: 1px 6px; border-radius: 6px; font-size: .9em; }
#preview pre { background: var(--codebg); padding: 14px; border-radius: 12px; overflow-x: auto; }
#preview pre code { padding: 0; background: none; }
#preview blockquote { margin: 1em 0; padding-left: 18px; border-left: 4px solid var(--bar); border-radius: 2px; }
#preview ul ul { list-style: circle; }
#preview li::marker { color: var(--bar); }
#preview ul:has(input[type=checkbox]) { list-style: none; padding-left: 4px; }
#preview input[type=checkbox] { appearance: none; -webkit-appearance: none; width: 22px; height: 22px; margin: 0 10px -5px 0; border: 2px solid var(--muted); border-radius: 7px; background: transparent; cursor: pointer; display: inline-grid; place-items: center; }
#preview input[type=checkbox]:checked { background: var(--accent); border-color: var(--accent); }
#preview input[type=checkbox]:checked::after { content: '✓'; color: var(--on-accent); font-size: 15px; font-weight: 800; line-height: 1; }
#preview .tag { background: var(--tagbg); color: var(--fg); border-radius: 12px; padding: 2px 10px; font-size: .92em; }
#preview table { border-collapse: collapse; } #preview td, #preview th { border: 1px solid var(--line); padding: 6px 10px; }
.empty { flex: 1; display: grid; place-items: center; color: var(--muted); }
.banner { background: var(--warn-bg); color: var(--warn-fg); padding: 10px 16px; font-size: 14px; display: flex; gap: 10px; align-items: center; }
.banner button { margin-left: auto; }

/* modal + toast */
#modal { position: fixed; inset: 0; background: rgba(0, 0, 0, .55); display: grid; place-items: center; z-index: 10; padding: 12px; }
#modalBox { background: var(--bg2); color: var(--fg); border-radius: 18px; padding: 22px; width: min(560px, 100%); max-height: 86vh; overflow-y: auto; box-shadow: 0 14px 50px var(--shadow); border: 1px solid var(--line); }
#modalBox h2 { margin: 0 0 10px; font-size: 21px; font-weight: 800; color: var(--fg-strong); }
#modalBox label { display: block; margin: 14px 0 5px; font-size: 13px; color: var(--muted); }
#modalBox input[type=text], #modalBox textarea, #modalBox select { width: 100%; padding: 9px 12px; border: 0; border-radius: 12px; background: var(--field); outline: 0; color: var(--fg-strong); }
#modalBox textarea { min-height: 90px; font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 13px; }
.row { display: flex; gap: 8px; justify-content: flex-end; margin-top: 18px; flex-wrap: wrap; }
.sweep-item { padding: 9px 0; border-bottom: 1px solid var(--line); }
.sweep-item .c { font-weight: 700; color: var(--fg-strong); }
.sweep-item .d { color: var(--muted); font-size: 12px; display: flex; gap: 6px; flex-wrap: wrap; margin-top: 3px; }
.sweep-item.done { opacity: .5; }
.ok { color: #7fc79a !important; } .bad { color: var(--danger) !important; }
#toast { position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%); background: var(--bg3); color: var(--fg-strong); padding: 10px 18px; border-radius: 22px; z-index: 20; font-size: 14px; max-width: 90vw; box-shadow: 0 6px 20px var(--shadow); }

/* calendar grid */
#calendar { display: flex; flex-direction: column; min-width: 0; overflow: hidden; }
#app.cal-mode { grid-template-columns: 230px 1fr; }
#app.cal-mode #list, #app.cal-mode #editor { display: none; }
.cal-head { display: flex; align-items: center; gap: 8px; padding: 10px 16px; min-height: 60px; }
.cal-title { font-size: 20px; font-weight: 800; margin: 0 10px; flex: 1; color: var(--fg-strong); }
.seg { display: flex; background: var(--bg3); border-radius: 20px; overflow: hidden; margin-right: 6px; }
.seg button { background: none; border: 0; padding: 7px 14px; font-size: 13px; font-weight: 600; color: var(--fg-strong); }
.seg button.on { background: var(--accent); color: var(--on-accent); border-radius: 20px; }
.cal-body { flex: 1; display: flex; flex-direction: column; min-height: 0; overflow: hidden; border-top: 1px solid var(--line); }
.tg-head, .tg-allday, .tg-grid { display: grid; }
.tg-head { border-bottom: 1px solid var(--line); padding-right: 12px; }
.tg-day { text-align: center; padding: 6px 0; font-size: 12px; color: var(--muted); border-left: 1px solid var(--line); }
.tg-day .num { font-size: 18px; color: var(--fg-strong); margin-left: 2px; display: inline-block; min-width: 30px; line-height: 30px; border-radius: 15px; }
.tg-day.today .num { background: var(--accent); color: var(--on-accent); font-weight: 700; }
.tg-allday { border-bottom: 1px solid var(--line); padding-right: 12px; }
.tg-lbl { font-size: 10px; color: var(--muted); text-align: right; padding: 4px 6px; }
.tg-adcol { border-left: 1px solid var(--line); padding: 2px; display: grid; gap: 2px; align-content: start; min-height: 6px; }
.tg-scroll { flex: 1; overflow-y: auto; }
.tg-hour { font-size: 10px; color: var(--muted); text-align: right; padding-right: 6px; transform: translateY(-7px); }
.tg-col { position: relative; border-left: 1px solid var(--line); }
.tg-col.today { background: color-mix(in srgb, var(--accent) 7%, transparent); }
.tg-cell { border-bottom: 1px solid var(--line); box-sizing: border-box; }
.tg-now { position: absolute; left: 0; right: 0; height: 2px; background: var(--accent); z-index: 3; pointer-events: none; }
.cev { background: var(--ev); color: var(--fg-strong); border-left: 3px solid var(--muted); border-radius: 6px; padding: 1px 6px; font-size: 12px; line-height: 1.35; cursor: pointer; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.cev:hover { filter: brightness(1.12); }
.cev.has-note { background: var(--evnote); border-left-color: var(--accent); }
.cev.timed { position: absolute; z-index: 2; white-space: normal; box-sizing: border-box; }
.cev.narrow { font-size: 11px; padding: 1px 3px; }
.cev.narrow b { display: none; }
.cev b { font-weight: 700; }
.mg { flex: 1; display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); grid-template-rows: 28px repeat(6, minmax(0, 1fr)); overflow: hidden; }
.mg-dow { text-align: center; font-size: 12px; color: var(--muted); padding: 6px 0; border-bottom: 1px solid var(--line); }
.mg-cell { border-right: 1px solid var(--line); border-bottom: 1px solid var(--line); padding: 2px 4px; overflow: hidden; display: flex; flex-direction: column; gap: 2px; cursor: pointer; min-height: 0; }
.mg-cell:hover { background: var(--sel); }
.mg-cell.other { background: var(--bg2); color: var(--muted); }
.mg-num { font-size: 12px; align-self: flex-end; width: 22px; height: 22px; line-height: 22px; text-align: center; border-radius: 11px; }
.mg-cell.today .mg-num { background: var(--accent); color: var(--on-accent); font-weight: 700; }
.mg-more { font-size: 11px; color: var(--muted); }

/* mobile: one pane at a time */
@media (max-width: 860px) {
  #app { grid-template-columns: 1fr; }
  #sidebar, #list, #editor { grid-column: 1; grid-row: 1; }
  #app[data-pane="sidebar"] #list, #app[data-pane="sidebar"] #editor,
  #app[data-pane="list"] #sidebar, #app[data-pane="list"] #editor,
  #app[data-pane="editor"] #sidebar, #app[data-pane="editor"] #list { display: none; }
  .only-mobile { display: inline-grid; }
  .tool { padding: 7px 11px; }
  #btnPin, .status { display: none; }
  #text { padding: 16px 20px; font-size: 18px; }
  #preview { padding: 16px 20px; }
  #app { padding-bottom: env(safe-area-inset-bottom); }
}

/* attachments + sketch editor */
.lbl { display: inline; }
.thumbs { display: flex; gap: 8px; margin-top: 8px; overflow: hidden; }
.thumbs img { height: 64px; width: 96px; object-fit: cover; border-radius: 8px; background: #fff; flex: none; }
.attach { display: flex; gap: 10px; padding: 8px max(28px, calc((100% - 700px) / 2)); overflow-x: auto; border-top: 1px solid var(--line); }
.attach .att { position: relative; flex: none; border: 0; background: none; padding: 0; border-radius: 10px; overflow: hidden; }
.attach .att img { height: 64px; display: block; background: #fff; }
.attach .att span { position: absolute; right: 4px; bottom: 4px; background: var(--accent); color: var(--on-accent); border-radius: 50%; width: 20px; height: 20px; font-size: 12px; display: grid; place-items: center; }
#preview img { max-width: 100%; height: auto; border-radius: 12px; background: #fff; cursor: zoom-in; }
#preview img.sketch { cursor: pointer; }
.sk-overlay { position: fixed; inset: 0; z-index: 30; background: var(--bg); display: flex; flex-direction: column; overscroll-behavior: contain; }
.sk-bar { display: flex; align-items: center; gap: 8px; padding: 8px 12px; background: var(--bg2); border-bottom: 1px solid var(--pane); overflow-x: auto; flex: none; }
.sk-bar .tool { flex: none; } .sk-bar .tool:disabled { opacity: .4; }
.sk-group { display: flex; gap: 6px; align-items: center; flex: none; }
.sk-sw { width: 28px; height: 28px; border-radius: 50%; border: 2px solid transparent; padding: 0; flex: none; }
.sk-sw.on { box-shadow: 0 0 0 2px var(--bg2), 0 0 0 4px var(--accent); }
.sk-size { width: 90px; flex: none; accent-color: var(--accent); }
.sk-finger { font-size: 13px; color: var(--fg-strong); white-space: nowrap; flex: none; }
.sk-spacer { flex: 1; }
.sk-scroll { flex: 1; overflow: auto; padding: 12px; text-align: center; -webkit-overflow-scrolling: touch; overscroll-behavior: contain; }
.sk-canvas { background: #fff; border-radius: 6px; box-shadow: 0 4px 20px var(--shadow); touch-action: none; -webkit-touch-callout: none; user-select: none; -webkit-user-select: none; cursor: crosshair; display: inline-block; vertical-align: top; }
@media (max-width: 860px) {
  .lbl { display: none; }
}
#editor > header { overflow-x: auto; scrollbar-width: none; flex-wrap: nowrap; }
#editor > header::-webkit-scrollbar { display: none; }
#editor > header > * { flex: none; }
#editor > header .spacer { flex: 1 0 0; min-width: 0; }

/* folders, people, meta bar */
.section-title { display: flex; justify-content: space-between; align-items: center; }
.mini { background: none; border: 0; color: var(--muted); font-size: 16px; cursor: pointer; padding: 0 6px; border-radius: 6px; }
.mini:hover { background: var(--sel); color: var(--fg-strong); }
#folders a, #people a { align-items: center; gap: 6px; }
#folders a .n, #people a .n { color: var(--muted); font-size: 12px; margin-left: auto; }
#folders a .edit, #people a .edit { visibility: hidden; background: none; border: 0; color: var(--muted); cursor: pointer; padding: 0 4px; }
#folders a:hover .edit, #people a:hover .edit { visibility: visible; }
@media (hover: none) { #folders a .edit, #people a .edit { visibility: visible; } }
.meta { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; padding: 8px 18px 0; font-size: 13px; }
.chip { display: inline-flex; align-items: center; gap: 6px; background: var(--tagbg); color: var(--fg); border-radius: 14px; padding: 3px 10px; cursor: pointer; border: 0; font: inherit; }
.chip:hover { background: var(--sel2); }
.chip .x { color: var(--muted); padding-left: 2px; }
.chip.folder::before { content: "📁"; font-size: 12px; }
.chip.person::before { content: "👤"; font-size: 12px; }
.chip.add { background: none; border: 1px dashed var(--muted); color: var(--muted); }
.pick { max-height: 280px; overflow-y: auto; margin: 8px 0; }
.pick button { display: block; width: 100%; text-align: left; background: none; border: 0; color: var(--fg); padding: 8px 10px; border-radius: 8px; cursor: pointer; font: inherit; }
.pick button:hover { background: var(--sel); }
.pick small { color: var(--muted); margin-left: 6px; }
.modal-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 12px; flex-wrap: wrap; }
