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

:root {
    --sidebar-w: 220px;
    --bg: #f4f6fb;
    --surface: #ffffff;
    --border: #e2e8f0;
    --text: #1e293b;
    --muted: #64748b;
    --primary: #4f46e5;
    --primary-light: #eef2ff;

    --blue: #3b82f6;
    --blue-bg: #eff6ff;
    --green: #22c55e;
    --green-bg: #f0fdf4;
    --purple: #a855f7;
    --purple-bg: #faf5ff;
    --orange: #f97316;
    --orange-bg: #fff7ed;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    background: var(--bg);
    color: var(--text);
    display: flex;
    min-height: 100vh;
}

/* ── Sidebar ── */
.sidebar {
    width: var(--sidebar-w);
    background: var(--surface);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0; left: 0; bottom: 0;
    padding: 24px 16px;
}

.sidebar-logo {
    padding: 0 8px 24px;
}

.sidebar-logo-img {
    width: 100%;
    max-width: 100px;
    height: auto;
    display: block;
}

.sidebar-nav { list-style: none; display: flex; flex-direction: column; gap: 4px; flex: 1; }

/* ── Sidebar user block ── */
.sidebar-user {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px;
    border-top: 1px solid var(--border);
    margin-top: 8px;
    gap: 8px;
}

.sidebar-user-info {
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.sidebar-user-name {
    font-size: 0.82rem;
    font-weight: 600;
    color: var(--text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.sidebar-user-role {
    font-size: 0.72rem;
    color: var(--muted);
}

.logout-btn {
    font-size: 1.1rem;
    color: var(--muted);
    text-decoration: none;
    padding: 4px;
    border-radius: 6px;
    transition: color 0.15s, background 0.15s;
    flex-shrink: 0;
}
.logout-btn:hover { color: #ef4444; background: #fee2e2; }

.sidebar-nav a {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    border-radius: 8px;
    text-decoration: none;
    color: var(--muted);
    font-size: 0.9rem;
    font-weight: 500;
    transition: background 0.15s, color 0.15s;
}

.sidebar-nav a:hover { background: var(--bg); color: var(--text); }
.sidebar-nav a.active { background: var(--primary-light); color: var(--primary); }
.nav-icon { font-size: 1rem; }

/* ── Main ── */
.main-content {
    margin-left: var(--sidebar-w);
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

.topbar {
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    padding: 18px 32px;
}

.page-title { font-size: 1.25rem; font-weight: 600; }

.content { padding: 28px 32px; display: flex; flex-direction: column; gap: 24px; }

/* ── Stat Cards ── */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 16px;
}

.stat-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 20px;
    display: flex;
    align-items: center;
    gap: 16px;
}

.stat-icon { font-size: 2rem; }

.stat-info { display: flex; flex-direction: column; }
.stat-value { font-size: 1.5rem; font-weight: 700; line-height: 1.2; }
.stat-label { font-size: 0.8rem; color: var(--muted); margin-top: 2px; }

.stat-card--blue  { border-left: 4px solid var(--blue);   background: var(--blue-bg); }
.stat-card--green { border-left: 4px solid var(--green);  background: var(--green-bg); }
.stat-card--purple{ border-left: 4px solid var(--purple); background: var(--purple-bg); }
.stat-card--orange{ border-left: 4px solid var(--orange); background: var(--orange-bg); }

/* ── Card ── */
.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    overflow: hidden;
}

.card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    border-bottom: 1px solid var(--border);
}

.card-header h2 { font-size: 1rem; font-weight: 600; }

/* ── Buttons ── */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 16px;
    border-radius: 8px;
    font-size: 0.85rem;
    font-weight: 500;
    cursor: pointer;
    border: none;
    text-decoration: none;
    transition: opacity 0.15s;
}
.btn:hover { opacity: 0.85; }

.btn-primary { background: var(--primary); color: #fff; }
.btn-outline { background: transparent; color: var(--primary); border: 1px solid var(--primary); }

/* ── Table ── */
.data-table { width: 100%; border-collapse: collapse; font-size: 0.8rem; }

.data-table th {
    text-align: left;
    padding: 10px 12px;
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--muted);
    background: var(--bg);
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
}

.data-table td {
    padding: 10px 12px;
    border-bottom: 1px solid var(--border);
    color: var(--text);
    white-space: nowrap;
}

.data-table tbody tr:last-child td { border-bottom: none; }
.data-table tbody tr:hover { background: var(--bg); }

.order-id { font-weight: 600; color: var(--primary); }

/* ── Badges ── */
.badge {
    display: inline-block;
    padding: 3px 10px;
    border-radius: 999px;
    font-size: 0.75rem;
    font-weight: 500;
}

.badge--delivered  { background: #dcfce7; color: #166534; }
.badge--shipped    { background: #dbeafe; color: #1e40af; }
.badge--processing { background: #fef9c3; color: #854d0e; }
.badge--pending    { background: #fee2e2; color: #991b1b; }

/* ── Machine Tags ── */
.machine-tag {
    display: inline-block;
    padding: 3px 10px;
    border-radius: 999px;
    font-size: 0.75rem;
    font-weight: 600;
}
.machine-tag--excavator { background: #fff3e0; color: #e65100; }
.machine-tag--bulldozer { background: #e8f5e9; color: #2e7d32; }
.machine-tag--lowbed    { background: #f3e5f5; color: #6a1b9a; }

/* ── Table footer total ── */
.total-row td {
    border-top: 2px solid var(--border);
    padding-top: 12px;
    background: var(--bg);
}

.entry-id { font-weight: 600; color: var(--primary); }

/* ── Tracking values ── */
.tracking-value { font-variant-numeric: tabular-nums; }
.tracking-unit  { font-size: 0.7rem; color: var(--muted); margin-left: 1px; }

/* ── Filter Bar ── */
.filter-bar {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 16px 20px;
}

.filter-form {
    display: flex;
    align-items: flex-end;
    gap: 16px;
    flex-wrap: wrap;
}

.filter-group {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.filter-group label {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.filter-group select,
.filter-group input[type="date"] {
    padding: 8px 12px;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 0.875rem;
    color: var(--text);
    background: var(--bg);
    outline: none;
    transition: border-color 0.15s;
}

.filter-group select:focus,
.filter-group input[type="date"]:focus {
    border-color: var(--primary);
}

.filter-group input:disabled,
.filter-group select:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.filter-divider {
    font-size: 0.8rem;
    color: var(--muted);
    padding-bottom: 8px;
    font-style: italic;
}

.filter-active-label {
    display: inline-block;
    margin-left: 10px;
    background: var(--primary-light);
    color: var(--primary);
    font-size: 0.75rem;
    font-weight: 500;
    padding: 2px 10px;
    border-radius: 999px;
}

/* ── Login page ── */
.login-body {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    background: var(--bg);
}

.login-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 40px 36px;
    width: 100%;
    max-width: 380px;
    box-shadow: 0 4px 24px rgba(0,0,0,0.06);
}

.login-logo {
    display: flex;
    justify-content: center;
    margin-bottom: 24px;
}

.login-logo img { height: 48px; width: auto; }

.login-title {
    font-size: 1.4rem;
    font-weight: 700;
    text-align: center;
    margin-bottom: 4px;
}

.login-subtitle {
    font-size: 0.85rem;
    color: var(--muted);
    text-align: center;
    margin-bottom: 28px;
}

.login-error {
    background: #fee2e2;
    color: #991b1b;
    border: 1px solid #fca5a5;
    border-radius: 8px;
    padding: 10px 14px;
    font-size: 0.85rem;
    margin-bottom: 20px;
}

.login-form { display: flex; flex-direction: column; gap: 16px; }

.login-field { display: flex; flex-direction: column; gap: 6px; }

.login-field label {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.login-field input {
    padding: 10px 14px;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 0.9rem;
    color: var(--text);
    background: var(--bg);
    outline: none;
    transition: border-color 0.15s;
}

.login-field input:focus { border-color: var(--primary); }

.login-btn { width: 100%; justify-content: center; padding: 11px; font-size: 0.95rem; margin-top: 4px; }

/* ── Mobile Nav Toggle ── */
.menu-toggle {
    display: none;
    background: none;
    border: none;
    font-size: 1.4rem;
    cursor: pointer;
    color: var(--text);
    padding: 4px 8px;
    border-radius: 6px;
    line-height: 1;
    flex-shrink: 0;
}

.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.4);
    z-index: 99;
}
.sidebar-overlay.open { display: block; }

/* ── Responsive ── */
@media (max-width: 768px) {
    .menu-toggle { display: block; }

    .sidebar {
        transform: translateX(-100%);
        transition: transform 0.25s ease;
        z-index: 100;
    }
    .sidebar.open { transform: translateX(0); }

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

    .topbar {
        padding: 14px 16px;
        display: flex;
        align-items: center;
        gap: 12px;
    }
    .page-title { font-size: 1.1rem; }

    .content { padding: 16px; gap: 16px; }

    .stats-grid {
        grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
        gap: 12px;
    }

    /* Hide less critical columns on mobile to prevent horizontal scroll */
    .col-index { display: none; }
    .data-table th:nth-child(3),
    .data-table td:nth-child(3) { display: none; } /* Machine ID */
    .data-table th:nth-child(8),
    .data-table td:nth-child(8) { display: none; } /* Site */

    .card { overflow-x: hidden; }
    .data-table { width: 100%; }
    .data-table td, .data-table th { white-space: normal; }

    .card-header { flex-wrap: wrap; gap: 8px; }

    .filter-form { flex-direction: column; align-items: stretch; gap: 10px; }
    .filter-group select,
    .filter-group input[type="date"] { width: 100%; }
    .filter-divider { padding-bottom: 0; }
}

/* ── Print ── */
.print-header { display: none; }
.print-summary { display: none; }
.print-footer-note { display: none; }
.print-machine-summary { display: none; }

@media print {
    @page {
        size: A4 landscape;
        margin: 1.5cm 1.8cm;
    }

    body { background: #fff; font-size: 11px; color: #000; }
    .sidebar, .topbar, .card-header, .no-print { display: none !important; }
    .col-index { display: table-cell !important; }
    .data-table th:nth-child(3), .data-table td:nth-child(3) { display: table-cell !important; }
    .data-table th:nth-child(8), .data-table td:nth-child(8) { display: table-cell !important; }
    .main-content { margin-left: 0; }
    .content { padding: 0; }
    .card { border: none; border-radius: 0; box-shadow: none; }

    /* ── Print Header ── */
    .print-header {
        display: flex;
        align-items: center;
        justify-content: space-between;
        padding-bottom: 12px;
        margin-bottom: 6px;
        border-bottom: 3px solid #1a1a2e;
    }

    .print-logo { height: 52px; width: auto; }

    .print-header-right {
        text-align: right;
    }
    .print-report-title {
        font-size: 16px;
        font-weight: 700;
        color: #1a1a2e;
        letter-spacing: 0.03em;
        text-transform: uppercase;
        margin-bottom: 4px;
    }
    .print-meta {
        font-size: 9.5px;
        color: #555;
        line-height: 1.6;
    }

    /* ── Summary boxes ── */
    .print-summary {
        display: flex;
        gap: 12px;
        margin: 12px 0;
    }
    .print-summary-box {
        flex: 1;
        border: 1px solid #ccc;
        border-radius: 4px;
        padding: 8px 12px;
        text-align: center;
    }
    .print-summary-box .ps-label {
        font-size: 8.5px;
        text-transform: uppercase;
        letter-spacing: 0.05em;
        color: #666;
        display: block;
        margin-bottom: 2px;
    }
    .print-summary-box .ps-value {
        font-size: 14px;
        font-weight: 700;
        color: #1a1a2e;
    }

    .ps-excavator { background: #fff3e0 !important; border-color: #e65100 !important; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
    .ps-excavator .ps-label { color: #e65100 !important; }
    .ps-excavator .ps-value { color: #e65100 !important; }

    .ps-bulldozer { background: #e8f5e9 !important; border-color: #2e7d32 !important; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
    .ps-bulldozer .ps-label { color: #2e7d32 !important; }
    .ps-bulldozer .ps-value { color: #2e7d32 !important; }

    .ps-lowbed { background: #f3e5f5 !important; border-color: #6a1b9a !important; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
    .ps-lowbed .ps-label { color: #6a1b9a !important; }
    .ps-lowbed .ps-value { color: #6a1b9a !important; }

    /* ── Table ── */
    .data-table {
        width: 100%;
        border-collapse: collapse;
        font-size: 10px;
        margin-top: 4px;
    }

    .data-table thead tr {
        background: #1a1a2e !important;
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
    }

    .data-table th {
        padding: 8px 10px;
        font-size: 8.5px;
        font-weight: 700;
        text-transform: uppercase;
        letter-spacing: 0.06em;
        color: #fff !important;
        background: #1a1a2e !important;
        border: none;
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
    }

    .data-table td {
        padding: 7px 10px;
        border-bottom: 1px solid #e0e0e0;
        color: #000;
    }

    .data-table tbody tr:nth-child(even) td {
        background: #f7f7f7 !important;
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
    }

    .data-table tbody tr:hover { background: transparent; }

    .total-row td {
        border-top: 2px solid #1a1a2e;
        background: #eef2ff !important;
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
        font-size: 10.5px;
    }

    /* ── Machine tags in print ── */
    .machine-tag {
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
        border-radius: 999px;
        padding: 2px 8px;
        font-weight: 700;
        font-size: 9.5px;
    }
    .machine-tag--excavator { background: #fff3e0 !important; color: #e65100 !important; }
    .machine-tag--bulldozer { background: #e8f5e9 !important; color: #2e7d32 !important; }
    .machine-tag--lowbed    { background: #f3e5f5 !important; color: #6a1b9a !important; }

    /* ── Per-machine summary ── */
    .print-machine-summary {
        display: block;
        text-align: right;
        margin: 14px 0 0;
        page-break-inside: avoid;
        break-inside: avoid;
        page-break-before: auto;
    }

    .pms-table {
        margin-left: auto;
        border: 1px solid #ccc;
    }

    .pms-title {
        font-size: 10px;
        font-weight: 700;
        text-transform: uppercase;
        letter-spacing: 0.06em;
        color: #1a1a2e;
        margin-bottom: 6px;
        text-align: right;
    }

    .pms-table {
        width: auto;
        min-width: 320px;
        border-collapse: collapse;
        font-size: 9.5px;
        margin-left: auto;
    }

    .pms-table th {
        background: #1a1a2e !important;
        color: #fff !important;
        padding: 6px 10px;
        font-size: 8px;
        font-weight: 700;
        text-transform: uppercase;
        letter-spacing: 0.05em;
        text-align: left;
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
    }

    .pms-table td {
        padding: 5px 10px;
        border-bottom: 1px solid #e0e0e0;
    }

    .pms-table .pms-total td {
        border-top: 2px solid #1a1a2e;
        background: #1a1a2e !important;
        color: #fff !important;
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
        padding: 7px 10px;
        font-size: 10px;
    }

    /* ── Footer note ── */
    .print-footer-note {
        display: block;
        margin-top: 16px;
        padding-top: 8px;
        border-top: 1px solid #ccc;
        font-size: 8.5px;
        color: #888;
        display: flex;
        justify-content: space-between;
    }
}
