/* TravelTrek V2 — base styles */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --color-bg:       #f5f5f5;
  --color-surface:  #ffffff;
  --color-primary:  #1a73e8;
  --color-text:     #202124;
  --color-muted:    #5f6368;
  --color-border:   #dadce0;
  --color-hover:    #f1f3f4;
  --radius:         8px;
  --shadow:         0 1px 3px rgba(0,0,0,.12), 0 1px 2px rgba(0,0,0,.08);
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--color-bg);
  color: var(--color-text);
  font-size: 16px;
  line-height: 1.5;
}

/* Header */
.site-header {
  background: var(--color-primary);
  padding: 0 1.5rem;
  height: 56px;
  display: flex;
  align-items: center;
  gap: 1rem;
  box-shadow: var(--shadow);
}
.site-title {
  color: #fff;
  font-size: 1.2rem;
  font-weight: 600;
  text-decoration: none;
  letter-spacing: .01em;
  flex: 1;
}
.header-right {
  display: flex;
  align-items: center;
  gap: .75rem;
}
.header-user {
  color: rgba(255,255,255,.85);
  font-size: .875rem;
}
.header-logout {
  background: none;
  border: 1px solid rgba(255,255,255,.4);
  color: #fff;
  border-radius: 4px;
  padding: .2rem .6rem;
  font-size: .8rem;
  cursor: pointer;
}
.header-logout:hover { background: rgba(255,255,255,.15); }
.header-nav-link {
  color: rgba(255,255,255,.85);
  font-size: .875rem;
  text-decoration: none;
  padding: .2rem .5rem;
  border-radius: 4px;
}
.header-nav-link:hover { background: rgba(255,255,255,.15); color: #fff; }

/* Admin mode toggle */
.admin-toggle {
  background: rgba(255,255,255,.15);
  border: 1px solid rgba(255,255,255,.3);
  color: rgba(255,255,255,.8);
  border-radius: 4px;
  padding: .2rem .6rem;
  font-size: .8rem;
  cursor: pointer;
  transition: background .15s;
}
.admin-toggle:hover  { background: rgba(255,255,255,.25); }
.admin-toggle.admin-on {
  background: #f9a825;
  border-color: #f9a825;
  color: #202124;
  font-weight: 600;
}

/* Login page */
.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--color-bg);
}
.login-box {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 2rem;
  width: 100%;
  max-width: 360px;
}
.login-logo {
  font-size: 1.4rem;
  font-weight: 700;
  color: var(--color-primary);
  margin-bottom: .25rem;
}
.login-title {
  font-size: 1.1rem;
  font-weight: 600;
  margin-bottom: 1.25rem;
  color: var(--color-muted);
}
.field-group { margin-bottom: 1rem; }
.field-group label {
  display: block;
  font-size: .875rem;
  font-weight: 500;
  margin-bottom: .3rem;
}
.field-group input {
  width: 100%;
  padding: .5rem .75rem;
  border: 1px solid var(--color-border);
  border-radius: 6px;
  font-size: 1rem;
  outline: none;
}
.field-group input:focus { border-color: var(--color-primary); }
.btn-primary {
  background: var(--color-primary);
  color: #fff;
  border: none;
  border-radius: 6px;
  padding: .6rem 1.25rem;
  font-size: 1rem;
  font-weight: 500;
  cursor: pointer;
}
.btn-primary:hover { background: #1557b0; }
.btn-primary:disabled { background: var(--color-border); color: var(--color-muted); cursor: not-allowed; }
.btn-danger { background: #c0392b; color: #fff; border: none; border-radius: 6px; padding: .6rem 1.25rem; font-size: 1rem; font-weight: 500; cursor: pointer; }
.btn-danger:hover { background: #a93226; }
.btn-sm { padding: .35rem .75rem; font-size: .85rem; }
.btn-full { width: 100%; }

/* Raw fields panel (admin only) */
.admin-raw-fields {
  margin-top: .25rem;
}
.admin-raw-fields summary {
  font-size: .8rem;
  font-weight: 700;
  color: var(--color-muted);
  cursor: pointer;
  user-select: none;
  list-style: none;
  padding: .3rem 0;
}
.admin-raw-fields summary::-webkit-details-marker { display: none; }
.admin-raw-fields summary::before { content: '▶ '; font-size: .65rem; }
.admin-raw-fields[open] summary::before { content: '▼ '; }
.admin-raw-fields[open] summary { color: var(--color-text); }
.admin-raw-grid {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: .15rem .75rem;
  font-size: .75rem;
  font-family: ui-monospace, "SF Mono", monospace;
  background: var(--color-bg);
  border-radius: 6px;
  padding: .5rem .6rem;
  margin-top: .4rem;
}
.admin-raw-grid > span:nth-child(odd)  { color: var(--color-muted); white-space: nowrap; font-weight: 600; }
.admin-raw-grid > span:nth-child(even) { color: var(--color-text);  word-break: break-all; }

/* Layout */
.container {
  max-width: 860px;
  margin: 2rem auto;
  padding: 0 1rem;
}
.page-header {
  margin-bottom: 1.5rem;
}
.page-header h1 {
  font-size: 1.6rem;
  font-weight: 600;
}

/* Trip list */
.trip-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: .75rem;
}
.trip-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  transition: box-shadow .15s;
}
.trip-card:hover {
  box-shadow: 0 2px 8px rgba(0,0,0,.15);
}
.trip-link {
  display: block;
  padding: 1rem 1.25rem;
  text-decoration: none;
  color: inherit;
}
.trip-name {
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--color-primary);
  margin-bottom: .25rem;
}
.trip-meta {
  display: flex;
  flex-wrap: wrap;
  gap: .5rem 1.25rem;
  font-size: .875rem;
  color: var(--color-muted);
}
.trip-count {
  margin-left: auto;
  font-weight: 500;
}

/* Flash messages */
.flash {
  padding: .75rem 1rem;
  border-radius: var(--radius);
  margin-bottom: 1rem;
  font-size: .9rem;
}
.flash-error   { background: #fce8e6; color: #c5221f; }
.flash-success { background: #e6f4ea; color: #137333; }
.flash-info    { background: #e8f0fe; color: #1558d6; }

.empty { color: var(--color-muted); font-style: italic; }

/* Back link */
.back-link {
  display: inline-block;
  font-size: .875rem;
  color: var(--color-primary);
  text-decoration: none;
  margin-bottom: .5rem;
}
.back-link:hover { text-decoration: underline; }

/* Trip summary line under heading */
.trip-summary {
  display: flex;
  flex-wrap: wrap;
  gap: .5rem 1.25rem;
  font-size: .875rem;
  color: var(--color-muted);
  margin-top: .25rem;
}

/* Date groups */
.date-group { margin-bottom: 1.5rem; }
.date-heading {
  font-size: .8rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--color-muted);
  padding: .25rem 0;
  border-bottom: 1px solid var(--color-border);
  margin-bottom: .5rem;
}
.date-heading.undated { color: #aaa; }

/* Entry rows */
.entry-list { list-style: none; display: flex; flex-direction: column; gap: 2px; }

.entry-row {
  display: flex;
  align-items: center;
  gap: .75rem;
  padding: .5rem .75rem;
  background: var(--color-surface);
  border-radius: 6px;
  border-left: 3px solid var(--color-border);
  font-size: .9rem;
}
.entry-row:hover { background: var(--color-hover); cursor: pointer; }

/* Type accent colours */
.entry-type-flight        { border-left-color: #1a73e8; }
.entry-type-hotel         { border-left-color: #9c27b0; }
.entry-type-transport     { border-left-color: #e65100; }
.entry-type-food_and_drink{ border-left-color: #2e7d32; }
.entry-type-activity      { border-left-color: #f9a825; }
.entry-type-shopping      { border-left-color: #00838f; }
.entry-type-general       { border-left-color: #78909c; }

.entry-icon { font-size: 1.1rem; flex-shrink: 0; }

.entry-body {
  flex: 1;
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: .25rem .75rem;
  min-width: 0;
}
.entry-vendor {
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.entry-city  { font-size: .8rem; color: var(--color-muted); }
.entry-subtype { font-size: .8rem; color: var(--color-muted); text-transform: capitalize; }

.entry-right {
  display: flex;
  align-items: center;
  gap: .5rem;
  flex-shrink: 0;
  font-size: .85rem;
}
.entry-amount { font-weight: 600; }
.entry-children {
  background: var(--color-border);
  border-radius: 10px;
  padding: 1px 7px;
  font-size: .75rem;
  color: var(--color-muted);
}

/* Status badges */
.entry-status {
  font-size: .72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .04em;
  padding: 2px 6px;
  border-radius: 4px;
  background: #e8f0fe;
  color: #1558d6;
}
.status-completed  { background: #e6f4ea; color: #137333; }
.status-booked     { background: #e8f0fe; color: #1558d6; }
.status-reserved   { background: #e8f0fe; color: #1558d6; }
.status-planned    { background: #f1f3f4; color: #5f6368; }
.status-cancelled  { background: #fce8e6; color: #c5221f; text-decoration: line-through; }
.status-no_show    { background: #fce8e6; color: #c5221f; }
.status-skipped    { background: #f1f3f4; color: #aaa; }

/* ── Entry detail ─────────────────────────────────────────────────────────── */
.entry-detail-title {
  font-size: 1.5rem;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: .5rem;
  margin: .25rem 0;
}
.entry-icon-lg { font-size: 1.4rem; }
.entry-detail-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: .5rem 1rem;
  font-size: .875rem;
  color: var(--color-muted);
  margin-top: .25rem;
}

.detail-grid {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  margin-top: 1.25rem;
}

.detail-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1rem 1.25rem;
}
.detail-card-title {
  font-size: .75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .07em;
  color: var(--color-muted);
  margin-bottom: .75rem;
}
.detail-card-audit { opacity: .85; }

/* Field list */
.field-list { display: flex; flex-direction: column; gap: .5rem; }
.field-row { display: flex; gap: 1rem; font-size: .9rem; }
.field-row dt {
  width: 130px;
  flex-shrink: 0;
  color: var(--color-muted);
  font-weight: 500;
}
.field-row dd { flex: 1; word-break: break-word; }
.muted { color: var(--color-muted); font-size: .85em; }

/* JSON lists */
.json-list { list-style: none; display: flex; flex-direction: column; gap: .2rem; }
.json-kv { margin-right: .75rem; }
.json-key { color: var(--color-muted); font-size: .8em; text-transform: capitalize; }

/* Passenger list */
.pax-list { list-style: none; display: flex; flex-direction: column; gap: .2rem; font-size: .875rem; }

/* Child blocks */
.child-block {
  padding: .6rem .75rem;
  border-left: 3px solid var(--color-border);
  border-radius: 0 4px 4px 0;
  margin-bottom: .5rem;
  font-size: .875rem;
}
.child-type-flight   { border-left-color: #1a73e8; }
.child-type-transport{ border-left-color: #e65100; }
.child-route {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: .3rem .6rem;
  font-weight: 500;
}
.iata { font-size: 1rem; font-weight: 700; letter-spacing: .05em; }
.route-arrow { color: var(--color-muted); }
.flight-num { color: var(--color-primary); font-size: .85rem; }
.child-times {
  display: flex;
  flex-wrap: wrap;
  gap: .3rem 1rem;
  color: var(--color-muted);
  font-size: .8rem;
  margin-top: .2rem;
}

/* ── Loading overlay ─────────────────────────────────────────────────────── */
.loading-overlay {
  display: none; position: fixed; inset: 0;
  background: rgba(0,0,0,.45); z-index: 9000;
  align-items: center; justify-content: center;
}
.loading-box {
  background: var(--color-surface);
  border-radius: 12px;
  padding: 2rem 2.5rem;
  text-align: center;
  box-shadow: 0 8px 32px rgba(0,0,0,.25);
  min-width: 160px;
}
.loading-spinner {
  width: 38px; height: 38px; margin: 0 auto .9rem;
  border: 4px solid var(--color-border);
  border-top-color: var(--color-primary);
  border-radius: 50%;
  animation: tt-spin .75s linear infinite;
}
@keyframes tt-spin { to { transform: rotate(360deg); } }
.loading-message {
  font-size: .95rem; font-weight: 600; color: var(--color-text);
}

/* ── SSE log panel ───────────────────────────────────────────────────────── */
.sse-log {
  margin-top: .75rem;
  max-height: 320px;
  overflow-y: auto;
  font-family: ui-monospace, "SF Mono", monospace;
  font-size: .78rem;
  background: #1e1e1e;
  color: #d4d4d4;
  border-radius: 6px;
  padding: .5rem .75rem;
  display: none;
}
.sse-log.sse-active { display: block; }
.sse-line { padding: .15rem 0; line-height: 1.4; }
.sse-created { color: #89d185; }
.sse-skip    { color: #9cdcfe; }
.sse-info    { color: #ce9178; }
.sse-done    { color: #dcdcaa; font-weight: 700; }
.sse-error   { color: #f48771; }

/* ── Admin replay page ───────────────────────────────────────────────────── */
.replay-count { font-size: .95rem; margin-bottom: .75rem; }
.replay-note  { font-size: .8rem; color: var(--color-muted); margin-bottom: .75rem; }
.replay-row   { display: flex; gap: .75rem; align-items: center; flex-wrap: wrap; }
.replay-select {
  flex: 1; min-width: 180px;
  padding: .45rem .6rem;
  border: 1px solid var(--color-border);
  border-radius: 6px;
  font-size: .9rem;
  background: var(--color-surface);
}

/* ── File list (replay page) ─────────────────────────────────────────────── */
.file-list {
  border: 1px solid var(--color-border);
  border-radius: 6px;
  overflow-y: auto;
  max-height: 260px;
  font-size: .85rem;
}
.file-row {
  display: flex;
  align-items: center;
  gap: .75rem;
  padding: .35rem .6rem;
  border-bottom: 1px solid var(--color-border);
}
.file-row:last-child { border-bottom: none; }
.file-row-check { cursor: pointer; }
.file-row-check:hover { background: var(--color-hover); }
.file-row-check input[type=checkbox] { flex-shrink: 0; accent-color: var(--color-primary); }
.file-name { flex: 1; font-family: ui-monospace, "SF Mono", monospace; }
.file-size  { flex-shrink: 0; font-size: .75rem; }
.file-select-controls {
  display: flex;
  align-items: center;
  gap: .5rem;
  margin-bottom: .4rem;
  font-size: .8rem;
}
.link-btn {
  background: none; border: none; padding: 0;
  color: var(--color-primary); font-size: inherit;
  cursor: pointer; text-decoration: underline;
}
.link-btn:hover { color: #1557b0; }

/* ── Asset list (replay page) ────────────────────────────────────────────── */
.replay-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: .75rem;
  margin-bottom: 1rem;
  padding: .6rem .75rem;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
}
.replay-toolbar-left  { display: flex; align-items: center; gap: .75rem; }
.replay-toolbar-right { display: flex; align-items: center; gap: .6rem; flex-wrap: wrap; }
.replay-select-all { display: flex; align-items: center; gap: .4rem; font-size: .875rem; cursor: pointer; font-weight: 600; }

.asset-list { display: flex; flex-direction: column; gap: .5rem; }

.asset-card {
  display: flex;
  align-items: flex-start;
  gap: .75rem;
  padding: .75rem;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-left: 3px solid var(--color-border);
  border-radius: var(--radius);
}
.asset-card.asset-confirmed { border-left-color: #2e7d32; opacity: .75; }
.asset-card.asset-pending   { border-left-color: #f9a825; }

.asset-check-label { padding-top: .15rem; flex-shrink: 0; cursor: pointer; }
.asset-check-label input { accent-color: var(--color-primary); width: 16px; height: 16px; }

.asset-body { flex: 1; min-width: 0; }
.asset-title {
  font-weight: 500;
  font-size: .9rem;
  margin-bottom: .2rem;
  word-break: break-word;
}
.asset-meta {
  display: flex;
  flex-wrap: wrap;
  gap: .2rem .75rem;
  font-size: .78rem;
  color: var(--color-muted);
  margin-bottom: .2rem;
}
.asset-preview {
  font-size: .78rem;
  color: var(--color-muted);
  line-height: 1.4;
  margin-top: .2rem;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.asset-img-wrap { margin-top: .5rem; }

/* Thumbnail + hover zoom */
.asset-thumb-container {
  position: relative;
  display: inline-block;
}
.asset-thumb {
  width: 120px;
  height: 80px;
  object-fit: cover;
  border-radius: 6px;
  border: 1px solid var(--color-border);
  display: block;
  cursor: zoom-in;
  transition: opacity .15s;
}
.asset-thumb:hover { opacity: .9; }

/* Hover preview — large image floats to the right */
.asset-thumb-hover {
  display: none;
  position: absolute;
  left: calc(100% + 12px);
  top: 50%;
  transform: translateY(-50%);
  z-index: 200;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: 8px;
  box-shadow: 0 8px 32px rgba(0,0,0,.2);
  padding: 4px;
  pointer-events: none;
}
.asset-thumb-hover img {
  max-width: 640px;
  max-height: 520px;
  width: auto;
  height: auto;
  display: block;
  border-radius: 5px;
}
.asset-thumb-container:hover .asset-thumb-hover { display: block; }

/* Lightbox */
.lightbox {
  position: fixed; inset: 0; z-index: 9100;
  background: rgba(0,0,0,.88);
  display: flex; align-items: center; justify-content: center;
  cursor: zoom-out;
}
.lightbox-inner {
  position: relative;
  max-width: 92vw;
  max-height: 92vh;
  cursor: default;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: .5rem;
}
.lightbox-inner img {
  max-width: 90vw;
  max-height: 85vh;
  object-fit: contain;
  border-radius: 8px;
  box-shadow: 0 8px 40px rgba(0,0,0,.5);
  display: block;
}
.lightbox-close {
  position: absolute;
  top: -2.5rem; right: 0;
  background: none; border: none;
  color: #fff; font-size: 1.4rem;
  cursor: pointer; opacity: .7;
  line-height: 1;
}
.lightbox-close:hover { opacity: 1; }
.lightbox-caption {
  color: rgba(255,255,255,.7);
  font-size: .8rem;
  font-family: ui-monospace, monospace;
  text-align: center;
}

.asset-status {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: .25rem;
  flex-shrink: 0;
}
.badge {
  font-size: .72rem;
  font-weight: 600;
  padding: 2px 7px;
  border-radius: 10px;
  white-space: nowrap;
}
.badge-confirmed { background: #e6f4ea; color: #137333; }
.badge-pending   { background: #fef9e7; color: #b7860b; }
.badge-new       { background: #f1f3f4; color: #5f6368; }
