/* NoteForge — warm paper + amber identity */
:root {
  --bg: #faf6ef;
  --panel: #ffffff;
  --text: #2d2416;
  --text-muted: #8a7c66;
  --border: #eadfcc;
  --primary: #d97706;
  --primary-dark: #b45309;
  --red: #dc2626;
  --radius: 14px;
  --shadow: 0 2px 5px rgba(120, 84, 20, .06), 0 14px 34px -22px rgba(120, 84, 20, .35);
  --shadow-lift: 0 8px 18px rgba(120, 84, 20, .12), 0 24px 48px -22px rgba(120, 84, 20, .4);
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
html { overflow-x: hidden; scroll-behavior: smooth; }
body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: radial-gradient(ellipse at 15% -10%, rgba(217,119,6,.07), transparent 45%), var(--bg);
  color: var(--text); font-size: 15px; line-height: 1.55; overflow-x: hidden;
}
::selection { background: rgba(217, 119, 6, .22); }
img { max-width: 100%; }
button { font-family: inherit; }
a { color: var(--primary); }
textarea { resize: vertical; }

.btn { display: inline-flex; align-items: center; gap: 7px; padding: 9px 16px; border-radius: 11px; border: 1px solid var(--border); background: var(--panel); color: var(--text); font-size: 13.5px; font-weight: 600; cursor: pointer; transition: transform .12s, box-shadow .15s, background .15s; white-space: nowrap; }
.btn:hover { transform: translateY(-1px); box-shadow: 0 4px 12px rgba(120,84,20,.12); }
.btn.primary { background: linear-gradient(135deg, #f59e0b, #d97706); border-color: transparent; color: #fff; box-shadow: 0 4px 14px rgba(217,119,6,.35); }
.btn.primary:hover { background: linear-gradient(135deg, #fbab1c, #b45309); }
.btn.danger { border-color: #fecaca; color: #b91c1c; }
.btn.small { padding: 5px 11px; font-size: 12.5px; }
.btn.ghost { border-color: transparent; background: transparent; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.input { width: 100%; padding: 10px 13px; border: 1px solid var(--border); border-radius: 11px; font-size: 14px; font-family: inherit; color: var(--text); background: var(--panel); outline: none; transition: border-color .15s, box-shadow .15s; }
.input:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(217, 119, 6, .16); }
.meta { font-size: 11.5px; font-weight: 800; text-transform: uppercase; letter-spacing: .6px; color: var(--text-muted); }
.small-muted { font-size: 12.5px; color: var(--text-muted); }
.toolbar { display: flex; gap: 8px; align-items: center; }
.toolbar.wrap { flex-wrap: wrap; }
.grow { flex: 1; }
.field { display: block; margin-bottom: 12px; }
.field .meta { display: block; margin-bottom: 5px; }
.empty { padding: 60px 20px; text-align: center; color: var(--text-muted); font-size: 14px; }
.avatar { width: 34px; height: 34px; border-radius: 50%; background: linear-gradient(135deg, #f59e0b, #b45309); color: #fff; display: inline-flex; align-items: center; justify-content: center; font-weight: 800; font-size: 12px; cursor: pointer; flex-shrink: 0; }
.toast { position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%); background: #2d2416; color: #fff; padding: 11px 20px; border-radius: 10px; font-size: 13.5px; z-index: 120; box-shadow: 0 8px 30px rgba(0,0,0,.3); max-width: 90vw; }
.toast.error { background: #b91c1c; }
.toast.success { background: #047857; }

/* auth */
.auth-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 24px; background: linear-gradient(135deg, #7c2d12 0%, #d97706 100%); }
.auth-box { width: 100%; max-width: 400px; background: var(--panel); border-radius: 16px; padding: 30px; box-shadow: 0 20px 60px rgba(0,0,0,.35); }
.auth-box h1 { margin: 0 0 4px; font-size: 23px; font-family: Georgia, 'Times New Roman', serif; }
.auth-logo { font-weight: 800; font-size: 20px; color: var(--text); margin-bottom: 16px; }
.auth-logo span { color: var(--primary); }

/* shell */
.nf-shell { min-height: 100vh; display: flex; flex-direction: column; }
.nf-header { display: flex; align-items: center; gap: 12px; padding: 12px 20px; background: rgba(255,252,246,.92); backdrop-filter: blur(8px); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 30; }
.nf-logo { font-weight: 800; font-size: 20px; cursor: pointer; white-space: nowrap; }
.nf-logo span { color: var(--primary); }
.nf-search { max-width: 380px; }
.nf-menu { display: none; font-size: 16px; }
.nf-body { display: flex; flex: 1; min-height: 0; }
.nf-side { width: 240px; flex-shrink: 0; padding: 18px 12px; border-right: 1px solid var(--border); display: flex; flex-direction: column; gap: 3px; }
.side-item { display: flex; align-items: center; justify-content: space-between; gap: 8px; width: 100%; text-align: left; border: none; background: transparent; padding: 8px 12px; border-radius: 10px; font-size: 14px; font-weight: 600; color: var(--text); cursor: pointer; }
.side-item:hover { background: rgba(217,119,6,.08); }
.side-item.active { background: rgba(217,119,6,.14); color: var(--primary-dark); }
.side-count { font-size: 11px; font-weight: 700; color: var(--text-muted); background: rgba(120,84,20,.08); padding: 1px 7px; border-radius: 99px; }
.side-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 12px 4px; }
.side-tags { display: flex; flex-wrap: wrap; gap: 5px; padding: 4px 10px; }
.side-usage { margin-top: auto; padding: 12px; border-top: 1px solid var(--border); }
.nf-main { flex: 1; min-width: 0; padding: 22px; max-width: 1200px; }

/* note grid */
.note-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 14px; }
.note-card { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; cursor: pointer; box-shadow: var(--shadow); transition: transform .13s, box-shadow .16s; display: flex; flex-direction: column; min-height: 130px; }
.note-card:hover { transform: translateY(-3px); box-shadow: var(--shadow-lift); }
.note-card-top { display: flex; align-items: flex-start; gap: 8px; }
.note-title { margin: 0 0 6px; font-size: 16.5px; font-family: Georgia, 'Times New Roman', serif; line-height: 1.3; flex: 1; overflow-wrap: anywhere; }
.note-pin { border: none; background: transparent; cursor: pointer; font-size: 14px; opacity: .25; transition: opacity .15s, transform .15s; padding: 2px; }
.note-card:hover .note-pin { opacity: .7; }
.note-pin.on { opacity: 1 !important; transform: rotate(-18deg); }
.note-excerpt { margin: 0 0 10px; font-size: 13px; color: var(--text-muted); line-height: 1.55; flex: 1; overflow-wrap: anywhere; }
.note-foot { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.tag-chip { display: inline-block; padding: 2px 9px; border-radius: 99px; background: rgba(217,119,6,.12); color: #92500a; font-size: 11.5px; font-weight: 700; cursor: pointer; }
.tag-chip.on { background: var(--primary); color: #fff; }

/* editor */
.editor { max-width: 860px; }
.editor-bar { margin-bottom: 14px; }
.editor-title { width: 100%; border: none; background: transparent; font-size: 32px; font-weight: 700; font-family: Georgia, 'Times New Roman', serif; color: var(--text); outline: none; padding: 4px 0 10px; }
.editor-body { width: 100%; min-height: 56vh; border: 1px solid var(--border); border-radius: 14px; background: var(--panel); padding: 18px; font-family: ui-monospace, 'SF Mono', Menlo, monospace; font-size: 14px; line-height: 1.7; color: var(--text); outline: none; }
.editor-body:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(217,119,6,.14); }
.color-dot { width: 20px; height: 20px; border-radius: 50%; border: 1.5px solid var(--border); cursor: pointer; padding: 0; }
.color-dot.on { border-color: var(--primary); box-shadow: 0 0 0 2px rgba(217,119,6,.3); }

/* markdown preview */
.md-preview { background: var(--panel); border: 1px solid var(--border); border-radius: 14px; padding: 22px 26px; min-height: 56vh; font-size: 15px; line-height: 1.7; overflow-wrap: anywhere; }
.md-preview h2, .md-preview h3, .md-preview h4 { font-family: Georgia, 'Times New Roman', serif; margin: 18px 0 8px; line-height: 1.25; }
.md-preview h2 { font-size: 26px; } .md-preview h3 { font-size: 21px; } .md-preview h4 { font-size: 17px; }
.md-preview p { margin: 0 0 4px; }
.md-preview .md-gap { height: 12px; }
.md-preview code { background: rgba(217,119,6,.1); padding: 1.5px 6px; border-radius: 6px; font-size: .9em; font-family: ui-monospace, Menlo, monospace; }
.md-preview pre { background: #2d2416; color: #f5ead6; padding: 14px 16px; border-radius: 12px; overflow-x: auto; }
.md-preview pre code { background: transparent; color: inherit; padding: 0; }
.md-preview blockquote { margin: 8px 0; padding: 8px 16px; border-left: 3px solid var(--primary); background: rgba(217,119,6,.06); border-radius: 0 10px 10px 0; color: #6b5d45; }
.md-preview ul, .md-preview ol { margin: 6px 0; padding-left: 26px; }
.md-preview ul.md-checks { list-style: none; padding-left: 4px; }
.md-preview .md-check label { display: flex; gap: 9px; align-items: flex-start; cursor: pointer; padding: 3px 0; }
.md-preview .md-check input { margin-top: 4px; cursor: pointer; }
.md-preview .md-check.done span { text-decoration: line-through; color: var(--text-muted); }
.md-preview img { border-radius: 12px; box-shadow: var(--shadow); margin: 8px 0; }
.md-preview hr { border: none; border-top: 1px solid var(--border); margin: 16px 0; }

/* dark theme */
[data-theme="dark"] {
  --bg: #191410;
  --panel: #241e17;
  --text: #ece3d2;
  --text-muted: #a3947c;
  --border: #3a3023;
  --shadow: 0 2px 5px rgba(0,0,0,.35), 0 14px 34px -22px rgba(0,0,0,.7);
  --shadow-lift: 0 8px 18px rgba(0,0,0,.45), 0 24px 48px -22px rgba(0,0,0,.8);
}
[data-theme="dark"] body { background: radial-gradient(ellipse at 15% -10%, rgba(217,119,6,.1), transparent 45%), var(--bg); }
[data-theme="dark"] .nf-header { background: rgba(30, 24, 18, .92); }
[data-theme="dark"] .side-count { background: rgba(217,119,6,.16); }
[data-theme="dark"] .tag-chip { background: rgba(217,119,6,.2); color: #f0b262; }
[data-theme="dark"] .md-preview pre { background: #141009; }
[data-theme="dark"] .toast { background: #46382f; }
[data-theme="dark"] .md-preview blockquote { color: #c2ae8e; }

/* responsive */
@media (max-width: 760px) {
  .nf-menu { display: inline-flex; }
  .nf-side { position: fixed; top: 59px; left: 0; bottom: 0; z-index: 40; background: var(--bg); transform: translateX(-100%); transition: transform .2s; box-shadow: 8px 0 30px rgba(0,0,0,.15); overflow-y: auto; }
  .nf-side.open { transform: translateX(0); }
  .nf-main { padding: 14px 12px; }
  .nf-search { min-width: 0; flex: 1; }
  .nf-header { padding: 10px 12px; gap: 8px; }
  .nf-header .btn.primary { padding: 9px 12px; }
  .editor-title { font-size: 25px; }
  .input { font-size: 16px; min-height: 44px; }
  .note-grid { grid-template-columns: 1fr 1fr; gap: 10px; }
}
@media (max-width: 480px) {
  .note-grid { grid-template-columns: 1fr; }
  .nf-logo { display: none; }
}

/* Partner link chips */
.link-chip { background: rgba(13,148,136,.12); color: #0f5e56; }
.link-chip a { color: inherit; text-decoration: none; }
.link-chip.tc { background: rgba(99,102,241,.12); color: #4338ca; }

/* ── Modals & templates ─────────────────────────── */
.nf-modal-wrap { position: fixed; inset: 0; background: rgba(30, 25, 15, .45); display: flex; align-items: center; justify-content: center; z-index: 90; padding: 16px; }
.nf-modal { background: var(--panel, #fff); border-radius: 12px; box-shadow: 0 24px 60px rgba(0,0,0,.35); padding: 18px 20px; width: 100%; max-width: 620px; max-height: 88vh; overflow: auto; }
.tpl-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 10px; }
.tpl-card { border: 1px solid var(--border, #e7e0d2); border-radius: 10px; background: var(--bg-soft, #faf6ef); padding: 18px 12px; font-size: 14.5px; font-weight: 600; cursor: pointer; text-align: center; font-family: inherit; }
.tpl-card:hover { border-color: #d97706; box-shadow: 0 4px 14px rgba(217, 119, 6, .15); }

/* ── Capture bar / AI ───────────────────────────── */
.capture-bar { margin: 2px 0 8px; padding: 6px 8px; border: 1px dashed var(--border, #e7e0d2); border-radius: 10px; }
.rec-on { background: #dc2626 !important; color: #fff !important; animation: nfpulse 1.2s infinite; }
@keyframes nfpulse { 50% { opacity: .65; } }
.ai-btn { color: #9333ea; }
.ai-result { border: 1px solid var(--border, #e7e0d2); border-radius: 10px; padding: 12px 14px; background: var(--bg-soft, #faf6ef); }

/* ── Attachments ────────────────────────────────── */
.att-strip { display: flex; flex-direction: column; gap: 8px; margin-bottom: 12px; }
.att-card { border: 1px solid var(--border, #e7e0d2); border-radius: 10px; padding: 8px 12px; background: var(--bg-soft, #faf6ef); }
.att-head { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.att-head a { font-weight: 600; word-break: break-all; }
.att-card audio, .att-card video { width: 100%; margin-top: 8px; border-radius: 8px; max-height: 320px; }
.att-x { cursor: pointer; opacity: .55; margin-left: auto; padding: 2px 6px; }
.att-x:hover { opacity: 1; color: #dc2626; }
.att-ocr-done { font-size: 12px; color: #16a34a; font-weight: 700; }
.note-excerpt.locked { font-style: italic; opacity: .7; }

/* ── Sketch ─────────────────────────────────────── */
.sketch-modal { max-width: 960px; }
.sketch-canvas { width: 100%; border: 1px solid var(--border, #e7e0d2); border-radius: 10px; touch-action: none; cursor: crosshair; background: #fff; }

/* ── Lock screen ────────────────────────────────── */
.lock-screen { display: flex; justify-content: center; padding-top: 60px; }
.lock-box { text-align: center; max-width: 340px; width: 100%; }
.lock-box h2 { margin: 10px 0 4px; }
.lock-box .input { margin-top: 14px; text-align: center; }

/* ── Tasks ──────────────────────────────────────── */
.nf-h { font-family: Georgia, 'Times New Roman', serif; margin: 4px 0 14px; }
.task-add .input:first-child { flex: 1; }
.task-row { display: flex; align-items: center; gap: 10px; padding: 9px 12px; border: 1px solid var(--border, #e7e0d2); border-radius: 10px; margin-bottom: 7px; background: var(--panel, #fff); }
.task-row.done .task-text { text-decoration: line-through; opacity: .55; }
.task-row input[type="checkbox"] { width: 17px; height: 17px; accent-color: #d97706; }
.task-due { font-size: 12.5px; font-weight: 700; color: #92600a; background: #fdf0d2; padding: 2px 9px; border-radius: 99px; white-space: nowrap; }
.task-due.overdue { color: #b91c1c; background: #fde8e8; }
.task-due.today { color: #1d4ed8; background: #e3f0fd; }

/* ── Home widgets ───────────────────────────────── */
.widget-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(290px, 1fr)); gap: 14px; }
.widget { border: 1px solid var(--border, #e7e0d2); border-radius: 12px; background: var(--panel, #fff); padding: 14px 16px; box-shadow: 0 1px 3px rgba(80, 60, 20, .06); }
.widget-head { display: flex; align-items: center; font-weight: 700; margin-bottom: 10px; font-family: Georgia, serif; }
.widget-row { display: flex; align-items: center; gap: 8px; padding: 6px 4px; border-radius: 8px; text-decoration: none; color: inherit; font-size: 14px; }
.widget-row:hover { background: var(--bg-soft, #faf6ef); }
.widget-row strong { font-weight: 600; }
.widget-row .small-muted { margin-left: auto; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 55%; }
.widget .scratch { width: 100%; min-height: 130px; resize: vertical; font-family: inherit; }
.stat-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.stat { text-align: center; background: var(--bg-soft, #faf6ef); border-radius: 10px; padding: 12px 6px; }
.stat strong { display: block; font-size: 22px; font-family: Georgia, serif; }
.stat span { font-size: 12px; color: var(--text-muted, #8a7d63); }

/* ── Notebook bar / sharing / sections ──────────── */
.nb-bar { border: 1px solid var(--border, #e7e0d2); border-radius: 10px; padding: 8px 12px; margin-bottom: 12px; background: var(--panel, #fff); }
.shared-chip { font-size: 12px; font-weight: 700; background: #e6f6ec; color: #166534; border-radius: 99px; padding: 2px 10px; }
.share-row { display: flex; align-items: center; gap: 8px; padding: 8px 6px; border-bottom: 1px solid var(--border, #e7e0d2); cursor: pointer; }
.share-row:last-child { border-bottom: none; }
.side-sec { padding-left: 18px; }
.side-sec .side-item { font-size: 13.5px; padding-top: 5px; padding-bottom: 5px; }

[data-theme="dark"] .nf-modal, [data-theme="dark"] .widget, [data-theme="dark"] .task-row, [data-theme="dark"] .nb-bar { background: #221c12; border-color: #3a3122; }
[data-theme="dark"] .tpl-card, [data-theme="dark"] .att-card, [data-theme="dark"] .stat, [data-theme="dark"] .ai-result, [data-theme="dark"] .widget-row:hover { background: #2a2316; border-color: #3a3122; }
[data-theme="dark"] .sketch-canvas { background: #fff; }
[data-theme="dark"] .task-due { background: #4d3d0a; color: #ffe380; }
[data-theme="dark"] .task-due.overdue { background: #3a1611; color: #ff9c8f; }
[data-theme="dark"] .shared-chip { background: #0e2e22; color: #7ee2b8; }

.nf-upgrade-link { display: inline-block; margin-top: 6px; font-weight: 700; color: #d97706; text-decoration: none; font-size: 12px; }

.nf-bill-scopes { display: flex; flex-direction: column; gap: 8px; }
.nf-bill-scope { display: flex; align-items: flex-start; gap: 10px; padding: 10px 12px; border: 2px solid var(--border, #e7e0d2); border-radius: 10px; cursor: pointer; }
.nf-bill-scope.active { border-color: #d97706; background: rgba(217, 119, 6, .07); }
.nf-bill-scope input { margin-top: 3px; accent-color: #d97706; }
[data-theme="dark"] .nf-bill-scope { border-color: #3a3122; }
[data-theme="dark"] .nf-bill-scope.active { background: #2a2316; }

.nf-suite-links { padding: 10px 12px 4px; border-top: 1px solid var(--border, #e7e0d2); margin-top: 8px; }
.nf-suite-link { font-size: 12px; font-weight: 700; text-decoration: none; color: var(--text-muted, #8a7d63); padding: 3px 8px; border: 1px solid var(--border, #e7e0d2); border-radius: 99px; white-space: nowrap; }
.nf-suite-link:hover { color: #d97706; border-color: #d97706; }
[data-theme="dark"] .nf-suite-link { border-color: #3a3122; }
