/* TRG Transactions. Dark-first iPhone PWA. TRG design tokens. */

:root {
  --bg: #111111;
  --card: #1B1B1B;
  --line: #2A2A2A;
  --ink: #F5F3EE;
  --muted: #9A968E;
  --blue: #1D86E8;
  --gold: #DFAF37;
  --red: #E05252;
  --amber: #E08A3C;
  --yellow: #E8C25A;
  --radius: 14px;
}

* { box-sizing: border-box; }

html {
  color-scheme: dark;
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 15px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

.wrap {
  max-width: 640px;
  margin: 0 auto;
  padding-left: calc(16px + env(safe-area-inset-left));
  padding-right: calc(16px + env(safe-area-inset-right));
}

button, input {
  font: inherit;
  color: inherit;
}
button { cursor: pointer; }

a { color: var(--blue); text-decoration: none; }

:focus-visible {
  outline: 2px solid var(--blue);
  outline-offset: 2px;
}

/* ---------- Header ---------- */

.app-header {
  position: sticky;
  top: 0;
  z-index: 20;
  background: rgba(17, 17, 17, 0.88);
  -webkit-backdrop-filter: blur(14px);
  backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--line);
  padding-top: env(safe-area-inset-top);
}

.header-inner { padding-top: 12px; padding-bottom: 10px; }

.app-header h1 {
  margin: 0;
  font-size: 20px;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.meta {
  margin: 2px 0 0;
  font-size: 13px;
  color: var(--muted);
}

/* ---------- Sync banner ---------- */

.banner {
  margin: 12px 0 0;
  padding: 10px 12px;
  border: 1px solid rgba(224, 138, 60, 0.5);
  background: rgba(224, 138, 60, 0.12);
  color: var(--amber);
  border-radius: 10px;
  font-size: 13px;
}

/* ---------- View toggle + filter chips ---------- */

.seg {
  display: flex;
  gap: 4px;
  margin: 14px 0 0;
  padding: 3px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 13px;
}

.seg-btn {
  flex: 1;
  height: 44px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: var(--muted);
  font-size: 14px;
  font-weight: 600;
  transition: background 0.15s ease, color 0.15s ease;
}

.seg-btn.active {
  background: var(--blue);
  color: #fff;
}

.chips {
  display: flex;
  gap: 8px;
  margin: 12px 0 0;
}

.chip {
  height: 44px;
  padding: 0 20px;
  border: 1px solid var(--line);
  border-radius: 22px;
  background: var(--card);
  color: var(--muted);
  font-size: 14px;
  font-weight: 600;
  transition: border-color 0.15s ease, color 0.15s ease, background 0.15s ease;
}

.chip.active {
  border-color: var(--blue);
  background: rgba(29, 134, 232, 0.15);
  color: var(--ink);
}

/* ---------- Cards ---------- */

main { padding-bottom: calc(104px + env(safe-area-inset-bottom)); }

/* Works for both views: chips are hidden in the Closed view. */
.list { margin-top: 14px; }

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px 14px 12px;
  margin-bottom: 12px;
}

.addr-street {
  font-size: 17px;
  font-weight: 650;
  letter-spacing: -0.01em;
}

.addr-city {
  font-size: 13px;
  color: var(--muted);
  margin-top: 1px;
}

.card-who {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 9px;
  flex-wrap: wrap;
}

.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 6px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  border: 1px solid var(--muted);
  color: var(--muted);
}

.badge-blue {
  border-color: var(--blue);
  color: var(--blue);
}

.clients { font-size: 14px; }

.next {
  margin: 10px 0 0;
  font-size: 14px;
  font-weight: 600;
}

/* Urgency colors: overdue red, 3 days or less amber, 7 days or less yellow. */
.u-over { color: var(--red); }
.u-soon { color: var(--amber); }
.u-week { color: var(--yellow); }
.u-none { color: var(--muted); }

/* ---------- Date rail ---------- */

.rail {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 6px;
  margin: 11px 0 0;
}

.pill {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  min-height: 44px;
  padding: 6px 2px;
  border-radius: 9px;
  background: #232323;
  color: #A8A49B;
  text-align: center;
}

.pill-label {
  font-size: 9.5px;
  font-weight: 700;
  letter-spacing: 0.08em;
  opacity: 0.72;
}

.pill-val {
  font-size: 12.5px;
  font-weight: 600;
}

.pill.u-over { background: rgba(224, 82, 82, 0.16); color: var(--red); }
.pill.u-soon { background: rgba(224, 138, 60, 0.16); color: var(--amber); }
.pill.u-week { background: rgba(232, 194, 90, 0.14); color: var(--yellow); }

.pill-empty,
.pill-waived {
  background: #1E1E1E;
  color: #6E6A63;
}

.pill-waived .pill-val {
  font-size: 10.5px;
  font-weight: 500;
  font-style: italic;
}

.warn-dot {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--red);
}

/* ---------- Card footer ---------- */

.card-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-top: 11px;
  padding-top: 10px;
  border-top: 1px solid #242424;
}

.foot-info {
  min-width: 0;
  font-size: 12px;
  color: var(--muted);
}

.foot-line {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.btn-tracker {
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  height: 38px;
  padding: 0 14px;
  border: 1px solid var(--blue);
  border-radius: 10px;
  color: var(--blue);
  font-size: 13px;
  font-weight: 600;
}

/* ---------- Closed list ---------- */

.closed-item {
  border-left: 3px solid var(--gold);
  padding-left: 13px;
}

.closed-date {
  margin-top: 8px;
  font-size: 13px;
  color: var(--gold);
  font-weight: 600;
}

.closed-item .card-who { margin-top: 6px; }

/* ---------- Empty / loading / error ---------- */

.empty {
  margin: 32px 0;
  text-align: center;
  color: var(--muted);
  font-size: 14px;
}

.skel {
  height: 150px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  margin-bottom: 12px;
  background: linear-gradient(100deg, #1B1B1B 40%, #212121 50%, #1B1B1B 60%);
  background-size: 200% 100%;
  animation: shimmer 1.4s linear infinite;
}

@keyframes shimmer {
  to { background-position: -200% 0; }
}

@media (prefers-reduced-motion: reduce) {
  .skel { animation: none; }
}

.error-card { text-align: center; padding: 20px 14px; }
.error-text { margin: 0 0 12px; color: var(--muted); }

/* ---------- Buttons (admin, generic) ---------- */

.btn {
  height: 44px;
  padding: 0 16px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #232323;
  color: var(--ink);
  font-size: 14px;
  font-weight: 600;
}

.btn:disabled { opacity: 0.5; cursor: default; }

.btn-mini {
  height: 34px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
}

.btn-mini.danger {
  color: var(--red);
  border-color: rgba(224, 82, 82, 0.45);
}

/* ---------- Admin ---------- */

.admin {
  margin: 22px 0 0;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--card);
}

.admin-summary {
  list-style: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 48px;
  padding: 0 14px;
  font-size: 15px;
  font-weight: 650;
  cursor: pointer;
}

.admin-summary::-webkit-details-marker { display: none; }

.admin-summary::after {
  content: "";
  width: 8px;
  height: 8px;
  border-right: 2px solid var(--muted);
  border-bottom: 2px solid var(--muted);
  transform: rotate(45deg);
  transition: transform 0.15s ease;
}

.admin[open] .admin-summary::after { transform: rotate(-135deg); }

.admin-body {
  padding: 2px 14px 14px;
  border-top: 1px solid #242424;
}

.admin-h {
  margin: 14px 0 8px;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--muted);
}

.admin-users {
  list-style: none;
  margin: 0;
  padding: 0;
}

.admin-user {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  min-height: 40px;
  font-size: 14px;
}

.admin-user + .admin-user { border-top: 1px solid #242424; }

.admin-user-email {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.admin-add {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 10px;
}

.admin-add input[type="email"] {
  flex: 1;
  min-width: 160px;
  height: 44px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #161616;
  color: var(--ink);
}

.admin-add input[type="email"]::placeholder { color: #6E6A63; }

.admin-check {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: var(--muted);
}

.admin-check input { accent-color: var(--blue); }

.admin-tools {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.admin-status {
  margin: 12px 0 0;
  font-size: 13px;
  color: var(--muted);
  min-height: 1em;
}

/* ---------- Sign out ---------- */

.signout-row {
  margin: 26px 0 8px;
  text-align: center;
}

.signout-row a {
  font-size: 13px;
  color: var(--muted);
  padding: 10px;
}

/* ---------- Bottom bar ---------- */

.bottombar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 20;
  background: rgba(17, 17, 17, 0.92);
  -webkit-backdrop-filter: blur(14px);
  backdrop-filter: blur(14px);
  border-top: 1px solid var(--line);
}

.bottombar-inner {
  padding-top: 10px;
  padding-bottom: calc(12px + env(safe-area-inset-bottom));
}

.btn-primary {
  width: 100%;
  height: 48px;
  border: 0;
  border-radius: 12px;
  background: var(--blue);
  color: #fff;
  font-size: 15px;
  font-weight: 650;
  transition: background 0.15s ease, color 0.15s ease;
}

.btn-primary.on {
  background: rgba(29, 134, 232, 0.12);
  border: 1px solid var(--blue);
  color: var(--blue);
}

.btn-primary:disabled { opacity: 0.6; }

.hint {
  margin: 4px 0 2px;
  text-align: center;
  font-size: 13px;
  color: var(--muted);
}

/* ---------- Login page ---------- */

.login-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100dvh;
  padding: calc(20px + env(safe-area-inset-top)) 20px calc(20px + env(safe-area-inset-bottom));
}

.login-card {
  width: min(400px, 100%);
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 30px 24px 26px;
  text-align: center;
}

.mark {
  position: relative;
  width: 58px;
  height: 58px;
  margin: 0 auto 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 14px;
  font-size: 22px;
  font-weight: 700;
  letter-spacing: 0.02em;
  overflow: hidden;
}

.mark::after {
  content: "";
  position: absolute;
  left: 12px;
  right: 12px;
  bottom: 8px;
  height: 3px;
  border-radius: 2px;
  background: var(--blue);
}

.login-card h1 {
  margin: 0;
  font-size: 21px;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.login-sub {
  margin: 4px 0 20px;
  font-size: 13px;
  color: var(--muted);
}

.login-err {
  margin: 0 0 14px;
  padding: 10px 12px;
  border: 1px solid rgba(224, 82, 82, 0.5);
  background: rgba(224, 82, 82, 0.1);
  color: var(--red);
  border-radius: 10px;
  font-size: 13px;
  text-align: left;
}

.login-form {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.login-form input[type="email"],
.login-form input[type="text"] {
  height: 48px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #161616;
  color: var(--ink);
  font-size: 16px; /* 16px stops iOS Safari from zooming the field on focus */
}

.login-form input[type="email"]::placeholder,
.login-form input[type="text"]::placeholder { color: #6E6A63; }

#code-form { margin-top: 12px; }

.login-sent {
  margin: 6px 0 0;
  padding: 12px;
  border: 1px solid rgba(29, 134, 232, 0.45);
  background: rgba(29, 134, 232, 0.1);
  border-radius: 10px;
  font-size: 14px;
  color: var(--ink);
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}
