/* Desktop UI — Stingray Accounting */

html {
  scrollbar-gutter: stable;
}

body {
  font-family: Arial, sans-serif;
  margin: 0;
  background: #f6f8fa;
  color: #111827;
}

.wrap {
  max-width: 960px;
  width: 100%;
  margin: 24px auto;
  padding: 0 16px;
  box-sizing: border-box;
}

.card {
  background: #fff;
  border: 1px solid #d1d5db;
  border-radius: 10px;
  padding: 16px;
  margin-bottom: 16px;
  overflow-x: auto;
  max-width: 100%;
  box-sizing: border-box;
}

.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.grow { flex: 1; }

input, button, select, textarea { font-size: 14px; padding: 8px 10px; box-sizing: border-box; }
input, select, textarea { border: 1px solid #9ca3af; border-radius: 6px; }
textarea { font-family: Consolas, monospace; width: 100%; resize: vertical; }

button {
  border: 1px solid #374151;
  border-radius: 6px;
  background: #111827;
  color: #fff;
  cursor: pointer;
}
button.secondary { background: #fff; color: #111827; }
button.danger { background: #b91c1c; border-color: #b91c1c; color: #fff; }
a.button { text-decoration: none; display: inline-block; }

.muted { color: #6b7280; }

.status {
  white-space: pre-wrap;
  font-family: Consolas, monospace;
  font-size: 13px;
  background: #0f172a;
  color: #d1fae5;
  padding: 12px;
  border-radius: 8px;
  max-height: 360px;
  overflow: auto;
}

table { width: 100%; border-collapse: collapse; font-size: 14px; table-layout: fixed; }
th, td {
  padding: 8px 12px;
  text-align: left;
  border-bottom: 1px solid #e5e7eb;
  vertical-align: top;
  overflow: hidden;
  text-overflow: ellipsis;
}
th { background: #f9fafb; font-weight: 600; }

.badge {
  display: inline-block;
  padding: 2px 7px;
  border-radius: 4px;
  font-size: 12px;
  font-weight: 600;
  background: #e5e7eb;
}
.badge-from    { background: #dbeafe; color: #1e40af; }
.badge-subject { background: #dcfce7; color: #166534; }
.badge-body    { background: #fef9c3; color: #92400e; }

.pat-list { font-family: Consolas, monospace; font-size: 12px; color: #374151; }
.dest-null { color: #9ca3af; font-style: italic; }

/* --- messages ---------------------------------------------------------- */

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(17, 24, 39, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
}
.modal-card {
  background: #fff;
  border: 1px solid #d1d5db;
  border-radius: 10px;
  padding: 20px 24px;
  min-width: 260px;
  text-align: center;
  box-shadow: 0 10px 30px rgba(17, 24, 39, 0.18);
}
.modal-card p { margin: 0 0 16px; font-size: 15px; }
a.modal-ok {
  display: inline-block;
  border: 1px solid #374151;
  border-radius: 6px;
  background: #111827;
  color: #fff;
  text-decoration: none;
  padding: 8px 16px;
  font-size: 14px;
}
.msg-ok    { color: #065f46; }
.msg-error { color: #b91c1c; }
.msg-info  { color: #2563eb; }
.inline-error { color: #b91c1c; font-size: 14px; margin-left: 10px; }

/* --- page header ------------------------------------------------------- */

.page-head {
  padding: 10px 16px;
}
.page-head-bar {
  align-items: center;
  gap: 12px;
  margin: 0;
}
.page-title {
  margin: 0;
  font-size: 1.25rem;
  font-weight: 700;
  flex: 1;
  min-width: 12rem;
}
.page-company {
  margin: 4px 0 0 0;
  font-size: 1.15rem;
  font-weight: 700;
  color: #111827;
}
.page-head-sub {
  align-items: center;
  gap: 8px;
  margin-top: 4px;
}
.page-head-sub .page-company {
  margin: 0;
  flex: 1;
}
.nav { margin: 0; gap: 6px; }
.nav-user { color: #374151; }
button.nav-active { border-color: #2563eb; color: #2563eb; }

/* --- forms ------------------------------------------------------------- */

.field { display: block; }
.field-label { font-size: 12px; color: #6b7280; }
.field-input { margin-top: 4px; }
.field-label-strong {
  display: block;
  margin-bottom: 4px;
  font-size: 13px;
  color: #9ca3af;
}
.stack > .row + .row { margin-top: 8px; }
.form-actions { margin-top: 12px; }

.entry-form {
  max-width: 36rem;
}
.entry-form .entry-row {
  display: grid;
  grid-template-columns: 9rem minmax(0, 1fr);
  align-items: center;
  column-gap: 12px;
  margin-top: 8px;
}
.entry-form .entry-row:first-of-type { margin-top: 0; }
.entry-form .field-label-strong {
  margin-bottom: 0;
  text-align: left;
}
.entry-form .entry-row input,
.entry-form .entry-row select,
.entry-form .entry-row textarea {
  width: 100%;
  max-width: 28rem;
  justify-self: start;
  text-align: left;
}
.entry-form .form-actions {
  display: flex;
  justify-content: flex-start;
}
.rule-form-row { align-items: flex-start; gap: 12px; flex-wrap: nowrap; }
.rule-dest { min-width: 180px; }
.rule-dest input { margin-top: 4px; width: 100%; }
.checkbox-label { display: flex; align-items: center; gap: 8px; cursor: pointer; }
.checkbox-label input { width: auto; margin: 0; }

.settings-table { border-collapse: collapse; width: 100%; }
.settings-table td { border-bottom: none; }
.settings-table .label {
  padding: 5px 12px 5px 0;
  white-space: nowrap;
  color: #9ca3af;
  font-size: 13px;
}
.settings-table .label-first { width: 120px; }
.settings-table .value { padding: 4px 0; }
.settings-table .value input { width: 100%; }
.settings-table .value input.port { width: 80px; }

/* --- tables ------------------------------------------------------------ */

.col-num   { width: 32px; }
.col-field { width: 80px; }
.col-actions { width: 130px; }
.col-money { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
.row-index { color: #9ca3af; font-size: 12px; }
.nowrap { white-space: nowrap; }
button.btn-sm, a.btn-sm { font-size: 12px; padding: 4px 8px; }
th.row-actions, td.row-actions {
  width: 112px;
  text-align: right;
  overflow: visible;
  white-space: nowrap;
  vertical-align: middle;
}
form.inline { display: inline-flex; vertical-align: middle; }
a.icon-btn, button.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  padding: 0;
  box-sizing: border-box;
  vertical-align: middle;
}
a.icon-btn {
  border: 1px solid #374151;
  border-radius: 6px;
  background: #fff;
  color: #111827;
  text-decoration: none;
}
a.icon-btn svg, button.icon-btn svg { width: 16px; height: 16px; display: block; }
button.icon-btn-delete {
  margin-left: 6px;
  background: #fff;
  color: #dc2626;
  border-color: #dc2626;
}
a.icon-btn-email { margin-left: 6px; }
.letter-actions { display: flex; gap: 8px; margin: 0 0 14px; }
.entry-form .email-entry {
  display: block;
}
.email-editor-head {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 8px;
}
.entry-form .email-editor-head .field-label-strong {
  margin-bottom: 0;
}
.entry-form .email-editor-head select {
  width: auto;
  max-width: 14rem;
  margin-left: auto;
}
.entry-form .email-entry .jodit-container,
.note-editor .jodit-container {
  max-width: none;
}

/* --- rules page -------------------------------------------------------- */

.section-head {
  align-items: center;
  margin-bottom: 12px;
  gap: 12px;
  width: 100%;
}
.section-head h3 { margin: 0; }
.section-head-actions {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}
.lookup-label {
  font-size: 14px;
  font-weight: 700;
  color: #111827;
  white-space: nowrap;
}
#payeeLookup, #donorLookup { width: 200px; }
tr.list-highlight td, tr.payee-highlight td { background: #dbeafe; }
.mobile-card.list-highlight { outline: 2px solid #2563eb; }
#ruleSearch { flex: 1; max-width: 360px; }
.no-match { display: none; color: #6b7280; font-style: italic; margin-top: 8px; }
.expand-btn {
  display: none;
  margin-top: 10px;
  background: none;
  border: 1px solid #4b5563;
  color: #9ca3af;
  font-size: 13px;
  padding: 5px 14px;
  border-radius: 6px;
  cursor: pointer;
}

/* --- processing page --------------------------------------------------- */

.autorun-row { align-items: center; gap: 12px; }
.autorun-row label { font-size: 14px; }
#intervalInput { width: 70px; }
#autoRunStatus { font-size: 13px; }
.status-head { align-items: center; margin-bottom: 8px; }
.status-head h3 { margin: 0; }
#runState { margin-right: auto; font-size: 13px; }

/* --- reports ----------------------------------------------------------- */

.report-company {
  margin: 0 0 4px 0;
  font-size: 13px;
  color: #6b7280;
}
.report-title { margin: 0 0 4px 0; }
.report-date { margin: 0 0 16px 0; }
.report-count { margin: 12px 0 0 0; }
.report-table th { white-space: nowrap; }

@media print {
  body { background: #fff; }
  .wrap { max-width: none; margin: 0; padding: 0; }
  .no-print { display: none !important; }
  .card {
    border: none;
    padding: 0;
    margin: 0;
  }
  .report-table th, .report-table td {
    border-bottom: 1px solid #d1d5db;
  }
}

.todo-table .col-index { width: 4.5rem; }
.todo-table .col-date { width: 4.5rem; }
.todo-table .col-priority { width: 5.5rem; }
.todo-table .col-done { width: 3.5rem; }
.todo-table td.todo-desc {
  white-space: normal;
  overflow: visible;
  text-overflow: clip;
}
.todo-done {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 400;
}

.sheet-scroll { overflow-x: auto; }
.sheet-status { min-height: 1.2em; margin: 0 0 8px; }
.sheet-status-error { color: #b91c1c; }
.todo-sheet { table-layout: auto; }
.todo-sheet th[data-sort] { cursor: pointer; user-select: none; white-space: nowrap; }
.todo-sheet th .sort-mark { color: #2563eb; font-size: 12px; }
.todo-sheet td { padding: 0; overflow: visible; }
.todo-sheet input {
  width: 100%;
  border: 1px solid transparent;
  background: transparent;
  border-radius: 0;
  padding: 8px;
}
.todo-sheet input:focus {
  border-color: #2563eb;
  background: #fff;
  outline: none;
}
.todo-sheet .sheet-done-cell { text-align: center; }
.todo-sheet .sheet-done-cell:focus-within {
  background: #dbeafe;
  box-shadow: inset 0 0 0 2px #2563eb;
}
.todo-sheet input[type="checkbox"] {
  width: 16px;
  height: 16px;
  margin: 8px auto;
  display: block;
  accent-color: #111827;
}
.todo-sheet input[type="checkbox"]:focus {
  outline: 2px solid #2563eb;
  outline-offset: 2px;
  background: transparent;
}
.todo-sheet tr.sheet-error input { background: #fef2f2; }
.todo-sheet .col-index { width: 4.5rem; }
.todo-sheet .col-date { width: 5rem; }
.todo-sheet .col-priority { width: 5.5rem; }
.todo-sheet .col-done { width: 3.5rem; }
.todo-sheet tr.sheet-actions th {
  background: transparent;
  border-bottom: none;
  padding: 0 0 8px;
  font-weight: 400;
}
.sheet-actions-buttons {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
}
.sheet-actions-buttons button:disabled {
  opacity: 0.45;
  cursor: default;
}
.sheet-delete-cell { width: 2.5rem; text-align: center; }
.sheet-delete {
  background: transparent;
  color: #dc2626;
  border: none;
  line-height: 1;
  padding: 4px 8px;
}
.sheet-delete svg { display: block; width: 18px; height: 18px; }
.sheet-delete:hover { color: #991b1b; }

body.sheet-screen {
  overflow: hidden;
}
body.sheet-screen .wrap {
  max-width: none;
  width: 100%;
  height: 100vh;
  height: 100dvh;
  margin: 0;
  padding: 12px 16px;
  display: flex;
  flex-direction: column;
  box-sizing: border-box;
}
body.sheet-screen .page-head {
  flex: 0 0 auto;
  margin-bottom: 8px;
}
body.sheet-screen .sheet-card {
  flex: 1 1 auto;
  min-height: 0;
  margin-bottom: 0;
  display: flex;
  flex-direction: column;
}
body.sheet-screen .section-head,
body.sheet-screen .sheet-status {
  flex: 0 0 auto;
}
body.sheet-screen .sheet-scroll {
  flex: 1 1 auto;
  min-height: 0;
  overflow: auto;
}
body.sheet-screen .todo-sheet thead {
  position: sticky;
  top: 0;
  z-index: 2;
}
body.sheet-screen .todo-sheet thead th {
  background: #f9fafb;
}
body.sheet-screen .todo-sheet tr.sheet-actions th {
  background: #fff;
}

.login-card { max-width: 22rem; }
.login-card input { width: 100%; }
.login-forgot { margin: 14px 0 0; font-size: 14px; }
.login-forgot a { color: #2563eb; }
