* {
    box-sizing: border-box;
}

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

body {
    margin: 0;
    min-height: 100vh;
    background: var(--bg);
    color: var(--text);
    font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    font-size: 15px;
    line-height: 1.5;
}

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

a {
    color: inherit;
}

.app-body {
    min-height: 100vh;
}

.app-layout {
    min-height: 100vh;
}

.sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    z-index: 1000;
    display: flex;
    width: 250px;
    flex-direction: column;
    padding: 18px 14px;
    border-right: 1px solid var(--border);
    background: var(--sidebar-bg);
    box-shadow: var(--shadow-sm);
}

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 12px;
    min-height: 56px;
    padding: 6px 8px 20px;
}

.sidebar-logo {
    display: grid;
    width: 38px;
    height: 38px;
    place-items: center;
    flex: 0 0 38px;
    border-radius: 10px;
    background: var(--primary);
    color: #fff;
    font-size: 1.05rem;
    font-weight: 800;
}

.sidebar-title {
    font-size: 1rem;
    font-weight: 750;
}

.sidebar-subtitle {
    margin-top: 2px;
    color: var(--text-muted);
    font-size: 0.78rem;
}

.sidebar-nav {
    display: flex;
    flex: 1;
    flex-direction: column;
    gap: 5px;
}

.nav-link,
.sidebar-action {
    display: flex;
    width: 100%;
    min-height: 42px;
    align-items: center;
    gap: 12px;
    padding: 10px 12px;
    border: 0;
    border-radius: 9px;
    background: transparent;
    color: var(--text-muted);
    font: inherit;
    font-weight: 600;
    text-align: left;
    text-decoration: none;
    cursor: pointer;
    transition:
        background 140ms ease,
        color 140ms ease;
}

.nav-link:hover,
.sidebar-action:hover {
    background: var(--surface-alt);
    color: var(--text);
}

.nav-link.active {
    background: var(--primary-soft);
    color: var(--primary);
}

.nav-icon {
    display: inline-flex;
    width: 20px;
    height: 20px;
    align-items: center;
    justify-content: center;
    flex: 0 0 20px;
}

.nav-icon svg {
    width: 18px;
    height: 18px;
    fill: currentColor;
}

.nav-label {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.sidebar-bottom {
    display: flex;
    flex-direction: column;
    gap: 5px;
    padding-top: 12px;
    border-top: 1px solid var(--border);
}

.app-main {
    min-width: 0;
    min-height: 100vh;
    margin-left: 250px;
}

.topbar {
    position: sticky;
    top: 0;
    z-index: 900;
    display: flex;
    min-height: 78px;
    align-items: center;
    gap: 20px;
    padding: 14px 28px;
    border-bottom: 1px solid var(--border);
    background: var(--topbar-bg);
    backdrop-filter: blur(10px);
}

.topbar-heading {
    min-width: 0;
    flex: 1;
}

.topbar-heading h1 {
    margin: 0;
    font-size: 1.35rem;
    line-height: 1.2;
}

.topbar-heading p {
    margin: 5px 0 0;
    color: var(--text-muted);
    font-size: 0.86rem;
}

.topbar-user {
    display: flex;
    align-items: center;
    gap: 10px;
}

.user-avatar {
    display: grid;
    width: 38px;
    height: 38px;
    place-items: center;
    flex: 0 0 38px;
    border-radius: 50%;
    background: var(--primary-soft);
    color: var(--primary);
    font-size: 0.8rem;
    font-weight: 800;
}

.user-info {
    display: flex;
    flex-direction: column;
    line-height: 1.25;
}

.user-info strong {
    font-size: 0.88rem;
}

.user-info span {
    margin-top: 2px;
    color: var(--text-muted);
    font-size: 0.76rem;
}

.mobile-menu-button {
    display: none;
    width: 40px;
    height: 40px;
    align-items: center;
    justify-content: center;
    border: 1px solid var(--border);
    border-radius: 9px;
    background: var(--surface);
    color: var(--text);
    cursor: pointer;
}

.dashboard-content {
    width: min(100%, 1600px);
    margin: 0 auto;
    padding: 28px;
}

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

.stat-card {
    min-width: 0;
    padding: 18px;
    border: 1px solid var(--border);
    border-radius: 14px;
    background: var(--surface);
    box-shadow: var(--shadow-sm);
}

.stat-label {
    color: var(--text-muted);
    font-size: 0.78rem;
    font-weight: 650;
}

.stat-value {
    margin-top: 7px;
    font-size: 1.55rem;
    font-weight: 780;
    line-height: 1.2;
}

.stat-description {
    margin-top: 6px;
    color: var(--text-muted);
    font-size: 0.78rem;
}

.dashboard-grid {
    display: grid;
    grid-template-columns: minmax(0, 1.45fr) minmax(280px, 0.75fr);
    gap: 18px;
}

.panel {
    min-width: 0;
    padding: 20px;
    border: 1px solid var(--border);
    border-radius: 14px;
    background: var(--surface);
    box-shadow: var(--shadow-sm);
}

.panel + .panel {
    margin-top: 18px;
}

.panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 16px;
}

.panel-header h2,
.panel-header h3 {
    margin: 0;
}

.panel-header p {
    margin: 5px 0 0;
    color: var(--text-muted);
    font-size: 0.85rem;
}

.table-wrap {
    width: 100%;
    overflow-x: auto;
}

.data-table {
    width: 100%;
    border-collapse: collapse;
}

.data-table th,
.data-table td {
    padding: 12px 10px;
    border-bottom: 1px solid var(--border);
    text-align: left;
    vertical-align: middle;
}

.data-table th {
    color: var(--text-muted);
    font-size: 0.75rem;
    font-weight: 700;
}

.data-table tbody tr:last-child td {
    border-bottom: 0;
}

.empty-state {
    padding: 34px 20px;
    color: var(--text-muted);
    text-align: center;
}

.button {
    display: inline-flex;
    min-height: 38px;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 8px 13px;
    border: 1px solid transparent;
    border-radius: 9px;
    text-decoration: none;
    font-weight: 650;
    cursor: pointer;
}

.button-primary {
    border-color: var(--primary);
    background: var(--primary);
    color: #fff;
}

.button-primary:hover {
    background: var(--primary-hover);
}

.button-secondary {
    border-color: var(--border);
    background: var(--surface);
    color: var(--text);
}

.button-secondary:hover {
    background: var(--surface-alt);
}

.badge {
    display: inline-flex;
    align-items: center;
    padding: 4px 8px;
    border-radius: 999px;
    background: var(--surface-alt);
    color: var(--text-muted);
    font-size: 0.72rem;
    font-weight: 700;
}

.badge-success {
    background: var(--success-soft);
    color: var(--success);
}

.badge-warning {
    background: var(--warning-soft);
    color: var(--warning);
}

.badge-danger {
    background: var(--danger-soft);
    color: var(--danger);
}

.quick-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
}

@media (max-width: 1100px) {
    .stats-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

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

@media (max-width: 820px) {
    .sidebar {
        transform: translateX(-100%);
        transition: transform 180ms ease;
    }

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

    .app-main {
        margin-left: 0;
    }

    .mobile-menu-button {
        display: inline-flex;
    }

    .topbar {
        padding-inline: 18px;
    }

    .dashboard-content {
        padding: 20px 18px;
    }
}

@media (max-width: 560px) {
    .stats-grid {
        grid-template-columns: 1fr;
    }

    .topbar-user .user-info {
        display: none;
    }
}

/* Role-aware workspace switching */
.workspace-switch {
    margin-bottom: 3px;
    border: 1px solid var(--border);
    background: var(--surface-alt);
    color: var(--text);
}

.workspace-switch:hover {
    border-color: var(--primary);
    background: var(--primary-soft);
    color: var(--primary);
}
