:root {
  color-scheme: light;
  --bg: #f4f6f8;
  --surface: #ffffff;
  --surface-2: #eef3f6;
  --text: #17212b;
  --muted: #64717f;
  --line: #d9e0e6;
  --income: #167a4a;
  --expense: #b33c3c;
  --balance: #1d5f93;
  --tithe: #7a4f13;
  --focus: #286f98;
  --shadow: 0 10px 30px rgba(30, 42, 54, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: Arial, "Noto Sans Hebrew", sans-serif;
}

.login-screen {
  display: grid;
  min-height: 100vh;
  place-items: center;
  padding: 20px;
}

.login-screen.hidden,
.app-locked {
  display: none;
}

.login-panel {
  display: grid;
  width: min(420px, 100%);
  gap: 16px;
  padding: 22px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.login-panel h1 {
  font-size: 1.5rem;
}

#loginMessage {
  color: var(--expense);
  min-height: 20px;
}

button,
input,
select {
  font: inherit;
}

.app-shell {
  width: min(1180px, calc(100% - 32px));
  margin: 0 auto;
  padding: 28px 0;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 22px;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--muted);
  font-size: 0.9rem;
}

h1,
h2,
h3,
p {
  margin: 0;
}

h1 {
  font-size: 2rem;
}

h2 {
  font-size: 1.1rem;
}

.toolbar {
  display: flex;
  gap: 8px;
}

.icon-button,
.text-button,
.secondary-button,
.primary-button {
  border: 1px solid transparent;
  cursor: pointer;
  transition: border-color 160ms ease, background 160ms ease, transform 160ms ease;
}

.icon-button {
  display: grid;
  width: 42px;
  height: 42px;
  place-items: center;
  border-color: var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  font-size: 1.3rem;
}

.icon-button:hover,
.text-button:hover,
.secondary-button:hover,
.primary-button:hover {
  transform: translateY(-1px);
}

.icon-button.danger {
  color: var(--expense);
}

.summary-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}

#mainSummaries {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.summary-card {
  min-height: 104px;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.summary-card span {
  display: block;
  color: var(--muted);
  font-size: 0.92rem;
  margin-bottom: 12px;
}

.summary-card strong {
  display: block;
  font-size: 1.55rem;
  white-space: nowrap;
}

.summary-card.income strong {
  color: var(--income);
}

.summary-card.expense strong {
  color: var(--expense);
}

.summary-card.balance strong {
  color: var(--balance);
}

.summary-card.tithe strong,
.summary-card.fifth strong {
  color: var(--tithe);
}

.folder-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}

.folder-card {
  min-height: 88px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
  color: var(--text);
  cursor: pointer;
  font-weight: 700;
  padding: 16px;
  text-align: right;
}

.folder-card::before {
  content: "▸";
  display: block;
  color: var(--focus);
  font-size: 1.25rem;
  margin-bottom: 8px;
}

.app-dialog {
  width: min(1120px, calc(100% - 28px));
  max-height: min(88vh, 900px);
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: 0 24px 80px rgba(30, 42, 54, 0.24);
  padding: 0;
}

.app-dialog::backdrop {
  background: rgba(23, 33, 43, 0.35);
}

.dialog-header {
  position: sticky;
  top: 0;
  z-index: 1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
}

#dialogBody {
  max-height: calc(88vh - 72px);
  overflow: auto;
  padding: 16px;
}

.window-content:not(.active-window) {
  display: none;
}

.window-content.active-window.summary-grid,
.window-content.active-window.quick-calculator,
.window-content.active-window.entry-form {
  display: grid;
  box-shadow: none;
}

.window-content.active-window.panel {
  display: block;
  box-shadow: none;
}

.quick-calculator {
  display: grid;
  gap: 16px;
  margin-bottom: 16px;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.folder-section {
  display: block;
}

.folder-summary {
  cursor: pointer;
  list-style: none;
}

.folder-summary::-webkit-details-marker {
  display: none;
}

.folder-summary::before {
  content: "▸";
  color: var(--focus);
  font-weight: 700;
}

.folder-section[open] .folder-summary {
  margin-bottom: 16px;
}

.folder-section[open] .folder-summary::before {
  content: "▾";
}

.calculator-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.calculator-header p {
  color: var(--muted);
  font-size: 0.9rem;
  margin-top: 4px;
}

.calculator-header strong {
  color: var(--income);
  font-size: 1.6rem;
  white-space: nowrap;
}

.calculator-grid {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 12px;
  align-items: end;
}

.hours-grid {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 12px;
  align-items: end;
}

.work-scan-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 12px;
  align-items: end;
}

.folder-input-label input[type="file"] {
  padding: 9px;
}

.work-scan-result {
  margin-top: 14px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
}

.work-scan-result ul {
  display: grid;
  gap: 6px;
  margin: 10px 0 0;
  padding: 0 18px 0 0;
}

.work-scan-actions {
  display: flex;
  gap: 10px;
  align-items: center;
  margin-top: 12px;
}

.work-scan-actions span {
  color: var(--muted);
  font-size: 0.9rem;
}

.work-scan-list {
  display: grid;
  gap: 8px;
  margin-top: 12px;
}

.work-scan-monitor {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.work-scan-monitor span {
  display: block;
  margin-top: 4px;
  color: var(--muted);
  font-size: 0.85rem;
  overflow-wrap: anywhere;
}

.timer-actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.timer-actions span {
  grid-column: 1 / -1;
  color: var(--muted);
  font-size: 0.85rem;
  min-height: 20px;
}

.payment-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 12px;
  align-items: end;
}

.calculator-grid label span {
  color: var(--text);
  font-size: 0.84rem;
}

.workbench {
  display: grid;
  grid-template-columns: 330px minmax(0, 1fr);
  gap: 16px;
  align-items: start;
  margin-bottom: 16px;
}

.client-summary-panel {
  margin-bottom: 16px;
}

.projects-panel {
  margin-bottom: 16px;
}

.entry-form,
.panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.entry-form {
  display: grid;
  gap: 14px;
  padding: 18px;
}

.form-header,
.panel-header {
  display: flex;
  justify-content: space-between;
  gap: 14px;
}

.form-header {
  align-items: center;
}

.panel-header {
  align-items: end;
  padding: 18px;
  border-bottom: 1px solid var(--line);
}

.panel-header p {
  color: var(--muted);
  font-size: 0.9rem;
  margin-top: 4px;
}

label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 0.9rem;
}

input,
select {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--text);
  padding: 0 12px;
}

input[type="checkbox"] {
  width: auto;
  min-height: auto;
  padding: 0;
}

input:focus,
select:focus,
button:focus-visible {
  outline: 3px solid rgba(40, 111, 152, 0.2);
  border-color: var(--focus);
}

.segmented {
  display: grid;
  grid-template-columns: 1fr 1fr;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-2);
}

.segmented label {
  display: block;
  color: var(--text);
}

.segmented input {
  position: absolute;
  width: auto;
  min-height: 0;
  opacity: 0;
}

.segmented span {
  display: block;
  min-height: 36px;
  padding: 9px 10px;
  border-radius: 6px;
  text-align: center;
  cursor: pointer;
}

.segmented input:checked + span {
  background: var(--surface);
  box-shadow: 0 2px 8px rgba(30, 42, 54, 0.12);
}

.primary-button {
  min-height: 44px;
  border-radius: 8px;
  background: var(--focus);
  color: #fff;
  font-weight: 700;
}

.text-button {
  min-height: 34px;
  padding: 0 10px;
  border-radius: 8px;
  background: var(--surface-2);
  color: var(--text);
}

.secondary-button {
  min-height: 44px;
  border-color: var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  font-weight: 700;
}

.secondary-button:disabled {
  cursor: default;
  opacity: 0.55;
  transform: none;
}

.text-button.ghost {
  background: transparent;
  border-color: var(--line);
}

.link-button {
  border: 0;
  background: transparent;
  color: var(--focus);
  cursor: pointer;
  font-weight: 700;
  padding: 0;
  text-align: right;
}

.danger-button {
  color: var(--expense);
  border-color: var(--line);
}

.hidden {
  display: none;
}

.filters {
  display: grid;
  grid-template-columns: 155px 150px;
  gap: 10px;
}

.table-wrap {
  position: relative;
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
}

th,
td {
  padding: 13px 14px;
  border-bottom: 1px solid var(--line);
  text-align: right;
  vertical-align: middle;
  white-space: nowrap;
}

th {
  color: var(--muted);
  font-size: 0.84rem;
  font-weight: 700;
}

td.note-cell {
  color: var(--muted);
  white-space: normal;
  min-width: 160px;
}

.amount {
  font-weight: 700;
  direction: ltr;
  text-align: right;
}

.inline-input {
  min-width: 150px;
  max-width: 220px;
}

.paid-toggle {
  display: inline-flex;
  grid-auto-flow: column;
  align-items: center;
  gap: 7px;
  color: var(--text);
  white-space: nowrap;
}

.client-detail-row > td {
  background: #f8fafb;
  padding: 0;
}

.client-detail {
  display: grid;
  gap: 12px;
  padding: 12px;
}

.client-detail table {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
}

.client-detail-empty {
  padding: 16px;
  color: var(--muted);
}

.client-payment-box {
  display: grid;
  gap: 10px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.client-payment-box h3 {
  font-size: 1rem;
}

.client-payment-form {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  align-items: end;
}

.projects-layout {
  display: grid;
  grid-template-columns: 300px minmax(0, 1fr);
  gap: 16px;
  padding: 16px;
}

.project-form,
.project-detail-card,
.project-list {
  display: grid;
  gap: 12px;
}

.project-form,
.project-detail-card {
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.project-form h3,
.project-detail-card h3 {
  font-size: 1rem;
}

.project-main {
  display: grid;
  gap: 12px;
}

.project-card {
  display: grid;
  gap: 5px;
  width: 100%;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  text-align: right;
}

.project-card.active {
  border-color: var(--focus);
  background: #f0f7fb;
}

.project-card.completed {
  border-color: #1d74a8;
  background: #e7f4fb;
  box-shadow: inset 4px 0 0 #2b7da8;
}

.project-card.completed.active {
  background: #d9edf8;
}

.project-card span {
  color: var(--muted);
  font-size: 0.85rem;
}

.project-detail-header {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: flex-start;
}

.project-detail-card.completed {
  border-color: #1d74a8;
  background: #eef8fc;
}

.project-summary-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 10px;
}

.project-mini-card {
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fafb;
}

.project-mini-card span {
  display: block;
  color: var(--muted);
  font-size: 0.82rem;
  margin-bottom: 6px;
}

.project-mini-card strong {
  display: block;
  line-height: 1.35;
  overflow-wrap: anywhere;
}

.project-expense-form {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 12px;
  align-items: end;
}

.project-receipt-form {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  align-items: end;
}

.project-finish-button:disabled {
  cursor: default;
  opacity: 0.65;
  transform: none;
}

.expanded-row td {
  background: #f8fafb;
}

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  padding: 0 9px;
  border-radius: 999px;
  font-size: 0.84rem;
}

.badge.income {
  background: #e6f4ed;
  color: var(--income);
}

.badge.expense {
  background: #faeaea;
  color: var(--expense);
}

.badge.payment {
  background: #e7f1f8;
  color: var(--focus);
}

.row-actions {
  display: flex;
  gap: 6px;
  justify-content: flex-end;
}

.row-actions button {
  min-width: 34px;
  height: 34px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  cursor: pointer;
}

.row-actions .delete {
  color: var(--expense);
}

.empty-state {
  display: none;
  padding: 46px 20px;
  text-align: center;
}

.empty-state h3 {
  font-size: 1.1rem;
  margin-bottom: 8px;
}

.empty-state p {
  color: var(--muted);
}

.empty .empty-state {
  display: block;
}

.empty table {
  display: none;
}

@media (max-width: 920px) {
  .summary-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .folder-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .calculator-grid,
  .hours-grid,
  .work-scan-grid,
  .payment-grid,
  .client-payment-form,
  .projects-layout,
  .project-summary-grid,
  .project-expense-form,
  .project-receipt-form {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .workbench {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 640px) {
  .app-shell {
    width: min(100% - 20px, 1180px);
    padding: 18px 0;
  }

  .topbar,
  .panel-header,
  .work-scan-actions {
    align-items: stretch;
    flex-direction: column;
  }

  .summary-grid,
  .folder-grid,
  .calculator-grid,
  .hours-grid,
  .work-scan-grid,
  .payment-grid,
  .client-payment-form,
  .projects-layout,
  .project-summary-grid,
  .project-expense-form,
  .project-receipt-form,
  .filters {
    grid-template-columns: 1fr;
  }

  .calculator-header {
    align-items: stretch;
    flex-direction: column;
  }

  h1 {
    font-size: 1.6rem;
  }

  .summary-card {
    min-height: 90px;
  }
}
