:root {
  --bg: #0f172a;
  --surface: #1e293b;
  --surface2: #334155;
  --text: #f1f5f9;
  --muted: #94a3b8;
  --primary: #3b82f6;
  --primary-dark: #1F4E79;
  --ok: #22c55e;
  --warn: #eab308;
  --danger: #ef4444;
  --flag-yellow: #854d0e;
  --flag-yellow-bg: #fef9c3;
  --flag-red: #991b1b;
  --flag-red-bg: #fee2e2;
  --radius: 12px;
  --shadow: 0 8px 24px rgba(0,0,0,.25);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  /* iOS PWA / notched devices (Add to Home Screen) */
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  padding: 0;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  min-height: 100%;
  min-height: 100dvh;
  -webkit-text-size-adjust: 100%;
}
a { color: var(--primary); text-decoration: none; }
button, input, select, textarea {
  font: inherit;
  color: inherit;
}

.app-header {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: .75rem;
  /* Push nav below iOS status bar / Dynamic Island when installed as web app */
  padding-top: calc(.85rem + var(--safe-top));
  padding-right: calc(1rem + var(--safe-right));
  padding-bottom: .85rem;
  padding-left: calc(1rem + var(--safe-left));
  background: rgba(15, 23, 42, .92);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--surface2);
}
.app-header h1 {
  margin: 0;
  font-size: 1.1rem;
  letter-spacing: .02em;
}
.brand { min-width: 0; flex: 1 1 auto; }
.brand-link {
  display: inline-flex;
  align-items: center;
  gap: .65rem;
  color: inherit;
  max-width: 100%;
}
.brand-logo {
  display: block;
  height: 2rem;
  width: auto;
  max-width: min(160px, 42vw);
  object-fit: contain;
  border-radius: 4px;
  /* Logo is white-on-black; sits cleanly on dark header */
  background: #000;
  padding: .2rem .35rem;
}
.brand-title {
  font-size: 1.05rem;
  font-weight: 650;
  letter-spacing: .02em;
  white-space: nowrap;
}
@media (max-width: 520px) {
  .brand-title { display: none; }
  .brand-logo { height: 1.75rem; }
}
.nav-actions { display: flex; gap: .5rem; flex-wrap: wrap; flex: 0 1 auto; justify-content: flex-end; }

.container {
  width: min(1100px, 100%);
  margin: 0 auto;
  padding: 1rem;
  padding-left: calc(1rem + var(--safe-left));
  padding-right: calc(1rem + var(--safe-right));
  padding-bottom: calc(5rem + var(--safe-bottom));
}

.card {
  background: var(--surface);
  border: 1px solid var(--surface2);
  border-radius: var(--radius);
  padding: 1rem;
  margin-bottom: 1rem;
  box-shadow: var(--shadow);
}
.card h2, .card h3 { margin-top: 0; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: .4rem;
  border: 1px solid var(--surface2);
  background: var(--surface2);
  color: var(--text);
  border-radius: 10px;
  padding: .55rem .9rem;
  cursor: pointer;
  min-height: 44px;
  white-space: nowrap;
}
.btn:active { transform: scale(.98); }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; font-weight: 600; }
.btn.ghost { background: transparent; }
.btn.danger { background: #7f1d1d; border-color: #991b1b; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

.grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: .75rem;
}
@media (max-width: 700px) {
  .grid-2 { grid-template-columns: 1fr; }
}

label {
  display: block;
  font-size: .85rem;
  color: var(--muted);
  margin-bottom: .25rem;
}
input, select, textarea {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--surface2);
  border-radius: 10px;
  padding: .65rem .75rem;
  min-height: 44px;
}
textarea { min-height: 88px; resize: vertical; }
.field { margin-bottom: .75rem; }

.muted { color: var(--muted); }
.small { font-size: .85rem; }
.row-between {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: .75rem;
  flex-wrap: wrap;
}

.trip-list { display: flex; flex-direction: column; gap: .75rem; }
.trip-item {
  display: block;
  background: var(--surface);
  border: 1px solid var(--surface2);
  border-radius: var(--radius);
  padding: 1rem;
  color: inherit;
}
.trip-item:hover { border-color: var(--primary); }
.badge {
  display: inline-block;
  font-size: .75rem;
  padding: .2rem .55rem;
  border-radius: 999px;
  background: var(--surface2);
}
.badge.ready { background: #14532d; color: #bbf7d0; }
.badge.draft { background: #1e3a5f; color: #bfdbfe; }
.badge.review { background: #713f12; color: #fde68a; }

/* Review table */
.table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  border-radius: var(--radius);
  border: 1px solid var(--surface2);
}
table.expenses {
  width: 100%;
  border-collapse: collapse;
  min-width: 860px;
  font-size: .9rem;
}
table.expenses th, table.expenses td {
  border-bottom: 1px solid var(--surface2);
  padding: .55rem .5rem;
  text-align: left;
  vertical-align: top;
}
table.expenses th {
  background: var(--primary-dark);
  color: #fff;
  position: sticky;
  top: 0;
  z-index: 1;
}
table.expenses input, table.expenses select {
  min-height: 38px;
  padding: .35rem .45rem;
  font-size: .85rem;
}
tr.flag-yellow {
  background: var(--flag-yellow-bg) !important;
  color: #1c1917;
}
tr.flag-red {
  background: var(--flag-red-bg) !important;
  color: #1c1917;
}
tr.flag-yellow input, tr.flag-yellow select,
tr.flag-red input, tr.flag-red select {
  color: #0f172a;
  background: rgba(255,255,255,.85);
}
.flag-pill {
  display: inline-block;
  font-size: .72rem;
  font-weight: 700;
  padding: .15rem .4rem;
  border-radius: 6px;
  margin-top: .25rem;
}
.flag-pill.yellow { background: #facc15; color: #422006; }
.flag-pill.red { background: #ef4444; color: #fff; }

.upload-zone {
  border: 2px dashed var(--surface2);
  border-radius: var(--radius);
  padding: 1.25rem;
  text-align: center;
  background: rgba(30, 41, 59, .6);
}
.upload-zone.drag { border-color: var(--primary); background: rgba(59,130,246,.1); }
.upload-actions {
  display: flex;
  flex-wrap: wrap;
  gap: .5rem;
  justify-content: center;
  margin-top: .75rem;
}
.file-input-hidden { display: none; }

.toast {
  position: fixed;
  bottom: calc(1rem + var(--safe-bottom));
  left: 50%;
  transform: translateX(-50%);
  background: #022c22;
  border: 1px solid #10b981;
  color: #ecfdf5;
  padding: .75rem 1rem;
  border-radius: 999px;
  z-index: 50;
  max-width: 92vw;
  box-shadow: var(--shadow);
}
.toast.error { background: #450a0a; border-color: #ef4444; color: #fef2f2; }

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

/* Receipt viewer */
.modal[hidden] { display: none !important; }
.modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}
.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(2, 6, 23, .72);
  backdrop-filter: blur(3px);
}
.modal-panel {
  position: relative;
  z-index: 1;
  width: min(920px, 100%);
  max-height: min(92vh, 900px);
  overflow: auto;
  background: var(--surface);
  border: 1px solid var(--surface2);
  border-radius: var(--radius);
  padding: 1rem;
  box-shadow: var(--shadow);
}
.receipt-viewer {
  background: #0b1220;
  border-radius: 10px;
  border: 1px solid var(--surface2);
  min-height: 200px;
  max-height: 70vh;
  overflow: auto;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: .5rem;
}
.receipt-viewer img {
  max-width: 100%;
  height: auto;
  display: block;
  border-radius: 6px;
}
.receipt-viewer iframe {
  width: 100%;
  min-height: 65vh;
  border: 0;
  border-radius: 6px;
  background: #fff;
}
.btn.view-receipt {
  min-height: 34px;
  padding: .3rem .55rem;
  font-size: .8rem;
}

.spinner {
  display: inline-block;
  width: 1rem;
  height: 1rem;
  border: 2px solid rgba(255,255,255,.3);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.fab-bar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  padding: .65rem 1rem calc(.65rem + env(safe-area-inset-bottom));
  background: rgba(15, 23, 42, .95);
  border-top: 1px solid var(--surface2);
  display: none;
  gap: .5rem;
  justify-content: stretch;
  z-index: 15;
}
.fab-bar .btn { flex: 1; }
.fab-bar.visible { display: flex; }

.export-links { display: flex; flex-wrap: wrap; gap: .5rem; margin-top: .75rem; }
