:root {
    /* surfaces — obsidian warm */
    --bg: #0f0e0c;
    --bg-secondary: #191714;
    --bg-tertiary: #221f1b;
    --border: rgba(200, 180, 150, 0.08);
    --border-emphasis: rgba(200, 180, 150, 0.15);
    --border-strong: rgba(200, 180, 150, 0.25);
    /* text — warm ink */
    --text: #e8e0d4;
    --text-muted: #b8ad9e;
    --text-dim: #5a5248;
    /* accent — amber/gold */
    --accent: #d4a04a;
    --accent-hover: #e0b35a;
    --accent-muted: rgba(212, 160, 74, 0.12);
    /* semantic */
    --green: #7a9e6b;
    --red: #c45c3c;
    --orange: #d4a04a;
    --purple: #7a9bb5;
    --radius: 6px;
    --max-width: 860px;
    /* typography */
    --font-body: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
    --font-mono: 'IBM Plex Mono', 'Menlo', monospace;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

/* Dark-mode scrollbar */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
    background: rgba(200, 180, 150, 0.15);
    border-radius: 4px;
}
::-webkit-scrollbar-thumb:hover { background: rgba(200, 180, 150, 0.25); }
/* Firefox */
* { scrollbar-width: thin; scrollbar-color: rgba(200, 180, 150, 0.15) transparent; }

body {
    font-family: var(--font-body);
    background: var(--bg);
    color: var(--text);
    line-height: 1.6;
    min-height: 100vh;
}

a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-hover); text-decoration: underline; }

/* Layout */
.container { max-width: var(--max-width); margin: 0 auto; padding: 0 20px; }
.header {
    border-bottom: 1px solid var(--border);
    padding: 0;
    position: sticky;
    top: 0;
    z-index: 100;
    background: var(--bg);
}
.header-inner {
    max-width: calc(var(--max-width) + 300px);
    margin: 0 auto;
    padding: 0 24px;
    height: 56px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.logo {
    font-family: var(--font-mono);
    font-size: 1.125rem;
    font-weight: 600;
    letter-spacing: -0.02em;
    color: var(--text);
}
.logo:hover { color: var(--accent); text-decoration: none; }
.header-nav { display: flex; gap: 16px; align-items: center; }
.header-nav a { color: var(--text-muted); font-size: 14px; }
.header-nav a:hover { color: var(--text); text-decoration: none; }

/* Buttons */
.btn {
    display: inline-block;
    padding: 6px 16px;
    font-size: 14px;
    font-weight: 500;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    background: var(--bg-tertiary);
    color: var(--text);
    cursor: pointer;
    text-decoration: none;
    line-height: 1.5;
}
.btn:hover { background: var(--bg-tertiary); text-decoration: none; color: var(--text); }
.btn-primary {
    background: var(--accent);
    border-color: var(--accent);
    color: #0f0e0c;
    font-weight: 600;
}
.btn-primary:hover { background: var(--accent-hover); color: #0f0e0c; }
.btn-danger {
    background: transparent;
    border-color: var(--border);
    color: var(--red);
}
.btn-danger:hover { background: rgba(248,81,73,0.1); color: var(--red); }
.btn-sm { padding: 3px 12px; font-size: 12px; }

/* Forms */
.form-group { margin-bottom: 16px; }
.form-group label {
    display: block;
    font-size: 14px;
    font-weight: 500;
    margin-bottom: 6px;
    color: var(--text);
}
.form-group input,
.form-group textarea,
.form-group select {
    width: 100%;
    padding: 8px 12px;
    font-size: 14px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text);
    font-family: inherit;
}
.form-group input:focus,
.form-group textarea:focus,
.form-group select:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(88,166,255,0.15);
}
.form-group textarea {
    min-height: 300px;
    resize: vertical;
    font-family: var(--font-mono);
    font-size: 13px;
    line-height: 1.5;
}
.form-row { display: flex; gap: 16px; }
.form-row .form-group { flex: 1; }
.form-help { font-size: 12px; color: var(--text-muted); margin-top: 4px; }

/* Cards / Items */
.item-list { display: flex; flex-direction: column; gap: 1px; }
.item-card {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 16px;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    margin-bottom: -1px;
}
.item-card:first-child { border-radius: var(--radius) var(--radius) 0 0; }
.item-card:last-child { border-radius: 0 0 var(--radius) var(--radius); margin-bottom: 0; }
.item-card:only-child { border-radius: var(--radius); }
.item-info { flex: 1; min-width: 0; }
.item-title {
    font-size: 14px;
    font-weight: 600;
    color: var(--accent);
    display: block;
    margin-bottom: 2px;
}
.item-meta {
    font-size: 12px;
    color: var(--text-muted);
    display: flex;
    gap: 12px;
    align-items: center;
    flex-wrap: wrap;
}
.item-actions { display: flex; gap: 8px; align-items: center; flex-shrink: 0; margin-left: 16px; }

/* Badges */
.badge {
    display: inline-block;
    padding: 1px 8px;
    font-size: 11px;
    font-weight: 500;
    border-radius: 10px;
    border: 1px solid;
}
.badge-public { color: var(--green); border-color: rgba(122,158,107,0.3); }
.badge-private { color: var(--red); border-color: rgba(196,92,60,0.3); }
.badge-shared { color: var(--purple); border-color: rgba(122,155,181,0.3); }
.badge-unlisted { color: var(--text-muted); border-color: var(--border-emphasis); }
.badge-note { color: var(--accent); border-color: rgba(212,160,74,0.3); }

/* Search match indicators */
.match-indicator {
    font-size: 10px;
    padding: 1px 6px;
    border-radius: 3px;
    font-weight: 500;
    letter-spacing: 0.02em;
}
.match-title { color: var(--accent); background: rgba(212, 160, 74, 0.1); }
.match-tag { color: var(--green); background: rgba(122, 158, 107, 0.1); }
.match-content { color: var(--text-dim); background: rgba(200, 180, 150, 0.06); }
.badge-list { color: var(--orange); border-color: rgba(210,153,34,0.3); }
.badge-document { color: var(--green); border-color: rgba(63,185,80,0.3); }

.tag {
    display: inline-block;
    padding: 1px 6px;
    font-size: 11px;
    background: rgba(88,166,255,0.1);
    color: var(--accent);
    border-radius: 4px;
}

/* Toolbar */
.toolbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
    gap: 12px;
    flex-wrap: wrap;
}
.toolbar h1 { font-size: 20px; font-weight: 600; }
.search-box {
    display: flex;
    gap: 8px;
    align-items: center;
}
.search-box input {
    padding: 6px 12px;
    font-size: 13px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text);
    width: 220px;
}
.search-box input:focus {
    outline: none;
    border-color: var(--accent);
}
.filter-tabs {
    display: flex;
    gap: 4px;
    margin-bottom: 16px;
}
.filter-tab {
    padding: 4px 12px;
    font-size: 13px;
    color: var(--text-muted);
    border-radius: var(--radius);
    text-decoration: none;
}
.filter-tab:hover { color: var(--text); text-decoration: none; background: var(--bg-tertiary); }
.filter-tab.active {
    color: var(--text);
    background: var(--bg-tertiary);
    font-weight: 500;
}

/* Content rendering */
.content-body {
    line-height: 1.8;
    font-size: 15px;
}
.content-body h1, .content-body h2, .content-body h3 {
    margin-top: 24px;
    margin-bottom: 12px;
    padding-bottom: 4px;
    border-bottom: 1px solid var(--border);
}
.content-body h1 { font-size: 24px; }
.content-body h2 { font-size: 20px; }
.content-body h3 { font-size: 16px; border-bottom: none; }
.content-body p { margin-bottom: 12px; }
.content-body ul, .content-body ol { margin-bottom: 12px; padding-left: 24px; }
.content-body li { margin-bottom: 4px; }
.content-body code {
    background: var(--bg-tertiary);
    padding: 2px 6px;
    border-radius: 3px;
    font-size: 85%;
    font-family: var(--font-mono);
}
.content-body pre {
    background: var(--bg-tertiary);
    padding: 16px;
    border-radius: var(--radius);
    overflow-x: auto;
    margin-bottom: 16px;
}
.content-body pre code { background: none; padding: 0; }
.content-body table {
    width: 100%;
    border-collapse: collapse;
    margin-bottom: 16px;
}
.content-body th, .content-body td {
    border: 1px solid var(--border);
    padding: 8px 12px;
    text-align: left;
}
.content-body th { background: var(--bg-tertiary); font-weight: 600; }
.content-body blockquote {
    border-left: 3px solid var(--border);
    padding-left: 16px;
    color: var(--text-muted);
    margin-bottom: 12px;
}
.content-body a { color: var(--accent); }

/* Auth forms */
.auth-card {
    max-width: 380px;
    margin: 80px auto;
    padding: 32px;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius);
}
.auth-card h1 {
    font-size: 24px;
    margin-bottom: 24px;
    text-align: center;
}

/* Flash messages */
.flash {
    padding: 10px 16px;
    border-radius: var(--radius);
    margin-bottom: 16px;
    font-size: 14px;
    border: 1px solid;
}
.flash-error { background: rgba(248,81,73,0.1); border-color: rgba(248,81,73,0.3); color: var(--red); }
.flash-success { background: rgba(63,185,80,0.1); border-color: rgba(63,185,80,0.3); color: var(--green); }

/* Profile page */
.profile-header {
    margin-bottom: 24px;
    padding-bottom: 16px;
    border-bottom: 1px solid var(--border);
}
.profile-header h1 { font-size: 24px; margin-bottom: 4px; }
.profile-header .username { color: var(--text-muted); font-size: 16px; }

/* Item page */
.item-header {
    margin-bottom: 24px;
}
.item-header h1 { font-size: 28px; margin-bottom: 8px; }
.item-header-meta {
    display: flex;
    gap: 12px;
    align-items: center;
    color: var(--text-muted);
    font-size: 14px;
}

/* Settings */
.key-card {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 16px;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    margin-bottom: 8px;
}
.key-info { flex: 1; }
.key-name { font-weight: 600; font-size: 14px; }
.key-meta { font-size: 12px; color: var(--text-muted); }
.key-reveal {
    margin-top: 12px;
    padding: 12px;
    background: var(--bg-tertiary);
    border-radius: var(--radius);
    font-family: var(--font-mono);
    font-size: 13px;
    word-break: break-all;
    border: 1px solid var(--orange);
}

/* View toggle */
.view-toggle { display: flex; gap: 2px; }
.btn-active {
    background: var(--accent);
    border-color: var(--accent);
    color: #fff;
}
.btn-active:hover { background: var(--accent-hover); color: #fff; }

/* Tree view */
.tree-container {
    border: 1px solid var(--border);
    border-radius: 10px;
    background: var(--bg-secondary);
    overflow: hidden;
}
.tree-row {
    display: flex;
    align-items: stretch;
    height: 38px;
    padding-left: 12px;
    padding-right: 10px;
    border-bottom: 1px solid rgba(200, 180, 150, 0.04);
    animation: treeEnter 0.3s cubic-bezier(0.16, 1, 0.3, 1) both;
    animation-delay: calc(var(--i, 0) * 10ms);
}
.tree-row:last-child { border-bottom: none; }
@keyframes treeEnter {
    from { opacity: 0; transform: translateX(-6px); }
    to   { opacity: 1; transform: translateX(0); }
}
.tree-row--folder { cursor: pointer; }
.tree-row--folder:hover { background: rgba(200, 180, 150, 0.04); }
.tree-row--file:hover,
.tree-row--empty:hover { background: rgba(200, 180, 150, 0.03); }
.tree-row.tree-hidden { display: none !important; }

/* Indent guides — 20px wide to match chevron, center line aligns with parent chevron */
.tree-guide {
    width: 20px;
    flex-shrink: 0;
    position: relative;
}
.tree-guide::after {
    content: '';
    position: absolute;
    left: calc(50% - 0.5px);
    top: 0;
    bottom: 0;
    width: 1px;
    background: rgba(200, 180, 150, 0.08);
    transition: opacity 0.15s, background 0.15s;
}
.tree-row:hover .tree-guide::after {
    background: rgba(200, 180, 150, 0.15);
}

.tree-row-inner {
    display: flex;
    align-items: center;
    flex: 1;
    min-width: 0;
}

/* Chevron */
.tree-chevron {
    width: 20px;
    height: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    border-radius: 3px;
    transition: background 0.1s;
}
.tree-row--folder:hover .tree-chevron { background: rgba(200, 180, 150, 0.08); }
.tree-chevron svg {
    width: 12px;
    height: 12px;
    transition: transform 0.2s cubic-bezier(0.25, 0.46, 0.45, 0.94);
    transform: rotate(90deg);
}
.tree-row--folder.collapsed .tree-chevron svg { transform: rotate(0deg); }
.tree-spacer { width: 20px; flex-shrink: 0; }

/* Icons */
.tree-icon {
    width: 20px;
    height: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    margin-right: 8px;
}
.tree-icon--folder { color: var(--accent); }
.tree-icon--file { color: var(--text-muted); }
.tree-row--folder.collapsed .tree-icon--folder { opacity: 0.65; }

/* Labels */
.tree-name {
    font-size: 14px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    min-width: 0;
}
.tree-row--folder .tree-name {
    font-weight: 600;
    color: var(--text);
}
.tree-row--folder .tree-name a {
    color: inherit;
    text-decoration: none;
}
.tree-row--folder .tree-name a:hover {
    color: var(--accent);
}
.tree-row--file .tree-name a {
    color: var(--text-muted);
    text-decoration: none;
    font-weight: 400;
}
.tree-row--file .tree-name a:hover { color: var(--accent); text-decoration: none; }
.tree-count {
    font-size: 11px;
    color: var(--text-dim);
    margin-left: 8px;
    flex-shrink: 0;
    font-variant-numeric: tabular-nums;
}

/* File metadata */
.tree-meta {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-left: 10px;
    flex-shrink: 0;
}
.tree-vis { font-size: 12px; opacity: 0.5; line-height: 1; }
.tree-badge {
    display: inline-flex;
    align-items: center;
    height: 18px;
    padding: 0 7px;
    font-size: 10px;
    font-weight: 600;
    border-radius: 9px;
    border: 1px solid;
    letter-spacing: 0.02em;
}
.tree-badge--note     { color: var(--accent); border-color: rgba(212, 160, 74, 0.25); }
.tree-badge--list     { color: var(--orange); border-color: rgba(210, 153, 34, 0.25); }
.tree-badge--document { color: var(--green);  border-color: rgba(63, 185, 80, 0.25); }
.tree-tag {
    display: inline-flex;
    align-items: center;
    height: 18px;
    padding: 0 6px;
    font-size: 10px;
    background: rgba(200, 180, 150, 0.07);
    color: var(--accent);
    border-radius: 4px;
}

/* Hover actions */
.tree-actions {
    display: flex;
    gap: 4px;
    margin-left: auto;
    padding-left: 12px;
    flex-shrink: 0;
    opacity: 0;
    transition: opacity 0.12s ease;
}
.tree-row:hover .tree-actions { opacity: 1; }
.tree-btn {
    display: inline-flex;
    align-items: center;
    height: 22px;
    padding: 0 8px;
    font-size: 11px;
    font-weight: 500;
    color: var(--text-muted);
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    border-radius: 4px;
    text-decoration: none;
    transition: color 0.1s, background 0.1s, border-color 0.1s;
    cursor: pointer;
    white-space: nowrap;
}
.tree-btn:hover {
    color: var(--text);
    background: var(--bg-tertiary);
    border-color: #484f58;
    text-decoration: none;
}
.tree-empty-msg {
    font-size: 12px;
    color: var(--text-dim);
    font-style: italic;
}

/* Empty state */
.empty-state {
    text-align: center;
    padding: 48px 20px;
    color: var(--text-muted);
}
.empty-state p { margin-bottom: 16px; font-size: 15px; }

/* Landing */
.hero {
    text-align: center;
    padding: 60px 20px 40px;
}
.hero h1 { font-size: 36px; margin-bottom: 12px; }
.hero p { font-size: 18px; color: var(--text-muted); max-width: 560px; margin: 0 auto 24px; }
.hero-actions { display: flex; gap: 12px; justify-content: center; }

/* Setup / Getting Started */
.setup-section { margin-bottom: 8px; }
.setup-details {
    border: 1px solid var(--border);
    border-radius: var(--radius);
    margin-bottom: 8px;
    background: var(--bg-secondary);
}
.setup-details summary {
    padding: 10px 16px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    color: var(--text);
    list-style: none;
}
.setup-details summary::before {
    content: '\25B6';
    display: inline-block;
    margin-right: 8px;
    font-size: 10px;
    transition: transform 0.15s;
    color: var(--text-muted);
}
.setup-details[open] summary::before { transform: rotate(90deg); }
.setup-details summary:hover { background: var(--bg-tertiary); }
.setup-body {
    padding: 0 16px 16px;
    font-size: 14px;
    line-height: 1.6;
}
.setup-body p { margin-bottom: 10px; color: var(--text-muted); }
.setup-note { font-size: 13px; color: var(--text-dim); }
.setup-note strong { color: var(--text-muted); }
.code-block {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 12px 16px;
    margin-bottom: 12px;
    font-family: var(--font-mono);
    font-size: 13px;
    line-height: 1.7;
    overflow-x: auto;
}
.code-block code { color: var(--text); background: none; padding: 0; }
.code-comment { color: var(--text-dim); }

/* Responsive */
@media (max-width: 640px) {
    .form-row { flex-direction: column; gap: 0; }
    .toolbar { flex-direction: column; align-items: stretch; }
    .search-box input { width: 100%; }
    .item-card { flex-direction: column; align-items: flex-start; }
    .item-actions { margin-left: 0; margin-top: 8px; }
    .hero h1 { font-size: 28px; }
}

/* Nav: New button highlight */
.nav-new {
    background: var(--green);
    color: var(--bg) !important;
    padding: 2px 10px;
    border-radius: var(--radius);
    font-weight: 600;
    font-size: 13px;
}
.nav-new:hover {
    opacity: 0.9;
    text-decoration: none !important;
}

/* Badge: public_edit */
.badge-public_edit {
    background: var(--accent-muted);
    color: var(--accent);
    border: 1px solid rgba(212, 160, 74, 0.3);
}

/* SVG visibility badges */
.vis-badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-size: 11px;
    line-height: 1;
    vertical-align: middle;
}
.vis-badge .vis-icon { flex-shrink: 0; vertical-align: middle; }
.vis-badge .vis-icon-sm { margin-left: -2px; }
.vis-badge .vis-label { white-space: nowrap; }
.vis-badge--public  { color: var(--green); }
.vis-badge--private { color: var(--red); }
.vis-badge--shared  { color: var(--purple); }
.vis-badge--unlisted { color: var(--text-muted); }
.vis-badge--public_edit { color: var(--accent); }
.vis-badge--mixed   { color: var(--text-muted); }

/* Nav dropdown */
.nav-dropdown {
    position: relative;
    display: inline-block;
}
.nav-dropdown-toggle {
    background: none;
    border: 1px solid var(--border);
    color: var(--text);
    padding: 4px 10px;
    border-radius: var(--radius);
    cursor: pointer;
    font-size: 14px;
    font-family: inherit;
}
.nav-dropdown-toggle:hover {
    border-color: var(--text-muted);
}
.nav-dropdown-menu {
    display: none;
    position: absolute;
    right: 0;
    top: calc(100% + 6px);
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    min-width: 160px;
    padding: 4px 0;
    z-index: 100;
    box-shadow: 0 8px 24px rgba(0,0,0,0.4);
}
.nav-dropdown.open .nav-dropdown-menu {
    display: block;
}
.nav-dropdown-menu a {
    display: block;
    padding: 8px 14px;
    color: var(--text);
    font-size: 14px;
    text-decoration: none;
}
.nav-dropdown-menu a:hover {
    background: var(--bg-tertiary);
    text-decoration: none;
}
.nav-dropdown-divider {
    height: 1px;
    background: var(--border);
    margin: 4px 0;
}

/* Segmented control (view toggle) */
.seg-control {
    display: inline-flex;
    background: var(--bg-tertiary);
    border-radius: 5px;
    padding: 2px;
    gap: 1px;
}
.seg-control a {
    padding: 3px 12px;
    font-size: 12px;
    color: var(--text-muted);
    text-decoration: none;
    border-radius: 4px;
    transition: all 0.15s;
}
.seg-control a:hover {
    color: var(--text);
    text-decoration: none;
}
.seg-control a.active {
    background: var(--bg-secondary);
    color: var(--text);
    box-shadow: 0 1px 2px rgba(0,0,0,0.2);
}

/* ── Rendered markdown content ─────────────────── */
.rendered-content ul,
.rendered-content ol {
    padding-left: 1.75em;
    margin: 0.5em 0;
}
.rendered-content li {
    margin: 0.25em 0;
    line-height: 1.6;
}
.rendered-content li > ul,
.rendered-content li > ol {
    margin: 0.25em 0;
}
.rendered-content p {
    margin: 0.75em 0;
}
.rendered-content h1, .rendered-content h2, .rendered-content h3,
.rendered-content h4, .rendered-content h5, .rendered-content h6 {
    margin: 1.25em 0 0.5em;
    line-height: 1.3;
}
.rendered-content h1:first-child, .rendered-content h2:first-child,
.rendered-content h3:first-child {
    margin-top: 0;
}
.rendered-content blockquote {
    border-left: 3px solid var(--accent);
    padding: 0.25em 1em;
    margin: 0.75em 0;
    color: var(--text-muted);
}
.rendered-content pre {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 1em;
    overflow-x: auto;
    margin: 0.75em 0;
}
.rendered-content code {
    font-family: var(--font-mono);
    font-size: 0.9em;
}
.rendered-content :not(pre) > code {
    background: var(--bg-tertiary);
    padding: 0.15em 0.4em;
    border-radius: 3px;
}
.rendered-content table {
    border-collapse: collapse;
    margin: 0.75em 0;
    width: 100%;
}
.rendered-content th, .rendered-content td {
    border: 1px solid var(--border);
    padding: 0.5em 0.75em;
    text-align: left;
}
.rendered-content th {
    background: var(--bg-secondary);
    font-weight: 600;
}
.rendered-content hr {
    border: none;
    border-top: 1px solid var(--border);
    margin: 1.5em 0;
}
.rendered-content a {
    color: var(--accent);
}
.rendered-content img {
    max-width: 100%;
    border-radius: 6px;
}
