/* KM+ Rodovias - Web App (estilo nativo) */

:root {
  --bg: #0d2f32;
  --hero-bg: #123c39;
  --hero-border: #1e5852;
  --card-bg: #fffdf8;
  --card-border: #ddd2be;
  --input-border: #d8d2c5;
  --input-bg: #fffdf7;
  --list-bg: #f7f1e4;
  --list-border: #e5d9c4;
  --text-cream: #fff8eb;
  --text-green-light: #d6ead9;
  --text-green-muted: #8dc3bd;
  --text-green-bright: #8fe0cf;
  --text-dark: #123b39;
  --text-body: #4e5a57;
  --text-label: #7b6f5a;
  --text-sub: #5f6d69;
  --ribbon-bg: #d7f4ea;
  --ribbon-text: #12594f;
  --badge-bg: rgba(255,255,255,0.08);
  --badge-border: rgba(143, 224, 207, 0.22);
  --badge-label: #92c9bf;
  --warning-bg: #fff2df;
  --warning-border: #f0d0a4;
  --warning-text: #80522a;
  --error-bg: #ffe2dd;
  --error-border: #e49e91;
  --error-text: #852d21;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Display", "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text-dark);
  -webkit-text-size-adjust: 100%;
  -webkit-font-smoothing: antialiased;
}

/* --- Layout --- */
.app-container {
  max-width: 480px;
  margin: 0 auto;
  min-height: 100%;
  background: var(--bg);
  display: flex;
  flex-direction: column;
}

.app-scroll {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 16px;
  padding-top: calc(16px + env(safe-area-inset-top, 0px));
  padding-bottom: calc(16px + var(--safe-bottom));
  display: flex;
  flex-direction: column;
  gap: 14px;
}

/* --- Hero Card (KM Display) --- */
.hero-card {
  border-radius: 30px;
  padding: 18px;
  background: var(--hero-bg);
  border: 1px solid var(--hero-border);
  box-shadow: 0 10px 18px rgba(0,0,0,0.22);
}

.hero-top {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 14px;
}

.hero-logo {
  width: 58px;
  height: 58px;
  border-radius: 20px;
  border: 2px solid rgba(255,255,255,0.16);
  object-fit: cover;
}

.hero-logo-placeholder {
  width: 58px;
  height: 58px;
  border-radius: 20px;
  border: 2px solid rgba(255,255,255,0.16);
  background: rgba(255,255,255,0.06);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
  flex-shrink: 0;
}

.hero-copy {
  flex: 1;
  min-width: 0;
}

.hero-mode {
  color: var(--text-green-muted);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 1.1px;
  margin-bottom: 4px;
  font-weight: 700;
}

.hero-road-code {
  color: var(--text-green-bright);
  font-size: 16px;
  font-weight: 900;
  letter-spacing: 1px;
  margin-bottom: 3px;
}

.hero-road-name {
  color: var(--text-green-light);
  font-size: 14px;
  line-height: 19px;
}

/* KM Value */
.hero-km-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: nowrap;
}

.hero-km-left {
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
}

.hero-km {
  color: var(--text-cream);
  font-size: 54px;
  font-weight: 900;
  letter-spacing: -1.8px;
  line-height: 1;
  transition: opacity 0.3s;
  white-space: nowrap;
}

@media (max-width: 380px) {
  .hero-km {
    font-size: 46px;
    letter-spacing: -1.5px;
  }
}

.hero-km.stale {
  opacity: 0.55;
}

.hero-km-caption {
  color: #cfe6e1;
  font-size: 14px;
  margin-top: 2px;
}

/* Battery Toggle */
.battery-toggle {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  width: 64px;
  height: 64px;
  min-width: 64px;
  border-radius: 18px;
  background: rgba(255,255,255,0.07);
  border: 1px solid rgba(255,255,255,0.14);
  color: var(--text-cream);
  cursor: pointer;
  transition: background 0.2s, border-color 0.2s, color 0.2s, transform 0.1s;
  padding: 0;
  font-family: inherit;
  flex-shrink: 0;
  -webkit-appearance: none;
  -moz-appearance: none;
  appearance: none;
  -webkit-tap-highlight-color: transparent;
  box-shadow: none;
  outline: none;
}

.battery-toggle:active {
  transform: scale(0.94);
}

.battery-toggle.active {
  background: rgba(158, 218, 122, 0.22);
  border-color: rgba(158, 218, 122, 0.55);
  color: #b4e898;
}

.battery-icon {
  width: 26px;
  height: 26px;
  stroke-width: 2;
}

.battery-bolt {
  opacity: 0;
  transition: opacity 0.2s;
}

.battery-toggle.active .battery-bolt {
  opacity: 1;
}

.battery-label {
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.8px;
  text-transform: uppercase;
}

/* Ribbon (marker range) */
.hero-ribbon {
  margin-top: 18px;
  align-self: flex-start;
  display: inline-block;
  background: var(--ribbon-bg);
  border-radius: 999px;
  padding: 8px 14px;
}

.hero-ribbon-text {
  color: var(--ribbon-text);
  font-weight: 800;
  font-size: 13px;
}

/* Badge Row */
.hero-badge-row {
  margin-top: 16px;
  display: flex;
  gap: 10px;
}

.hero-badge {
  flex: 1;
  background: var(--badge-bg);
  border-radius: 16px;
  min-height: 72px;
  padding: 11px 14px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}

.hero-badge-action {
  border: 1px solid rgba(158, 218, 122, 0.5);
  background: rgba(158, 218, 122, 0.12);
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, transform 0.1s;
  flex-direction: row;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px 10px 14px;
  gap: 10px;
  font-family: inherit;
  -webkit-appearance: none;
  -moz-appearance: none;
  appearance: none;
  -webkit-tap-highlight-color: transparent;
  outline: none;
  text-align: left;
  color: inherit;
}

.hero-badge-action:active {
  background: rgba(158, 218, 122, 0.22);
  border-color: rgba(158, 218, 122, 0.7);
  transform: scale(0.98);
}

.hero-badge-info {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 2px;
}

.hero-badge-refresh-icon {
  width: 40px;
  height: 40px;
  border-radius: 12px;
  background: rgba(158, 218, 122, 0.25);
  border: 1px solid rgba(158, 218, 122, 0.45);
  color: #b4e898;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background 0.15s;
}

.hero-badge-refresh-icon svg {
  width: 22px;
  height: 22px;
}

.hero-badge-refresh-icon.spinning svg {
  animation: refresh-spin 0.8s linear infinite;
}

.hero-badge-action:active .hero-badge-refresh-icon {
  background: rgba(158, 218, 122, 0.4);
}

@keyframes refresh-spin {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}

.hero-badge-label {
  color: var(--badge-label);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  margin-bottom: 4px;
}

.hero-badge-value {
  color: #ffffff;
  font-size: 15px;
  line-height: 19px;
  font-weight: 800;
}

.hero-badge-hint {
  color: var(--badge-label);
  font-size: 11px;
  margin-top: 6px;
}

/* Centered state (loading / waiting) */
.hero-centered {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 26px 0;
  gap: 12px;
}

.hero-centered .state-text {
  color: var(--text-green-light);
  font-size: 15px;
  text-align: center;
}

.hero-centered .km-fallback {
  color: var(--text-cream);
  font-size: 28px;
  font-weight: 700;
}

.spinner-hero {
  width: 36px;
  height: 36px;
  border: 3px solid rgba(255,255,255,0.15);
  border-top-color: #74d3c5;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* --- Selector Card --- */
.selector-card {
  background: var(--card-bg);
  border-radius: 22px;
  padding: 16px;
  border: 1px solid var(--card-border);
}

.section-label {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--text-label);
  margin-bottom: 10px;
  font-weight: 700;
}

.selector-button {
  border: 1px solid var(--input-border);
  border-radius: 16px;
  padding: 12px 13px;
  background: var(--input-bg);
  display: flex;
  align-items: center;
  justify-content: space-between;
  cursor: pointer;
  transition: border-color 0.15s;
  width: 100%;
  font-family: inherit;
  text-align: left;
}

.selector-button:active {
  border-color: var(--text-dark);
}

.selector-button-copy {
  flex: 1;
  padding-right: 12px;
  min-width: 0;
}

.selector-button-code {
  color: var(--text-dark);
  font-size: 15px;
  font-weight: 800;
  margin-bottom: 2px;
}

.selector-button-name {
  color: var(--text-body);
  font-size: 12px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.selector-button-coverage {
  color: var(--text-label);
  font-size: 11px;
  margin-top: 4px;
  font-weight: 700;
}

.selector-button-arrow {
  color: var(--text-dark);
  font-size: 14px;
  font-weight: 800;
  flex-shrink: 0;
}

/* Dropdown list */
.selector-list {
  margin-top: 10px;
  max-height: 260px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  background: var(--list-bg);
  border: 1px solid var(--list-border);
  border-radius: 18px;
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.selector-option {
  border: 1px solid var(--input-border);
  border-radius: 16px;
  padding: 10px 13px;
  background: var(--input-bg);
  cursor: pointer;
  display: flex;
  align-items: flex-start;
  transition: all 0.12s;
}

.selector-option:active {
  transform: scale(0.98);
}

.selector-option.active {
  background: #113c3a;
  border-color: #113c3a;
}

.selector-option .opt-content {
  flex: 1;
  min-width: 0;
}

.selector-option .opt-code {
  color: var(--text-dark);
  font-size: 14px;
  font-weight: 800;
  margin-bottom: 2px;
}

.selector-option.active .opt-code {
  color: #f4efe2;
}

.selector-option .opt-name {
  color: var(--text-body);
  font-size: 12px;
}

.selector-option.active .opt-name {
  color: var(--text-green-light);
}

.selector-option .opt-coverage {
  color: var(--text-label);
  font-size: 11px;
  margin-top: 4px;
  font-weight: 700;
}

.selector-option.active .opt-coverage {
  color: #c9e6de;
}

.selector-option .opt-star {
  padding-left: 8px;
  padding-top: 2px;
  font-size: 18px;
  color: #c5b99a;
  cursor: pointer;
  flex-shrink: 0;
  background: none;
  border: none;
  font-family: inherit;
}

.selector-option .opt-star.starred {
  color: #d4a017;
}

/* --- Destination Search Card --- */
.destination-card {
  background: var(--card-bg);
  border-radius: 22px;
  padding: 16px;
  border: 1px solid var(--card-border);
}

.dest-input-row {
  display: flex;
  gap: 10px;
  margin-top: 14px;
}

.dest-input-group {
  flex: 1;
}

.dest-input-label {
  color: var(--text-label);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.9px;
  font-weight: 700;
  margin-bottom: 8px;
}

.dest-input {
  width: 100%;
  border: 1px solid var(--input-border);
  border-radius: 18px;
  padding: 14px;
  background: var(--input-bg);
  font-size: 24px;
  font-weight: 800;
  color: var(--text-dark);
  letter-spacing: 0.5px;
  font-family: inherit;
  -moz-appearance: textfield;
}

.dest-input::-webkit-outer-spin-button,
.dest-input::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

.dest-input::placeholder {
  color: #7f8c88;
}

.dest-hint {
  color: var(--text-sub);
  font-size: 12px;
  line-height: 18px;
  margin-top: 10px;
}

.dest-notice {
  color: var(--warning-text);
  font-size: 12px;
  line-height: 18px;
  margin-top: 8px;
  padding: 8px 10px;
  border-radius: 12px;
  background: var(--warning-bg);
  border: 1px solid var(--warning-border);
}

.dest-error {
  color: var(--error-text);
  font-size: 13px;
  line-height: 18px;
  margin-top: 8px;
  padding: 8px 10px;
  border-radius: 12px;
  background: var(--error-bg);
  border: 1px solid var(--error-border);
}

.dest-button {
  margin-top: 14px;
  width: 100%;
  min-height: 50px;
  border-radius: 18px;
  border: none;
  background: var(--text-dark);
  color: #ffffff;
  font-size: 15px;
  font-weight: 800;
  font-family: inherit;
  cursor: pointer;
  transition: opacity 0.15s;
}

.dest-button:active {
  opacity: 0.7;
}

/* --- Home Button --- */
.home-button {
  align-self: center;
  display: flex;
  align-items: center;
  gap: 8px;
  text-align: center;
  padding: 12px 22px;
  border-radius: 999px;
  background: rgba(255,255,255,0.08);
  border: 1px solid rgba(255,255,255,0.14);
  cursor: pointer;
  text-decoration: none;
  transition: background 0.15s;
}

.home-button:active {
  background: rgba(255,255,255,0.14);
}

.home-button-icon {
  color: var(--text-green-light);
  font-size: 18px;
  font-weight: 800;
}

.home-button-text {
  color: var(--text-green-light);
  font-size: 13px;
  font-weight: 800;
}

/* --- Warning / Error boxes --- */
.warning-box {
  background: var(--warning-bg);
  border-radius: 18px;
  padding: 16px;
  border: 1px solid var(--warning-border);
}

.warning-box .warning-title {
  color: var(--warning-text);
  font-weight: 800;
  margin-bottom: 4px;
  font-size: 14px;
}

.warning-box .warning-text {
  color: var(--warning-text);
  font-size: 13px;
  line-height: 20px;
}

.error-box {
  background: var(--error-bg);
  border-radius: 18px;
  padding: 16px;
  border: 1px solid var(--error-border);
}

.error-box .error-title {
  color: var(--error-text);
  font-weight: 800;
  margin-bottom: 4px;
}

.error-box .error-text {
  color: var(--error-text);
  line-height: 21px;
  font-size: 13px;
}

/* --- Legal Button --- */
.legal-button {
  align-self: center;
  text-align: center;
  padding: 10px 18px;
  border-radius: 999px;
  background: rgba(255,255,255,0.08);
  border: 1px solid rgba(255,255,255,0.14);
  cursor: pointer;
  font-family: inherit;
}

.legal-button:active {
  background: rgba(255,255,255,0.14);
}

.legal-button-label {
  color: var(--text-green-light);
  font-size: 13px;
  font-weight: 800;
  margin-bottom: 2px;
}

.legal-button-sub {
  color: #98beb8;
  font-size: 11px;
}

/* --- Loading screen --- */
.loading-screen {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 40px 20px;
  gap: 16px;
}

.loading-screen .progress-text {
  color: var(--text-green-light);
  font-size: 13px;
  font-weight: 500;
}

.loading-screen .progress-bar-bg {
  width: 200px;
  height: 3px;
  background: rgba(255,255,255,0.12);
  border-radius: 2px;
  overflow: hidden;
}

.loading-screen .progress-bar-fill {
  height: 100%;
  background: #74d3c5;
  border-radius: 2px;
  transition: width 0.3s ease;
}

/* --- Dropdown Overlay (bottom sheet) --- */
.dropdown-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(5, 17, 19, 0.5);
  z-index: 100;
}

.dropdown-overlay.open {
  display: flex;
  align-items: flex-end;
  justify-content: center;
  animation: fadeIn 0.15s ease-out;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

.dropdown-panel {
  width: 100%;
  max-width: 480px;
  max-height: 80vh;
  background: var(--card-bg);
  border-top-left-radius: 28px;
  border-top-right-radius: 28px;
  padding-top: 18px;
  display: flex;
  flex-direction: column;
  animation: slideUp 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes slideUp {
  from { transform: translateY(100%); }
  to { transform: translateY(0); }
}

.dropdown-header {
  padding: 0 20px 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid #ebe1cf;
}

.dropdown-title {
  color: var(--text-dark);
  font-size: 20px;
  font-weight: 900;
}

.dropdown-close {
  padding: 8px 12px;
  border-radius: 999px;
  background: #e6f2ee;
  border: none;
  cursor: pointer;
  font-family: inherit;
  color: var(--ribbon-text);
  font-weight: 800;
  font-size: 14px;
}

.dropdown-list {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 12px;
  padding-bottom: calc(12px + var(--safe-bottom));
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.dropdown-option {
  border: 1px solid var(--input-border);
  border-radius: 16px;
  padding: 10px 13px;
  background: var(--input-bg);
  cursor: pointer;
  transition: all 0.12s;
}

.dropdown-option:active {
  transform: scale(0.98);
}

.dropdown-option.active {
  background: #113c3a;
  border-color: #113c3a;
}

.dropdown-option .d-code {
  font-size: 14px;
  font-weight: 800;
  color: var(--text-dark);
  margin-bottom: 2px;
}

.dropdown-option.active .d-code {
  color: #f4efe2;
}

.dropdown-option .d-name {
  font-size: 12px;
  color: var(--text-body);
}

.dropdown-option.active .d-name {
  color: var(--text-green-light);
}

.dropdown-option .d-coverage {
  font-size: 11px;
  color: var(--text-label);
  margin-top: 4px;
  font-weight: 700;
}

.dropdown-option.active .d-coverage {
  color: #c9e6de;
}

/* --- Responsive desktop border --- */
@media (min-width: 481px) {
  .app-container {
    border-left: 1px solid rgba(255,255,255,0.08);
    border-right: 1px solid rgba(255,255,255,0.08);
    box-shadow: 0 0 60px rgba(0,0,0,0.4);
  }
}

/* --- Utility --- */
.hidden {
  display: none !important;
}
