/* ============================================
   DESIGN SYSTEM
   Based on tactical UI refactoring principles
   ============================================ */

/* --- CSS Custom Properties (Design Tokens) --- */
:root {
    /* Spacing Scale (no arbitrary values) */
    --space-1: 4px;
    --space-2: 8px;
    --space-3: 12px;
    --space-4: 16px;
    --space-5: 24px;
    --space-6: 32px;
    --space-7: 48px;
    --space-8: 64px;
    --space-9: 96px;

    /* Type Scale (hand-picked, not ratio-based) */
    --text-xs: 12px;
    --text-sm: 14px;
    --text-base: 16px;
    --text-lg: 18px;
    --text-xl: 20px;
    --text-2xl: 24px;
    --text-3xl: 30px;
    --text-4xl: 36px;

    /* Font Weights */
    --font-normal: 400;
    --font-medium: 500;
    --font-semibold: 600;
    --font-bold: 700;

    /* Line Heights (inversely proportional to size) */
    --leading-tight: 1.2;
    --leading-normal: 1.5;
    --leading-relaxed: 1.7;

    /* Greys (tinted slightly blue for warmth) */
    --grey-50: hsl(220, 20%, 98%);
    --grey-100: hsl(220, 18%, 96%);
    --grey-200: hsl(220, 16%, 90%);
    --grey-300: hsl(220, 14%, 80%);
    --grey-400: hsl(220, 12%, 65%);
    --grey-500: hsl(220, 10%, 50%);
    --grey-600: hsl(220, 12%, 40%);
    --grey-700: hsl(220, 14%, 30%);
    --grey-800: hsl(220, 16%, 20%);
    --grey-900: hsl(220, 18%, 12%);

    /* Primary (Blue with hue rotation for shades) */
    --primary-50: hsl(210, 100%, 97%);
    --primary-100: hsl(210, 95%, 93%);
    --primary-200: hsl(210, 90%, 85%);
    --primary-300: hsl(210, 85%, 70%);
    --primary-400: hsl(215, 80%, 58%);
    --primary-500: hsl(220, 75%, 50%);
    --primary-600: hsl(225, 70%, 45%);
    --primary-700: hsl(230, 65%, 38%);
    --primary-800: hsl(235, 60%, 30%);
    --primary-900: hsl(240, 55%, 22%);

    /* Accent (Purple) */
    --accent-500: hsl(270, 65%, 55%);

    /* Semantic Colors */
    --success-50: hsl(145, 80%, 95%);
    --success-500: hsl(145, 65%, 42%);
    --success-700: hsl(150, 60%, 30%);

    --warning-50: hsl(40, 95%, 93%);
    --warning-500: hsl(35, 90%, 50%);
    --warning-700: hsl(30, 85%, 40%);

    --danger-50: hsl(0, 85%, 95%);
    --danger-500: hsl(0, 70%, 55%);
    --danger-700: hsl(5, 65%, 42%);

    /* Shadows (Elevation System) */
    --shadow-sm: 0 1px 2px hsla(220, 20%, 20%, 0.05);
    --shadow-md: 0 4px 6px -1px hsla(220, 20%, 20%, 0.08),
                 0 2px 4px -1px hsla(220, 20%, 20%, 0.04);
    --shadow-lg: 0 10px 15px -3px hsla(220, 20%, 20%, 0.08),
                 0 4px 6px -2px hsla(220, 20%, 20%, 0.04);
    --shadow-xl: 0 20px 25px -5px hsla(220, 20%, 20%, 0.1),
                 0 10px 10px -5px hsla(220, 20%, 20%, 0.04);

    /* Border Radius */
    --radius-sm: 4px;
    --radius-md: 8px;
    --radius-lg: 12px;
    --radius-full: 9999px;

    /* Layout */
    --sidebar-width: 260px;
}

/* --- Reset & Base --- */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html {
    font-size: 16px;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    font-size: var(--text-base);
    line-height: var(--leading-normal);
    color: var(--grey-800);
    background-color: var(--grey-100);
}

/* --- Layout --- */
.app {
    display: flex;
    min-height: 100vh;
}

/* --- Sidebar --- */
.sidebar {
    width: var(--sidebar-width);
    background: var(--grey-900);
    color: var(--grey-100);
    display: flex;
    flex-direction: column;
    position: fixed;
    height: 100vh;
    z-index: 100;
}

.sidebar-header {
    padding: var(--space-5);
    border-bottom: 1px solid hsla(220, 20%, 100%, 0.08);
}

.logo {
    display: flex;
    align-items: center;
    gap: var(--space-3);
}

.logo-icon {
    width: 36px;
    height: 36px;
    background: linear-gradient(135deg, var(--primary-400), var(--primary-600));
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: var(--font-bold);
    font-size: var(--text-lg);
    color: white;
}

.logo-text {
    font-weight: var(--font-semibold);
    font-size: var(--text-lg);
    letter-spacing: -0.02em;
}

/* Navigation */
.nav {
    flex: 1;
    padding: var(--space-4);
    display: flex;
    flex-direction: column;
    gap: var(--space-1);
}

.nav-item {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    padding: var(--space-3) var(--space-4);
    border-radius: var(--radius-md);
    color: var(--grey-400);
    text-decoration: none;
    font-size: var(--text-sm);
    font-weight: var(--font-medium);
    transition: all 0.15s ease;
}

.nav-item:hover {
    color: var(--grey-100);
    background: hsla(220, 20%, 100%, 0.05);
}

.nav-item.active {
    color: white;
    background: hsla(220, 20%, 100%, 0.1);
}

.nav-icon {
    width: 20px;
    height: 20px;
    stroke-width: 1.5;
    opacity: 0.7;
}

.nav-item.active .nav-icon,
.nav-item:hover .nav-icon {
    opacity: 1;
}

/* Sidebar Footer */
.sidebar-footer {
    padding: var(--space-4);
    border-top: 1px solid hsla(220, 20%, 100%, 0.08);
}

.user-info {
    display: flex;
    align-items: center;
    gap: var(--space-3);
}

.avatar {
    width: 40px;
    height: 40px;
    background: linear-gradient(135deg, var(--primary-500), var(--accent-500));
    border-radius: var(--radius-full);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: var(--font-semibold);
    font-size: var(--text-sm);
    color: white;
}

.user-details {
    display: flex;
    flex-direction: column;
}

.user-name {
    font-weight: var(--font-medium);
    font-size: var(--text-sm);
    color: var(--grey-100);
}

.user-role {
    font-size: var(--text-xs);
    color: var(--grey-500);
}

/* --- Main Content --- */
.main {
    flex: 1;
    margin-left: var(--sidebar-width);
    padding: var(--space-6);
    max-width: calc(100vw - var(--sidebar-width));
}

/* Header */
.header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: var(--space-6);
}

.page-title {
    font-size: var(--text-2xl);
    font-weight: var(--font-semibold);
    color: var(--grey-900);
    line-height: var(--leading-tight);
    letter-spacing: -0.02em;
}

.page-subtitle {
    font-size: var(--text-sm);
    color: var(--grey-500);
    margin-top: var(--space-1);
}

.header-right {
    display: flex;
    align-items: center;
    gap: var(--space-4);
}

/* Search Box */
.search-box {
    position: relative;
}

.search-icon {
    position: absolute;
    left: var(--space-3);
    top: 50%;
    transform: translateY(-50%);
    width: 18px;
    height: 18px;
    color: var(--grey-400);
}

.search-input {
    padding: var(--space-2) var(--space-4) var(--space-2) var(--space-7);
    border: 1px solid var(--grey-200);
    border-radius: var(--radius-md);
    font-size: var(--text-sm);
    width: 240px;
    background: white;
    transition: all 0.15s ease;
}

.search-input:focus {
    outline: none;
    border-color: var(--primary-400);
    box-shadow: 0 0 0 3px var(--primary-100);
}

.search-input::placeholder {
    color: var(--grey-400);
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    gap: var(--space-2);
    padding: var(--space-2) var(--space-4);
    border-radius: var(--radius-md);
    font-size: var(--text-sm);
    font-weight: var(--font-medium);
    cursor: pointer;
    border: none;
    transition: all 0.15s ease;
}

.btn svg {
    width: 16px;
    height: 16px;
}

.btn-primary {
    background: var(--primary-500);
    color: white;
    box-shadow: var(--shadow-sm);
}

.btn-primary:hover {
    background: var(--primary-600);
    box-shadow: var(--shadow-md);
}

/* --- Stats Grid --- */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: var(--space-5);
    margin-bottom: var(--space-6);
}

.stat-card {
    background: white;
    border-radius: var(--radius-lg);
    padding: var(--space-5);
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--grey-200);
}

.stat-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: var(--space-2);
}

.stat-label {
    font-size: var(--text-sm);
    color: var(--grey-500);
    font-weight: var(--font-medium);
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.stat-badge {
    font-size: var(--text-xs);
    font-weight: var(--font-semibold);
    padding: var(--space-1) var(--space-2);
    border-radius: var(--radius-full);
}

.stat-badge.positive {
    background: var(--success-50);
    color: var(--success-700);
}

.stat-badge.negative {
    background: var(--danger-50);
    color: var(--danger-700);
}

.stat-value {
    font-size: var(--text-3xl);
    font-weight: var(--font-bold);
    color: var(--grey-900);
    line-height: var(--leading-tight);
    letter-spacing: -0.02em;
}

.stat-comparison {
    font-size: var(--text-sm);
    color: var(--grey-400);
    margin-top: var(--space-2);
}

/* --- Charts Section --- */
.charts-section {
    display: grid;
    grid-template-columns: 2fr 1fr;
    gap: var(--space-5);
    margin-bottom: var(--space-6);
}

.chart-card {
    background: white;
    border-radius: var(--radius-lg);
    padding: var(--space-5);
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--grey-200);
}

.card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: var(--space-5);
}

.card-title {
    font-size: var(--text-lg);
    font-weight: var(--font-semibold);
    color: var(--grey-800);
}

.card-actions {
    display: flex;
    gap: var(--space-1);
    background: var(--grey-100);
    padding: var(--space-1);
    border-radius: var(--radius-md);
}

.tab-btn {
    padding: var(--space-2) var(--space-3);
    border: none;
    background: transparent;
    font-size: var(--text-sm);
    font-weight: var(--font-medium);
    color: var(--grey-500);
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all 0.15s ease;
}

.tab-btn:hover {
    color: var(--grey-700);
}

.tab-btn.active {
    background: white;
    color: var(--grey-800);
    box-shadow: var(--shadow-sm);
}

/* Bar Chart */
.chart-container {
    height: 220px;
    display: flex;
    align-items: flex-end;
}

.chart-bars {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    width: 100%;
    height: 100%;
    gap: var(--space-3);
    padding-bottom: var(--space-6);
    position: relative;
}

.chart-bar {
    flex: 1;
    height: var(--height);
    background: linear-gradient(180deg, var(--primary-400), var(--primary-600));
    border-radius: var(--radius-sm) var(--radius-sm) 0 0;
    position: relative;
    transition: all 0.3s ease;
    cursor: pointer;
}

.chart-bar:hover {
    background: linear-gradient(180deg, var(--primary-300), var(--primary-500));
}

.chart-bar::before {
    content: attr(data-value);
    position: absolute;
    top: -28px;
    left: 50%;
    transform: translateX(-50%);
    font-size: var(--text-xs);
    font-weight: var(--font-semibold);
    color: var(--grey-600);
    opacity: 0;
    transition: opacity 0.2s ease;
}

.chart-bar:hover::before {
    opacity: 1;
}

.bar-label {
    position: absolute;
    bottom: -24px;
    left: 50%;
    transform: translateX(-50%);
    font-size: var(--text-xs);
    color: var(--grey-500);
}

/* Donut Chart */
.donut-chart {
    width: 160px;
    height: 160px;
    margin: 0 auto var(--space-5);
    position: relative;
}

.donut-ring {
    width: 100%;
    height: 100%;
    border-radius: 50%;
    background: conic-gradient(
        var(--primary-500) 0deg 140deg,
        var(--accent-500) 140deg 240deg,
        var(--success-500) 240deg 305deg,
        var(--warning-500) 305deg 360deg
    );
    mask: radial-gradient(circle at center, transparent 55%, black 56%);
    -webkit-mask: radial-gradient(circle at center, transparent 55%, black 56%);
}

.donut-center {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    text-align: center;
}

.donut-value {
    display: block;
    font-size: var(--text-2xl);
    font-weight: var(--font-bold);
    color: var(--grey-800);
    line-height: var(--leading-tight);
}

.donut-label {
    display: block;
    font-size: var(--text-xs);
    color: var(--grey-500);
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

/* Chart Legend */
.chart-legend {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: var(--space-3);
}

.legend-item {
    display: flex;
    align-items: center;
    gap: var(--space-3);
}

.legend-color {
    width: 12px;
    height: 12px;
    border-radius: var(--radius-sm);
    background: var(--color);
}

.legend-label {
    flex: 1;
    font-size: var(--text-sm);
    color: var(--grey-600);
}

.legend-value {
    font-size: var(--text-sm);
    font-weight: var(--font-semibold);
    color: var(--grey-800);
    font-variant-numeric: tabular-nums;
}

/* --- Activity Section --- */
.activity-section {
    margin-bottom: var(--space-6);
}

.card {
    background: white;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--grey-200);
    overflow: hidden;
}

.card > .card-header {
    padding: var(--space-5);
    border-bottom: 1px solid var(--grey-100);
}

.card-link {
    font-size: var(--text-sm);
    color: var(--primary-500);
    text-decoration: none;
    font-weight: var(--font-medium);
}

.card-link:hover {
    color: var(--primary-600);
    text-decoration: underline;
}

/* Data Table */
.data-table {
    width: 100%;
    border-collapse: collapse;
}

.data-table th {
    text-align: left;
    padding: var(--space-3) var(--space-5);
    font-size: var(--text-xs);
    font-weight: var(--font-semibold);
    color: var(--grey-500);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    background: var(--grey-50);
    border-bottom: 1px solid var(--grey-200);
}

.data-table td {
    padding: var(--space-4) var(--space-5);
    font-size: var(--text-sm);
    border-bottom: 1px solid var(--grey-100);
}

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

.data-table tr:hover {
    background: var(--grey-50);
}

.customer-cell {
    display: flex;
    align-items: center;
    gap: var(--space-3);
}

.customer-avatar {
    width: 32px;
    height: 32px;
    background: var(--grey-200);
    border-radius: var(--radius-full);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: var(--text-xs);
    font-weight: var(--font-semibold);
    color: var(--grey-600);
}

.customer-name {
    font-weight: var(--font-medium);
    color: var(--grey-800);
}

/* Status Badges */
.status-badge {
    display: inline-flex;
    align-items: center;
    padding: var(--space-1) var(--space-2);
    border-radius: var(--radius-full);
    font-size: var(--text-xs);
    font-weight: var(--font-medium);
}

.status-badge.success {
    background: var(--success-50);
    color: var(--success-700);
}

.status-badge.pending {
    background: var(--warning-50);
    color: var(--warning-700);
}

.status-badge.failed {
    background: var(--danger-50);
    color: var(--danger-700);
}

/* Utility Classes */
.text-right {
    text-align: right;
}

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

.text-mono {
    font-variant-numeric: tabular-nums;
    font-feature-settings: "tnum";
}

/* --- Responsive --- */
@media (max-width: 1200px) {
    .stats-grid {
        grid-template-columns: repeat(2, 1fr);
    }

    .charts-section {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 768px) {
    .sidebar {
        transform: translateX(-100%);
    }

    .main {
        margin-left: 0;
        max-width: 100vw;
    }

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

    .header {
        flex-direction: column;
        gap: var(--space-4);
    }

    .header-right {
        width: 100%;
    }

    .search-input {
        width: 100%;
    }
}
