:root {
    --bg-main: #f5f3ef;
    --bg-card: #f7f3ee;
    --bg-card-elevated: #efeae2;
    --bg-surface-contrast: #ffffff;
    --ink: #303a50;
    --ink-muted: rgba(48, 58, 80, 0.72);
    --ink-subtle: rgba(48, 58, 80, 0.52);
    --line: #303a50;
    --line-subtle: rgba(48, 58, 80, 0.16);
    --line-medium: rgba(48, 58, 80, 0.28);
    --state-hover: rgba(48, 58, 80, 0.08);
    --state-active: rgba(48, 58, 80, 0.14);
    --btn-hover: #242d3f;
    --font-serif: 'DM Serif Display', Georgia, serif;
    --font-sans: 'DM Sans', system-ui, -apple-system, sans-serif;
    --ease-fast: 140ms cubic-bezier(0.2, 0, 0, 1);
    --radius-xs: 8px;
    --radius-sm: 12px;
    --radius-md: 16px;
    --radius-lg: 22px;
    --radius-xl: 28px;
    --radius-pill: 9999px;
}

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

html {
    background-color: var(--bg-main);
    color: var(--ink);
    font-family: var(--font-sans);
    font-size: 16px;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    scroll-behavior: smooth;
}

/* Custom Material 3 Scrollbar (applied strictly where default scroll is active) */
html,
body,
.m3-dialog,
.m3-table-wrap,
.m3-code,
.nav-rail,
.m3-textarea {
    scrollbar-width: thin;
    scrollbar-color: rgba(48, 58, 80, 0.42) var(--bg-main);
}

html::-webkit-scrollbar,
body::-webkit-scrollbar,
.m3-dialog::-webkit-scrollbar,
.m3-table-wrap::-webkit-scrollbar,
.m3-code::-webkit-scrollbar,
.nav-rail::-webkit-scrollbar,
.m3-textarea::-webkit-scrollbar {
    width: 10px;
    height: 10px;
}

html::-webkit-scrollbar-track,
body::-webkit-scrollbar-track,
.m3-dialog::-webkit-scrollbar-track,
.m3-table-wrap::-webkit-scrollbar-track,
.m3-code::-webkit-scrollbar-track,
.nav-rail::-webkit-scrollbar-track,
.m3-textarea::-webkit-scrollbar-track {
    background: var(--bg-main);
    border-radius: var(--radius-pill);
}

html::-webkit-scrollbar-thumb,
body::-webkit-scrollbar-thumb,
.m3-dialog::-webkit-scrollbar-thumb,
.m3-table-wrap::-webkit-scrollbar-thumb,
.m3-code::-webkit-scrollbar-thumb,
.nav-rail::-webkit-scrollbar-thumb,
.m3-textarea::-webkit-scrollbar-thumb {
    background-color: rgba(48, 58, 80, 0.36);
    border-radius: var(--radius-pill);
    border: 2px solid var(--bg-main);
    transition: background-color var(--ease-fast);
}

html::-webkit-scrollbar-thumb:hover,
body::-webkit-scrollbar-thumb:hover,
.m3-dialog::-webkit-scrollbar-thumb:hover,
.m3-table-wrap::-webkit-scrollbar-thumb:hover,
.m3-code::-webkit-scrollbar-thumb:hover,
.nav-rail::-webkit-scrollbar-thumb:hover,
.m3-textarea::-webkit-scrollbar-thumb:hover {
    background-color: rgba(48, 58, 80, 0.68);
}

html::-webkit-scrollbar-thumb:active,
body::-webkit-scrollbar-thumb:active,
.m3-dialog::-webkit-scrollbar-thumb:active,
.m3-table-wrap::-webkit-scrollbar-thumb:active,
.m3-code::-webkit-scrollbar-thumb:active,
.nav-rail::-webkit-scrollbar-thumb:active,
.m3-textarea::-webkit-scrollbar-thumb:active {
    background-color: var(--ink);
}

html::-webkit-scrollbar-corner,
body::-webkit-scrollbar-corner,
.m3-dialog::-webkit-scrollbar-corner,
.m3-table-wrap::-webkit-scrollbar-corner,
.m3-code::-webkit-scrollbar-corner,
.nav-rail::-webkit-scrollbar-corner,
.m3-textarea::-webkit-scrollbar-corner {
    background: var(--bg-main);
}

body {
    background-color: var(--bg-main);
    color: var(--ink);
    font-family: var(--font-sans);
    min-height: 100vh;
}

h1, h2, h3, h4, .serif {
    font-family: var(--font-serif);
    font-weight: 400;
    color: var(--ink);
    line-height: 1.18;
    letter-spacing: -0.01em;
}

a {
    color: var(--ink);
    text-decoration: none;
    transition: opacity var(--ease-fast), background-color var(--ease-fast);
}

button, input, select, textarea {
    font-family: var(--font-sans);
    color: var(--ink);
}

/* Material 3 Expressive Rounded Icons */
.ms-icon {
    font-family: 'Material Symbols Rounded';
    font-weight: normal;
    font-style: normal;
    font-size: 20px;
    line-height: 1;
    letter-spacing: normal;
    text-transform: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    white-space: nowrap;
    word-wrap: normal;
    direction: ltr;
    -webkit-font-smoothing: antialiased;
    font-variation-settings: 'FILL' 0, 'wght' 400, 'GRAD' 0, 'opsz' 24;
    user-select: none;
    flex-shrink: 0;
}

.ms-icon.filled {
    font-variation-settings: 'FILL' 1, 'wght' 400, 'GRAD' 0, 'opsz' 24;
}

.ms-icon.sm { font-size: 18px; }
.ms-icon.lg { font-size: 24px; }
.ms-icon.xl { font-size: 28px; }

/* Fast Page Entry Transition (No scale, no glow) */
@keyframes m3FadeSlide {
    from {
        opacity: 0;
        transform: translateY(4px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.view-animate {
    animation: m3FadeSlide 140ms cubic-bezier(0.2, 0, 0, 1) forwards;
}

/* Material 3 Buttons (No scale transform, no excess shadow, no glow) */
.m3-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    height: 42px;
    padding: 0 22px;
    border-radius: var(--radius-pill);
    border: none;
    font-family: var(--font-sans);
    font-size: 0.925rem;
    font-weight: 500;
    letter-spacing: 0.01em;
    cursor: pointer;
    transition: background-color var(--ease-fast), color var(--ease-fast), opacity var(--ease-fast);
    white-space: nowrap;
    text-decoration: none;
}

.m3-btn:disabled {
    opacity: 0.45;
    cursor: not-allowed;
}

.m3-btn-filled {
    background-color: var(--ink);
    color: var(--bg-main);
}

.m3-btn-filled:hover:not(:disabled) {
    background-color: var(--btn-hover);
}

.m3-btn-tonal {
    background-color: var(--bg-card-elevated);
    color: var(--ink);
}

.m3-btn-tonal:hover:not(:disabled) {
    background-color: rgba(48, 58, 80, 0.14);
}

.m3-btn-outlined {
    background-color: transparent;
    color: var(--ink);
    border: 1px solid var(--line);
}

.m3-btn-outlined:hover:not(:disabled) {
    background-color: var(--state-hover);
}

.m3-btn-text {
    background-color: transparent;
    color: var(--ink);
    padding: 0 14px;
}

.m3-btn-text:hover:not(:disabled) {
    background-color: var(--state-hover);
}

.m3-btn-sm {
    height: 34px;
    padding: 0 14px;
    font-size: 0.84rem;
}

.m3-icon-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 38px;
    height: 38px;
    border-radius: var(--radius-pill);
    border: none;
    background: transparent;
    color: var(--ink);
    cursor: pointer;
    transition: background-color var(--ease-fast);
}

.m3-icon-btn:hover:not(:disabled) {
    background-color: var(--state-hover);
}

/* Material 3 Clean Borderless Cards */
.m3-card {
    background-color: var(--bg-card);
    border-radius: var(--radius-lg);
    border: none;
    box-shadow: none;
    padding: 24px;
    transition: background-color var(--ease-fast);
}

.m3-card-compact {
    background-color: var(--bg-card);
    border-radius: var(--radius-md);
    border: none;
    box-shadow: none;
    padding: 18px 20px;
}

.m3-card-contrast {
    background-color: var(--bg-surface-contrast);
    border-radius: var(--radius-lg);
    border: none;
    box-shadow: none;
    padding: 24px;
}

.m3-card-dark {
    background-color: var(--ink);
    color: var(--bg-main);
    border-radius: var(--radius-lg);
    border: none;
    box-shadow: none;
    padding: 24px;
}

.m3-card-dark h1, .m3-card-dark h2, .m3-card-dark h3, .m3-card-dark h4 {
    color: var(--bg-main);
}

/* Structural Lines (Strictly #303a50 or clean subtle alpha) */
.m3-divider {
    border: none;
    border-top: 1px solid var(--line-subtle);
    margin: 20px 0;
}

.m3-divider-strong {
    border: none;
    border-top: 1px solid var(--line);
    margin: 20px 0;
}

/* Material 3 Form Controls */
.m3-field {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-bottom: 16px;
}

.m3-label {
    font-size: 0.84rem;
    font-weight: 600;
    color: var(--ink);
    letter-spacing: 0.01em;
}

.m3-input, .m3-select, .m3-textarea {
    width: 100%;
    background-color: var(--bg-main);
    color: var(--ink);
    border: none;
    border-bottom: 1.5px solid var(--line);
    border-radius: var(--radius-xs) var(--radius-xs) 0 0;
    padding: 11px 14px;
    font-size: 0.95rem;
    transition: background-color var(--ease-fast), border-color var(--ease-fast);
    outline: none;
}

.m3-input-surface {
    background-color: var(--bg-card);
}

.m3-input:focus, .m3-select:focus, .m3-textarea:focus {
    background-color: var(--bg-card-elevated);
    border-bottom-width: 2px;
}

.m3-textarea {
    min-height: 92px;
    resize: vertical;
}

/* Material 3 Checkbox & Switch */
.m3-check-row {
    display: inline-flex;
    align-items: flex-start;
    gap: 10px;
    cursor: pointer;
    user-select: none;
    font-size: 0.92rem;
    color: var(--ink);
}

.m3-checkbox {
    appearance: none;
    width: 20px;
    height: 20px;
    border: 1.75px solid var(--line);
    border-radius: 5px;
    background-color: transparent;
    display: inline-grid;
    place-content: center;
    cursor: pointer;
    flex-shrink: 0;
    margin-top: 2px;
    transition: background-color var(--ease-fast);
}

.m3-checkbox:checked {
    background-color: var(--ink);
}

.m3-checkbox:checked::before {
    content: 'check';
    font-family: 'Material Symbols Rounded';
    font-size: 15px;
    color: var(--bg-main);
    line-height: 1;
}

/* Material 3 Chips / Tags (Clean, no outline) */
.m3-chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    height: 28px;
    padding: 0 12px;
    border-radius: var(--radius-pill);
    background-color: var(--bg-card-elevated);
    color: var(--ink);
    font-size: 0.78rem;
    font-weight: 600;
    letter-spacing: 0.01em;
}

.m3-chip-filled {
    background-color: var(--ink);
    color: var(--bg-main);
}

/* Layout Shells */
.top-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 32px;
    border-bottom: 1px solid var(--line-subtle);
    background-color: var(--bg-main);
    position: sticky;
    top: 0;
    z-index: 30;
}

.brand-mark {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    font-family: var(--font-serif);
    font-size: 1.45rem;
    color: var(--ink);
}

.app-shell {
    display: grid;
    grid-template-columns: 260px 1fr;
    min-height: calc(100vh - 69px);
}

.nav-rail {
    padding: 24px 16px;
    border-right: 1px solid var(--line-subtle);
    background-color: var(--bg-main);
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.nav-rail-item {
    display: flex;
    align-items: center;
    gap: 12px;
    height: 46px;
    padding: 0 16px;
    border-radius: var(--radius-pill);
    border: none;
    background: transparent;
    color: var(--ink);
    font-size: 0.92rem;
    font-weight: 500;
    cursor: pointer;
    text-align: left;
    transition: background-color var(--ease-fast);
    width: 100%;
}

.nav-rail-item:hover {
    background-color: var(--state-hover);
}

.nav-rail-item.active {
    background-color: var(--ink);
    color: var(--bg-main);
    font-weight: 600;
}

.main-stage {
    padding: 32px 40px 64px;
    max-width: 1280px;
    width: 100%;
}

/* Grid Helpers */
.grid-2 {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 20px;
}

.grid-3 {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 20px;
}

.grid-4 {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 16px;
}

.flex-between {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    flex-wrap: wrap;
}

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

/* Clean Data Tables */
.m3-table-wrap {
    width: 100%;
    overflow-x: auto;
}

.m3-table {
    width: 100%;
    border-collapse: collapse;
    text-align: left;
    font-size: 0.92rem;
}

.m3-table th {
    padding: 12px 14px;
    font-weight: 600;
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--ink-muted);
    border-bottom: 1.5px solid var(--line);
}

.m3-table td {
    padding: 14px;
    border-bottom: 1px solid var(--line-subtle);
    vertical-align: middle;
}

/* Progress Bar (Material 3 Linear Indicator) */
.m3-progress-track {
    width: 100%;
    height: 8px;
    background-color: var(--bg-card-elevated);
    border-radius: var(--radius-pill);
    overflow: hidden;
}

.m3-progress-fill {
    height: 100%;
    background-color: var(--ink);
    border-radius: var(--radius-pill);
    transition: width 160ms cubic-bezier(0.2, 0, 0, 1);
}

/* Checklist Interactive Row */
.checklist-row {
    display: flex;
    align-items: flex-start;
    gap: 14px;
    padding: 14px 16px;
    border-radius: var(--radius-md);
    background-color: var(--bg-main);
    cursor: pointer;
    transition: background-color var(--ease-fast);
    margin-bottom: 8px;
}

.checklist-row:hover {
    background-color: var(--bg-card-elevated);
}

.checklist-row.completed .checklist-label {
    text-decoration: line-through;
    color: var(--ink-muted);
}

/* Modal / Dialog (Material 3 Dialog) */
.m3-dialog-backdrop {
    position: fixed;
    inset: 0;
    background-color: rgba(48, 58, 80, 0.42);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    z-index: 100;
    animation: m3FadeSlide 120ms cubic-bezier(0.2, 0, 0, 1);
}

.m3-dialog {
    background-color: var(--bg-card);
    color: var(--ink);
    border-radius: var(--radius-xl);
    border: none;
    width: 100%;
    max-width: 620px;
    max-height: 90vh;
    overflow-y: auto;
    padding: 28px;
}

/* Snackbar / Toast */
#toast-root {
    position: fixed;
    bottom: 24px;
    right: 24px;
    z-index: 200;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.m3-snackbar {
    background-color: var(--ink);
    color: var(--bg-main);
    padding: 12px 20px;
    border-radius: var(--radius-md);
    font-size: 0.9rem;
    font-weight: 500;
    display: flex;
    align-items: center;
    gap: 10px;
    animation: m3FadeSlide 120ms cubic-bezier(0.2, 0, 0, 1);
}

/* Code Block */
.m3-code {
    background-color: var(--ink);
    color: var(--bg-main);
    padding: 16px 18px;
    border-radius: var(--radius-md);
    font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
    font-size: 0.85rem;
    overflow-x: auto;
    line-height: 1.55;
}

/* Responsive Breakpoints */
@media (max-width: 960px) {
    .app-shell {
        grid-template-columns: 1fr;
    }
    .nav-rail {
        flex-direction: row;
        overflow-x: auto;
        border-right: none;
        border-bottom: 1px solid var(--line-subtle);
        padding: 12px 16px;
    }
    .nav-rail-item {
        width: auto;
        flex-shrink: 0;
    }
    .main-stage {
        padding: 24px 18px 48px;
    }
    .grid-2, .grid-3, .grid-4 {
        grid-template-columns: 1fr;
    }
    .top-bar {
        padding: 14px 18px;
    }
}

/* Rich Text Editor & Formatted Content Blocks */
.rte-surface:empty::before {
    content: attr(data-placeholder);
    color: var(--ink-subtle);
    pointer-events: none;
}

.rte-surface ul,
.rte-content ul {
    list-style-type: disc;
    padding-left: 1.5rem;
    margin: 0.5rem 0;
}

.rte-surface ol,
.rte-content ol {
    list-style-type: decimal;
    padding-left: 1.5rem;
    margin: 0.5rem 0;
}

.rte-surface li,
.rte-content li {
    margin-bottom: 0.25rem;
}

.rte-surface p,
.rte-content p {
    margin-bottom: 0.65rem;
}

.rte-surface h2,
.rte-content h2 {
    font-size: 1.35rem;
    margin: 0.75rem 0 0.35rem;
}

.rte-surface h3,
.rte-content h3 {
    font-size: 1.15rem;
    margin: 0.65rem 0 0.3rem;
}

.rte-surface a,
.rte-content a {
    color: var(--ink);
    text-decoration: underline;
    font-weight: 600;
}

