* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: Arial, sans-serif;
    line-height: 1.4;
    color: #333;
    background-color: #f4f4f4;
    min-width: 320px;
    font-size: 0.97rem;
}

header {
    background-color: #2c3e50;
    color: white;
    padding: 0.7rem;
    text-align: center;
    margin-bottom: 0.7rem;
    box-shadow: 0 2px 5px rgba(0,0,0,0.08);
}

header h1 {
    font-size: 1.5rem;
    margin-bottom: 0.2em;
}

main {
    max-width: 900px;
    margin: 0 auto;
    padding: 0.7rem;
    min-width: 320px;
}

footer {
    background-color: #2c3e50;
    color: white;
    text-align: center;
    padding: 0.7rem;
    margin-top: 1.5rem;
}

section {
    background-color: white;
    border-radius: 8px;
    box-shadow: 0 2px 6px rgba(0,0,0,0.10);
    padding: 1rem 1rem 0.7rem 1rem;
    margin-bottom: 1rem;
}

section {
    padding: 1rem 1rem 0.7rem 1rem;
    margin-bottom: 1rem;
}

h2 {
    margin-bottom: 0.3rem;
    color: #2c3e50;
    font-size: 1.1rem;
}

#inputs h2,
#results h2 {
    font-size: 1.1rem;
    margin-bottom: 0.3em;
}

.address-container {
    margin-bottom: 1rem;
}

.address-input {
    margin-bottom: 0.7rem;
    position: relative;
}

.address-input label {
    display: block;
    margin-bottom: 0.3rem;
    font-weight: bold;
    font-size: 0.98rem;
}

.address-input label {
    font-size: 0.98rem;
}

.address-input input {
    width: 100%;
    padding: 0.5rem;
    border: 1px solid #ddd;
    border-radius: 5px;
    font-size: 0.98rem;
    transition: border-color 0.2s;
}

.address-input input:focus {
    border-color: #3498db;
    outline: none;
    box-shadow: 0 0 5px rgba(52, 152, 219, 0.3);
}

.address-input input {
    padding: 0.5rem;
    font-size: 0.98rem;
}

.options-container {
    margin-bottom: 1rem;
    padding-top: 0.2rem;
}

.option {
    margin-bottom: 0.7rem;
}

.option label {
    display: block;
    margin-bottom: 0.3rem;
    font-weight: bold;
    font-size: 0.98rem;
}

.option label {
    font-size: 0.98rem;
}

.option select {
    width: 100%;
    padding: 0.5rem;
    border: 1px solid #ddd;
    border-radius: 5px;
    font-size: 0.98rem;
    background-color: white;
}

.btn {
    padding: 0.5rem 1.1rem;
    background-color: #3498db;
    color: white;
    border: none;
    border-radius: 5px;
    cursor: pointer;
    font-size: 0.95rem;
    font-weight: 600;
    transition: all 0.2s;
    min-width: 90px;
    box-shadow: 0 1px 2px rgba(0,0,0,0.08);
    margin: 0.3rem 0.3rem 0.3rem 0;
}

.btn:hover {
    background-color: #2980b9;
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(0,0,0,0.15);
}

.btn:active {
    transform: translateY(0);
    box-shadow: 0 1px 2px rgba(0,0,0,0.08);
}

.btn.primary {
    background-color: #2ecc71;
    font-size: 1rem;
    padding: 0.7rem 1.2rem;
    min-width: 120px;
    display: block;
    margin: 0.7rem auto 0.3rem auto;
}

.btn.primary:hover {
    background-color: #27ae60;
}

.btn:disabled, .btn[disabled] {
    background-color: #bfc9d1 !important;
    color: #eaeaea !important;
    cursor: not-allowed !important;
    box-shadow: none !important;
    opacity: 0.7;
}

#add-waypoint {
    margin-bottom: 1.5rem;
}

.addresses-header-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    min-height: 2em;
    margin-bottom: 0.5em;
    flex-wrap: wrap;
    gap: 0.5em;
}

.addresses-header-row > h2 {
    flex: 1 1 auto;
    min-width: 120px;
    margin-bottom: 0;
}

.google-contacts-btn {
    flex: 0 1 auto;
    min-width: 120px;
    width: auto;
    max-width: 100%;
    box-sizing: border-box;
}

.google-contacts-btn svg {
    width: 1.1em !important;
    height: 1.1em !important;
    min-width: 1.1em !important;
    min-height: 1.1em !important;
    margin-right: 0.3em;
    flex-shrink: 0;
}

.google-contacts-btn:hover {
    background: #2980b9;
    color: #fff;
    border-color: #2980b9;
}

.google-contacts-btn:hover svg {
    filter: brightness(0) invert(1);
}

#map-container {
    height: 320px;
    margin-top: 0.7rem;
    border-radius: 6px;
    overflow: hidden;
    box-shadow: 0 2px 6px rgba(0,0,0,0.10);
}

#map {
    width: 100%;
    height: 100%;
}

.route-calc-icon {
    vertical-align: middle;
    display: inline-block;
    width: 1.3em;
    height: 1.3em;
    margin-right: 0.3em;
}

.gmaps-icon {
    vertical-align: middle;
    display: inline-block;
    width: 1.1em;
    height: 1.1em;
    margin-right: 0.2em;
}

.route-calc-icon svg,
.gmaps-icon svg,
#inputs .google-contacts-btn svg,
.github-link-fixed svg {
    width: 1em !important;
    height: 1em !important;
    min-width: 1em !important;
    min-height: 1em !important;
    max-width: 1em !important;
    max-height: 1em !important;
    vertical-align: middle;
    display: inline-block;
}

.route-calc-icon,
.gmaps-icon {
    width: 1em;
    height: 1em;
    margin-right: 0.2em;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

#inputs .google-contacts-btn svg {
    margin-right: 0.2em;
}

@media (min-width: 768px) {
    #results {
        display: grid;
        grid-template-columns: 1fr 2fr;
        gap: 2rem;
    }
    .btn {
        display: inline-block;
    }
}

@media (max-width: 767px) {
    .btn {
        display: block;
        width: 100%;
        margin: 0.5rem 0;
    }
    main {
        padding: 0.3rem;
    }
    section {
        padding: 0.5rem 0.5rem 0.3rem 0.5rem;
    }
    #map-container {
        height: 180px;
    }
}

.remove-waypoint {
    background: none;
    border: none;
    color: #e74c3c;
    cursor: pointer;
    font-size: 1.1rem;
    padding: 0 0.3rem;
    margin-left: 0.5rem;
    transition: transform 0.2s;
}

.remove-waypoint:hover {
    transform: scale(1.2);
    color: #c0392b;
}

.route-summary {
    background-color: #f8f9fa;
    padding: 0.7rem;
    border-radius: 5px;
    margin-bottom: 0.7rem;
    font-size: 0.98rem;
    font-weight: bold;
    box-shadow: 0 1px 2px rgba(0,0,0,0.08);
}

.route-list ol {
    list-style-position: inside;
    padding-left: 0;
    counter-reset: route-counter -1;
}

.route-list li {
    padding: 0.4rem 0.3rem;
    list-style: none;
    position: relative;
    padding-left: 1.3rem;
    font-size: 0.97rem;
}

.route-list li:before {
    counter-increment: route-counter;
    content: counter(route-counter);
    position: absolute;
    left: 0;
    top: 50%;
    transform: translateY(-50%);
    background-color: #3498db;
    color: white;
    width: 1.1rem;
    height: 1.1rem;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
    line-height: 1.1rem;
    font-size: 1rem;
    text-align: center;
    padding-top: 0;
    padding-bottom: 0;
}

.route-list li:first-child:before {
    content: "S";
    background-color: #4CAF50;
}

.route-list li:first-child + li:before {
    counter-reset: route-counter -1;
}

.route-list li:last-child:before {
    content: "E";
    background-color: #F44336;
}

.route-list li:last-child {
    border-bottom: none;
}

.route-list li:not(:first-child):not(:last-child):before {
    background-color: #3498db;
}

.loading {
    display: inline-block;
    position: relative;
    width: 80px;
    height: 80px;
}

.loading:after {
    content: " ";
    display: block;
    border-radius: 50%;
    width: 0;
    height: 0;
    margin: 8px;
    box-sizing: border-box;
    border: 32px solid #3498db;
    border-color: #3498db transparent #3498db transparent;
    animation: loading 1.2s infinite;
}

.loading-text {
    margin-left: 8px;
}

@keyframes loading {
    0% {
        transform: rotate(0);
        animation-timing-function: cubic-bezier(0.55, 0.055, 0.675, 0.19);
    }
    50% {
        transform: rotate(180deg);
        animation-timing-function: cubic-bezier(0.215, 0.61, 0.355, 1);
    }
    100% {
        transform: rotate(360deg);
    }
}

.github-link-fixed {
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: 1000;
    color: #24292e;
}

.github-link-fixed svg {
    color: #000;
    fill: #000;
}

.text-decoration-none {
    text-decoration: none;
}

.route-buttons-row {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 0.5rem;
    margin-top: 1.2em;
    flex-wrap: wrap;
}
#gmaps-row {
    display: flex;
    justify-content: center;
    margin-bottom: 0.5em;
}
#route-storage-ui > div:first-child {
    display: flex;
    justify-content: center;
    gap: 0.5em;
}
#share-route-row {
    display: flex;
    justify-content: center;
    margin-bottom: 0.5em;
}
#route-storage-ui > div {
    display: flex;
    flex-direction: row;
    gap: 0.3rem;
    flex-wrap: nowrap;
    justify-content: center;
    align-items: center;
}
#route-storage-ui .btn {
    width: auto;
    min-width: 0;
    flex: 0 0 auto;
    white-space: nowrap;
    margin: 0;
}
@media (max-width: 700px) {
  .route-buttons-row {
    flex-direction: column;
    align-items: stretch;
    gap: 0.5rem;
  }
  .route-buttons-row > .btn,
  #route-storage-ui > div {
    width: 100%;
    display: flex;
    gap: 0.5rem;
    justify-content: center;
  }
  #route-storage-ui .btn {
    flex: 1 1 0;
    min-width: 0;
    width: 100%;
    margin: 0;
    text-align: center;
  }
}
@media (max-width: 600px) {
  #route-storage-ui {
    width: 100%;
  }
  #route-storage-ui > div {
    width: 100%;
  }
  #route-storage-ui .btn {
    width: 50%;
    flex: 1 1 0;
    min-width: 0;
    margin: 0;
  }
}

.custom-autocomplete-dropdown .autocomplete-item.selected {
  background: #eaf6ff;
  color: #2261a9;
  font-weight: bold;
  border-left: 4px solid #2261a9;
}

.waypoint-inline {
    display: flex;
    align-items: center;
    gap: 0.5em;
    margin-bottom: 0.5em;
}
.waypoint-number {
    font-weight: bold;
    min-width: 1.5em;
    text-align: right;
    color: #2c3e50;
}
.remove-waypoint {
    background: none;
    border: none;
    color: #c0392b;
    font-size: 1.2em;
    margin-left: 0.3em;
    cursor: pointer;
    padding: 0 0.3em;
    line-height: 1;
}
.waypoint-inline input.waypoint {
    width: 100%;
    padding: 0.5rem;
    border: 1px solid #ddd;
    border-radius: 5px;
    font-size: 0.98rem;
    transition: border-color 0.2s;
    background-color: white;
    margin-bottom: 0;
}
.waypoint-inline input.waypoint:focus {
    border-color: #3498db;
    outline: none;
    box-shadow: 0 0 5px rgba(52, 152, 219, 0.3);
}

/* Modal Styles */
.modal {
  display: none;
  position: fixed;
  z-index: 10000;
  left: 0;
  top: 0;
  width: 100vw;
  height: 100vh;
  background: rgba(0,0,0,0.35);
  align-items: center;
  justify-content: center;
}
.modal.show {
  display: flex;
}
.modal-content {
  background: #fff;
  border-radius: 10px;
  min-width: 320px;
  max-width: 90vw;
  padding: 2em 1.5em 1.5em 1.5em;
  box-shadow: 0 8px 32px rgba(0,0,0,0.18);
  position: relative;
}
.modal-close {
  position: absolute;
  top: 0.7em;
  right: 1em;
  background: none;
  border: none;
  font-size: 1.7em;
  color: #888;
  cursor: pointer;
}

.modal-form {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1em;
  width: 100%;
  max-width: 340px;
  margin: 0 auto;
  background: none;
  box-shadow: none;
  padding: 0;
}

.modal-label {
  font-weight: 600;
  width: 100%;
  text-align: left;
}

.modal-input {
  width: 100%;
  max-width: 100%;
  padding: 0.6em;
  border-radius: 6px;
  border: 1px solid #bfc9d1;
  font-size: 1.1em;
  box-sizing: border-box;
}

.modal-btn {
  width: 100%;
  max-width: 200px;
  margin-top: 0.5em;
  align-self: center;
  padding: 0.6em 1em;
  font-size: 1em;
  min-width: 90px;
}

.modal-route-list {
  display: flex;
  flex-direction: column;
  gap: 0.7em;
}

.modal-route-entry {
  position: relative;
  background: #f7fafd;
  border: 1px solid #e0e6ed;
  border-radius: 8px;
  box-shadow: 0 2px 8px rgba(44,62,80,0.04);
  padding: 1em 1.2em;
  display: flex;
  align-items: center;
  gap: 1em;
  transition: box-shadow 0.2s;
}

.modal-route-info {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 0.2em;
}

.modal-route-name {
  font-size: 1.13em;
  font-weight: 600;
  color: #2261a9;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.modal-route-date {
  color: #888;
  font-size: 0.98em;
  margin-top: 0.1em;
  text-align: right;
}

.modal-route-actions {
  display: flex;
  gap: 0.5em;
}

.modal-btn-delete {
  background: #e74c3c;
  color: #fff;
}

.modal-btn-load {
  background: #2ecc71;
  color: #fff;
}

@media (max-width: 600px) {
  .modal-content {
    min-width: unset;
    width: 99vw;
    max-width: 99vw;
    border-radius: 0.7em;
    padding: 0.7em 0.2em 0.7em 0.2em;
    max-height: 95vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
  }
  .modal-form {
    max-width: 99vw;
    padding: 0;
  }
  .modal-btn {
    font-size: 0.98em;
    padding: 0.5em 0.7em;
    min-width: 70px;
    max-width: 98vw;
  }
  .modal-route-entry {
    padding: 0.7em 0.5em;
    gap: 0.5em;
  }
  .google-contacts-btn {
    width: auto;
    min-width: 120px;
    justify-content: flex-start;
    height: 2em;
    padding: 0 0.8em;
    margin-top: 0;
    font-size: 0.97rem;
  }
  .addresses-header-row {
    flex-direction: row;
    align-items: center;
    gap: 0.5em;
  }
}
@media (max-width: 420px) {
  .addresses-header-row {
    flex-direction: column;
    align-items: stretch;
    gap: 0.5em;
  }
  .google-contacts-btn {
    width: 100%;
    min-width: unset;
    justify-content: center;
    margin-top: 0.5em;
  }
}

#route-storage-ui {
    width: 100%;
}
#route-storage-ui > div {
    display: flex;
    flex-direction: row;
    gap: 0.3rem;
    flex-wrap: nowrap;
    justify-content: center;
    align-items: center;
}
#route-storage-ui .btn {
    width: auto;
    min-width: 0;
    flex: 0 0 auto;
    white-space: nowrap;
    margin: 0;
}
@media (max-width: 600px) {
  #route-storage-ui {
    width: 100%;
  }
  #route-storage-ui > div {
    width: 100%;
  }
  #route-storage-ui .btn {
    width: 50%;
    flex: 1 1 0;
    min-width: 0;
    margin: 0;
  }
}

.address-input.end {
    margin-top: 1rem;
}

.icon-dropdown {
    font-family: 'Segoe UI Emoji', 'Segoe UI Symbol', Arial, sans-serif;
    font-size: 0.98rem;
    padding-left: 0.5rem;
    padding-right: 0.5rem;
    min-width: 180px;
    background-color: #fff;
    border: 1px solid #ddd;
    border-radius: 5px;
    margin-bottom: 0.5rem;
}

.icon-dropdown option {
    font-family: 'Segoe UI Emoji', 'Segoe UI Symbol', Arial, sans-serif;
    font-size: 0.98rem;
    padding-left: 0.5rem;
}

.icon-dropdown:focus {
    border-color: #3498db;
    outline: none;
    box-shadow: 0 0 5px rgba(52, 152, 219, 0.3);
}

.route-leg-info {
    font-size: 0.92em;
    color: #888;
    margin-left: 2.2em;
    margin-bottom: 0.1em;
    margin-top: -0.2em;
    display: block;
}

.autocomplete-item-contact {
  color: #2980b9;
  font-weight: bold;
}
.contact-badge {
  background: #eaf6ff;
  color: #2980b9;
  font-size: 0.85em;
  padding: 2px 6px;
  border-radius: 6px;
  margin-left: 8px;
}

.modal-message {
  padding: 1em 0;
  color: #888;
  text-align: center;
}

#import-google-contacts[disabled], #import-google-contacts.loaded {
  background: #eaf6ff;
  color: #2980b9;
  border: 1px solid #2980b9;
  cursor: default;
}