:root {
    --bg: #000000;
    --surface: #111113;
    --surface-2: #1c1c1e;
    --surface-3: #2c2c2e;
    --text: #ffffff;
    --muted: #9a9aa0;
    --dim: #6d6d72;
    --border: rgba(84, 84, 88, 0.65);
    --accent: #0a84ff;
    --danger: #ff453a;
    --success: #34c759;
    --warning: #ffd60a;
    --syntax-color: #6d6d72;
    --code-bg: #1c1c1e;
    --code-text: #d1d1d6;
    --link-color: #64d2ff;
    --selection-bg: rgba(10, 132, 255, 0.3);
    --font-family: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
    --font-family-mono: var(--font-family);
    color-scheme: dark;
}

*,
*::before,
*::after {
    box-sizing: border-box;
}

html,
body {
    width: 100%;
    height: 100%;
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font-family: var(--font-family);
    -webkit-font-smoothing: antialiased;
    text-size-adjust: 100%;
    overscroll-behavior: none;
}

body,
ion-app {
    background: var(--bg);
}

ion-content,
ion-toolbar,
ion-list,
ion-item {
    --background: var(--bg);
    --color: var(--text);
    font-family: inherit;
}

ion-toolbar {
    --border-color: var(--border);
}

ion-title {
    font-size: 18px;
    font-weight: 700;
    letter-spacing: 0;
}

ion-button,
ion-input,
ion-label,
ion-note,
ion-toast {
    font-family: inherit;
}

button,
input,
textarea {
    font: inherit;
}

.hidden,
.settings-view.hidden {
    display: none !important;
}

.app-shell {
    position: relative;
    width: 100%;
    height: 100vh;
    height: 100dvh;
    overflow: hidden;
    background: var(--bg);
}

.notes-sidebar,
.editor-view {
    height: 100%;
    min-height: 0;
    background: var(--bg);
}

.notes-sidebar {
    display: flex;
    flex-direction: column;
    border-right: 1px solid var(--border);
}

.editor-view {
    display: flex;
    flex-direction: column;
}

.settings-view {
    background: var(--bg);
    z-index: 20;
}

.header-icon-btn {
    --color: var(--accent);
}

.mobile-only {
    display: none;
}

.filter-toolbar,
.editor-meta-toolbar {
    --min-height: auto;
}

.filter-section {
    display: grid;
    gap: 10px;
    width: 100%;
    padding: 8px 12px 12px;
}

.search-container {
    position: relative;
    display: flex;
    align-items: center;
    min-height: 40px;
    border: 1px solid transparent;
    border-radius: 10px;
    background: var(--surface-2);
}

.search-container:focus-within {
    background: var(--surface-3);
    border-color: rgba(10, 132, 255, 0.55);
}

.search-icon {
    width: 18px;
    height: 18px;
    margin-left: 12px;
    color: var(--dim);
    flex: 0 0 auto;
}

.search-container input {
    width: 100%;
    min-width: 0;
    height: 40px;
    padding: 0 40px 0 10px;
    border: 0;
    outline: 0;
    color: var(--text);
    background: transparent;
    font-size: 15px;
}

.search-container input::placeholder {
    color: var(--dim);
}

.clear-btn {
    position: absolute;
    right: 6px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border: 0;
    border-radius: 999px;
    color: var(--dim);
    background: transparent;
    padding: 0;
}

.clear-btn ion-icon {
    width: 19px;
    height: 19px;
}

.view-content {
    --background: var(--bg);
}

.note-list {
    background: transparent;
}

.note-row {
    --background: transparent;
    --background-hover: rgba(44, 44, 46, 0.72);
    --inner-padding-end: 10px;
    --padding-start: 10px;
    --min-height: 84px;
    margin-bottom: 6px;
    border: 1px solid transparent;
    border-radius: 8px;
}

.note-row.active {
    --background: rgba(10, 132, 255, 0.15);
    border-color: rgba(10, 132, 255, 0.48);
}

.note-row ion-icon {
    width: 22px;
    height: 22px;
    margin-right: 10px;
    color: var(--accent);
}

.note-title {
    margin: 0;
    color: var(--text);
    font-size: 15px;
    font-weight: 700;
    letter-spacing: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.note-preview,
.note-date {
    margin: 4px 0 0;
    color: var(--muted);
    font-size: 12px;
    line-height: 1.35;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.note-date {
    color: var(--dim);
}

.empty-state,
.empty-editor {
    color: var(--muted);
    text-align: center;
    line-height: 1.5;
}

.empty-state {
    padding: 36px 18px;
}

.editor-meta {
    width: 100%;
    min-height: 34px;
    padding: 8px 16px 10px;
    color: var(--dim);
    font-size: 12px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.editor-main {
    position: relative;
    display: flex;
    flex: 1;
    min-height: 0;
    background: var(--bg);
}

.empty-editor {
    display: grid;
    place-items: center;
    align-content: center;
    gap: 14px;
    width: 100%;
    min-height: 100%;
    padding: 24px;
}

.empty-editor ion-icon {
    width: 42px;
    height: 42px;
    color: var(--dim);
}

.editor-host,
.editor-wrapper,
.editor-content-wrapper {
    width: 100%;
    height: 100%;
    min-height: 0;
}

.editor-wrapper {
    display: flex;
    flex-direction: column;
    background: var(--bg);
}

.editor-content-wrapper {
    flex: 1;
}

.editor-scroller {
    width: 100%;
    height: 100%;
    overflow-y: auto;
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
}

.editor-content {
    position: relative;
    min-height: 100%;
    max-width: 980px;
    margin: 0 auto;
    padding: 28px 28px 50vh;
    outline: none;
    color: var(--text);
    white-space: pre-wrap;
    overflow-wrap: anywhere;
    word-break: normal;
    caret-color: var(--accent);
    line-height: 1.65;
    text-align: left;
}

.editor-content:focus {
    outline: none;
}

.editor-content ::selection {
    background-color: var(--selection-bg);
}

.editor-content.empty::before {
    content: attr(data-placeholder);
    position: absolute;
    color: var(--dim);
    pointer-events: none;
}

.line {
    position: relative;
    min-height: 1.65em;
}

.line:empty::before {
    content: "\200B";
}

.syntax {
    color: var(--syntax-color);
    font-weight: 400;
    font-style: normal;
}

.syntax-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

.line.focused .syntax-hidden {
    position: static;
    width: auto;
    height: auto;
    padding: 0;
    margin: 0;
    overflow: visible;
    clip: auto;
    white-space: pre-wrap;
}

.md-heading {
    margin: 0;
    padding: 0;
    color: var(--text);
    font-weight: 700;
}

.md-heading-1 {
    font-size: 2em;
    line-height: 1.3;
    margin-top: 0.67em;
    margin-bottom: 0.67em;
}

.md-heading-2 {
    font-size: 1.5em;
    line-height: 1.35;
    margin-top: 0.83em;
    margin-bottom: 0.83em;
}

.md-heading-3 {
    font-size: 1.25em;
    line-height: 1.4;
    margin-top: 1em;
    margin-bottom: 1em;
}

.md-heading-4 {
    font-size: 1.1em;
    line-height: 1.45;
    margin-top: 1.33em;
    margin-bottom: 1.33em;
}

.md-heading-5 {
    font-size: 1em;
    line-height: 1.5;
    margin-top: 1.67em;
    margin-bottom: 1.67em;
}

.md-heading-6 {
    color: var(--muted);
    font-size: 0.9em;
    line-height: 1.55;
    margin-top: 2em;
    margin-bottom: 2em;
}

.line:first-child .md-heading {
    margin-top: 0;
}

.md-bold {
    color: var(--text);
    font-weight: 700;
}

.md-italic {
    font-style: italic;
}

.md-bold-italic {
    font-weight: 700;
    font-style: italic;
}

.md-code-inline {
    padding: 0.15em 0.4em;
    border-radius: 4px;
    background: var(--code-bg);
    color: var(--code-text);
    font-family: var(--font-family-mono);
    font-size: 0.9em;
}

.line.code-block {
    padding-left: 1em;
    padding-right: 1em;
    background: var(--code-bg);
    color: var(--code-text);
    font-family: var(--font-family-mono);
    font-size: 0.9em;
}

.line.code-block-start {
    border-top-left-radius: 6px;
    border-top-right-radius: 6px;
    padding-top: 0.75em;
}

.line.code-block-end {
    border-bottom-left-radius: 6px;
    border-bottom-right-radius: 6px;
    padding-bottom: 0.75em;
}

.md-link {
    color: var(--link-color);
    text-decoration: none;
}

.md-link-url {
    color: var(--dim);
}

.line.blockquote {
    border-left: 3px solid #bf5af2;
    padding-left: 1em;
    color: var(--muted);
}

.line.list-item {
    position: relative;
}

.line.list-item-unordered {
    padding-left: 2ch;
}

.line.list-item-ordered {
    padding-left: 3ch;
}

.line.list-item-ordered[data-marker-width="3"] { padding-left: 4ch; }
.line.list-item-ordered[data-marker-width="4"] { padding-left: 5ch; }
.line.list-item-ordered[data-marker-width="5"] { padding-left: 6ch; }
.line.list-item-unordered[data-indent="1"] { padding-left: 6ch; }
.line.list-item-unordered[data-indent="2"] { padding-left: 10ch; }
.line.list-item-unordered[data-indent="3"] { padding-left: 14ch; }
.line.list-item-unordered[data-indent="4"] { padding-left: 18ch; }
.line.list-item-unordered[data-indent="5"] { padding-left: 22ch; }
.line.list-item-unordered[data-indent="6"] { padding-left: 26ch; }
.line.list-item-ordered[data-indent="1"] { padding-left: 7ch; }
.line.list-item-ordered[data-indent="2"] { padding-left: 11ch; }
.line.list-item-ordered[data-indent="3"] { padding-left: 15ch; }
.line.list-item-ordered[data-indent="4"] { padding-left: 19ch; }
.line.list-item-ordered[data-indent="5"] { padding-left: 23ch; }
.line.list-item-ordered[data-indent="6"] { padding-left: 27ch; }

.md-list-marker {
    position: absolute;
    left: 0;
    color: var(--syntax-color);
}

.line.list-item-unordered[data-indent="1"] .md-list-marker { left: 4ch; }
.line.list-item-unordered[data-indent="2"] .md-list-marker { left: 8ch; }
.line.list-item-unordered[data-indent="3"] .md-list-marker { left: 12ch; }
.line.list-item-unordered[data-indent="4"] .md-list-marker { left: 16ch; }
.line.list-item-unordered[data-indent="5"] .md-list-marker { left: 20ch; }
.line.list-item-unordered[data-indent="6"] .md-list-marker { left: 24ch; }
.line.list-item-ordered[data-indent="1"] .md-list-marker { left: 4ch; }
.line.list-item-ordered[data-indent="2"] .md-list-marker { left: 8ch; }
.line.list-item-ordered[data-indent="3"] .md-list-marker { left: 12ch; }
.line.list-item-ordered[data-indent="4"] .md-list-marker { left: 16ch; }
.line.list-item-ordered[data-indent="5"] .md-list-marker { left: 20ch; }
.line.list-item-ordered[data-indent="6"] .md-list-marker { left: 24ch; }

.line.list-item.focused {
    padding-left: 0;
}

.line.list-item.focused .md-list-marker {
    position: static;
}

.line.horizontal-rule {
    display: flex;
    align-items: center;
    height: 2em;
}

.line.horizontal-rule::after {
    content: "";
    flex: 1;
    height: 1px;
    background: var(--dim);
}

.md-strikethrough {
    color: var(--muted);
    text-decoration: line-through;
}

.md-task-checkbox {
    color: var(--success);
}

.md-task-checked {
    color: var(--dim);
    text-decoration: line-through;
}

.settings-body {
    max-width: 760px;
    margin: 0 auto;
    padding-bottom: calc(32px + env(safe-area-inset-bottom));
}

.settings-section-title {
    margin: 0;
    color: var(--text);
    font-size: 14px;
    font-weight: 700;
}

.settings-description,
.setting-hint {
    color: var(--muted);
    font-size: 12px;
    line-height: 1.45;
}

.sync-buttons {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
    gap: 10px;
    margin: 12px 0 18px;
}

.sync-status {
    min-height: 22px;
    margin: 4px 0 18px;
    color: var(--muted);
    font-size: 13px;
    line-height: 1.45;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
}

.sync-status.success {
    color: var(--success);
}

.sync-status.error {
    color: var(--danger);
}

.pwa-update-status {
    display: inline-flex;
    align-items: center;
    min-height: 26px;
    padding: 0 9px;
    border-radius: 999px;
    color: var(--muted);
    background: var(--surface-2);
    font-size: 12px;
    font-weight: 700;
}

.pwa-update-current,
.pwa-update-ready {
    color: var(--success);
}

.pwa-update-error {
    color: var(--danger);
}

.config-json-panel {
    display: grid;
    gap: 8px;
    margin: 10px 0 20px;
}

.config-json-label {
    color: var(--muted);
    font-size: 12px;
}

.config-json-text {
    width: 100%;
    min-height: 180px;
    padding: 12px;
    border: 1px solid var(--border);
    border-radius: 8px;
    outline: none;
    resize: vertical;
    background: var(--surface-2);
    color: var(--text);
    font-size: 12px;
    line-height: 1.45;
}

.config-json-text:focus {
    border-color: rgba(10, 132, 255, 0.65);
}

.debug-log-summary {
    white-space: normal;
}

.clipboard-copy-target {
    position: fixed;
    top: 0;
    left: 0;
    width: 1px;
    height: 1px;
    opacity: 0;
    pointer-events: none;
}

@media (min-width: 860px) {
    .app-shell {
        display: flex;
    }

    .notes-sidebar {
        flex: 0 0 360px;
        width: 360px;
    }

    .editor-view {
        flex: 1;
        min-width: 0;
    }

    .settings-view {
        position: fixed;
        inset: 0;
    }
}

@media (max-width: 859px) {
    .mobile-only {
        display: block;
    }

    .notes-sidebar,
    .editor-view,
    .settings-view {
        position: absolute;
        inset: 0;
        width: 100%;
        transition: transform 160ms ease-out;
    }

    .notes-sidebar {
        z-index: 1;
    }

    .editor-view {
        z-index: 2;
        transform: translateX(100%);
        border-right: 0;
    }

    .settings-view {
        z-index: 3;
        transform: translateX(100%);
    }

    .app-shell[data-view="editor"] .notes-sidebar,
    .app-shell[data-view="settings"] .notes-sidebar {
        transform: translateX(-24%);
    }

    .app-shell[data-view="editor"] .editor-view,
    .app-shell[data-view="settings"] .settings-view {
        transform: translateX(0);
    }

    .editor-content {
        padding: 22px 18px 50vh;
    }

    .sync-buttons {
        grid-template-columns: 1fr;
    }
}
