/* ===== RESET & BASE ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
    --primary: #2563eb;
    --primary-hover: #1d4ed8;
    --primary-light: #eff6ff;
    --success: #16a34a;
    --success-light: #dcfce7;
    --warning: #d97706;
    --warning-light: #fef3c7;
    --danger: #dc2626;
    --danger-light: #fef2f2;
    --info: #0891b2;
    --gray-50: #f9fafb;
    --gray-100: #f3f4f6;
    --gray-200: #e5e7eb;
    --gray-300: #d1d5db;
    --gray-400: #9ca3af;
    --gray-500: #6b7280;
    --gray-600: #4b5563;
    --gray-700: #374151;
    --gray-800: #1f2937;
    --gray-900: #111827;
    --sidebar-w: 260px;
    --topbar-h: 60px;
    --radius: 8px;
    --shadow: 0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.06);
    --shadow-md: 0 4px 6px rgba(0,0,0,.07), 0 2px 4px rgba(0,0,0,.06);
}

html { font-size: 15px; }
body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--gray-100);
    color: var(--gray-800);
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

a { color: var(--primary); text-decoration: none; }
a:hover { color: var(--primary-hover); text-decoration: underline; }

/* ===== LAYOUT ===== */
.layout-wrapper { display: flex; min-height: 100vh; }

/* ===== SIDEBAR ===== */
.sidebar {
    position: fixed; top: 0; left: 0; bottom: 0;
    width: var(--sidebar-w);
    background: var(--gray-900);
    color: #fff;
    display: flex; flex-direction: column;
    z-index: 1000;
    transition: transform .25s ease;
    overflow-y: auto;
}
.sidebar-brand {
    padding: 1.25rem 1.5rem;
    border-bottom: 1px solid rgba(255,255,255,.08);
    display: flex; align-items: center;
}
.sidebar-brand img { height: 36px; }
.sidebar-nav { list-style: none; padding: .75rem 0; flex: 1; }
.nav-section {
    padding: .75rem 1.5rem .375rem;
    font-size: .7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .06em;
    color: var(--gray-400);
}
.nav-item a {
    display: flex; align-items: center; gap: .625rem;
    padding: .5rem 1.5rem;
    color: var(--gray-300);
    font-size: .875rem;
    font-weight: 500;
    border-radius: 0;
    transition: background .15s, color .15s;
    text-decoration: none;
}
.nav-item a:hover { background: rgba(255,255,255,.06); color: #fff; text-decoration: none; }
.nav-item a.active { background: rgba(37,99,235,.35); color: #fff; }
.nav-icon { width: 20px; text-align: center; font-size: .85rem; flex-shrink: 0; }
.nav-badge {
    margin-left: auto;
    background: rgba(255,255,255,.12);
    color: var(--gray-300);
    font-size: .7rem;
    font-weight: 600;
    padding: .125rem .5rem;
    border-radius: 10px;
    min-width: 22px;
    text-align: center;
}

/* ===== SIDEBAR OVERLAY (mobile) ===== */
.sidebar-overlay {
    display: none; position: fixed; inset: 0;
    background: rgba(0,0,0,.5); z-index: 999;
}
.sidebar-overlay.show { display: block; }

/* ===== MAIN WRAPPER ===== */
.main-wrapper {
    margin-left: var(--sidebar-w);
    flex: 1;
    display: flex; flex-direction: column;
    min-height: 100vh;
}

/* ===== TOPBAR ===== */
.topbar {
    height: var(--topbar-h);
    background: #fff;
    border-bottom: 1px solid var(--gray-200);
    display: flex; align-items: center;
    justify-content: space-between;
    padding: 0 1.5rem;
    position: sticky; top: 0; z-index: 100;
}
.topbar-left { display: flex; align-items: center; gap: .75rem; }
.menu-toggle {
    display: none;
    background: none; border: none;
    font-size: 1.4rem; cursor: pointer;
    color: var(--gray-600);
    padding: .25rem;
}
.topbar-right { display: flex; align-items: center; gap: 1rem; }
.user-dropdown { position: relative; }
.user-btn {
    display: flex; align-items: center; gap: .5rem;
    background: none; border: none; cursor: pointer;
    font-size: .875rem; color: var(--gray-700);
    padding: .375rem .5rem;
    border-radius: var(--radius);
    transition: background .15s;
}
.user-btn:hover { background: var(--gray-100); }
.user-avatar {
    width: 32px; height: 32px;
    background: var(--primary);
    color: #fff;
    border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    font-weight: 600; font-size: .8rem;
}
.dropdown-menu {
    display: none;
    position: absolute; right: 0; top: calc(100% + 4px);
    background: #fff; border: 1px solid var(--gray-200);
    border-radius: var(--radius);
    box-shadow: var(--shadow-md);
    min-width: 160px;
    padding: .375rem;
    z-index: 200;
}
.dropdown-menu.show { display: block; }
.dropdown-menu a {
    display: block; padding: .5rem .75rem;
    font-size: .875rem; color: var(--gray-700);
    border-radius: 4px;
    text-decoration: none;
}
.dropdown-menu a:hover { background: var(--gray-50); text-decoration: none; }
.dropdown-menu .text-danger { color: var(--danger); }

/* ===== PAGE CONTENT ===== */
.page-content { flex: 1; padding: 1.5rem; }

/* ===== PAGE HEADER ===== */
.page-header {
    display: flex; align-items: center; justify-content: space-between;
    margin-bottom: 1.5rem;
    flex-wrap: wrap; gap: .5rem;
}
.page-title { font-size: 1.5rem; font-weight: 700; color: var(--gray-900); }
.breadcrumb {
    display: flex; align-items: center; gap: .375rem;
    font-size: .8rem; color: var(--gray-500);
}
.breadcrumb a { color: var(--gray-500); }
.breadcrumb a:hover { color: var(--primary); }
.breadcrumb .sep { color: var(--gray-300); }
.breadcrumb .current { color: var(--gray-700); font-weight: 500; }

/* ===== CARDS ===== */
.card {
    background: #fff;
    border: 1px solid var(--gray-200);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    margin-bottom: 1.5rem;
}
.card-header {
    padding: 1rem 1.25rem;
    border-bottom: 1px solid var(--gray-200);
    display: flex; align-items: center; justify-content: space-between;
}
.card-header h4 {
    font-size: 1rem; font-weight: 600; color: var(--gray-800); margin: 0;
}
.card-body { padding: 1.25rem; }

/* ===== ALERTS ===== */
.alert {
    padding: .75rem 1rem;
    border-radius: var(--radius);
    font-size: .875rem;
    font-weight: 500;
    margin-bottom: 1.25rem;
    display: flex; align-items: center; gap: .5rem;
}
.alert-success {
    background: var(--success-light);
    color: var(--success);
    border: 1px solid #bbf7d0;
}
.alert-danger {
    background: var(--danger-light);
    color: var(--danger);
    border: 1px solid #fecaca;
}
.alert-warning {
    background: var(--warning-light);
    color: var(--warning);
    border: 1px solid #fde68a;
}

/* ===== BADGES ===== */
.badge {
    display: inline-flex; align-items: center;
    padding: .2rem .6rem;
    font-size: .75rem;
    font-weight: 600;
    border-radius: 9999px;
    white-space: nowrap;
}
.badge-new { background: #dbeafe; color: #1e40af; }
.badge-supplement { background: #fef3c7; color: #92400e; }
.badge-repair { background: #e0e7ff; color: #3730a3; }
.badge-pickup { background: #d1fae5; color: #065f46; }
.badge-completed { background: #dcfce7; color: #166534; }
.badge-payment { background: #fce7f3; color: #9d174d; }
.badge-issue { background: #fef2f2; color: #991b1b; }

/* ===== TABLES ===== */
.modern-table {
    width: 100%;
    border-collapse: collapse;
    font-size: .875rem;
}
.modern-table thead th {
    background: var(--gray-50);
    color: var(--gray-600);
    font-weight: 600;
    font-size: .75rem;
    text-transform: uppercase;
    letter-spacing: .03em;
    padding: .75rem 1rem;
    border-bottom: 2px solid var(--gray-200);
    text-align: left;
    white-space: nowrap;
}
.modern-table tbody td {
    padding: .75rem 1rem;
    border-bottom: 1px solid var(--gray-100);
    color: var(--gray-700);
    vertical-align: middle;
}
.modern-table tbody tr:hover { background: var(--gray-50); }
.modern-table tbody tr:last-child td { border-bottom: none; }

/* Detail tables (key-value style) */
.detail-table { width: 100%; border-collapse: collapse; font-size: .875rem; }
.detail-table th {
    text-align: left;
    padding: .5rem .75rem;
    color: var(--gray-500);
    font-weight: 500;
    width: 180px;
    vertical-align: top;
    border-bottom: 1px solid var(--gray-100);
}
.detail-table td {
    padding: .5rem .75rem;
    color: var(--gray-800);
    border-bottom: 1px solid var(--gray-100);
    vertical-align: top;
}

/* ===== FORMS ===== */
.form-group { margin-bottom: 1rem; }
.form-label {
    display: block;
    font-size: .8rem;
    font-weight: 600;
    color: var(--gray-600);
    margin-bottom: .375rem;
    text-transform: uppercase;
    letter-spacing: .02em;
}
.form-control {
    display: block;
    width: 100%;
    padding: .5rem .75rem;
    font-size: .9rem;
    font-family: inherit;
    color: var(--gray-800);
    background: #fff;
    border: 1px solid var(--gray-300);
    border-radius: var(--radius);
    transition: border-color .15s, box-shadow .15s;
    line-height: 1.5;
}
.form-control:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(37,99,235,.15);
}
select.form-control {
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%236b7280' stroke-width='2'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right .75rem center;
    padding-right: 2.25rem;
}
textarea.form-control { resize: vertical; min-height: 100px; }

/* ===== BUTTONS ===== */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: .375rem;
    padding: .5rem 1rem;
    font-size: .875rem;
    font-weight: 600;
    font-family: inherit;
    border: 1px solid transparent;
    border-radius: var(--radius);
    cursor: pointer;
    transition: background .15s, box-shadow .15s, transform .1s;
    white-space: nowrap;
    text-decoration: none;
    line-height: 1.5;
}
.btn:hover { text-decoration: none; }
.btn:active { transform: scale(.98); }

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

.btn-success { background: var(--success); color: #fff; }
.btn-success:hover { background: #15803d; color: #fff; }

.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: #b91c1c; color: #fff; }

.btn-warning { background: var(--warning); color: #fff; }
.btn-warning:hover { background: #b45309; color: #fff; }

.btn-outline {
    background: #fff;
    border-color: var(--gray-300);
    color: var(--gray-700);
}
.btn-outline:hover { background: var(--gray-50); border-color: var(--gray-400); color: var(--gray-700); }

.btn-sm { padding: .3rem .65rem; font-size: .8rem; }
.btn-lg { padding: .625rem 1.5rem; font-size: 1rem; }

/* ===== STAT CARDS (Dashboard) ===== */
.stat-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: 1rem;
    margin-bottom: 1.5rem;
}
.stat-card {
    background: #fff;
    border: 1px solid var(--gray-200);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 1.25rem;
    text-align: center;
    transition: box-shadow .2s, transform .15s;
}
.stat-card:hover { box-shadow: var(--shadow-md); transform: translateY(-2px); }
.stat-card a { text-decoration: none; color: inherit; }
.stat-number {
    font-size: 2.5rem;
    font-weight: 800;
    color: var(--primary);
    line-height: 1.1;
    margin-bottom: .25rem;
}
.stat-label {
    font-size: .8rem;
    font-weight: 600;
    color: var(--gray-500);
    text-transform: uppercase;
    letter-spacing: .03em;
}

/* ===== SEARCH BAR ===== */
.search-bar {
    margin-bottom: 1.5rem;
}
.search-bar .form-control {
    font-size: 1.1rem;
    padding: .75rem 1rem;
}

/* ===== TWO-COLUMN LAYOUT ===== */
.grid-2 {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1.5rem;
    align-items: start;
}

/* ===== LINKS ===== */
.link-back {
    display: inline-flex; align-items: center; gap: .25rem;
    font-size: .85rem; font-weight: 500;
    color: var(--gray-500);
    margin-bottom: .5rem;
}
.link-back:hover { color: var(--primary); }

.link-edit {
    display: inline-flex; align-items: center; gap: .25rem;
    font-size: .8rem; font-weight: 500;
    color: var(--primary);
    margin-top: .75rem;
}
.link-danger { color: var(--danger); }
.link-danger:hover { color: #991b1b; }
.link-success { color: var(--success); }

/* ===== PRICE STRUCTURE ===== */
.grand-total {
    font-size: 1.75rem;
    font-weight: 800;
    color: var(--gray-900);
    padding: .75rem 0;
}
.paid-status { font-size: .75rem; font-weight: 600; }
.paid-yes { color: var(--success); }
.paid-no { color: var(--danger); }
.paid-na { color: var(--gray-500); }

/* ===== ATTACHMENTS ===== */
.attachment-thumb {
    height: 80px;
    border-radius: 4px;
    border: 1px solid var(--gray-200);
    object-fit: cover;
}

/* ===== DOWNLOAD BUTTONS ===== */
.download-list { display: flex; flex-direction: column; gap: .75rem; }
.download-link {
    display: inline-flex; align-items: center; gap: .5rem;
    padding: .625rem 1rem;
    background: var(--gray-50);
    border: 1px solid var(--gray-200);
    border-radius: var(--radius);
    color: var(--gray-700);
    font-weight: 500;
    font-size: .875rem;
    transition: background .15s;
    text-decoration: none;
}
.download-link:hover { background: var(--gray-100); text-decoration: none; }
.download-link svg { flex-shrink: 0; }

/* ===== LOGIN PAGE ===== */
.login-wrapper {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #1e3a8a 0%, #2563eb 50%, #0891b2 100%);
    padding: 1rem;
}
.login-card {
    background: #fff;
    border-radius: 12px;
    box-shadow: 0 20px 60px rgba(0,0,0,.15);
    width: 100%;
    max-width: 420px;
    padding: 2.5rem;
}
.login-card img { height: 50px; margin-bottom: 2rem; }
.login-card h2 {
    font-size: 1.5rem;
    font-weight: 700;
    margin-bottom: 1.5rem;
    color: var(--gray-900);
}
.login-error {
    background: var(--danger-light);
    color: var(--danger);
    padding: .5rem .75rem;
    border-radius: var(--radius);
    font-size: .85rem;
    margin-bottom: 1rem;
}

/* ===== FOOTER ===== */
.footer {
    padding: 1rem 1.5rem;
    text-align: center;
    font-size: .8rem;
    color: var(--gray-400);
    border-top: 1px solid var(--gray-200);
}

/* ===== EMPTY STATE ===== */
.empty-state {
    text-align: center;
    padding: 2.5rem 1rem;
    color: var(--gray-400);
    font-size: .9rem;
}

/* ===== RESPONSIVE ===== */
@media (max-width: 768px) {
    .sidebar { transform: translateX(-100%); }
    .sidebar.open { transform: translateX(0); }
    .main-wrapper { margin-left: 0; }
    .menu-toggle { display: block; }
    .page-content { padding: 1rem; }
    .grid-2 { grid-template-columns: 1fr; }
    .stat-grid { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); }
    .page-header { flex-direction: column; align-items: flex-start; }
    .modern-table { font-size: .8rem; }
    .modern-table thead th, .modern-table tbody td { padding: .5rem .625rem; }
    .detail-table th { width: 120px; }
}

@media (max-width: 480px) {
    .stat-grid { grid-template-columns: 1fr 1fr; }
    .login-card { padding: 1.5rem; }
}

/* ===== DATATABLE OVERRIDES ===== */
.dataTables_wrapper { font-size: .85rem; }
.dataTables_wrapper .dataTables_filter input {
    padding: .4rem .6rem;
    border: 1px solid var(--gray-300);
    border-radius: var(--radius);
    font-family: inherit;
}
.dataTables_wrapper .dataTables_length select {
    padding: .3rem .5rem;
    border: 1px solid var(--gray-300);
    border-radius: var(--radius);
    font-family: inherit;
}
table.dataTable thead th { border-bottom: 2px solid var(--gray-200) !important; }
table.dataTable tbody td { border-bottom: 1px solid var(--gray-100) !important; }
table.dataTable tbody tr:hover { background: var(--gray-50) !important; }
