/* Reusable UI components: buttons, banners, product rows, stat cards, tables,
   pills, forecast table, modal, empty/loading states. Light Zavation branding -
   colors come from tokens.css, never hardcoded here. */

/* Buttons */
.submit-btn {
  width: 100%; background: var(--zv-red); border: none; color: #fff; border-radius: 6px;
  padding: 13px; font-size: 12px; font-family: var(--font-body); font-weight: 700;
  letter-spacing: 0.1em; text-transform: uppercase; cursor: pointer;
  transition: background 0.15s, box-shadow 0.15s;
}
.submit-btn:hover { background: var(--zv-red-hover); }
.submit-btn:focus-visible { outline: 2px solid var(--zv-red-deep); outline-offset: 2px; }
.submit-btn:disabled { background: var(--panel-2); color: var(--faint); cursor: not-allowed; }
.submit-btn.secondary {
  background: var(--panel); border: 1px solid var(--border); color: var(--text-strong);
}
.submit-btn.secondary:hover { background: var(--panel-2); }

/* Error banner */
.error-banner {
  background: var(--zv-red-wash); border: 1px solid var(--zv-red); border-radius: 5px;
  padding: 10px 14px; margin-bottom: 18px; font-size: 12px; color: var(--zv-red-deep); display: none;
}
.error-banner.visible { display: block; }

/* Success / info banner (e.g. password-reset sent) */
.login-ok {
  background: #e9f5ee; border: 1px solid var(--accent-green); border-radius: 5px;
  padding: 10px 14px; margin-bottom: 18px; font-size: 12px; color: var(--accent-green); display: none;
}
.login-ok.visible { display: block; }

/* Inline text link button (e.g. "Forgot password?") */
.link-btn {
  background: none; border: none; color: var(--zv-blue); font-size: 12px; letter-spacing: 0.02em;
  cursor: pointer; margin-top: 14px; padding: 4px; width: 100%; text-align: center;
}
.link-btn:hover { color: var(--zv-blue-hover); text-decoration: underline; }

/* Case Schedule weeks (Feature 3) */
.cs-week { margin-bottom: 20px; }
.cs-week-current { border-left: 3px solid var(--zv-blue); padding-left: 12px; margin-left: -15px; }
.cs-week-title {
  font-size: 11px; letter-spacing: 0.08em; text-transform: uppercase; color: var(--zv-blue);
  font-weight: 700; margin-bottom: 8px; display: flex; align-items: center; gap: 10px;
}
.cs-week-count {
  background: var(--zv-blue-wash); color: var(--zv-blue); border-radius: 10px;
  padding: 1px 9px; font-size: 10px; font-weight: 700;
}

/* Win/Loss analysis (Feature 2) */
.winloss { background: var(--panel); border: 1px solid var(--border); border-radius: 8px; padding: 18px; }
.winloss-stats { display: flex; gap: 28px; margin-bottom: 18px; }
.winloss-stat { text-align: center; }
.wl-num { font-size: 26px; line-height: 1; }
.wl-lbl { font-size: 9px; letter-spacing: 0.1em; text-transform: uppercase; color: var(--muted); margin-top: 4px; }
.winloss-cols { display: grid; grid-template-columns: 1fr 1fr; gap: 24px; }
.wl-subtitle { font-size: 10px; letter-spacing: 0.1em; text-transform: uppercase; color: var(--muted); font-weight: 700; margin-bottom: 10px; }
.wl-row { margin-bottom: 10px; }
.wl-row-top { display: flex; justify-content: space-between; font-size: 12px; color: var(--text); margin-bottom: 4px; }
.wl-count { color: var(--muted); }
.wl-track { height: 6px; background: var(--panel-2); border-radius: 3px; overflow: hidden; }
.wl-fill { height: 100%; background: var(--zv-red); border-radius: 3px; }
.wl-muted { font-size: 12px; color: var(--muted); }
@media (max-width: 640px) { .winloss-cols { grid-template-columns: 1fr; } }

/* Inline filter toggle (e.g. "Show stalled only") */
.filter-toggle {
  display: inline-flex; align-items: center; gap: 6px; font-size: 12px; color: var(--text);
  letter-spacing: 0.02em; cursor: pointer; white-space: nowrap;
}
.filter-toggle input { width: auto; margin: 0; cursor: pointer; accent-color: var(--zv-red); }

/* Multi-product rows */
.product-row {
  background: var(--panel-2); border: 1px solid var(--border); border-radius: 6px; padding: 12px;
  margin-bottom: 8px; display: grid; grid-template-columns: 2fr 1fr 28px; gap: 10px; align-items: end;
}
.remove-btn {
  background: var(--panel); border: 1px solid var(--border); color: var(--muted); border-radius: 4px;
  width: 28px; height: 38px; cursor: pointer; font-size: 14px; font-family: inherit;
}
.remove-btn:hover { color: var(--zv-red); border-color: var(--zv-red); }
.add-product-btn {
  background: transparent; border: 1px dashed var(--zv-red); color: var(--zv-red); border-radius: 5px;
  padding: 8px; width: 100%; font-size: 10px; font-family: inherit; font-weight: 700; cursor: pointer;
  letter-spacing: 0.1em; text-transform: uppercase; margin-top: 4px;
}
.add-product-btn:hover { background: var(--zv-red-wash); }

/* Stat cards */
.stat-card {
  background: var(--panel); border: 1px solid var(--border); border-radius: 7px; padding: 16px 20px;
  flex: 1; min-width: 140px; position: relative; overflow: hidden; box-shadow: var(--shadow-sm);
}
.stat-accent { position: absolute; top: 0; left: 0; width: 3px; height: 100%; border-radius: 2px 0 0 2px; }
.stat-label {
  font-size: 10px; color: var(--muted); font-weight: 700; letter-spacing: 0.1em;
  margin-bottom: 5px; text-transform: uppercase;
}
.stat-value { font-size: 24px; color: var(--text-bright); line-height: 1; }
.stat-sub { font-size: 10px; color: var(--muted); margin-top: 4px; font-weight: 600; }

/* Table */
.table-wrap {
  border: 1px solid var(--border); border-radius: 7px; overflow: hidden; overflow-x: auto;
  background: var(--panel);
}
table { width: 100%; border-collapse: collapse; min-width: 900px; }
th {
  padding: 10px 12px; font-size: 9px; font-weight: 700; letter-spacing: 0.09em; color: var(--muted);
  text-align: left; cursor: pointer; user-select: none; text-transform: uppercase; white-space: nowrap;
  border-bottom: 1px solid var(--border); background: var(--panel-2);
}
th:hover { color: var(--zv-red); }
td { padding: 10px 12px; font-size: 12px; color: var(--text); border-bottom: 1px solid var(--border-soft); vertical-align: middle; }
tbody tr:nth-child(even) td { background: var(--row-alt); }
tbody tr:hover td { background: var(--row-hover); }

/* Pills, stage colors are supplied inline from config/stages.json */
.pill {
  display: inline-flex; align-items: center; gap: 5px; border-radius: 3px; padding: 2px 8px;
  font-size: 9px; font-weight: 700; letter-spacing: 0.06em; white-space: nowrap; text-transform: uppercase;
}
.pill .dot { width: 5px; height: 5px; border-radius: 50%; }

/* Forecast table */
.forecast-table { font-size: 11px; }
.forecast-table th { background: var(--panel-2); }
.forecast-table td.metric { color: var(--text-bright); }
.forecast-table td.month-cell { text-align: right; color: var(--muted); }
.forecast-table tr.total-row td { background: var(--zv-red-wash); color: var(--zv-red-deep); font-weight: 700; }
.forecast-table td.rep-cell { color: var(--text-strong); font-weight: 600; }
.forecast-table td.product-cell { color: var(--text-strong); }

/* Modal */
.modal-bg {
  position: fixed; inset: 0; background: rgba(16, 24, 40, 0.45); display: none;
  align-items: center; justify-content: center; z-index: 100; padding: 20px;
}
.modal-bg.visible { display: flex; }
.modal {
  background: var(--panel); border: 1px solid var(--border); border-top: 3px solid var(--zv-red);
  border-radius: 10px; padding: 24px; max-width: 520px; width: 100%; max-height: 90vh;
  overflow-y: auto; box-shadow: var(--shadow-md);
}
.modal-title { font-family: var(--font-display); font-size: 16px; font-weight: 700; color: var(--text-bright); margin-bottom: 4px; }
.modal-sub { font-size: 11px; color: var(--muted); letter-spacing: 0.04em; margin-bottom: 20px; }
.modal-btns { display: flex; gap: 8px; margin-top: 18px; }
.modal-btns button { flex: 1; }

/* States */
.empty { text-align: center; padding: 60px 20px; color: var(--muted); font-size: 12px; letter-spacing: 0.06em; }
.loading { text-align: center; padding: 40px; color: var(--muted); font-size: 12px; letter-spacing: 0.1em; }

/* Product combobox (type-ahead) */
.combo { position: relative; }
.combo-panel {
  position: absolute; top: 100%; left: 0; right: 0; z-index: 30; margin-top: 2px;
  background: var(--panel); border: 1px solid var(--border); border-radius: 6px; max-height: 300px;
  overflow-y: auto; box-shadow: var(--shadow-md);
}
.combo-head {
  font-size: 9px; letter-spacing: 0.1em; text-transform: uppercase; color: var(--zv-red);
  font-weight: 700; padding: 9px 12px 4px; position: sticky; top: 0; background: var(--panel);
  border-bottom: 1px solid var(--border-soft);
}
.combo-item {
  display: flex; justify-content: space-between; align-items: center; gap: 10px;
  padding: 7px 12px; cursor: pointer; font-size: 13px; color: var(--text-strong);
}
.combo-item:hover, .combo-item.active { background: var(--zv-red-wash); }
.combo-name { font-weight: 600; }
.combo-tag { font-size: 9px; color: var(--muted); letter-spacing: 0.06em; text-transform: uppercase; white-space: nowrap; }
.combo-sunset { opacity: 0.55; }
.combo-empty { padding: 12px; color: var(--muted); font-size: 12px; }

/* ---------- Intelligence tabs (Surgeon | Industry) ---------- */
.intel-tabbar { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 22px; border-bottom: 1px solid var(--border); padding-bottom: 12px; }
.intel-tab {
  background: none; border: 1px solid var(--border); color: var(--muted); border-radius: 6px;
  padding: 9px 16px; font-family: inherit; font-size: 10px; font-weight: 700; letter-spacing: 0.09em;
  text-transform: uppercase; cursor: pointer; transition: all 0.15s;
}
.intel-tab:hover { color: var(--text-strong); border-color: var(--muted-2); }
.intel-tab.active { background: var(--zv-red-wash); border-color: var(--zv-red); color: var(--zv-red-deep); }

/* First Case Communication form link (styled as a button inside the edit modal) */
.first-case-link { display: block; margin-top: 12px; text-align: center; text-decoration: none; box-sizing: border-box; }

/* ---------- Product (PM) view highlights ---------- */
/* Notes and Custom Needed are what Product Managers are actually here to read,
   so they get lifted out of the muted table treatment. */
.pm-note {
  color: var(--text-strong); background: #fdf8ec; border-left: 2px solid var(--accent-amber);
  padding: 6px 9px; border-radius: 3px; font-size: 12px; line-height: 1.5; white-space: pre-wrap;
}
.pm-note.empty-note { color: var(--muted); background: none; border-left-color: var(--border); font-style: italic; }
.pm-custom {
  color: var(--zv-red-deep); background: var(--zv-red-wash); border: 1px solid var(--zv-red);
  border-radius: 3px; padding: 3px 8px; font-size: 10px; font-weight: 700; letter-spacing: 0.05em;
  display: inline-block;
}
.pm-flagrow td { background: var(--zv-red-wash); }
.pm-flagrow:hover td { background: #fbe0e6; }

/* Comment thread */
.cmt { border-left: 2px solid var(--border); padding: 6px 10px; margin-bottom: 8px; }
.cmt-meta { font-size: 9px; color: var(--muted); letter-spacing: 0.06em; text-transform: uppercase; margin-bottom: 3px; font-weight: 700; }
.cmt-body { font-size: 12px; color: var(--text); line-height: 1.5; white-space: pre-wrap; }

/* ---------- Industry Intelligence brief ---------- */
.intel-brief { color: var(--text); font-size: 14px; line-height: 1.7; max-width: 900px; }
.intel-brief h2 {
  font-family: var(--font-display); font-size: 14px; color: var(--zv-red);
  letter-spacing: 0.05em; text-transform: uppercase; margin: 22px 0 8px;
}
.intel-brief h3 { font-size: 13px; color: var(--text-strong); margin: 16px 0 6px; }
.intel-brief ul { margin: 0 0 12px 18px; }
.intel-brief li { margin-bottom: 7px; }
.intel-brief a { color: var(--zv-blue); text-decoration: none; }
.intel-brief a:hover { text-decoration: underline; }
.intel-brief strong { color: var(--text-bright); }
.intel-cat {
  font-size: 9px; letter-spacing: 0.09em; text-transform: uppercase; color: var(--zv-red);
  font-weight: 700; border: 1px solid var(--zv-red); border-radius: 3px; padding: 2px 7px;
  display: inline-block; margin-right: 8px;
}
.intel-meta { font-size: 10px; color: var(--muted); letter-spacing: 0.05em; }

/* Read-only users (PMs, including leadership viewers, and read-only company-view members
   such as the IT director, migration 026) read every deal but cannot write one, so the EDIT
   column and Speak an update are not offered to them. Set on <body> by auth.showApp. */
body.read-only .edit-col,
body.read-only #homeVoice { display: none; }

/* Starting month + starting year (migrations 010, 011). The year is a plain dropdown,
   narrow and fixed width; the month takes the rest of the row. */
.month-year { display: flex; gap: 8px; align-items: stretch; }
.month-year select { flex: 1; min-width: 0; }
/* A fixed width, not flex-basis auto: every select is width:100% (styles/base.css), so
   "auto" made the year take the whole row and crushed the month down to its arrow. */
.month-year select.year-select { flex: 0 0 96px; width: 96px; }

/* Reporting period (this year / next year / next 12 months), shared by every forecast view. */
.period-select { min-width: 150px; }
.year-tag {
  display: inline-block; margin-left: 4px; padding: 0 5px; border-radius: 3px;
  background: var(--zv-blue-wash); color: var(--zv-blue); font-size: 10px; font-weight: 700;
}
/* "1st case": the line's start comes from its first case date, not the deal's month. */
.start-note { margin-left: 4px; color: var(--muted); font-size: 10px; white-space: nowrap; }

/* ---------- Wide tables on a phone ----------
   One treatment for every table: the first column (the name) stays put while the rest
   scrolls sideways under it, and the right edge fades while there is more to see
   (src/core/tableScroll.js sets .scrollable and .at-end). Tables that end in a Total
   column (Dashboard, Forecast, Manager forecast) pin that column too, so the name and
   its total always show together without scrolling. */
@media (max-width: 767px) {
  .table-wrap > table > * > tr > :first-child:not([colspan]) {
    position: sticky; left: 0; z-index: 1;
    background: var(--panel); box-shadow: 1px 0 0 var(--border);
    width: 130px; min-width: 130px; max-width: 130px; white-space: normal; overflow-wrap: anywhere;
  }
  .table-wrap > table > thead > tr > :first-child:not([colspan]) { background: var(--panel-2); z-index: 2; }
  .table-wrap > table > tbody > tr:nth-child(even) > :first-child:not([colspan]) { background: var(--row-alt); }
  .table-wrap > table > tbody > tr.pm-flagrow > :first-child { background: var(--zv-red-wash); }

  /* Month tables hold short numbers, so they size to them instead of the 900px desktop floor. */
  .table-wrap > table.forecast-table { width: max-content; min-width: 100%; }
  .table-wrap > table.forecast-table > * > tr > :last-child:not([colspan]) {
    position: sticky; right: 0; z-index: 1;
    background: var(--panel); box-shadow: -1px 0 0 var(--border);
  }
  .table-wrap > table.forecast-table > thead > tr > :last-child { background: var(--panel-2); z-index: 2; }
  .table-wrap > table.forecast-table > tbody > tr:nth-child(even) > :last-child:not([colspan]) { background: var(--row-alt); }
  .table-wrap > table.forecast-table > * > tr.total-row > td { background: var(--zv-red-wash); }

  .table-wrap.scrollable:not(.at-end):not(:has(> table.forecast-table)) {
    -webkit-mask-image: linear-gradient(to right, #000 calc(100% - 36px), rgba(0, 0, 0, 0.2));
    mask-image: linear-gradient(to right, #000 calc(100% - 36px), rgba(0, 0, 0, 0.2));
  }

  /* Nothing on a screen may widen the page: the fixed bottom bar is sized to the page, so
     an overflow pushes More off the edge. clip, not hidden, so sticky headers still work. */
  .screen { overflow-x: clip; }
}

/* Product view on a phone: a long note wrapped in a narrow column into a very tall row,
   and with that column off to the right, the visible cells sat centered in a blank band.
   Notes get a readable width and show three lines until tapped (src/screens/pmView.js),
   and every cell reads from the top. Desktop is unchanged. */
@media (max-width: 767px) {
  #pmTable td { vertical-align: top; }
  #pmTable .pm-note { min-width: 240px; display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 3; overflow: hidden; cursor: pointer; }
  #pmTable .pm-note.expanded { display: block; -webkit-line-clamp: unset; }
}

/* Sales: shown until the sales history arrives, in place of empty menus and sections. */
#screen-sales .sales-loading { display: none; }
#screen-sales.is-loading .sales-loading { display: block; }
#screen-sales.is-loading > :not(.sales-loading) { display: none; }

/* Order lines: status ticks, sortable headings, monthly totals */
.so-check { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; color: var(--text); }
.so-check input { width: auto; padding: 0; }
.so-sort { background: none; border: 0; padding: 0; font: inherit; color: inherit; cursor: pointer; text-align: left; white-space: nowrap; }
.section-sub { margin: 0 0 12px; }
.section-sub > summary { cursor: pointer; font-size: 12px; font-weight: 700; color: var(--muted); letter-spacing: 0.06em; text-transform: uppercase; margin-bottom: 8px; }
