:root {
  --color-primary: #0d9488;
  --color-primary-dark: #0f766e;
  --color-primary-light: #ccfbf1;
  --color-success: #15803d;
  --color-success-bg: #dcfce7;
  --color-success-bright: #22c55e;
  --color-warning: #b45309;
  --color-warning-bg: #fef3c7;
  --color-error: #dc2626;
  --color-error-bg: #fee2e2;

  --bg: #f2f5f0;
  --surface: #ffffff;
  --surface2: #f0f4ee;
  --text: #141a14;
  --text2: #3d4d3d;
  --text3: #4a5a4a;
  --border: #d8e0d6;
  --shadow-sm: 0 1px 3px rgba(0,0,0,.06);
  --shadow: 0 2px 8px rgba(0,0,0,.08);
  --shadow-lg: 0 8px 24px rgba(0,0,0,.1);

  --radius: 16px;
  --radius-sm: 10px;

  --header-bg: #0f766e;
  --line-hover: #ecf3ea;
  --badge-bg: #ccfbf1;
  --badge-text: #0d9488;
  --next-bg: #fef9c3;
  --next-color: #854d0e;
  --operator-resende: #0d9488;
  --operator-cidade: #ca8a04;
  --operator-agulhas: #c026d3;
  --now-badge: #dc2626;
  --accent: #f59e0b;

  --text-caption: .75rem;
  --text-sm: .875rem;
  --text-base: 1rem;
  --text-lg: 1.125rem;
  --text-xl: 1.5rem;
  --text-2xl: 2rem;
  --leading-tight: 1.2;
  --leading-normal: 1.4;
  --weight-normal: 400;
  --weight-medium: 500;
  --weight-semibold: 600;
  --weight-bold: 700;
}

[data-theme="dark"] {
  --color-primary: #5eead4;
  --color-primary-dark: #2dd4bf;
  --color-primary-light: #134e4a;
  --color-success: #86efac;
  --color-success-bg: #14532d;
  --color-success-bright: #22c55e;
  --color-warning: #fcd34d;
  --color-warning-bg: #451a03;
  --color-error: #fca5a5;
  --color-error-bg: #450a0a;

  --bg: #0c110c;
  --surface: #161f16;
  --surface2: #1c2a1c;
  --text: #e0e6e0;
  --text2: #9aaa9a;
  --text3: #8a9a8a;
  --border: #2a3a2a;
  --shadow-sm: 0 1px 3px rgba(0,0,0,.2);
  --shadow: 0 2px 8px rgba(0,0,0,.3);
  --shadow-lg: 0 8px 24px rgba(0,0,0,.4);

  --header-bg: #0b5e5a;
  --line-hover: #1c2a1c;
  --badge-bg: #134e4a;
  --badge-text: #5eead4;
  --next-bg: #422e00;
  --next-color: #fcd34d;
  --operator-resende: #5eead4;
  --operator-cidade: #fcd34d;
  --operator-agulhas: #f0abfc;
  --now-badge: #fca5a5;
  --accent: #fcd34d;
}

[data-theme="dark"] .city-btn.active,
[data-theme="dark"] .day-btn.active {
  background: #219e93;
  color: #000;
  border-color: #219e93;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  font-size: var(--text-base);
  line-height: var(--leading-normal);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  padding-bottom: 80px;
  transition: background .3s, color .3s;
}

header {
  background: var(--header-bg);
  color: #fff;
  padding: 20px 16px 16px;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: 0 4px 20px rgba(0,0,0,.15);
}

.header-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 4px;
}

h1 { font-size: var(--text-xl); font-weight: var(--weight-bold); letter-spacing: -.02em; line-height: var(--leading-tight); text-wrap: balance; }

.subtitle { font-size: var(--text-sm); opacity: .85; margin-bottom: 12px; font-weight: var(--weight-normal); }

.btn-icon {
  background: rgba(255,255,255,.15);
  border: none;
  color: #fff;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  font-size: var(--text-lg);
  cursor: pointer;
  transition: background .2s;
  display: flex;
  align-items: center;
  justify-content: center;
}
.btn-icon:hover { background: rgba(255,255,255,.25); }

main { max-width: 640px; margin: 0 auto; padding: 12px 12px 0; }

.offline-bar {
  background: var(--color-warning-bg);
  color: var(--color-warning);
  font-size: var(--text-caption);
  padding: 6px 12px;
  border-radius: var(--radius-sm);
  margin-bottom: 8px;
  text-align: center;
  font-weight: var(--weight-medium);
}
.offline-bar.hidden { display: none; }

.day-selector {
  display: flex;
  gap: 6px;
  margin-bottom: 12px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  padding-bottom: 4px;
}
.day-selector::-webkit-scrollbar { display: none; }

.day-btn {
  flex-shrink: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 7px 16px;
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  color: var(--text2);
  cursor: pointer;
  transition: all .2s;
  white-space: nowrap;
}
.day-btn:hover { border-color: var(--primary); color: var(--primary); }
.day-btn.active {
  background: #0b7a6f;
  color: #fff;
  border-color: #0b7a6f;
}

.next-bus-bar {
  background: var(--next-bg);
  border: 1px solid var(--accent);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  margin-bottom: 12px;
  display: flex;
  align-items: center;
  gap: 10px;
  animation: slideDown .3s ease;
}
@keyframes slideDown { from { opacity: 0; transform: translateY(-8px); } to { opacity: 1; transform: translateY(0); } }
.next-label {
  background: var(--accent);
  color: #fff;
  font-size: var(--text-caption);
  font-weight: var(--weight-bold);
  padding: 3px 8px;
  border-radius: 4px;
  letter-spacing: .05em;
}
#nextBusInfo { font-size: var(--text-sm); color: var(--next-color); font-weight: var(--weight-medium); }

.lines-container { display: flex; flex-direction: column; gap: 10px; }

.line-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
  transition: all .2s;
  cursor: pointer;
}
.line-card:hover { border-color: var(--primary); }
.line-card:active { transform: scale(.98); }

.line-header {
  padding: 14px 16px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  min-width: 0;
}
.line-code {
  background: var(--badge-bg);
  color: var(--badge-text);
  font-weight: var(--weight-bold);
  font-size: var(--text-sm);
  padding: 3px 10px;
  border-radius: 6px;
  flex-shrink: 0;
}
.line-name {
  flex: 1;
  font-size: var(--text-base);
  font-weight: var(--weight-medium);
  line-height: var(--leading-normal);
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.line-arrow { color: var(--text2); font-size: var(--text-sm); transition: transform .2s; }

.line-schedule-preview {
  padding: 0 16px 14px;
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}
.schedule-preview-item {
  font-size: var(--text-caption);
  color: var(--text2);
  background: var(--surface2);
  padding: 4px 10px;
  border-radius: 6px;
}

.hidden { display: none !important; }

/* Modal */
.modal {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}
.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,.5);
  animation: fadeIn .2s;
}
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
.modal-content {
  position: relative;
  background: var(--surface);
  border-radius: var(--radius) var(--radius) 0 0;
  width: 100%;
  max-width: 640px;
  max-height: 85vh;
  overflow-y: auto;
  animation: slideUp .3s ease;
  padding: 20px 16px 30px;
}
@keyframes slideUp { from { transform: translateY(100%); } to { transform: translateY(0); } }
.modal-close {
  position: absolute;
  top: 12px;
  right: 14px;
  background: var(--surface2);
  border: none;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  font-size: var(--text-lg);
  color: var(--text);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background .2s;
}
.modal-close:hover { background: var(--border); }

.modal-title {
  font-size: var(--text-lg);
  font-weight: var(--weight-bold);
  margin-bottom: 4px;
  padding-right: 40px;
  word-wrap: break-word;
  overflow-wrap: break-word;
}
.modal-code {
  display: inline-block;
  background: var(--badge-bg);
  color: var(--badge-text);
  font-weight: var(--weight-bold);
  font-size: var(--text-caption);
  padding: 2px 10px;
  border-radius: 6px;
  margin-bottom: 16px;
}
.modal-direction {
  font-size: var(--text-sm);
  color: var(--text2);
  margin-bottom: 16px;
  padding: 8px 12px;
  background: var(--surface2);
  border-radius: var(--radius-sm);
  font-weight: var(--weight-medium);
}

.schedule-section { margin-bottom: 20px; }
.schedule-section-title {
  font-size: var(--text-caption);
  font-weight: var(--weight-semibold);
  color: var(--text2);
  margin-bottom: 8px;
  text-transform: uppercase;
  letter-spacing: .06em;
}
.schedule-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(70px, 1fr));
  gap: 6px;
}
.schedule-time {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 6px 4px;
  text-align: center;
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  font-variant-numeric: tabular-nums;
  transition: all .15s;
}
.schedule-time.next-departure {
  background: var(--next-bg);
  border-color: var(--accent);
  color: var(--next-color);
  font-weight: var(--weight-bold);
  position: relative;
}
.schedule-time.next-departure::after {
  content: 'AGORA';
  position: absolute;
  top: -6px;
  right: -6px;
  background: var(--now-badge);
  color: #fff;
  font-size: var(--text-caption);
  font-weight: var(--weight-bold);
  padding: 1px 5px;
  border-radius: 4px;
}

footer {
  text-align: center;
  padding: 20px 16px;
  color: var(--text2);
  font-size: var(--text-caption);
  line-height: var(--leading-normal);
}
footer p { margin: 2px 0; }
.footer-small { margin-top: 4px; }
.pix-cta {
  background: none;
  border: 1px solid var(--accent);
  color: var(--accent);
  border-radius: 50px;
  padding: 4px 14px;
  font-size: var(--text-caption);
  cursor: pointer;
  transition: all .2s;
}
.pix-cta:hover {
  background: var(--accent);
  color: #fff;
}

.empty-state {
  text-align: center;
  padding: 40px 20px;
  color: var(--text2);
}
.empty-state .empty-icon { font-size: var(--text-2xl); margin-bottom: 12px; }
.empty-state p { font-size: var(--text-base); }

@media (min-width: 640px) {
  .modal-content { border-radius: var(--radius); margin-bottom: 40px; }
  main { padding: 16px 16px 0; }
}

@media (prefers-reduced-motion: reduce) {
  * {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}

.line-card:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 0;
  border-color: var(--primary);
}

.line-card { position: relative; }

/* Bottom Navigation */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: var(--surface);
  border-top: 1px solid var(--border);
  display: flex;
  z-index: 150;
  padding: 6px 0 env(safe-area-inset-bottom, 6px);
}
.nav-btn {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  background: none;
  border: none;
  padding: 6px 0;
  cursor: pointer;
  color: var(--text2);
  transition: color .2s;
}
.nav-btn.active { color: var(--primary); }
.nav-icon { font-size: 1.2rem; line-height: 1; }
.nav-label { font-size: var(--text-caption); font-weight: var(--weight-medium); }

.tab-content.hidden { display: none; }

.city-tabs{display:flex;gap:6px;margin-bottom:12px;overflow-x:auto;-webkit-overflow-scrolling:touch;padding-bottom:4px}
.city-tabs::-webkit-scrollbar{display:none}
.city-btn{flex-shrink:0;background:var(--surface);border:1px solid var(--border);border-radius:8px;padding:8px 16px;font-size:var(--text-sm);font-weight:var(--weight-medium);color:var(--text2);cursor:pointer;transition:all .2s;white-space:nowrap}
.city-btn:hover{border-color:var(--primary);color:var(--primary)}
.city-btn.active{background:#0b7a6f;color:#fff;border-color:#0b7a6f}
.operator-badge{font-size:var(--text-caption);color:var(--text2);background:var(--surface2);padding:3px 8px;border-radius:4px;flex-shrink:0;white-space:nowrap;font-weight:var(--weight-medium)}
