:root {
    color-scheme: light;
    --bg: #f5f7fb;
    --surface: #ffffff;
    --surface-2: #eef3f8;
    --text: #172033;
    --muted: #637083;
    --line: #d9e1ec;
    --primary: #1f6feb;
    --primary-dark: #1959bd;
    --accent: #00897b;
    --warning: #b7791f;
    --danger: #d43c3c;
    --shadow: 0 12px 36px rgba(25, 43, 74, .12);
    --radius: 8px;
    --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
    --sans: Inter, "Segoe UI", Arial, "Microsoft YaHei", sans-serif;
}

body.dark {
    color-scheme: dark;
    --bg: #111827;
    --surface: #182132;
    --surface-2: #223047;
    --text: #eef4ff;
    --muted: #9eabc0;
    --line: #334258;
    --primary: #63a4ff;
    --primary-dark: #3b82f6;
    --accent: #33b39e;
    --warning: #e0aa44;
    --danger: #ff6b6b;
    --shadow: 0 12px 36px rgba(0, 0, 0, .32);
}

* {
    box-sizing: border-box;
}

html,
body {
    min-height: 100%;
}

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font-family: var(--sans);
    font-size: 14px;
}

button,
input,
textarea,
select {
    font: inherit;
}

button {
    cursor: pointer;
}

button:disabled {
    cursor: not-allowed;
    opacity: .62;
}

.app-shell {
    min-height: 100vh;
}

.auth-screen,
.deploy-screen {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 24px;
    background:
        linear-gradient(135deg, rgba(31, 111, 235, .14), transparent 38%),
        linear-gradient(315deg, rgba(0, 137, 123, .16), transparent 36%),
        var(--bg);
}

.auth-panel {
    width: min(440px, 100%);
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 28px;
}

.deploy-panel {
    width: min(760px, 100%);
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 28px;
}

.brand-block {
    margin-bottom: 24px;
}

.brand-mark {
    width: 56px;
    height: 56px;
    display: grid;
    place-items: center;
    border-radius: 8px;
    background: #172033;
    color: #fff;
    font-weight: 800;
}

.brand-mark.compact {
    width: 40px;
    height: 40px;
    font-size: 12px;
}

.brand-block h1 {
    margin: 16px 0 6px;
    font-size: 26px;
}

.brand-block p,
.brand-row span {
    margin: 0;
    color: var(--muted);
}

.auth-form {
    display: grid;
    gap: 14px;
}

.deploy-form {
    display: grid;
    gap: 14px;
}

.deploy-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 12px;
}

.deploy-status {
    margin-top: 18px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    overflow: hidden;
}

.deploy-status-head {
    min-height: 44px;
    padding: 0 14px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid var(--line);
    background: var(--surface-2);
}

#deployState {
    color: var(--muted);
    font-size: 12px;
}

#deployLog {
    min-height: 220px;
    max-height: 360px;
    margin: 0;
    padding: 14px;
    overflow: auto;
    background: #101928;
    color: #e8eef8;
    font-family: var(--mono);
    font-size: 12px;
    line-height: 1.6;
    white-space: pre-wrap;
}

label span {
    display: block;
    margin-bottom: 7px;
    color: var(--muted);
}

input,
textarea,
select {
    width: 100%;
    border: 1px solid var(--line);
    border-radius: 6px;
    background: var(--surface);
    color: var(--text);
    outline: none;
}

input,
select {
    min-height: 40px;
    padding: 0 12px;
}

textarea {
    padding: 16px;
    resize: none;
}

input:focus,
textarea:focus,
select:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(31, 111, 235, .14);
}

.primary-action,
.ghost-action,
.icon-button,
.nav-item,
.ai-actions button,
.upload-label {
    border-radius: 6px;
    border: 1px solid transparent;
    min-height: 38px;
}

.primary-action {
    background: var(--primary);
    color: #fff;
    border-color: var(--primary);
    font-weight: 700;
    padding: 0 16px;
}

.primary-action:hover {
    background: var(--primary-dark);
}

.primary-action.full {
    width: 100%;
}

.ghost-action {
    background: var(--surface);
    color: var(--text);
    border-color: var(--line);
    padding: 0 14px;
}

.icon-button {
    width: 38px;
    height: 38px;
    display: grid;
    place-items: center;
    background: var(--surface);
    color: var(--text);
    border-color: var(--line);
    flex: 0 0 auto;
}

.icon-button.danger {
    color: var(--danger);
}

.hidden {
    display: none !important;
}

.sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    width: 248px;
    padding: 18px;
    background: var(--surface);
    border-right: 1px solid var(--line);
    display: flex;
    flex-direction: column;
    gap: 18px;
}

.brand-row {
    display: flex;
    gap: 12px;
    align-items: center;
}

.brand-row strong,
.brand-row span {
    display: block;
}

.nav-stack {
    display: grid;
    gap: 8px;
}

.nav-item {
    background: transparent;
    color: var(--muted);
    border-color: transparent;
    text-align: left;
    padding: 0 12px;
}

.nav-item.active,
.nav-item:hover {
    color: var(--text);
    background: var(--surface-2);
}

.sidebar-footer {
    margin-top: auto;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.text-link {
    color: var(--primary);
    background: transparent;
    border: 0;
    padding: 0;
    text-decoration: none;
}

.workspace {
    margin-left: 248px;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

.topbar {
    height: 64px;
    padding: 12px 18px;
    display: flex;
    gap: 16px;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid var(--line);
    background: color-mix(in srgb, var(--surface) 92%, transparent);
    position: sticky;
    top: 0;
    z-index: 5;
}

.search-wrap {
    width: min(540px, 100%);
}

.toolbar,
.editor-actions,
.ai-actions {
    display: flex;
    gap: 8px;
    align-items: center;
}

.content-grid {
    display: grid;
    grid-template-columns: 310px minmax(0, 1fr) 260px;
    gap: 14px;
    padding: 14px;
    min-height: calc(100vh - 64px);
}

.note-list-panel,
.editor-panel,
.inspector {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    min-width: 0;
}

.note-list-panel {
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.panel-title {
    height: 48px;
    padding: 0 14px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid var(--line);
}

.note-list {
    overflow: auto;
}

.note-item {
    width: 100%;
    border: 0;
    border-bottom: 1px solid var(--line);
    background: transparent;
    color: var(--text);
    text-align: left;
    padding: 13px 14px;
    min-height: 78px;
}

.note-item.active {
    background: var(--surface-2);
    border-left: 3px solid var(--primary);
}

.note-item strong,
.note-item span {
    display: block;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.note-item span {
    color: var(--muted);
    margin-top: 7px;
    font-size: 12px;
}

.editor-panel {
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.editor-head {
    min-height: 62px;
    padding: 10px 12px;
    display: flex;
    gap: 12px;
    align-items: center;
    border-bottom: 1px solid var(--line);
}

.title-input {
    border: 0;
    box-shadow: none !important;
    font-size: 22px;
    font-weight: 700;
    padding: 0;
}

.meta-row {
    display: grid;
    grid-template-columns: minmax(140px, 1fr) 120px 86px;
    gap: 10px;
    padding: 10px 12px;
    border-bottom: 1px solid var(--line);
    align-items: center;
}

#saveState {
    color: var(--muted);
    text-align: right;
    font-size: 12px;
}

.mode-tabs {
    display: flex;
    gap: 6px;
    padding: 10px 12px;
    border-bottom: 1px solid var(--line);
}

.mode-tabs button {
    min-height: 30px;
    padding: 0 12px;
    border: 1px solid var(--line);
    background: var(--surface);
    color: var(--muted);
    border-radius: 6px;
}

.mode-tabs button.active {
    color: #fff;
    background: var(--accent);
    border-color: var(--accent);
}

.editor-split {
    flex: 1;
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    min-height: 440px;
}

.editor-split.edit-only {
    grid-template-columns: 1fr;
}

.editor-split.preview-only {
    grid-template-columns: 1fr;
}

.editor-split.edit-only .preview,
.editor-split.preview-only textarea {
    display: none;
}

#noteContent {
    height: 100%;
    border: 0;
    border-radius: 0;
    box-shadow: none;
    font-family: var(--mono);
    line-height: 1.6;
}

.preview {
    padding: 18px 22px;
    overflow: auto;
    border-left: 1px solid var(--line);
    line-height: 1.7;
}

.preview h1,
.preview h2,
.preview h3 {
    line-height: 1.25;
}

.preview pre,
.shared-note {
    overflow: auto;
    padding: 14px;
    background: #101928;
    color: #e8eef8;
    border-radius: 6px;
    font-family: var(--mono);
}

.preview code {
    font-family: var(--mono);
}

.editor-foot {
    min-height: 54px;
    padding: 8px 12px;
    display: flex;
    justify-content: space-between;
    gap: 12px;
    border-top: 1px solid var(--line);
}

.ai-actions {
    flex-wrap: wrap;
}

.ai-actions button,
.upload-label {
    border-color: var(--line);
    background: var(--surface);
    color: var(--text);
    padding: 0 12px;
    display: inline-grid;
    place-items: center;
}

.inspector {
    padding: 14px;
    overflow: auto;
}

.inspector h2 {
    font-size: 14px;
    margin: 0 0 10px;
}

.inspector section + section {
    margin-top: 24px;
}

.version-list {
    display: grid;
    gap: 8px;
}

.version-item {
    border: 1px solid var(--line);
    border-radius: 6px;
    padding: 9px;
}

.version-item strong,
.version-item span {
    display: block;
    overflow-wrap: anywhere;
}

.version-item span,
.stats-list dt {
    color: var(--muted);
    font-size: 12px;
}

.stats-list {
    margin: 0;
    display: grid;
    gap: 10px;
}

.stats-list div {
    display: flex;
    justify-content: space-between;
}

.stats-list dd {
    margin: 0;
    font-weight: 700;
}

.modal {
    width: min(760px, calc(100vw - 32px));
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--surface);
    color: var(--text);
    box-shadow: var(--shadow);
}

.modal::backdrop {
    background: rgba(10, 18, 32, .45);
}

.modal header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 14px;
}

.plan-list {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 12px;
}

.plan {
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 14px;
    display: grid;
    gap: 10px;
}

.plan strong {
    font-size: 18px;
}

.plan span {
    color: var(--muted);
}

.toast {
    position: fixed;
    left: 50%;
    bottom: 22px;
    transform: translateX(-50%);
    background: #172033;
    color: #fff;
    padding: 10px 14px;
    border-radius: 6px;
    box-shadow: var(--shadow);
    z-index: 20;
}

.share-wrap {
    min-height: 100vh;
    padding: 32px 18px;
    display: grid;
    place-items: start center;
}

.share-card {
    width: min(900px, 100%);
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 26px;
    box-shadow: var(--shadow);
}

.share-card header {
    border-bottom: 1px solid var(--line);
    margin-bottom: 18px;
}

.share-card p {
    color: var(--muted);
}

.no-copy {
    user-select: none;
}

@media (max-width: 1180px) {
    .content-grid {
        grid-template-columns: 280px minmax(0, 1fr);
    }

    .inspector {
        display: none;
    }
}

@media (max-width: 780px) {
    .sidebar {
        position: static;
        width: auto;
        border-right: 0;
        border-bottom: 1px solid var(--line);
    }

    .workspace {
        margin-left: 0;
    }

    .topbar {
        position: static;
        height: auto;
        flex-direction: column;
        align-items: stretch;
    }

    .content-grid {
        grid-template-columns: 1fr;
        padding: 10px;
    }

    .editor-head,
    .editor-foot {
        align-items: stretch;
        flex-direction: column;
    }

    .editor-actions,
    .toolbar {
        justify-content: flex-start;
        flex-wrap: wrap;
    }

    .meta-row {
        grid-template-columns: 1fr;
    }

    #saveState {
        text-align: left;
    }

    .editor-split {
        grid-template-columns: 1fr;
        min-height: 640px;
    }

    .preview {
        border-left: 0;
        border-top: 1px solid var(--line);
    }

    .plan-list {
        grid-template-columns: 1fr;
    }

    .deploy-grid {
        grid-template-columns: 1fr;
    }
}
