/* ── Buttons ── */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 8px;
    padding: 10px 20px; border-radius: var(--radius); font-size: 14px; font-weight: 600;
    font-family: var(--font); cursor: pointer; transition: all 0.15s;
    border: 1.5px solid transparent; text-decoration: none; white-space: nowrap;
}
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-sm { padding: 6px 14px; font-size: 13px; border-radius: var(--radius-sm); }
.btn-lg { padding: 14px 28px; font-size: 16px; }
.btn-primary { background: var(--primary); color: #fff; border-color: var(--primary); }
.btn-primary:hover:not(:disabled) { background: var(--primary-dark); border-color: var(--primary-dark); transform: translateY(-1px); box-shadow: 0 4px 12px rgba(67,56,202,0.25); }
.btn-outline { background: var(--white); color: var(--gray-700); border-color: var(--gray-200); }
.btn-outline:hover:not(:disabled) { border-color: var(--primary); color: var(--primary); }
.btn-danger { background: var(--red); color: #fff; border-color: var(--red); }
.btn-danger:hover:not(:disabled) { background: #dc2626; }
.btn-success { background: var(--green); color: #fff; border-color: var(--green); }
.btn-ghost { background: transparent; color: var(--gray-600); border-color: transparent; }
.btn-ghost:hover:not(:disabled) { background: var(--gray-100); color: var(--dark); }
.btn-icon { padding: 8px; }

/* ── Cards ── */
.card {
    background: var(--white); border: 1px solid var(--gray-200);
    border-radius: var(--radius-lg); overflow: hidden;
}
.card-header {
    padding: 20px 24px; border-bottom: 1px solid var(--gray-100);
    display: flex; align-items: center; justify-content: space-between; gap: 16px;
}
.card-header h3 { font-size: 16px; font-weight: 700; color: var(--dark); }
.card-body { padding: 24px; }
.card-footer { padding: 16px 24px; border-top: 1px solid var(--gray-100); background: var(--gray-50); }

/* ── Stat Cards ── */
.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 16px; margin-bottom: 28px; }
.stat-card {
    background: var(--white); border: 1px solid var(--gray-200);
    border-radius: var(--radius-lg); padding: 20px 24px;
}
.stat-card .stat-label { font-size: 13px; font-weight: 500; color: var(--gray-500); margin-bottom: 4px; }
.stat-card .stat-value { font-size: 28px; font-weight: 800; color: var(--dark); }
.stat-card .stat-sub { font-size: 12px; color: var(--gray-400); margin-top: 4px; }

/* ── Forms ── */
.form-group { margin-bottom: 20px; }
.form-label { display: block; font-size: 13px; font-weight: 600; color: var(--gray-700); margin-bottom: 6px; }
.form-input, .form-select, .form-textarea {
    width: 100%; padding: 10px 14px;
    border: 1.5px solid var(--gray-200); border-radius: var(--radius);
    font-size: 14px; font-family: var(--font); color: var(--gray-800);
    transition: border-color 0.15s, box-shadow 0.15s;
    background: var(--white);
}
.form-input:focus, .form-select:focus, .form-textarea:focus {
    outline: none; border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(67,56,202,0.1);
}
.form-input::placeholder { color: var(--gray-400); }
.form-input.error { border-color: var(--red); }
.form-error { font-size: 12px; color: var(--red); margin-top: 4px; }
.form-hint { font-size: 12px; color: var(--gray-400); margin-top: 4px; }
.form-textarea { resize: vertical; min-height: 80px; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
@media (max-width: 520px) { .form-row { grid-template-columns: 1fr; } }

/* ── Tables ── */
.table-container { overflow-x: auto; }
.data-table { width: 100%; border-collapse: collapse; font-size: 14px; }
.data-table th {
    text-align: left; padding: 12px 16px;
    font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.5px;
    color: var(--gray-500); background: var(--gray-50);
    border-bottom: 1px solid var(--gray-200);
}
.data-table td { padding: 14px 16px; border-bottom: 1px solid var(--gray-100); color: var(--gray-700); }
.data-table tr:hover td { background: var(--gray-50); }
.data-table .td-actions { white-space: nowrap; text-align: right; }

/* ── Badges ── */
.badge {
    display: inline-flex; align-items: center; gap: 4px;
    padding: 3px 10px; border-radius: 20px;
    font-size: 12px; font-weight: 600;
}
.badge-green { background: var(--green-light); color: #065f46; }
.badge-red { background: var(--red-light); color: #991b1b; }
.badge-amber { background: var(--amber-light); color: #92400e; }
.badge-blue { background: var(--blue-light); color: #1e40af; }
.badge-gray { background: var(--gray-100); color: var(--gray-600); }

/* ── Toast ── */
#toast-container {
    position: fixed; bottom: 24px; right: 24px; z-index: 9999;
    display: flex; flex-direction: column-reverse; gap: 8px;
}
.toast {
    padding: 14px 20px; border-radius: var(--radius);
    font-size: 14px; font-weight: 500; color: #fff;
    box-shadow: var(--shadow-lg); min-width: 280px; max-width: 420px;
    animation: toastIn 0.3s ease;
    display: flex; align-items: center; gap: 10px;
}
.toast-success { background: #059669; }
.toast-error { background: var(--red); }
.toast-info { background: var(--blue); }
.toast-warning { background: var(--amber); color: var(--gray-900); }
@keyframes toastIn { from { opacity: 0; transform: translateY(16px); } to { opacity: 1; transform: translateY(0); } }

/* ── Modal ── */
.modal-backdrop {
    position: fixed; inset: 0; background: rgba(0,0,0,0.4);
    z-index: 1000; display: flex; align-items: center; justify-content: center;
    padding: 24px; animation: fadeIn 0.15s;
}
.modal {
    background: var(--white); border-radius: var(--radius-lg);
    box-shadow: 0 20px 60px rgba(0,0,0,0.15); width: 100%; max-width: 520px;
    max-height: 90vh; overflow-y: auto; animation: modalIn 0.2s ease;
}
.modal-header {
    padding: 20px 24px; border-bottom: 1px solid var(--gray-100);
    display: flex; align-items: center; justify-content: space-between;
}
.modal-header h3 { font-size: 18px; font-weight: 700; color: var(--dark); }
.modal-close { width: 32px; height: 32px; border: none; background: none; cursor: pointer; border-radius: var(--radius-sm); color: var(--gray-400); display: flex; align-items: center; justify-content: center; }
.modal-close:hover { background: var(--gray-100); color: var(--gray-600); }
.modal-body { padding: 24px; }
.modal-footer { padding: 16px 24px; border-top: 1px solid var(--gray-100); display: flex; justify-content: flex-end; gap: 10px; }
.modal-wide { max-width: 720px; }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes modalIn { from { opacity: 0; transform: scale(0.95); } to { opacity: 1; transform: scale(1); } }

/* ── Empty State ── */
.empty-state { text-align: center; padding: 60px 24px; }
.empty-state .empty-icon { font-size: 48px; margin-bottom: 16px; opacity: 0.5; }
.empty-state h3 { font-size: 18px; font-weight: 700; color: var(--dark); margin-bottom: 8px; }
.empty-state p { font-size: 14px; color: var(--gray-500); margin-bottom: 20px; }

/* ── Spinner ── */
.spinner { width: 24px; height: 24px; border: 3px solid var(--gray-200); border-top-color: var(--primary); border-radius: 50%; animation: spin 0.6s linear infinite; }
.spinner-sm { width: 16px; height: 16px; border-width: 2px; }
@keyframes spin { to { transform: rotate(360deg); } }
.loading-center { display: flex; align-items: center; justify-content: center; padding: 60px; }

/* ── Pagination ── */
.pagination { display: flex; align-items: center; gap: 8px; justify-content: center; padding: 20px 0; }
.pagination button {
    padding: 8px 14px; border: 1px solid var(--gray-200); border-radius: var(--radius-sm);
    background: var(--white); font-size: 13px; font-weight: 500; color: var(--gray-600);
    cursor: pointer; font-family: var(--font);
}
.pagination button:hover:not(:disabled) { border-color: var(--primary); color: var(--primary); }
.pagination button.active { background: var(--primary); color: #fff; border-color: var(--primary); }
.pagination button:disabled { opacity: 0.4; cursor: not-allowed; }
.pagination .page-info { font-size: 13px; color: var(--gray-500); }

/* ── Search / Toolbar ── */
.toolbar { display: flex; align-items: center; gap: 12px; margin-bottom: 20px; flex-wrap: wrap; }
.search-input {
    flex: 1; min-width: 200px; padding: 10px 14px 10px 38px;
    border: 1.5px solid var(--gray-200); border-radius: var(--radius);
    font-size: 14px; font-family: var(--font); color: var(--gray-800);
    background: var(--white) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='%239ca3af' viewBox='0 0 16 16'%3E%3Cpath d='M11.742 10.344a6.5 6.5 0 1 0-1.397 1.398h-.001l3.85 3.85a1 1 0 0 0 1.415-1.414l-3.85-3.85zm-5.442.156a5 5 0 1 1 0-10 5 5 0 0 1 0 10z'/%3E%3C/svg%3E") no-repeat 12px center;
}
.search-input:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(67,56,202,0.1); }
.filter-select { padding: 10px 14px; border: 1.5px solid var(--gray-200); border-radius: var(--radius); font-size: 14px; font-family: var(--font); background: var(--white); color: var(--gray-700); }

/* ── Letter Avatar ── */
.avatar-letter {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 18px;
    color: white;
    text-transform: uppercase;
    flex-shrink: 0;
}

/* ── Mobile Dashboard Cards ── */
.dash-card {
    background: var(--white);
    border: 1px solid var(--gray-200);
    border-radius: var(--radius-lg);
    padding: 20px;
    margin-bottom: 16px;
}
.dash-card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 12px;
}
.dash-card-title {
    font-size: 16px;
    font-weight: 700;
    color: var(--dark);
}

/* Status toggle card */
.status-card {
    background: var(--white);
    border: 2px solid var(--gray-200);
    border-radius: var(--radius-xl);
    padding: 24px;
    text-align: center;
    margin-bottom: 20px;
}
.status-card.online { border-color: var(--green); }
.status-card .status-label {
    font-size: 22px;
    font-weight: 800;
    margin-bottom: 12px;
}
.status-card .status-dot {
    width: 12px; height: 12px;
    border-radius: 50%;
    display: inline-block;
    margin-right: 8px;
    animation: pulse 1.5s infinite;
}
.status-dot.green { background: var(--green); }
.status-dot.gray { background: var(--gray-400); }

/* Delivery card */
.delivery-card {
    background: var(--white);
    border: 1px solid var(--gray-200);
    border-radius: var(--radius-lg);
    padding: 20px;
    margin-bottom: 12px;
    transition: box-shadow 0.15s;
}
.delivery-card:active { box-shadow: var(--shadow-md); }
.delivery-route {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 12px;
    font-size: 14px;
}
.delivery-route .route-dot {
    width: 10px; height: 10px;
    border-radius: 50%;
    flex-shrink: 0;
}
.delivery-route .route-dot.pickup { background: var(--blue); }
.delivery-route .route-dot.dropoff { background: var(--green); }
.delivery-route .route-line {
    width: 2px; height: 20px;
    background: var(--gray-300);
    margin-left: 4px;
}
.delivery-route .route-text {
    flex: 1;
    color: var(--gray-700);
    font-size: 14px;
    line-height: 1.4;
}
.delivery-actions {
    display: flex;
    gap: 10px;
    margin-top: 12px;
}
.delivery-actions .btn {
    flex: 1;
    min-height: 48px;
    font-size: 15px;
}

/* Section titles */
.dash-section {
    font-size: 15px;
    font-weight: 700;
    color: var(--gray-500);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin: 24px 0 12px;
}

/* Quick action button (large) */
.quick-action-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    width: 100%;
    padding: 20px;
    background: var(--primary);
    color: white;
    border: none;
    border-radius: var(--radius-lg);
    font-size: 18px;
    font-weight: 700;
    font-family: var(--font);
    cursor: pointer;
    margin-bottom: 20px;
    min-height: 60px;
    transition: all 0.15s;
    text-decoration: none;
}
.quick-action-btn:hover { background: var(--primary-dark); color: white; transform: translateY(-1px); }

/* Mobile bottom nav */
.mobile-bottom-nav {
    display: none;
    position: fixed;
    bottom: 0; left: 0; right: 0;
    background: var(--white);
    border-top: 1px solid var(--gray-200);
    padding: 8px 0;
    padding-bottom: max(8px, env(safe-area-inset-bottom));
    z-index: 50;
}
.mobile-bottom-nav .nav-items {
    display: flex;
    justify-content: space-around;
}
.mobile-bottom-nav .nav-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    padding: 6px 12px;
    font-size: 11px;
    font-weight: 600;
    color: var(--gray-400);
    text-decoration: none;
    min-width: 64px;
}
.mobile-bottom-nav .nav-item.active { color: var(--primary); }
.mobile-bottom-nav .nav-item svg { width: 24px; height: 24px; }

/* Cards grid for desktop */
.dash-grid {
    display: grid;
    gap: 16px;
}

@media (min-width: 769px) {
    .dash-grid { grid-template-columns: repeat(2, 1fr); }
    .dash-grid-3 { grid-template-columns: repeat(3, 1fr); }
    .mobile-bottom-nav { display: none !important; }
}

@media (max-width: 768px) {
    .mobile-bottom-nav { display: block; }
    /* Add padding at bottom for nav */
    .main-content { padding-bottom: 80px !important; }
}

/* ── Mobile Responsiveness (Bug 4 fix) ── */
@media (max-width: 768px) {
    .data-table { font-size: 13px; }
    .data-table th, .data-table td { padding: 10px 12px; }
    .page-header-row { flex-direction: column; align-items: flex-start; gap: 12px; }
    .toolbar { flex-direction: column; align-items: stretch; }
    .search-input { min-width: unset; }
}

@media (max-width: 520px) {
    .branding-grid, .settings-grid { grid-template-columns: 1fr !important; }
    .stats-grid { grid-template-columns: 1fr !important; }
    .card-body { padding: 16px; }
    .card-header { padding: 16px; }
}

/* ── Mobile grid stacking (Issue 4) ── */
@media (max-width: 768px) {
    [style*="grid-template-columns: 1fr 1fr"],
    [style*="grid-template-columns:1fr 1fr"] {
        grid-template-columns: 1fr !important;
    }
    [style*="grid-template-columns: 1fr 1fr 1fr"],
    [style*="grid-template-columns:1fr 1fr 1fr"] {
        grid-template-columns: 1fr !important;
    }
}

/* Drawer component */
.drawer-overlay { position:fixed;top:0;left:0;right:0;bottom:0;background:rgba(0,0,0,0.4);z-index:1000;display:flex;justify-content:flex-end; }
.drawer { width:480px;max-width:100%;height:100vh;background:var(--white);display:flex;flex-direction:column;box-shadow:-4px 0 24px rgba(0,0,0,0.15);animation:slideIn 0.3s ease; }
.drawer-header { padding:20px 24px;border-bottom:1px solid var(--gray-200);position:sticky;top:0;background:var(--white);z-index:1;display:flex;justify-content:space-between;align-items:center; }
.drawer-header h2 { margin:0;font-size:18px; }
.drawer-body { flex:1;overflow-y:auto;padding:24px; }
.drawer-footer { padding:16px 24px;border-top:1px solid var(--gray-200);position:sticky;bottom:0;background:var(--white);display:flex;gap:12px;justify-content:flex-end; }
@keyframes slideIn { from { transform:translateX(100%); } to { transform:translateX(0); } }
@media (max-width: 768px) { .drawer { width:100%; } }
