/* 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;
}
.sheet-head-bar .page-title {
  flex: 0 0 auto;
  min-width: 0;
  color: #0000cd;
}
.sheet-head-bar .nav {
  margin-left: auto;
}
.sheet-head-bar .sheet-actions-buttons {
  justify-content: flex-start;
}
.sheet-head-bar .sheet-status {
  margin: 0;
  min-height: 0;
}
.sheet-filter {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-weight: 700;
  color: #111827;
  white-space: nowrap;
}
.sheet-filter input {
  width: 9rem;
  font-size: 16px;
}
.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[type="date"] {
  max-width: 11rem;
}
.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; }
.note-status {
  margin: 0;
  font-weight: 400;
  color: #6b7280;
  white-space: nowrap;
}
.note-filter {
  display: inline-flex;
  align-items: center;
  margin: 0;
}
.note-filter input {
  width: 11rem;
  font-size: 14px;
  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-group { width: 8rem; }
.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-note-cell { width: 3.4rem; text-align: center; }
.sheet-delete-cell { width: 2.8rem; text-align: center; }
.sheet-note {
  background: transparent;
  color: #1e7a43;
  border: none;
  line-height: 1;
  padding: 4px 6px;
}
.sheet-note svg { display: block; width: 18px; height: 18px; }
.sheet-note:hover { color: #14532d; }
.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; }

.time-sheet .col-client { width: 12rem; }
.time-sheet .col-hours { width: 5.5rem; }

body.sheet-screen {
  overflow: hidden;
  background: #9fe0d8;
}
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 .page-head,
body.sheet-screen .sheet-card {
  background: #e7f8f5;
  border-color: #3a9e94;
}
body.sheet-screen .todo-sheet tbody td {
  background: #c6efbf;
  border-bottom: 1px solid #2e8b57;
}
body.sheet-screen .todo-sheet thead th {
  background: #1e7a43;
  color: #fff;
  border-bottom: 1px solid #166534;
}
body.sheet-screen .todo-sheet th .sort-mark {
  color: #d1fae5;
}
body.sheet-screen .todo-sheet tr.sheet-actions th {
  background: #fff;
}

body.sheet-screen.time-screen {
  background: #ffe14a;
}
body.sheet-screen.time-screen .page-head,
body.sheet-screen.time-screen .sheet-card {
  background: #fff3a1;
  border-color: #e0b400;
}
body.sheet-screen.time-screen .todo-sheet tbody td {
  background: #ffb7d5;
  border-bottom: 1px solid #e4567a;
}
body.sheet-screen.time-screen .todo-sheet thead th {
  background: #e4567a;
  color: #fff;
  border-bottom: 1px solid #b4235a;
}

body.notes-screen {
  background: #f6e7c1;
}
body.notes-screen .page-head {
  background: #8a5a2b;
  border-color: #6e4520;
  color: #fff;
}
body.notes-screen .page-title {
  color: #0000cd;
}
body.notes-screen .page-head .sheet-filter,
body.notes-screen .page-head .sheet-status {
  color: #fff;
}
body.notes-screen .page-head .sheet-actions-buttons button:disabled {
  opacity: 1;
  background: transparent;
  color: #fff;
  border-color: #fff;
}
body.notes-screen .card:not(.page-head) {
  background: #fff8ea;
  border-color: #e2c48a;
}
body.notes-screen table .col-date {
  width: 5.5rem;
  white-space: nowrap;
}
body.notes-screen table th {
  background: #8a5a2b;
  color: #fff;
  border-bottom-color: #6e4520;
}
body.notes-screen table td {
  background: #fff8ea;
  border-bottom-color: #e2c48a;
}
body.notes-screen table a {
  color: #5c3b16;
}
body.notes-screen .jodit-wysiwyg {
  background: #fff8ea;
}
#noteDictate.note-dictate-on {
  background: #b91c1c;
  border-color: #b91c1c;
  color: #fff;
}
body.notes-screen button:disabled {
  opacity: 0.45;
  cursor: default;
}

/* iPhone. iPad stays on the wide sheet. Inputs stay 16px so iOS does not zoom. */
@media (max-width: 700px), (max-width: 940px) and (max-height: 500px) {
  body.sheet-screen .wrap {
    padding: 8px;
    padding-left: max(8px, env(safe-area-inset-left));
    padding-right: max(8px, env(safe-area-inset-right));
    padding-bottom: max(8px, env(safe-area-inset-bottom));
  }
  body.sheet-screen .sheet-head-bar .nav {
    margin-left: 0;
  }
  body.sheet-screen .sheet-filter {
    flex: 1 1 12rem;
  }
  body.sheet-screen .sheet-filter input {
    width: 100%;
    min-width: 7rem;
  }
  body.sheet-screen .todo-sheet {
    width: max-content;
    min-width: 100%;
  }
  body.sheet-screen .todo-sheet input:not([type="checkbox"]) {
    font-size: 16px;
    width: 5.5rem;
  }
  body.sheet-screen .todo-sheet input[data-field="description"] {
    width: 14rem;
  }
  body.sheet-screen .todo-sheet input[data-field="group_name"] {
    width: 8rem;
  }
  body.sheet-screen .sheet-scroll {
    overflow: auto;
    -webkit-overflow-scrolling: touch;
  }
}

.login-card { max-width: 22rem; }
.login-card input { width: 100%; }
.login-forgot { margin: 14px 0 0; font-size: 14px; }
.login-forgot a { color: #2563eb; }
