/* Secure Notepad - one clean stylesheet, light + dark. No inline styles needed (CSP: style-src 'self'). */
:root {
  --bg: #f4f5f8;
  --panel: #ffffff;
  --side: #fafbfc;
  --line: #e4e7ee;
  --line-strong: #cfd4de;
  --text: #1d2433;
  --muted: #6b7385;
  --accent: #3b5bdb;
  --accent-soft: #e8edff;
  --accent-text: #fff;
  --hover: #eef0f5;
  --danger: #d1342a;
  --ok: #17803d;
  --warn-bg: #fff5d6;
  --warn-text: #5d4a00;
  --radius: 10px;
  --shadow: 0 8px 30px rgba(20, 30, 60, .12);
  --mono: ui-monospace, "SFMono-Regular", Consolas, "Cascadia Mono", Menlo, "Liberation Mono", monospace;
  --ui: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14161b;
    --panel: #1c1f26;
    --side: #181b21;
    --line: #2b303a;
    --line-strong: #3a4150;
    --text: #e8eaf0;
    --muted: #98a0b2;
    --accent: #7c93ff;
    --accent-soft: #263055;
    --accent-text: #0d1330;
    --hover: #252a34;
    --danger: #ff7a6e;
    --ok: #62d08a;
    --warn-bg: #3b3200;
    --warn-text: #ffe58a;
    --shadow: 0 8px 30px rgba(0, 0, 0, .5);
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; margin: 0; }
body { font: 14px/1.45 var(--ui); color: var(--text); background: var(--bg); }
button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; border: 1px solid var(--line-strong); background: var(--panel); border-radius: 8px; padding: 6px 14px; }
button:hover:not(:disabled) { border-color: var(--accent); }
button:disabled { opacity: .45; cursor: default; }
button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); font-weight: 600; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
input[type=text], input[type=password] { width: 100%; padding: 8px 10px; border: 1px solid var(--line-strong); border-radius: 8px; background: var(--panel); }
kbd { font: 12px var(--ui); color: var(--muted); margin-left: 24px; }
.spacer { flex: 1; }
.hint { color: var(--muted); font-size: 12px; font-weight: 400; }
.msg { min-height: 1.4em; margin: 12px 0 0; font-size: 13px; }
.msg.error { color: var(--danger); }
.msg.ok { color: var(--ok); }
.warn { margin: 0; padding: 10px 12px; border-radius: 8px; background: var(--warn-bg); color: var(--warn-text); font-size: 12px; }

/* ---------- sign in ---------- */
.auth { min-height: 100%; display: flex; align-items: center; justify-content: center; padding: 16px; }
.auth-box { width: 100%; max-width: 420px; background: var(--panel); border: 1px solid var(--line); border-radius: 16px; box-shadow: var(--shadow); overflow: hidden; }
.auth-box > .titlebar { padding: 16px 20px; border-bottom: 1px solid var(--line); font-weight: 600; }
.auth-body { padding: 20px; }
.auth form { display: flex; flex-direction: column; gap: 14px; }
.auth label { display: flex; flex-direction: column; gap: 5px; font-size: 13px; font-weight: 500; }
.tabs { display: flex; gap: 4px; margin-bottom: 16px; border-bottom: 1px solid var(--line); }
.tab { border: 0; border-bottom: 2px solid transparent; border-radius: 0; background: none; padding: 8px 14px; color: var(--muted); }
.tab.active { color: var(--text); border-bottom-color: var(--accent); font-weight: 600; }

/* ---------- app shell ---------- */
.app { display: flex; flex-direction: column; height: 100%; }
.app.busy { cursor: progress; }
.titlebar { display: flex; align-items: center; gap: 10px; padding: 10px 16px; background: var(--panel); border-bottom: 1px solid var(--line); font-weight: 600; }
.brand-mark { color: var(--accent); }
#window-title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }

.menubar { display: flex; align-items: center; gap: 2px; padding: 4px 10px; background: var(--panel); border-bottom: 1px solid var(--line); }
.menu { position: relative; }
.menu-btn { border: 0; background: none; padding: 5px 10px; border-radius: 6px; }
.menu-btn:hover:not(:disabled), .menu-btn[aria-expanded="true"] { background: var(--hover); }
.menu-list { position: absolute; z-index: 20; top: 100%; left: 0; min-width: 230px; padding: 6px; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.menu-list button { display: flex; justify-content: space-between; align-items: center; width: 100%; border: 0; background: none; text-align: left; padding: 7px 10px; border-radius: 6px; }
.menu-list button:hover:not(:disabled) { background: var(--accent-soft); }
.menu-list hr { border: 0; border-top: 1px solid var(--line); margin: 5px 0; }
.menu-hint { margin-left: auto; color: var(--muted); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.account-menu .menu-list { left: auto; right: 0; min-width: 180px; }
.account-button { display: flex; align-items: center; gap: 8px; }
.account-avatar, .sidebar-avatar { width: 24px; height: 24px; border-radius: 50%; background: var(--accent-soft); color: var(--accent); display: inline-flex; align-items: center; justify-content: center; font-size: 12px; font-weight: 600; text-transform: uppercase; }
.account-label { padding: 6px 10px; color: var(--muted); font-size: 12px; }

.body { flex: 1; min-height: 0; display: flex; gap: 14px; padding: 14px; }

/* ---------- sidebar ---------- */
.sidebar { width: 300px; flex: none; display: flex; flex-direction: column; background: var(--side); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.sidebar-actions { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; padding: 0 10px 10px; }
.sidebar-actions button { display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 8px 4px; font-size: 12px; border-radius: 10px; background: var(--panel); }
.sidebar-head { display: flex; align-items: center; gap: 4px; padding: 10px 8px 6px 12px; font-size: 11px; font-weight: 600; letter-spacing: .04em; white-space: nowrap; text-transform: uppercase; color: var(--muted); }
.icon-btn { white-space: nowrap; flex: none; border: 0; background: none; padding: 3px 7px; border-radius: 6px; font-size: 13px; letter-spacing: 0; text-transform: none; }
.icon-btn:hover:not(:disabled) { background: var(--hover); }
.path-bar { display: flex; gap: 8px; align-items: center; margin: 0 10px 8px; padding: 5px 8px; border: 1px solid var(--line); border-radius: 8px; background: var(--panel); font-size: 12px; min-width: 0; }
.path-label { color: var(--muted); }
#current-path { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; direction: rtl; text-align: left; }
.tree { flex: 1; overflow: auto; padding: 4px 8px 10px; border-top: 1px solid var(--line); }
.tree .empty { padding: 10px; color: var(--muted); font-style: italic; font-size: 13px; }
.row { display: flex; align-items: center; gap: 10px; min-height: 42px; padding: 8px 12px 8px calc(10px + var(--depth, 0) * 18px); margin-bottom: 2px; border-radius: 10px; color: var(--text); font-size: 15px; cursor: pointer; user-select: none; }
.row:hover { background: var(--hover); }
.row.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.row.root { font-weight: 600; }
.row.drop-target { outline: 2px dashed var(--accent); outline-offset: -2px; background: var(--accent-soft); }
.row.cut-pending { opacity: .5; text-decoration: line-through; }
.row .label { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row .meta { flex: none; padding: 2px 8px; border-radius: 999px; background: var(--hover); color: var(--muted); font-size: 11px; font-weight: 500; }
.row.active .meta { background: var(--panel); color: var(--accent); }
.sidebar-account { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 10px 12px; border-top: 1px solid var(--line); }
.sidebar-user { display: flex; align-items: center; gap: 8px; min-width: 0; }
.sidebar-user-meta { display: flex; flex-direction: column; min-width: 0; line-height: 1.2; }
.sidebar-user-meta small { color: var(--muted); }
.sidebar-logout { padding: 4px 10px; font-size: 12px; }

/* ---------- editor ---------- */
.editor { flex: 1; min-width: 0; min-height: 0; resize: none; margin: 0; padding: 26px 30px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--panel); color: var(--text); font: 15px/1.75 var(--mono); tab-size: 4; white-space: pre-wrap; overflow-wrap: break-word; }
.editor:focus-visible { outline: 2px solid var(--accent-soft); outline-offset: 0; border-color: var(--accent); }
.editor:disabled { color: var(--muted); }
.editor::placeholder { color: var(--muted); opacity: .8; }
.editor.nowrap { white-space: pre; overflow-wrap: normal; overflow: auto; }

/* ---------- spreadsheet ---------- */
.sheet-pane { flex: 1; min-width: 0; min-height: 0; display: flex; flex-direction: column; border: 1px solid var(--line); border-radius: var(--radius); background: var(--panel); overflow: hidden; font-size: 14px; }
.sheet-bar { display: flex; align-items: center; gap: 12px; padding: 7px 12px; border-bottom: 1px solid var(--line); min-height: 38px; font-size: 13px; }
.sheet-ref { min-width: 70px; padding-right: 12px; border-right: 1px solid var(--line); font-weight: 600; color: var(--accent); }
.sheet-fx { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-family: var(--mono); color: var(--muted); }
.sheet-scroll { flex: 1; overflow: auto; outline: none; scroll-padding: 30px 0 0 48px; user-select: none; }
.sheet-table { border-collapse: separate; border-spacing: 0; table-layout: fixed; width: max-content; }
.sheet-table th, .sheet-table td { height: 26px; padding: 0 8px; border-right: 1px solid var(--line); border-bottom: 1px solid var(--line); overflow: hidden; white-space: nowrap; text-overflow: ellipsis; position: relative; }
.sheet-table th { position: sticky; z-index: 1; background: var(--side); color: var(--muted); font-size: 12px; font-weight: 500; text-align: center; cursor: default; }
.sheet-table thead th { top: 0; }
.sheet-table th.row-head { left: 0; cursor: pointer; }
.sheet-table th.corner { left: 0; z-index: 2; }
.sheet-table th.col-head { cursor: col-resize; }
.sheet-table td[data-kind="num"] { text-align: right; font-variant-numeric: tabular-nums; }
.sheet-table td[data-kind="err"] { color: var(--danger); }
.sheet-table td.sel { background: var(--accent-soft); }
.sheet-table td.cur { background: var(--panel); outline: 2px solid var(--accent); outline-offset: -2px; z-index: 0; }
.sheet-input { position: absolute; inset: 0; width: 100%; height: 100%; margin: 0; padding: 0 6px; border: 2px solid var(--accent); border-radius: 0; background: var(--panel); color: var(--text); font: inherit; outline: none; user-select: text; }

/* ---------- status bar ---------- */
.statusbar { display: flex; align-items: center; gap: 4px; padding: 6px 16px; background: var(--panel); border-top: 1px solid var(--line); color: var(--muted); font-size: 12px; }
.statusbar #status { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.statusbar .cell { padding: 0 10px; border-left: 1px solid var(--line); white-space: nowrap; }
.statusbar .lock { color: var(--ok); }

/* ---------- dialog ---------- */
.modal { position: fixed; inset: 0; z-index: 50; display: flex; align-items: center; justify-content: center; padding: 16px; background: rgba(15, 20, 35, .45); }
.dialog { width: 100%; max-width: 440px; background: var(--panel); border: 1px solid var(--line); border-radius: 14px; box-shadow: var(--shadow); overflow: hidden; }
.dialog > .titlebar { border-bottom: 1px solid var(--line); }
.dialog-body { display: flex; flex-direction: column; gap: 12px; padding: 18px 20px; }
.dialog-body p { margin: 0; }
.dialog-body .msg { min-height: 0; margin: 0; }
.dialog-buttons { display: flex; justify-content: flex-end; gap: 8px; padding: 12px 20px; background: var(--side); border-top: 1px solid var(--line); }
.choices { max-height: 240px; overflow: auto; border: 1px solid var(--line); border-radius: 8px; padding: 3px; }
.choice { display: block; width: 100%; text-align: left; border: 0; background: none; padding: 7px 10px; border-radius: 6px; }
.choice:hover { background: var(--hover); }
.choice.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }

/* ---------- distraction-free ---------- */
.app.distraction-free .titlebar, .app.distraction-free .menubar, .app.distraction-free .sidebar { display: none; }
.app.distraction-free .body { justify-content: center; padding: 24px 12px; }
.app.distraction-free .editor, .app.distraction-free .sheet-pane { max-width: 1000px; }

/* ---------- small screens ---------- */
@media (max-width: 760px) {
  .body { flex-direction: column; padding: 10px; gap: 10px; }
  .sidebar { width: auto; max-height: 38vh; }
  .editor { flex: 1 0 260px; padding: 18px 16px; font-size: 14px; }
  .sheet-pane { flex: 1 0 300px; }
  .menu-hint, .statusbar .cell:not(.lock) { display: none; }
}

/* ---------- file-type icons (inline SVG, CSP-safe) ---------- */
.icon, .ico { display: inline-block; flex: none; width: 22px; height: 22px; background: center / contain no-repeat; }
.i-folder { background-image: url("data:image/svg+xml,%3Csvg xmlns=%22http://www.w3.org/2000/svg%22 viewBox=%220 0 24 24%22%3E%3Cpath d=%22M2 6.5A2.5 2.5 0 0 1 4.5 4H9l2.2 2.4H19.5A2.5 2.5 0 0 1 22 8.9V18a2.5 2.5 0 0 1-2.5 2.5h-15A2.5 2.5 0 0 1 2 18z%22 fill=%22%23F2B134%22/%3E%3Cpath d=%22M2 9.5h20V18a2.5 2.5 0 0 1-2.5 2.5h-15A2.5 2.5 0 0 1 2 18z%22 fill=%22%23F7C95C%22/%3E%3C/svg%3E"); }
.i-folder-open { background-image: url("data:image/svg+xml,%3Csvg xmlns=%22http://www.w3.org/2000/svg%22 viewBox=%220 0 24 24%22%3E%3Cpath d=%22M2 6.5A2.5 2.5 0 0 1 4.5 4H9l2.2 2.4H18.5A2.5 2.5 0 0 1 21 8.9V10H6.2a2 2 0 0 0-1.9 1.4L2 18.5z%22 fill=%22%23E09F1F%22/%3E%3Cpath d=%22M5 11.5a1.5 1.5 0 0 1 1.4-1h14.9a1 1 0 0 1 .95 1.3l-2.1 6.6a2 2 0 0 1-1.9 1.4H4.2a1 1 0 0 1-.95-1.3z%22 fill=%22%23F7C95C%22/%3E%3C/svg%3E"); }
.i-file { background-image: url("data:image/svg+xml,%3Csvg xmlns=%22http://www.w3.org/2000/svg%22 viewBox=%220 0 24 24%22%3E%3Cpath d=%22M6 2.5h8.5L19.5 7.5V20a1.5 1.5 0 0 1-1.5 1.5H6A1.5 1.5 0 0 1 4.5 20V4A1.5 1.5 0 0 1 6 2.5z%22 fill=%22%23fff%22 stroke=%22%238D96AB%22 stroke-width=%221.3%22/%3E%3Cpath d=%22M14.5 2.5v5h5%22 fill=%22%23E4E8F2%22 stroke=%22%238D96AB%22 stroke-width=%221.3%22 stroke-linejoin=%22round%22/%3E%3Cpath d=%22M8 12h8M8 15h8M8 18h5%22 stroke=%22%238D96AB%22 stroke-width=%221.3%22 stroke-linecap=%22round%22/%3E%3C/svg%3E"); }
.i-sheet { background-image: url("data:image/svg+xml,%3Csvg xmlns=%22http://www.w3.org/2000/svg%22 viewBox=%220 0 24 24%22%3E%3Crect x=%222.5%22 y=%222.5%22 width=%2219%22 height=%2219%22 rx=%224%22 fill=%22%231D6F42%22/%3E%3Cpath d=%22M8 7.5l8 9M16 7.5l-8 9%22 stroke=%22%23fff%22 stroke-width=%222.4%22 stroke-linecap=%22round%22/%3E%3C/svg%3E"); }
.row::before { content: ""; flex: none; width: 14px; height: 14px; margin-left: -4px; background: currentColor; opacity: .55; -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns=%22http://www.w3.org/2000/svg%22 viewBox=%220 0 24 24%22%3E%3Cpath d=%22M9 6l6 6-6 6%22 fill=%22none%22 stroke=%22%23000%22 stroke-width=%222.4%22 stroke-linecap=%22round%22 stroke-linejoin=%22round%22/%3E%3C/svg%3E") center / 14px no-repeat; mask: url("data:image/svg+xml,%3Csvg xmlns=%22http://www.w3.org/2000/svg%22 viewBox=%220 0 24 24%22%3E%3Cpath d=%22M9 6l6 6-6 6%22 fill=%22none%22 stroke=%22%23000%22 stroke-width=%222.4%22 stroke-linecap=%22round%22 stroke-linejoin=%22round%22/%3E%3C/svg%3E") center / 14px no-repeat; transition: transform .12s; visibility: hidden; }
.row[aria-expanded]::before { visibility: visible; }
.row[aria-expanded="true"]::before { transform: rotate(90deg); }
