:root {
    --bg: #f7f8fa;
    --bg-elevated: #ffffff;
    --fg: #1a2130;
    --fg-muted: #5b6472;
    --border: #e1e5ea;
    --accent: #0d3b66;
    --accent-fg: #ffffff;
    --gold: #f4b942;
    --danger: #c53030;
    --danger-bg: #fdecec;
    --success: #1a7f4b;
    --success-bg: #e7f7ee;
    --info: #1a5c96;
    --info-bg: #e5f0fb;
    --owner-fg: #9a6a12;
    --owner-bg: #fbf0da;
    --ins-bg: #d9f4e0;
    --ins-fg: #146c33;
    --del-bg: #fbdadb;
    --del-fg: #8a1f22;
    --radius: 8px;
    --shadow: 0 1px 2px rgba(16, 24, 40, 0.06), 0 1px 3px rgba(16, 24, 40, 0.08);
    color-scheme: light;
}

@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
        --bg: #12151c;
        --bg-elevated: #1b1f29;
        --fg: #e7eaf0;
        --fg-muted: #9aa3b2;
        --border: #2b303c;
        --accent: #5b9bd8;
        --accent-fg: #0b1220;
        --gold: #f4b942;
        --danger: #f47171;
        --danger-bg: #3a1c1c;
        --success: #57c98a;
        --success-bg: #163524;
        --info: #7cb8e8;
        --info-bg: #1a2e42;
        --owner-fg: var(--gold);
        --owner-bg: #3a2f14;
        --ins-bg: #163524;
        --ins-fg: #7fe0a6;
        --del-bg: #3a1c1c;
        --del-fg: #f6a5a7;
        color-scheme: dark;
    }
}

:root[data-theme="dark"] {
    --bg: #12151c;
    --bg-elevated: #1b1f29;
    --fg: #e7eaf0;
    --fg-muted: #9aa3b2;
    --border: #2b303c;
    --accent: #5b9bd8;
    --accent-fg: #0b1220;
    --gold: #f4b942;
    --danger: #f47171;
    --danger-bg: #3a1c1c;
    --success: #57c98a;
    --success-bg: #163524;
    --info: #7cb8e8;
    --info-bg: #1a2e42;
    --owner-fg: var(--gold);
    --owner-bg: #3a2f14;
    --ins-bg: #163524;
    --ins-fg: #7fe0a6;
    --del-bg: #3a1c1c;
    --del-fg: #f6a5a7;
    color-scheme: dark;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    background: var(--bg);
    color: var(--fg);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    line-height: 1.5;
}

a { color: var(--accent); }

.container {
    max-width: 960px;
    margin: 0 auto;
    padding: 0 20px;
}

/* --- Top nav --- */
.nav {
    background: var(--bg-elevated);
    border-bottom: 1px solid var(--border);
}
.nav-inner {
    display: flex;
    align-items: center;
    justify-content: space-between;
    max-width: 960px;
    margin: 0 auto;
    padding: 12px 20px;
}
.brand {
    display: flex;
    align-items: center;
    gap: 8px;
    font-weight: 700;
    font-size: 18px;
    color: var(--fg);
    text-decoration: none;
}
.brand img { height: 28px; width: 28px; }
.nav-links {
    display: flex;
    align-items: center;
    gap: 18px;
    list-style: none;
    margin: 0;
    padding: 0;
}
.nav-links a { color: var(--fg-muted); text-decoration: none; font-size: 14px; }
.nav-links a:hover { color: var(--fg); }

/* --- Buttons / forms --- */
.btn {
    display: inline-block;
    padding: 9px 16px;
    border-radius: var(--radius);
    border: 1px solid transparent;
    background: var(--accent);
    color: var(--accent-fg);
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    text-decoration: none;
    line-height: 1.3;
}
.btn:hover { opacity: 0.92; }
.btn-secondary { background: transparent; border-color: var(--border); color: var(--fg); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-sm { padding: 6px 12px; font-size: 13px; }

.field { margin-bottom: 16px; }
.field label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 6px; color: var(--fg-muted); }
.field input[type="text"], .field input[type="email"], .field input[type="password"],
.field select, .field textarea {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--bg-elevated);
    color: var(--fg);
    font-size: 14px;
}
.field .hint { font-size: 12px; color: var(--fg-muted); margin-top: 4px; }

.pwd-wrap { position: relative; }
.pwd-wrap input[type="password"], .pwd-wrap input[type="text"] { padding-right: 40px; }
.pwd-toggle {
    position: absolute;
    top: 50%;
    right: 8px;
    transform: translateY(-50%);
    display: flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    padding: 0;
    background: none;
    border: none;
    cursor: pointer;
    color: var(--fg-muted);
}
.pwd-toggle:hover { color: var(--fg); }
.pwd-toggle svg { width: 18px; height: 18px; }

.card {
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 24px;
}

/* --- Flash messages --- */
.flash { padding: 12px 16px; border-radius: var(--radius); margin-bottom: 16px; font-size: 14px; }
.flash-success { background: var(--success-bg); color: var(--success); }
.flash-error { background: var(--danger-bg); color: var(--danger); }
.flash-info { background: var(--bg-elevated); border: 1px solid var(--border); color: var(--fg); }

/* --- Usage bar --- */
.usage-bar { background: var(--border); border-radius: 999px; height: 6px; overflow: hidden; }
.usage-bar-fill { background: var(--accent); height: 100%; }
.usage-bar-fill.usage-warn { background: var(--gold); }
.usage-bar-fill.usage-danger { background: var(--danger); }

/* --- Notes list --- */
.note-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 14px 0;
    border-bottom: 1px solid var(--border);
}
.note-row:last-child { border-bottom: none; }
.note-row-clickable { position: relative; cursor: pointer; margin: 0 -12px; padding: 14px 12px; border-radius: var(--radius); }
.note-row-clickable:hover { background: var(--bg); }
.note-row-clickable .stretched-link::after { content: ""; position: absolute; inset: 0; }
.note-title { font-weight: 600; text-decoration: none; color: var(--fg); }
.note-meta { font-size: 12px; color: var(--fg-muted); }
.badge { display: inline-block; font-size: 11px; padding: 2px 8px; border-radius: 999px; background: var(--border); color: var(--fg-muted); }
.badge-owner { background: var(--owner-bg); color: var(--owner-fg); }
.badge-write { background: var(--success-bg); color: var(--success); }
.badge-read { background: var(--info-bg); color: var(--info); }

/* --- Diff view --- */
ins.diff-ins { background: var(--ins-bg); color: var(--ins-fg); text-decoration: none; }
del.diff-del { background: var(--del-bg); color: var(--del-fg); }

/* --- Rich text editor (Quill) --- */
#quill-editor .ql-toolbar { border-color: var(--border); border-radius: var(--radius) var(--radius) 0 0; background: var(--bg-elevated); }
#quill-editor .ql-container { border-color: var(--border); border-radius: 0 0 var(--radius) var(--radius); font-size: 15px; }
#quill-editor .ql-editor { min-height: 480px; color: var(--fg); resize: vertical; overflow-y: auto; }
#quill-editor .ql-editor.ql-blank::before { color: var(--fg-muted); font-style: normal; }
#quill-editor .ql-stroke { stroke: var(--fg-muted); }
#quill-editor .ql-fill { fill: var(--fg-muted); }
#quill-editor .ql-picker-label { color: var(--fg-muted); }

/* --- Note content rendering --- */
.note-content { word-wrap: break-word; }
.note-content img { max-width: 100%; }

/* --- Tables (admin) --- */
table.data-table { width: 100%; border-collapse: collapse; font-size: 14px; }
table.data-table th, table.data-table td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--border); }
table.data-table th { color: var(--fg-muted); font-weight: 600; font-size: 12px; text-transform: uppercase; }

/* --- Spotlight tour --- */
.tour-overlay { position: fixed; inset: 0; background: rgba(0,0,0,0.55); z-index: 1000; }
.tour-tooltip {
    position: absolute; max-width: 280px; background: var(--bg-elevated); color: var(--fg);
    border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; z-index: 1001;
}
.tour-tooltip h4 { margin: 0 0 6px; }
.tour-tooltip p { margin: 0 0 12px; font-size: 13px; color: var(--fg-muted); }
.tour-highlight { position: relative; z-index: 1001; outline: 3px solid var(--gold); border-radius: 4px; }

footer.site-footer { text-align: center; color: var(--fg-muted); font-size: 12px; padding: 32px 0; }
