/* ==========================================================================
   bus.nlink.kr - 1-Tier Realtime Bus Tracker CSS
   Theme: Slate Minimal Monochrome & Sky Blue Accent
   Mobile-First (Optimized for Galaxy S24: 360px~384px)
   ========================================================================== */

:root {
  --bg-primary: #0b1120;
  --bg-secondary: #0f172a;
  --bg-card: #1e293b;
  --bg-card-hover: #334155;
  --bg-glass: rgba(30, 41, 59, 0.75);
  --bg-inset: rgba(0, 0, 0, 0.15);
  --border-color: rgba(255, 255, 255, 0.08);
  --border-subtle: rgba(255, 255, 255, 0.04);
  --border-focus: #38bdf8;
  
  --text-primary: #f8fafc;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;
  
  --accent-blue: #0284c7;
  --accent-sky: #38bdf8;
  --accent-emerald: #10b981;
  --accent-amber: #f59e0b;
  --accent-rose: #f43f5e;
  
  --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.2);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.3);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.4);
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-full: 9999px;
  
  --safe-bottom: env(safe-area-inset-bottom, 16px);
}

/* Light Mode Overrides (WCAG AA Compliant) */
[data-theme="light"] {
  --bg-primary: #f8fafc;
  --bg-secondary: #f1f5f9;
  --bg-card: #ffffff;
  --bg-card-hover: #f8fafc;
  --bg-glass: rgba(255, 255, 255, 0.85);
  --bg-inset: rgba(0, 0, 0, 0.04);
  --border-color: rgba(0, 0, 0, 0.1);
  --border-subtle: rgba(0, 0, 0, 0.05);
  --border-focus: #0284c7;
  
  --text-primary: #0f172a;
  --text-secondary: #334155;
  --text-muted: #64748b;
  
  --accent-sky: #0284c7; /* WCAG AA High Contrast */
  
  --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.08);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
}

/* 1. Global Reset & Touch Optimization (Mandatory Rule) */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Pretendard Variable", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background-color: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.5;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  overflow-x: hidden;
  
  /* Native App UX Rule */
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
}

/* Selectable elements */
input, textarea, [contenteditable="true"], .selectable, .selectable-text {
  -webkit-user-select: text;
  user-select: text;
}

/* App Container */
.app-container {
  width: 100%;
  max-width: 480px;
  min-width: 320px;
  padding: 0 14px 40px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

/* Header */
.app-header {
  position: sticky;
  top: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  background-color: var(--bg-glass);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border-color);
  margin: 0 -14px 4px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 6px;
  text-decoration: none;
  color: inherit;
  flex-shrink: 0;
}

.brand-icon {
  width: 26px;
  height: 26px;
  border-radius: var(--radius-sm);
}

.brand-title {
  font-size: 1.1rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--text-primary);
  display: flex;
  align-items: center;
  gap: 5px;
}

.brand-badge {
  font-size: 0.65rem;
  padding: 2px 6px;
  border-radius: var(--radius-full);
  background-color: rgba(56, 189, 248, 0.15);
  color: var(--accent-sky);
  font-weight: 600;
  border: 1px solid rgba(56, 189, 248, 0.3);
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

/* Galaxy S24 (360px) Header Optimization */
@media (max-width: 384px) {
  .app-header {
    padding: 8px 10px;
  }
  .brand-title {
    font-size: 1rem;
  }
  .btn-pill {
    padding: 4px 8px;
    font-size: 0.72rem;
  }
  .btn-icon {
    width: 28px;
    height: 28px;
    font-size: 0.85rem;
  }
}

/* Pill Buttons */
.btn-pill {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 5px 9px;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-primary);
  background-color: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-full);
  cursor: pointer;
  transition: all 0.2s ease;
  white-space: nowrap;
}

.btn-pill:hover, .btn-pill:active {
  background-color: var(--bg-card-hover);
  border-color: var(--border-focus);
}

.btn-pill-primary {
  background: linear-gradient(135deg, #0284c7, #0369a1);
  color: #ffffff;
  border: none;
}

.btn-icon {
  width: 30px;
  height: 30px;
  border-radius: var(--radius-full);
  background-color: var(--bg-card);
  border: 1px solid var(--border-color);
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.2s ease;
  flex-shrink: 0;
}

.btn-icon:hover, .btn-icon:active {
  color: var(--text-primary);
  border-color: var(--border-focus);
}

/* Section Common */
.section-title {
  font-size: 0.88rem;
  font-weight: 700;
  color: var(--text-secondary);
  letter-spacing: 0.02em;
  margin-bottom: 8px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.section-title .badge-count {
  font-size: 0.72rem;
  padding: 2px 7px;
  background-color: var(--bg-card);
  border-radius: var(--radius-full);
  color: var(--accent-sky);
}

/* Section 1: Favorites Widget (Primary Focus) */
.favorites-container {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.fav-card {
  background-color: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 13px 15px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  box-shadow: var(--shadow-sm);
  transition: transform 0.15s ease, border-color 0.15s ease;
  position: relative;
  overflow: hidden;
}

.fav-card:active {
  transform: scale(0.985);
}

.fav-card.verified, .fav-card.success {
  border-left: 4px solid var(--accent-emerald);
}

.fav-card.warning {
  border-left: 4px solid var(--accent-amber);
}

.fav-card.danger {
  border-left: 4px solid var(--accent-rose);
}

.fav-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.fav-route-badge {
  font-size: 1.1rem;
  font-weight: 800;
  color: #ffffff;
  background: linear-gradient(135deg, #0284c7, #0369a1);
  padding: 2px 9px;
  border-radius: var(--radius-sm);
  letter-spacing: -0.02em;
  flex-shrink: 0;
}

/* Flex Min-Width: 0 to enable text ellipsis (Mandatory Bugfix) */
.fav-station-info {
  display: flex;
  flex-direction: column;
  gap: 2px;
  flex: 1;
  min-width: 0;
  margin: 0 10px;
}

.fav-station-name {
  font-size: 0.94rem;
  font-weight: 700;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.fav-direction {
  font-size: 0.74rem;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.fav-eta-wrap {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  background-color: var(--bg-inset);
  border-radius: var(--radius-sm);
  padding: 7px 11px;
}

.fav-eta-time {
  font-size: 1.3rem;
  font-weight: 800;
  color: var(--accent-sky);
  letter-spacing: -0.03em;
}

.fav-eta-time.danger {
  color: var(--accent-rose);
  animation: pulse-danger 1.5s infinite;
}

@keyframes pulse-danger {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.6; }
}

.fav-stops {
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text-secondary);
}

.fav-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 0.74rem;
  color: var(--text-muted);
  border-top: 1px solid var(--border-subtle);
  padding-top: 7px;
}

.bus-meta-tag {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 0.7rem;
  padding: 2px 6px;
  border-radius: 4px;
  background-color: rgba(255, 255, 255, 0.05);
}

.bus-meta-tag.verified {
  color: var(--accent-emerald);
  background-color: rgba(16, 185, 129, 0.12);
}

.bus-meta-tag.unverified {
  color: var(--accent-amber);
  background-color: rgba(245, 158, 11, 0.12);
}

/* Empty Favorites State */
.fav-empty-card {
  background-color: var(--bg-card);
  border: 1px dashed var(--border-color);
  border-radius: var(--radius-md);
  padding: 20px 16px;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

.fav-empty-icon {
  font-size: 1.8rem;
  opacity: 0.8;
}

.fav-empty-text {
  font-size: 0.88rem;
  color: var(--text-secondary);
  line-height: 1.4;
}

/* Section 2: Search Bar */
.search-box-wrap {
  position: relative;
  width: 100%;
}

.search-input {
  width: 100%;
  height: 44px;
  padding: 0 40px 0 38px;
  font-size: 0.92rem;
  background-color: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-full);
  color: var(--text-primary);
  outline: none;
  transition: all 0.2s ease;
  box-shadow: var(--shadow-sm);
}

.search-input:focus {
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px rgba(56, 189, 248, 0.2);
}

.search-input::placeholder {
  color: var(--text-muted);
}

.search-icon-left {
  position: absolute;
  left: 13px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
  pointer-events: none;
}

.search-clear-btn {
  position: absolute;
  right: 12px;
  top: 50%;
  transform: translateY(-50%);
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 1.1rem;
  cursor: pointer;
  padding: 4px;
  display: none;
}

.search-results-dropdown {
  position: absolute;
  top: 50px;
  left: 0;
  right: 0;
  background-color: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  max-height: 320px;
  overflow-y: auto;
  z-index: 40;
  display: none;
}

.search-item {
  padding: 11px 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--border-subtle);
  cursor: pointer;
}

.search-item:hover, .search-item:active {
  background-color: var(--bg-card-hover);
}

/* Section 3: Nearby Stations Accordion List */
.station-list {
  display: flex;
  flex-direction: column;
  gap: 9px;
}

.station-card {
  background-color: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  overflow: hidden;
  transition: border-color 0.2s ease;
}

.station-header {
  padding: 13px 15px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  cursor: pointer;
}

.station-header:hover {
  background-color: rgba(255, 255, 255, 0.02);
}

.station-info {
  display: flex;
  flex-direction: column;
  gap: 2px;
  flex: 1;
  min-width: 0;
  margin-right: 10px;
}

.station-title-row {
  display: flex;
  align-items: center;
  gap: 7px;
  min-width: 0;
}

.station-name {
  font-size: 0.94rem;
  font-weight: 700;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.station-distance {
  font-size: 0.73rem;
  color: var(--accent-sky);
  font-weight: 600;
  flex-shrink: 0;
}

.station-sub {
  font-size: 0.73rem;
  color: var(--text-muted);
}

.chevron-icon {
  transition: transform 0.25s ease;
  color: var(--text-muted);
  flex-shrink: 0;
}

.station-card.open .chevron-icon {
  transform: rotate(180deg);
}

.station-body {
  display: none;
  padding: 0 15px 13px;
  border-top: 1px solid var(--border-subtle);
  background-color: var(--bg-inset);
}

.station-card.open .station-body {
  display: block;
}

/* Arrival Item inside Station */
.arrival-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 9px 0;
  border-bottom: 1px solid var(--border-subtle);
}

.arrival-row:last-child {
  border-bottom: none;
}

.arrival-bus-badge {
  font-size: 0.92rem;
  font-weight: 700;
  color: #ffffff;
  background-color: #0284c7;
  padding: 2px 7px;
  border-radius: 6px;
  min-width: 42px;
  text-align: center;
  flex-shrink: 0;
}

.arrival-center {
  flex: 1;
  min-width: 0;
  margin: 0 10px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.arrival-dir {
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--accent-sky);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.arrival-status-row {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 0.8rem;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.arrival-vehicle-tag {
  font-size: 0.7rem;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.arrival-time-col {
  text-align: right;
  flex-shrink: 0;
}

.arrival-time-main {
  font-size: 0.98rem;
  font-weight: 800;
  color: var(--accent-sky);
}

.arrival-fav-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 6px;
  margin-left: 5px;
  font-size: 1.05rem;
  border-radius: var(--radius-full);
  flex-shrink: 0;
}

.arrival-fav-btn.active {
  color: #fbbf24;
}

/* Info Box Safe Comment */
.info-card {
  background-color: rgba(2, 132, 199, 0.08);
  border: 1px solid rgba(56, 189, 248, 0.2);
  border-radius: var(--radius-md);
  padding: 11px 13px;
  display: flex;
  align-items: flex-start;
  gap: 9px;
  font-size: 0.8rem;
  color: var(--text-secondary);
  line-height: 1.45;
}

/* Modal Standard (Themed In-App Modal) */
.modal-overlay {
  position: fixed;
  inset: 0;
  background-color: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 14px;
}

.modal-overlay.active {
  display: flex;
}

.modal-content {
  width: 100%;
  max-width: 440px;
  max-height: 85vh;
  background-color: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  animation: modal-pop 0.2s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes modal-pop {
  from { opacity: 0; transform: scale(0.94); }
  to { opacity: 1; transform: scale(1); }
}

.modal-header {
  padding: 12px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--border-color);
}

.modal-title {
  font-size: 0.98rem;
  font-weight: 700;
  color: var(--text-primary);
}

.modal-close-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 1.25rem;
  cursor: pointer;
  padding: 4px;
}

.modal-body {
  padding: 15px 16px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 13px;
  font-size: 0.86rem;
  line-height: 1.55;
  color: var(--text-secondary);
}

.modal-footer {
  padding: 11px 16px;
  border-top: 1px solid var(--border-color);
  display: flex;
  justify-content: flex-end;
}

/* Tab Switching inside Legal Modal (Clean Border) */
.modal-tabs {
  display: flex;
  gap: 6px;
}

.modal-tab-btn {
  background: none;
  border: none;
  padding: 5px 10px;
  font-size: 0.84rem;
  font-weight: 600;
  color: var(--text-muted);
  border-radius: var(--radius-sm);
  cursor: pointer;
}

.modal-tab-btn.active {
  background-color: rgba(56, 189, 248, 0.15);
  color: var(--accent-sky);
}

/* Toast Message */
.toast-msg {
  position: fixed;
  bottom: calc(var(--safe-bottom) + 20px);
  left: 50%;
  transform: translateX(-50%) translateY(100px);
  background-color: var(--bg-card);
  color: var(--text-primary);
  border: 1px solid var(--border-focus);
  padding: 9px 16px;
  border-radius: var(--radius-full);
  font-size: 0.84rem;
  font-weight: 600;
  box-shadow: var(--shadow-lg);
  z-index: 200;
  opacity: 0;
  transition: all 0.25s ease;
  pointer-events: none;
  white-space: nowrap;
}

.toast-msg.show {
  transform: translateX(-50%) translateY(0);
  opacity: 1;
}

/* Footer */
.app-footer {
  margin-top: 20px;
  padding-top: 14px;
  border-top: 1px solid var(--border-color);
  text-align: center;
  font-size: 0.74rem;
  color: var(--text-muted);
  display: flex;
  flex-direction: column;
  gap: 7px;
}

.footer-links {
  display: flex;
  justify-content: center;
  gap: 12px;
}

.footer-link {
  color: var(--text-secondary);
  text-decoration: none;
  cursor: pointer;
}

.footer-link:hover {
  color: var(--accent-sky);
  text-decoration: underline;
}
