/* sarai.css — Sarai mobile-first design system */

/* ------------------------------------------------------------------
   Tokens
   ------------------------------------------------------------------ */
:root {
  --ink:     #1c2620;
  --bg:      #f6f7f5;
  --surface: #ffffff;
  --moss:    #2c4a3a;
  --sage:    #7a9b86;
  --line:    #e2e6e1;
  --risk:    #b4541f;
  --ok:      #2f7d4f;
  --muted:   #6b756e;
}

/* ------------------------------------------------------------------
   Reset & base
   ------------------------------------------------------------------ */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

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

/* ------------------------------------------------------------------
   Focus
   ------------------------------------------------------------------ */
:focus-visible {
  outline: 2px solid var(--moss);
  outline-offset: 2px;
}

/* ------------------------------------------------------------------
   Mono helper
   ------------------------------------------------------------------ */
.mono {
  font-family: ui-monospace, "Cascadia Code", "SF Mono", Menlo, Consolas, monospace;
}

/* ------------------------------------------------------------------
   Muted
   ------------------------------------------------------------------ */
.muted { color: var(--muted); }

/* ------------------------------------------------------------------
   Top nav (sticky, moss bg — shows brand + push btn on mobile;
   also reveals primary links on desktop)
   ------------------------------------------------------------------ */
.top-nav {
  position: sticky;
  top: 0;
  z-index: 100;
  background: var(--moss);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.55rem 1rem;
  gap: 0.5rem;
}

.top-nav .brand {
  font-weight: 700;
  font-size: 1rem;
  color: #fff;
  text-decoration: none;
  white-space: nowrap;
  flex-shrink: 0;
}

.top-nav .top-links {
  display: none; /* hidden on mobile; shown at ≥768px */
  align-items: center;
  gap: 0.15rem;
  flex-wrap: nowrap;
}

.top-nav .top-links a {
  color: rgba(255,255,255,0.82);
  text-decoration: none;
  font-size: 0.82rem;
  padding: 0.28rem 0.55rem;
  border-radius: 5px;
  white-space: nowrap;
  transition: background 0.12s, color 0.12s;
}

.top-nav .top-links a:hover,
.top-nav .top-links a.active {
  background: rgba(255,255,255,0.15);
  color: #fff;
}

.top-nav .top-right {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  flex-shrink: 0;
}

/* ------------------------------------------------------------------
   Bottom nav (mobile tab bar — fixed, 4 tabs)
   ------------------------------------------------------------------ */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 100;
  background: var(--surface);
  border-top: 1px solid var(--line);
  display: flex;
  align-items: stretch;
  height: 56px;
  padding-bottom: env(safe-area-inset-bottom, 0px);
}

.bottom-nav a {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-decoration: none;
  color: var(--muted);
  font-size: 0.68rem;
  font-weight: 500;
  gap: 0.08rem;
  min-height: 44px;
  transition: color 0.12s;
  padding: 0.25rem 0;
}

.bottom-nav a .nav-icon {
  font-size: 1.15rem;
  line-height: 1.1;
}

.bottom-nav a:hover  { color: var(--moss); }
.bottom-nav a.active { color: var(--moss); font-weight: 700; }

/* ------------------------------------------------------------------
   Content wrapper
   ------------------------------------------------------------------ */
.content {
  padding: 1rem;
  padding-bottom: 5rem; /* clear fixed bottom-nav */
  max-width: 900px;
  margin: 0 auto;
}

/* ------------------------------------------------------------------
   Stack / cluster layout helpers
   ------------------------------------------------------------------ */
.stack { display: flex; flex-direction: column; gap: 0.75rem; }
.cluster {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
}

/* ------------------------------------------------------------------
   Card
   ------------------------------------------------------------------ */
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 1rem;
  margin-bottom: 1rem;
}

.card h2 {
  font-size: 1rem;
  font-weight: 600;
  color: var(--ink);
  margin-bottom: 0.65rem;
}

.card h3 {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--ink);
  margin-bottom: 0.4rem;
}

/* At-risk pulse animation */
.card.at-risk {
  border-color: var(--risk);
  background: #fff9f6;
}

@media (prefers-reduced-motion: no-preference) {
  .card.at-risk {
    animation: risk-pulse 2.6s ease-in-out infinite;
  }
}

@keyframes risk-pulse {
  0%,  100% { box-shadow: 0 0 0 0   rgba(180, 84, 31, 0); }
  50%        { box-shadow: 0 0 0 5px rgba(180, 84, 31, 0.18); }
}

/* Danger zone card */
.card-danger { border-color: #f5c2c7 !important; }
.card-danger h2 { color: #842029 !important; }

/* ------------------------------------------------------------------
   Pill (rounded label)
   ------------------------------------------------------------------ */
.pill {
  display: inline-block;
  padding: 0.22rem 0.6rem;
  border-radius: 99px;
  font-size: 0.72rem;
  font-weight: 600;
}

/* ------------------------------------------------------------------
   Buttons  — ≥44px tap target
   ------------------------------------------------------------------ */
.btn, a.btn, button.btn, input[type=submit].btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  padding: 0.5rem 1.05rem;
  border-radius: 6px;
  font-size: 0.9rem;
  font-weight: 500;
  cursor: pointer;
  text-decoration: none;
  border: 1px solid transparent;
  line-height: 1.2;
  transition: background 0.12s, border-color 0.12s, color 0.12s;
  white-space: nowrap;
  -webkit-tap-highlight-color: transparent;
}

.btn-primary  { background: var(--moss); color: #fff; border-color: var(--moss); }
.btn-primary:hover  { background: #1e3428; border-color: #1e3428; }

.btn-secondary { background: var(--surface); color: var(--ink); border-color: var(--line); }
.btn-secondary:hover { background: var(--bg); }

.btn-danger { background: #dc3545; color: #fff; border-color: #dc3545; }
.btn-danger:hover { background: #b02a37; border-color: #b02a37; }

.btn-sm {
  min-height: 36px;
  padding: 0.28rem 0.65rem;
  font-size: 0.82rem;
}

.btn-active {
  background: var(--moss) !important;
  color: #fff !important;
  border-color: var(--moss) !important;
}

form.inline { display: inline; }

/* ------------------------------------------------------------------
   Badges
   ------------------------------------------------------------------ */
.badge {
  display: inline-block;
  padding: 0.18rem 0.48rem;
  border-radius: 4px;
  font-size: 0.74rem;
  font-weight: 600;
  letter-spacing: 0.01em;
  line-height: 1.4;
}

/* Source */
.badge-direct { background: #dbeafe; color: #1e40af; }
.badge-hw     { background: #e2e3e5; color: #383d41; }
.badge-bc     { background: #e2e3e5; color: #383d41; }

/* Risk / status */
.badge-risk    { background: var(--risk); color: #fff; font-weight: 700; letter-spacing: 0.03em; }
.badge-ok      { background: var(--ok);   color: #fff; }
.badge-pending { background: #fff3cd; color: #664d03; border: 1px solid #ffc107; }

/* Generic */
.badge-yes     { background: #d1fae5; color: #065f46; }
.badge-no      { background: #f1f5f9; color: var(--muted); border: 1px solid var(--line); }
.badge-success { background: #d1fae5; color: #065f46; }
.badge-warning { background: #fff3cd; color: #856404; }
.badge-danger  { background: #fde8e8; color: #842029; }
.badge-info    { background: #dbeafe; color: #1e40af; }
.badge-muted   { background: #e2e3e5; color: #383d41; }

/* Stage */
.badge-stage-received  { background: #f1f5f9; color: var(--muted); border: 1px solid var(--line); }
.badge-stage-enriched  { background: #fff3cd; color: #856404; }
.badge-stage-in_pms    { background: #dbeafe; color: #1e40af; }
.badge-stage-messaged  { background: #cffafe; color: #155e75; }
.badge-stage-responded { background: #d1fae5; color: #065f46; }
.badge-stage-deposit   { background: #16a34a; color: #fff; }
.badge-stage-confirmed { background: #065f46; color: #fff; }
.badge-stage-cancelled { background: #e2e3e5; color: #383d41; }

/* ------------------------------------------------------------------
   Fields / forms  — 16px font to prevent iOS auto-zoom
   ------------------------------------------------------------------ */
.field        { margin-bottom: 0.875rem; }
.form-group   { margin-bottom: 0.875rem; }

label {
  display: block;
  font-size: 0.85rem;
  font-weight: 500;
  margin-bottom: 0.3rem;
  color: var(--ink);
}

input[type=text],
input[type=password],
input[type=date],
input[type=email],
input[type=tel],
input[type=number],
input[type=url],
select,
textarea {
  width: 100%;
  padding: 0.55rem 0.75rem;
  border: 1px solid var(--line);
  border-radius: 6px;
  font-size: 16px; /* 16px prevents iOS auto-zoom */
  font-family: inherit;
  color: var(--ink);
  background: var(--surface);
  appearance: none;
  -webkit-appearance: none;
}

input[type=text]:focus,
input[type=password]:focus,
input[type=date]:focus,
input[type=email]:focus,
input[type=tel]:focus,
input[type=number]:focus,
input[type=url]:focus,
select:focus,
textarea:focus {
  outline: none;
  border-color: var(--moss);
  box-shadow: 0 0 0 2px rgba(44, 74, 58, 0.14);
}

select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath fill='%236b756e' d='M6 8L0 0h12z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.7rem center;
  padding-right: 2rem;
}

textarea { resize: vertical; min-height: 80px; }

input[type=checkbox] { width: auto; }
input[type=file] { padding: 0.4rem 0.5rem; font-size: 0.875rem; }

.form-row { display: flex; gap: 0.75rem; }
.form-row .form-group { flex: 1; min-width: 0; }

/* ------------------------------------------------------------------
   Table (scrollable wrapper on mobile)
   ------------------------------------------------------------------ */
.table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  border-radius: 6px;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.875rem;
}

th {
  text-align: left;
  padding: 0.5rem 0.65rem;
  background: var(--bg);
  border-bottom: 2px solid var(--line);
  font-weight: 600;
  color: var(--muted);
  font-size: 0.78rem;
  white-space: nowrap;
}

td {
  padding: 0.5rem 0.65rem;
  border-bottom: 1px solid var(--line);
  vertical-align: middle;
}

tr:last-child td { border-bottom: none; }
tr:hover td { background: var(--bg); }

/* Detail table (key-value rows) */
.detail-table { border-collapse: collapse; width: 100%; }
.detail-table th {
  text-align: left;
  width: 140px;
  font-weight: 500;
  color: var(--muted);
  padding: 0.3rem 0.5rem 0.3rem 0;
  vertical-align: top;
  font-size: 0.82rem;
  background: none;
  border: none;
  border-bottom: none;
}
.detail-table td {
  padding: 0.3rem 0;
  font-size: 0.875rem;
  border: none;
}

/* ------------------------------------------------------------------
   Stats row
   ------------------------------------------------------------------ */
.stats { display: flex; gap: 0.65rem; margin-bottom: 1rem; flex-wrap: wrap; }
.stat {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0.75rem 0.875rem;
  flex: 1;
  min-width: 110px;
}
.stat-value { font-size: 1.6rem; font-weight: 700; color: var(--ink); line-height: 1.1; }
.stat-label { font-size: 0.76rem; color: var(--muted); margin-top: 0.2rem; }

/* ------------------------------------------------------------------
   Flash / alerts
   ------------------------------------------------------------------ */
.flash {
  padding: 0.7rem 0.9rem;
  border-radius: 6px;
  margin-bottom: 0.875rem;
  font-size: 0.875rem;
  line-height: 1.4;
}
.flash-ok   { background: #d1fae5; color: #065f46; border: 1px solid #a7f3d0; }
.flash-err  { background: #fde8e8; color: #842029; border: 1px solid #fca5a5; }
.flash-warn { background: #fff3cd; color: #856404; border: 1px solid #fcd34d; }
.flash-info { background: #dbeafe; color: #1e40af; border: 1px solid #93c5fd; }

/* ------------------------------------------------------------------
   Lifecycle stepper
   ------------------------------------------------------------------ */
.stepper {
  display: flex;
  align-items: center;
  gap: 0;
  margin-bottom: 1rem;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  padding-bottom: 0.25rem;
  flex-wrap: nowrap;
}
.step-item { display: flex; align-items: center; white-space: nowrap; }
.step-dot {
  width: 22px; height: 22px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 0.68rem; font-weight: 700; flex-shrink: 0;
}
.step-label { margin: 0 0.3rem; white-space: nowrap; font-size: 0.75rem; font-weight: 500; }
.step-connector { height: 2px; width: 14px; flex-shrink: 0; }

.step-done .step-dot    { background: var(--ok); color: #fff; }
.step-done .step-label  { color: var(--ok); }
.step-current .step-dot {
  background: var(--moss); color: #fff;
  box-shadow: 0 0 0 3px rgba(44, 74, 58, 0.18);
}
.step-current .step-label { color: var(--moss); font-weight: 700; }
.step-pending .step-dot   { background: var(--line); color: var(--muted); }
.step-pending .step-label { color: var(--muted); }

/* ------------------------------------------------------------------
   Misc UI
   ------------------------------------------------------------------ */
.empty { color: var(--muted); font-style: italic; padding: 0.65rem 0; }
.error { color: #842029; font-size: 0.85rem; margin-top: 0.4rem; }

.sub-label {
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  margin-bottom: 0.4rem;
}

.deposit-ask {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  background: #fff3cd;
  border: 1px solid #fcd34d;
  border-radius: 6px;
  padding: 0.5rem 0.9rem;
  font-size: 0.9rem;
  font-weight: 600;
  color: #856404;
  margin-bottom: 0.875rem;
}

.comms-pipeline { display: flex; gap: 0.35rem; align-items: center; flex-wrap: wrap; }
.comms-arrow { color: var(--line); font-size: 0.85rem; }

.msg-textarea {
  width: 100%;
  padding: 0.65rem 0.75rem;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 6px;
  font-size: 0.875rem;
  font-family: inherit;
  resize: vertical;
  color: var(--ink);
}

/* ------------------------------------------------------------------
   Worklist session cards
   ------------------------------------------------------------------ */
.session-card {
  display: block;
  text-decoration: none;
  color: inherit;
}
.session-card:hover .card { border-color: var(--sage); }

.session-card-name {
  font-size: 1rem;
  font-weight: 600;
  color: var(--ink);
  margin-bottom: 0.2rem;
}
.session-card-meta {
  font-size: 0.82rem;
  color: var(--muted);
  line-height: 1.65;
}

/* ------------------------------------------------------------------
   h1, h2
   ------------------------------------------------------------------ */
h1 { font-size: 1.35rem; margin-bottom: 0.875rem; color: var(--ink); font-weight: 700; }
h2 { font-size: 1.05rem; margin-bottom: 0.65rem; color: var(--ink); font-weight: 600; }

/* ------------------------------------------------------------------
   Desktop overrides  (≥768px)
   ------------------------------------------------------------------ */
@media (min-width: 768px) {
  /* Hide bottom nav; show top-nav links */
  .bottom-nav            { display: none; }
  .top-nav .top-links    { display: flex; }

  .content {
    padding: 1.5rem 2rem;
    padding-bottom: 2rem;
  }

  .card { padding: 1.25rem 1.5rem; }

  /* 2-col card grid helper */
  .card-grid-2 {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 1rem;
  }
  .card-grid-2 .card { margin-bottom: 0; }

  /* Worklist 2-col session cards */
  .worklist-cards {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.75rem;
  }
  .worklist-cards .session-card .card { margin-bottom: 0; }
}
