:root {
    --md-sys-color-primary: #4f378b;
    --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-tertiary: #7d5260;
    --md-sys-color-on-tertiary: #ffffff;
    --md-sys-color-tertiary-container: #ffd8e4;
    --md-sys-color-on-tertiary-container: #31111d;

    --md-sys-color-surface: #10131c;
    --md-sys-color-surface-dim: #0c0f17;
    --md-sys-color-surface-bright: #1d212c;
    --md-sys-color-surface-container-lowest: #0a0d14;
    --md-sys-color-surface-container-low: #141824;
    --md-sys-color-surface-container: #191d28;
    --md-sys-color-surface-container-high: #222733;
    --md-sys-color-surface-container-highest: #2c3240;

    --md-sys-color-on-surface: #e3e2e6;
    --md-sys-color-on-surface-variant: #c5c6d0;

    --md-sys-color-outline: #8f9099;
    --md-sys-color-outline-variant: #454754;

    --md-sys-color-error: #ffb4ab;
    --md-sys-color-on-error: #690005;
    --md-sys-color-error-container: #93000a;
    --md-sys-color-on-error-container: #ffdad6;

    --md-sys-color-success: #8de5b0;
    --md-sys-color-on-success: #00391f;
    --md-sys-color-success-container: #00522f;
    --md-sys-color-on-success-container: #a9f5c7;

    --md-shape-corner-small: 8px;
    --md-shape-corner-medium: 14px;
    --md-shape-corner-large: 20px;
    --md-shape-corner-xl: 28px;

    --md-elevation-1: 0 1px 2px rgba(0, 0, 0, 0.28), 0 1px 3px rgba(0, 0, 0, 0.24);
    --md-elevation-2: 0 2px 6px rgba(0, 0, 0, 0.28), 0 1px 2px rgba(0, 0, 0, 0.24);
    --md-elevation-3: 0 6px 16px rgba(0, 0, 0, 0.28), 0 2px 5px rgba(0, 0, 0, 0.24);
}

* {
    box-sizing: border-box;
}

html,
body {
    margin: 0;
    padding: 0;
}

body.md3-body {
    font-family: "Roboto", "Noto Sans", "Segoe UI", Arial, sans-serif;
    color: var(--md-sys-color-on-surface);
    min-height: 100vh;
    background:
        radial-gradient(circle at 12% 8%, color-mix(in srgb, var(--md-sys-color-primary) 22%, transparent), transparent 42%),
        radial-gradient(circle at 85% 90%, color-mix(in srgb, var(--md-sys-color-secondary) 18%, transparent), transparent 45%),
        linear-gradient(170deg, var(--md-sys-color-surface-dim), var(--md-sys-color-surface));
}

.md3-top-app-bar {
    position: sticky;
    top: 0;
    z-index: 40;
    background: color-mix(in srgb, var(--md-sys-color-surface-container-low) 85%, transparent);
    backdrop-filter: blur(12px);
    border-bottom: 1px solid color-mix(in srgb, var(--md-sys-color-outline-variant) 55%, transparent);
}

.md3-top-app-bar__inner,
.md3-container {
    width: min(1200px, 94vw);
    margin: 0 auto;
}

.md3-top-app-bar__inner {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 12px 0;
    flex-wrap: wrap;
}

.md3-brand {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.md3-title-large {
    margin: 0;
    font-size: 1.3rem;
    line-height: 1.35;
    font-weight: 600;
    letter-spacing: 0.01em;
}

.md3-title-medium {
    margin: 0;
    font-size: 1.05rem;
    line-height: 1.4;
    font-weight: 600;
}

.md3-title-small {
    margin: 0;
    font-size: 0.95rem;
    line-height: 1.4;
    font-weight: 600;
}

.md3-body-medium {
    margin: 0;
    font-size: 0.95rem;
    line-height: 1.5;
    color: var(--md-sys-color-on-surface-variant);
}

.md3-body-small {
    margin: 0;
    font-size: 0.82rem;
    line-height: 1.4;
    color: var(--md-sys-color-on-surface-variant);
}

.md3-label {
    font-size: 0.78rem;
    line-height: 1.35;
    color: var(--md-sys-color-on-surface-variant);
    margin-bottom: 6px;
    display: inline-block;
}

.md3-container {
    padding: 18px 0 40px;
}

.md3-grid {
    display: grid;
    gap: 14px;
}

.md3-grid.cols-2 {
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
}

.md3-grid.cols-3 {
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
}

.md3-card {
    background: color-mix(in srgb, var(--md-sys-color-surface-container) 92%, transparent);
    border: 1px solid color-mix(in srgb, var(--md-sys-color-outline-variant) 55%, transparent);
    border-radius: var(--md-shape-corner-large);
    box-shadow: var(--md-elevation-1);
    padding: 16px;
}

.md3-card.tonal {
    background: color-mix(in srgb, var(--md-sys-color-secondary-container) 18%, var(--md-sys-color-surface-container));
}

.md3-card.outline {
    background: transparent;
    box-shadow: none;
}

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

.md3-chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    border-radius: 999px;
    padding: 7px 12px;
    font-size: 0.78rem;
    border: 1px solid color-mix(in srgb, var(--md-sys-color-outline) 45%, transparent);
    color: var(--md-sys-color-on-surface-variant);
    background: color-mix(in srgb, var(--md-sys-color-surface-container-high) 70%, transparent);
}

.md3-chip.primary {
    border-color: color-mix(in srgb, var(--md-sys-color-primary) 45%, transparent);
    color: color-mix(in srgb, var(--md-sys-color-primary-container) 82%, white);
    background: color-mix(in srgb, var(--md-sys-color-primary) 18%, transparent);
}

.md3-btn {
    appearance: none;
    border: none;
    border-radius: 999px;
    padding: 10px 16px;
    font-size: 0.9rem;
    line-height: 1;
    cursor: pointer;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    transition: transform .15s ease, filter .15s ease, background .2s ease;
}

.md3-btn:hover {
    transform: translateY(-1px);
    filter: brightness(1.03);
}

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

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

.md3-btn-tonal {
    background: color-mix(in srgb, var(--md-sys-color-secondary-container) 40%, var(--md-sys-color-surface-container-high));
    color: var(--md-sys-color-on-secondary-container);
}

.md3-btn-outlined {
    border: 1px solid color-mix(in srgb, var(--md-sys-color-outline) 65%, transparent);
    color: var(--md-sys-color-on-surface);
    background: color-mix(in srgb, var(--md-sys-color-surface-container-low) 70%, transparent);
}

.md3-btn-danger {
    background: color-mix(in srgb, var(--md-sys-color-error) 22%, var(--md-sys-color-surface-container));
    color: var(--md-sys-color-error);
}

.md3-form {
    display: grid;
    gap: 12px;
}

.md3-field {
    display: grid;
    gap: 6px;
}

.md3-input,
.md3-select,
.md3-textarea {
    width: 100%;
    border-radius: var(--md-shape-corner-medium);
    border: 1px solid color-mix(in srgb, var(--md-sys-color-outline) 66%, transparent);
    background: color-mix(in srgb, var(--md-sys-color-surface-container-low) 85%, transparent);
    color: var(--md-sys-color-on-surface);
    padding: 11px 12px;
    font: inherit;
}

.md3-textarea {
    min-height: 110px;
    resize: vertical;
}

.md3-input:focus,
.md3-select:focus,
.md3-textarea:focus {
    outline: 2px solid color-mix(in srgb, var(--md-sys-color-primary) 65%, transparent);
    outline-offset: 1px;
}

.md3-alert {
    border-radius: var(--md-shape-corner-medium);
    padding: 11px 13px;
    margin-bottom: 12px;
    font-size: 0.9rem;
}

.md3-alert.success {
    border: 1px solid color-mix(in srgb, var(--md-sys-color-success) 55%, transparent);
    background: color-mix(in srgb, var(--md-sys-color-success-container) 60%, transparent);
    color: var(--md-sys-color-on-success-container);
}

.md3-alert.error {
    border: 1px solid color-mix(in srgb, var(--md-sys-color-error) 50%, transparent);
    background: color-mix(in srgb, var(--md-sys-color-error-container) 65%, transparent);
    color: var(--md-sys-color-on-error-container);
}

.md3-kpis {
    display: grid;
    gap: 12px;
    grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
}

.md3-kpi-value {
    font-size: 1.9rem;
    line-height: 1;
    font-weight: 700;
    margin-top: 8px;
}

.md3-table-wrap {
    overflow: auto;
    border-radius: var(--md-shape-corner-medium);
    border: 1px solid color-mix(in srgb, var(--md-sys-color-outline-variant) 60%, transparent);
}

.md3-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.88rem;
}

.md3-table th,
.md3-table td {
    text-align: left;
    padding: 10px 10px;
    border-bottom: 1px solid color-mix(in srgb, var(--md-sys-color-outline-variant) 45%, transparent);
}

.md3-table thead th {
    background: color-mix(in srgb, var(--md-sys-color-surface-container-high) 85%, transparent);
    color: var(--md-sys-color-on-surface-variant);
    font-size: 0.78rem;
    font-weight: 600;
    letter-spacing: 0.02em;
    text-transform: uppercase;
}

.md3-inline-form {
    display: inline;
}

.md3-stat-grid {
    display: grid;
    grid-template-columns: repeat(7, minmax(0, 1fr));
    gap: 8px;
    align-items: end;
    min-height: 150px;
    margin-top: 8px;
}

.md3-stat-bar {
    border-radius: 10px 10px 4px 4px;
    background: linear-gradient(180deg, var(--md-sys-color-primary), color-mix(in srgb, var(--md-sys-color-tertiary) 60%, var(--md-sys-color-primary)));
    position: relative;
    min-height: 6px;
}

.md3-stat-bar strong {
    position: absolute;
    top: -18px;
    left: 50%;
    transform: translateX(-50%);
    font-size: 0.7rem;
}

.md3-stat-bar span {
    position: absolute;
    bottom: -18px;
    left: 50%;
    transform: translateX(-50%);
    font-size: 0.68rem;
    color: var(--md-sys-color-on-surface-variant);
}

.md3-option {
    display: block;
    cursor: pointer;
}

.md3-option input {
    display: none;
}

.md3-option span {
    display: block;
    border-radius: var(--md-shape-corner-medium);
    border: 1px solid color-mix(in srgb, var(--md-sys-color-outline) 70%, transparent);
    padding: 12px;
    color: var(--md-sys-color-on-surface-variant);
    background: color-mix(in srgb, var(--md-sys-color-surface-container-low) 85%, transparent);
    transition: .2s ease;
    cursor: pointer;
}

.md3-option:hover span {
    border-color: color-mix(in srgb, var(--md-sys-color-primary) 48%, transparent);
    background: color-mix(in srgb, var(--md-sys-color-surface-container-high) 92%, transparent);
}

.md3-option input:checked + span {
    color: var(--md-sys-color-on-primary-container);
    border-color: color-mix(in srgb, var(--md-sys-color-primary) 65%, transparent);
    background: color-mix(in srgb, var(--md-sys-color-primary-container) 38%, transparent);
}

.md3-progress-track {
    height: 10px;
    border-radius: 999px;
    overflow: hidden;
    border: 1px solid color-mix(in srgb, var(--md-sys-color-outline-variant) 55%, transparent);
    background: color-mix(in srgb, var(--md-sys-color-surface-container-high) 74%, transparent);
}

.md3-progress-bar {
    display: block;
    width: 0;
    height: 100%;
    border-radius: 999px;
    background: linear-gradient(90deg, var(--md-sys-color-primary), var(--md-sys-color-tertiary));
    transition: width .4s ease;
}

.md3-space-top {
    margin-top: 14px;
}

.md3-space-bottom {
    margin-bottom: 14px;
}

@media (max-width: 840px) {
    .md3-container,
    .md3-top-app-bar__inner {
        width: min(1200px, 96vw);
    }

    .md3-grid.cols-2,
    .md3-grid.cols-3,
    .md3-kpis {
        grid-template-columns: 1fr;
    }

    .md3-stat-grid {
        min-height: 130px;
    }
}
