:root {
    --bg: #0e1116;
    --surface: #161a22;
    --surface-2: #1e232e;
    --surface-3: #262c38;
    --border: #2b313d;
    --border-strong: #3a4250;
    --text: #e6e9f0;
    --muted: #8b93a5;
    --accent: #4c8dff;
    --accent-hover: #3d7ce8;
    --danger: #e0605f;
    --ok: #3fb27f;
    --warn: #d99a3c;
    --radius: 10px;
    --mono: ui-monospace, SFMono-Regular, "Cascadia Code", Consolas, "Liberation Mono", monospace;
}

* {
    box-sizing: border-box;
}

html,
body {
    height: 100%;
}

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
        "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
    font-size: 14px;
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
}

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

code {
    font-family: var(--mono);
    font-size: 13px;
}

/* ---------- 按钮 ---------- */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 8px 16px;
    border: 1px solid var(--border-strong);
    border-radius: var(--radius);
    background: var(--surface-2);
    color: var(--text);
    font-size: 14px;
    font-family: inherit;
    line-height: 1.4;
    cursor: pointer;
    white-space: nowrap;
    transition: background .15s ease, border-color .15s ease;
}

.btn:hover {
    background: var(--surface-3);
}

.btn-sm {
    padding: 5px 12px;
    font-size: 13px;
}

.btn-primary {
    background: var(--accent);
    border-color: var(--accent);
    color: #fff;
}

.btn-primary:hover {
    background: var(--accent-hover);
    border-color: var(--accent-hover);
}

.btn-ghost {
    background: transparent;
    border-color: var(--border);
}

.btn-ghost:hover {
    background: var(--surface-2);
}

.btn-danger {
    background: transparent;
    border-color: var(--border);
    color: var(--danger);
}

.btn-danger:hover {
    background: rgba(224, 96, 95, .12);
    border-color: var(--danger);
}

.btn-block {
    width: 100%;
    padding: 10px 16px;
}

/* ---------- 登录 / 安装页 ---------- */

.auth-page {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    padding: 24px;
}

.auth-card {
    width: 100%;
    max-width: 380px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 32px;
}

.auth-card-wide {
    max-width: 440px;
}

.auth-title {
    margin: 0 0 4px;
    font-size: 20px;
    font-weight: 600;
}

.auth-subtitle {
    margin: 0 0 20px;
    color: var(--muted);
    font-size: 13px;
}

.auth-form {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.field {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.field-label {
    color: var(--muted);
    font-size: 13px;
}

input[type="text"],
input[type="password"],
input[type="search"] {
    width: 100%;
    padding: 9px 12px;
    background: var(--bg);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius);
    color: var(--text);
    font-size: 14px;
    font-family: inherit;
    outline: none;
    transition: border-color .15s ease;
}

input:focus {
    border-color: var(--accent);
}

.captcha-row {
    display: flex;
    gap: 10px;
    align-items: stretch;
}

.captcha-row input {
    flex: 1;
    text-transform: uppercase;
}

.captcha-img {
    height: 44px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    cursor: pointer;
    display: block;
}

/* ---------- 提示条 ---------- */

.alert {
    padding: 10px 14px;
    border-radius: var(--radius);
    font-size: 13px;
    margin-bottom: 16px;
    border: 1px solid transparent;
}

.alert-error {
    background: rgba(224, 96, 95, .12);
    border-color: rgba(224, 96, 95, .4);
    color: #f3b1b1;
}

.alert-ok {
    background: rgba(63, 178, 127, .12);
    border-color: rgba(63, 178, 127, .4);
    color: #a9e5c8;
}

.alert-warn {
    background: rgba(217, 154, 60, .12);
    border-color: rgba(217, 154, 60, .4);
    color: #f0cd93;
}

.hint {
    color: var(--muted);
    font-size: 13px;
}

/* ---------- 列表页 ---------- */

.app-shell {
    max-width: 860px;
    margin: 0 auto;
    padding: 0 20px 60px;
}

.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 18px 0;
    border-bottom: 1px solid var(--border);
    margin-bottom: 20px;
    flex-wrap: wrap;
}

.topbar-left,
.topbar-right {
    display: flex;
    align-items: center;
    gap: 12px;
}

.brand {
    font-size: 16px;
    font-weight: 600;
}

.brand-sub,
.user {
    color: var(--muted);
    font-size: 13px;
}

.inline-form {
    display: inline;
}

.toolbar {
    display: flex;
    gap: 12px;
    margin-bottom: 20px;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
}

.search-form {
    display: flex;
    gap: 8px;
    flex: 1;
    min-width: 240px;
}

.note-list {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.note-item {
    display: flex;
    align-items: center;
    gap: 12px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 14px 16px;
    transition: border-color .15s ease, background .15s ease;
}

.note-item:hover {
    border-color: var(--border-strong);
    background: var(--surface-2);
}

.note-link {
    flex: 1;
    min-width: 0;
    color: inherit;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.note-head {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 12px;
}

.note-title {
    font-size: 15px;
    font-weight: 500;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.note-time {
    color: var(--muted);
    font-size: 12px;
    flex-shrink: 0;
}

.note-excerpt {
    color: var(--muted);
    font-size: 13px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.note-delete {
    flex-shrink: 0;
    opacity: 0;
    transition: opacity .15s ease;
}

.note-item:hover .note-delete,
.note-delete:focus-within {
    opacity: 1;
}

.empty {
    text-align: center;
    padding: 60px 20px;
    color: var(--muted);
}

.empty p {
    margin: 0 0 16px;
}

/* ---------- 编辑页 ---------- */

.editor-page {
    height: 100vh;
    overflow: hidden;
}

.editor-shell {
    display: flex;
    flex-direction: column;
    height: 100vh;
}

.editor-shell .topbar {
    margin: 0;
    padding: 12px 20px;
    flex-shrink: 0;
}

.save-status {
    color: var(--muted);
    font-size: 13px;
}

.save-status[data-kind="ok"] {
    color: var(--ok);
}

.save-status[data-kind="error"] {
    color: var(--danger);
}

.editor-form {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
}

.editor-title {
    margin: 0;
    padding: 18px 24px;
    background: transparent;
    border: none;
    border-bottom: 1px solid var(--border);
    color: var(--text);
    font-size: 20px;
    font-weight: 600;
    font-family: inherit;
    outline: none;
    flex-shrink: 0;
}

.editor-panes {
    flex: 1;
    display: grid;
    grid-template-columns: 1fr 1fr;
    min-height: 0;
}

.pane {
    min-height: 0;
    overflow-y: auto;
}

.pane-edit {
    border-right: 1px solid var(--border);
}

.editor-textarea {
    display: block;
    width: 100%;
    height: 100%;
    min-height: 100%;
    padding: 20px 24px;
    background: transparent;
    border: none;
    color: var(--text);
    font-family: var(--mono);
    font-size: 14px;
    line-height: 1.7;
    outline: none;
    resize: none;
}

/* ---------- Markdown 预览 ---------- */

.markdown-body {
    padding: 20px 24px 60px;
    font-size: 15px;
    line-height: 1.75;
    word-wrap: break-word;
}

.markdown-body > *:first-child {
    margin-top: 0;
}

.markdown-body h1,
.markdown-body h2,
.markdown-body h3,
.markdown-body h4 {
    margin: 1.4em 0 .6em;
    font-weight: 600;
    line-height: 1.3;
}

.markdown-body h1 {
    font-size: 1.7em;
    border-bottom: 1px solid var(--border);
    padding-bottom: .3em;
}

.markdown-body h2 {
    font-size: 1.4em;
    border-bottom: 1px solid var(--border);
    padding-bottom: .3em;
}

.markdown-body h3 {
    font-size: 1.2em;
}

.markdown-body p,
.markdown-body ul,
.markdown-body ol {
    margin: 0 0 1em;
}

.markdown-body ul,
.markdown-body ol {
    padding-left: 1.6em;
}

.markdown-body blockquote {
    margin: 0 0 1em;
    padding: 4px 16px;
    border-left: 3px solid var(--border-strong);
    color: var(--muted);
}

.markdown-body img {
    max-width: 100%;
}

.markdown-body table {
    border-collapse: collapse;
    margin-bottom: 1em;
    width: 100%;
}

.markdown-body th,
.markdown-body td {
    border: 1px solid var(--border);
    padding: 6px 12px;
}

.markdown-body th {
    background: var(--surface-2);
}

.markdown-body a {
    text-decoration: underline;
}

.markdown-body pre {
    margin: 0 0 1em;
    background: #0d1117;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow-x: auto;
}

.markdown-body pre code {
    display: block;
    padding: 16px;
    background: transparent;
    font-size: 13px;
    line-height: 1.6;
}

.markdown-body p code,
.markdown-body li code,
.markdown-body td code {
    padding: 2px 6px;
    background: var(--surface-3);
    border-radius: 4px;
}

.markdown-body hr {
    border: none;
    border-top: 1px solid var(--border);
    margin: 1.6em 0;
}

/* ---------- 响应式 ---------- */

@media (max-width: 760px) {
    .editor-panes {
        grid-template-columns: 1fr;
        grid-template-rows: 1fr 1fr;
    }

    .pane-edit {
        border-right: none;
        border-bottom: 1px solid var(--border);
    }

    .note-delete {
        opacity: 1;
    }
}
