:root {
    --primary: #001f3f;
    --secondary: #003366;
    --success: #4cc9f0;
    --danger: #f72585;
    --warning: #f8961e;
    --info: #4895ef;
    --light: #f8f9fa;
    --dark: #212529;
    --white: #ffffff;
    --gray: #6c757d;
    --gray-light: #e9ecef;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background-color: #f5f7fa;
    margin-left: 210px;
    padding: 40px;
    color: #333;
}

@media (max-width: 768px) {
    body {
        margin-left: 0;
        padding: 20px;
    }
}

.dashboard-container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 20px;
    background: white;
    border-radius: 8px;
    box-shadow: 0 0 20px rgba(0,0,0,0.05);
    min-height: calc(100vh - 80px);
}

.dashboard-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
}

.dashboard-header h1 {
    color: var(--primary);
    margin: 0;
    font-size: 1.3rem;
}

.date-filter {
    display: flex;
    gap: 10px;
}

.btn {
    padding: 6px 12px;
    border: none;
    border-radius: 4px;
    background-color: var(--white);
    color: var(--primary);
    cursor: pointer;
    font-weight: 500;
    font-size: 13px;
    display: flex;
    align-items: center;
    gap: 4px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
    transition: all 0.3s ease;
}

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

.btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(0,0,0,0.15);
}

/* Dashboard Grid Layout */
.dashboard-grid {
    display: grid;
    grid-template-columns: 1fr 2fr;
    gap: 20px;
    margin-bottom: 30px;
}

.summary-card {
    background: var(--white);
    border-radius: 10px;
    padding: 20px;
    box-shadow: 0 4px 6px rgba(0,0,0,0.05);
}

/* Summary Grid */
.summary-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    grid-template-rows: 1fr 1fr;
    gap: 12px;
    height: 100%;
}

.summary-grid-item {
    background: #f8f9fa;
    border-radius: 10px;
    padding: 14px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    box-shadow: 0 2px 4px rgba(0,0,0,0.05);
}

.summary-grid-item h3 {
    margin: 0 0 6px 0;
    font-size: 10px;
    line-height: 1.15;
    color: var(--gray);
    font-weight: 500;
}

.summary-grid-item span {
    font-size: clamp(12px, 1.4vw, 16px);
    line-height: 1;
    font-weight: 600;
    color: var(--dark);
    word-break: break-word;
}

.chart-card {
    background: var(--white);
    border-radius: 10px;
    padding: 20px;
    box-shadow: 0 4px 6px rgba(0,0,0,0.05);
}

.chart-card h2 {
    margin-top: 0;
    margin-bottom: 20px;
    font-size: 18px;
    color: var(--primary);
}

.table-section {
    background: var(--white);
    border-radius: 10px;
    padding: 20px;
    box-shadow: 0 4px 6px rgba(0,0,0,0.05);
}

.table-section h2 {
    margin-top: 0;
    color: var(--primary);
}

.table-controls {
    display: flex;
    justify-content: space-between;
    margin-bottom: 15px;
}

.table-controls input, .table-controls select {
    padding: 8px 12px;
    border: 1px solid var(--gray-light);
    border-radius: 5px;
}

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

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

#purchases-table th {
    background-color: var(--primary);
    color: white;
    padding: 12px 15px;
    text-align: left;
}

#purchases-table td {
    padding: 12px 15px;
    border-bottom: 1px solid var(--gray-light);
}

.purchase-number-cell {
    display: inline-flex;
    flex-direction: column;
    gap: 4px;
}

.purchase-number-value {
    font-weight: 600;
}

.purchase-receiver-badge {
    display: inline-flex;
    align-items: center;
    width: fit-content;
    padding: 3px 8px;
    border-radius: 999px;
    background: rgba(0, 31, 63, 0.08);
    color: var(--primary);
    font-size: 11px;
    font-weight: 600;
    line-height: 1.2;
    text-transform: capitalize;
}

.purchase-receiver-badge-shop {
    background: rgba(123, 31, 162, 0.12);
    color: #7b1fa2;
}

.purchase-receiver-badge-store {
    background: rgba(46, 125, 50, 0.12);
    color: #2e7d32;
}

#purchases-table tr:hover {
    background-color: #f8f9fa;
}

.status-badge {
    padding: 5px 10px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 500;
    text-transform: capitalize;
}

.status-created { background-color: #fff3cd; color: #856404; }
.status-completed { background-color: #d4edda; color: #155724; }
.status-cancelled { background-color: #f8d7da; color: #721c24; }

.action-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 30px;
    height: 30px;
    border-radius: 50%;
    color: #555;
    background: transparent;
    border: none;
    cursor: pointer;
    font-size: 1.2rem;
    margin: 0 3px;
    text-decoration: none;
}

.action-btn.view:hover {
    color: var(--primary);
    background: rgba(0, 31, 63, 0.1);
}

.action-btn.delete {
    color: #ff3d3d;
}

.action-btn.delete:hover {
    color: #ff0000;
    background: rgba(255, 0, 0, 0.1);
}

#purchases-table td:last-child {
    text-align: left;
}

.pagination {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 15px;
    margin-top: 20px;
}

.pagination button {
    background: var(--primary);
    color: white;
    border: none;
    width: 35px;
    height: 35px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}

.pagination button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

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

@media (max-width: 768px) {
    body {
        margin-left: 0;
        padding-top: 60px;
    }

    .dashboard-container {
        padding: 15px;
    }

    .summary-grid {
        gap: 10px;
    }

    .summary-grid-item {
        padding: 15px;
    }

    .summary-grid-item span {
        font-size: 18px;
    }

    .chart-card {
        width: 100%;
        max-width: 100%;
        overflow-x: auto;
    }

    .chart-card canvas {
        width: 100% !important;
        height: auto !important;
    }

    .table-controls {
        flex-direction: column;
        gap: 10px;
    }

    #purchases-table {
        display: block;
        overflow-x: auto;
        white-space: nowrap;
    }

    #purchases-table th, 
    #purchases-table td {
        min-width: 120px;
    }

    .date-filter {
        width: 100%;
        overflow-x: auto;
        padding-bottom: 10px;
        flex-wrap: nowrap;
    }

    .date-filter .btn {
        flex-shrink: 0;
    }
}

@media (max-width: 480px) {
    .dashboard-header h1 {
        font-size: 1.5rem;
        margin-bottom: 1em;
    }

    .dashboard-header {
        flex-direction: column;
    }

    .btn {
        padding: 6px 10px;
        font-size: 0.9rem;
    }
}

/* Purchases table supplier link style: inherit color, highlight on hover */
#purchases-table a {
    color: inherit;
    text-decoration: none;
}

#purchases-table a:hover,
#purchases-table a:focus {
    color: var(--primary);
    text-decoration: underline;
}

/* Theme parity: emphasize tiles and tables */
:is(html[data-theme='dark'], body[data-theme='dark']) body {
    background: #0b1220;
    color: #e5e7eb;
}

:is(html[data-theme='dark'], body[data-theme='dark']) .dashboard-container {
    background: #0f172a;
    border: 1px solid #334155;
    box-shadow: 0 24px 48px rgba(2, 6, 23, 0.45);
}

:is(html[data-theme='dark'], body[data-theme='dark']) .card,
:is(html[data-theme='dark'], body[data-theme='dark']) .summary-card,
:is(html[data-theme='dark'], body[data-theme='dark']) .summary-grid-item,
:is(html[data-theme='dark'], body[data-theme='dark']) .chart-card,
:is(html[data-theme='dark'], body[data-theme='dark']) .chart-container,
:is(html[data-theme='dark'], body[data-theme='dark']) .table-section {
    background: #111827;
    border: 1px solid #334155;
    box-shadow: 0 14px 30px rgba(2, 8, 23, 0.38);
}

:is(html[data-theme='dark'], body[data-theme='dark']) .table-responsive {
    border: 1px solid #334155;
    border-radius: 12px;
    box-shadow: inset 0 0 0 1px rgba(71, 85, 105, 0.35);
}

:is(html[data-theme='dark'], body[data-theme='dark']) .table-section thead th {
    background: #1e293b;
    color: #e2e8f0;
    border-bottom: 1px solid #334155;
}

:is(html[data-theme='dark'], body[data-theme='dark']) .table-section tbody tr {
    background: #111827;
}

:is(html[data-theme='dark'], body[data-theme='dark']) .table-section tbody td {
    color: #e5e7eb;
    border-bottom: 1px solid #273449;
}

:is(html[data-theme='dark'], body[data-theme='dark']) .table-section tbody tr:hover {
    background: #1f2937;
}

:is(html[data-theme='dark'], body[data-theme='dark']) .dashboard-header h1,
:is(html[data-theme='dark'], body[data-theme='dark']) .table-section h2,
:is(html[data-theme='dark'], body[data-theme='dark']) .chart-card h2,
:is(html[data-theme='dark'], body[data-theme='dark']) .chart-container h2,
:is(html[data-theme='dark'], body[data-theme='dark']) .summary-grid-item h3,
:is(html[data-theme='dark'], body[data-theme='dark']) .card-info h3 {
    color: #f8fafc;
}

:is(html[data-theme='dark'], body[data-theme='dark']) .summary-grid-item span,
:is(html[data-theme='dark'], body[data-theme='dark']) .card-info span,
:is(html[data-theme='dark'], body[data-theme='dark']) .card-note {
    color: #dbeafe;
}

:is(html[data-theme='dark'], body[data-theme='dark']) .table-controls input,
:is(html[data-theme='dark'], body[data-theme='dark']) .table-controls select,
:is(html[data-theme='dark'], body[data-theme='dark']) .chart-filter {
    background: #0f172a;
    color: #e5e7eb;
    border: 1px solid #334155;
}

:is(html[data-theme='light'], body[data-theme='light']) body {
    background: #f3f7fb;
    color: #1f2937;
}

:is(html[data-theme='light'], body[data-theme='light']) .dashboard-container {
    background: #ffffff;
    border: 1px solid #dbe5f2;
    box-shadow: 0 18px 36px rgba(15, 23, 42, 0.1);
}

:is(html[data-theme='light'], body[data-theme='light']) .card,
:is(html[data-theme='light'], body[data-theme='light']) .summary-card,
:is(html[data-theme='light'], body[data-theme='light']) .summary-grid-item,
:is(html[data-theme='light'], body[data-theme='light']) .chart-card,
:is(html[data-theme='light'], body[data-theme='light']) .chart-container,
:is(html[data-theme='light'], body[data-theme='light']) .table-section {
    background: #ffffff;
    border: 1px solid #dde6f2;
    box-shadow: 0 12px 24px rgba(15, 23, 42, 0.08);
}

:is(html[data-theme='light'], body[data-theme='light']) .table-responsive {
    border: 1px solid #d6e2f0;
    border-radius: 12px;
}

:is(html[data-theme='light'], body[data-theme='light']) .table-section thead th {
    background: #f1f5f9;
    border-bottom: 1px solid #d6e2f0;
}

:is(html[data-theme='light'], body[data-theme='light']) .table-section tbody tr:hover {
    background: #f8fbff;
}

/* Regression fixes: chart overflow and hover contrast */
.dashboard-grid,
.dashboard-grid > *,
.chart-card,
.table-section {
    min-width: 0;
}

.chart-card {
    overflow: hidden;
}

.chart-card canvas {
    display: block;
    width: 100% !important;
    max-width: 100% !important;
}

.table-responsive {
    max-width: 100%;
}

:is(html[data-theme='dark'], body[data-theme='dark']) #purchases-table tbody tr:hover {
    background: #334155;
}

:is(html[data-theme='dark'], body[data-theme='dark']) #purchases-table tbody tr:hover td,
:is(html[data-theme='dark'], body[data-theme='dark']) #purchases-table tbody tr:hover td a {
    color: #f8fafc;
}

:is(html[data-theme='light'], body[data-theme='light']) #purchases-table tbody tr:hover {
    background: #eaf1ff;
}

:is(html[data-theme='light'], body[data-theme='light']) #purchases-table tbody tr:hover td,
:is(html[data-theme='light'], body[data-theme='light']) #purchases-table tbody tr:hover td a {
    color: #0f172a;
}

/* Mobile overflow guard for chart containers */
.chart-card {
    box-sizing: border-box;
}

@media (max-width: 768px) {
    .dashboard-container,
    .dashboard-grid,
    .dashboard-grid > *,
    .chart-card {
        width: 100%;
        max-width: 100%;
        min-width: 0;
        box-sizing: border-box;
    }

    .chart-card {
        overflow: hidden;
        margin-left: 0;
        margin-right: 0;
    }
}
