:root {
    /* Theme colors and their compatibility aliases are owned by theme.css. */
    --white: #ffffff;

    --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 5%);
    --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 10%), 0 2px 4px -2px rgb(0 0 0 / 10%);
    --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 10%), 0 4px 6px -4px rgb(0 0 0 / 10%);
    --shadow-xl: 0 20px 25px -5px rgb(0 0 0 / 10%), 0 8px 10px -6px rgb(0 0 0 / 10%);

    --radius-sm: .375rem;
    --radius-md: .5rem;
    --radius-lg: .75rem;
    --radius-xl: 1rem;
    --radius-2xl: 1.5rem;

    --font-sans: "Segoe UI", Tahoma, Arial, sans-serif;

    /* Shared UI system tokens. Palette values remain owned by theme.css. */
    --dfms-icon-control-size: 2.25rem;
    --dfms-control-height: 2.75rem;
    --dfms-control-radius: var(--radius-lg);
    --dfms-surface-radius: var(--radius-xl);
    --dfms-transition-fast: 160ms ease;
    --dfms-page-padding: clamp(.875rem, 2vw, 2rem);
    --dfms-surface-shadow: 0 .4rem 1.2rem rgb(15 23 42 / 6%);
    --dfms-surface-shadow-hover: 0 .55rem 1.35rem rgb(15 23 42 / 9%);
    --dfms-focus-ring: 0 0 0 .2rem rgb(102 126 234 / 20%);
}

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

html,
body {
    width: 100%;
    max-width: 100%;
    min-width: 0;
}

html {
    min-height: 100%;
    background-color: var(--background);
}

body {
    min-height: 100%;
    margin: 0;
    overflow-x: hidden;
    background-color: var(--background);
    color: var(--text-primary);
    font-family: var(--font-sans);
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    text-rendering: optimizeLegibility;
}

button,
input,
select,
textarea {
    font: inherit;
}

button,
a {
    -webkit-tap-highlight-color: transparent;
}

img,
svg {
    max-width: 100%;
}

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

h1,
h2,
h3,
h4,
h5,
h6 {
    margin: 0;
    color: var(--text-primary);
    font-weight: 700;
    line-height: 1.3;
}

p {
    margin: 0;
    color: var(--text-secondary);
    line-height: 1.7;
}

/* Shared buttons */
.btn,
.button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: var(--dfms-control-height);
    gap: .5rem;
    padding: .625rem 1rem;
    border: 1px solid transparent;
    border-radius: var(--dfms-control-radius);
    color: var(--text-primary);
    background-color: transparent;
    font: inherit;
    font-size: .875rem;
    font-weight: 650;
    line-height: 1.25;
    text-align: center;
    text-decoration: none;
    cursor: pointer;
    transition:
        background-color var(--dfms-transition-fast),
        border-color var(--dfms-transition-fast),
        color var(--dfms-transition-fast),
        box-shadow var(--dfms-transition-fast);
}

.btn:focus-visible,
.button:focus-visible {
    outline: 2px solid var(--primary);
    outline-offset: 2px;
    box-shadow: var(--dfms-focus-ring);
}

.btn:disabled,
.button:disabled,
.btn[aria-disabled="true"],
.button[aria-disabled="true"] {
    cursor: not-allowed;
    opacity: .55;
}


.btn-primary,
.button.primary {
    color: var(--white);
    background-color: var(--primary);
}

.btn-primary:hover:not(:disabled),
.button.primary:hover:not(:disabled) {
    background-color: var(--primary-hover);
}

.btn-secondary {
    color: var(--text-primary);
    background-color: var(--surface);
    border-color: var(--outline);
}

.btn-secondary:hover:not(:disabled) {
    background-color: var(--background);
    border-color: var(--text-muted);
}

.btn-ghost {
    color: var(--text-secondary);
    background-color: transparent;
}

.btn-ghost:hover:not(:disabled) {
    color: var(--primary);
    background-color: var(--primary-container);
}

.btn-danger {
    color: var(--white);
    background-color: var(--danger);
}

.btn-sm {
    min-height: 2.25rem;
    padding: .4rem .7rem;
    font-size: .78rem;
}

/* Shared page content */
.page-container {
    width: min(100%, 90rem);
    min-width: 0;
    margin-inline: auto;
    padding: var(--dfms-page-padding);
}

/* Compatibility surfaces still used by non-migrated pages. */
.hero-section {
    position: relative;
    margin-bottom: 2rem;
    padding: clamp(1.5rem, 3vw, 3rem);
    overflow: hidden;
    color: var(--white);
    background: linear-gradient(135deg, var(--primary) 0%, var(--secondary) 100%);
    border-radius: var(--radius-2xl);
    box-shadow: var(--shadow-lg);
}

.hero-section::after {
    position: absolute;
    inset: 0;
    background: radial-gradient(circle at top right, rgb(255 255 255 / 10%) 0%, transparent 70%);
    content: "";
    pointer-events: none;
}

.hero-section h1 {
    margin-bottom: .5rem;
    color: var(--white);
    font-size: clamp(1.75rem, 3vw, 2.5rem);
}

.hero-section p {
    color: rgb(255 255 255 / 90%);
    font-size: 1rem;
}

.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(min(15rem, 100%), 1fr));
    gap: 1rem;
    margin-bottom: 2rem;
}

.stat-card,
.panel {
    min-width: 0;
    background-color: var(--surface);
    border: 1px solid var(--outline);
    border-radius: var(--dfms-surface-radius);
    box-shadow: var(--shadow-sm);
}

.stat-card {
    display: flex;
    flex-direction: column;
    gap: .5rem;
    padding: 1.25rem;
    transition: border-color var(--dfms-transition-fast), box-shadow var(--dfms-transition-fast);
}

.stat-card:hover {
    box-shadow: var(--shadow-md);
}

.stat-label {
    color: var(--text-secondary);
    font-size: .875rem;
    font-weight: 500;
}

.stat-value {
    color: var(--text-primary);
    font-size: 1.75rem;
    font-weight: 800;
}

.details-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 1rem;
}

.panel {
    padding: 1.25rem;
}

.panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    margin-bottom: 1rem;
    padding-bottom: .875rem;
    border-bottom: 1px solid var(--outline);
}

.panel h2 {
    font-size: 1.125rem;
}

.data-list {
    display: flex;
    flex-direction: column;
    gap: .75rem;
}

.data-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    min-width: 0;
}

.data-label {
    color: var(--text-secondary);
    font-size: .875rem;
}

.data-value {
    min-width: 0;
    overflow-wrap: anywhere;
    color: var(--text-primary);
    font-size: .875rem;
    font-weight: 650;
}

.alert,
.form-message {
    padding: .8rem 1rem;
    border: 1px solid transparent;
    border-radius: var(--dfms-control-radius);
    font-size: .875rem;
    line-height: 1.65;
}

.alert {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
}

.alert-info {
    color: #3730a3;
    background-color: var(--primary-container);
    border-color: #c7d2fe;
}

.alert-content p {
    margin-top: .25rem;
    color: inherit;
    font-size: .875rem;
}

.form-message-error {
    color: var(--dfms-danger, var(--danger));
    background: rgb(220 38 38 / 8%);
    border-color: rgb(220 38 38 / 20%);
}

.form-message-warning {
    color: var(--dfms-warning, var(--warning));
    background: rgb(217 119 6 / 9%);
    border-color: rgb(217 119 6 / 22%);
}

.status-badge {
    display: inline-flex;
    align-items: center;
    min-height: 1.75rem;
    padding: .25rem .65rem;
    border-radius: 999px;
    font-size: .75rem;
    font-weight: 700;
}

.status-badge.success {
    color: #166534;
    background: #dcfce7;
}

.status-badge.warning {
    color: #92400e;
    background: #fef3c7;
}

.status-badge.danger {
    color: #991b1b;
    background: #fee2e2;
}

.dashboard-loading,
.dashboard-error {
    display: flex;
    min-height: clamp(12rem, 35dvh, 20rem);
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 1rem;
    padding: 1rem;
    text-align: center;
}

.loading-spinner,
.spinner-sm {
    border-style: solid;
    border-color: var(--primary-container);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

.loading-spinner {
    width: 2.5rem;
    height: 2.5rem;
    border-width: 3px;
}

.spinner-sm {
    width: 1rem;
    height: 1rem;
    border-width: 2px;
}

.error-icon {
    font-size: 3rem;
}

/* First-user / error / empty route surfaces */
.first-user-page,
.access-denied,
.not-found {
    width: 100%;
    min-height: 100dvh;
    padding:
        max(1rem, env(safe-area-inset-top, 0px))
        max(1rem, env(safe-area-inset-right, 0px))
        max(1rem, env(safe-area-inset-bottom, 0px))
        max(1rem, env(safe-area-inset-left, 0px));
    background: var(--dfms-page, var(--background));
}

.first-user-page {
    display: grid;
    place-items: center;
}

.first-user-card {
    width: min(100%, 46rem);
    min-width: 0;
    padding: clamp(1.25rem, 3vw, 2rem);
    color: var(--dfms-text, var(--text-primary));
    background: var(--dfms-surface, var(--surface));
    border: 1px solid var(--dfms-border, var(--outline));
    border-radius: var(--radius-2xl);
    box-shadow: var(--dfms-surface-shadow);
}

.first-user-header {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr);
    align-items: center;
    gap: .875rem;
    margin-bottom: 1.25rem;
}

.first-user-header > div {
    min-width: 0;
}

.first-user-header h1,
.first-user-card > h1 {
    color: var(--dfms-text, var(--text-primary));
    font-size: clamp(1.25rem, 2.4vw, 1.65rem);
}

.first-user-header p,
.first-user-card > p {
    margin-top: .35rem;
    color: var(--dfms-text-muted, var(--text-secondary));
    font-size: .875rem;
}

.first-user-badge {
    display: grid;
    width: 2.5rem;
    aspect-ratio: 1;
    place-items: center;
    color: var(--dfms-primary, var(--primary));
    background: var(--dfms-primary-soft, var(--primary-container));
    border-radius: var(--radius-lg);
    font-weight: 800;
}

.first-user-form {
    display: grid;
    gap: 1rem;
    margin-top: 1rem;
}

.form-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: .875rem 1rem;
}

.form-grid label {
    display: grid;
    min-width: 0;
    gap: .4rem;
    color: var(--dfms-text, var(--text-primary));
    font-size: .84rem;
    font-weight: 650;
}

.form-grid label > span {
    min-width: 0;
}

.form-grid small {
    color: var(--dfms-text-muted, var(--text-secondary));
    font-weight: 500;
}

.form-grid input,
.form-grid select,
.form-grid textarea {
    width: 100%;
    min-width: 0;
    min-height: var(--dfms-control-height);
    padding: .65rem .8rem;
    color: var(--dfms-text, var(--text-primary));
    background: var(--dfms-surface-muted, var(--background));
    border: 1px solid var(--dfms-border, var(--outline));
    border-radius: var(--dfms-control-radius);
    outline: 0;
    transition:
        background-color var(--dfms-transition-fast),
        border-color var(--dfms-transition-fast),
        box-shadow var(--dfms-transition-fast);
}

.form-grid input:hover:not(:disabled),
.form-grid select:hover:not(:disabled),
.form-grid textarea:hover:not(:disabled) {
    border-color: var(--dfms-primary, var(--primary));
}

.form-grid input:focus-visible,
.form-grid select:focus-visible,
.form-grid textarea:focus-visible {
    background: var(--dfms-surface, var(--surface));
    border-color: var(--dfms-primary, var(--primary));
    box-shadow: var(--dfms-focus-ring);
}

.form-grid input:disabled,
.form-grid select:disabled,
.form-grid textarea:disabled {
    cursor: not-allowed;
    opacity: .65;
}

.password-guidance {
    color: var(--dfms-text-muted, var(--text-secondary));
    font-size: .78rem;
}

.first-user-submit {
    justify-self: end;
    min-width: 11rem;
}

.access-denied,
.not-found {
    display: grid;
    place-content: center;
    justify-items: center;
    gap: .875rem;
    color: var(--dfms-text, var(--text-primary));
    text-align: center;
}

.access-denied p,
.not-found {
    color: var(--dfms-text-muted, var(--text-secondary));
}

/* Utilities */
.text-success { color: var(--success); }
.text-danger { color: var(--danger); }
.text-warning { color: var(--warning); }

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

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

.fade-in {
    animation: fadeIn .3s ease-out both;
}

@media (max-width: 64rem) {
    .details-grid {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 42rem) {
    .form-grid {
        grid-template-columns: 1fr;
    }

    .first-user-submit {
        width: 100%;
        justify-self: stretch;
    }

    .data-item {
        align-items: flex-start;
        flex-direction: column;
        gap: .25rem;
    }
}

@media (max-width: 34rem) {
    .page-container {
        padding: .875rem;
    }

    .hero-section {
        margin-bottom: 1rem;
        border-radius: var(--radius-xl);
    }

    .stats-grid {
        grid-template-columns: 1fr;
    }

    .first-user-card {
        padding: 1.1rem;
        border-radius: var(--radius-xl);
    }

    .first-user-header {
        align-items: start;
    }
}

@media (prefers-reduced-motion: reduce) {
    .btn,
    .button,
    .stat-card,
    .form-grid input,
    .form-grid select,
    .form-grid textarea,
    .fade-in {
        transition: none;
        animation: none;
    }

    .loading-spinner,
    .spinner-sm {
        animation: none;
    }
}
