:root {
  --bg: #0f1117;
  --panel: #171a23;
  --panel-2: #1e222e;
  --border: #2a2f3c;
  --text: #e6e8ee;
  --muted: #8b90a0;
  --accent: #a06bff;
  --accent-soft: #2c2150;
  --green: #3ecf8e;
  --yellow: #f0b429;
  --red: #f06363;
  --pink: #ec6ed6;
  --radius: 10px;
  --shadow: 0 8px 30px rgba(0,0,0,.4);
}
/* Light palette: applied when the system prefers light AND the user hasn't forced a theme. */
@media (prefers-color-scheme: light) {
  :root:not([data-theme]) {
    --bg: #f6f4fb; --panel: #ffffff; --panel-2: #f2eefb; --border: #e7e2f0;
    --text: #1a1d26; --muted: #6b7180; --accent: #7c3aed; --accent-soft: #ede5ff; --shadow: 0 6px 24px rgba(0,0,0,.12);
  }
}
/* Explicit user choice via the theme toggle (overrides the system preference). */
[data-theme="light"] {
  --bg: #f6f4fb; --panel: #ffffff; --panel-2: #f2eefb; --border: #e7e2f0;
  --text: #1a1d26; --muted: #6b7180; --accent: #7c3aed; --accent-soft: #ede5ff; --shadow: 0 6px 24px rgba(0,0,0,.12);
}
[data-theme="dark"] {
  --bg: #0f1117; --panel: #171a23; --panel-2: #1e222e; --border: #2a2f3c;
  --text: #e6e8ee; --muted: #8b90a0; --accent: #a06bff; --accent-soft: #2c2150; --shadow: 0 8px 30px rgba(0,0,0,.4);
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font: 14px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  background: var(--bg); color: var(--text);
  -webkit-font-smoothing: antialiased;
}
#app { display: grid; grid-template-columns: 256px 1fr; height: 100vh; }

/* Sidebar */
#sidebar { background: var(--panel); border-right: 1px solid var(--border); padding: 16px 12px; overflow-y: auto; display: flex; flex-direction: column; gap: 14px; }
.brand { font-size: 16px; font-weight: 700; display: flex; align-items: center; gap: 8px; padding: 0 4px; }
.nav-section { font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 6px 4px 4px; display: flex; justify-content: space-between; align-items: center; }
.nav-item { display: flex; align-items: center; gap: 6px; padding: 7px 10px; border-radius: 8px; color: var(--text); cursor: pointer; text-decoration: none; font-size: 13.5px; }
.nav-item:hover { background: var(--panel-2); }
.nav-item.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.nav-item .count { margin-left: auto; background: var(--accent); color: #fff; border-radius: 10px; font-size: 11px; padding: 0 6px; }
.folder-row { display: flex; align-items: center; gap: 6px; padding: 7px 10px; border-radius: 8px; cursor: pointer; font-size: 13.5px; }
.folder-row:hover { background: var(--panel-2); }
.folder-row.active { background: var(--accent-soft); color: var(--accent); }
.folder-row .dot { width: 9px; height: 9px; border-radius: 50%; background: var(--muted); flex: none; }
.folder-row .fcount { margin-left: auto; color: var(--muted); font-size: 12px; }
.folder-row .fdel { opacity: 0; color: var(--muted); }
.folder-row:hover .fdel { opacity: 1; }
.folder-row.drop-hi, .nav-item.drop-hi { background: var(--accent-soft); outline: 1px dashed var(--accent); color: var(--accent); }
.proj-card.dragging { opacity: .4; }

/* Search */
.search-wrap { position: relative; }
#globalSearch { width: 100%; padding: 8px 10px; background: var(--panel-2); border: 1px solid var(--border); border-radius: 8px; color: var(--text); }
.search-results { position: absolute; top: 110%; left: 0; right: 0; background: var(--panel); border: 1px solid var(--border); border-radius: 8px; box-shadow: var(--shadow); z-index: 30; max-height: 60vh; overflow-y: auto; }
.search-results .sr-item { padding: 8px 10px; cursor: pointer; border-bottom: 1px solid var(--border); }
.search-results .sr-item:hover { background: var(--panel-2); }
.search-results .sr-head { font-size: 11px; color: var(--muted); padding: 6px 10px; text-transform: uppercase; }

/* Buttons */
.btn { background: var(--panel-2); color: var(--text); border: 1px solid var(--border); border-radius: 8px; padding: 7px 12px; cursor: pointer; font-size: 13px; }
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.block { width: 100%; }
.btn.danger:hover { border-color: var(--red); color: var(--red); }
.btn.sm { padding: 4px 8px; font-size: 12px; }
.mini { background: none; border: none; color: var(--muted); cursor: pointer; font-size: 16px; line-height: 1; padding: 0 4px; }
.mini:hover { color: var(--accent); }

/* Main */
#main { overflow-y: auto; padding: 22px 26px 60px; }
.list-header { display: flex; align-items: center; gap: 12px; margin-bottom: 16px; flex-wrap: wrap; }
.list-header h1 { font-size: 20px; margin: 0; }
.list-header .spacer { flex: 1; }
.toolbar { display: flex; gap: 8px; align-items: center; }
select, input[type=text], input[type=date], textarea { background: var(--panel-2); border: 1px solid var(--border); color: var(--text); border-radius: 8px; padding: 7px 9px; font: inherit; }
textarea { width: 100%; resize: vertical; min-height: 90px; line-height: 1.55; }

/* Project list */
.proj-card { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 13px 15px; margin-bottom: 10px; cursor: pointer; display: flex; align-items: flex-start; gap: 12px; transition: border-color .12s; }
.proj-card:hover { border-color: var(--accent); }
.proj-card .pc-main { flex: 1; min-width: 0; }
.proj-card .pc-title { font-weight: 600; font-size: 15px; display: flex; align-items: center; gap: 7px; }
.proj-card .pc-desc { color: var(--muted); font-size: 13px; margin-top: 3px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.proj-card .pc-meta { display: flex; gap: 8px; align-items: center; margin-top: 8px; flex-wrap: wrap; }
.badge { font-size: 11px; padding: 2px 8px; border-radius: 20px; font-weight: 600; border: 1px solid transparent; }
.badge.status-open { background: var(--accent-soft); color: var(--accent); }
.badge.status-in_progress { background: rgba(240,180,41,.16); color: var(--yellow); }
.badge.status-blocked { background: rgba(240,99,99,.16); color: var(--red); }
.badge.status-done { background: rgba(62,207,142,.16); color: var(--green); }
.prio { font-size: 11px; color: var(--muted); display: inline-flex; align-items: center; gap: 4px; }
.prio b { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }
.prio.high b { background: var(--red); } .prio.medium b { background: var(--yellow); } .prio.low b { background: var(--muted); }
.tag { font-size: 11px; background: var(--panel-2); border: 1px solid var(--border); padding: 1px 7px; border-radius: 6px; color: var(--muted); }
.muted { color: var(--muted); }
.empty { text-align: center; color: var(--muted); padding: 60px 20px; }
.empty .big { font-size: 40px; }

/* Detail view */
.detail-top { display: flex; align-items: flex-start; gap: 12px; margin-bottom: 6px; }
.back { color: var(--muted); cursor: pointer; }
.back:hover { color: var(--accent); }
.detail-title { font-size: 24px; font-weight: 700; border: 1px solid transparent; border-radius: 8px; padding: 2px 6px; margin: 0; flex: 1; }
.detail-title:hover, .editable:hover { background: var(--panel-2); }
.detail-fields { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin: 10px 0 18px; }
.field-pill { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); }
.detail-desc { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px; margin-bottom: 22px; }
.section-h { font-size: 13px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); margin: 18px 0 10px; display: flex; align-items: center; gap: 8px; }
.entry-composer { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px; margin-bottom: 16px; }
.composer-row { display: flex; gap: 8px; align-items: center; margin-top: 8px; }
.entry { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 14px; margin-bottom: 10px; }
.entry-head { display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--muted); margin-bottom: 6px; }
.entry-head .etype { font-weight: 600; padding: 1px 7px; border-radius: 6px; text-transform: capitalize; }
.etype.note { background: var(--accent-soft); color: var(--accent); }
.etype.summary { background: rgba(236,110,214,.16); color: var(--pink); }
.etype.log { background: var(--panel-2); }
.entry-actions { margin-left: auto; display: flex; gap: 6px; opacity: 0; }
.entry:hover .entry-actions { opacity: 1; }
.entry-actions a { cursor: pointer; color: var(--muted); }
.entry-actions a:hover { color: var(--accent); }
.md { line-height: 1.6; word-wrap: break-word; }
.md h1, .md h2, .md h3 { margin: .6em 0 .3em; }
.md code { background: var(--panel-2); padding: 1px 5px; border-radius: 4px; font-size: 90%; }
.md pre { background: var(--panel-2); padding: 10px; border-radius: 8px; overflow-x: auto; }
.md ul, .md ol { padding-left: 22px; }
.md a { color: var(--accent); }
.md blockquote { border-left: 3px solid var(--border); margin: 0; padding-left: 12px; color: var(--muted); }
.attach-list { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.attach { display: inline-flex; align-items: center; gap: 5px; font-size: 12px; background: var(--panel-2); border: 1px solid var(--border); border-radius: 6px; padding: 3px 8px; text-decoration: none; color: var(--text); }
.attach:hover { border-color: var(--accent); }
.attach .x { color: var(--muted); cursor: pointer; }

/* Inbox */
.inbox-note { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 14px; margin-bottom: 10px; }

/* Toast */
.toast { position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%); background: var(--panel); border: 1px solid var(--border); box-shadow: var(--shadow); border-radius: 10px; padding: 10px 14px; display: flex; align-items: center; gap: 14px; z-index: 100; }
.toast .undo { color: var(--accent); cursor: pointer; font-weight: 600; }

/* Modal */
.modal-host { position: fixed; inset: 0; background: rgba(0,0,0,.5); display: flex; align-items: center; justify-content: center; z-index: 200; }
.modal-box { background: var(--panel); border: 1px solid var(--border); border-radius: 14px; box-shadow: var(--shadow); width: min(540px, 92vw); max-height: 88vh; overflow-y: auto; padding: 20px; }
.modal-box h2 { margin: 0 0 14px; font-size: 18px; }
.form-row { margin-bottom: 12px; }
.form-row label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 4px; }
.form-row input, .form-row select, .form-row textarea { width: 100%; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.rev-item { border: 1px solid var(--border); border-radius: 8px; padding: 10px; margin-bottom: 8px; }
.rev-item .rev-meta { font-size: 12px; color: var(--muted); display: flex; justify-content: space-between; margin-bottom: 6px; }

/* Inline status select on project cards */
.status-select { font-size: 11px; font-weight: 600; border-radius: 20px; border: 1px solid var(--border); padding: 2px 6px; cursor: pointer; -webkit-appearance: none; appearance: none; background: var(--accent-soft); color: var(--accent); }
.status-select.status-in_progress { background: rgba(240,180,41,.16); color: var(--yellow); }
.status-select.status-blocked { background: rgba(240,99,99,.16); color: var(--red); }
.status-select.status-done { background: rgba(62,207,142,.16); color: var(--green); }
.status-select:hover { border-color: var(--accent); }
.status-select option { background: var(--panel); color: var(--text); }

/* Sidebar collapsible sections */
.nav-section { cursor: pointer; user-select: none; }
.nav-section[data-section] > span:nth-child(2) { flex: 1; }
.sec-twist { display: inline-block; transition: transform .12s; font-size: 10px; }
nav.collapsed .sec-twist { transform: rotate(-90deg); }
nav.collapsed .sec-body { display: none; }

/* Finder-style file browser */
.files-box { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 10px 12px 14px; margin-bottom: 22px; }
.files-box.dragover { border-color: var(--accent); background: var(--accent-soft); }
.crumbs { display: flex; align-items: center; gap: 4px; flex-wrap: wrap; margin-bottom: 10px; font-size: 13px; }
.crumb { color: var(--accent); cursor: pointer; padding: 2px 6px; border-radius: 6px; text-decoration: none; }
.crumb:hover { background: var(--panel-2); }
.crumb.drop-hi { background: var(--accent-soft); outline: 1px dashed var(--accent); }
.crumb-sep { color: var(--muted); }
.files-toolbar { display: flex; gap: 8px; align-items: center; margin-bottom: 10px; }
.file-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 6px; min-height: 120px; border-radius: 8px; padding: 4px; }
.file-grid.empty-folder { display: flex; align-items: center; justify-content: center; border: 1.5px dashed var(--border); }
.empty-msg { text-align: center; color: var(--muted); padding: 26px 10px; }
.file-tile { position: relative; display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 12px 6px 8px; border-radius: 9px; cursor: pointer; border: 1px solid transparent; }
.file-tile:hover { background: var(--panel-2); }
.file-tile.drop-hi { background: var(--accent-soft); border-color: var(--accent); border-style: dashed; }
.file-tile.dragging { opacity: .4; }
.tile-icon { font-size: 34px; line-height: 1; pointer-events: none; height: 38px; display: flex; align-items: center; }
.tile-thumb { width: 56px; height: 42px; object-fit: cover; border-radius: 6px; border: 1px solid var(--border); pointer-events: none; background: var(--panel-2); }
.tile-name { font-size: 12px; text-align: center; word-break: break-word; line-height: 1.3; max-height: 2.6em; overflow: hidden; pointer-events: none; }
.tile-size { font-size: 10px; pointer-events: none; }
.tile-act { position: absolute; top: 3px; right: 4px; display: flex; gap: 5px; opacity: 0; background: var(--panel); border: 1px solid var(--border); border-radius: 6px; padding: 1px 4px; }
.file-tile:hover .tile-act { opacity: 1; }
.tile-act a { cursor: pointer; color: var(--muted); font-size: 12px; text-decoration: none; }
.tile-act a:hover { color: var(--accent); }

/* Home: folder grid (file-system style) */
.folder-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; margin-bottom: 8px; }
.folder-tile { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px 14px; cursor: pointer; display: flex; flex-direction: column; align-items: center; gap: 4px; transition: border-color .12s; }
.folder-tile:hover { border-color: var(--accent); }
.folder-tile.drop-hi { background: var(--accent-soft); border-color: var(--accent); border-style: dashed; }
.folder-tile.add-folder { background: transparent; border: 1.5px dashed var(--border); color: var(--muted); justify-content: center; }
.folder-tile.add-folder:hover { border-color: var(--accent); color: var(--accent); background: var(--accent-soft); }
.folder-tile.add-folder .ft-icon { font-size: 30px; font-weight: 300; }
.ft-icon { font-size: 40px; line-height: 1; }
.ft-name { font-weight: 600; text-align: center; word-break: break-word; }
.ft-count { font-size: 12px; }

/* Project-card extras: checkbox, ellipsis, selected state */
.proj-card .pc-check { margin-top: 3px; width: 16px; height: 16px; accent-color: var(--accent); cursor: pointer; flex: none; }
.proj-card.selected { border-color: var(--accent); background: var(--accent-soft); }
.pc-menu { background: none; border: none; color: var(--muted); font-size: 18px; cursor: pointer; padding: 0 6px; line-height: 1; border-radius: 6px; flex: none; align-self: flex-start; }
.pc-menu:hover { background: var(--panel-2); color: var(--accent); }

/* Priority dropdown on cards */
.prio-select { font-size: 11px; font-weight: 600; border-radius: 20px; border: 1px solid var(--border); padding: 2px 6px; cursor: pointer; -webkit-appearance: none; appearance: none; background: var(--panel-2); }
.prio-select.prio-high { color: var(--red); } .prio-select.prio-medium { color: var(--yellow); } .prio-select.prio-low { color: var(--muted); }
.prio-select:hover { border-color: var(--accent); }
.prio-select option { background: var(--panel); color: var(--text); }

/* Bulk-action bar */
.bulk-bar { display: flex; align-items: center; gap: 10px; background: var(--accent-soft); border: 1px solid var(--accent); border-radius: 10px; padding: 8px 12px; margin-bottom: 14px; }
.bulk-bar .spacer { flex: 1; }

/* Popover menu */
.popover { position: fixed; z-index: 300; background: var(--panel); border: 1px solid var(--border); border-radius: 10px; box-shadow: var(--shadow); padding: 5px; min-width: 170px; max-height: 60vh; overflow-y: auto; }
.pop-head { font-size: 11px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); padding: 6px 10px 3px; }
.pop-item { padding: 7px 10px; border-radius: 7px; cursor: pointer; font-size: 13.5px; }
.pop-item:hover { background: var(--panel-2); }
.pop-item.danger { color: var(--red); }
.pop-div { height: 1px; background: var(--border); margin: 5px 4px; }

/* Auth screen */
.auth-screen { position: fixed; inset: 0; display: flex; align-items: center; justify-content: center; background: var(--bg); z-index: 500; }
.auth-card { background: var(--panel); border: 1px solid var(--border); border-radius: 14px; box-shadow: var(--shadow); padding: 28px; width: min(380px, 92vw); }
.auth-brand { font-size: 20px; font-weight: 700; text-align: center; margin-bottom: 20px; }
.auth-error { background: rgba(240,99,99,.14); color: var(--red); border-radius: 8px; padding: 8px 12px; margin-bottom: 12px; font-size: 13px; }
.auth-hint { color: var(--muted); font-size: 12.5px; margin-top: 14px; text-align: center; }
.auth-card .form-row { margin-bottom: 12px; }
.auth-card .form-row label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 4px; }
.auth-card input { width: 100%; padding: 9px 10px; background: var(--panel-2); border: 1px solid var(--border); border-radius: 8px; color: var(--text); }
.auth-card .btn.primary { margin-top: 6px; }

/* Account footer in sidebar */
.account { margin-top: auto; padding-top: 12px; border-top: 1px solid var(--border); display: flex; flex-direction: column; gap: 8px; }
.account-row { display: flex; align-items: center; gap: 6px; }
.account-row .muted { flex: 1; font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.storage-info { font-size: 11px; }

/* Admin-only elements hidden for non-admins */
#app:not(.is-admin) .admin-only { display: none !important; }

/* Sharing modal rows */
.share-row { padding: 8px 4px; border-bottom: 1px solid var(--border); }
.share-row label { display: flex; align-items: center; gap: 10px; cursor: pointer; }
.share-row input[type=checkbox] { width: 17px; height: 17px; accent-color: var(--accent); }

/* Tasks */
.tasks-box { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 10px 12px; margin-bottom: 22px; }
.task-add { display: flex; gap: 8px; margin-bottom: 8px; }
.task-input { flex: 1; padding: 7px 9px; background: var(--panel-2); border: 1px solid var(--border); border-radius: 8px; color: var(--text); font: inherit; }
.task-row { display: flex; align-items: center; gap: 10px; padding: 6px 4px; border-radius: 7px; }
.task-row:hover { background: var(--panel-2); }
.task-check { flex: none; width: 21px; height: 21px; border-radius: 50%; border: 2px solid var(--muted); background: transparent; color: #fff; cursor: pointer; display: flex; align-items: center; justify-content: center; font-size: 12px; line-height: 1; padding: 0; transition: background .12s, border-color .12s; }
.task-check:hover { border-color: var(--green); }
.task-check.done { background: var(--green); border-color: var(--green); }
.task-title { flex: 1; cursor: text; }
.task-title.done { text-decoration: line-through; color: var(--muted); }
.task-del { flex: none; background: none; border: none; color: var(--muted); cursor: pointer; opacity: 0; font-size: 13px; }
.task-row:hover .task-del { opacity: 1; }
.task-del:hover { color: var(--red); }

.hidden { display: none !important; }
.kbd { font-size: 11px; background: var(--panel-2); border: 1px solid var(--border); border-radius: 4px; padding: 1px 5px; color: var(--muted); }
.dragover { border-color: var(--accent) !important; background: var(--accent-soft); }
