:root {
  --bg: #ffffff;
  --card: #ffffff;
  --muted: #6b6b6b;
  --text: #111111;
  --primary: #111111;
  --primary-600: #000000;
  --danger: #c93a2e;
  --ok: #0e8b44;
  --border: #e6e6e6;
  --tone-green: #eef8f1;
  --tone-red: #fff1f1;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: "Avenir Next", Avenir, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

.app-header {
  padding: 28px 20px 16px;
  text-align: center;
}
.app-header h1 {
  margin: 0;
  font-weight: 600;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  font-family: inherit;
}
.app-header .sub { color: var(--muted); margin-top: 6px; font-size: 13px; }

.container {
  max-width: 1100px;
  margin: 0 auto;
  padding: 0 20px 40px;
}

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 0;
  padding: 24px;
  margin-bottom: 20px;
}

.grid { display: grid; gap: 12px; }
.grid.two { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid.three { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid.four { grid-template-columns: repeat(4, minmax(0, 1fr)); }
@media (max-width: 900px) {
  .grid.four { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 640px) {
  .grid.two, .grid.three, .grid.four { grid-template-columns: 1fr; }
}

fieldset { border: 1px solid var(--border); border-radius: 0; padding: 16px; }
legend { color: var(--muted); padding: 0 6px; letter-spacing: 0.06em; text-transform: uppercase; font-size: 12px; font-family: inherit; }

.field label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 6px; }
.field input, .field select {
  width: 100%;
  padding: 12px 12px;
  background: #fff;
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 0;
  outline: none;
}
.country-picker {
  position: relative;
}
.country-picker select { position: absolute; width: 1px; height: 1px; opacity: 0; pointer-events: none; }
.country-display { padding: 12px; border: 1px solid var(--border); background: #fff; cursor: pointer; }
.country-dropdown {
  position: absolute;
  z-index: 10;
  left: 0; right: 0;
  margin-top: 4px;
  background: #fff;
  border: 1px solid var(--border);
  max-height: 260px;
  overflow: auto;
  display: none;
}
.country-dropdown.open { display: block; }
.country-search { padding: 10px 12px; border-bottom: 1px solid var(--border); }
.country-search input { width: 100%; padding: 10px 12px; border: 1px solid var(--border); background: #fff; }
.country-group { padding: 8px 12px; font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; }
.country-item { display: flex; align-items: center; gap: 10px; padding: 8px 12px; cursor: pointer; }
.country-item:hover { background: #f5f5f5; }
.flag { width: 18px; height: 12px; border: 1px solid #ddd; background-size: cover; background-position: center; }
.field input:focus, .field select:focus { border-color: var(--primary); box-shadow: 0 0 0 2px rgba(17,17,17,0.08); }
.field small.error { color: var(--danger); display: block; min-height: 16px; margin-top: 6px; }

.derived { display: flex; gap: 16px; color: var(--muted); margin-top: 10px; font-size: 14px; }

.actions { display: flex; gap: 10px; margin-top: 14px; }
.btn {
  appearance: none;
  border: 1px solid var(--text);
  background: transparent;
  color: var(--text);
  padding: 12px 16px;
  border-radius: 0;
  cursor: pointer;
}
.btn.primary, .btn-primary { background: var(--primary); border-color: var(--primary-600); color: #ffffff; }
.btn.primary:hover, .btn-primary:hover { background: var(--primary-600); color: #ffffff; }
.btn:hover { filter: none; background: #161616; color: #fff; }

.results { display: grid; gap: 14px; }
.results-legend { display: flex; gap: 14px; align-items: center; padding: 6px 0; border-bottom: 1px solid var(--border); }
.results-legend .legend-item { display: flex; align-items: center; gap: 8px; color: var(--muted); }
.results-legend img { width: 18px; height: 18px; object-fit: contain; display: block; }
.results-section { display: grid; gap: 10px; padding: 10px; }
.results-section.economy { background: var(--tone-green); border-left: 3px solid var(--ok); }
.results-section.express { background: var(--tone-red); border-left: 3px solid var(--danger); }
.section-title { text-transform: uppercase; letter-spacing: .12em; font-size: 12px; color: var(--text); font-weight: 700; }
.result {
  display: grid;
  grid-template-columns: 48px 1fr auto;
  gap: 12px;
  align-items: center;
  padding: 14px 12px;
  border: 1px solid var(--border);
  border-radius: 0;
  background: #fafafa;
}
.logo {
  width: 40px; height: 40px; display: grid; place-items: center; border: 1px solid var(--border); background: #fff; font-weight: 700; font-size: 12px;
}
.logo img { max-width: 32px; max-height: 28px; object-fit: contain; display: block; }
.badge { font-size: 12px; padding: 4px 10px; border-radius: 999px; background: #f2f2f2; color: var(--muted); border: 1px solid var(--border); }
.price { font-weight: 700; text-align: right; }
.eta-strong { font-size: 12px; color: var(--muted); text-align: right; }
.eta { color: var(--muted); font-size: 13px; }

.app-footer { color: var(--muted); font-size: 12px; text-align: center; padding: 24px; }

.templates { display: grid; gap: 10px; }
.templates .group { display: grid; grid-template-columns: 120px 1fr; gap: 10px; align-items: center; }
.templates .label { color: var(--muted); }
.templates .btns { display: flex; gap: 8px; flex-wrap: wrap; }

.chips { display: flex; gap: 8px; margin-bottom: 10px; flex-wrap: wrap; }
.chip { border: 1px solid var(--border); padding: 6px 12px; border-radius: 999px; color: var(--text); cursor: pointer; user-select: none; background: #fff; }
.chip:hover { background: #111; color: #fff; border-color: #111; }
.chip.active { background: #111; color: #fff; border-color: #111; }

/* Modal */
.modal { position: fixed; inset: 0; background: rgba(0,0,0,0.35); display: none; align-items: center; justify-content: center; }
.modal.open { display: flex; }
.modal-content { width: min(1000px, 92vw); background: #fff; border: 1px solid var(--border); }
.modal-header { display: flex; align-items: center; justify-content: space-between; padding: 14px 16px; border-bottom: 1px solid var(--border); }
.modal-header .title { letter-spacing: .12em; text-transform: uppercase; font-weight: 600; }
.modal-toolbar { padding: 10px 16px; border-bottom: 1px solid var(--border); }
.modal-toolbar input { width: 100%; padding: 10px 12px; border: 1px solid var(--border); }
.table-wrap { max-height: 60vh; overflow: auto; }
#templateListView, #templateFormView { padding: 16px; }
#templateFormView .field { margin-bottom: 16px; }
.table { width: 100%; border-collapse: collapse; table-layout: fixed; }
.table thead th { text-align: left; font-size: 12px; color: var(--muted); padding: 10px 12px; border-bottom: 1px solid var(--border); text-transform: uppercase; letter-spacing: .06em; }
.table tbody td { padding: 10px 12px; border-bottom: 1px solid var(--border); vertical-align: top; }
.table tbody td:last-child { white-space: nowrap; width: 140px; }
.table tbody td:first-child { font-weight: 600; }
#templateTable thead th:nth-child(1) { width: 20%; }
#templateTable thead th:nth-child(2) { width: 12%; }
#templateTable thead th:nth-child(3) { width: 14%; }
#templateTable thead th:nth-child(4) { width: 14%; }
#templateTable thead th:nth-child(5) { width: 12%; }
#templateTable thead th:nth-child(6) { width: 14%; }
#templateTable thead th:nth-child(7) { width: 140px; }

#bookTable thead th:nth-child(1) { width: 14%; }
#bookTable thead th:nth-child(2) { width: 16%; }
#bookTable thead th:nth-child(3) { width: 20%; }
#bookTable thead th:nth-child(4) { width: 12%; }
#bookTable thead th:nth-child(5) { width: 10%; }
#bookTable thead th:nth-child(6) { width: 11%; }
#bookTable thead th:nth-child(7) { width: 17%; min-width: 180px; }

/* Error and Success messages */
.message-box { margin-top: 16px; padding: 16px; border-radius: 4px; animation: slideIn 0.3s ease; }
@keyframes slideIn { from { opacity: 0; transform: translateY(-10px); } to { opacity: 1; transform: translateY(0); } }


