/* Multi-line expense entry — the sheet built by js/expense-multi.js.
   Loads after the inline <style> in index.html, so equal-specificity rules here
   win by source order (HANDOFF rule 7). It reuses .ev-form-backdrop,
   .ev-form-card, .form-input, .form-select and .form-label unchanged; everything
   below is the row grid and the save report. */

.xm-card { max-width: 820px; }

/* ---- where these lines came from ----
   Only rendered when the sheet was opened from a document (js/intake.js or the
   invoice detail view). Hidden entirely on the hand-entered sheet, so that one
   looks exactly as it always did. */
.xm-source {
  font-size: 0.8rem;
  line-height: 1.6;
  color: var(--sand);
  border-left: 2px solid var(--amber);
  padding: 0.15rem 0 0.15rem 0.8rem;
  margin-bottom: 1rem;
}
.xm-source[hidden] { display: none; }

/* ---- shared fields ---- */

.xm-shared {
  background: var(--glass-white);
  border: 1px solid var(--glass-border);
  border-radius: 12px;
  padding: 1rem 1.1rem;
  margin-bottom: 1.1rem;
}
.xm-shared-title {
  font-size: 0.62rem;
  letter-spacing: 3px;
  text-transform: uppercase;
  color: var(--muted);
  font-weight: 600;
  margin-bottom: 0.85rem;
}
.xm-shared-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.85rem 1rem;
}

/* ---- rows ---- */

.xm-rows { display: flex; flex-direction: column; gap: 0.7rem; }

.xm-row {
  border: 1px solid var(--glass-border);
  border-radius: 12px;
  padding: 0.7rem 0.8rem;
  background: var(--charcoal-soft);
  transition: border-color 0.15s ease, opacity 0.15s ease;
}

.xm-row-main {
  display: grid;
  /* number · amount · category · description · remove */
  grid-template-columns: 1.4rem 7.5rem 9.5rem minmax(0, 1fr) 2rem;
  gap: 0.5rem;
  align-items: center;
}

.xm-num {
  font-family: 'Fraunces', serif;
  font-size: 0.9rem;
  color: var(--muted);
  text-align: center;
}

.xm-row .form-input,
.xm-row .form-select { margin: 0; }

.xm-rowbtn {
  background: none;
  border: 1px solid var(--glass-border);
  border-radius: 8px;
  color: var(--muted);
  font-size: 0.85rem;
  line-height: 1;
  padding: 0.5rem 0;
  cursor: pointer;
}
.xm-rowbtn:hover:not(:disabled) { color: #E05A4A; border-color: rgba(224, 90, 74, 0.5); }
.xm-rowbtn:disabled { opacity: 0.3; cursor: default; }

/* ---- per-line overrides ---- */

.xm-override-toggle {
  background: none;
  border: none;
  padding: 0.45rem 0 0 1.9rem;
  font-size: 0.72rem;
  color: var(--muted);
  cursor: pointer;
  text-decoration: underline;
  text-underline-offset: 3px;
}
.xm-override-toggle:hover { color: var(--amber); }
.xm-override-toggle.xm-override-open { color: var(--amber); }

.xm-override {
  margin: 0.6rem 0 0.2rem 1.9rem;
  padding: 0.8rem 0.9rem;
  border: 1px dashed var(--glass-border);
  border-radius: 10px;
}
.xm-override-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.7rem 0.9rem;
}

/* ---- per-line outcome ---- */

.xm-row-msg { font-size: 0.75rem; line-height: 1.5; margin-left: 1.9rem; }
.xm-row-msg:empty { display: none; }
.xm-row-msg-ok { color: var(--st-booked); margin-top: 0.45rem; }
.xm-row-msg-bad { color: #E05A4A; margin-top: 0.45rem; }
/* A line the duplicate guard skipped. Amber, not red: nothing is broken and
   nothing needs doing — the money is already in the books. */
.xm-row-msg-warn { color: var(--amber); margin-top: 0.45rem; }

.xm-row-bad { border-color: rgba(224, 90, 74, 0.55); }
.xm-row-saved { opacity: 0.62; border-color: rgba(34, 197, 94, 0.4); }

/* ---- add a line ---- */

.xm-addrow {
  margin-top: 0.85rem;
  background: none;
  border: 1px dashed var(--glass-border);
  border-radius: 10px;
  color: var(--amber);
  padding: 0.65rem 1rem;
  width: 100%;
  font-size: 0.82rem;
  letter-spacing: 1px;
  cursor: pointer;
}
.xm-addrow:hover { border-color: var(--amber); background: var(--glass-white); }

/* ---- the report ---- */

.xm-report {
  margin-top: 1rem;
  font-size: 0.82rem;
  line-height: 1.6;
  border-radius: 10px;
}
.xm-report:empty { display: none; }
.xm-report-busy { color: var(--muted); padding: 0.7rem 0.9rem; }
.xm-report-warn {
  color: var(--amber);
  padding: 0.7rem 0.9rem;
  border: 1px solid var(--glass-border);
}
.xm-report-ok {
  color: var(--st-booked);
  padding: 0.7rem 0.9rem;
  border: 1px solid var(--st-booked-border);
  background: var(--st-booked-bg);
}
/* A partial failure is the one thing on this screen he must not skim past. */
.xm-report-bad {
  color: #E05A4A;
  padding: 0.85rem 1rem;
  border: 1px solid rgba(224, 90, 74, 0.5);
  background: rgba(224, 90, 74, 0.08);
}
.xm-report-list { margin: 0.6rem 0 0; padding-left: 1.2rem; }
.xm-report-list li { margin-bottom: 0.35rem; }
.xm-report-tail { margin-top: 0.7rem; color: var(--sand); }

/* The two answers to "close and lose them?", which used to be a window.confirm.
   Only the buttons are styled: .xm-report-tail also carries plain sentences in
   the partial-failure report, and turning it into a flex row for the sake of
   two buttons would reflow those. Inline-block buttons wrap on their own on a
   narrow phone, which is what matters — a question whose second answer is off
   the edge of the strip is the same failure as a dialog that never drew. */
.xm-report-tail button { margin: 0.35rem 0.4rem 0 0; }

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

.xm-footer { justify-content: space-between; align-items: center; }
.xm-total {
  font-family: 'Fraunces', serif;
  font-size: 0.95rem;
  color: var(--amber);
}
.xm-footer-btns { display: flex; gap: 10px; }

/* ---- light theme ----
   HANDOFF rule 6: --amber is roughly 2:1 on white and #E05A4A is not much
   better, so anything that is TEXT gets the darkened pair. Borders, dashes and
   fills keep the flat accent — they are not read, and they do not need it. */

body.light-theme .xm-row { background: rgba(0, 0, 0, 0.02); border-color: rgba(0, 0, 0, 0.12); }
body.light-theme .xm-shared { background: rgba(0, 0, 0, 0.02); border-color: rgba(0, 0, 0, 0.12); }
body.light-theme .xm-override { border-color: rgba(0, 0, 0, 0.18); }
body.light-theme .xm-addrow { color: #9C5C08; border-color: rgba(0, 0, 0, 0.18); }
body.light-theme .xm-override-toggle:hover,
body.light-theme .xm-override-toggle.xm-override-open { color: #9C5C08; }
body.light-theme .xm-total { color: #9C5C08; }
body.light-theme .xm-report-warn { color: #9C5C08; }
body.light-theme .xm-report-bad { color: #B03A2E; }
body.light-theme .xm-row-msg-bad { color: #B03A2E; }
body.light-theme .xm-row-msg-warn { color: #9C5C08; }
body.light-theme .xm-source { color: #3A342B; }
body.light-theme .xm-rowbtn:hover:not(:disabled) { color: #B03A2E; }
body.light-theme .xm-report-tail { color: #3A342B; }
body.light-theme .xm-row-msg-ok { color: #15803D; }
body.light-theme .xm-report-ok { color: #15803D; }

/* ---- phone ----
   Five columns do not fit 390px. Amount and category share the top line,
   description takes the next one, and the remove button stays reachable. */
@media (max-width: 640px) {
  .xm-row-main {
    grid-template-columns: 1.4rem minmax(0, 1fr) 2rem;
    grid-template-areas:
      "num amount remove"
      "num cat    cat"
      "num desc   desc";
    gap: 0.45rem 0.5rem;
    align-items: center;
  }
  .xm-num { grid-area: num; align-self: start; padding-top: 0.7rem; }
  .xm-row-main .xm-amount { grid-area: amount; }
  .xm-row-main .xm-cat { grid-area: cat; }
  .xm-row-main .xm-desc { grid-area: desc; }
  .xm-row-main .xm-remove { grid-area: remove; align-self: start; }

  .xm-shared-grid,
  .xm-override-grid { grid-template-columns: minmax(0, 1fr); }
  .xm-override { margin-left: 0; }
  .xm-override-toggle { padding-left: 0; }
  .xm-row-msg { margin-left: 0; }
  .xm-footer { flex-direction: column; align-items: stretch; }
  .xm-footer-btns { justify-content: flex-end; }
}
