:root {
    font-family:
        -apple-system, BlinkMacSystemFont, "Segoe UI",
        Roboto, Helvetica, Arial, sans-serif;
    color-scheme: light;
}

* {
    box-sizing: border-box;
}

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

body {
    --page: #f3f4f6;
    --panel: #ffffff;
    --panel-soft: #f8f8fa;
    --text: #202124;
    --muted: #74777c;
    --border: #dedfe3;
    --accent: #d89a00;
    --accent-soft: #fff2c5;
    --danger: #b42318;
    --shadow: 0 12px 35px rgba(0, 0, 0, 0.08);

    background: var(--page);
    color: var(--text);
}

body[data-theme="dark"] {
    color-scheme: dark;

    --page: #111214;
    --panel: #1b1d20;
    --panel-soft: #24272b;
    --text: #f2f3f4;
    --muted: #a9adb3;
    --border: #363a40;
    --accent: #f4c44e;
    --accent-soft: #4b3c13;
    --danger: #ff8178;
    --shadow: 0 12px 35px rgba(0, 0, 0, 0.35);
}

body[data-theme="madi"] {
    color-scheme: light;

    --page: #f7efec;
    --panel: #fffaf7;
    --panel-soft: #f4e7e4;
    --text: #493d3d;
    --muted: #8f7d7b;
    --border: #e8d5d0;
    --accent: #b87982;
    --accent-soft: #efd8da;
    --danger: #a74848;
    --shadow: 0 14px 40px rgba(119, 76, 79, 0.13);
}

button,
input,
select {
    font: inherit;
}

button,
select {
    cursor: pointer;
}

button:focus-visible,
input:focus-visible,
select:focus-visible,
a:focus-visible {
    outline: 3px solid color-mix(in srgb, var(--accent) 35%, transparent);
    outline-offset: 2px;
}

.app-shell {
    display: grid;
    grid-template-columns: 330px minmax(0, 1fr);
    width: 100%;
    min-height: 100vh;
}

.sidebar {
    display: flex;
    flex-direction: column;
    min-width: 0;
    height: 100vh;
    padding: 18px;
    overflow: hidden;
    background: var(--panel);
    border-right: 1px solid var(--border);
}

.sidebar-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 18px;
}

.brand {
    font-size: 24px;
    font-weight: 750;
    letter-spacing: -0.7px;
}

.username {
    margin-top: 2px;
    color: var(--muted);
    font-size: 13px;
}

.theme-select {
    max-width: 100px;
    padding: 8px 9px;
    color: var(--text);
    background: var(--panel-soft);
    border: 1px solid var(--border);
    border-radius: 10px;
}

.new-note-button,
.primary-button {
    width: 100%;
    padding: 11px 14px;
    color: #fff;
    font-weight: 700;
    background: var(--accent);
    border: 0;
    border-radius: 12px;
}

.search-form {
    margin: 12px 0 9px;
}

.search-form input,
.login-form input {
    width: 100%;
    padding: 11px 13px;
    color: var(--text);
    background: var(--panel-soft);
    border: 1px solid var(--border);
    border-radius: 11px;
}

.section-navigation {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 6px;
    margin-bottom: 9px;
}

.section-navigation a {
    padding: 8px;
    color: var(--muted);
    text-align: center;
    text-decoration: none;
    border-radius: 9px;
}

.section-navigation a.active {
    color: var(--text);
    font-weight: 650;
    background: var(--accent-soft);
}

.notes-list {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    padding-right: 3px;
}

.note-item {
    display: block;
    margin-bottom: 6px;
    padding: 12px;
    color: var(--text);
    text-decoration: none;
    border: 1px solid transparent;
    border-radius: 12px;
}

.note-item:hover {
    background: var(--panel-soft);
}

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

.note-item-heading {
    display: flex;
    gap: 7px;
    min-width: 0;
    font-weight: 700;
}

.note-item-title {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.pin-symbol {
    flex: none;
    color: var(--accent);
    font-size: 10px;
    line-height: 22px;
}

.note-item-preview {
    height: 38px;
    margin: 5px 0;
    overflow: hidden;
    color: var(--muted);
    font-size: 13px;
    line-height: 19px;
}

.note-item time {
    color: var(--muted);
    font-size: 11px;
}

.empty-list {
    padding: 30px 10px;
    color: var(--muted);
    text-align: center;
}

.logout-form {
    margin-top: 10px;
}

.logout-form button {
    width: 100%;
    padding: 9px;
    color: var(--muted);
    background: transparent;
    border: 1px solid var(--border);
    border-radius: 10px;
}

.workspace {
    min-width: 0;
    height: 100vh;
    padding: 24px;
    overflow: hidden;
}

.note-editor {
    display: flex;
    flex-direction: column;
    width: min(1050px, 100%);
    height: 100%;
    margin: 0 auto;
    overflow: hidden;
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 18px;
    box-shadow: var(--shadow);
}

.editor-header {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 15px 18px;
    border-bottom: 1px solid var(--border);
}

.note-title {
    min-width: 0;
    flex: 1;
    padding: 5px 2px;
    color: var(--text);
    font-size: clamp(20px, 3vw, 29px);
    font-weight: 750;
    background: transparent;
    border: 0;
}

.note-title:disabled {
    opacity: 1;
}

.note-actions {
    display: flex;
    gap: 7px;
    flex-wrap: wrap;
    justify-content: flex-end;
}

.note-actions button {
    padding: 8px 11px;
    color: var(--text);
    background: var(--panel-soft);
    border: 1px solid var(--border);
    border-radius: 9px;
}

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

#toolbar {
    background: var(--panel-soft);
    border: 0;
    border-bottom: 1px solid var(--border);
}

#editor {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    border: 0;
}

.ql-container.ql-snow {
    color: var(--text);
    background: var(--panel);
    border: 0;
    font-family: inherit;
    font-size: 16px;
}

.ql-editor {
    min-height: 100%;
    padding: 30px clamp(20px, 5vw, 70px);
    line-height: 1.65;
}

.ql-toolbar.ql-snow {
    border: 0;
}

body[data-theme="dark"] .ql-snow .ql-stroke {
    stroke: var(--text);
}

body[data-theme="dark"] .ql-snow .ql-fill {
    fill: var(--text);
}

body[data-theme="dark"] .ql-snow .ql-picker {
    color: var(--text);
}

body[data-theme="dark"] .ql-snow .ql-picker-options {
    background: var(--panel);
    border-color: var(--border);
}

.is-trashed #toolbar {
    display: none;
}

.editor-footer {
    display: flex;
    justify-content: space-between;
    gap: 15px;
    padding: 9px 18px;
    color: var(--muted);
    font-size: 12px;
    border-top: 1px solid var(--border);
}

#save-status.is-error {
    color: var(--danger);
}

.empty-workspace {
    display: grid;
    place-content: center;
    height: 100%;
    color: var(--muted);
    text-align: center;
}

.empty-workspace h1 {
    margin: 8px 0;
    color: var(--text);
}

.empty-icon {
    font-size: 50px;
    color: var(--accent);
}

.login-page {
    display: grid;
    place-items: center;
    min-height: 100vh;
    padding: 20px;
}

.login-card {
    width: min(410px, 100%);
    padding: 36px;
    text-align: center;
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 22px;
    box-shadow: var(--shadow);
}

.login-logo {
    display: grid;
    place-items: center;
    width: 58px;
    height: 58px;
    margin: 0 auto 14px;
    color: #fff;
    font-size: 28px;
    font-weight: 800;
    background: var(--accent);
    border-radius: 18px;
}

.login-card h1 {
    margin: 0;
}

.login-subtitle {
    margin: 7px 0 25px;
    color: var(--muted);
}

.login-form {
    display: grid;
    gap: 10px;
    text-align: left;
}

.login-form label {
    margin-top: 5px;
    font-size: 13px;
    font-weight: 650;
}

.login-form button {
    margin-top: 12px;
}

.form-error {
    margin-bottom: 15px;
    padding: 10px;
    color: var(--danger);
    background: color-mix(in srgb, var(--danger) 10%, var(--panel));
    border-radius: 10px;
}

@media (max-width: 820px) {
    .app-shell {
        display: block;
    }

    .sidebar {
        width: 100%;
        height: 42vh;
        min-height: 310px;
        border-right: 0;
        border-bottom: 1px solid var(--border);
    }

    .workspace {
        height: 58vh;
        min-height: 430px;
        padding: 10px;
    }

    .note-editor {
        border-radius: 13px;
    }

    .editor-header {
        align-items: flex-start;
        flex-direction: column;
        gap: 9px;
    }

    .note-title {
        width: 100%;
    }

    .note-actions {
        width: 100%;
        justify-content: flex-start;
    }

    .editor-footer {
        align-items: flex-start;
        flex-direction: column;
        gap: 3px;
    }

    .ql-editor {
        padding: 20px 16px;
    }
}

/* MadiNotes mobile iPhone-style list v3 */

.brand-mobile,
.mobile-back-button,
.mobile-section-title,
.new-note-icon {
    display: none;
}

@media (max-width: 820px) {
    html,
    body {
        width: 100%;
        height: 100%;
        min-height: 100%;
        overflow: hidden;
    }

    body {
        background: var(--panel);
    }

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

    body.mobile-note-list .workspace {
        display: none;
    }

    body.mobile-note-open .sidebar {
        display: none;
    }

    .sidebar {
        position: relative;
        width: 100%;
        height: 100vh;
        height: 100dvh;
        min-height: 0;
        padding:
            max(14px, env(safe-area-inset-top))
            16px
            max(16px, env(safe-area-inset-bottom));
        overflow: hidden;
        background: var(--panel);
        border: 0;
    }

    .sidebar-header {
        flex: none;
        align-items: flex-start;
        margin: 0 0 14px;
    }

    .brand-desktop {
        display: none;
    }

    .brand-mobile {
        display: block;
        font-size: 34px;
        font-weight: 800;
        line-height: 1.08;
        letter-spacing: -1.2px;
    }

    .username {
        margin-top: 5px;
        font-size: 13px;
    }

    .theme-select {
        max-width: 96px;
        padding: 7px 8px;
        background: var(--panel-soft);
        border: 0;
        border-radius: 10px;
    }

    .search-form {
        flex: none;
        margin: 0 0 10px;
    }

    .search-form input {
        padding: 10px 13px;
        font-size: 16px;
        background: var(--panel-soft);
        border: 0;
        border-radius: 12px;
        appearance: none;
    }

    .section-navigation {
        flex: none;
        gap: 2px;
        margin-bottom: 8px;
        padding: 3px;
        background: var(--panel-soft);
        border-radius: 11px;
    }

    .section-navigation a {
        padding: 7px 8px;
        font-size: 14px;
        border-radius: 8px;
    }

    .notes-list {
        flex: 1;
        min-height: 0;
        margin: 0 -16px;
        padding: 0 0 88px;
        overflow-y: auto;
        overscroll-behavior: contain;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
        border-top: 1px solid var(--border);
    }

    .notes-list::-webkit-scrollbar {
        display: none;
    }

    .mobile-section-title {
        display: block;
        padding: 13px 20px 5px;
        color: var(--muted);
        font-size: 13px;
        font-weight: 700;
        line-height: 18px;
        background: var(--panel);
    }

    .note-item {
        position: relative;
        display: block;
        min-height: 78px;
        margin: 0;
        padding: 11px 20px 10px;
        color: var(--text);
        background: transparent;
        border: 0;
        border-radius: 0;
        -webkit-tap-highlight-color: transparent;
    }

    .note-item::after {
        position: absolute;
        right: 0;
        bottom: 0;
        left: 20px;
        height: 1px;
        content: "";
        background: var(--border);
    }

    .note-item:last-of-type::after {
        display: none;
    }

    .note-item:hover,
    body.mobile-note-list .note-item.active {
        background: transparent;
        border-color: transparent;
    }

    .note-item:active {
        background: var(--panel-soft);
    }

    .note-item-heading {
        gap: 7px;
        font-size: 17px;
        font-weight: 700;
        line-height: 22px;
    }

    .pin-symbol {
        font-size: 9px;
        line-height: 22px;
    }

    .note-item-preview {
        height: auto;
        margin: 3px 0 2px;
        overflow: hidden;
        font-size: 15px;
        line-height: 20px;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    .note-item time {
        display: block;
        font-size: 13px;
        line-height: 18px;
    }

    .empty-list {
        padding: 52px 20px;
        font-size: 15px;
    }

    .new-note-form {
        position: fixed;
        right: max(18px, env(safe-area-inset-right));
        bottom: max(18px, env(safe-area-inset-bottom));
        z-index: 50;
        margin: 0;
    }

    .new-note-button {
        display: grid;
        place-items: center;
        width: 54px;
        height: 54px;
        padding: 0;
        border-radius: 50%;
        box-shadow: 0 8px 24px
            color-mix(in srgb, var(--accent) 35%, transparent);
    }

    .new-note-button:active {
        transform: scale(0.96);
    }

    .new-note-icon {
        display: block;
        color: #fff;
        font-size: 27px;
        font-weight: 500;
        line-height: 1;
    }

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

    .logout-form {
        flex: none;
        margin: 8px 74px 0 0;
    }

    .logout-form button {
        padding: 10px 4px;
        text-align: left;
        border: 0;
    }

    .workspace {
        width: 100%;
        height: 100vh;
        height: 100dvh;
        min-height: 0;
        padding: 0;
        background: var(--panel);
    }

    .note-editor {
        width: 100%;
        height: 100%;
        margin: 0;
        border: 0;
        border-radius: 0;
        box-shadow: none;
    }

    .editor-header {
        flex: none;
        align-items: center;
        flex-direction: row;
        flex-wrap: wrap;
        gap: 8px;
        padding:
            max(10px, env(safe-area-inset-top))
            12px
            10px;
    }

    .mobile-back-button {
        display: inline-flex;
        flex: none;
        align-items: center;
        gap: 3px;
        color: var(--accent);
        font-size: 17px;
        font-weight: 600;
        text-decoration: none;
    }

    .mobile-back-button > span {
        font-size: 30px;
        font-weight: 400;
        line-height: 18px;
    }

    .note-title {
        flex: 1;
        width: auto;
        min-width: 0;
        font-size: 22px;
    }

    .note-actions {
        flex-basis: 100%;
        width: 100%;
        flex-wrap: nowrap;
        justify-content: flex-start;
        padding-bottom: 1px;
        overflow-x: auto;
        scrollbar-width: none;
    }

    .note-actions::-webkit-scrollbar {
        display: none;
    }

    .note-actions button {
        flex: none;
    }

    #toolbar {
        flex: none;
        overflow-x: auto;
        white-space: nowrap;
        -webkit-overflow-scrolling: touch;
    }

    .ql-toolbar.ql-snow {
        padding: 8px;
    }

    .ql-editor {
        padding:
            20px
            16px
            calc(24px + env(safe-area-inset-bottom));
    }

    .editor-footer {
        padding:
            8px
            14px
            max(8px, env(safe-area-inset-bottom));
    }
}
