:root {
    color-scheme: light;
    --control-height: 38px;
    --panel-radius: 8px;
    --bg: #f6f7f9;
    --surface: #ffffff;
    --surface-soft: #eef3f5;
    --ink: #1f2933;
    --muted: #687385;
    --line: #d9e0ea;
    --accent: #2f6f73;
    --accent-dark: #234f52;
    --danger: #b42318;
    --shadow: 0 18px 42px rgba(31, 41, 51, 0.09);
}

:root[data-theme="dark"] {
    color-scheme: dark;
    --bg: #11171d;
    --surface: #18212a;
    --surface-soft: #202b35;
    --ink: #edf4f7;
    --muted: #a5b2bd;
    --line: #31404c;
    --accent: #5fb5a9;
    --accent-dark: #8dd4ca;
    --danger: #ff8b81;
    --shadow: 0 18px 42px rgba(0, 0, 0, 0.28);
}

* {
    box-sizing: border-box;
}

[hidden] {
    display: none !important;
}

body {
    min-height: 100vh;
    margin: 0;
    background:
        linear-gradient(180deg, rgba(47, 111, 115, 0.11), rgba(47, 111, 115, 0) 320px),
        var(--bg);
    color: var(--ink);
    font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    line-height: 1.5;
}

a {
    color: var(--accent-dark);
    font-weight: 800;
}

.topbar {
    width: min(1360px, calc(100% - 32px));
    min-height: 68px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    margin: 0 auto;
}

.brand,
.nav {
    display: flex;
    align-items: center;
}

.brand {
    gap: 10px;
    color: var(--ink);
    font-size: 18px;
    font-weight: 900;
    text-decoration: none;
}

.brand-mark {
    width: 36px;
    height: 36px;
    display: inline-grid;
    place-items: center;
    border-radius: 8px;
    background: var(--accent);
    box-shadow: 0 10px 20px rgba(47, 111, 115, 0.22);
}

.brand-mark::before {
    content: "";
    width: 17px;
    height: 21px;
    border-radius: 3px;
    background: #fff;
    box-shadow: inset 0 -6px 0 rgba(47, 111, 115, 0.18);
}

.nav {
    gap: 10px;
    flex-wrap: wrap;
    justify-content: flex-end;
}

.nav form {
    margin: 0;
}

.theme-picker {
    min-height: 36px;
    display: inline-flex;
    overflow: hidden;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--surface);
}

.theme-choice {
    min-width: 64px;
    border: 0;
    border-right: 1px solid var(--line);
    padding: 0 12px;
    background: transparent;
    color: var(--muted);
    font: inherit;
    font-size: 13px;
    font-weight: 900;
    cursor: pointer;
}

.theme-choice:last-child {
    border-right: 0;
}

.theme-choice.is-active {
    background: var(--accent);
    color: #fff;
}

.theme-choice:focus-visible {
    outline: 3px solid rgba(47, 111, 115, 0.22);
    outline-offset: -3px;
}

.user-chip,
.nav-link,
.role-chip {
    min-height: 36px;
    display: inline-flex;
    align-items: center;
    border: 1px solid rgba(47, 111, 115, 0.18);
    border-radius: 8px;
    padding: 0 12px;
    background: color-mix(in srgb, var(--surface) 82%, transparent);
    color: var(--accent-dark);
    font-size: 14px;
    font-weight: 850;
    text-decoration: none;
}

.shell {
    width: min(1360px, calc(100% - 32px));
    margin: 0 auto;
    padding: 16px 0 40px;
}

.auth-card {
    width: min(440px, 100%);
    display: grid;
    gap: 18px;
    margin: 48px auto 0;
    border: 1px solid rgba(31, 41, 51, 0.09);
    border-radius: 8px;
    padding: 28px;
    background: var(--surface);
    box-shadow: var(--shadow);
}

h1,
h2,
p {
    margin-top: 0;
}

h1 {
    margin-bottom: 8px;
    font-size: 30px;
    line-height: 1.14;
    letter-spacing: 0;
}

h2 {
    margin-bottom: 6px;
    font-size: 22px;
}

p {
    color: var(--muted);
}

.form,
.note-form {
    display: grid;
    gap: 14px;
}

label,
.compact-field {
    display: grid;
    gap: 7px;
    color: var(--ink);
    font-size: 14px;
    font-weight: 850;
}

input,
textarea,
select {
    width: 100%;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--surface);
    color: var(--ink);
    font: inherit;
    outline: none;
}

input,
select {
    min-height: 46px;
    padding: 0 12px;
}

textarea {
    min-height: 210px;
    resize: vertical;
    padding: 12px;
}

input:focus,
textarea:focus,
select:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 4px rgba(47, 111, 115, 0.14);
}

.button {
    min-height: var(--control-height);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: 1px solid var(--accent);
    border-radius: 8px;
    padding: 0 14px;
    background: var(--accent);
    color: #fff;
    font: inherit;
    font-size: 14px;
    font-weight: 900;
    text-decoration: none;
    cursor: pointer;
}

.button:hover {
    background: var(--accent-dark);
    color: #fff;
}

.button:disabled {
    cursor: not-allowed;
    opacity: 0.62;
}

.button-light {
    border-color: var(--line);
    background: var(--surface);
    color: var(--accent-dark);
}

.button-light:hover {
    background: var(--surface-soft);
    color: var(--accent-dark);
}

.button-danger {
    border-color: rgba(180, 35, 24, 0.2);
    background: var(--surface);
    color: var(--danger);
}

.text-button {
    border: 0;
    padding: 0;
    background: transparent;
    color: var(--danger);
    font: inherit;
    font-size: 13px;
    font-weight: 850;
    cursor: pointer;
}

.switch-link {
    margin: 0;
    font-size: 14px;
}

.alert {
    margin: 0;
    border: 1px solid rgba(180, 35, 24, 0.16);
    border-radius: 8px;
    padding: 10px 12px;
    background: color-mix(in srgb, var(--danger) 10%, var(--surface));
    color: var(--danger);
    font-weight: 800;
}

.memo-app {
    display: grid;
    grid-template-columns: minmax(240px, 280px) minmax(300px, 360px) minmax(420px, 1fr);
    gap: 12px;
    align-items: stretch;
}

.memo-sidebar,
.memo-list-panel,
.memo-detail,
.composer,
.note,
.user-card,
.empty-state {
    border: 1px solid rgba(31, 41, 51, 0.09);
    border-radius: var(--panel-radius);
    background: var(--surface);
    box-shadow: var(--shadow);
}

.memo-sidebar,
.memo-list-panel,
.memo-detail {
    height: calc(100vh - 124px);
    min-height: 560px;
    padding: 14px;
    overflow: auto;
}

.memo-sidebar {
    position: sticky;
    top: 12px;
    display: grid;
    align-content: start;
    gap: 12px;
}

.memo-app input,
.memo-app select {
    min-height: var(--control-height);
    padding: 0 10px;
    font-size: 14px;
}

.memo-app .button {
    min-height: var(--control-height);
    padding: 0 12px;
    font-size: 14px;
}

.toolbar-row,
.detail-actions,
.detail-top {
    display: flex;
    gap: 8px;
    align-items: center;
    flex-wrap: wrap;
}

.toolbar-row > * {
    flex: 1 1 0;
}

.save-status {
    min-height: var(--control-height);
    display: inline-flex;
    align-items: center;
    gap: 8px;
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 0 10px;
    color: var(--muted);
    font-size: 13px;
    font-weight: 850;
}

.save-status[data-mode="saving"]::before {
    content: "";
    width: 14px;
    height: 14px;
    flex: 0 0 auto;
    border: 2px solid color-mix(in srgb, var(--accent) 28%, transparent);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

.save-status[data-mode="saved"],
.save-status[data-mode="offline"] {
    border-color: color-mix(in srgb, var(--accent) 34%, var(--line));
    color: var(--accent-dark);
}

.save-status[data-mode="error"] {
    border-color: color-mix(in srgb, var(--danger) 34%, var(--line));
    color: var(--danger);
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

.save-control {
    display: flex;
    gap: 8px;
    align-items: center;
    flex-wrap: wrap;
}

.detail-save-footer {
    position: sticky;
    bottom: 0;
    z-index: 2;
    display: flex;
    justify-content: flex-end;
    border-top: 1px solid var(--line);
    padding: 10px 0;
    background: linear-gradient(180deg, color-mix(in srgb, var(--surface) 72%, transparent), var(--surface) 36%);
}

.detail-save-footer .button {
    min-width: 92px;
}

.folder-panel,
.backup-panel,
.checklist-panel,
.attachment-panel,
.history-panel {
    display: grid;
    gap: 8px;
}

.folder-heading {
    display: flex;
    gap: 8px;
    align-items: center;
    min-height: 24px;
}

.folder-heading strong {
    margin-right: auto;
    font-size: 14px;
}

.folder-list,
.note-list,
.user-list,
.checklist-items,
#historyList {
    display: grid;
    gap: 8px;
}

.selection-toolbar {
    display: flex;
    gap: 8px;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 10px;
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 8px;
    background: var(--surface-soft);
}

.selection-toolbar span {
    color: var(--muted);
    font-size: 13px;
    font-weight: 850;
}

.folder-item,
.note-card {
    width: 100%;
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 10px;
    background: var(--surface);
    color: var(--ink);
    font: inherit;
    text-align: left;
    cursor: pointer;
}

.folder-item {
    display: flex;
    justify-content: space-between;
    min-height: var(--control-height);
    align-items: center;
    font-size: 14px;
    font-weight: 850;
}

.folder-item.is-active,
.note-card.is-active {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(47, 111, 115, 0.14);
}

.folder-create {
    display: grid;
    grid-template-columns: minmax(0, 1fr) max-content;
    gap: 8px;
    align-items: stretch;
}

.folder-create .button {
    min-width: 52px;
}

.backup-panel form {
    display: grid;
    gap: 8px;
}

.note-card {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr);
    gap: 4px;
    height: 112px;
    overflow: hidden;
}

.note-open {
    display: grid;
    gap: 4px;
    min-width: 0;
    border: 0;
    padding: 0;
    background: transparent;
    color: inherit;
    font: inherit;
    text-align: left;
    cursor: pointer;
}

.select-row {
    align-self: start;
    padding-top: 2px;
}

.select-row input,
.attachment-row input[type="checkbox"] {
    width: 18px;
    min-height: 18px;
    accent-color: var(--accent);
}

.note-card strong,
.note-open strong {
    overflow: hidden;
    font-size: 15px;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.note-card p,
.note-open p {
    display: -webkit-box;
    margin-bottom: 0;
    overflow: hidden;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
}

.note-card span,
.note-card small,
.note-open span,
.note-open small {
    overflow: hidden;
    color: var(--muted);
    font-size: 12px;
    font-weight: 800;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.pin-mark {
    color: var(--accent-dark);
    font-weight: 900;
}

mark {
    border-radius: 3px;
    padding: 0 2px;
    background: #fff0a6;
    color: #1f2933;
}

.memo-detail {
    display: grid;
    gap: 12px;
    align-content: start;
}

.detail-empty {
    align-self: center;
    justify-self: center;
    text-align: center;
}

.detail-editor {
    display: grid;
    gap: 12px;
}

.detail-top {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
}

#noteTitle {
    min-height: 44px;
    font-size: 22px;
    font-weight: 900;
}

.checklist-row {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr) auto;
    gap: 8px;
    align-items: center;
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 8px;
}

.checklist-row input[type="checkbox"] {
    width: 20px;
    min-height: 20px;
    accent-color: var(--accent);
}

.checklist-row input[type="text"] {
    border: 0;
    min-height: 34px;
    padding: 0 6px;
}

.hint,
.subtle-text {
    color: var(--muted);
    font-size: 12px;
    font-weight: 800;
}

.attachment-list {
    display: grid;
    gap: 8px;
}

.attachment-row {
    display: grid;
    grid-template-columns: auto 44px minmax(0, 1fr) auto auto;
    gap: 8px;
    align-items: center;
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 8px;
}

.attachment-row a {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.attachment-row span {
    color: var(--muted);
    font-size: 12px;
    font-weight: 850;
}

.attachment-thumb {
    width: 44px;
    height: 44px;
    display: grid;
    place-items: center;
    overflow: hidden;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--surface-soft);
}

.attachment-thumb img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.attachment-file::before {
    content: "";
    width: 18px;
    height: 24px;
    border: 2px solid var(--muted);
    border-radius: 3px;
    box-shadow: inset -5px 5px 0 color-mix(in srgb, var(--muted) 12%, transparent);
}

.history-entry {
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 12px;
    background: var(--surface-soft);
}

.history-entry p {
    margin-bottom: 8px;
    white-space: pre-wrap;
}

.history-actions {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.modal-backdrop {
    position: fixed;
    inset: 0;
    z-index: 20;
    display: grid;
    place-items: center;
    padding: 18px;
    background: rgba(17, 23, 29, 0.48);
}

.modal-panel {
    width: min(960px, 100%);
    max-height: min(760px, calc(100vh - 36px));
    display: grid;
    gap: 12px;
    overflow: auto;
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 16px;
    background: var(--surface);
    box-shadow: var(--shadow);
}

.confirm-panel {
    width: min(420px, 100%);
}

.confirm-panel p {
    margin-bottom: 0;
}

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

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

.revision-compare section {
    min-width: 0;
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 12px;
    background: var(--surface-soft);
}

.revision-compare h3 {
    margin: 0 0 8px;
    font-size: 15px;
}

.revision-field {
    display: grid;
    gap: 5px;
    margin-top: 10px;
}

.revision-field span {
    color: var(--muted);
    font-size: 12px;
    font-weight: 900;
}

.revision-field strong {
    word-break: break-word;
}

.revision-field pre {
    max-height: 420px;
    margin: 0;
    overflow: auto;
    white-space: pre-wrap;
    word-break: break-word;
    font: inherit;
}

.admin-layout {
    display: grid;
    grid-template-columns: minmax(280px, 360px) minmax(0, 1fr);
    gap: 18px;
    align-items: start;
}

.composer,
.note,
.user-card,
.empty-state {
    padding: 18px;
}

.composer {
    position: sticky;
    top: 18px;
    display: grid;
    gap: 18px;
}

.section-heading p {
    margin-bottom: 0;
}

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

.user-card-header h2 {
    margin-bottom: 4px;
}

.user-card-header p {
    margin-bottom: 0;
    font-size: 13px;
    font-weight: 750;
}

.account-actions {
    display: grid;
    grid-template-columns: minmax(180px, 220px) minmax(220px, 1fr) auto;
    gap: 12px;
    align-items: end;
}

.account-actions form {
    display: grid;
    gap: 8px;
    margin: 0;
}

.empty-state {
    text-align: center;
}

.empty-state p {
    margin-bottom: 0;
}

@media (max-width: 1180px) {
    .memo-app {
        grid-template-columns: minmax(210px, 240px) minmax(260px, 320px) minmax(340px, 1fr);
    }
}

@media (max-width: 860px) {
    .topbar {
        align-items: flex-start;
        flex-direction: column;
        padding: 16px 0;
    }

    .shell {
        width: min(100% - 24px, 1200px);
        padding-top: 8px;
    }

    .memo-app,
    .admin-layout,
    .account-actions {
        grid-template-columns: 1fr;
    }

    .memo-sidebar,
    .composer {
        position: static;
    }

    .memo-sidebar,
    .memo-list-panel,
    .memo-detail {
        height: auto;
        min-height: auto;
        padding: 16px;
    }

    .detail-save-footer {
        position: static;
        justify-content: stretch;
        border-top: 0;
        padding: 0;
        background: transparent;
    }

    .detail-save-footer .button {
        width: 100%;
        box-shadow: none;
    }

    .detail-top {
        grid-template-columns: 1fr;
    }

    .toolbar-row .button,
    .detail-actions .button {
        flex: 1 1 120px;
    }

    .revision-compare {
        grid-template-columns: 1fr;
    }

    h1 {
        font-size: 28px;
    }

    #noteTitle {
        font-size: 20px;
    }
}

@media (max-width: 520px) {
    .topbar,
    .shell {
        width: min(100% - 20px, 1360px);
    }

    .brand {
        font-size: 17px;
    }

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

    .theme-picker,
    .user-chip,
    .nav-link,
    .nav form,
    .nav .button {
        flex: 1 1 auto;
    }

    .theme-choice {
        min-width: 0;
        flex: 1 1 0;
        padding: 0 10px;
    }

    .memo-sidebar,
    .memo-list-panel,
    .memo-detail {
        padding: 14px;
    }

    .folder-create {
        grid-template-columns: minmax(0, 1fr) max-content;
    }
}
