* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --primary-color: #2563eb;
    --primary-dark: #1e40af;
    --bg-primary: #ffffff;
    --bg-secondary: #f9fafb;
    --text-primary: #111827;
    --text-secondary: #6b7280;
    --border-color: #e5e7eb;
    --success-color: #10b981;
    --warning-color: #f59e0b;
    --danger-color: #ef4444;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background-color: var(--bg-secondary);
    color: var(--text-primary);
    line-height: 1.6;
}

body.compact {
    line-height: 1.45;
}

.skip-link {
    position: absolute;
    left: -9999px;
    top: 0;
    background-color: var(--primary-color);
    color: #fff;
    padding: 0.6rem 1rem;
    border-radius: 0 0 6px 0;
    z-index: 300;
}

.skip-link:focus {
    left: 0;
}

:focus-visible {
    outline: 2px solid var(--primary-color);
    outline-offset: 2px;
}

/* Header */
.header {
    background-color: var(--bg-primary);
    border-bottom: 1px solid var(--border-color);
    padding: 1rem 2rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    position: sticky;
    top: 0;
    z-index: 100;
}

.header-left {
    display: flex;
    align-items: center;
    gap: 2rem;
}

.logo {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--primary-color);
}

.nav {
    display: flex;
    gap: 2rem;
    list-style: none;
}

.nav a {
    text-decoration: none;
    color: var(--text-secondary);
    font-size: 0.95rem;
    transition: color 0.2s;
}

.nav a:hover,
.nav a.active {
    color: var(--primary-color);
}

.header-right {
    display: flex;
    align-items: center;
    gap: 1.5rem;
}

.user-info {
    text-align: right;
}

.user-name {
    font-weight: 600;
    font-size: 0.95rem;
    color: var(--text-primary);
}

.user-status {
    font-size: 0.8rem;
    color: var(--text-secondary);
}

.avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--primary-color), #1e40af);
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-weight: 700;
    font-size: 0.9rem;
    border: none;
    cursor: pointer;
    font-family: inherit;
    flex-shrink: 0;
}

/* Main Container */
.container {
    max-width: 1440px;
    margin: 0 auto;
    padding: 2rem;
    display: grid;
    grid-template-columns: 250px 1fr;
    gap: 2rem;
}

/* Sidebar */
.sidebar {
    background-color: var(--bg-primary);
    border-radius: 8px;
    padding: 1.5rem;
    height: fit-content;
    border: 1px solid var(--border-color);
}

.sidebar-section {
    margin-bottom: 2rem;
}

.sidebar-section:last-child {
    margin-bottom: 0;
}

.sidebar-title {
    font-size: 0.75rem;
    font-weight: 700;
    text-transform: uppercase;
    color: var(--text-secondary);
    margin-bottom: 1rem;
}

.sidebar-list {
    list-style: none;
}

.sidebar-item {
    margin-bottom: 0.5rem;
}

.sidebar-link {
    display: block;
    padding: 0.75rem 1rem;
    border-radius: 6px;
    text-decoration: none;
    color: var(--text-secondary);
    font-size: 0.9rem;
    transition: all 0.2s;
}

.sidebar-link:hover {
    background-color: var(--bg-secondary);
    color: var(--primary-color);
}

.sidebar-link.active {
    background-color: #eff6ff;
    color: var(--primary-color);
    font-weight: 600;
}

/* Main Content */
.main-content {
    display: grid;
    gap: 2rem;
    align-content: start;
    min-width: 0;
}

.main-content:focus {
    outline: none;
}

.welcome-section {
    background: linear-gradient(135deg, var(--primary-color), var(--primary-dark));
    color: white;
    padding: 2rem;
    border-radius: 8px;
    display: flex;
    flex-wrap: wrap;
    gap: 1rem;
    justify-content: space-between;
    align-items: center;
}

.welcome-title {
    font-size: 1.75rem;
    margin-bottom: 0.5rem;
}

.welcome-subtitle {
    opacity: 0.9;
    font-size: 1rem;
}

.welcome-actions {
    display: flex;
    gap: 0.75rem;
    flex-wrap: wrap;
}

.btn-on-gradient {
    background-color: rgba(255, 255, 255, 0.16);
    color: #fff;
    border: 1px solid rgba(255, 255, 255, 0.45);
}

.btn-on-gradient:hover {
    background-color: rgba(255, 255, 255, 0.28);
}

/* Cards Grid */
.cards-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 1.5rem;
}

.card {
    background-color: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 1.5rem;
    transition: all 0.2s;
}

.card:hover {
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
    border-color: var(--primary-color);
}

a.card,
button.card {
    display: block;
    width: 100%;
    text-align: left;
    text-decoration: none;
    color: inherit;
    font-family: inherit;
    cursor: pointer;
}

.card-header {
    display: flex;
    justify-content: space-between;
    align-items: start;
    margin-bottom: 1rem;
}

.card-title {
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
}

.card-icon {
    width: 32px;
    height: 32px;
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
    flex-shrink: 0;
}

.card-icon.primary {
    background-color: #eff6ff;
    color: var(--primary-color);
}

.card-icon.success {
    background-color: #ecfdf5;
    color: var(--success-color);
}

.card-icon.warning {
    background-color: #fffbeb;
    color: var(--warning-color);
}

.card-value {
    font-size: 2rem;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 0.5rem;
}

.card-change {
    font-size: 0.85rem;
    color: var(--text-secondary);
}

.card-change.positive {
    color: var(--success-color);
}

.card-change.negative {
    color: var(--danger-color);
}

/* Table */
.data-section {
    background-color: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 1.5rem;
}

.section-title {
    font-size: 1.1rem;
    font-weight: 600;
    margin-bottom: 1.5rem;
    color: var(--text-primary);
}

.section-head {
    display: flex;
    flex-wrap: wrap;
    gap: 1rem;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.5rem;
}

.section-head .section-title {
    margin-bottom: 0;
}

.section-tools {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
    align-items: center;
}

.field-label {
    display: block;
    font-size: 0.8rem;
    font-weight: 600;
    text-transform: uppercase;
    color: var(--text-secondary);
    margin-bottom: 0.35rem;
}

input[type="text"],
input[type="date"],
input[type="search"],
input[type="number"],
select,
textarea {
    font-family: inherit;
    font-size: 0.9rem;
    color: var(--text-primary);
    background-color: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    padding: 0.55rem 0.7rem;
    width: 100%;
}

textarea {
    min-height: 88px;
    resize: vertical;
}

.section-tools input[type="search"],
.section-tools select {
    width: auto;
    min-width: 160px;
}

.table-wrapper {
    overflow-x: auto;
}

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

thead {
    background-color: var(--bg-secondary);
    border-bottom: 2px solid var(--border-color);
}

th {
    padding: 1rem;
    text-align: left;
    font-weight: 600;
    font-size: 0.85rem;
    color: var(--text-secondary);
    text-transform: uppercase;
    white-space: nowrap;
}

th.sortable {
    cursor: pointer;
    user-select: none;
}

th.sortable:hover {
    color: var(--primary-color);
}

th .sort-indicator {
    margin-left: 0.35rem;
    font-size: 0.7rem;
}

td {
    padding: 1rem;
    border-bottom: 1px solid var(--border-color);
    font-size: 0.9rem;
    vertical-align: middle;
}

tbody tr:hover {
    background-color: var(--bg-secondary);
}

td.numeric,
th.numeric {
    text-align: right;
}

td.row-actions {
    white-space: nowrap;
    text-align: right;
}

.status-badge {
    display: inline-block;
    padding: 0.4rem 0.8rem;
    border-radius: 4px;
    font-size: 0.8rem;
    font-weight: 600;
}

.status-badge.active {
    background-color: #ecfdf5;
    color: var(--success-color);
}

.status-badge.inactive {
    background-color: #f3f4f6;
    color: var(--text-secondary);
}

.status-badge.done {
    background-color: #eff6ff;
    color: var(--primary-color);
}

.status-badge.overdue {
    background-color: #fef2f2;
    color: var(--danger-color);
}

.status-badge.pending {
    background-color: #fffbeb;
    color: var(--warning-color);
}

.muted {
    color: var(--text-secondary);
}

.due-overdue {
    color: var(--danger-color);
    font-weight: 600;
}

/* Button */
.btn {
    padding: 0.6rem 1.2rem;
    border: none;
    border-radius: 6px;
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    font-family: inherit;
    line-height: 1.4;
}

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

.btn-primary:hover {
    background-color: var(--primary-dark);
}

.btn-secondary {
    background-color: var(--bg-secondary);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
}

.btn-secondary:hover {
    background-color: #f3f4f6;
}

.btn-danger {
    background-color: #fef2f2;
    color: var(--danger-color);
    border: 1px solid #fecaca;
}

.btn-danger:hover {
    background-color: #fee2e2;
}

.btn-sm {
    padding: 0.35rem 0.7rem;
    font-size: 0.8rem;
}

.btn:disabled {
    opacity: 0.55;
    cursor: not-allowed;
}

/* Empty state */
.empty-state {
    text-align: center;
    padding: 2.5rem 1rem;
    color: var(--text-secondary);
}

.empty-state h3 {
    color: var(--text-primary);
    font-size: 1.05rem;
    margin-bottom: 0.5rem;
}

.empty-state p {
    margin-bottom: 1.25rem;
    font-size: 0.9rem;
}

.empty-actions {
    display: flex;
    gap: 0.75rem;
    justify-content: center;
    flex-wrap: wrap;
}

/* Forms / detail lists */
.form-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 1.25rem;
}

.form-row {
    margin-bottom: 1.25rem;
}

.form-actions {
    display: flex;
    gap: 0.75rem;
    flex-wrap: wrap;
    margin-top: 1.5rem;
}

.hint {
    font-size: 0.8rem;
    color: var(--text-secondary);
    margin-top: 0.35rem;
}

.detail-list {
    list-style: none;
    display: grid;
    gap: 0.9rem;
}

.detail-list li {
    display: flex;
    justify-content: space-between;
    gap: 1rem;
    font-size: 0.9rem;
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 0.75rem;
}

.detail-list li:last-child {
    border-bottom: none;
    padding-bottom: 0;
}

.detail-list dt,
.detail-list .label {
    color: var(--text-secondary);
}

.toggle-row {
    display: flex;
    align-items: flex-start;
    gap: 0.75rem;
    padding: 0.9rem 0;
    border-bottom: 1px solid var(--border-color);
}

.toggle-row:last-of-type {
    border-bottom: none;
}

.toggle-row input[type="checkbox"] {
    width: 18px;
    height: 18px;
    margin-top: 0.25rem;
    accent-color: var(--primary-color);
    flex-shrink: 0;
}

.toggle-row .toggle-text strong {
    display: block;
    font-size: 0.95rem;
}

.toggle-row .toggle-text span {
    font-size: 0.85rem;
    color: var(--text-secondary);
}

/* Charts */
.chart-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
    gap: 1.5rem;
}

.chart {
    width: 100%;
    height: auto;
    overflow: visible;
}

.chart-bar {
    fill: var(--primary-color);
}

.chart-axis {
    stroke: var(--border-color);
    stroke-width: 1;
}

.chart-label {
    font-size: 11px;
    fill: var(--text-secondary);
}

.chart-value {
    font-size: 11px;
    font-weight: 700;
    fill: var(--text-primary);
}

.legend {
    list-style: none;
    display: flex;
    flex-wrap: wrap;
    gap: 1rem;
    margin-top: 1rem;
    font-size: 0.85rem;
    color: var(--text-secondary);
}

.legend li {
    display: flex;
    align-items: center;
    gap: 0.4rem;
}

.swatch {
    width: 12px;
    height: 12px;
    border-radius: 3px;
    display: inline-block;
}

.meter {
    background-color: var(--bg-secondary);
    border-radius: 999px;
    height: 8px;
    overflow: hidden;
    margin-top: 0.5rem;
}

.meter > span {
    display: block;
    height: 100%;
    background-color: var(--primary-color);
    border-radius: 999px;
}

/* Dialog */
.dialog-backdrop {
    position: fixed;
    inset: 0;
    background-color: rgba(17, 24, 39, 0.55);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
    z-index: 200;
}

.dialog-backdrop[hidden] {
    display: none;
}

.dialog {
    background-color: var(--bg-primary);
    border-radius: 8px;
    border: 1px solid var(--border-color);
    padding: 1.5rem;
    width: min(520px, 100%);
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: 0 20px 45px rgba(0, 0, 0, 0.2);
}

.dialog-title {
    font-size: 1.15rem;
    font-weight: 600;
    margin-bottom: 1.25rem;
}

.dialog-body {
    display: grid;
    gap: 1rem;
}

.dialog-actions {
    display: flex;
    justify-content: flex-end;
    gap: 0.75rem;
    margin-top: 1.5rem;
}

.dialog-error {
    margin-top: 1rem;
    color: var(--danger-color);
    font-size: 0.85rem;
    font-weight: 600;
}

.dialog-message {
    font-size: 0.95rem;
    color: var(--text-secondary);
}

/* Toasts */
.toast-stack {
    position: fixed;
    right: 1.5rem;
    bottom: 1.5rem;
    display: grid;
    gap: 0.6rem;
    z-index: 250;
    max-width: min(360px, calc(100vw - 3rem));
}

.toast {
    background-color: var(--text-primary);
    color: #fff;
    padding: 0.75rem 1rem;
    border-radius: 6px;
    font-size: 0.88rem;
    box-shadow: 0 8px 20px rgba(0, 0, 0, 0.18);
}

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

.toast.error {
    background-color: var(--danger-color);
}

/* Responsive */
@media (max-width: 720px) {
    .container {
        grid-template-columns: 1fr;
        padding: 1rem;
        gap: 1rem;
    }

    .header {
        flex-direction: column;
        gap: 1rem;
        align-items: flex-start;
        padding: 1rem;
    }

    .header-right {
        width: 100%;
        justify-content: flex-end;
    }

    .nav {
        gap: 1rem;
        font-size: 0.85rem;
        flex-wrap: wrap;
    }

    .header-left {
        gap: 1rem;
        flex-direction: column;
        align-items: flex-start;
        width: 100%;
    }

    .sidebar {
        padding: 0.75rem;
    }

    .sidebar-section {
        margin-bottom: 0.75rem;
    }

    .sidebar-title {
        margin-bottom: 0.5rem;
    }

    .sidebar-list {
        display: flex;
        gap: 0.5rem;
        overflow-x: auto;
        padding-bottom: 0.25rem;
    }

    .sidebar-item {
        margin-bottom: 0;
    }

    .sidebar-link {
        white-space: nowrap;
        padding: 0.5rem 0.85rem;
        border: 1px solid var(--border-color);
    }

    .main-content {
        gap: 1rem;
    }

    .welcome-section {
        padding: 1.5rem;
    }

    .cards-grid {
        grid-template-columns: 1fr;
        gap: 1rem;
    }

    .welcome-title {
        font-size: 1.3rem;
    }

    .table-wrapper {
        font-size: 0.8rem;
    }

    th, td {
        padding: 0.75rem 0.5rem;
    }

    .data-section {
        padding: 1rem;
    }

    .section-tools {
        width: 100%;
    }

    .section-tools input[type="search"],
    .section-tools select {
        flex: 1 1 140px;
        min-width: 0;
    }

    .toast-stack {
        right: 1rem;
        left: 1rem;
        bottom: 1rem;
        max-width: none;
    }
}

@media print {
    .header, .sidebar, .toast-stack, .section-tools, .welcome-actions {
        display: none !important;
    }

    body {
        background-color: #fff;
    }

    .container {
        display: block;
        padding: 0;
    }
}
