:root {
  --bg: #f4f5f2;
  --panel: #ffffff;
  --panel-muted: #eef3ef;
  --ink: #1c2520;
  --muted: #657168;
  --line: #d8ded8;
  --cash-in: #157f4f;
  --cash-out: #b94132;
  --accent: #1b6f8f;
  --accent-dark: #11526a;
  --shadow: 0 20px 55px rgba(31, 43, 36, 0.12);
  color-scheme: light;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

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

button,
input,
select {
  font: inherit;
}

button {
  border: 0;
  cursor: pointer;
}

.hidden {
  display: none !important;
}

.app-shell {
  min-height: 100vh;
}

.login-view {
  align-items: center;
  display: flex;
  justify-content: center;
  min-height: 100vh;
  padding: 24px;
}

.login-panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  max-width: 430px;
  padding: 28px;
  width: 100%;
}

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

h1,
h2 {
  letter-spacing: 0;
  margin: 0;
}

h1 {
  font-size: clamp(1.8rem, 4vw, 2.6rem);
  line-height: 1.05;
}

h2 {
  font-size: 1.08rem;
}

.login-form,
.entry-panel {
  display: grid;
  gap: 16px;
}

.login-form {
  margin-top: 24px;
}

label {
  color: var(--muted);
  display: grid;
  font-size: 0.88rem;
  font-weight: 700;
  gap: 8px;
}

input,
select {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--ink);
  font-size: 1rem;
  min-height: 44px;
  padding: 10px 12px;
  width: 100%;
}

input:focus,
select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(27, 111, 143, 0.16);
  outline: 0;
}

button[type="submit"],
.login-form button,
.entry-panel button[type="submit"] {
  background: var(--accent);
  border-radius: 6px;
  color: #fff;
  font-weight: 800;
  min-height: 44px;
  padding: 11px 16px;
}

button[type="submit"]:hover,
.login-form button:hover,
.entry-panel button[type="submit"]:hover {
  background: var(--accent-dark);
}

.ghost-button {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--ink);
  font-weight: 800;
  min-height: 36px;
  padding: 8px 12px;
}

.ghost-button:hover {
  border-color: var(--accent);
  color: var(--accent-dark);
}

.hint,
.form-error,
.empty-state {
  color: var(--muted);
  font-size: 0.9rem;
  line-height: 1.45;
  margin: 14px 0 0;
}

.form-error {
  color: var(--cash-out);
  font-weight: 700;
  margin: 0;
  min-height: 20px;
}

.dashboard-view {
  margin: 0 auto;
  max-width: 1180px;
  padding: calc(28px + env(safe-area-inset-top)) 20px calc(40px + env(safe-area-inset-bottom));
}

.topbar,
.section-heading {
  align-items: center;
  display: flex;
  gap: 16px;
  justify-content: space-between;
}

.user-chip {
  align-items: center;
  display: flex;
  gap: 10px;
}

.user-chip span {
  color: var(--muted);
  font-weight: 800;
}

.summary-grid {
  display: grid;
  gap: 14px;
  grid-template-columns: 1.3fr 1fr 1fr;
  margin-top: 28px;
}

.summary-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 20px;
}

.summary-card span {
  color: var(--muted);
  display: block;
  font-size: 0.86rem;
  font-weight: 800;
  margin-bottom: 8px;
}

.summary-card strong {
  display: block;
  font-size: clamp(1.45rem, 3vw, 2.15rem);
  letter-spacing: 0;
  line-height: 1.1;
}

.balance-card {
  background: var(--ink);
  border-color: var(--ink);
  color: #fff;
}

.balance-card span {
  color: #cbd8cf;
}

.workspace-grid {
  display: grid;
  gap: 16px;
  grid-template-columns: minmax(280px, 360px) 1fr;
  margin-top: 16px;
}

.entry-panel,
.history-panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 18px;
}

.entry-panel {
  align-self: start;
}

.type-toggle {
  border: 0;
  display: grid;
  gap: 10px;
  grid-template-columns: 1fr 1fr;
  margin: 0;
  padding: 0;
}

.type-toggle legend {
  color: var(--muted);
  font-size: 0.88rem;
  font-weight: 800;
  grid-column: 1 / -1;
  margin-bottom: -2px;
}

.type-toggle label {
  display: block;
}

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

.type-toggle span {
  align-items: center;
  background: var(--panel-muted);
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--ink);
  display: flex;
  font-weight: 800;
  justify-content: center;
  min-height: 44px;
  padding: 10px 12px;
}

.type-toggle input:checked + span {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.table-wrap {
  margin-top: 14px;
  overflow-x: auto;
  width: 100%;
}

table {
  border-collapse: collapse;
  min-width: 720px;
  width: 100%;
}

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

th {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 900;
  text-transform: uppercase;
}

td {
  font-size: 0.92rem;
}

td small {
  color: var(--muted);
  font-size: 0.78rem;
}

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

.cash-in {
  color: var(--cash-in);
}

.cash-out {
  color: var(--cash-out);
}

.type-badge {
  border-radius: 999px;
  display: inline-flex;
  font-size: 0.78rem;
  font-weight: 900;
  padding: 5px 9px;
}

.type-badge.cash-in {
  background: rgba(21, 127, 79, 0.12);
}

.type-badge.cash-out {
  background: rgba(185, 65, 50, 0.12);
}

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

.actions button {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--ink);
  font-size: 0.82rem;
  font-weight: 800;
  min-height: 32px;
  padding: 6px 9px;
}

.actions button:hover {
  border-color: var(--accent);
  color: var(--accent-dark);
}

.actions .danger:hover {
  border-color: var(--cash-out);
  color: var(--cash-out);
}

.actions-col {
  width: 130px;
}

@media (max-width: 850px) {
  .dashboard-view {
    padding: calc(22px + env(safe-area-inset-top)) 14px calc(32px + env(safe-area-inset-bottom));
  }

  .topbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .section-heading {
    gap: 10px;
  }

  .user-chip {
    justify-content: space-between;
    width: 100%;
  }

  .summary-grid,
  .workspace-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 520px) {
  .login-view {
    align-items: flex-start;
    padding: calc(18px + env(safe-area-inset-top)) 12px calc(18px + env(safe-area-inset-bottom));
  }

  .login-panel,
  .entry-panel,
  .history-panel,
  .summary-card {
    padding: 16px;
  }

  .login-panel {
    margin-top: 12px;
  }

  .dashboard-view {
    padding-left: 10px;
    padding-right: 10px;
  }

  h1 {
    font-size: 1.85rem;
  }

  .summary-grid {
    gap: 10px;
    margin-top: 18px;
  }

  .summary-card strong {
    font-size: 1.55rem;
    overflow-wrap: anywhere;
  }

  .workspace-grid {
    gap: 12px;
    margin-top: 12px;
  }

  .section-heading {
    align-items: stretch;
    flex-direction: column;
  }

  .section-heading .ghost-button {
    width: 100%;
  }

  .type-toggle {
    grid-template-columns: 1fr 1fr;
  }

  input,
  select,
  button[type="submit"],
  .ghost-button,
  .type-toggle span {
    min-height: 48px;
  }

  .table-wrap {
    margin-top: 12px;
    overflow: visible;
  }

  table,
  thead,
  tbody,
  tr,
  th,
  td {
    display: block;
  }

  table {
    min-width: 0;
  }

  thead {
    clip: rect(0 0 0 0);
    height: 1px;
    overflow: hidden;
    position: absolute;
    white-space: nowrap;
    width: 1px;
  }

  tr {
    background: #fff;
    border: 1px solid var(--line);
    border-radius: 8px;
    margin-bottom: 12px;
    padding: 12px;
  }

  td {
    align-items: flex-start;
    border-bottom: 0;
    display: grid;
    gap: 8px;
    grid-template-columns: 84px 1fr;
    padding: 8px 0;
    word-break: break-word;
  }

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

  .amount-cell {
    white-space: normal;
  }

  .actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
  }

  .actions button {
    min-height: 42px;
    width: 100%;
  }
}

@media (max-width: 360px) {
  .type-toggle {
    grid-template-columns: 1fr;
  }

  td {
    grid-template-columns: 74px 1fr;
  }
}
