:root {
  --bg: #faf7f2;
  --surface: #ffffff;
  --border: #e8e1d6;
  --text: #2b2620;
  --text-dim: #7a7266;
  --accent: #c1622f;
  --accent-dim: #f3e2d5;
  --safe: #1a7f4e;
  --safe-bg: #e6f4ec;
  --warn: #b8860b;
  --warn-bg: #fbf1d8;
  --danger: #c0392b;
  --danger-bg: #fbe4e0;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #1b1815;
    --surface: #24211d;
    --border: #3a352c;
    --text: #f1ece2;
    --text-dim: #a99f8e;
    --accent: #e08a54;
    --accent-dim: #3d2a1c;
    --safe: #4ade8c;
    --safe-bg: #163527;
    --warn: #e0b84a;
    --warn-bg: #3a2f10;
    --danger: #e0796a;
    --danger-bg: #3a1c17;
  }
}
:root[data-theme="dark"] {
  --bg: #1b1815; --surface: #24211d; --border: #3a352c; --text: #f1ece2; --text-dim: #a99f8e;
  --accent: #e08a54; --accent-dim: #3d2a1c; --safe: #4ade8c; --safe-bg: #163527;
  --warn: #e0b84a; --warn-bg: #3a2f10; --danger: #e0796a; --danger-bg: #3a1c17;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Inter", -apple-system, BlinkMacSystemFont, sans-serif;
  min-height: 100vh;
}
h1, h2, h3, .brand { font-family: "Fraunces", Georgia, serif; }

.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 32px; border-bottom: 1px solid var(--border); background: var(--surface);
  position: sticky; top: 0; z-index: 10;
}
.brand { font-size: 20px; font-weight: 600; cursor: pointer; color: var(--accent); }
nav { display: flex; gap: 8px; }
nav button, .btn {
  font-family: inherit; font-size: 14px; font-weight: 600; padding: 9px 16px;
  border-radius: 999px; border: 1px solid var(--border); background: var(--surface);
  color: var(--text); cursor: pointer; transition: all .15s;
}
nav button:hover, .btn:hover { border-color: var(--accent); color: var(--accent); }
.btn-primary { background: var(--accent); color: #fff; border-color: var(--accent); }
.btn-primary:hover { opacity: .9; color: #fff; }

#app { max-width: 1100px; margin: 0 auto; padding: 32px; }

.hero { margin-bottom: 32px; }
.hero h1 { font-size: 32px; margin: 0 0 8px; text-wrap: balance; }
.hero p { color: var(--text-dim); font-size: 15px; margin: 0; }

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 16px; }
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: 14px;
  padding: 0; transition: transform .15s, border-color .15s; overflow: hidden;
}
.card:hover { border-color: var(--accent); transform: translateY(-2px); }
.card-main { padding: 18px; cursor: pointer; }
.card h3 { margin: 0 0 4px; font-size: 18px; }
.card .meta { color: var(--text-dim); font-size: 13px; }
.card-selected { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.select-toggle {
  width: 100%; border: none; border-top: 1px solid var(--border); background: var(--bg);
  color: var(--text-dim); padding: 8px 12px; font-size: 13px; font-weight: 600; cursor: pointer;
  font-family: inherit;
}
.select-toggle:hover { color: var(--accent); }
.card-selected .select-toggle { color: var(--accent); background: var(--accent-dim); }

.search-row { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 20px; }
.search-row input {
  font-family: inherit; padding: 10px 14px; border-radius: 10px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); font-size: 14px; flex: 1; min-width: 220px;
}
.search-row input:focus { outline: none; border-color: var(--accent); }
.search-hint { color: var(--text-dim); font-size: 13px; margin: 0 0 12px; }

.itinerary-panel {
  background: var(--accent-dim); border: 1px solid var(--accent); border-radius: 12px;
  padding: 14px 18px; margin-bottom: 20px;
}
.itinerary-panel h4 { margin: 0 0 8px; font-size: 14px; text-transform: uppercase; letter-spacing: .04em; }
.itin-origin { font-size: 14px; margin-bottom: 8px; color: var(--text); }
.itin-chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  display: inline-flex; align-items: center; gap: 6px; background: var(--surface);
  border: 1px solid var(--border); border-radius: 999px; padding: 6px 8px 6px 14px; font-size: 13px;
}
.chip-remove {
  border: none; background: none; color: var(--text-dim); cursor: pointer; font-size: 16px;
  line-height: 1; padding: 2px 4px; border-radius: 50%;
}
.chip-remove:hover { color: var(--accent); background: var(--accent-dim); }

.section { margin-bottom: 28px; }
.section h2 { font-size: 20px; margin: 0 0 12px; display: flex; align-items: center; gap: 8px; }
.section-body {
  background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 20px;
}
.tag-row { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 10px; }
.tag {
  font-size: 12px; font-weight: 600; padding: 4px 10px; border-radius: 999px;
  background: var(--accent-dim); color: var(--accent);
}
.pill { font-size: 12px; font-weight: 700; padding: 3px 10px; border-radius: 999px; }
.pill-safe { background: var(--safe-bg); color: var(--safe); }
.pill-warn { background: var(--warn-bg); color: var(--warn); }
.pill-danger { background: var(--danger-bg); color: var(--danger); }

.advisory-row {
  display: flex; justify-content: space-between; align-items: center;
  padding: 10px 0; border-bottom: 1px solid var(--border);
}
.advisory-row:last-child { border-bottom: none; }

table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 10px 8px; border-bottom: 1px solid var(--border); }
th { color: var(--text-dim); font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: .04em; }
tr:last-child td { border-bottom: none; }

.bullet-list { margin: 0; padding-left: 18px; line-height: 1.7; }
.empty-note { color: var(--text-dim); font-style: italic; font-size: 14px; }

.summary-box {
  background: var(--accent-dim); border-radius: 12px; padding: 18px; margin-bottom: 24px;
  font-size: 15px; line-height: 1.6;
}
.summary-box .provider-tag { display: block; margin-top: 10px; font-size: 11px; color: var(--text-dim); font-style: italic; }
.provenance-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-top: 10px; }
.provenance-row .provider-tag { margin-top: 0; }
.refresh-btn {
  border: 1px solid var(--border); background: var(--surface); color: var(--text-dim);
  font-size: 11px; padding: 4px 10px; border-radius: 999px; cursor: pointer; font-family: inherit;
  white-space: nowrap;
}
.refresh-btn:hover { color: var(--accent); border-color: var(--accent); }
.modal-provenance-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-top: 4px; }


.form-row { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 20px; }
.form-row input, .form-row select {
  font-family: inherit; padding: 9px 12px; border-radius: 8px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); font-size: 14px;
}

#chat-fab {
  position: fixed; bottom: 24px; right: 24px; width: 56px; height: 56px; border-radius: 50%;
  background: var(--accent); color: #fff; border: none; font-size: 22px; cursor: pointer;
  box-shadow: 0 4px 16px rgba(0,0,0,.2); z-index: 20;
}
#chat-panel {
  position: fixed; bottom: 92px; right: 24px; width: 340px; max-height: 480px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 16px;
  box-shadow: 0 8px 32px rgba(0,0,0,.25); display: flex; flex-direction: column; z-index: 20; overflow: hidden;
}
#chat-panel[hidden] { display: none; }
.chat-header {
  display: flex; justify-content: space-between; align-items: center; padding: 12px 16px;
  background: var(--accent); color: #fff; font-weight: 600; font-size: 14px;
}
.chat-header button { background: none; border: none; color: #fff; font-size: 20px; cursor: pointer; }
#chat-messages { flex: 1; overflow-y: auto; padding: 12px 16px; font-size: 14px; display: flex; flex-direction: column; gap: 10px; }
.chat-msg { padding: 8px 12px; border-radius: 10px; max-width: 85%; line-height: 1.5; }
.chat-msg.user { align-self: flex-end; background: var(--accent-dim); color: var(--text); }
.chat-msg.assistant { align-self: flex-start; background: var(--bg); border: 1px solid var(--border); }
#chat-form { display: flex; border-top: 1px solid var(--border); }
#chat-input { flex: 1; border: none; padding: 12px; font-family: inherit; font-size: 14px; background: var(--surface); color: var(--text); }
#chat-input:focus { outline: none; }
#chat-form button { border: none; background: var(--accent); color: #fff; padding: 0 16px; cursor: pointer; font-weight: 600; }

.loading { color: var(--text-dim); padding: 40px; text-align: center; }

.tag-clickable { cursor: pointer; }
.tag-clickable:hover { background: var(--accent); color: #fff; }
.clickable-li { cursor: pointer; }
.clickable-li:hover { color: var(--accent); text-decoration: underline; }

.modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,.5); display: flex;
  align-items: center; justify-content: center; z-index: 50; padding: 20px;
}
.modal-overlay[hidden] { display: none; }
.modal-box {
  background: var(--surface); border-radius: 16px; max-width: 480px; width: 100%;
  max-height: 80vh; overflow-y: auto; box-shadow: 0 12px 48px rgba(0,0,0,.3);
}
.modal-header {
  display: flex; justify-content: space-between; align-items: center; padding: 16px 20px;
  border-bottom: 1px solid var(--border); font-weight: 700; font-size: 16px; position: sticky; top: 0;
  background: var(--surface);
}
.modal-close { border: none; background: none; font-size: 22px; cursor: pointer; color: var(--text-dim); }
.modal-close:hover { color: var(--accent); }
#modal-body { padding: 20px; }
#modal-body p { line-height: 1.6; margin: 0 0 12px; }
.modal-provenance { font-size: 12px; color: var(--text-dim); font-style: italic; }
.modal-links { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 12px; }
.modal-links a {
  color: var(--accent); text-decoration: none; font-size: 13px; font-weight: 600;
  border: 1px solid var(--accent); border-radius: 999px; padding: 6px 14px;
}
.modal-links a:hover { background: var(--accent); color: #fff; }
