:root {
  --primary: #1a73e8;
  --primary-dark: #1557b0;
  --primary-light: #e8f0fe;
  --success: #0f9d58;
  --warning: #f4b400;
  --danger: #d93025;
  --text: #202124;
  --text-secondary: #5f6368;
  --bg: #f8f9fa;
  --card-bg: #ffffff;
  --border: #dadce0;
  --shadow: 0 1px 3px rgba(0,0,0,0.12), 0 1px 2px rgba(0,0,0,0.08);
  --shadow-lg: 0 4px 12px rgba(0,0,0,0.15);
  --radius: 8px;
  --sidebar-w: 240px;
  --header-h: 56px;
}

* { margin: 0; padding: 0; box-sizing: border-box; }
body { font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif; color: var(--text); background: var(--bg); line-height: 1.5; }
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ── Auth Pages ── */
.auth-page { min-height: 100vh; display: flex; align-items: center; justify-content: center; background: linear-gradient(135deg, #667eea 0%, #764ba2 100%); padding: 20px; }
.auth-card { background: var(--card-bg); border-radius: 12px; box-shadow: var(--shadow-lg); padding: 40px; width: 100%; max-width: 440px; }
.auth-card h1 { font-size: 24px; margin-bottom: 4px; }
.auth-card p { color: var(--text-secondary); margin-bottom: 24px; font-size: 14px; }
.auth-card .logo { text-align: center; margin-bottom: 24px; }
.auth-card .logo h1 { font-size: 28px; background: linear-gradient(135deg, #667eea, #764ba2); -webkit-background-clip: text; -webkit-text-fill-color: transparent; }
.form-group { margin-bottom: 16px; }
.form-group label { display: block; font-size: 13px; font-weight: 500; color: var(--text-secondary); margin-bottom: 4px; }
.form-group input, .form-group select { width: 100%; padding: 10px 12px; border: 1px solid var(--border); border-radius: var(--radius); font-size: 14px; outline: none; transition: border-color 0.2s; }
.form-group input:focus { border-color: var(--primary); box-shadow: 0 0 0 2px var(--primary-light); }
.btn { display: inline-flex; align-items: center; justify-content: center; padding: 10px 20px; border: none; border-radius: var(--radius); font-size: 14px; font-weight: 500; cursor: pointer; transition: all 0.2s; gap: 8px; }
.btn-primary { background: var(--primary); color: white; }
.btn-primary:hover { background: var(--primary-dark); box-shadow: var(--shadow); }
.btn-block { width: 100%; }
.btn-ghost { background: transparent; color: var(--text-secondary); border: 1px solid var(--border); }
.btn-ghost:hover { background: var(--bg); }
.btn-sm { padding: 6px 12px; font-size: 12px; }
.btn-danger { background: var(--danger); color: white; }
.btn-success { background: var(--success); color: white; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* ── App Layout ── */
.app-layout { display: flex; min-height: 100vh; }

/* Sidebar */
.sidebar { width: var(--sidebar-w); background: #1a1a2e; color: white; display: flex; flex-direction: column; position: fixed; top: 0; left: 0; bottom: 0; z-index: 100; transition: transform 0.3s; }
.sidebar-header { padding: 16px 20px; border-bottom: 1px solid rgba(255,255,255,0.1); }
.sidebar-header h2 { font-size: 18px; }
.sidebar-header .sub { font-size: 11px; opacity: 0.6; }
.sidebar-nav { flex: 1; overflow-y: auto; padding: 8px 0; }
.sidebar-nav .section { padding: 8px 20px 4px; font-size: 10px; text-transform: uppercase; letter-spacing: 1px; opacity: 0.5; }
.sidebar-nav a { display: flex; align-items: center; gap: 10px; padding: 10px 20px; color: rgba(255,255,255,0.7); font-size: 13px; transition: all 0.2s; text-decoration: none; }
.sidebar-nav a:hover, .sidebar-nav a.active { background: rgba(255,255,255,0.1); color: white; }
.sidebar-nav a.active { border-left: 3px solid var(--primary); }
.sidebar-nav a .icon { width: 20px; text-align: center; font-size: 16px; }
.sidebar-footer { padding: 12px 20px; border-top: 1px solid rgba(255,255,255,0.1); font-size: 12px; }
.sidebar-footer a { color: rgba(255,255,255,0.5); display: block; padding: 4px 0; }

/* Main Content */
.main-content { margin-left: var(--sidebar-w); flex: 1; display: flex; flex-direction: column; min-height: 100vh; }
.topbar { height: var(--header-h); display: flex; align-items: center; justify-content: space-between; padding: 0 24px; background: var(--card-bg); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 50; }
.topbar h1 { font-size: 18px; font-weight: 600; }
.topbar-actions { display: flex; align-items: center; gap: 12px; }
.topbar-actions .org-name { font-size: 13px; color: var(--text-secondary); }
.content-area { padding: 24px; flex: 1; }

/* ── Cards ── */
.card { background: var(--card-bg); border-radius: var(--radius); box-shadow: var(--shadow); padding: 20px; margin-bottom: 16px; }
.card-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 16px; }
.card-header h3 { font-size: 16px; font-weight: 600; }
.card-header .badge { font-size: 11px; padding: 2px 8px; border-radius: 12px; background: var(--primary-light); color: var(--primary); }

/* ── Grid ── */
.grid { display: grid; gap: 16px; }
.grid-2 { grid-template-columns: repeat(2, 1fr); }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
.grid-4 { grid-template-columns: repeat(4, 1fr); }
@media (max-width: 768px) { .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; } }

/* ── KPI ── */
.kpi-card { text-align: center; padding: 24px 16px; }
.kpi-card .value { font-size: 32px; font-weight: 700; margin-bottom: 4px; }
.kpi-card .label { font-size: 13px; color: var(--text-secondary); }
.kpi-card .trend { font-size: 11px; margin-top: 4px; }

/* ── Table ── */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th { text-align: left; padding: 10px 12px; border-bottom: 2px solid var(--border); font-weight: 600; color: var(--text-secondary); font-size: 12px; text-transform: uppercase; letter-spacing: 0.5px; }
td { padding: 10px 12px; border-bottom: 1px solid var(--border); }
tr:hover td { background: var(--bg); }

/* ── Status Badges ── */
.badge { display: inline-block; padding: 2px 8px; border-radius: 12px; font-size: 11px; font-weight: 500; }
.badge-open { background: #e8f0fe; color: #1a73e8; }
.badge-scheduled { background: #fef7e0; color: #f4b400; }
.badge-in_progress, .badge-in-progress { background: #e8f5e9; color: #0f9d58; }
.badge-completed { background: #e8f5e9; color: #0f9d58; }
.badge-cancelled { background: #fce8e6; color: #d93025; }
.badge-urgent { background: #fce8e6; color: #d93025; animation: pulse 1.5s infinite; }
.badge-active { background: #e8f5e9; color: #0f9d58; }
.badge-warning { background: #fef7e0; color: #f4b400; }
.badge-draft { background: #f3e8fd; color: #7c3aed; }
.badge-sent { background: #e0f2fe; color: #0369a1; }
.badge-paid { background: #e8f5e9; color: #0f9d58; }
.badge-partial { background: #fef7e0; color: #f4b400; }
.badge-overdue { background: #fce8e6; color: #d93025; animation: pulse 1.5s infinite; }
.badge-planned { background: #e8f0fe; color: #1a73e8; }
.badge-visited { background: #e8f5e9; color: #0f9d58; }
.badge-skipped { background: #fce8e6; color: #d93025; }
/* Route stop number circle */
.stop-row .stop-num { width:28px;height:28px;border-radius:50%;display:flex;align-items:center;justify-content:center;font-size:12px;font-weight:700;flex-shrink:0; }
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: 0.6; } }

/* ── Status Bar ── */
.status-bar { padding: 8px 16px; border-radius: var(--radius); margin-bottom: 16px; font-size: 13px; }
.status-bar.info { background: var(--primary-light); color: var(--primary); }
.status-bar.success { background: #e8f5e9; color: var(--success); }
.status-bar.error { background: #fce8e6; color: var(--danger); }

/* ── Modal ── */
.modal-overlay { position: fixed; top: 0; left: 0; right: 0; bottom: 0; background: rgba(0,0,0,0.5); z-index: 200; display: flex; align-items: center; justify-content: center; padding: 20px; }
.modal { background: var(--card-bg); border-radius: 12px; box-shadow: var(--shadow-lg); width: 100%; max-width: 560px; max-height: 80vh; overflow-y: auto; padding: 24px; }
.modal h2 { font-size: 18px; margin-bottom: 16px; }
.modal-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 20px; padding-top: 16px; border-top: 1px solid var(--border); }

/* ── Landing Page ── */
.landing { min-height: 100vh; }
.hero { background: linear-gradient(135deg, #1a1a2e 0%, #16213e 50%, #0f3460 100%); color: white; padding: 80px 24px; text-align: center; }
.hero h1 { font-size: 48px; margin-bottom: 16px; font-weight: 700; }
.hero p { font-size: 18px; opacity: 0.85; max-width: 600px; margin: 0 auto 32px; }
.hero .btn { font-size: 16px; padding: 14px 32px; }
.hero .btn-primary { background: #e94560; }
.hero .btn-primary:hover { background: #d63851; }
.features { padding: 64px 24px; max-width: 1100px; margin: 0 auto; }
.features h2 { text-align: center; font-size: 32px; margin-bottom: 48px; }
.feature-grid { display: grid; grid-template-columns: repeat(3,1fr); gap: 24px; }
.feature-card { text-align: center; padding: 32px 20px; border-radius: var(--radius); background: var(--card-bg); box-shadow: var(--shadow); }
.feature-card .icon { font-size: 40px; margin-bottom: 16px; }
.feature-card h3 { font-size: 18px; margin-bottom: 8px; }
.feature-card p { font-size: 14px; color: var(--text-secondary); }
.pricing { padding: 64px 24px; background: var(--bg); }
.pricing h2 { text-align: center; font-size: 32px; margin-bottom: 48px; }
.pricing-grid { display: grid; grid-template-columns: repeat(3,1fr); gap: 24px; max-width: 900px; margin: 0 auto; }
.pricing-card { text-align: center; padding: 32px 20px; border-radius: var(--radius); background: var(--card-bg); box-shadow: var(--shadow); }
.pricing-card.featured { border: 2px solid var(--primary); position: relative; }
.pricing-card .price { font-size: 36px; font-weight: 700; margin: 16px 0; }
.pricing-card .price span { font-size: 14px; color: var(--text-secondary); }
.pricing-card ul { list-style: none; text-align: left; margin: 16px 0; }
.pricing-card li { padding: 6px 0; font-size: 13px; }
.pricing-card li:before { content: "✓ "; color: var(--success); }
@media (max-width: 768px) { .feature-grid, .pricing-grid { grid-template-columns: 1fr; } }

/* ── Tab Bar ── */
.tab-bar { display: flex; gap: 0; border-bottom: 2px solid var(--border); margin-bottom: 20px; }
.tab-bar .tab { padding: 10px 20px; font-size: 13px; font-weight: 500; color: var(--text-secondary); cursor: pointer; border-bottom: 2px solid transparent; margin-bottom: -2px; transition: all 0.2s; }
.tab-bar .tab:hover { color: var(--text); }
.tab-bar .tab.active { color: var(--primary); border-bottom-color: var(--primary); }

/* ── Utilities ── */
.flex { display: flex; }
.flex-1 { flex: 1; }
.gap-8 { gap: 8px; }
.gap-16 { gap: 16px; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.mt-16 { margin-top: 16px; }
.mb-16 { margin-bottom: 16px; }
.text-center { text-align: center; }
.text-sm { font-size: 13px; }
.text-muted { color: var(--text-secondary); }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ── Mobile Toggle ── */
.mobile-toggle { display: none; background: none; border: none; color: white; font-size: 24px; cursor: pointer; padding: 8px; }
@media (max-width: 768px) {
  .mobile-toggle { display: block; }
  .sidebar { transform: translateX(-100%); z-index: 100; }
  .sidebar.open { transform: translateX(0); box-shadow: var(--shadow-lg); }
  .main-content { margin-left: 0; }
  .content-area { padding: 12px; }
  .grid-2 { grid-template-columns: 1fr; }
  .grid-3 { grid-template-columns: 1fr; }
  .topbar { padding: 8px 12px; }
  .topbar h1 { font-size: 16px; }
  .modal { width: 95%; margin: 10px auto; max-height: 90vh; }
  .form-inline { flex-direction: column; }
  .form-inline .form-group input { width: 100%; min-width: 0; }
  .card { padding: 12px; }
  .card-header h3 { font-size: 14px; }
  table { font-size: 12px; }
  th, td { padding: 6px 4px; }
  .btn { padding: 8px 14px; font-size: 13px; }
  select.form-input { font-size: 16px; } /* prevents iOS zoom */
}
@media (max-width: 480px) {
  .topbar-actions .org-name { display: none; }
  .content-area { padding: 8px; }
  .card { padding: 8px; }
  .sidebar-header h2 { font-size: 16px; }
}

/* ── Form Inline ── */
.form-inline { display: flex; gap: 8px; align-items: flex-end; flex-wrap: wrap; }
.form-inline .form-group { margin-bottom: 0; }
.form-inline .form-group input { width: auto; min-width: 120px; }

/* ── Empty State ── */
.empty-state { text-align: center; padding: 48px 24px; color: var(--text-secondary); }
.empty-state .icon { font-size: 48px; margin-bottom: 12px; }
.empty-state h3 { font-size: 18px; margin-bottom: 8px; color: var(--text); }
