/* MD3 Design Tokens & Components */

:root {
    /* Color Palette - Purple (Primary) */
    --md-sys-color-primary: #6750A4;
    --md-sys-color-on-primary: #FFFFFF;
    --md-sys-color-primary-container: #EADDFF;
    --md-sys-color-on-primary-container: #21005D;

    --md-sys-color-secondary: #625B71;
    --md-sys-color-on-secondary: #FFFFFF;
    --md-sys-color-secondary-container: #E8DEF8;
    --md-sys-color-on-secondary-container: #1D192B;

    --md-sys-color-surface: #FFFBFE;
    --md-sys-color-on-surface: #1C1B1F;
    --md-sys-color-surface-variant: #E7E0EC;
    --md-sys-color-on-surface-variant: #49454F;

    --md-sys-color-outline: #79747E;
    --md-sys-color-outline-variant: #CAC4D0;

    --md-sys-color-error: #B3261E;

    /* Surfaces */
    --md-sys-color-surface-container-lowest: #FFFFFF;
    --md-sys-color-surface-container-low: #F7F2FA;
    --md-sys-color-surface-container: #F3EDF7;
    --md-sys-color-surface-container-high: #ECE6F0;

    /* Typography */
    --md-sys-typescale-font: 'Inter', sans-serif;

    /* Shape */
    --md-sys-shape-corner-extra-small: 4px;
    --md-sys-shape-corner-small: 8px;
    --md-sys-shape-corner-medium: 12px;
    --md-sys-shape-corner-large: 16px;
    --md-sys-shape-corner-extra-large: 28px;
    --md-sys-shape-corner-full: 9999px;

    /* Elevation */
    --md-sys-elevation-level-1: 0 1px 2px rgba(0, 0, 0, 0.3), 0 1px 3px 1px rgba(0, 0, 0, 0.15);
    --md-sys-elevation-level-2: 0 1px 2px rgba(0, 0, 0, 0.3), 0 2px 6px 2px rgba(0, 0, 0, 0.15);
    --md-sys-elevation-level-3: 0 1px 3px rgba(0, 0, 0, 0.3), 0 4px 8px 3px rgba(0, 0, 0, 0.15);
}

/* Dark Theme Overrides */
[data-theme="dark"] {
    --md-sys-color-primary: #D0BCFF;
    --md-sys-color-on-primary: #381E72;
    --md-sys-color-primary-container: #4F378B;
    --md-sys-color-on-primary-container: #EADDFF;

    --md-sys-color-surface: #1C1B1F;
    --md-sys-color-on-surface: #E6E1E5;
    --md-sys-color-surface-variant: #49454F;
    --md-sys-color-on-surface-variant: #CAC4D0;

    --md-sys-color-surface-container-lowest: #0F0D13;
    --md-sys-color-surface-container-low: #1D1B20;
    --md-sys-color-surface-container: #211F26;
    --md-sys-color-surface-container-high: #2B2930;
}

body {
    background-color: var(--md-sys-color-surface);
    color: var(--md-sys-color-on-surface);
    font-family: var(--md-sys-typescale-font);
    margin: 0;
    transition: background-color 0.3s, color 0.3s;
}

/* COMPONENTS */

/* 1. Top App Bar */
.md3-top-app-bar {
    height: 64px;
    padding: 0 24px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    background-color: var(--md-sys-color-surface);
    color: var(--md-sys-color-on-surface);
    /* No shadow by default in MD3 large screens, but okay for web app */
    /* box-shadow: var(--md-sys-elevation-level-1); */
    position: sticky;
    top: 0;
    z-index: 100;
}

.md3-top-app-bar .actions {
    display: flex;
    gap: 8px;
    align-items: center;
}

/* 2. Buttons */
.md3-btn {
    height: 40px;
    padding: 0 24px;
    border-radius: var(--md-sys-shape-corner-full);
    font-size: 14px;
    font-weight: 500;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    border: none;
    transition: all 0.2s;
    text-decoration: none;
    gap: 8px;
}

.md3-btn-filled {
    background-color: var(--md-sys-color-primary);
    color: var(--md-sys-color-on-primary);
}

.md3-btn-filled:hover {
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
    opacity: 0.95;
    transform: translateY(-1px);
}

.md3-btn-filed:active {
    transform: translateY(0);
}

.md3-btn-tonal {
    background-color: var(--md-sys-color-secondary-container);
    color: var(--md-sys-color-on-secondary-container);
}

.md3-btn-tonal:hover {
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.15);
}

.md3-btn-text {
    background: transparent;
    color: var(--md-sys-color-primary);
    padding: 0 16px;
}

.md3-btn:disabled {
    background-color: rgba(28, 27, 31, 0.12);
    color: rgba(28, 27, 31, 0.38);
    cursor: not-allowed;
    box-shadow: none;
}

/* 3. Cards */
.md3-card {
    background-color: var(--md-sys-color-surface-container-low);
    border-radius: var(--md-sys-shape-corner-medium);
    padding: 24px;
    transition: all 0.2s;
}

.md3-card-elevated {
    background-color: var(--md-sys-color-surface-container-low);
    box-shadow: var(--md-sys-elevation-level-1);
}

.md3-card-outlined {
    background-color: var(--md-sys-color-surface);
    border: 1px solid var(--md-sys-color-outline-variant);
}

/* 4. Icon Button */
.md3-icon-btn {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    color: var(--md-sys-color-on-surface-variant);
    border: none;
    cursor: pointer;
    font-size: 24px;
    /* Icon size */
    transition: background 0.2s;
}

.md3-icon-btn:hover {
    background-color: rgba(73, 69, 79, 0.08);
    /* Hover state */
}

/* 5. Switch (Toggle) */
.md3-switch {
    display: inline-flex;
    align-items: center;
    cursor: pointer;
    position: relative;
    user-select: none;
}

.md3-switch input {
    display: none;
}

.md3-switch-track {
    width: 52px;
    height: 32px;
    background-color: var(--md-sys-color-surface-variant);
    border: 2px solid var(--md-sys-color-outline);
    border-radius: 100px;
    /* Pillow */
    transition: 0.2s;
}

.md3-switch-handle {
    width: 16px;
    height: 16px;
    background-color: var(--md-sys-color-outline);
    border-radius: 50%;
    position: absolute;
    top: 8px;
    /* Vertical center of 32px track (2px border) -> 28px inner -> 14 - 8 = 6? NO. */
    left: 8px;
    transition: 0.2s;
}

/* Adjustments */
.md3-switch-handle {
    top: 8px;
    left: 8px;
}

/* Checked State */
.md3-switch input:checked+.md3-switch-track {
    background-color: var(--md-sys-color-primary);
    border-color: var(--md-sys-color-primary);
}

.md3-switch input:checked+.md3-switch-track .md3-switch-handle {
    background-color: var(--md-sys-color-on-primary);
    transform: translateX(20px);
    width: 24px;
    height: 24px;
    top: 4px;
    left: 4px;
    /* Adjust left to match scaling */
}

/* 6. Slider */
input[type=range].md3-slider {
    -webkit-appearance: none;
    width: 100%;
    height: 4px;
    border-radius: 2px;
    background: var(--md-sys-color-secondary-container);
    outline: none;
}

input[type=range].md3-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: var(--md-sys-color-primary);
    cursor: pointer;
    border: none;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
}

/* Utils */
.md3-headline-small {
    font-size: 24px;
    line-height: 32px;
    font-weight: 400;
    color: var(--md-sys-color-on-surface);
}

.md3-title-medium {
    font-size: 16px;
    line-height: 24px;
    font-weight: 500;
    letter-spacing: 0.15px;
    color: var(--md-sys-color-on-surface);
}

.md3-body-medium {
    font-size: 14px;
    line-height: 20px;
    font-weight: 400;
    letter-spacing: 0.25px;
    color: var(--md-sys-color-on-surface-variant);
}