:root {
    --brand-500: #208BBF;
    --brand-600: #183994;
    --brand-50: #f0f7ff;
    --surface: #ffffff;
    --surface-soft: #f8fafc;
    --text: #1f2937;
    --muted: #64748b;
    --border: #dbe1ea;
    --success: #15803d;
    --warning: #b45309;
    --danger: #dc2626;
    --shadow: 0 10px 30px rgba(15, 23, 42, 0.08);
}

* {
    box-sizing: border-box;
}

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

body {
    font-family: Arial, sans-serif;
    color: var(--text);
    background: linear-gradient(180deg, #f7f9fc 0%, #ffffff 100%);
}

/* === Nav === */
.app-nav {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 10px 18px;
    background: linear-gradient(90deg, var(--brand-600), var(--brand-500));
    color: #fff;
    box-shadow: 0 2px 12px rgba(24, 57, 148, 0.2);
}

.brand-link {
    display: inline-flex;
    align-items: center;
    gap: 12px;
    color: inherit;
    text-decoration: none;
}

.brand-mark {
    font-size: 1.8rem;
    line-height: 1;
}

.brand-text {
    display: inline-flex;
    align-items: baseline;
    gap: 6px;
    font-size: 1.65rem;
}

.brand-text strong {
    font-weight: 700;
}

.brand-text span {
    font-size: 1rem;
    opacity: 0.9;
}

.nav-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}

.nav-icon-button {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    height: 40px;
    padding: 0 12px;
    border: none;
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.15);
    color: #fff;
    font: inherit;
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s;
    white-space: nowrap;
}

.nav-icon-button:hover {
    background: rgba(255, 255, 255, 0.28);
}

.nav-button-label {
    font-size: 0.88rem;
}

/* === Main === */
.page-main {
    max-width: 1320px;
    margin: 0 auto;
    padding: 18px 20px 40px;
}

.editor-panel {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 10px;
    box-shadow: var(--shadow);
    padding: 20px;
}

.title-input,
.content-editor {
    width: 100%;
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 14px 16px;
    font: inherit;
    color: var(--text);
    background: var(--surface);
    outline: none;
}

.title-input {
    margin-bottom: 16px;
    font-size: 2rem;
    font-weight: 700;
}

.title-input:focus,
.content-editor:focus {
    border-color: rgba(32, 139, 191, 0.55);
    box-shadow: 0 0 0 4px rgba(32, 139, 191, 0.12);
}

.toolbar-row,
.toolbar-actions,
.footer-row,
.save-group,
.dialog-actions {
    display: flex;
    align-items: center;
}

.toolbar-row,
.footer-row {
    justify-content: space-between;
    gap: 16px;
}

.toolbar-row {
    margin-bottom: 14px;
}

.toolbar-actions {
    gap: 14px;
    flex-wrap: wrap;
}

.tablist {
    display: inline-flex;
    align-items: center;
    gap: 8px;
}

.tab-button {
    border: none;
    background: none;
    padding: 0;
    color: var(--brand-500);
    font: inherit;
    font-weight: 700;
    cursor: pointer;
}

.tab-button[aria-selected="true"] {
    color: var(--brand-600);
    text-decoration: underline;
    text-underline-offset: 4px;
}

.mode-description,
.toolbar-note,
.draft-status,
.save-status,
#draft-dialog-description,
#new-memo-dialog-description {
    margin: 0;
    color: var(--muted);
    font-size: 0.95rem;
    line-height: 1.6;
}

.editor-container {
    display: flex;
    gap: 16px;
}

.editor-container .content-editor {
    flex: 1;
    min-width: 0;
}

.content-editor {
    min-height: 430px;
    resize: vertical;
    font-size: 1rem;
    line-height: 1.65;
}

/* === Markdown Preview === */
.md-preview {
    flex: 1;
    min-width: 0;
    min-height: 430px;
    max-height: 600px;
    overflow-y: auto;
    padding: 14px 16px;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: var(--surface-soft);
    font-size: 1rem;
    line-height: 1.65;
}

.md-preview-empty {
    color: var(--muted);
    margin: 0;
}

.md-preview h1, .md-preview h2, .md-preview h3,
.md-preview h4, .md-preview h5, .md-preview h6 {
    margin: 0.6em 0 0.4em;
    line-height: 1.3;
}

.md-preview h1 { font-size: 1.6rem; border-bottom: 2px solid var(--border); padding-bottom: 0.3em; }
.md-preview h2 { font-size: 1.35rem; border-bottom: 1px solid var(--border); padding-bottom: 0.25em; }
.md-preview h3 { font-size: 1.15rem; }

.md-preview p { margin: 0.5em 0; }

.md-preview ul, .md-preview ol {
    padding-left: 1.5em;
    margin: 0.5em 0;
}

.md-preview code {
    background: #f1f5f9;
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 0.9em;
    font-family: 'SF Mono', 'Fira Code', monospace;
}

.md-preview pre {
    border-radius: 8px;
    overflow-x: auto;
    margin: 0.6em 0;
}

.md-preview pre code {
    padding: 14px 16px;
    display: block;
    font-size: 0.88em;
}

.md-preview blockquote {
    margin: 0.5em 0;
    padding: 8px 16px;
    border-left: 4px solid var(--brand-500);
    background: var(--brand-50);
    color: var(--text);
}

.md-preview blockquote p { margin: 0.25em 0; }

.md-preview table {
    width: 100%;
    border-collapse: collapse;
    margin: 0.6em 0;
}

.md-preview th, .md-preview td {
    border: 1px solid var(--border);
    padding: 8px 12px;
    text-align: left;
}

.md-preview th {
    background: var(--surface-soft);
    font-weight: 700;
}

.md-preview hr {
    border: none;
    border-top: 1px solid var(--border);
    margin: 1em 0;
}

.md-preview img {
    max-width: 100%;
    border-radius: 6px;
}

.md-preview a {
    color: var(--brand-500);
    text-decoration: underline;
}

/* === Footer === */
.footer-row {
    margin-top: 14px;
}

.save-group {
    gap: 14px;
    flex-wrap: wrap;
}

.save-button,
.dialog-primary,
.dialog-secondary {
    border: none;
    border-radius: 6px;
    padding: 10px 18px;
    font: inherit;
    cursor: pointer;
}

.save-button,
.dialog-primary {
    background: linear-gradient(135deg, var(--brand-500), var(--brand-600));
    color: #fff;
    font-weight: 700;
}

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

.dialog-secondary {
    background: #eef2f7;
    color: var(--text);
    font-weight: 700;
}

.dialog-danger {
    background: #fef2f2;
    color: var(--danger);
}

.dialog-danger:hover {
    background: #fee2e2;
}

.draft-status.is-success,
.save-status.is-success {
    color: var(--success);
}

.draft-status.is-warning,
.save-status.is-warning {
    color: var(--warning);
}

/* === Drawer toggle (legacy compat) === */
.drawer-toggle {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    border: none;
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.15);
    color: #fff;
    cursor: pointer;
    transition: background 0.2s;
}

.drawer-toggle:hover {
    background: rgba(255, 255, 255, 0.28);
}

/* === Drawer backdrop === */
.drawer-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.4);
    z-index: 90;
    opacity: 0;
    transition: opacity 0.25s;
}

.drawer-backdrop.is-open {
    opacity: 1;
}

/* === Side drawer === */
.saved-drawer {
    position: fixed;
    top: 0;
    right: 0;
    width: min(380px, 85vw);
    height: 100%;
    background: var(--surface);
    box-shadow: -8px 0 30px rgba(15, 23, 42, 0.15);
    z-index: 100;
    transform: translateX(100%);
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    overflow-y: auto;
    padding: 24px;
    display: flex;
    flex-direction: column;
}

.saved-drawer.is-open {
    transform: translateX(0);
}

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

.drawer-header h2 {
    margin: 0;
    font-size: 1.25rem;
}

.drawer-close {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    border: none;
    border-radius: 8px;
    background: none;
    color: var(--muted);
    cursor: pointer;
    transition: background 0.2s, color 0.2s;
    flex-shrink: 0;
}

.drawer-close:hover {
    background: #f1f5f9;
    color: var(--text);
}

.drawer-sub {
    margin: 4px 0 0;
    color: var(--muted);
    font-size: 0.9rem;
}

/* === Memo list in drawer === */
.memo-list {
    flex: 1;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.memo-list-empty {
    text-align: center;
    padding: 40px 16px;
    color: var(--muted);
}

.memo-list-empty p {
    margin: 0;
    font-size: 0.95rem;
}

.memo-list-empty-sub {
    margin-top: 6px !important;
    font-size: 0.85rem !important;
    opacity: 0.8;
}

.memo-item {
    position: relative;
    padding: 14px 16px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--surface-soft);
    cursor: pointer;
    transition: border-color 0.2s, box-shadow 0.2s;
}

.memo-item:hover {
    border-color: rgba(32, 139, 191, 0.4);
    box-shadow: 0 2px 8px rgba(32, 139, 191, 0.1);
}

.memo-item.is-active {
    border-color: var(--brand-500);
    background: var(--brand-50);
}

.memo-item-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 8px;
}

.memo-item-title {
    margin: 0;
    font-size: 0.98rem;
    font-weight: 600;
    color: var(--text);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    flex: 1;
    min-width: 0;
}

.memo-item-delete {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    border: none;
    border-radius: 6px;
    background: none;
    color: var(--muted);
    cursor: pointer;
    transition: background 0.15s, color 0.15s;
    flex-shrink: 0;
    opacity: 0;
}

.memo-item:hover .memo-item-delete {
    opacity: 1;
}

.memo-item-delete:hover {
    background: #fef2f2;
    color: var(--danger);
}

.memo-item-meta {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-top: 4px;
    font-size: 0.82rem;
    color: var(--muted);
}

.memo-item-badge {
    display: inline-block;
    padding: 1px 7px;
    border-radius: 4px;
    font-size: 0.75rem;
    font-weight: 600;
    background: #fef3c7;
    color: var(--warning);
}

.memo-item-preview {
    margin: 6px 0 0;
    font-size: 0.85rem;
    color: var(--muted);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* === Dialog === */
.dialog-backdrop {
    position: fixed;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    background: rgba(15, 23, 42, 0.5);
    z-index: 200;
}

.dialog-card {
    width: min(100%, 420px);
    background: #fff;
    border-radius: 10px;
    padding: 24px;
    box-shadow: 0 24px 60px rgba(15, 23, 42, 0.28);
}

.dialog-card-settings {
    width: min(100%, 480px);
}

.dialog-card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 20px;
}

.dialog-card-header h2 {
    margin: 0;
    font-size: 1.35rem;
}

.dialog-card h2 {
    margin: 0 0 10px;
    font-size: 1.35rem;
}

.dialog-actions {
    justify-content: flex-end;
    gap: 10px;
    margin-top: 18px;
}

.dialog-actions-triple {
    flex-wrap: wrap;
}

/* === Dialog checkbox === */
.dialog-checkbox-label {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-top: 14px;
    font-size: 0.92rem;
    color: var(--muted);
    cursor: pointer;
}

.dialog-checkbox-label input[type="checkbox"] {
    width: 16px;
    height: 16px;
    accent-color: var(--brand-500);
    cursor: pointer;
}

/* === Settings dialog === */
.settings-section {
    margin-bottom: 22px;
}

.settings-label {
    margin: 0 0 10px;
    font-size: 1rem;
    font-weight: 600;
    color: var(--text);
}

.settings-slider-row {
    display: flex;
    align-items: center;
    gap: 12px;
}

.settings-range-label {
    font-size: 0.82rem;
    color: var(--muted);
    white-space: nowrap;
    min-width: 32px;
}

.settings-slider {
    flex: 1;
    height: 6px;
    -webkit-appearance: none;
    appearance: none;
    background: var(--border);
    border-radius: 3px;
    outline: none;
}

.settings-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--brand-500), var(--brand-600));
    cursor: pointer;
    box-shadow: 0 2px 6px rgba(32, 139, 191, 0.3);
}

.settings-slider::-moz-range-thumb {
    width: 20px;
    height: 20px;
    border-radius: 50%;
    border: none;
    background: linear-gradient(135deg, var(--brand-500), var(--brand-600));
    cursor: pointer;
    box-shadow: 0 2px 6px rgba(32, 139, 191, 0.3);
}

.settings-value {
    margin: 8px 0 0;
    font-size: 0.88rem;
    color: var(--brand-600);
    font-weight: 600;
}

.settings-radio-group {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.settings-radio-label {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 0.95rem;
    color: var(--text);
    cursor: pointer;
    padding: 8px 12px;
    border-radius: 6px;
    border: 1px solid var(--border);
    transition: border-color 0.2s, background 0.2s;
}

.settings-radio-label:hover {
    background: var(--surface-soft);
}

.settings-radio-label input[type="radio"] {
    accent-color: var(--brand-500);
    width: 16px;
    height: 16px;
    cursor: pointer;
}

.settings-radio-label input[type="radio"]:checked + span {
    color: var(--brand-600);
    font-weight: 600;
}

/* === Utility === */
.hidden {
    display: none !important;
}

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

/* === Responsive === */
@media (max-width: 920px) {
    .app-nav {
        flex-wrap: wrap;
        gap: 10px;
    }

    .toolbar-row,
    .footer-row {
        flex-direction: column;
        align-items: flex-start;
    }

    .toolbar-actions,
    .save-group,
    .dialog-actions {
        width: 100%;
        flex-wrap: wrap;
    }

    .brand-text {
        font-size: 1.3rem;
        flex-wrap: wrap;
    }

    .nav-button-label {
        display: none;
    }

    .title-input {
        font-size: 1.5rem;
    }

    .content-editor {
        min-height: 420px;
    }

    .editor-container {
        flex-direction: column;
    }

    .md-preview {
        min-height: 300px;
    }

    .memo-item-delete {
        opacity: 1;
    }
}
