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

html, body {
    margin: 0;
    padding: 0;
    height: 100%;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', sans-serif;
    font-size: 15px;
    color: #2d2d2d;
    background: #fff;
    display: flex;
    flex-direction: column;
    height: 100vh;
}

/* ── Topbar ──────────────────────────────────────────────────────────────── */

.topbar {
    height: 48px;
    flex-shrink: 0;
    background: #375fd7;
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 18px;
    user-select: none;
}

.topbar-brand {
    font-weight: 700;
    font-size: 1.1em;
    letter-spacing: 0.03em;
}

.topbar-user {
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 0.85em;
}

.topbar-username {
    opacity: 0.85;
}

.btn-topbar-logout {
    color: rgba(255,255,255,0.88);
    text-decoration: none;
    border: 1px solid rgba(255,255,255,0.4);
    border-radius: 4px;
    padding: 3px 10px;
    font-size: 0.88em;
    transition: background 0.15s;
}

.btn-topbar-logout:hover {
    background: rgba(255,255,255,0.18);
    color: #fff;
}

/* ── App layout ──────────────────────────────────────────────────────────── */

.app-layout {
    display: flex;
    flex: 1;
    overflow: hidden;
}

/* ── Sidebar ─────────────────────────────────────────────────────────────── */

.sidebar {
    width: 240px;
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    border-right: 1px solid #e4e4e8;
    background: #f6f6f9;
    overflow: hidden;
}

.sidebar-header {
    padding: 12px 10px;
    border-bottom: 1px solid #e4e4e8;
    flex-shrink: 0;
}

.btn-new {
    width: 100%;
    padding: 8px 12px;
    background: #375fd7;
    color: #fff;
    border: none;
    border-radius: 6px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.15s;
}

.btn-new:hover {
    background: #2d52c0;
}

.note-list {
    flex: 1;
    overflow-y: auto;
    padding: 6px 0;
}

.note-item {
    padding: 9px 14px;
    cursor: pointer;
    border-radius: 6px;
    margin: 2px 6px;
    transition: background 0.1s;
}

.note-item:hover {
    background: #eceef6;
}

.note-item.active {
    background: #dce1f5;
}

.note-item-title {
    display: block;
    font-size: 13.5px;
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    color: #1e1e2e;
}

.note-item-date {
    display: block;
    font-size: 11px;
    color: #aaa;
    margin-top: 2px;
}

/* ── Editor panel ────────────────────────────────────────────────────────── */

.editor-panel {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    background: #fff;
}

/* Empty state */
.editor-empty {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #bbb;
    text-align: center;
    line-height: 2;
    font-size: 15px;
}

.editor-empty-icon {
    font-size: 2.5em;
    margin-bottom: 8px;
    opacity: 0.4;
}

.btn-new-inline {
    background: none;
    border: none;
    color: #375fd7;
    cursor: pointer;
    font-size: 15px;
    font-family: inherit;
    padding: 0;
    text-decoration: underline;
    text-underline-offset: 2px;
}

.btn-new-inline:hover {
    color: #2d52c0;
}

/* Active editor */
.editor-active {
    flex: 1;
    flex-direction: column;
    overflow: hidden;
    display: none;
}

.editor-titlebar {
    padding: 16px 24px 10px;
    border-bottom: 1px solid #f0f0f2;
    flex-shrink: 0;
}

.note-title {
    width: 100%;
    border: none;
    outline: none;
    font-size: 1.45em;
    font-weight: 700;
    color: #111;
    font-family: inherit;
    background: transparent;
    padding: 0;
}

.note-title::placeholder {
    color: #ddd;
    font-weight: 300;
}

.editor-toolbar {
    padding: 6px 24px;
    border-bottom: 1px solid #f0f0f2;
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
    flex-wrap: wrap;
}

.btn-tool {
    padding: 4px 11px;
    font-size: 12px;
    font-family: inherit;
    border: 1px solid #d8d8dc;
    border-radius: 4px;
    background: #fff;
    color: #555;
    cursor: pointer;
    transition: background 0.12s;
}

.btn-tool:hover {
    background: #f4f4f7;
}

.btn-danger {
    color: #b02020;
    border-color: #e0b0b0;
}

.btn-danger:hover {
    background: #fff0f0;
    border-color: #d08080;
}

.save-status {
    font-size: 12px;
    color: #aaa;
    margin-left: auto;
    white-space: nowrap;
}

.editor {
    flex: 1;
    padding: 20px 24px 32px;
    overflow-y: auto;
    outline: none;
    font-size: 15px;
    line-height: 1.7;
    color: #2d2d2d;
    font-family: inherit;
    word-break: break-word;
}

.editor:empty::before {
    content: 'Notiz schreiben…';
    color: #ccc;
    pointer-events: none;
    display: block;
}

/* Preserve pasted formatting */
.editor b, .editor strong { font-weight: bold; }
.editor i, .editor em     { font-style: italic; }
.editor u                  { text-decoration: underline; }
.editor s, .editor strike  { text-decoration: line-through; }
.editor a                  { color: #375fd7; }
.editor h1 { font-size: 1.6em; margin: 0.6em 0 0.3em; }
.editor h2 { font-size: 1.35em; margin: 0.6em 0 0.3em; }
.editor h3 { font-size: 1.15em; margin: 0.5em 0 0.25em; }
.editor ul, .editor ol { padding-left: 1.6em; margin: 0.4em 0; }
.editor blockquote {
    border-left: 3px solid #e0e0e4;
    margin: 0.5em 0 0.5em 0;
    padding: 0.2em 0 0.2em 1em;
    color: #777;
}
.editor pre, .editor code {
    font-family: 'SFMono-Regular', Consolas, monospace;
    font-size: 0.9em;
    background: #f6f6f9;
    border-radius: 3px;
    padding: 0 3px;
}
.editor pre {
    padding: 10px 14px;
    overflow-x: auto;
}

/* ── Auth pages ──────────────────────────────────────────────────────────── */

.auth-body {
    background: #f4f5f9;
}

.auth-page {
    flex: 1;
    display: flex;
    align-items: flex-start;
    justify-content: center;
    padding: 40px 16px;
    overflow-y: auto;
}

.auth-card {
    width: 100%;
    max-width: 360px;
    background: #fff;
    border: 1px solid #e4e4e8;
    border-radius: 10px;
    box-shadow: 0 4px 20px rgba(0,0,0,0.07);
    padding: 28px 28px 24px;
}

.auth-title {
    font-size: 1.3em;
    font-weight: 700;
    color: #111;
    margin: 0 0 20px;
    text-align: center;
}

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

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

.auth-field label {
    font-size: 11.5px;
    font-weight: 600;
    color: #999;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    padding-left: 2px;
}

.auth-field input {
    width: 100%;
    padding: 9px 12px;
    font-size: 15px;
    font-family: inherit;
    color: #2d2d2d;
    border: 1px solid #d8d8dc;
    border-radius: 6px;
    outline: none;
    transition: border-color 0.15s, box-shadow 0.15s;
}

.auth-field input:focus {
    border-color: #375fd7;
    box-shadow: 0 0 0 3px rgba(55,95,215,0.15);
}

.auth-btn {
    margin-top: 4px;
    padding: 10px;
    font-size: 15px;
    font-family: inherit;
    font-weight: 600;
    color: #fff;
    background: #375fd7;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    transition: background 0.15s;
}

.auth-btn:hover {
    background: #2d52c0;
}

.auth-error {
    color: #b02020;
    font-size: 13px;
    margin: 12px 0 0;
    text-align: center;
}

.auth-switch {
    font-size: 13px;
    margin: 16px 0 0;
    text-align: center;
    color: #888;
}

.auth-switch a {
    color: #375fd7;
    text-decoration: none;
}

.auth-switch a:hover {
    text-decoration: underline;
}

/* ── Responsive ──────────────────────────────────────────────────────────── */

@media (max-width: 600px) {
    .sidebar {
        width: 180px;
    }
    .editor-titlebar,
    .editor-toolbar,
    .editor {
        padding-left: 14px;
        padding-right: 14px;
    }
}

@media (max-width: 440px) {
    .sidebar {
        width: 140px;
    }
    .note-item-date {
        display: none;
    }
}
