:root {
    --primary: #2563eb;
    --primary-light: #3b82f6;
    --primary-dark: #1d4ed8;
    --sidebar-bg: #0f172a;
    --sidebar-hover: #1e293b;
    --sidebar-active: #1e293b;
    --bg: #f1f5f9;
    --surface: #ffffff;
    --text: #1e293b;
    --text-muted: #64748b;
    --border: #e2e8f0;
    --success: #10b981;
    --success-bg: #d1fae5;
    --warning: #f59e0b;
    --warning-bg: #fef3c7;
    --danger: #ef4444;
    --danger-bg: #fee2e2;
    --info-bg: #dbeafe;
    --radius: 8px;
    --radius-lg: 12px;
    --shadow: 0 1px 3px rgba(0,0,0,0.08), 0 1px 2px rgba(0,0,0,0.04);
    --shadow-md: 0 4px 6px rgba(0,0,0,0.05), 0 2px 4px rgba(0,0,0,0.04);
}

* { margin: 0; padding: 0; box-sizing: border-box; }
html, body { height: 100%; }
body { font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif; background: var(--bg); color: var(--text); font-size: 14px; line-height: 1.5; }

/* Utilities */
.hidden { display: none !important; }
.screen { min-height: 100vh; }

/* Login */
#login-screen {
    display: flex; align-items: center; justify-content: center;
    background: linear-gradient(135deg, #0f172a 0%, #1e293b 100%);
}
.login-card {
    background: var(--surface); border-radius: var(--radius-lg); padding: 3rem;
    width: 100%; max-width: 400px; box-shadow: var(--shadow-md);
}
.login-logo { text-align: center; margin-bottom: 2rem; }
.logo-icon {
    display: inline-flex; align-items: center; justify-content: center;
    width: 56px; height: 56px; background: var(--primary); color: white;
    border-radius: var(--radius-lg); font-weight: 700; font-size: 1.25rem;
    margin-bottom: 1rem;
}
.login-logo h1 { font-size: 1.5rem; color: var(--text); }
.login-logo p { color: var(--text-muted); font-size: 0.875rem; }
.form-group { margin-bottom: 1.25rem; }
.form-group label { display: block; font-weight: 500; margin-bottom: 0.375rem; font-size: 0.875rem; color: var(--text); }
.form-group input {
    width: 100%; padding: 0.625rem 0.875rem; border: 1px solid var(--border);
    border-radius: var(--radius); font-size: 0.875rem; font-family: inherit;
    transition: border-color 0.15s, box-shadow 0.15s;
}
.form-group input:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(37,99,235,0.1); }
.alert { padding: 0.75rem; border-radius: var(--radius); font-size: 0.875rem; margin-bottom: 1rem; background: var(--danger-bg); color: var(--danger); }

/* Buttons */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 0.5rem;
    padding: 0.625rem 1.25rem; border: none; border-radius: var(--radius);
    font-size: 0.875rem; font-weight: 500; font-family: inherit; cursor: pointer;
    transition: all 0.15s;
}
.btn-primary { background: var(--primary); color: white; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-full { width: 100%; }
.btn-sm { padding: 0.375rem 0.75rem; font-size: 0.8125rem; }

/* App Layout */
#app-screen { display: flex; min-height: 100vh; }

/* Sidebar */
.sidebar {
    width: 240px; background: var(--sidebar-bg); color: white;
    display: flex; flex-direction: column; position: fixed;
    top: 0; left: 0; bottom: 0; z-index: 50;
}
.sidebar-brand {
    display: flex; align-items: center; gap: 0.75rem;
    padding: 1.25rem 1.25rem; border-bottom: 1px solid rgba(255,255,255,0.08);
    font-weight: 600; font-size: 0.9375rem;
}
.logo-icon-sm {
    width: 32px; height: 32px; background: var(--primary); border-radius: 6px;
    display: flex; align-items: center; justify-content: center;
    font-weight: 700; font-size: 0.75rem;
}
.sidebar-nav { flex: 1; padding: 0.75rem; display: flex; flex-direction: column; gap: 2px; }
.nav-item {
    display: flex; align-items: center; gap: 0.75rem;
    padding: 0.625rem 0.875rem; border-radius: var(--radius);
    color: rgba(255,255,255,0.6); text-decoration: none; font-size: 0.875rem;
    transition: all 0.15s; border: none; background: none; cursor: pointer;
    width: 100%; text-align: left; font-family: inherit;
}
.nav-item:hover { color: white; background: var(--sidebar-hover); }
.nav-item.active { color: white; background: var(--sidebar-active); font-weight: 500; }
.sidebar-footer { padding: 0.75rem; border-top: 1px solid rgba(255,255,255,0.08); }

/* Main Content */
.main-content { margin-left: 240px; flex: 1; min-height: 100vh; display: flex; flex-direction: column; }
.top-bar {
    display: flex; align-items: center; justify-content: space-between;
    padding: 1rem 2rem; background: var(--surface); border-bottom: 1px solid var(--border);
}
.top-bar h2 { font-size: 1.125rem; font-weight: 600; }
.top-bar-right { display: flex; align-items: center; gap: 1rem; color: var(--text-muted); font-size: 0.875rem; }
.page-content { padding: 2rem; flex: 1; }

/* Stats Cards */
.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 1.25rem; margin-bottom: 2rem; }
.stat-card {
    background: var(--surface); border-radius: var(--radius-lg); padding: 1.5rem;
    box-shadow: var(--shadow); border: 1px solid var(--border);
}
.stat-card .label { font-size: 0.8125rem; color: var(--text-muted); font-weight: 500; margin-bottom: 0.5rem; }
.stat-card .value { font-size: 2rem; font-weight: 700; color: var(--text); }
.stat-card .value.primary { color: var(--primary); }
.stat-card .value.success { color: var(--success); }
.stat-card .value.warning { color: var(--warning); }
.stat-card .value.danger { color: var(--danger); }

/* Tables */
.card { background: var(--surface); border-radius: var(--radius-lg); box-shadow: var(--shadow); border: 1px solid var(--border); overflow: hidden; }
.card-header { padding: 1.25rem 1.5rem; border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; }
.card-header h3 { font-size: 1rem; font-weight: 600; }
table { width: 100%; border-collapse: collapse; }
th { text-align: left; padding: 0.75rem 1.5rem; font-size: 0.75rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.05em; color: var(--text-muted); background: var(--bg); border-bottom: 1px solid var(--border); }
td { padding: 0.875rem 1.5rem; border-bottom: 1px solid var(--border); font-size: 0.875rem; }
tr:last-child td { border-bottom: none; }
tr:hover td { background: #f8fafc; }

/* Badges */
.badge {
    display: inline-flex; align-items: center; padding: 0.1875rem 0.625rem;
    border-radius: 999px; font-size: 0.75rem; font-weight: 500;
}
.badge-scheduled { background: var(--info-bg); color: var(--primary); }
.badge-pending { background: var(--warning-bg); color: #92400e; }
.badge-en_route, .badge-en-route { background: var(--info-bg); color: var(--primary); }
.badge-delivered, .badge-completed { background: var(--success-bg); color: #065f46; }
.badge-failed { background: var(--danger-bg); color: #991b1b; }

/* Empty State */
.empty-state { text-align: center; padding: 4rem 2rem; color: var(--text-muted); }
.empty-state svg { margin-bottom: 1rem; opacity: 0.4; }
.empty-state h3 { font-size: 1rem; margin-bottom: 0.5rem; color: var(--text); }
.empty-state p { font-size: 0.875rem; }

/* Loading */
.loading { display: flex; align-items: center; justify-content: center; padding: 4rem; color: var(--text-muted); }

/* Responsive */
@media (max-width: 768px) {
    .sidebar { width: 60px; }
    .sidebar-brand span, .nav-item span { display: none; }
    .sidebar-brand { justify-content: center; padding: 1rem; }
    .main-content { margin-left: 60px; }
    .page-content { padding: 1rem; }
    .stats-grid { grid-template-columns: 1fr 1fr; }
}
/* Search Bar */
.search-bar { margin-bottom: 1.25rem; }
.search-input-wrapper {
    position: relative; display: flex; align-items: center;
    background: var(--surface); border: 1.5px solid var(--border);
    border-radius: var(--radius-lg); box-shadow: var(--shadow);
    transition: border-color 0.15s, box-shadow 0.15s;
}
.search-input-wrapper:focus-within {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(37,99,235,0.1);
}
.search-icon {
    position: absolute; left: 1rem; color: var(--text-muted);
    pointer-events: none;
}
.search-input {
    width: 100%; padding: 0.75rem 1rem 0.75rem 2.75rem;
    border: none; background: transparent; font-size: 0.9375rem;
    font-family: inherit; color: var(--text); outline: none;
}
.search-input::placeholder { color: var(--text-muted); }
.search-count {
    padding-right: 1rem; font-size: 0.8125rem; color: var(--text-muted);
    white-space: nowrap;
}
/* Pagination */
.pagination {
    display: flex; align-items: center; justify-content: center;
    gap: 0.375rem; margin-top: 1.25rem; padding: 0.5rem 0;
}
.page-btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 0.25rem;
    padding: 0.5rem 0.875rem; border: 1.5px solid var(--border);
    border-radius: var(--radius); background: var(--surface);
    font-size: 0.8125rem; font-weight: 500; font-family: inherit;
    color: var(--text); cursor: pointer; transition: all 0.15s;
    min-width: 36px;
}
.page-btn:hover:not(.disabled):not(.active) {
    border-color: var(--primary); color: var(--primary); background: var(--info-bg, #dbeafe);
}
.page-btn.active {
    background: var(--primary); color: white; border-color: var(--primary);
}
.page-btn.disabled {
    opacity: 0.4; cursor: not-allowed;
}
.page-ellipsis {
    padding: 0.5rem 0.25rem; color: var(--text-muted); font-size: 0.875rem;
}
/* Pagination */
.pagination {
    display: flex; align-items: center; justify-content: center;
    gap: 0.375rem; margin-top: 1.25rem; padding: 0.5rem 0;
}
.page-btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 0.25rem;
    padding: 0.5rem 0.875rem; border: 1.5px solid var(--border);
    border-radius: var(--radius); background: var(--surface);
    font-size: 0.8125rem; font-weight: 500; font-family: inherit;
    color: var(--text); cursor: pointer; transition: all 0.15s;
    min-width: 36px;
}
.page-btn:hover:not(.disabled):not(.active) {
    border-color: var(--primary); color: var(--primary); background: var(--info-bg, #dbeafe);
}
.page-btn.active {
    background: var(--primary); color: white; border-color: var(--primary);
}
.page-btn.disabled {
    opacity: 0.4; cursor: not-allowed;
}
.page-ellipsis {
    padding: 0.5rem 0.25rem; color: var(--text-muted); font-size: 0.875rem;
}
/* Clickable rows */
.clickable-row { cursor: pointer; transition: background 0.1s; }
.clickable-row:hover td { background: var(--info-bg, #dbeafe) !important; }

/* Back button */
.btn-back {
    display: inline-flex; align-items: center; gap: 0.375rem;
    padding: 0.5rem 0.875rem; margin-bottom: 1.25rem;
    border: 1.5px solid var(--border); border-radius: var(--radius);
    background: var(--surface); color: var(--text-muted);
    font-size: 0.8125rem; font-weight: 500; font-family: inherit;
    cursor: pointer; transition: all 0.15s;
}
.btn-back:hover { color: var(--primary); border-color: var(--primary); }

/* Detail header */
.detail-header {
    display: flex; justify-content: space-between; align-items: flex-start;
    margin-bottom: 1.5rem; flex-wrap: wrap; gap: 1rem;
}
.detail-header-left { display: flex; align-items: center; gap: 1rem; flex-wrap: wrap; }
.detail-header-left h2 { font-size: 1.5rem; font-weight: 700; }
.detail-header-right { text-align: right; }
.order-total { font-size: 1.75rem; font-weight: 700; color: var(--primary); }
.hubspot-link {
    font-size: 0.8125rem; color: var(--primary); text-decoration: none;
    padding: 0.25rem 0.625rem; border-radius: 4px; background: var(--info-bg, #dbeafe);
}
.hubspot-link:hover { text-decoration: underline; }

/* Detail grid */
.detail-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 1.25rem; }
.detail-grid-sm { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1.5rem; }
@media (max-width: 768px) {
    .detail-grid { grid-template-columns: 1fr; }
    .detail-grid-sm { grid-template-columns: 1fr; }
}

/* Detail cards */
.detail-card-body { padding: 1.25rem; }
.detail-row { display: flex; justify-content: space-between; align-items: flex-start; padding: 0.5rem 0; border-bottom: 1px solid var(--border); }
.detail-row:last-child { border-bottom: none; }
.detail-label { font-size: 0.8125rem; color: var(--text-muted); font-weight: 500; min-width: 90px; flex-shrink: 0; }
.detail-value { font-size: 0.875rem; text-align: right; word-break: break-word; }
.detail-value a { color: var(--primary); text-decoration: none; }
.detail-value a:hover { text-decoration: underline; }

/* Header count badge */
.header-count {
    font-size: 0.75rem; font-weight: 500; color: var(--text-muted);
    background: var(--bg); padding: 0.25rem 0.625rem; border-radius: 999px;
}

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

/* Empty state small */
.empty-state-sm { padding: 2rem 1.5rem; text-align: center; color: var(--text-muted); font-size: 0.875rem; }

/* Notes */
.notes-list { padding: 0; }
.note-item { padding: 1rem 1.5rem; border-bottom: 1px solid var(--border); }
.note-item:last-child { border-bottom: none; }
.note-meta { display: flex; gap: 0.75rem; margin-bottom: 0.5rem; }
.note-date { font-size: 0.75rem; color: var(--text-muted); font-weight: 500; }
.note-author { font-size: 0.75rem; color: var(--primary); }
.note-body { font-size: 0.875rem; line-height: 1.6; color: var(--text); }

/* Status timeline */
.status-timeline { margin-top: 1.5rem; padding-top: 1rem; border-top: 1px solid var(--border); }
.status-timeline h4 { font-size: 0.875rem; font-weight: 600; margin-bottom: 1rem; color: var(--text); }
.timeline-item { display: flex; gap: 0.875rem; margin-bottom: 1rem; position: relative; }
.timeline-item:not(:last-child)::before {
    content: ''; position: absolute; left: 6px; top: 18px; bottom: -12px;
    width: 2px; background: var(--border);
}
.timeline-dot {
    width: 14px; height: 14px; border-radius: 50%; flex-shrink: 0; margin-top: 3px;
    background: var(--border);
}
.timeline-dot.badge-scheduled { background: var(--primary); }
.timeline-dot.badge-en_route { background: var(--warning); }
.timeline-dot.badge-arrived { background: #8b5cf6; }
.timeline-dot.badge-delivered { background: var(--success); }
.timeline-dot.badge-failed { background: var(--danger); }
.timeline-content { flex: 1; }
.timeline-content strong { font-size: 0.8125rem; text-transform: capitalize; }
.timeline-time { font-size: 0.75rem; color: var(--text-muted); margin-left: 0.5rem; }
.timeline-content p { font-size: 0.8125rem; color: var(--text-muted); margin-top: 0.25rem; }
