:root {
    --primary-color: #4f6ef7;
    --primary-soft: rgba(79, 110, 247, 0.1);
    --primary-strong: #3a55d9;
    --bg-color: #eef1f7;
    --sidebar-bg: #f9fafc;
    --sidebar-hover: #eceff5;
    --text-color: #181b22;
    --text-muted: #7a8294;
    --border-color: #e2e6ee;
    --page-bg: #ffffff;
    --grid-color: #dfe4ec;
    --header-bg: rgba(255, 255, 255, 0.82);
    --surface-bg: #ffffff;
    --recent-card-border: #e2e6ee;
    --recent-card-border-hover: #aab8e8;
    --shadow-sm: 0 1px 3px rgba(24, 32, 56, 0.07);
    --shadow-md: 0 6px 20px rgba(24, 32, 56, 0.1);
    --shadow-lg: 0 18px 44px rgba(24, 32, 56, 0.18);
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

body {
    background-color: var(--bg-color);
    color: var(--text-color);
    overflow: hidden; /* Prevent body scroll, layout handles scrolling */
}

/* Moderne, dezente Scrollbars */
::-webkit-scrollbar {
    width: 10px;
    height: 10px;
}
::-webkit-scrollbar-track {
    background: transparent;
}
::-webkit-scrollbar-thumb {
    background: rgba(125, 135, 160, 0.35);
    border-radius: 99px;
    border: 2px solid transparent;
    background-clip: content-box;
}
::-webkit-scrollbar-thumb:hover {
    background: rgba(125, 135, 160, 0.55);
    border: 2px solid transparent;
    background-clip: content-box;
}

#app {
    display: flex;
    height: 100vh;
    width: 100vw;
}

@media (max-width: 1100px) {
    #sidebar {
        width: 220px;
    }

    #main-header {
        height: auto;
        min-height: 60px;
        padding: 0.5rem 1rem;
        flex-wrap: wrap;
        gap: 8px;
        align-items: center;
    }

    .toolbar {
        width: 100%;
        overflow: visible;
        white-space: normal;
        flex-wrap: wrap;
        row-gap: 8px;
        padding-bottom: 4px;
    }

    #notebook-container {
        padding: 1rem;
    }

    #pages-wrapper {
        max-width: 620px;
    }




    .eraser-popover {
        left: auto;
        right: 0;
    }

    .tool-popover {
        left: auto;
        right: 0;
    }
}

@media (max-width: 820px) {
    #sidebar {
        width: 0;
        border-right: none;
    }

    body:not(.sidebar-collapsed) #sidebar {
        width: 220px;
        border-right: 1px solid var(--border-color);
    }
}

/* Sidebar */
#sidebar {
    width: 300px;
    background-color: var(--sidebar-bg);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    transition: width 0.3s ease;
    overflow: hidden;
    flex-shrink: 0;
}

body.sidebar-collapsed #sidebar {
    width: 0;
    border-right: none;
}

.sidebar-header {
    padding: 1rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid var(--border-color);
}

.sidebar-header h2 {
    font-size: 1.25rem;
    font-weight: 600;
}

.icon-btn {
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    color: var(--primary-color);
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    transition: background 0.2s;
}

.icon-btn:hover {
    background: rgba(0, 122, 255, 0.1);
}

.folder-list {
    flex: 1;
    overflow-y: auto;
    padding: 0.5rem 0;
}

#sidebar-footer {
    padding: 0.75rem;
    border-top: 1px solid var(--border-color);
    background: var(--sidebar-bg);
}

.sidebar-footer-btn {
    width: 100%;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    background: var(--page-bg);
    color: var(--text-color);
    font-size: 0.95rem;
    font-weight: 500;
    padding: 0.6rem 0.75rem;
    cursor: pointer;
    text-align: left;
    transition: background 0.2s, border-color 0.2s;
}

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

.folder-item {
    margin-bottom: 0.5rem;
}

.folder-header {
    padding: 0.5rem 1rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-weight: 600;
    font-size: 0.92rem;
    cursor: pointer;
    border-radius: var(--radius-sm);
    margin: 0 8px;
    transition: background 0.15s;
}

.folder-header:hover {
    background-color: var(--sidebar-hover);
}

.folder-color-dot {
    display: inline-block;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    margin-right: 8px;
    box-shadow: 0 0 0 1px rgba(0,0,0,0.12);
    vertical-align: middle;
}

.notebook-list {
    padding-left: 1.5rem;
    list-style: none;
}

.notebook-item {
    padding: 0.45rem 0.8rem;
    font-size: 0.95rem;
    cursor: pointer;
    position: relative;
    border-radius: var(--radius-sm);
    margin: 1px 8px 1px 0;
    transition: background 0.15s;
}

.notebook-item:hover {
    background-color: var(--sidebar-hover);
}

.notebook-item.active {
    background-color: var(--primary-soft);
    color: var(--primary-color);
    font-weight: 600;
}

.add-notebook-btn {
    font-size: 0.85rem;
    color: var(--primary-color);
    padding: 0.2rem 1rem;
    cursor: pointer;
    margin-top: 0.2rem;
}

.add-notebook-btn:hover {
    text-decoration: underline;
}

/* Main View */
#main-view {
    flex: 1;
    display: flex;
    flex-direction: column;
    background-color: var(--bg-color);
    position: relative;
}

#empty-state {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #8e8e93;
    font-size: 1.1rem;
}

.start-screen {
    flex: 1;
    display: flex;
    align-items: flex-start;
    justify-content: flex-start;
    padding: 2rem;
    overflow-y: auto;
}

.start-screen-content {
    width: min(960px, 100%);
    margin: 0 auto;
}

.start-screen h1 {
    font-size: 2.1rem;
    font-weight: 700;
    letter-spacing: -0.02em;
    margin-bottom: 0.35rem;
}

.start-screen-subtitle {
    color: var(--text-muted);
    margin-bottom: 1.2rem;
}

.start-screen-section-title {
    margin-top: 1.1rem;
    margin-bottom: 0.65rem;
}

.start-screen-actions {
    display: flex;
    justify-content: flex-start;
    margin-bottom: 1rem;
}

.start-primary-btn {
    border: none;
    background: linear-gradient(135deg, var(--primary-color) 0%, var(--primary-strong) 100%);
    color: #fff;
    border-radius: var(--radius-md);
    padding: 0.65rem 1.1rem;
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
    box-shadow: 0 4px 14px rgba(79, 110, 247, 0.35);
    transition: transform 0.15s, box-shadow 0.2s;
}

.start-primary-btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 6px 20px rgba(79, 110, 247, 0.45);
}

.start-primary-btn:active {
    transform: translateY(0) scale(0.98);
}

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

.recent-notebook-card {
    min-width: 0;
    border: 1px solid var(--recent-card-border);
    background: var(--page-bg);
    border-radius: var(--radius-lg);
    padding: 12px;
    cursor: pointer;
    box-shadow: var(--shadow-sm);
    transition: transform 0.18s ease, box-shadow 0.22s ease, border-color 0.2s ease;
}

.recent-notebook-card:hover {
    transform: translateY(-3px);
    border-color: var(--recent-card-border-hover);
    box-shadow: var(--shadow-md);
}

.recent-notebook-title {
    color: #1f2937;
    font-size: 1rem;
    font-weight: 600;
    margin-bottom: 2px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.recent-notebook-meta {
    color: #4b5563;
    font-size: 0.9rem;
    margin-bottom: 8px;
}

.recent-notebook-preview {
    width: 100%;
    aspect-ratio: 1 / 1.414;
    border: 1px solid var(--recent-card-border);
    border-radius: 8px;
    background: #fff;
    margin-bottom: 8px;
    display: block;
}

body.dark-mode .recent-notebook-card {
    background: #2b2f38 !important;
    border-color: #586274 !important;
    box-shadow: 0 2px 10px rgba(0,0,0,0.35);
}

body.dark-mode .recent-notebook-card:hover {
    border-color: #8ea4cc !important;
}

body.dark-mode .recent-notebook-preview {
    border-color: #586274 !important;
    background: #1f232b;
}

body.dark-mode .recent-notebook-title,
body.dark-mode .recent-notebook-meta,
body.dark-mode .recent-notebook-page {
    color: #e6ebf5;
}

.recent-notebook-page {
    color: #4b5563;
    font-size: 0.85rem;
}

.recent-notebook-empty {
    border: 1px dashed var(--border-color);
    border-radius: 12px;
    padding: 18px;
    color: #8e8e93;
    background: var(--page-bg);
}

.start-folders-tree {
    margin-top: 0.45rem;
    border: 1px solid var(--border-color);
    border-radius: 12px;
    background: var(--page-bg);
    padding: 12px;
}

.start-folders-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(210px, 1fr));
    gap: 12px;
}

.start-folder-card {
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    padding: 12px;
    background: var(--surface-bg);
    cursor: pointer;
    box-shadow: var(--shadow-sm);
    transition: transform 0.18s ease, box-shadow 0.22s ease;
}

.start-folder-card:hover {
    transform: translateY(-3px);
    box-shadow: var(--shadow-md);
}

.start-add-card {
    border: 1.5px dashed var(--border-color);
    border-radius: 12px;
    min-height: 180px;
    background: rgba(0,0,0,0.02);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 8px;
    cursor: pointer;
    transition: background 0.2s ease, border-color 0.2s ease;
}

.start-add-card:hover {
    background: rgba(0, 122, 255, 0.06);
    border-color: var(--primary-color);
}

.start-add-card-small {
    min-height: 72px;
}

.start-add-icon {
    width: 38px;
    height: 38px;
    border-radius: 10px;
    border: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.35rem;
    font-weight: 700;
    color: var(--primary-color);
    background: var(--page-bg);
}

.start-add-label {
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--text-color);
}

.start-folder-icon-wrap {
    display: flex;
    justify-content: center;
    margin-bottom: 8px;
}

.start-folder-icon {
    position: relative;
    width: 120px;
    height: 84px;
    border-radius: 14px;
    background: linear-gradient(
        180deg,
        var(--folder-color-light, #6dd5ed) 0%,
        var(--folder-color, #56c7e6) 45%,
        var(--folder-color-dark, #4eb9d8) 100%
    );
    box-shadow: inset 0 -2px 0 rgba(0,0,0,0.08);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 34px;
}

.start-folder-icon::before {
    content: '';
    position: absolute;
    top: -8px;
    left: 12px;
    width: 44px;
    height: 14px;
    border-radius: 10px 10px 0 0;
    background: var(--folder-color-tab, #58cce8);
}

.start-folder-title {
    color: #1f2937;
    font-size: 1rem;
    font-weight: 700;
    margin-bottom: 2px;
    text-align: center;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.start-folder-meta {
    color: #4b5563;
    font-size: 0.86rem;
    text-align: center;
    margin-bottom: 8px;
}

.start-folder-notebooks {
    list-style: none;
    padding-left: 0;
}

.start-folder-notebook-item {
    color: #1f2937;
    padding: 5px 7px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 0.94rem;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.start-folder-notebook-item:hover {
    background: var(--sidebar-hover);
}

.start-folder-view-header {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 10px;
}

.start-back-btn {
    border: 1px solid var(--border-color);
    background: var(--page-bg);
    color: var(--text-color);
    border-radius: 8px;
    padding: 6px 10px;
    font-size: 0.92rem;
    cursor: pointer;
}

.start-folder-view-title {
    font-size: 1.35rem;
    color: var(--text-color);
}

.start-folder-notebooks-list {
    border: 1px solid var(--border-color);
    border-radius: 12px;
    background: var(--page-bg);
    padding: 12px;
}

.start-folder-open-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(210px, 1fr));
    gap: 12px;
}

.start-folder-open-item {
    border: 1px solid var(--border-color);
    border-radius: 10px;
    padding: 10px;
    background: var(--page-bg);
    color: var(--text-color);
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    cursor: pointer;
}

.start-folder-open-item:hover {
    background: var(--sidebar-hover);
}

.start-folder-open-notebook-card {
    min-width: 0;
    min-height: 132px;
}

.start-folder-open-folder-card {
    min-height: 132px;
}

.start-notebook-emoji-preview {
    width: 100%;
    aspect-ratio: 2.4 / 1;
    border: 1px solid var(--recent-card-border);
    border-radius: 8px;
    background: linear-gradient(180deg, #ffffff 0%, #f4f7ff 100%);
    margin-bottom: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 3rem;
    line-height: 1;
}

body.dark-mode .start-folders-tree {
    background: #252a33;
    border-color: #586274;
}

body.dark-mode .start-folder-card {
    background: #2b2f38;
    border-color: #586274;
}

body.dark-mode .start-add-card {
    border-color: #586274;
    background: #2b2f38;
}

body.dark-mode .start-add-card:hover {
    background: #323847;
    border-color: #8ea4cc;
}

body.dark-mode .start-add-icon {
    background: #252a33;
    border-color: #586274;
    color: #7fb5ff;
}

body.dark-mode .start-add-label {
    color: #e6ebf5;
}

body.dark-mode .folder-color-dot {
    box-shadow: 0 0 0 1px rgba(255,255,255,0.16);
}

body.dark-mode .start-folder-title,
body.dark-mode .start-folder-meta,
body.dark-mode .start-folder-notebook-item {
    color: #e6ebf5;
}

body.dark-mode .start-folder-notebook-item:hover {
    background: #3a4150;
}

body.dark-mode .start-notebook-emoji-preview {
    border-color: #586274;
    background: linear-gradient(180deg, #1f232b 0%, #252a33 100%);
}

body.dark-mode .start-back-btn,
body.dark-mode .start-folder-open-item,
body.dark-mode .start-folder-notebooks-list {
    background: #2b2f38;
    border-color: #586274;
    color: #e6ebf5;
}

body.dark-mode .start-folder-open-item:hover,
body.dark-mode .start-back-btn:hover {
    background: #3a4150;
}

.start-folders-empty {
    color: #8e8e93;
    padding: 6px;
}

body.start-screen-active #sidebar {
    width: 0 !important;
    border-right: none !important;
}

#main-header {
    height: 60px;
    padding: 0 1.5rem;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
    background-color: var(--header-bg);
    backdrop-filter: blur(16px) saturate(1.4);
    -webkit-backdrop-filter: blur(16px) saturate(1.4);
    z-index: 10;
    box-shadow: var(--shadow-sm);
    position: relative;
}

.home-btn {
    position: absolute;
    right: 12px;
    top: 50%;
    transform: translateY(-50%);
    z-index: 11;
}

.toolbar {
    display: flex;
    gap: 10px;
    align-items: center;
    flex: 1;
    min-width: 0;
    margin-left: 12px;
}

.toolbar-tools-track {
    flex: 1;
    min-width: 0;
    display: flex;
    align-items: center;
}

.toolbar-divider {
    width: 1px;
    height: 24px;
    background-color: var(--border-color);
    margin: 0 5px;
}

.tool-select {
    padding: 6px;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    background: var(--page-bg);
    color: var(--text-color);
    font-size: 0.9rem;
    outline: none;
}

.tool-btn {
    min-width: 36px;
    height: 36px;
    padding: 6px 8px;
    border: 1px solid transparent;
    background: transparent;
    border-radius: 10px;
    cursor: pointer;
    font-size: 1.1rem;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.18s, box-shadow 0.18s, transform 0.12s, border-color 0.18s;
}

.tool-btn:hover:not(:disabled) {
    background: var(--primary-soft);
    transform: translateY(-1px);
}

.tool-btn:active:not(:disabled) {
    transform: translateY(0) scale(0.96);
}

.tool-btn.active {
    background: var(--primary-soft);
    border-color: var(--primary-color);
    box-shadow: var(--shadow-sm);
}

.pen-menu,
.highlighter-menu,
.eraser-menu {
    position: relative;
}

.pen-menu #pen-tool,
.highlighter-menu #highlighter-tool,
#eraser-tool {
    gap: 4px;
}

.pen-menu #pen-tool .tool-caret,
.highlighter-menu #highlighter-tool .tool-caret,
#eraser-tool .tool-caret {
    font-size: 0.75rem;
    opacity: 0.85;
    transform: translateY(1px);
}

/* Unified Popover Styling */
.tool-popover,
.eraser-popover {
    position: absolute;
    top: calc(100% + 8px);
    left: 0;
    min-width: 240px;
    background: #2d2d2f;
    border: 1px solid #535356;
    border-radius: 10px;
    box-shadow: 0 12px 28px rgba(0,0,0,0.28);
    padding: 12px;
    z-index: 120;
    color: #f5f5f7;
}

.tool-popover h4,
.eraser-popover h4 {
    font-size: 1rem;
    font-weight: 700;
    margin-bottom: 10px;
}

.width-btn-list,
.eraser-width-list {
    display: flex;
    align-items: center;
    gap: 10px;
    border-bottom: 1px solid rgba(255,255,255,0.16);
    padding-bottom: 12px;
    margin-bottom: 12px;
}

.width-btn,
.eraser-width-btn {
    border: none;
    background: transparent;
    color: #f5f5f7;
    cursor: pointer;
    border-radius: 999px;
    line-height: 1;
    padding: 0;
    width: 30px;
    height: 30px;
}

.width-btn[data-width="1"] { font-size: 8px; }
.width-btn[data-width="2"] { font-size: 10px; }
.width-btn[data-width="3"] { font-size: 12px; }
.width-btn[data-width="5"] { font-size: 16px; }
.width-btn[data-width="8"] { font-size: 20px; }
.width-btn[data-width="10"] { font-size: 12px; }
.width-btn[data-width="15"] { font-size: 16px; }
.width-btn[data-width="20"] { font-size: 20px; }
.width-btn[data-width="28"] { font-size: 24px; }
.width-btn[data-width="36"] { font-size: 28px; }

.eraser-width-btn[data-width="8"] { font-size: 10px; }
.eraser-width-btn[data-width="14"] { font-size: 14px; }
.eraser-width-btn[data-width="20"] { font-size: 20px; }
.eraser-width-btn[data-width="28"] { font-size: 24px; }
.eraser-width-btn[data-width="36"] { font-size: 28px; }

.width-btn.active,
.eraser-width-btn.active {
    outline: 2px solid #f5f5f7;
    outline-offset: 2px;
    background: rgba(255,255,255,0.08);
}

.opacity-slider {
    width: 100%;
    accent-color: #b17be9;
    cursor: pointer;
}

.eraser-type-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.eraser-type-btn {
    border: 1px solid #6a6a6d;
    background: #3a3a3d;
    color: #f5f5f7;
    border-radius: 8px;
    padding: 8px 10px;
    text-align: left;
    cursor: pointer;
    font-size: 0.95rem;
}

.eraser-type-btn.active {
    border-color: #b17be9;
    box-shadow: inset 0 0 0 1px #b17be9;
}

.color-btn-list {
    display: flex;
    gap: 10px;
    border-bottom: 1px solid rgba(255,255,255,0.16);
    padding-bottom: 12px;
    margin-bottom: 12px;
}

.color-preset-btn {
    width: 30px;
    height: 30px;
    border-radius: 6px;
    border: 2px solid transparent;
    cursor: pointer;
    transition: transform 0.1s, border-color 0.1s;
}

.color-preset-btn.active,
.color-preset-btn:focus {
    border-color: #f5f5f7;
    outline: none;
}

.color-preset-btn:hover {
    transform: scale(1.1);
}

.custom-color-row {
    display: flex;
    align-items: center;
    gap: 10px;
}

.popover-color-picker {
    width: 50px;
    height: 30px;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    padding: 2px;
}

/* Custom Color Wrapper */
.custom-color-wrapper {
    position: relative;
    margin-left: 2px;
    display: flex;
    align-items: center;
}
.custom-color-btn {
    min-width: 36px;
    height: 32px;
    padding: 0 8px;
    font-size: 1rem;
}

.hidden-color-input {
    position: absolute;
    width: 1px;
    height: 1px;
    opacity: 0;
    pointer-events: none;
}

/* Notebook Container */
#notebook-container {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 2rem;
    display: flex;
    flex-direction: column;
    align-items: center;
    scroll-behavior: smooth;
    touch-action: pan-x pan-y; /* disable native pinch-zoom to allow custom */
}

#pages-wrapper {
    display: flex;
    flex-direction: column;
    gap: 2rem;
    width: 100%;
    max-width: 1131px;
    transform-origin: top center;
    transition: transform 0.1s ease-out;
}

.a4-page {
    position: relative;
    width: min(100%, 800px);
    aspect-ratio: 1 / 1.414;
    background-color: var(--page-bg);
    box-shadow: 0 2px 6px rgba(24, 32, 56, 0.06), 0 14px 36px rgba(24, 32, 56, 0.12);
    border-radius: 10px;
    margin: 0 auto;
}

.a4-page.orientation-landscape {
    width: min(100%, 1131px);
    aspect-ratio: 1.414 / 1;
}

/* Background Types */
.bg-blank {
    background-image: none !important;
}
.bg-lined {
    background-image: linear-gradient(var(--grid-color) 1px, transparent 1px) !important;
    background-size: 100% 30px !important;
    background-position: 0 40px !important;
}
.bg-squared {
    background-image: linear-gradient(var(--grid-color) 1px, transparent 1px), linear-gradient(90deg, var(--grid-color) 1px, transparent 1px) !important;
    background-size: 30px 30px !important;
    background-position: 0 0 !important;
}

.a4-page canvas {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    /* touch-action none: verhindert, dass der Browser Stiftstriche als
       Scroll-Geste abbricht (pointercancel). Finger-Scrollen wird in
       script.js manuell umgesetzt. */
    touch-action: none;
    border-radius: 10px;
    cursor: crosshair;
}

.page-number {
    position: absolute;
    bottom: -25px;
    left: 50%;
    transform: translateX(-50%);
    font-size: 0.8rem;
    color: #8e8e93;
}

#scroll-bottom-detector {
    height: 50px;
    width: 100%;
}

.hidden {
    display: none !important;
}

/* Modal */
.modal {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(15, 20, 35, 0.45);
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
}

.modal-content {
    background: var(--surface-bg);
    padding: 1.75rem;
    border-radius: var(--radius-lg);
    width: 340px;
    border: 1px solid var(--border-color);
    box-shadow: var(--shadow-lg);
    animation: modal-pop 0.18s ease-out;
}

@keyframes modal-pop {
    from {
        opacity: 0;
        transform: translateY(10px) scale(0.97);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

.modal-content h3 {
    margin-bottom: 1rem;
    font-size: 1.2rem;
}

.modal-content input {
    width: 100%;
    padding: 0.65rem 0.75rem;
    border: 1px solid var(--border-color);
    border-radius: 10px;
    margin-bottom: 1.5rem;
    font-size: 1rem;
    outline: none;
    background: var(--bg-color);
    color: var(--text-color);
    transition: border-color 0.15s, box-shadow 0.15s;
}

.modal-content input:focus {
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px var(--primary-soft);
}

.settings-label {
    display: block;
    margin-bottom: 0.5rem;
    font-size: 0.95rem;
    color: var(--text-color);
}

.settings-select {
    width: 100%;
    margin-bottom: 1.5rem;
}

.notebook-create-modal-content {
    width: 380px;
}

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

.modal-actions button {
    padding: 0.55rem 1.1rem;
    border: none;
    border-radius: 10px;
    cursor: pointer;
    font-size: 0.95rem;
    font-weight: 600;
    transition: filter 0.2s, transform 0.1s, box-shadow 0.2s;
}

.modal-actions button.primary {
    box-shadow: 0 3px 10px rgba(79, 110, 247, 0.3);
}

.modal-actions button:active {
    transform: scale(0.96);
}

.modal-actions button:hover {
    filter: brightness(0.9);
}

.modal-actions button#modal-cancel,
.modal-actions button#confirm-cancel,
.modal-actions button#notebook-create-cancel {
    background: #e5e5ea;
    color: var(--text-color);
}

.modal-actions button.primary {
    background: var(--primary-color);
    color: white;
}

/* Context Menu */
.context-menu {
    position: fixed;
    z-index: 1000;
    background: var(--surface-bg);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-md);
    padding: 6px;
    min-width: 180px;
    animation: modal-pop 0.14s ease-out;
}
.context-menu-item {
    padding: 8px 12px;
    cursor: pointer;
    font-size: 0.95rem;
    color: var(--text-color);
    border-radius: var(--radius-sm);
    transition: background 0.15s;
}
.context-menu-item:hover {
    background: var(--primary-soft);
}
.context-menu-item.danger {
    color: #ff3b30;
}

/* Color swatches */
.color-swatches {
    display: flex;
    gap: 8px;
    align-items: center;
    margin: 0 10px;
}
.color-swatch {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    border: 2px solid transparent;
    cursor: pointer;
    box-shadow: inset 0 0 0 1px rgba(0,0,0,0.1);
    transition: transform 0.1s, border-color 0.1s;
}
.color-swatch.active {
    border-color: var(--primary-color);
    transform: scale(1.15);
}

/* Selection Overlay */
.selection-overlay {
    position: absolute;
    border: 1px dashed var(--primary-color);
    background: rgba(0, 122, 255, 0.05);
    cursor: move;
    z-index: 50;
    pointer-events: auto;
}

.selection-resize-handle {
    position: absolute;
    bottom: -6px;
    right: -6px;
    width: 12px;
    height: 12px;
    background: #fff;
    border: 2px solid var(--primary-color);
    border-radius: 50%;
    cursor: se-resize;
    z-index: 51;
}

.selection-delete-btn {
    position: absolute;
    top: -30px;
    right: 0;
    background: #fff;
    border: 1px solid #ff3b30;
    border-radius: 4px;
    color: #ff3b30;
    padding: 2px 6px;
    font-size: 0.9rem;
    cursor: pointer;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
    z-index: 52;
}
.selection-delete-btn:hover {
    background: #ffe5e5;
}

/* Dark mode styles (applied via body class) */
body.dark-mode {
    --primary-color: #6c86ff;
    --primary-soft: rgba(108, 134, 255, 0.16);
    --primary-strong: #8da1ff;
    --bg-color: #13151a;
    --sidebar-bg: #1a1d24;
    --sidebar-hover: #262a34;
    --text-color: #ecf0f7;
    --text-muted: #99a1b3;
    --border-color: #2b303c;
    --grid-color: #dfe4ec; /* Seiten bleiben weiß, Raster bleibt hell */
    --header-bg: rgba(26, 29, 36, 0.85);
    --surface-bg: #20242d;
    --recent-card-border: #343a48;
    --recent-card-border-hover: #5b6c9e;
    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.4);
    --shadow-md: 0 6px 20px rgba(0, 0, 0, 0.45);
    --shadow-lg: 0 18px 44px rgba(0, 0, 0, 0.6);
    /* we keep the --page-bg white intentionally */
}
body.dark-mode #main-header {
    background-color: var(--header-bg);
    border-bottom: 1px solid var(--border-color);
}
body.dark-mode .tool-btn {
    color: #f2f2f7;
}
body.dark-mode .tool-select {
    background: var(--surface-bg);
    color: #f2f2f7;
    border-color: var(--border-color);
}
body.dark-mode .modal-content {
    background: #2c2c2e;
    color: #f2f2f7;
}
body.dark-mode .modal-content input {
    background: #1c1c1e;
    color: #f2f2f7;
}
body.dark-mode .modal-actions button#modal-cancel,
body.dark-mode .modal-actions button#confirm-cancel,
body.dark-mode .modal-actions button#notebook-create-cancel {
    background: #3a3a3c;
    color: #f2f2f7;
}

body.dark-mode .sidebar-footer-btn {
    background: #3a3a3c;
    border-color: #48484a;
    color: #f2f2f7;
}

/* Tool Icons Position Styles */

/* Tools container - flex base */
.tools-container {
    display: flex;
    gap: 10px;
    align-items: center;
}

/* Tools on the left (default) */
.tools-position-left {
    margin-right: auto;
}

/* Tools in the middle */
.tools-position-center {
    margin-left: auto;
    margin-right: auto;
}

/* Tools on the right */
.tools-position-right {
    margin-left: auto;
}

@media (max-width: 1100px) {
    .toolbar-tools-track {
        flex: 0 0 auto;
        min-width: auto;
    }

    .tools-position-left,
    .tools-position-center,
    .tools-position-right {
        margin-left: 0;
        margin-right: 0;
    }
}
/* --- Sidebar-Suche --- */
.sidebar-search-wrapper {
    padding: 0.6rem 0.8rem;
    border-bottom: 1px solid var(--border-color);
}

.sidebar-search {
    width: 100%;
    padding: 8px 12px;
    border: 1px solid var(--border-color);
    border-radius: 10px;
    background: var(--bg-color);
    color: var(--text-color);
    font-size: 0.92rem;
    outline: none;
    transition: border-color 0.15s, box-shadow 0.15s;
}

.sidebar-search:focus {
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px var(--primary-soft);
}

/* --- Undo/Redo --- */
.tool-btn:disabled {
    opacity: 0.35;
    cursor: default;
}

/* --- Text-Werkzeug --- */
.text-menu {
    position: relative;
}

.text-size-list {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.text-size-btn {
    border: 1px solid #6a6a6d;
    background: #3a3a3d;
    color: #f5f5f7;
    border-radius: 8px;
    padding: 8px 10px;
    text-align: left;
    cursor: pointer;
    font-size: 0.95rem;
}

.text-size-btn.active {
    border-color: #b17be9;
    box-shadow: inset 0 0 0 1px #b17be9;
}

.text-edit-overlay {
    position: absolute;
    z-index: 60;
    min-width: 90px;
    min-height: 1.5em;
    padding: 1px 2px;
    margin: 0;
    border: 1px dashed var(--primary-color);
    border-radius: 4px;
    background: rgba(0, 122, 255, 0.04);
    outline: none;
    resize: none;
    overflow: hidden;
    white-space: pre;
}

/* --- Backup Buttons --- */
.settings-backup-actions {
    display: flex;
    gap: 10px;
    margin-bottom: 1rem;
}

.settings-backup-btn {
    flex: 1;
    padding: 9px 10px;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    background: var(--sidebar-bg);
    color: var(--text-color);
    cursor: pointer;
    font-size: 0.92rem;
}

.settings-backup-btn:hover {
    background: var(--sidebar-hover);
}

/* --- MDI Icons --- */
.mdi {
    width: 20px;
    height: 20px;
    display: block;
    flex-shrink: 0;
}

.icon-btn .mdi {
    width: 22px;
    height: 22px;
}

.tool-btn {
    color: var(--text-muted);
}

.tool-btn.active {
    color: var(--primary-color);
}

body.dark-mode .tool-btn {
    color: var(--text-muted);
}

body.dark-mode .tool-btn.active {
    color: var(--primary-color);
}

.sidebar-footer-btn {
    display: flex;
    align-items: center;
    gap: 8px;
}

.sidebar-footer-btn .mdi {
    width: 18px;
    height: 18px;
    color: var(--text-muted);
}

.settings-backup-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 7px;
}

.settings-backup-btn .mdi {
    width: 17px;
    height: 17px;
    color: var(--text-muted);
}

.selection-delete-btn .mdi {
    width: 16px;
    height: 16px;
}

.tool-caret {
    font-size: 0.7rem;
    opacity: 0.7;
    line-height: 1;
}

/* --- Login (Mehrbenutzer) --- */
.login-overlay {
    position: fixed;
    inset: 0;
    z-index: 5000;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-color);
}

.login-card {
    width: min(360px, calc(100vw - 40px));
    background: var(--surface-bg);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    padding: 2rem;
    display: flex;
    flex-direction: column;
    gap: 12px;
    animation: modal-pop 0.2s ease-out;
}

.login-card h1 {
    font-size: 1.7rem;
    letter-spacing: -0.02em;
    text-align: center;
}

.login-subtitle {
    color: var(--text-muted);
    text-align: center;
    font-size: 0.95rem;
    margin-bottom: 6px;
}

.login-card input {
    padding: 0.7rem 0.8rem;
    border: 1px solid var(--border-color);
    border-radius: 10px;
    background: var(--bg-color);
    color: var(--text-color);
    font-size: 1rem;
    outline: none;
    transition: border-color 0.15s, box-shadow 0.15s;
}

.login-card input:focus {
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px var(--primary-soft);
}

.login-error {
    color: #ff3b30;
    font-size: 0.88rem;
    text-align: center;
}

.login-submit-btn {
    width: 100%;
}

.login-secondary-btn {
    border: none;
    background: transparent;
    color: var(--primary-color);
    font-size: 0.92rem;
    cursor: pointer;
    padding: 6px;
}

.login-secondary-btn:hover {
    text-decoration: underline;
}

/* --- Konto-Zeile in den Einstellungen --- */
.settings-account-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    margin-bottom: 1rem;
    padding-top: 0.75rem;
    border-top: 1px solid var(--border-color);
}

#settings-account-name {
    font-size: 0.92rem;
    color: var(--text-muted);
}

.settings-logout-btn {
    flex: 0 0 auto;
}

/* --- Geteilte Notizbücher --- */
.shared-owner-hint {
    display: block;
    font-size: 0.78rem;
    color: var(--text-muted);
    margin-top: 1px;
}
