:root {
  --paper: #FBF6EA;
  --sand: #F3EAD7;
  --card: #FFFDF6;
  --ink: #26251F;
  --muted: #8A8171;
  --teal: #0E5E54;
  --teal-2: #15776B;
  --gold: #E8A13D;
  --gold-soft: #F2C879;
  --line: #E4D9C2;
  --danger: #B3492F;
  --shadow: 0 2px 10px rgba(38, 37, 31, .07);
}
@media (prefers-color-scheme: dark) {
  :root {
    --paper: #131B19;
    --sand: #0E1513;
    --card: #1B2523;
    --ink: #EFE7D3;
    --muted: #9AA396;
    --teal: #3FA08F;
    --teal-2: #2C7A6D;
    --gold: #E8A13D;
    --gold-soft: #8A6420;
    --line: #2C3833;
    --shadow: 0 2px 10px rgba(0, 0, 0, .35);
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--paper);
  color: var(--ink);
  font-family: 'Be Vietnam Pro', system-ui, sans-serif;
  font-size: 15px;
  line-height: 1.5;
}
.hidden { display: none !important; }
[hidden] { display: none !important; }
.mono { font-family: 'Space Mono', monospace; }

/* ---------- màn khoá / bìa hộ chiếu ---------- */
.login {
  position: fixed; inset: 0; z-index: 50;
  display: flex; align-items: center; justify-content: center;
  background: var(--teal);
  padding: 24px;
}
.passport-cover { width: min(360px, 92vw); }
.cover-frame {
  border: 3px double var(--gold-soft);
  border-radius: 14px;
  padding: 44px 28px 36px;
  text-align: center;
  color: #F7EFD9;
}
.cover-crest { font-size: 42px; margin-bottom: 10px; }
.cover-title {
  font-family: 'Fraunces', serif;
  font-size: 34px; letter-spacing: .35em; margin: 0 0 6px;
  text-indent: .35em;
}
.cover-sub {
  font-family: 'Space Mono', monospace;
  font-size: 11px; letter-spacing: .18em; opacity: .8; margin: 0 0 34px;
}
.login input {
  width: 100%; padding: 12px 14px; border-radius: 8px;
  border: 1px solid rgba(247, 239, 217, .4);
  background: rgba(255, 255, 255, .08); color: #F7EFD9;
  font-size: 16px; text-align: center; outline: none;
}
.login input::placeholder { color: rgba(247, 239, 217, .55); }
.login button {
  width: 100%; margin-top: 12px; padding: 12px;
  border: none; border-radius: 8px; cursor: pointer;
  background: var(--gold); color: #3A2A0C;
  font-family: 'Be Vietnam Pro', sans-serif; font-weight: 600; font-size: 15px;
}
.login-err { color: #FFC9B5; font-size: 13px; margin: 10px 0 0; }

/* ---------- khung app ---------- */
.app { min-height: 100dvh; display: flex; flex-direction: column; }
.top {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 16px;
  background: var(--teal); color: #F7EFD9;
  box-shadow: var(--shadow);
}
.brand { display: flex; align-items: center; gap: 8px; }
.brand-mark { color: var(--gold-soft); }
.brand-name { font-family: 'Fraunces', serif; font-size: 20px; font-weight: 700; letter-spacing: .04em; }
.top-actions { display: flex; gap: 6px; }
button.ghost {
  background: transparent; border: 1px solid rgba(247, 239, 217, .35);
  color: #F7EFD9; border-radius: 7px; padding: 5px 10px; cursor: pointer;
  font-family: 'Space Mono', monospace; font-size: 13px;
}

main { flex: 1; width: 100%; max-width: 860px; margin: 0 auto; padding: 16px 16px 110px; }

.section-title {
  font-family: 'Fraunces', serif; font-size: 19px; font-weight: 700;
  margin: 26px 0 10px; color: var(--teal);
}

/* ---------- stats ---------- */
.stats {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-top: 4px;
}
@media (min-width: 640px) { .stats { grid-template-columns: repeat(6, 1fr); } }
.stat {
  background: var(--card); border: 1px solid var(--line); border-radius: 10px;
  padding: 12px 8px 10px; text-align: center; box-shadow: var(--shadow);
}
.stat b {
  display: block; font-family: 'Space Mono', monospace; font-size: 20px;
  color: var(--teal); letter-spacing: -.02em;
}
.stat span { font-size: 11px; color: var(--muted); letter-spacing: .04em; }

/* ---------- stamps ---------- */
.stamps { display: flex; flex-wrap: wrap; gap: 12px; }
.stamp {
  border: 2px dashed var(--gold);
  color: var(--gold);
  border-radius: 50% 45% 52% 48% / 48% 52% 45% 55%;
  padding: 14px 18px; text-align: center; min-width: 96px;
  background: transparent;
}
.stamp .flag { font-size: 20px; display: block; }
.stamp .cname { font-size: 11px; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; display: block; margin-top: 2px; }
.stamp .meta { font-family: 'Space Mono', monospace; font-size: 10px; opacity: .8; display: block; }
.stamps-empty, .list-empty { color: var(--muted); font-size: 14px; }

/* ---------- flight list ---------- */
.year-h {
  font-family: 'Space Mono', monospace; font-size: 13px; color: var(--muted);
  margin: 18px 0 8px; letter-spacing: .12em;
}
.flight-card {
  background: var(--card); border: 1px solid var(--line); border-radius: 12px;
  margin-bottom: 10px; box-shadow: var(--shadow);
}
.fc-head {
  display: flex; align-items: center; gap: 14px;
  padding: 12px 14px; cursor: pointer;
}
.flight-card.open { border-color: var(--gold); }
.fc-date {
  font-family: 'Space Mono', monospace; text-align: center; min-width: 44px;
  color: var(--teal);
}
.fc-date b { display: block; font-size: 18px; line-height: 1.1; }
.fc-date span { font-size: 10px; text-transform: uppercase; letter-spacing: .1em; }
.fc-main { flex: 1; min-width: 0; }
.fc-route { font-family: 'Space Mono', monospace; font-weight: 700; font-size: 16px; }
.fc-route .arrow { color: var(--gold); }
.fc-cities { font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.fc-meta { font-size: 12px; color: var(--muted); }
.fc-meta .chip {
  display: inline-block; background: var(--sand); border-radius: 5px;
  padding: 0 6px; margin-right: 6px; font-family: 'Space Mono', monospace; font-size: 11px;
  color: var(--ink);
}
.fc-side { text-align: right; }
.fc-km { font-family: 'Space Mono', monospace; font-size: 12px; color: var(--muted); white-space: nowrap; }
.fc-actions { margin-top: 4px; white-space: nowrap; }
.fc-actions button {
  background: none; border: none; cursor: pointer; font-size: 14px;
  color: var(--muted); padding: 2px 5px;
}
.fc-actions button:hover { color: var(--teal); }
.fc-actions button.arm {
  background: var(--danger); color: #fff; border-radius: 5px;
  font-size: 11px; font-weight: 600; padding: 3px 7px;
}
button.danger.arm { background: var(--danger); color: #fff; }

/* ---------- nhật ký + ảnh trong card ---------- */
.fc-detail { border-top: 1px dashed var(--line); padding: 12px 14px 14px; }
.diary {
  width: 100%; min-height: 88px; resize: vertical;
  padding: 10px 12px; border-radius: 8px;
  border: 1px solid var(--line); background: var(--paper); color: var(--ink);
  font-family: inherit; font-size: 14px; line-height: 1.6; outline: none;
}
.diary:focus { border-color: var(--teal-2); }
.diary-row { display: flex; align-items: center; gap: 10px; margin: 8px 0 12px; }
button.sm { padding: 7px 14px; font-size: 13px; }
.photo-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
@media (min-width: 640px) { .photo-grid { grid-template-columns: repeat(5, 1fr); } }
.photo-item { position: relative; aspect-ratio: 1; border-radius: 8px; overflow: hidden; }
.photo-item img {
  width: 100%; height: 100%; object-fit: cover; display: block; cursor: zoom-in;
  background: var(--sand);
}
.ph-del {
  position: absolute; top: 4px; right: 4px;
  width: 22px; height: 22px; border: none; border-radius: 50%;
  background: rgba(0, 0, 0, .45); color: #fff; font-size: 11px; cursor: pointer;
  line-height: 1;
}
.ph-del.arm { width: auto; border-radius: 5px; padding: 0 7px; background: var(--danger); font-weight: 600; }
.photo-add {
  aspect-ratio: 1; border: 2px dashed var(--line); border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  font-size: 26px; color: var(--muted); cursor: pointer;
}
.photo-add:hover { border-color: var(--gold); color: var(--gold); }

/* ---------- share ---------- */
.share-badge {
  font-family: 'Space Mono', monospace; font-size: 9px; letter-spacing: .1em;
  background: rgba(247, 239, 217, .14); border: 1px solid rgba(247, 239, 217, .35);
  padding: 2px 8px; border-radius: 10px; margin-left: 10px; vertical-align: middle;
}
.share-panel {
  position: absolute; top: 50px; right: 12px; z-index: 40;
  background: var(--card); color: var(--ink);
  border: 1px solid var(--line); border-radius: 10px;
  padding: 12px 14px; box-shadow: var(--shadow); min-width: 270px;
}
.share-line { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.share-line label { display: flex; align-items: center; gap: 7px; font-size: 13px; cursor: pointer; }
.share-panel button.ghost { border-color: var(--line); color: var(--teal); }
.share-panel .hint { word-break: break-all; margin-top: 6px; }
.share-row { margin-top: 12px; display: flex; align-items: center; gap: 10px; font-size: 13px; }
.share-row label { display: flex; align-items: center; gap: 7px; cursor: pointer; }
.share-row button.ghost { border-color: var(--line); color: var(--teal); font-size: 12px; }
.live-row { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; flex-wrap: wrap; }
.live-ext { color: var(--muted); font-size: 12px; text-decoration: none; border-bottom: 1px dashed var(--muted); }
.live-ext:hover { color: var(--teal); }
.live-btn { border-color: var(--teal-2) !important; color: var(--teal) !important; }
.live-btn.on { background: var(--teal); color: #F7EFD9 !important; }
.diary-read {
  white-space: pre-wrap; background: var(--paper); border: 1px solid var(--line);
  border-radius: 8px; padding: 10px 12px; font-size: 14px; line-height: 1.6; margin-bottom: 12px;
}
body.share #logout-btn, body.share #share-btn, body.share #fab,
body.share #add-sec, body.share #import-sec { display: none; }
body.share .fc-head { cursor: default; }
body.share-flight .stats, body.share-flight #stamps,
body.share-flight h2[data-i18n="stampsTitle"], body.share-flight h2[data-i18n="logTitle"] { display: none; }

/* ---------- lightbox ---------- */
.lightbox {
  position: fixed; inset: 0; z-index: 80;
  background: rgba(10, 14, 13, .9);
  display: flex; align-items: center; justify-content: center; gap: 4px;
}
.lightbox img { max-width: 90vw; max-height: 88vh; border-radius: 6px; }
.lb-x {
  position: absolute; top: 14px; right: 16px;
  background: none; border: none; color: #fff; font-size: 22px; cursor: pointer;
}
.lb-nav {
  background: none; border: none; color: #fff; font-size: 46px;
  cursor: pointer; padding: 0 10px; user-select: none;
}

/* ---------- map ---------- */
.map-wrap {
  position: relative; border: 1px solid var(--line); border-radius: 12px;
  overflow: hidden; box-shadow: var(--shadow);
}
#map { width: 100%; height: 320px; }
@media (min-width: 640px) { #map { height: 440px; } }
.map-badge {
  position: absolute; top: 10px; left: 10px; z-index: 5;
  background: var(--card); border: 1px solid var(--line); border-radius: 8px;
  padding: 6px 12px; font-family: 'Space Mono', monospace; font-size: 12px;
  box-shadow: var(--shadow);
}

/* ---------- form ---------- */
.card {
  background: var(--card); border: 1px solid var(--line); border-radius: 12px;
  padding: 18px; box-shadow: var(--shadow);
}
.form label { display: block; margin-bottom: 12px; }
.form label > span {
  display: block; font-size: 12px; font-weight: 600; color: var(--muted);
  margin-bottom: 4px; letter-spacing: .03em;
}
.form input, .form textarea {
  width: 100%; padding: 9px 11px; border-radius: 8px;
  border: 1px solid var(--line); background: var(--paper); color: var(--ink);
  font-size: 15px; font-family: inherit; outline: none;
}
.form input:focus, .form textarea:focus { border-color: var(--teal-2); }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.no-row { display: flex; gap: 8px; }
.no-row input { flex: 1; min-width: 0; }
button.lookup {
  border: 1px solid var(--teal-2); color: var(--teal); background: none;
  border-radius: 8px; padding: 0 12px; cursor: pointer; font-family: inherit;
  font-size: 13px; white-space: nowrap;
}
button.lookup:hover { background: var(--sand); }
button.lookup:disabled { opacity: .5; cursor: wait; }
.hint { color: var(--muted); font-size: 11px; display: block; min-height: 14px; margin-top: 3px; }
.est { font-family: 'Space Mono', monospace; font-size: 13px; color: var(--teal); min-height: 18px; }
.form-actions { display: flex; gap: 10px; margin-top: 4px; }
button.primary {
  background: var(--teal); color: #F7EFD9; border: none; border-radius: 8px;
  padding: 11px 20px; font-size: 15px; font-weight: 600; cursor: pointer;
  font-family: inherit;
}
button.primary:hover { background: var(--teal-2); }
button.danger {
  background: none; border: 1px solid var(--danger); color: var(--danger);
  border-radius: 8px; padding: 11px 16px; cursor: pointer; font-family: inherit;
}
#view-add button.ghost { border-color: var(--line); color: var(--muted); }

/* autocomplete */
.ac { position: relative; }
.ac-list {
  position: absolute; left: 0; right: 0; z-index: 30;
  background: var(--card); border: 1px solid var(--line); border-radius: 8px;
  box-shadow: var(--shadow); max-height: 240px; overflow-y: auto;
}
.ac-item { padding: 8px 11px; cursor: pointer; font-size: 13px; }
.ac-item:hover, .ac-item.sel { background: var(--sand); }
.ac-item b { font-family: 'Space Mono', monospace; color: var(--teal); }
.ac-item small { color: var(--muted); }

/* ---------- import TripIt ---------- */
.imp-top { display: flex; gap: 14px; align-items: flex-end; flex-wrap: wrap; margin-bottom: 8px; }
.imp-home span {
  display: block; font-size: 12px; font-weight: 600; color: var(--muted); margin-bottom: 4px;
}
.imp-home input {
  width: 72px; padding: 9px 11px; border-radius: 8px; text-transform: uppercase;
  border: 1px solid var(--line); background: var(--paper); color: var(--ink); font-size: 15px;
}
.drop {
  flex: 1; min-width: 220px;
  border: 2px dashed var(--line); border-radius: 10px;
  padding: 16px; text-align: center; color: var(--muted); font-size: 13px;
}
.drop.over { border-color: var(--gold); color: var(--gold); }
.drop button.ghost { border-color: var(--line); color: var(--teal); cursor: pointer; margin-left: 4px; }

.imp-row {
  display: grid; grid-template-columns: 24px 130px 64px 20px 64px 88px 1fr; gap: 6px;
  align-items: center; padding: 6px 0; border-bottom: 1px dashed var(--line);
  font-size: 13px;
}
.imp-row input { padding: 5px 7px; font-size: 13px; border: 1px solid var(--line); border-radius: 6px; background: var(--paper); color: var(--ink); width: 100%; }
.imp-row .arrow { text-align: center; color: var(--gold); }
.imp-row .imp-note { color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.imp-row .badge {
  display: inline-block; font-size: 10px; padding: 1px 6px; border-radius: 4px;
  background: var(--sand); color: var(--danger); margin-left: 6px;
}
.imp-cities { grid-column: 2 / 8; font-size: 11px; color: var(--muted); padding-bottom: 2px; }
.imp-row.off input, .imp-row.off .imp-note { opacity: .45; }
@media (max-width: 640px) {
  .imp-row { grid-template-columns: 24px 108px 56px 14px 56px 1fr; }
  .imp-row .imp-no { display: none; }
}

/* ---------- nút thêm chuyến nổi ---------- */
#fab {
  position: fixed; right: 20px; bottom: max(20px, env(safe-area-inset-bottom)); z-index: 20;
  width: 54px; height: 54px; border-radius: 50%;
  background: var(--teal); color: #F7EFD9; border: none; cursor: pointer;
  font-size: 24px; line-height: 1;
  box-shadow: 0 4px 14px rgba(14, 94, 84, .4);
}
#fab:hover { background: var(--teal-2); }

/* ---------- toast ---------- */
.toast {
  position: fixed; bottom: 28px; left: 50%; transform: translateX(-50%); z-index: 60;
  background: var(--teal); color: #F7EFD9;
  border-radius: 20px; padding: 9px 20px; font-size: 14px;
  box-shadow: var(--shadow);
}
