:root {
  /* Bangkok palette */
  --bg: #e7e9f1;
  --bg-elev: #dfe1e9;
  --bg-card: #ffffff;
  --border: #cfcdcb;
  --text: #464d2c;
  --text-dim: #a8a8a2;
  --text-faint: #cfcdcb;
  --gold: #c2a25b;
  --gold-glow: #ffb94d22;
  --teal: #005842;
  --rose: #d35b17;
  --green: #00714c;
  --saffron: #ffb94d;
  --mono: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, monospace;
  --serif: 'Instrument Serif', 'Times New Roman', Georgia, serif;
  --sans: -apple-system, BlinkMacSystemFont, 'Segoe UI', Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }

html { overflow-x: hidden; }

body {
  margin: 0;
  overflow-x: hidden;
  background: var(--bg);
  background-attachment: fixed;
  color: var(--text);
  font-family: var(--sans);
  font-size: 14px;
  line-height: 1.5;
  min-height: 100vh;
}

a { color: var(--gold); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ── Header ──────────────────────────────────────────── */

header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1.5rem 2rem 1rem;
  max-width: 1400px;
  margin: 0 auto;
  border-bottom: 1px solid var(--border);
}

.logo { display: flex; align-items: baseline; gap: 0.75rem; }
.logo .plane {
  font-size: 1.5rem;
  color: var(--gold);
  transform: rotate(-15deg);
  display: inline-block;
}
.logo h1 {
  font-family: var(--serif);
  font-weight: 400;
  font-size: 2.25rem;
  margin: 0;
  letter-spacing: -0.02em;
}
.logo h1 em {
  font-style: italic;
  color: var(--gold);
}

.status {
  display: flex;
  align-items: center;
  gap: 1rem;
  font-family: var(--mono);
  font-size: 0.8rem;
}
.dim { color: var(--text-dim); }
.faint { color: var(--text-faint); }

button {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text);
  padding: 0.5rem 1rem;
  font-family: var(--mono);
  font-size: 0.8rem;
  cursor: pointer;
  border-radius: 4px;
  transition: all 0.15s;
}
button:hover:not(:disabled) {
  border-color: var(--gold);
  color: var(--gold);
}
button:disabled {
  opacity: 0.6;
  cursor: not-allowed;
  pointer-events: none;
}
button.active {
  background: var(--gold);
  color: var(--bg);
  border-color: var(--gold);
  font-weight: 600;
}

/* ── Tabs ───────────────────────────────────────────── */

.tabs {
  max-width: 1400px;
  margin: 0 auto;
  padding: 0.5rem 2rem;
  display: flex;
  gap: 0.25rem;
  border-bottom: 1px solid var(--border);
  overflow-x: auto;
}
.tabs button {
  border: none;
  background: transparent;
  padding: 0.75rem 1.25rem;
  border-radius: 0;
  border-bottom: 2px solid transparent;
  font-family: var(--sans);
  font-size: 0.9rem;
}
.tabs button.active {
  background: transparent;
  color: var(--gold);
  border-bottom-color: var(--gold);
  font-weight: 600;
}

main {
  max-width: 1400px;
  margin: 0 auto;
  padding: 2rem;
  width: 100%;
}

.tab { display: none; }
.tab.active { display: block; }

h2 {
  font-family: var(--serif);
  font-weight: 400;
  font-size: 1.5rem;
  margin: 0 0 1rem;
  letter-spacing: -0.01em;
}

/* ── Overview grid ───────────────────────────────────── */

#trips-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 1.25rem;
}

.trip-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 1.5rem;
  position: relative;
  transition: border-color 0.15s, box-shadow 0.15s;
  box-shadow: 0 1px 3px rgba(0,0,0,0.06);
}
.trip-card:hover {
  border-color: var(--gold);
  box-shadow: 0 4px 12px rgba(0,0,0,0.1);
  cursor: pointer;
}
.trip-card.no-data { opacity: 0.6; }

.trip-card .name {
  font-family: var(--serif);
  font-size: 1.25rem;
  margin-bottom: 0.25rem;
}
.trip-card .dates {
  font-family: var(--mono);
  font-size: 0.75rem;
  color: var(--text-dim);
  margin-bottom: 1rem;
}

.trip-card .price-main {
  font-family: var(--mono);
  font-size: 2.5rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  margin-bottom: 0.25rem;
}
.trip-card .price-main.good { color: var(--green); }
.trip-card .price-main.bad { color: var(--rose); }
.trip-card .price-main.none { color: var(--text-faint); font-size: 1.5rem; }
.trip-card .price-main .currency {
  font-size: 1.25rem;
  color: var(--text-dim);
  margin-left: 0.15rem;
}

.trip-card .price-stats {
  font-family: var(--mono);
  font-size: 0.75rem;
  color: var(--text-dim);
  display: flex;
  gap: 1rem;
  margin-top: 0.5rem;
  flex-wrap: wrap;
}
.trip-card .stat-label { color: var(--text-faint); }

.trip-card .threshold {
  margin-top: 1rem;
  padding-top: 1rem;
  border-top: 1px dashed var(--border);
  font-family: var(--mono);
  font-size: 0.75rem;
  display: flex;
  justify-content: space-between;
}
.trip-card .threshold .target { color: var(--gold); }

/* ── Trip detail ────────────────────────────────────── */

.trip-selector {
  margin-bottom: 2rem;
}
.trip-selector label {
  font-family: var(--mono);
  font-size: 0.8rem;
  color: var(--text-dim);
  margin-right: 0.5rem;
}
.trip-selector select {
  background: var(--bg-card);
  color: var(--text);
  border: 1px solid var(--border);
  padding: 0.5rem 0.75rem;
  font-family: var(--mono);
  font-size: 0.9rem;
  border-radius: 4px;
  min-width: 220px;
}

.trip-detail {
  display: grid;
  grid-template-columns: 1fr;
  gap: 2rem;
}
@media (min-width: 1024px) {
  .trip-detail { grid-template-columns: 1.4fr 1fr; }
}

.trip-chart-wrap {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 1.5rem;
  box-shadow: 0 1px 3px rgba(0,0,0,0.06);
}
.trip-chart-wrap canvas {
  max-height: 360px;
}

.trip-breakdown {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 1.5rem;
  box-shadow: 0 1px 3px rgba(0,0,0,0.06);
}

/* ── Tables ─────────────────────────────────────────── */

table {
  width: 100%;
  border-collapse: collapse;
  font-family: var(--mono);
  font-size: 0.8rem;
}
th {
  text-align: left;
  font-weight: 500;
  color: var(--text-dim);
  padding: 0.5rem 0.5rem;
  border-bottom: 1px solid var(--border);
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
td {
  padding: 0.6rem 0.5rem;
  border-bottom: 1px solid var(--border);
}
tbody tr:hover { background: var(--bg-elev); }
.price-cell { color: var(--gold); font-weight: 600; }
.best-row .price-cell { color: var(--green); }
.best-row td:first-child::before {
  content: "★ ";
  color: var(--gold);
}

/* ── Alerts list ────────────────────────────────────── */

#alerts-list {
  display: grid;
  gap: 1rem;
}
.alert-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-left: 3px solid var(--green);
  border-radius: 6px;
  padding: 1rem 1.25rem;
}
.alert-card.rise { border-left-color: var(--rose); }
.alert-card.threshold { border-left-color: var(--gold); box-shadow: 0 0 30px var(--gold-glow); }

.alert-header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 0.5rem;
}
.alert-header .kind {
  font-family: var(--mono);
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-dim);
}
.alert-header .trip-name { font-family: var(--serif); font-size: 1.15rem; }
.alert-header .price {
  font-family: var(--mono);
  font-size: 1.3rem;
  font-weight: 700;
  color: var(--gold);
}
.alert-meta {
  font-family: var(--mono);
  font-size: 0.75rem;
  color: var(--text-dim);
}


/* ── Intro ──────────────────────────────────────────── */

.intro {
  max-width: 1400px;
  margin: 0 auto;
  padding: 0.75rem 2rem;
  font-family: var(--mono);
  font-size: 0.75rem;
  color: var(--text-dim);
  line-height: 1.6;
}
@media (max-width: 768px) {
  .intro { padding: 0.5rem 0.75rem; font-size: 0.65rem; }
}

/* ── Infos grid ─────────────────────────────────────── */

.infos-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.25rem;
}
@media (max-width: 768px) {
  .infos-grid { grid-template-columns: 1fr; }
}

.info-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 1.5rem;
  box-shadow: 0 1px 3px rgba(0,0,0,0.06);
}
.info-card .chart-wrap {
  position: relative;
  height: 220px;
}
.info-card canvas {
  max-height: 220px;
}

.weather-now, .fx-now {
  font-family: var(--mono);
  font-size: 0.85rem;
  color: var(--text-dim);
  margin-bottom: 1rem;
  display: flex;
  gap: 1.5rem;
  flex-wrap: wrap;
}
.weather-now .temp-big, .fx-now .rate-big {
  font-size: 1.8rem;
  font-weight: 700;
  color: var(--text);
}

/* ── Tables responsive ──────────────────────────────── */

.table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

/* ── Responsive ─────────────────────────────────────── */

@media (max-width: 768px) {
  header {
    padding: 1rem;
    flex-direction: column;
    align-items: flex-start;
    gap: 0.75rem;
  }
  .status {
    width: 100%;
    justify-content: space-between;
    flex-wrap: wrap;
  }
  #last-run {
    font-size: 0.7rem;
    word-break: break-word;
    flex: 1;
    min-width: 0;
  }

  main { padding: 0.75rem; }

  .tabs {
    padding: 0 0.5rem;
    gap: 0;
    -webkit-overflow-scrolling: touch;
  }
  .tabs button {
    padding: 0.6rem 0.75rem;
    font-size: 0.8rem;
    white-space: nowrap;
    flex-shrink: 0;
  }

  .logo h1 { font-size: 1.5rem; }

  #trips-grid {
    grid-template-columns: 1fr;
    gap: 0.75rem;
  }
  .trip-card {
    padding: 1rem;
    overflow: hidden;
  }
  .trip-card .name { font-size: 1.1rem; }
  .trip-card .dates { font-size: 0.65rem; word-break: break-all; }
  .trip-card .price-main { font-size: 2rem; }
  .trip-card .price-stats {
    gap: 0.4rem 0.75rem;
    font-size: 0.7rem;
  }
  .trip-card .threshold { font-size: 0.7rem; }

  .trip-selector select {
    width: 100%;
    min-width: unset;
    font-size: 0.8rem;
  }

  .trip-detail { gap: 1rem; }
  .trip-chart-wrap, .trip-breakdown {
    padding: 0.75rem;
    overflow: hidden;
  }
  .trip-chart-wrap canvas { max-height: 250px; }

  table { font-size: 0.7rem; }
  th, td { padding: 0.4rem 0.25rem; }
  th { font-size: 0.6rem; }

  .alert-header { flex-direction: column; gap: 0.25rem; }
  .alert-header .price { font-size: 1.1rem; }
  .alert-header .kind { font-size: 0.6rem; }
  .alert-card { padding: 0.75rem; }
  .alert-meta { font-size: 0.65rem; word-break: break-word; }

  h2 { font-size: 1.25rem; }
}

@media (max-width: 380px) {
  .logo h1 { font-size: 1.25rem; }
  .trip-card .price-main { font-size: 1.75rem; }
  .tabs button { padding: 0.5rem 0.6rem; font-size: 0.75rem; }
  .trip-card .price-stats { font-size: 0.65rem; }
}
