:root {
  color-scheme: light;
  --bg: #f6f7f4;
  --surface: #ffffff;
  --surface-2: #eef3ee;
  --ink: #1f2933;
  --muted: #65717d;
  --line: #d9e0d9;
  --green: #237a57;
  --green-soft: #dff1e6;
  --coral: #c94f4f;
  --coral-soft: #fde5df;
  --teal: #146c73;
  --gold: #a36c12;
  --shadow: 0 18px 45px rgba(31, 41, 51, 0.08);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-width: 320px;
  background: var(--bg);
  color: var(--ink);
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-shell {
  width: min(1440px, 100%);
  margin: 0 auto;
  padding: 24px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 18px 0 24px;
}

.auth-panel {
  display: grid;
  grid-template-columns: minmax(220px, 1fr) minmax(360px, 1.4fr);
  gap: 16px;
  align-items: end;
  margin-bottom: 18px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.auth-panel p {
  margin-bottom: 0;
  color: var(--muted);
  font-size: 0.88rem;
}

.auth-form {
  display: grid;
  grid-template-columns: minmax(160px, 1fr) minmax(160px, 1fr) auto;
  gap: 10px;
  align-items: end;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--teal);
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

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

h1 {
  margin-bottom: 0;
  font-size: clamp(1.8rem, 3vw, 3rem);
  line-height: 1.05;
  letter-spacing: 0;
}

h2 {
  margin-bottom: 4px;
  font-size: 1.05rem;
}

h3 {
  margin-bottom: 12px;
  font-size: 0.95rem;
}

.topbar-actions,
.row-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.storage-status {
  display: inline-flex;
  align-items: center;
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--muted);
  padding: 8px 11px;
  font-size: 0.82rem;
  font-weight: 800;
  white-space: nowrap;
}

.storage-status.is-safe {
  color: var(--green);
  background: var(--green-soft);
}

.storage-status.is-warning {
  color: var(--gold);
  background: #fff4d7;
}

.icon-button {
  display: inline-grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
  font-size: 1.1rem;
  transition:
    background 0.18s ease,
    border-color 0.18s ease,
    transform 0.18s ease;
}

.icon-button:hover {
  border-color: #b8c6bb;
  background: var(--surface-2);
}

.icon-button:active {
  transform: translateY(1px);
}

.file-button {
  position: relative;
  overflow: hidden;
}

.file-button input {
  position: absolute;
  inset: 0;
  opacity: 0;
  pointer-events: none;
}

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

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

.metric span {
  display: block;
  margin-bottom: 10px;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 700;
}

.metric strong {
  display: block;
  color: var(--green);
  font-size: clamp(1.4rem, 2.5vw, 2.2rem);
  line-height: 1;
  word-break: break-word;
}

.metric-balance strong {
  color: var(--ink);
}

.metric-free strong {
  color: var(--teal);
}

.workspace {
  display: grid;
  grid-template-columns: 340px minmax(0, 1fr);
  gap: 18px;
  align-items: start;
}

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

.entry-panel {
  position: sticky;
  top: 18px;
  display: grid;
  gap: 14px;
  padding: 18px;
}

.form-heading,
.ledger-toolbar,
.report-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
}

.ghost-button {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  padding: 8px 10px;
  font-size: 0.85rem;
  font-weight: 700;
}

.ghost-button:hover {
  color: var(--ink);
  border-color: #b8c6bb;
}

.hidden {
  display: none !important;
}

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

.segmented label {
  min-width: 0;
}

.segmented input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.segmented span {
  display: grid;
  min-height: 40px;
  place-items: center;
  border-radius: 6px;
  color: var(--muted);
  font-weight: 800;
}

.segmented input:checked + span {
  background: var(--surface);
  color: var(--ink);
  box-shadow: 0 2px 10px rgba(31, 41, 51, 0.08);
}

.field {
  display: grid;
  gap: 6px;
  min-width: 0;
}

.field span {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
}

.field input,
.field select,
.field textarea,
.report-controls > input {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
  padding: 10px 12px;
  outline: none;
  transition:
    border-color 0.18s ease,
    box-shadow 0.18s ease;
}

.field textarea {
  resize: vertical;
  min-height: 84px;
}

.field input:focus,
.field select:focus,
.field textarea:focus,
.report-controls > input:focus {
  border-color: var(--teal);
  box-shadow: 0 0 0 3px rgba(20, 108, 115, 0.14);
}

.primary-button {
  min-height: 46px;
  border: 0;
  border-radius: 8px;
  background: var(--green);
  color: #fff;
  font-weight: 900;
}

.primary-button:hover {
  background: #1d684a;
}

.secondary-button {
  min-height: 38px;
  border: 1px solid #b8c6bb;
  border-radius: 8px;
  background: var(--surface-2);
  color: var(--ink);
  padding: 9px 12px;
  font-weight: 900;
}

.secondary-button:hover {
  background: #e2ebe3;
}

.compact-button {
  min-height: 40px;
  padding: 9px 14px;
}

.danger-button {
  min-height: 40px;
  border: 0;
  border-radius: 8px;
  background: var(--coral);
  color: #fff;
  padding: 9px 14px;
  font-weight: 900;
}

.danger-button:hover {
  background: #ad3f3f;
}

.ledger {
  min-width: 0;
  padding: 18px;
}

.ledger-toolbar {
  margin-bottom: 16px;
}

.ledger-toolbar p {
  margin-bottom: 0;
  color: var(--muted);
  font-size: 0.86rem;
}

.filters {
  display: grid;
  grid-template-columns: 150px 132px minmax(180px, 1fr);
  gap: 10px;
  width: min(620px, 100%);
}

.compact input,
.compact select {
  min-height: 38px;
}

.insight-row {
  display: grid;
  grid-template-columns: 1.15fr 0.85fr;
  gap: 12px;
  margin-bottom: 16px;
}

.breakdown,
.period-report {
  min-height: 156px;
  padding: 16px;
  box-shadow: none;
}

.breakdown-list {
  display: grid;
  gap: 10px;
}

.muted-line {
  margin: 0;
  color: var(--muted);
  font-size: 0.88rem;
}

.breakdown-item {
  display: grid;
  grid-template-columns: minmax(86px, 1fr) minmax(120px, 2fr) auto;
  align-items: center;
  gap: 10px;
  color: var(--muted);
  font-size: 0.87rem;
}

.bar {
  height: 9px;
  overflow: hidden;
  border-radius: 999px;
  background: var(--surface-2);
}

.bar span {
  display: block;
  width: 0%;
  height: 100%;
  border-radius: inherit;
  background: var(--coral);
  transition: width 0.2s ease;
}

.breakdown-amount {
  color: var(--ink);
  font-weight: 800;
  text-align: right;
  white-space: nowrap;
}

.report-head {
  margin-bottom: 16px;
}

.report-controls {
  display: grid;
  grid-template-columns: auto 150px;
  gap: 10px;
  align-items: center;
  min-width: min(360px, 100%);
}

.report-controls > input {
  min-height: 38px;
}

.mini-segmented {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  min-width: 142px;
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-2);
}

.mini-segmented input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.mini-segmented span {
  display: grid;
  min-height: 32px;
  place-items: center;
  border-radius: 6px;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 800;
}

.mini-segmented input:checked + span {
  background: var(--surface);
  color: var(--ink);
}

.report-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px 18px;
}

.report-grid article {
  display: grid;
  gap: 4px;
  padding-top: 10px;
  border-top: 1px solid var(--line);
}

.report-grid span {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
}

.report-grid strong {
  color: var(--green);
  font-size: 1.35rem;
  line-height: 1;
}

.report-grid strong.is-negative {
  color: var(--coral);
}

.table-wrap {
  position: relative;
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.salary-panel,
.savings-panel {
  display: grid;
  gap: 14px;
  margin-bottom: 16px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfb;
}

.salary-head,
.savings-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
}

.salary-head p,
.savings-head p,
.salary-status {
  margin: 0;
  color: var(--muted);
  font-size: 0.86rem;
}

.salary-form,
.savings-form {
  display: grid;
  grid-template-columns: minmax(150px, 1.4fr) minmax(130px, 1fr) minmax(110px, 0.8fr) 86px auto auto;
  gap: 10px;
  align-items: end;
}

.savings-form {
  grid-template-columns: minmax(170px, 1.3fr) minmax(110px, 0.75fr) minmax(150px, 0.9fr) 138px auto auto;
}

.salary-list,
.savings-list {
  display: grid;
  gap: 8px;
}

.salary-item,
.savings-item {
  display: grid;
  grid-template-columns: minmax(160px, 1fr) auto auto;
  align-items: center;
  gap: 12px;
  min-height: 54px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.savings-item {
  grid-template-columns: minmax(170px, 1fr) minmax(130px, 0.8fr) auto auto;
}

.savings-item.is-completed {
  background: var(--green-soft);
}

.salary-item strong,
.salary-item span,
.savings-item strong,
.savings-item span {
  display: block;
}

.salary-item span,
.savings-item span {
  margin-top: 3px;
  color: var(--muted);
  font-size: 0.82rem;
}

.salary-amount,
.savings-amount {
  font-weight: 900;
  white-space: nowrap;
}

.savings-progress {
  height: 10px;
  overflow: hidden;
  border-radius: 999px;
  background: var(--surface-2);
}

.savings-progress span {
  display: block;
  width: 0%;
  height: 100%;
  border-radius: inherit;
  background: var(--teal);
  transition: width 0.2s ease;
}

.savings-complete {
  color: var(--green);
}

.salary-item .icon-button,
.savings-item .icon-button {
  width: 34px;
  height: 34px;
}

.salary-list.is-empty,
.savings-list.is-empty {
  min-height: 72px;
  place-items: center;
  color: var(--muted);
  font-size: 0.88rem;
  text-align: center;
}

table {
  width: 100%;
  min-width: 820px;
  border-collapse: collapse;
  background: var(--surface);
}

th,
td {
  border-bottom: 1px solid var(--line);
  padding: 12px;
  text-align: left;
  vertical-align: middle;
}

th {
  background: #f1f5f1;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 900;
}

tbody tr:hover {
  background: #fbfcfb;
}

tbody tr:last-child td {
  border-bottom: 0;
}

.amount-column,
.amount-cell {
  text-align: right;
}

.amount-cell {
  font-weight: 900;
  white-space: nowrap;
}

.amount-income {
  color: var(--green);
}

.amount-expense {
  color: var(--coral);
}

.type-pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 76px;
  min-height: 28px;
  border-radius: 999px;
  padding: 4px 10px;
  font-size: 0.78rem;
  font-weight: 900;
}

.type-income {
  background: var(--green-soft);
  color: var(--green);
}

.type-expense {
  background: var(--coral-soft);
  color: var(--coral);
}

.action-column {
  width: 98px;
}

.row-actions {
  justify-content: flex-end;
}

.row-actions .icon-button {
  width: 34px;
  height: 34px;
}

.delete-action {
  color: var(--coral);
}

.empty-state {
  display: none;
  gap: 6px;
  place-items: center;
  min-height: 180px;
  color: var(--muted);
  text-align: center;
}

.empty-state strong {
  color: var(--ink);
}

.table-wrap.is-empty table {
  display: none;
}

.table-wrap.is-empty .empty-state {
  display: grid;
}

.confirm-dialog {
  width: min(420px, calc(100vw - 32px));
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0;
  color: var(--ink);
  box-shadow: 0 24px 70px rgba(31, 41, 51, 0.22);
}

.confirm-dialog::backdrop {
  background: rgba(31, 41, 51, 0.35);
}

.confirm-content {
  padding: 20px;
}

.confirm-content p {
  margin-bottom: 18px;
  color: var(--muted);
}

.confirm-content .field {
  margin-bottom: 14px;
}

.confirm-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

@media (max-width: 1060px) {
  .workspace,
  .insight-row {
    grid-template-columns: 1fr;
  }

  .entry-panel {
    position: static;
  }
}

@media (max-width: 760px) {
  .app-shell {
    padding: 16px;
  }

  .topbar,
  .ledger-toolbar,
  .form-heading,
  .report-head {
    align-items: stretch;
  }

  .topbar,
  .ledger-toolbar,
  .report-head {
    flex-direction: column;
  }

  .auth-panel,
  .auth-form {
    grid-template-columns: 1fr;
  }

  .topbar-actions {
    justify-content: flex-start;
  }

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

  .filters {
    grid-template-columns: 1fr;
    width: 100%;
  }

  .report-controls {
    grid-template-columns: 1fr;
    min-width: 0;
  }

  .salary-head,
  .savings-head,
  .salary-item,
  .savings-item {
    align-items: stretch;
  }

  .salary-head,
  .savings-head,
  .salary-item,
  .savings-item {
    grid-template-columns: 1fr;
  }

  .salary-head,
  .savings-head {
    flex-direction: column;
  }

  .salary-form,
  .savings-form {
    grid-template-columns: 1fr;
  }

  table {
    min-width: 0;
  }

  thead {
    display: none;
  }

  tbody,
  tr,
  td {
    display: block;
  }

  tbody tr {
    border-bottom: 1px solid var(--line);
    padding: 12px;
  }

  td {
    display: grid;
    grid-template-columns: 112px minmax(0, 1fr);
    gap: 10px;
    border-bottom: 0;
    padding: 7px 0;
    text-align: left;
  }

  td::before {
    content: attr(data-label);
    color: var(--muted);
    font-size: 0.78rem;
    font-weight: 900;
  }

  .amount-cell {
    text-align: left;
  }

  .row-actions {
    justify-content: flex-start;
  }

  .row-actions::before {
    padding-top: 7px;
  }
}

@media (max-width: 480px) {
  .summary-grid {
    grid-template-columns: 1fr;
  }

  .metric {
    min-height: 88px;
  }

  .breakdown-item {
    grid-template-columns: 1fr;
    gap: 6px;
  }

  .breakdown-amount {
    text-align: left;
  }
}
