/* ============================================================
   styles.css - design tokens + base + dashboard + form.
   Direction: paper-white workshop ledger. Walnut is the brand
   accent (the product is wood). Space Grotesk for headings,
   IBM Plex Sans for everything else. Signature element: the
   veneer strip, a segmented per-stage progress bar on each card.
   ============================================================ */

:root {
  /* palette */
  --paper: #faf9f7;
  --card: #ffffff;
  --ink: #1c1a17;
  --muted: #6e675e;
  --line: #e4e0da;
  --walnut: #6b4226;      /* brand accent */
  --walnut-soft: #f0e7df; /* accent wash for chips/hovers */
  --advance: #2e7d4f;     /* forward action */
  --lost: #a63d2f;        /* lost / destructive */
  --won: #b8860b;         /* the Advance Recd boundary */

  /* type */
  --font-display: "Space Grotesk", sans-serif;
  --font-body: "IBM Plex Sans", sans-serif;

  /* rhythm */
  --radius: 10px;
  --gap: 16px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: var(--font-body);
  background: var(--paper);
  color: var(--ink);
  font-size: 15px;
  line-height: 1.5;
}

/* ---------- top bar ---------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  padding: 14px 20px;
  border-bottom: 2px solid var(--walnut);
  background: var(--card);
}

.brand-name {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 18px;
  letter-spacing: 0.02em;
}

.brand-sub {
  font-family: var(--font-display);
  font-weight: 500;
  font-size: 13px;
  color: var(--walnut);
  margin-left: 8px;
  text-transform: uppercase;
  letter-spacing: 0.12em;
}

.topbar-actions { display: flex; gap: 8px; }

/* ---------- buttons ---------- */
.btn {
  font-family: var(--font-body);
  font-size: 14px;
  font-weight: 600;
  border-radius: var(--radius);
  border: 1px solid transparent;
  padding: 8px 14px;
  cursor: pointer;
}
.btn:focus-visible { outline: 2px solid var(--walnut); outline-offset: 2px; }
.btn.primary { background: var(--walnut); color: #fff; }
.btn.primary:hover { background: #55341e; }
.btn.ghost { background: transparent; color: var(--ink); border-color: var(--line); }
.btn.ghost:hover { background: var(--walnut-soft); }

/* ---------- layout ---------- */
main#app {
  max-width: 960px;
  margin: 0 auto;
  padding: var(--gap);
}

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 20px;
}

h1 {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 22px;
  margin-bottom: 6px;
}

.muted { color: var(--muted); }
.small { font-size: 13px; }

/* ---------- banners ---------- */
.banner {
  border-radius: var(--radius);
  padding: 10px 14px;
  margin: var(--gap);
  font-weight: 500;
}
.banner.warn {
  background: #fbeae7;
  color: var(--lost);
  border: 1px solid var(--lost);
}

/* ---------- dashboard ---------- */
.dash-summary { margin-bottom: var(--gap); font-size: 13px; }

.stage-group { margin-bottom: 22px; }

.stage-head {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 15px;
  display: flex;
  align-items: center;
  gap: 8px;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--line);
  margin-bottom: 10px;
}
.stage-group[data-phase="won"] .stage-head { color: var(--won); }
.stage-group[data-phase="production"] .stage-head { color: var(--walnut); }

.count {
  font-family: var(--font-body);
  font-size: 12px;
  font-weight: 600;
  background: var(--walnut-soft);
  color: var(--walnut);
  border-radius: 999px;
  padding: 1px 8px;
}

.cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 10px;
}

.project-card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px 14px;
  cursor: pointer;
  transition: border-color 0.12s;
}
.project-card:hover { border-color: var(--walnut); }

.card-top {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 8px;
}

.client { font-weight: 600; }

.chip {
  font-size: 11px;
  font-weight: 600;
  white-space: nowrap;
  background: var(--walnut-soft);
  color: var(--walnut);
  border-radius: 999px;
  padding: 2px 8px;
}

.product { font-size: 13px; margin-top: 2px; }

/* ---------- veneer strip (signature) ---------- */
.veneer {
  display: flex;
  gap: 2px;
  margin-top: 10px;
}
.veneer .seg {
  flex: 1;
  height: 6px;
  border-radius: 2px;
  background: var(--line);
}
.veneer .seg.filled { background: var(--walnut); }
.veneer .seg.filled.lost { background: var(--lost); }

/* ---------- terminal sections (Lost / Dispatched) ---------- */
.terminal-section {
  margin-top: 18px;
  border-top: 1px solid var(--line);
  padding-top: 10px;
}
.terminal-section summary {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 15px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 10px;
}

/* ---------- add-project form ---------- */
.form-card { max-width: 640px; margin: 0 auto; }

.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-top: 12px;
}

.form-grid label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 13px;
  font-weight: 600;
}

.form-grid .span2 { grid-column: 1 / -1; }

.form-grid input,
.form-grid select,
.form-grid textarea {
  font-family: var(--font-body);
  font-size: 14px;
  font-weight: 400;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--paper);
}
.form-grid input:focus,
.form-grid select:focus,
.form-grid textarea:focus {
  outline: 2px solid var(--walnut);
  outline-offset: 0;
}

.tag-internal {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--won);
  border: 1px solid var(--won);
  border-radius: 4px;
  padding: 0 4px;
  margin-left: 4px;
}

.form-error {
  color: var(--lost);
  font-weight: 600;
  margin-top: 10px;
}

.form-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 16px;
}

/* ---------- empty state ---------- */
.empty { text-align: center; padding: 48px 20px; }
.empty .btn { margin-top: 12px; }

/* ---------- mobile ---------- */
@media (max-width: 600px) {
  .form-grid { grid-template-columns: 1fr; }
  .cards { grid-template-columns: 1fr; }
}

/* ============================================================
   Step 3 additions: item rows, detail view, history, notes.
   ============================================================ */

.section-head {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 15px;
  margin: 20px 0 8px;
  color: var(--walnut);
}

/* ---------- item rows in the add form ---------- */
.item-row {
  display: grid;
  grid-template-columns: 1.1fr 1.6fr 0.8fr auto;
  gap: 8px;
  margin-bottom: 8px;
}

.item-row input {
  font-family: var(--font-body);
  font-size: 14px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--paper);
}
.item-row input:focus { outline: 2px solid var(--walnut); outline-offset: 0; }

.it-remove { padding: 4px 10px; font-size: 16px; line-height: 1; }

.items-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 4px;
}

.items-total { font-size: 14px; }

.note-label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 13px;
  font-weight: 600;
  margin-top: 16px;
}
.note-label textarea {
  font-family: var(--font-body);
  font-size: 14px;
  font-weight: 400;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--paper);
}
.note-label textarea:focus { outline: 2px solid var(--walnut); outline-offset: 0; }

/* ---------- card total ---------- */
.card-mid {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 8px;
}
.card-mid .total { font-size: 13px; font-weight: 600; white-space: nowrap; }

/* ---------- detail view ---------- */
.back-btn { margin-bottom: 12px; }

.detail-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 12px;
  margin-bottom: 10px;
}

.detail-facts {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 28px;
  margin-top: 16px;
}
.detail-facts dt {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
}
.detail-facts dd { font-weight: 500; }

/* ---------- items table ---------- */
.items-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}
.items-table th, .items-table td {
  text-align: left;
  padding: 8px 10px;
  border-bottom: 1px solid var(--line);
}
.items-table th {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
}
.items-table .num { text-align: right; white-space: nowrap; }
.items-table tfoot td { border-bottom: none; padding-top: 10px; }

.delivery { margin-top: 14px; }

/* ---------- history ---------- */
.history { list-style: none; }
.hist-item {
  display: flex;
  flex-direction: column;
  padding: 8px 0 8px 14px;
  border-left: 3px solid var(--line);
  margin-bottom: 4px;
}
.hist-item[data-action="advanced"] { border-left-color: var(--advance); }
.hist-item[data-action="moved_back"] { border-left-color: var(--won); }
.hist-item[data-action="lost"] { border-left-color: var(--lost); }
.hist-action { font-weight: 600; }
.hist-meta { font-size: 12px; }
.hist-reason { font-size: 13px; font-style: italic; color: var(--muted); }

/* ---------- notes ---------- */
.note-add { display: flex; gap: 8px; margin-bottom: 10px; }
.note-add input {
  flex: 1;
  font-family: var(--font-body);
  font-size: 14px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--paper);
}
.note-add input:focus { outline: 2px solid var(--walnut); outline-offset: 0; }

.notes { list-style: none; }
.note-item {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 6px 0;
  border-bottom: 1px solid var(--line);
}

@media (max-width: 600px) {
  .item-row { grid-template-columns: 1fr 1fr; }
  .item-row .it-specs { grid-column: 1 / -1; }
  .note-item { flex-direction: column; gap: 2px; }
}

/* ============================================================
   Step 4 additions: stage action buttons + reason box.
   ============================================================ */

.stage-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 8px;
  margin-top: 14px;
  padding-top: 14px;
  border-top: 1px solid var(--line);
}

.person-pick {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
}
.person-pick select {
  font-family: var(--font-body);
  font-size: 14px;
  padding: 7px 8px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--paper);
}

.btn.advance { background: var(--advance); color: #fff; }
.btn.advance:hover { background: #256540; }
.btn.danger {
  background: transparent;
  color: var(--lost);
  border-color: var(--lost);
}
.btn.danger:hover { background: #fbeae7; }

.reason-box { margin-top: 12px; background: var(--paper); }
.reason-title { font-weight: 600; margin-bottom: 8px; }
.reason-box input {
  width: 100%;
  font-family: var(--font-body);
  font-size: 14px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--card);
}
.reason-box input:focus { outline: 2px solid var(--walnut); outline-offset: 0; }

.closed-note {
  margin-top: 14px;
  padding-top: 14px;
  border-top: 1px solid var(--line);
  font-weight: 500;
}

@media (max-width: 600px) {
  .stage-actions { flex-direction: column; align-items: stretch; }
  .stage-actions .btn { width: 100%; }
}

/* ============================================================
   Step 5 additions: search bar + type filter.
   ============================================================ */

.dash-controls {
  display: flex;
  gap: 8px;
  margin-bottom: var(--gap);
}

#dash-search {
  flex: 1;
  font-family: var(--font-body);
  font-size: 15px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--card);
}
#dash-search:focus { outline: 2px solid var(--walnut); outline-offset: 0; }

#dash-type {
  font-family: var(--font-body);
  font-size: 14px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--card);
  max-width: 40%;
}
#dash-type:focus { outline: 2px solid var(--walnut); outline-offset: 0; }

.no-match { padding: 24px 0; text-align: center; }

@media (max-width: 600px) {
  .dash-controls { flex-direction: column; }
  #dash-type { max-width: 100%; }
}

/* ============================================================
   Step 6 additions: share status box.
   ============================================================ */

.share-box {
  margin-top: 14px;
  padding-top: 14px;
  border-top: 1px solid var(--line);
}

.share-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 8px;
}

.date-toggle {
  font-size: 13px;
  color: var(--muted);
  display: flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
}

.share-actions { display: flex; flex-wrap: wrap; gap: 8px; }

.share-feedback {
  margin-top: 10px;
  font-size: 13px;
  font-weight: 500;
  color: var(--advance);
  white-space: pre-wrap;
}

@media (max-width: 600px) {
  .share-head { flex-direction: column; align-items: flex-start; gap: 6px; }
  .share-actions .btn { flex: 1; }
}

/* ============================================================
   Step 8 additions: qty/price item rows, edit button, toggles.
   ============================================================ */

/* item rows: 6 columns sized to fit inside the card.
   min-width:0 on inputs lets them shrink instead of overflowing. */
.item-row {
  grid-template-columns: minmax(0, 1.3fr) minmax(0, 1.6fr) 56px minmax(0, 1fr) auto 32px;
  align-items: center;
  gap: 6px;
}

.item-row input { min-width: 0; }        /* critical: allow shrink */
.item-row .it-qty { text-align: center; }

/* hide number spinners so the narrow qty/price columns aren't clipped */
.item-row input[type="number"]::-webkit-inner-spin-button,
.item-row input[type="number"]::-webkit-outer-spin-button {
  -webkit-appearance: none;
  margin: 0;
}
.item-row input[type="number"] { -moz-appearance: textfield; appearance: textfield; }

.item-row.item-head {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
  margin-bottom: 4px;
}
.item-row.item-head span { padding: 0 2px; }

.it-line {
  font-size: 13px;
  font-weight: 600;
  text-align: right;
  white-space: nowrap;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
}

.it-remove {
  padding: 4px 0;
  width: 32px;
  text-align: center;
}

.detail-head-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

.share-toggles {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 16px;
}

/* the form card can be a touch wider so 6 columns breathe */
.form-card { max-width: 720px; }

@media (max-width: 640px) {
  .item-row {
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    padding: 10px;
    border: 1px solid var(--line);
    border-radius: 8px;
    margin-bottom: 10px;
  }
  .item-row.item-head { display: none; }
  .item-row .it-name { grid-column: 1 / -1; }
  .item-row .it-specs { grid-column: 1 / -1; }
  .item-row .it-line { grid-column: 1 / 2; text-align: left; align-self: center; }
  .item-row .it-remove { grid-column: 2 / 3; justify-self: end; }
}

/* ============================================================
   Step 7 additions: settings (stage + team management).
   ============================================================ */

.set-list { margin: 12px 0; }

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

.set-stage-name {
  flex: 1;
  min-width: 140px;
  font-family: var(--font-body);
  font-size: 14px;
  padding: 7px 9px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--paper);
}
.set-stage-name:focus { outline: 2px solid var(--walnut); outline-offset: 0; }

.phase-tag {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  padding: 2px 7px;
  border-radius: 999px;
}
.phase-sales { background: var(--walnut-soft); color: var(--walnut); }
.phase-won { background: #f6edd4; color: var(--won); }
.phase-production { background: #e6efe9; color: var(--advance); }
.phase-terminal { background: #eee; color: var(--ink); }

.set-row-actions { display: flex; gap: 4px; }

.btn.mini { padding: 5px 9px; font-size: 12px; }

.team-name { flex: 1; font-weight: 500; }

.set-add {
  display: flex;
  gap: 8px;
  margin-top: 12px;
  flex-wrap: wrap;
}
.set-add input {
  flex: 1;
  min-width: 160px;
  font-family: var(--font-body);
  font-size: 14px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--paper);
}
.set-add input:focus { outline: 2px solid var(--walnut); outline-offset: 0; }
.set-add select {
  font-family: var(--font-body);
  font-size: 14px;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--paper);
}

.set-reassign {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  padding: 10px;
  background: #fbeae7;
  border-radius: 8px;
  margin: 6px 0;
  font-size: 13px;
}
.set-reassign select {
  font-family: var(--font-body);
  font-size: 13px;
  padding: 6px 8px;
  border: 1px solid var(--line);
  border-radius: 6px;
}

/* ============================================================
   Step 9: print sheet.
   On screen the print area is hidden. When printing, everything
   else is hidden and only #print-area shows, so the client
   gets a clean status page with no app chrome.
   ============================================================ */

#print-area { display: none; }

@media print {
  /* hide the live app entirely */
  .topbar, main#app, .banner { display: none !important; }

  /* show only the print sheet */
  #print-area {
    display: block !important;
    font-family: var(--font-body);
    color: #000;
    padding: 0;
    max-width: 100%;
  }

  body { background: #fff; }

  .print-head {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    border-bottom: 2px solid #000;
    padding-bottom: 8px;
    margin-bottom: 16px;
  }
  .print-brand {
    font-family: var(--font-display);
    font-weight: 700;
    font-size: 20px;
    letter-spacing: 0.02em;
  }
  .print-date { font-size: 12px; color: #444; }

  .print-client {
    font-family: var(--font-display);
    font-size: 24px;
    margin-bottom: 4px;
  }
  .print-stage { font-size: 15px; margin-bottom: 4px; }
  .p-muted { color: #555; font-size: 13px; }

  .print-table {
    width: 100%;
    border-collapse: collapse;
    margin: 16px 0;
    font-size: 13px;
  }
  .print-table th, .print-table td {
    text-align: left;
    padding: 7px 8px;
    border-bottom: 1px solid #ccc;
  }
  .print-table th {
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: #555;
  }
  .print-table .num { text-align: right; }
  .print-table tfoot td { border-bottom: none; border-top: 2px solid #000; padding-top: 8px; }

  .print-delivery { margin: 10px 0; font-size: 14px; }

  .print-h2 {
    font-family: var(--font-display);
    font-size: 15px;
    margin: 18px 0 6px;
    border-bottom: 1px solid #ccc;
    padding-bottom: 3px;
  }
  .print-timeline { list-style: none; padding: 0; font-size: 13px; }
  .print-timeline li { padding: 3px 0; }

  .print-foot {
    margin-top: 28px;
    padding-top: 8px;
    border-top: 1px solid #ccc;
    font-size: 11px;
    color: #777;
  }
}
