:root {
    color-scheme: light dark;
    --bg: #f7f4ef;
    --panel: #ffffff;
    --text: #20252a;
    --muted: #65707a;
    --line: #d8ded7;
    --primary: #184e77;
    --accent: #2a9d8f;
    --warn: #b84a3a;
    --shadow: 0 18px 44px rgba(32, 37, 42, 0.1);
}

[data-theme="dark"] {
    --bg: #15181b;
    --panel: #20262b;
    --text: #f0f4f3;
    --muted: #a9b5bc;
    --line: #3a454c;
    --primary: #4da3d9;
    --accent: #52c7b8;
    --warn: #ff8a7a;
    --shadow: 0 18px 44px rgba(0, 0, 0, 0.28);
}

* {
    box-sizing: border-box;
}

[hidden] {
    display: none !important;
}

body {
    margin: 0;
    min-height: 100vh;
    background: var(--bg);
    color: var(--text);
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
input,
textarea {
    font: inherit;
}

.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 10px clamp(14px, 3vw, 28px);
    background: var(--panel);
    border-bottom: 1px solid var(--line);
}

.brand {
    min-width: 0;
}

.topbar-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    flex: 0 0 auto;
}

.icon-button {
    width: 34px;
    height: 34px;
    display: inline-grid;
    place-items: center;
    border: 1px solid var(--line);
    background: var(--panel);
    color: var(--text);
    flex: 0 0 auto;
    padding: 0;
    line-height: 1;
}

.compact {
    padding: 8px 11px;
}

.theme-icon {
    display: grid;
    place-items: center;
    width: 18px;
    height: 18px;
    font-size: 18px;
    line-height: 18px;
    transform: translateY(-0.5px);
}

.login-screen {
    display: grid;
    place-items: center;
    min-height: calc(100vh - 64px);
    width: min(100%, 460px);
    margin: 0 auto;
    padding: 24px 16px;
}

.login-panel {
    width: 100%;
    display: grid;
    gap: 16px;
    padding: clamp(18px, 4vw, 28px);
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 8px;
    box-shadow: var(--shadow);
}

.login-panel h2 {
    margin: 0;
    font-size: 1.45rem;
}

.login-panel p {
    margin: -8px 0 0;
    color: var(--muted);
}

.login-panel .login-error {
    margin: 0;
    color: var(--warn);
    font-weight: 700;
}

h1 {
    margin: 0;
    font-size: clamp(1.2rem, 2vw, 1.55rem);
    line-height: 1.1;
}

.topbar p {
    margin: 2px 0 0;
    color: var(--muted);
    font-size: 0.86rem;
}

.mode {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    min-width: 88px;
    justify-content: center;
    padding: 6px 10px;
    border: 1px solid var(--line);
    border-radius: 999px;
    background: var(--panel);
    font-size: 0.9rem;
}

.mode span {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--warn);
}

.mode[data-mode="online"] span {
    background: var(--accent);
}

.layout {
    display: grid;
    grid-template-columns: minmax(280px, 380px) 1fr;
    gap: 24px;
    width: min(1180px, calc(100vw - 32px));
    margin: 24px auto;
}

.certificate-notice {
    grid-column: 1 / -1;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 12px 14px;
    background: color-mix(in srgb, var(--primary) 10%, var(--panel));
    border: 1px solid var(--line);
    border-radius: 8px;
}

.certificate-notice[hidden] {
    display: none;
}

.certificate-notice strong {
    display: block;
    margin-bottom: 3px;
}

.certificate-notice p {
    margin: 0;
    color: var(--muted);
    font-size: 0.9rem;
}

.certificate-notice a {
    flex: 0 0 auto;
    padding: 9px 12px;
    border-radius: 6px;
    background: var(--primary);
    color: #fff;
    font-weight: 750;
    text-decoration: none;
}

.sidebar,
.editor {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 8px;
    box-shadow: var(--shadow);
}

.sidebar {
    min-height: calc(100vh - 132px);
    overflow: hidden;
}

.toolbar {
    display: grid;
    gap: 12px;
    padding: 16px;
    border-bottom: 1px solid var(--line);
}

label span {
    display: block;
    margin-bottom: 6px;
    color: var(--muted);
    font-size: 0.88rem;
    font-weight: 650;
}

input,
textarea {
    width: 100%;
    border: 1px solid var(--line);
    border-radius: 6px;
    padding: 11px 12px;
    color: var(--text);
    background: var(--panel);
}

textarea {
    min-height: 340px;
    resize: vertical;
}

.content-field > span {
    display: block;
    margin-bottom: 6px;
    color: var(--muted);
    font-size: 0.88rem;
    font-weight: 650;
}

.markdown-toolbar {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-bottom: 8px;
}

.markdown-toolbar button {
    width: 34px;
    height: 32px;
    display: inline-grid;
    place-items: center;
    padding: 0;
    border: 1px solid var(--line);
    background: var(--panel);
    color: var(--text);
    line-height: 1;
}

.markdown-preview {
    min-height: 110px;
    margin-top: 10px;
    padding: 12px;
    border: 1px solid var(--line);
    border-radius: 6px;
    background: color-mix(in srgb, var(--panel) 86%, var(--bg));
    overflow-wrap: anywhere;
}

.markdown-preview:empty::before {
    content: "Vorschau";
    color: var(--muted);
}

.markdown-preview h1,
.markdown-preview h2,
.markdown-preview h3 {
    margin: 0.6em 0 0.35em;
    font-size: 1.2rem;
}

.markdown-preview p,
.markdown-preview ul,
.markdown-preview blockquote {
    margin: 0.55em 0;
}

.markdown-preview ul {
    padding-left: 1.35rem;
}

.markdown-preview blockquote {
    padding-left: 10px;
    border-left: 3px solid var(--accent);
    color: var(--muted);
}

.markdown-preview code {
    padding: 2px 4px;
    border-radius: 4px;
    background: color-mix(in srgb, var(--line) 45%, transparent);
}

.markdown-preview a {
    color: var(--primary);
    font-weight: 700;
}

.note-reader[hidden],
.note-form-hidden {
    display: none;
}

.reader-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 18px;
}

.reader-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    flex: 0 0 auto;
}

.reader-header h2 {
    margin: 0;
    font-size: clamp(1.35rem, 2vw, 1.8rem);
    line-height: 1.2;
}

.reader-header p {
    margin: 7px 0 0;
    color: var(--muted);
}

.note-read-content {
    min-height: 420px;
    margin-top: 0;
}

button {
    border: 0;
    border-radius: 6px;
    padding: 11px 14px;
    font-weight: 750;
    cursor: pointer;
}

.primary,
#newNoteButton {
    background: var(--primary);
    color: #fff;
}

.secondary {
    border: 1px solid var(--line);
    background: var(--panel);
    color: var(--text);
}

.danger {
    color: var(--warn);
}

.note-list {
    max-height: calc(100vh - 260px);
    overflow: auto;
}

.note-item {
    width: 100%;
    display: block;
    text-align: left;
    padding: 14px 16px;
    border-radius: 0;
    background: transparent;
    border-bottom: 1px solid var(--line);
    color: var(--text);
}

.note-item.active {
    background: color-mix(in srgb, var(--accent) 14%, var(--panel));
}

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

.note-item small {
    margin-top: 5px;
    color: var(--muted);
    font-weight: 500;
}

.empty {
    padding: 28px 16px;
    color: var(--muted);
}

.editor {
    padding: clamp(16px, 3vw, 28px);
}

form {
    display: grid;
    gap: 18px;
}

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

.actions {
    display: flex;
    justify-content: flex-end;
    gap: 12px;
}

@media (max-width: 820px) {
    .topbar {
        align-items: center;
        flex-direction: row;
    }

    .layout {
        grid-template-columns: 1fr;
        margin-top: 16px;
    }

    .certificate-notice {
        align-items: flex-start;
        flex-direction: column;
    }

    .sidebar {
        min-height: 0;
    }

    .note-list {
        max-height: 320px;
    }

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

    .reader-header {
        flex-direction: column;
    }

    .reader-actions {
        width: 100%;
    }

    .reader-actions button {
        flex: 1 1 0;
    }
}
