/* Distributor portal styling.

   Shares the brand tokens with dashboard.css rather than importing it: the
   admin dashboard is a dense internal tool built around wide tables, and this
   is a mobile-first customer-facing surface (distributors are on phones), so
   the two need different layout rules on top of the same palette. */

:root {
  --brand: #10b981;
  --brand-dark: #064e3b;
  --brand-bright: #34d399;
  --brand-bright-dark: #059669;
  --ink: #f3f4f6;
  --ink-soft: #9ca3af;
  --ink-faint: #6b7280;
  --bg: #070d0b;
  --bg-soft: #0c1512;
  --bg-card: rgba(15, 26, 23, 0.7);
  --border: rgba(255, 255, 255, 0.08);
  --err: #ef4444;
  --err-bg: rgba(239, 68, 68, 0.1);
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 4px 20px rgba(0, 0, 0, 0.25);
  /* Tell the browser this surface is dark so the widgets it paints itself —
     the <select> drop-down list, the date/month pickers, scrollbars — come up
     dark too. Without it Chrome opens a white drop-down and the options keep
     the near-white inherited text colour, which left them unreadable. */
  color-scheme: dark;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "Outfit", "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--ink);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

a {
  color: var(--brand-bright);
  text-decoration: none;
  transition: color 0.2s ease;
}

a:hover {
  color: #fff;
}

code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  background: rgba(255, 255, 255, 0.06);
  border-radius: 4px;
  padding: 2px 6px;
  font-size: 0.92em;
}

/* ── Chrome ─────────────────────────────────────────────────────────────── */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 20px;
  background: rgba(7, 13, 11, 0.92);
  border-bottom: 1px solid var(--border);
  backdrop-filter: blur(16px);
  position: sticky;
  top: 0;
  z-index: 50;
}

.topbar .brand {
  font-weight: 800;
  font-size: 1.15rem;
  letter-spacing: -0.02em;
  color: #fff;
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.topbar-company {
  color: var(--ink-soft);
  font-size: 0.9rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 40vw;
}

.wrap {
  max-width: 1080px;
  margin: 0 auto;
  padding: 24px 20px 64px;
}

/* ── Surfaces ───────────────────────────────────────────────────────────── */

.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  margin-bottom: 20px;
  box-shadow: var(--shadow);
}

.card h1 {
  margin: 0 0 6px;
  font-size: 1.6rem;
  letter-spacing: -0.02em;
}

.card h2 {
  margin: 0 0 10px;
  font-size: 1.15rem;
}

.auth-card {
  max-width: 420px;
  margin: 48px auto;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 32px 28px;
  box-shadow: var(--shadow);
}

.auth-card h1 {
  margin: 0 0 8px;
  font-size: 1.5rem;
  letter-spacing: -0.02em;
}

.auth-footnote {
  margin: 20px 0 0;
  text-align: center;
  font-size: 0.9rem;
}

.auth-alt {
  margin-top: 14px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
  color: var(--ink-soft);
}

.muted {
  color: var(--ink-soft);
}

.small {
  font-size: 0.85rem;
}

.hint {
  display: block;
  margin-top: 5px;
  font-size: 0.8rem;
  color: var(--ink-faint);
}

.steps {
  padding-left: 20px;
  margin: 0 0 18px;
}

.steps li {
  margin-bottom: 10px;
}

/* ── Banners ────────────────────────────────────────────────────────────── */

.banner {
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  margin-bottom: 18px;
  font-size: 0.92rem;
}

.banner-error {
  background: var(--err-bg);
  border: 1px solid rgba(239, 68, 68, 0.3);
  color: #fca5a5;
}

/* ── Forms ──────────────────────────────────────────────────────────────── */

.stack {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.field label {
  display: block;
  margin-bottom: 6px;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--ink-soft);
}

input[type="text"],
input[type="tel"],
input[type="password"],
input[type="email"],
input[type="date"] {
  width: 100%;
  padding: 11px 13px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--ink);
  /* 16px minimum: anything smaller makes iOS Safari zoom the viewport on
     focus, which on a phone throws the whole form off-screen mid-typing. */
  font-size: 16px;
  font-family: inherit;
  transition:
    border-color 0.2s ease,
    background 0.2s ease;
}

input:focus,
select:focus {
  outline: none;
  border-color: var(--brand-bright-dark);
  background: rgba(255, 255, 255, 0.06);
}

/* Belt-and-braces alongside color-scheme above: the drop-down list is painted
   outside the page, so the options need their own opaque colours rather than
   the translucent white the closed <select> carries. Same rule dashboard.css
   and onboard.css already carry. */
select option {
  background: var(--bg-soft);
  color: #fff;
}

button {
  font-family: inherit;
  font-size: 0.92rem;
  font-weight: 600;
  padding: 11px 18px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  cursor: pointer;
  transition:
    background 0.2s ease,
    border-color 0.2s ease,
    color 0.2s ease;
}

button.primary,
button[type="submit"]:not(.secondary) {
  background: var(--brand);
  color: #04140f;
}

button.primary:hover,
button[type="submit"]:not(.secondary):hover {
  background: var(--brand-bright);
}

button.secondary {
  background: transparent;
  border-color: var(--border);
  color: var(--ink-soft);
}

button.secondary:hover {
  border-color: var(--brand-bright-dark);
  color: #fff;
}

button.block {
  width: 100%;
}

/* ── Section nav ────────────────────────────────────────────────────────── */

.portal-nav {
  border-bottom: 1px solid var(--border);
  background: rgba(7, 13, 11, 0.75);
  position: sticky;
  top: 57px;
  z-index: 40;
}

.portal-nav-inner {
  max-width: 1080px;
  margin: 0 auto;
  padding: 0 20px;
  display: flex;
  gap: 4px;
  /* Horizontal scroll rather than wrapping: on a phone the eight tabs
     become a swipeable strip instead of three stacked rows pushing the
     content off-screen. */
  overflow-x: auto;
  scrollbar-width: none;
}

.portal-nav-inner::-webkit-scrollbar {
  display: none;
}

.nav-tab {
  padding: 12px 14px;
  color: var(--ink-soft);
  font-size: 0.9rem;
  font-weight: 500;
  white-space: nowrap;
  border-bottom: 2px solid transparent;
}

.nav-tab:hover {
  color: #fff;
}

.nav-tab.is-active {
  color: var(--brand-bright);
  border-bottom-color: var(--brand-bright);
}

/* ── Stat tiles ─────────────────────────────────────────────────────────── */

.tiles {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 14px;
  margin-bottom: 20px;
}

.tiles-inline {
  margin: 18px 0 4px;
}

.tile {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
}

.tile-value {
  font-size: 1.5rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1.2;
}

.tile-label {
  margin-top: 6px;
  font-size: 0.82rem;
  color: var(--ink-soft);
}

.accent {
  color: var(--brand-bright);
}

.warn {
  color: #f87171;
}

.dim {
  color: var(--ink-faint);
}

/* ── Tables ─────────────────────────────────────────────────────────────── */

.table-wrap {
  /* Wide tables scroll inside their own box; the page body never scrolls
     sideways. */
  overflow-x: auto;
  margin-top: 16px;
}

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

th,
td {
  text-align: left;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

th {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--ink-faint);
  font-weight: 600;
}

tbody tr:hover {
  background: rgba(255, 255, 255, 0.02);
}

td.num,
th.num {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

td.cap {
  text-transform: capitalize;
}

td.empty {
  text-align: center;
  padding: 24px;
  color: var(--ink-soft);
  white-space: normal;
}

tfoot td {
  border-bottom: none;
  border-top: 1px solid var(--border-glow, var(--border));
}

.pill {
  display: inline-block;
  padding: 2px 9px;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: capitalize;
  background: rgba(255, 255, 255, 0.06);
  color: var(--ink-soft);
}

.pill.status-paid,
.pill.risk-low {
  background: var(--ok-bg, rgba(16, 185, 129, 0.1));
  color: var(--brand-bright);
}

.pill.status-pending,
.pill.status-partially-paid,
.pill.risk-medium {
  background: rgba(251, 191, 36, 0.12);
  color: #fbbf24;
}

.pill.status-overdue,
.pill.risk-high,
.pill.warn {
  background: var(--err-bg);
  color: #f87171;
}

/* ── Reports + misc ─────────────────────────────────────────────────────── */

.report-row {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
}

.report-row:last-child {
  border-bottom: none;
}

.report-name {
  flex: 1 1 200px;
  font-weight: 500;
}

.report-row select,
.report-row input[type="month"] {
  padding: 8px 10px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--ink);
  font-family: inherit;
  font-size: 0.85rem;
}

.row-actions {
  display: flex;
  gap: 14px;
  flex-wrap: wrap;
  margin-top: 16px;
}

.btn-link {
  font-size: 0.88rem;
  font-weight: 500;
}

/* Pagination — the row-count line plus prev/next, shared by every portal list
   page (see templates/portal/_pager.html). The count line carries no link, so
   it stays readable on its own when there is only one page. */
.pager {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px 16px;
  margin: 4px 0 14px;
}

.pager-count {
  margin: 0;
}

.pager-links {
  display: flex;
  align-items: center;
  gap: 14px;
}

.pager-links .is-disabled {
  opacity: 0.4;
  cursor: default;
}

.faq {
  padding: 14px 0;
  border-bottom: 1px solid var(--border);
}

.faq:last-child {
  border-bottom: none;
}

.faq-q {
  font-weight: 600;
  margin-bottom: 4px;
}

.faq-a {
  color: var(--ink-soft);
  font-size: 0.92rem;
}

.empty {
  color: var(--ink-soft);
  text-align: center;
  padding: 20px;
}

/* ── Inline row editing + write forms ───────────────────────────────────── */

.banner-ok {
  background: rgba(16, 185, 129, 0.1);
  border: 1px solid rgba(16, 185, 129, 0.3);
  color: var(--brand-bright);
}

.row-edit summary {
  cursor: pointer;
  font-size: 0.82rem;
  color: var(--ink-soft);
  list-style: none;
  padding: 4px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  display: inline-block;
}

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

.row-edit summary:hover {
  border-color: var(--brand-bright-dark);
  color: #fff;
}

.row-edit[open] summary {
  margin-bottom: 12px;
}

.edit-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 12px;
  align-items: end;
}

.edit-grid label {
  display: flex;
  flex-direction: column;
  gap: 5px;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--ink-soft);
  white-space: normal;
}

.edit-grid select {
  padding: 11px 13px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--ink);
  font-family: inherit;
  font-size: 16px;
}

.edit-actions {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.danger-form {
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}

button.danger {
  background: transparent;
  border-color: rgba(239, 68, 68, 0.35);
  color: #f87171;
}

button.danger:hover {
  background: var(--err-bg);
  border-color: var(--err);
}

/* ── Assistant chat ─────────────────────────────────────────────────────── */

.resume-card {
  border-color: rgba(251, 191, 36, 0.35);
}

.chat-log {
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-height: 420px;
  overflow-y: auto;
  margin: 16px 0;
}

.chat-log:empty {
  display: none;
}

.chat-msg {
  max-width: 80%;
  padding: 10px 14px;
  border-radius: 14px;
  font-size: 0.92rem;
  line-height: 1.55;
  /* Replies are plain text built with \n line breaks (the same strings
     WhatsApp receives), so preserve them without turning the text into
     markup. */
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.chat-user {
  align-self: flex-end;
  background: var(--brand-dark);
  color: #fff;
  border-bottom-right-radius: 4px;
}

.chat-assistant {
  align-self: flex-start;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--border);
  border-bottom-left-radius: 4px;
}

.chat-pending {
  color: var(--ink-faint);
}

.chat-refresh {
  align-self: center;
  font-size: 0.85rem;
}

.chat-suggestions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 12px;
}

.chip {
  padding: 6px 12px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.03);
  color: var(--ink-soft);
  font-size: 0.82rem;
  cursor: pointer;
}

.chip:hover {
  border-color: var(--brand-bright-dark);
  color: #fff;
}

.chat-form {
  display: flex;
  gap: 10px;
}

.chat-form input {
  flex: 1;
}

/* ── Small screens ──────────────────────────────────────────────────────── */

@media (max-width: 640px) {
  .wrap {
    padding: 16px 14px 48px;
  }

  .card {
    padding: 18px 16px;
  }

  .auth-card {
    margin: 24px auto;
    padding: 24px 20px;
  }

  .topbar-company {
    display: none;
  }

  .tiles {
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
  }

  .tile {
    padding: 14px;
  }

  .tile-value {
    font-size: 1.2rem;
  }

  /* Tables become stacked cards: each cell gets its column name from the
     data-label the templates already set, so nothing needs a second markup
     path for mobile. */
  thead {
    display: none;
  }

  table,
  tbody,
  tr,
  td {
    display: block;
    width: 100%;
  }

  tr {
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    margin-bottom: 10px;
    padding: 4px 0;
  }

  td {
    display: flex;
    justify-content: space-between;
    gap: 16px;
    border-bottom: none;
    padding: 6px 12px;
    white-space: normal;
  }

  td.num {
    text-align: right;
  }

  td::before {
    content: attr(data-label);
    color: var(--ink-faint);
    font-size: 0.78rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    flex-shrink: 0;
  }

  td.empty::before {
    content: none;
  }
}
