*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
body { font-family: system-ui, -apple-system, sans-serif; background: #f3f4f6; color: #111827; }

/* ── Landing ── */
#landing {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  min-height: 100vh;
  padding: 14vh 1rem 2rem;
  gap: 1rem;
}
#landing h1 { font-size: 2rem; font-weight: 700; margin-bottom: 0.5rem; }
#landing p { color: #6b7280; margin-bottom: 1rem; }
/* Plain text, not UI: no I-beam, no selection. Also keeps the hidden Ctrl+click
   on the title from painting a selection. */
#landing h1, #landing p { user-select: none; cursor: default; }

/* ── Editor / Admin ── */
#editor, #admin { display: none; padding: 1.25rem; max-width: 1100px; margin: 0 auto; }
/* Add-row sits above its list, so the two need breathing room between them. */
#admin .settings-add { margin-bottom: 0.9rem; }
#admin .settings-add input { padding: 0.5rem 0.65rem; }
/* Two of these stack in the admin view — 45vh each overflowed the window and gave the
   page its own scrollbar on top of the lists'. */
#admin .settings-list { max-height: clamp(140px, 26vh, 320px); }
#admin .settings-item { padding: 0.55rem 0.75rem; }

/* ── Editor header ── */
.editor-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
  margin-bottom: 1rem;
}
/* The report name is the headline here; Back sits at the far right of the header. */
.editor-title { display: flex; align-items: center; gap: 0.6rem; min-width: 0; }
.btn-back { flex: none; }
.report-name {
  font-size: 1.25rem;
  font-weight: 700;
  color: #111827;
  cursor: pointer;
  border-bottom: 1px dashed #d1d5db;
}
.report-name:hover { color: #2563eb; border-bottom-color: #2563eb; }
.report-name.unnamed { color: #9ca3af; font-style: italic; }
.editor-header-actions { display: flex; gap: 0.5rem; flex-wrap: wrap; justify-content: flex-end; align-items: center; }
/* Ambient confirmation for a successful save — failures get a modal instead, since
   they need acknowledging. */
.save-status {
  font-size: 0.85rem;
  color: #059669;
  opacity: 0;
  transition: opacity 0.3s;
}
.save-status.show { opacity: 1; }
/* Persistent, unlike .save-status — it stands until the settings actually reach the server. */
.unsynced-notice { font-size: 0.85rem; color: #b45309; margin-right: auto; }

/* ── Merge modal ── */
.merge-intro { color: #6b7280; font-size: 0.9rem; margin-bottom: 0.9rem; }
.merge-heading { font-size: 0.95rem; margin: 0.9rem 0 0.4rem; }
.merge-heading:first-child { margin-top: 0; }
.merge-opt { display: flex; align-items: center; gap: 0.4rem; cursor: pointer; }
.merge-note { color: #6b7280; font-size: 0.8rem; }
.merge-conflict { display: block; }
.merge-opts { display: flex; flex-direction: column; gap: 0.2rem; margin-top: 0.3rem; }

/* ── Buttons ── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.55rem 1.1rem;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.95rem;
  font-weight: 500;
  background: #2563eb;
  color: #fff;
  text-decoration: none;
  transition: background 0.15s;
}
.btn:hover { background: #1d4ed8; }
/* Nothing to save — say so rather than accepting a click that does nothing. */
.btn:disabled { opacity: 0.45; cursor: default; }
.btn:disabled:hover { background: #2563eb; }
.btn-secondary:disabled:hover { background: #6b7280; }
.btn-secondary { background: #6b7280; }
.btn-secondary:hover { background: #4b5563; }
.btn-danger { background: #dc2626; }
.btn-danger:hover { background: #b91c1c; }
.btn-sm { padding: 0.25rem 0.6rem; font-size: 0.8rem; }
.btn-outline {
  background: transparent;
  border: 2px solid #2563eb;
  color: #2563eb;
}
.btn-outline:hover { background: #eff6ff; }
.btn-icon { padding: 0.45rem 0.65rem; font-size: 1rem; }

/* ── Form card ── */
.card {
  background: #fff;
  border-radius: 10px;
  box-shadow: 0 1px 4px rgba(0,0,0,0.08);
  padding: 1.25rem;
  margin-bottom: 1rem;
}
.card-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 1rem; }
.card-header h2 { font-size: 1rem; font-weight: 600; color: #374151; }

.form-cols { display: flex; gap: 1.5rem; margin-bottom: 0.9rem; }
.form-col { flex: 1; display: flex; flex-direction: column; gap: 0.75rem; }
.form-row { display: flex; gap: 0.75rem; }
.form-row .form-group { flex: 1; }
.form-group label {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.8rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: #6b7280;
  margin-bottom: 0.3rem;
}
.form-group input {
  width: 100%;
  padding: 0.45rem 0.6rem;
  border: 1px solid #d1d5db;
  border-radius: 5px;
  font-size: 0.95rem;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.form-group input:focus {
  outline: none;
  border-color: #2563eb;
  box-shadow: 0 0 0 3px rgba(37,99,235,0.15);
}
.form-group input[readonly] { background: #f9fafb; color: #6b7280; }
.form-actions { display: flex; gap: 0.5rem; flex-wrap: wrap; justify-content: flex-end; align-items: center; }
.form-col .form-actions { margin-top: auto; padding-top: 0.25rem; }

/* ── Toolbar ── */
.toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.75rem;
}
.row-count { font-size: 0.875rem; color: #6b7280; }

/* ── Table ── */
.table-wrap {
  background: #fff;
  border-radius: 10px;
  box-shadow: 0 1px 4px rgba(0,0,0,0.08);
  overflow-x: auto;
}
table { width: 100%; border-collapse: collapse; }
/* Item soaks up all the slack the hidden Price/Count columns used to take; the rest
   are white-space: nowrap, so they only ever get what their content needs. */
#th-item { width: 100%; }
/* Date and Category read as one token each — wrapping them just to buy Item a few
   more pixels makes the table harder to scan. */
tbody td:first-child, tbody td:nth-child(3) { white-space: nowrap; }
thead th {
  background: #f9fafb;
  border-bottom: 2px solid #e5e7eb;
  padding: 0.6rem 0.85rem;
  text-align: left;
  font-size: 0.78rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: #6b7280;
  white-space: nowrap;
}
tbody td {
  padding: 0.55rem 0.85rem;
  border-bottom: 1px solid #f3f4f6;
  font-size: 0.9rem;
}
tbody tr:last-child td { border-bottom: none; }
tfoot td {
  padding: 0.6rem 0.85rem;
  border-top: 2px solid #e5e7eb;
  background: #f9fafb;
  font-size: 0.85rem;
  font-weight: 600;
  color: #374151;
}
tbody tr:hover td { background: #f9fafb; }
tbody tr.editing td { background: #eff6ff; }
.action-btns { display: flex; gap: 0.35rem; }
.action-btns .btn { padding: 0.3rem 0.45rem; }   /* icon-only: square up the btn-sm padding */
.action-btns svg { display: block; }             /* kill the inline-svg baseline gap */
thead th.th-actions { padding: 0.3rem 0.85rem; }
thead th.sortable { cursor: pointer; user-select: none; }
thead th.sortable:hover { color: #2563eb; }
thead th.sorted { color: #2563eb; }
.sort-ind { font-size: 0.7rem; }
.num { text-align: right; font-variant-numeric: tabular-nums; }
.empty-state { text-align: center; padding: 2.5rem; color: #9ca3af; font-size: 0.95rem; }

/* ── Dialog modal ── */
.modal-sm { width: 340px; }
#dialog-modal { z-index: 200; }
#dialog-message { font-size: 0.95rem; line-height: 1.55; color: #374151; }
#dialog-input {
  width: 100%;
  padding: 0.45rem 0.6rem;
  border: 1px solid #d1d5db;
  border-radius: 5px;
  font-size: 0.95rem;
}
#dialog-input:focus { outline: none; border-color: #2563eb; box-shadow: 0 0 0 3px rgba(37,99,235,0.15); }

/* ── Modal ── */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.45);
  z-index: 100;
  align-items: center;
  justify-content: center;
}
.modal-overlay.open { display: flex; }
.modal {
  background: #fff;
  border-radius: 12px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.2);
  width: 380px;
  max-width: 95vw;
  max-height: 85vh;
  display: flex;
  flex-direction: column;
}
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid #e5e7eb;
}
.modal-header h2 { font-size: 1.05rem; font-weight: 700; }
.modal-body {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  padding: 1.25rem;
  overflow-y: auto;
  flex: 1;
}
.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
  padding: 0.9rem 1.25rem;
  border-top: 1px solid #e5e7eb;
}
.settings-list {
  list-style: none;
  border: 1px solid #e5e7eb;
  border-radius: 6px;
  overflow-y: auto;
  max-height: 220px;
}
.settings-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.4rem 0.6rem;
  border-bottom: 1px solid #f3f4f6;
  gap: 0.5rem;
}
.settings-item:last-child { border-bottom: none; }
.settings-item.pickable { cursor: pointer; }
.settings-item.pickable:hover { background: #eff6ff; color: #2563eb; }
/* Suggestion dropdown under the Item/Category fields — see attachCombo(). It reuses
   .settings-list, which is where the max-height and the scrollbar come from. */
.combo { position: relative; }
.combo-list {
  position: absolute;
  z-index: 20;
  top: 100%;
  left: 0;
  right: 0;
  margin-top: 2px;
  background: #fff;
  box-shadow: 0 4px 12px rgba(0,0,0,0.12);
}
.combo-list .settings-item.active { background: #eff6ff; color: #2563eb; }
.settings-item span { font-size: 0.9rem; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.settings-item small { font-size: 0.78rem; color: #6b7280; }
.settings-add { display: flex; flex-direction: column; gap: 0.4rem; }
.settings-add-row { display: flex; gap: 0.4rem; }
.settings-add input, .settings-item input {
  flex: 1;
  padding: 0.4rem 0.55rem;
  border: 1px solid #d1d5db;
  border-radius: 5px;
  font-size: 0.9rem;
  min-width: 0;
}
.settings-add input:focus, .settings-item input:focus { outline: none; border-color: #2563eb; box-shadow: 0 0 0 2px rgba(37,99,235,0.15); }
/* An editing row is inputs where the label/price/count text was; the number fields don't
   need to be as wide as the label. */
.settings-item .edit-fields { display: flex; flex: 1; gap: 0.4rem; min-width: 0; }
.settings-item .edit-fields input[type="number"] { flex: 0 1 6rem; }
.settings-empty { padding: 1rem; text-align: center; color: #9ca3af; font-size: 0.875rem; }

/* ── Print preview ──
   The print rules live in print.css so the preview can apply them on screen. Here: the
   window they are viewed through. The sheets themselves are styled inside the iframe. */
.modal-preview { width: min(96vw, 1000px); }
.modal-preview .modal-body { padding: 0; }
.preview-toolbar {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.6rem 1.25rem;
  border-bottom: 1px solid #e5e7eb;
  flex-wrap: wrap;
}
.preview-toolbar select {
  padding: 0.3rem 0.45rem;
  border: 1px solid #d1d5db;
  border-radius: 5px;
  font-size: 0.85rem;
  background: #fff;
  min-width: 0;
}
/* The printer name is the long one — let it take the slack and truncate. */
#pv-printer { flex: 1; max-width: 20rem; }
.preview-pages { font-size: 0.8rem; color: #6b7280; margin-left: auto; }
#preview-frame {
  width: 100%;
  height: 70vh;
  border: none;
  display: block;
  background: #e5e7eb;
}
