:root {
    --primary-color: #0D47A1;
    --secondary-color: #1565C0;
    --ata-sidebar-width: 280px;
    --ata-sidebar-collapsed: 80px;
    --ata-topbar-height: 64px;
    --ata-admin-bg: #eef1f6;
    --ata-surface: #ffffff;
    --ata-text: #1a2332;
    --ata-muted: #64748b;
    --ata-border: #e2e8f0;
    --ata-shadow: 0 1px 3px rgba(15, 23, 42, 0.06), 0 8px 24px rgba(15, 23, 42, 0.04);
    --ata-radius: 14px;
    --ata-sidebar-admin-bg: linear-gradient(180deg, #0b3d91 0%, #0d47a1 48%, #1254b8 100%);
    --ata-sidebar-super-bg: linear-gradient(180deg, #111827 0%, #1f2937 55%, #111827 100%);
}

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

body {
    background-color: var(--ata-admin-bg);
    color: var(--ata-text);
    font-family: 'Segoe UI', system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
    -webkit-font-smoothing: antialiased;
}

body.ata-admin {
    overflow-x: hidden;
}

.ata-impersonation-bar {
    position: relative;
    z-index: 1100;
}

/* Shell */
.ata-admin-shell {
    min-height: 100vh;
}

#page-content-wrapper {
    min-height: 100vh;
    margin-left: var(--ata-sidebar-width);
    width: calc(100% - var(--ata-sidebar-width));
    transition: margin-left 0.28s ease, width 0.28s ease;
    display: flex;
    flex-direction: column;
}

body.sidebar-collapsed #page-content-wrapper {
    margin-left: var(--ata-sidebar-collapsed);
    width: calc(100% - var(--ata-sidebar-collapsed));
}

/* Sidebar */
.ata-sidebar {
    position: fixed;
    top: 0;
    left: 0;
    width: var(--ata-sidebar-width);
    height: 100vh;
    height: 100dvh;
    z-index: 1050;
    color: #fff;
    transition: transform 0.28s ease, width 0.28s ease;
    box-shadow: 4px 0 24px rgba(15, 23, 42, 0.12);
}

.ata-sidebar-admin {
    background: var(--ata-sidebar-admin-bg);
}

.ata-sidebar-super {
    background: var(--ata-sidebar-super-bg);
}

.ata-sidebar-inner {
    display: flex;
    flex-direction: column;
    height: 100%;
    min-height: 0;
}

.ata-sidebar-brand {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 18px 16px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    flex-shrink: 0;
}

.ata-sidebar-brand-mark {
    width: 42px;
    height: 42px;
    border-radius: 12px;
    background: rgba(255, 255, 255, 0.14);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
    flex-shrink: 0;
}

.ata-sidebar-brand-text {
    min-width: 0;
    flex: 1;
    transition: opacity 0.2s ease;
}

.ata-sidebar-brand-title {
    display: block;
    font-size: 1rem;
    font-weight: 700;
    line-height: 1.2;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.ata-sidebar-brand-sub {
    display: block;
    font-size: 0.75rem;
    opacity: 0.72;
    margin-top: 2px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.ata-sidebar-close {
    display: none;
    width: 36px;
    height: 36px;
    border: 0;
    border-radius: 10px;
    background: rgba(255, 255, 255, 0.12);
    color: #fff;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    cursor: pointer;
}

.ata-sidebar-close:hover {
    background: rgba(255, 255, 255, 0.2);
}

.ata-sidebar-nav {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
}

.ata-sidebar-nav-scroll {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 12px 10px;
    scrollbar-width: thin;
    scrollbar-color: rgba(255, 255, 255, 0.28) transparent;
}

.ata-sidebar-nav-scroll::-webkit-scrollbar {
    width: 6px;
}

.ata-sidebar-nav-scroll::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.22);
    border-radius: 999px;
}

.ata-sidebar-nav-scroll::-webkit-scrollbar-track {
    background: transparent;
}

.ata-nav-list {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.ata-nav-link {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 11px 14px;
    border-radius: 12px;
    color: rgba(255, 255, 255, 0.82);
    text-decoration: none;
    font-size: 0.92rem;
    font-weight: 500;
    transition: background 0.18s ease, color 0.18s ease, transform 0.18s ease;
    white-space: nowrap;
}

.ata-nav-link:hover {
    color: #fff;
    background: rgba(255, 255, 255, 0.1);
}

.ata-nav-link.active {
    color: #fff;
    background: rgba(255, 255, 255, 0.18);
    box-shadow: inset 3px 0 0 #fff;
}

.ata-nav-icon {
    width: 22px;
    height: 22px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    font-size: 1.05rem;
}

.ata-nav-label {
    transition: opacity 0.2s ease;
}

.ata-sidebar-footer {
    padding: 14px 12px 16px;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
    flex-shrink: 0;
}

.ata-sidebar-footer-user {
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 0;
}

.ata-sidebar-footer-avatar {
    width: 38px;
    height: 38px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.14);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.ata-sidebar-footer-text {
    min-width: 0;
    transition: opacity 0.2s ease;
}

.ata-sidebar-footer-name {
    display: block;
    font-size: 0.86rem;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.ata-sidebar-footer-role {
    display: block;
    font-size: 0.72rem;
    opacity: 0.68;
}

.ata-sidebar-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.45);
    z-index: 1040;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.28s ease, visibility 0.28s ease;
    backdrop-filter: blur(2px);
}

body.sidebar-open .ata-sidebar-backdrop {
    opacity: 1;
    visibility: visible;
}

/* Collapsed desktop sidebar */
body.sidebar-collapsed .ata-sidebar {
    width: var(--ata-sidebar-collapsed);
}

body.sidebar-collapsed .ata-sidebar-brand-text,
body.sidebar-collapsed .ata-nav-label,
body.sidebar-collapsed .ata-sidebar-footer-text {
    opacity: 0;
    width: 0;
    overflow: hidden;
}

body.sidebar-collapsed .ata-sidebar-brand {
    justify-content: center;
    padding-inline: 10px;
}

body.sidebar-collapsed .ata-nav-link {
    justify-content: center;
    padding-inline: 10px;
}

body.sidebar-collapsed .ata-nav-link.active {
    box-shadow: none;
}

body.sidebar-collapsed .ata-sidebar-footer-user {
    justify-content: center;
}

/* Topbar */
.ata-topbar {
    position: sticky;
    top: 0;
    z-index: 1030;
    min-height: var(--ata-topbar-height);
    padding: 0 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    background: rgba(255, 255, 255, 0.92);
    border-bottom: 1px solid var(--ata-border);
    backdrop-filter: blur(10px);
}

.ata-topbar-start,
.ata-topbar-end {
    display: flex;
    align-items: center;
    gap: 8px;
    min-width: 0;
}

.ata-topbar-end {
    flex-shrink: 0;
}

.ata-topbar-btn {
    width: 40px;
    height: 40px;
    border: 1px solid var(--ata-border);
    border-radius: 12px;
    background: var(--ata-surface);
    color: var(--ata-text);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
    cursor: pointer;
    transition: background 0.18s ease, border-color 0.18s ease;
}

.ata-topbar-btn:hover {
    background: #f8fafc;
    border-color: #cbd5e1;
}

.ata-topbar-btn-icon {
    position: relative;
}

.ata-topbar-badge {
    position: absolute;
    top: 4px;
    right: 4px;
    min-width: 18px;
    height: 18px;
    padding: 0 5px;
    border-radius: 999px;
    background: #dc2626;
    color: #fff;
    font-size: 0.65rem;
    font-weight: 700;
    line-height: 18px;
    text-align: center;
}

.ata-topbar-titles {
    min-width: 0;
    padding-left: 4px;
}

.ata-topbar-eyebrow {
    display: block;
    font-size: 0.72rem;
    font-weight: 600;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: var(--ata-muted);
    line-height: 1.2;
}

.ata-topbar-title {
    margin: 0;
    font-size: 1.05rem;
    font-weight: 700;
    line-height: 1.25;
    color: var(--ata-text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.ata-topbar-profile {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    border: 1px solid var(--ata-border);
    border-radius: 999px;
    background: var(--ata-surface);
    padding: 4px 10px 4px 4px;
    color: var(--ata-text);
    cursor: pointer;
    transition: background 0.18s ease, border-color 0.18s ease;
}

.ata-topbar-profile:hover {
    background: #f8fafc;
    border-color: #cbd5e1;
}

.ata-topbar-profile-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--primary-color), var(--secondary-color));
    color: #fff;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.ata-topbar-profile-name {
    font-size: 0.88rem;
    font-weight: 600;
}

.ata-topbar-profile-caret {
    font-size: 0.72rem;
    color: var(--ata-muted);
}

/* Main content */
.ata-main {
    flex: 1;
    padding: 20px 0 28px;
}

.ata-main-inner {
    max-width: 1600px;
}

.ata-main-inner > h2:first-child {
    font-size: 1.35rem;
    font-weight: 700;
    margin-bottom: 1.25rem;
}

/* Cards & components */
.card {
    border: 1px solid var(--ata-border);
    border-radius: var(--ata-radius);
    box-shadow: var(--ata-shadow);
}

.card-header {
    background: var(--ata-surface);
    border-bottom: 1px solid var(--ata-border);
    padding: 14px 18px;
}

.card-body {
    padding: 18px;
}

.stat-card {
    border: 1px solid var(--ata-border);
    border-radius: var(--ata-radius);
    box-shadow: var(--ata-shadow);
    transition: transform 0.2s ease, box-shadow 0.2s ease;
    height: 100%;
}

.stat-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 10px 28px rgba(15, 23, 42, 0.08);
}

.stat-card .stat-icon {
    width: 48px;
    height: 48px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
    flex-shrink: 0;
}

.table {
    --bs-table-bg: transparent;
}

.table th {
    font-weight: 600;
    font-size: 0.78rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--ata-muted);
    white-space: nowrap;
}

.table-responsive {
    -webkit-overflow-scrolling: touch;
}

.btn {
    border-radius: 10px;
    font-weight: 600;
}

.form-control,
.form-select {
    border-radius: 10px;
    border-color: var(--ata-border);
}

.form-control:focus,
.form-select:focus {
    border-color: var(--secondary-color);
    box-shadow: 0 0 0 0.2rem rgba(21, 101, 192, 0.12);
}

.dropdown-menu {
    border-radius: 12px;
    padding: 8px;
}

.dropdown-item {
    border-radius: 8px;
    padding: 8px 12px;
    font-size: 0.9rem;
}

.alert {
    border-radius: 12px;
    border: none;
}

.badge {
    font-weight: 600;
}

/* Legacy chat panel */
.timeline {
    position: relative;
    padding-left: 30px;
}

.timeline::before {
    content: '';
    position: absolute;
    left: 10px;
    top: 0;
    bottom: 0;
    width: 2px;
    background: #dee2e6;
}

.timeline-item {
    position: relative;
    padding-bottom: 20px;
}

.timeline-item::before {
    content: '';
    position: absolute;
    left: -24px;
    top: 4px;
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: var(--primary-color);
    border: 2px solid #fff;
}

.timeline-item.completed::before {
    background: #2E7D32;
}

.timeline-item.current::before {
    background: #E65100;
    box-shadow: 0 0 0 4px rgba(230, 81, 0, 0.2);
}

.chat-messages {
    height: 400px;
    overflow-y: auto;
    padding: 15px;
    background: #f8f9fa;
    border-radius: 8px;
}

.chat-message {
    margin-bottom: 12px;
    max-width: 80%;
}

.chat-message.user {
    margin-left: auto;
    text-align: right;
}

.chat-message .bubble {
    display: inline-block;
    padding: 10px 15px;
    border-radius: 18px;
    font-size: 0.95rem;
}

.chat-message.user .bubble {
    background: var(--primary-color);
    color: #fff;
}

.chat-message.assistant .bubble {
    background: #fff;
    border: 1px solid #dee2e6;
}

.measurement-progress {
    height: 8px;
    border-radius: 4px;
}

.login-page {
    min-height: 100vh;
    background: linear-gradient(135deg, #0D47A1 0%, #1565C0 50%, #1976D2 100%);
}

.login-card {
    border: none;
    border-radius: 16px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.2);
}

/* Responsive */
@media (max-width: 991.98px) {
    #page-content-wrapper {
        margin-left: 0;
        width: 100%;
    }

    .ata-sidebar {
        transform: translateX(-100%);
    }

    body.sidebar-open .ata-sidebar {
        transform: translateX(0);
    }

    .ata-sidebar-close {
        display: inline-flex;
    }

    body.sidebar-collapsed .ata-sidebar {
        width: var(--ata-sidebar-width);
    }

    body.sidebar-collapsed .ata-sidebar-brand-text,
    body.sidebar-collapsed .ata-nav-label,
    body.sidebar-collapsed .ata-sidebar-footer-text {
        opacity: 1;
        width: auto;
        overflow: visible;
    }

    body.sidebar-collapsed .ata-nav-link {
        justify-content: flex-start;
        padding-inline: 14px;
    }

    body.sidebar-collapsed .ata-sidebar-brand {
        justify-content: flex-start;
        padding-inline: 16px;
    }

    #sidebar-collapse {
        display: none !important;
    }

    .ata-topbar {
        padding-inline: 12px;
    }

    .ata-topbar-title {
        font-size: 0.95rem;
    }

    .ata-main {
        padding: 14px 0 22px;
    }

    .ata-main-inner {
        padding-inline: 12px !important;
    }
}

@media (max-width: 575.98px) {
    .ata-topbar-titles {
        max-width: 42vw;
    }

    .card-body {
        padding: 14px;
    }

    .stat-card .card-body {
        padding: 14px;
    }

    .stat-card h4 {
        font-size: 1.1rem;
    }
}

@media (min-width: 992px) {
    body.sidebar-open .ata-sidebar-backdrop {
        opacity: 0;
        visibility: hidden;
    }
}