:root {
  --bg: #f4f5f2;
  --panel: #ffffff;
  --login-panel: #f3e4bf;
  --panel-muted: #eef3ef;
  --ink: #1c2520;
  --muted: #657168;
  --line: #d8ded8;
  --cash-in: #5ac400;
  --cash-out: #b94132;
  --accent: #1b6f8f;
  --accent-dark: #11526a;
  --mobile-entry-panel: #ecd39a;
  --mobile-entry-border: #d6b875;
  --mobile-history-panel: #fbf3df;
  --mobile-history-border: #ead8a9;
  --mobile-cash-in-panel: #dff2e6;
  --mobile-cash-in-border: #b7dcc5;
  --mobile-cash-out-panel: #f8dfdc;
  --mobile-cash-out-border: #e7b8b1;
  --mobile-logout: #eca9a0;
  --mobile-logout-border: #d7796e;
  --history-header: #a3876f;
  --history-selected: #e6e6e6;
  --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;
}

html {
  -webkit-text-size-adjust: 100%;
  max-width: 100%;
  overscroll-behavior-x: none;
  text-size-adjust: 100%;
  overflow-x: hidden;
  width: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  min-width: 320px;
  max-width: 100%;
  overscroll-behavior-x: none;
  overflow-x: hidden;
  position: relative;
  touch-action: pan-y;
  width: 100%;
}

button,
input,
select {
  font: inherit;
}

button {
  border: 0;
  cursor: pointer;
}

.hidden {
  display: none !important;
}

.app-shell {
  min-height: 100vh;
  max-width: 100vw;
  overflow-x: hidden;
  width: 100%;
}

.login-view {
  align-items: center;
  display: flex;
  justify-content: center;
  min-height: 100vh;
  max-width: 100vw;
  overflow-x: hidden;
  padding: 24px;
  width: 100%;
}

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

.language-menu {
  position: absolute;
  right: 26px;
  top: 24px;
  z-index: 3;
}

.language-toggle {
  align-items: center;
  background: transparent;
  color: var(--accent);
  display: inline-flex;
  height: 36px;
  justify-content: center;
  padding: 0;
  width: 36px;
}

.language-toggle svg {
  fill: none;
  height: 23px;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 1.9;
  width: 23px;
}

.language-toggle:hover,
.language-toggle:focus-visible {
  color: var(--accent-dark);
  outline: 0;
}

.language-options {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 12px 30px rgba(31, 43, 36, 0.12);
  display: grid;
  gap: 4px;
  min-width: 122px;
  padding: 6px;
  position: absolute;
  right: 0;
  top: 40px;
}

.language-options button {
  background: transparent;
  border-radius: 6px;
  color: var(--ink);
  font-weight: 700;
  padding: 8px 10px;
  text-align: left;
  white-space: nowrap;
}

.language-options button:hover,
.language-options button.is-active {
  background: #eaf3f7;
  color: var(--accent);
}

.login-brand {
  align-items: center;
  display: flex;
  gap: 10px;
  margin-bottom: 24px;
  max-width: 66.666%;
  min-width: 0;
}

.login-brand img {
  display: block;
  flex: 1 1 auto;
  height: auto;
  min-width: 0;
  object-fit: contain;
}

.login-brand span {
  color: var(--ink);
  flex: 0 0 auto;
  font-size: 0.98rem;
  font-weight: 800;
  line-height: 1;
  white-space: nowrap;
}

.eyebrow {
  color: var(--accent);
  font-size: 1.08rem;
  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;
}

.edit-date-fields {
  display: grid;
  gap: 10px;
  grid-template-columns: 1fr 1fr;
}

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

.login-footer {
  color: var(--muted);
  font-size: 0.95rem;
  margin: 14px 0 0;
  text-align: center;
}

.login-footer strong {
  font-size: 1.02rem;
  font-weight: 900;
}

.login-footer span {
  font-weight: 400;
}

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;
  min-width: 0;
  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;
  overflow-x: hidden;
  padding: calc(28px + env(safe-area-inset-top)) 20px calc(40px + env(safe-area-inset-bottom));
  width: 100%;
}

.topbar,
.section-heading {
  align-items: center;
  display: flex;
  gap: 16px;
  justify-content: space-between;
  max-width: 100%;
  min-width: 0;
}

.topbar > *,
.section-heading > * {
  min-width: 0;
}

.project-title-display {
  align-items: flex-start;
  display: grid;
  gap: 4px;
}

.project-title-form {
  background: var(--mobile-history-panel);
  border: 1px solid var(--mobile-history-border);
  border-radius: 8px;
  display: grid;
  gap: 12px;
  max-width: 520px;
  padding: 14px;
}

.title-form-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.history-toolbar {
  align-items: stretch;
  display: grid;
  gap: 10px;
  justify-self: end;
  justify-items: stretch;
  max-width: 100%;
  min-width: 0;
  width: min(100%, 542px);
}

.history-actions {
  display: grid;
  gap: 10px;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  max-width: 100%;
  min-width: 0;
  width: 100%;
}

.export-filter {
  align-items: end;
  display: grid;
  gap: 10px;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  max-width: 100%;
  min-width: 0;
  width: 100%;
}

.export-filter label {
  gap: 5px;
}

.export-filter input {
  font-size: 0.82rem;
  min-height: 36px;
  padding: 7px 6px;
}

.export-filter .ghost-button {
  grid-column: 1 / -1;
  min-height: 36px;
}

.owner-only {
  display: none !important;
}

.owner-mode .history-toolbar .owner-only {
  display: inline-flex !important;
}

.owner-mode .project-title-display {
  cursor: pointer;
}

.owner-mode .project-title-display:focus {
  border-radius: 6px;
  box-shadow: 0 0 0 3px rgba(27, 111, 143, 0.16);
  outline: 0;
}

.owner-mode .project-title-display:hover h1 {
  color: var(--accent-dark);
}

.owner-mode th.owner-only,
.owner-mode td.owner-only {
  display: table-cell !important;
}

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

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

.user-chip span {
  color: var(--muted);
  font-weight: 800;
  min-width: 0;
  overflow-wrap: anywhere;
}

.summary-grid {
  display: grid;
  gap: 14px;
  grid-template-columns: 1.3fr 1fr 1fr;
  margin-top: 28px;
  max-width: 100%;
  min-width: 0;
}

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

.summary-grid .summary-card:nth-child(2) {
  background: var(--mobile-cash-in-panel);
  border-color: var(--mobile-cash-in-border);
}

.summary-grid .summary-card:nth-child(3) {
  background: var(--mobile-cash-out-panel);
  border-color: var(--mobile-cash-out-border);
}

.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;
}

#logoutButton {
  background: var(--mobile-logout);
  border-color: var(--mobile-logout-border);
  color: var(--ink);
}

#logoutButton:hover {
  background: #e89489;
  border-color: #cf685d;
  color: var(--ink);
}

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

.entry-panel,
.history-panel {
  background: var(--mobile-history-panel);
  border: 1px solid var(--mobile-history-border);
  border-radius: 8px;
  max-width: 100%;
  min-width: 0;
  overflow: hidden;
  padding: 18px;
}

.entry-panel {
  align-self: start;
  background: var(--mobile-entry-panel);
  border-color: var(--mobile-entry-border);
}

.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: 620px;
  width: 100%;
}

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

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

thead th {
  border-bottom-color: var(--history-header);
  color: #fff;
}

td {
  background: #fff;
  font-size: 0.92rem;
}

tr.selected-row {
  background: var(--history-selected);
}

tr.selected-row td {
  background: var(--history-selected);
}

tbody td {
  border-bottom-color: var(--ink);
}

.history-toolbar .ghost-button {
  align-items: center;
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  display: inline-flex;
  justify-content: center;
  text-align: center;
  width: 100%;
}

.history-toolbar .ghost-button:hover {
  background: var(--accent-dark);
  border-color: var(--accent-dark);
  color: #fff;
}

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

.date-cell {
  white-space: nowrap;
}

.select-col,
.select-cell {
  padding-left: 0;
  padding-right: 4px;
  width: 38px;
}

.row-select {
  align-items: center;
  cursor: pointer;
  display: inline-flex;
  height: 34px;
  justify-content: center;
  width: 34px;
}

.row-select input {
  height: 1px;
  opacity: 0;
  position: absolute;
  width: 1px;
}

.row-select span {
  background: #fff;
  border: 2px solid var(--ink);
  border-radius: 50%;
  display: block;
  height: 22px;
  position: relative;
  width: 22px;
}

.row-select input:checked + span {
  border-color: var(--accent);
}

.row-select input:checked + span::after {
  background: var(--accent);
  border-radius: 50%;
  content: "";
  height: 10px;
  left: 50%;
  position: absolute;
  top: 50%;
  transform: translate(-50%, -50%);
  width: 10px;
}

.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);
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

@media (min-width: 851px) {
  .history-panel > .section-heading {
    align-items: stretch;
    flex-direction: column;
    gap: 18px;
  }

  .history-panel .history-toolbar {
    justify-self: stretch;
    width: 100%;
  }

  thead th {
    font-size: 0.86rem;
    line-height: 1.2;
    padding-bottom: 16px;
    padding-top: 16px;
    vertical-align: middle;
    white-space: nowrap;
  }

  tbody td:last-child {
    white-space: nowrap;
  }
}

@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;
  }

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

  .history-toolbar {
    justify-content: flex-start;
    justify-items: start;
  }

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

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

@media (max-width: 520px) {
  html,
  body {
    min-width: 0;
    width: 100%;
  }

  .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;
  }

  .language-menu {
    right: 14px;
    top: 14px;
  }

  .login-brand {
    max-width: min(100%, 310px);
  }

  .login-brand span {
    font-size: 0.88rem;
  }

  .dashboard-view {
    max-width: 100dvw;
    padding-left: 10px;
    padding-right: 10px;
    width: 100dvw;
  }

  h1 {
    font-size: 1.85rem;
  }

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

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

  #logoutButton {
    background: var(--mobile-logout);
    border-color: var(--mobile-logout-border);
    color: var(--ink);
  }

  #logoutButton:hover {
    background: #e89489;
    border-color: #cf685d;
    color: var(--ink);
  }

  .summary-grid .summary-card:nth-child(2) {
    background: var(--mobile-cash-in-panel);
    border-color: var(--mobile-cash-in-border);
  }

  .summary-grid .summary-card:nth-child(3) {
    background: var(--mobile-cash-out-panel);
    border-color: var(--mobile-cash-out-border);
  }

  .workspace-grid {
    gap: 12px;
    max-width: 100%;
    margin-top: 12px;
    width: 100%;
  }

  .entry-panel {
    background: var(--mobile-entry-panel);
    border-color: var(--mobile-entry-border);
  }

  .history-panel {
    background: var(--mobile-history-panel);
    border-color: var(--mobile-history-border);
  }

  .section-heading {
    align-items: stretch;
    flex-direction: column;
    max-width: 100%;
    width: 100%;
  }

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

  .history-toolbar {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    justify-items: stretch;
    max-width: 100%;
    min-width: 0;
  }

  .export-filter {
    grid-column: 1 / -1;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    width: 100%;
  }

  .export-filter .ghost-button {
    grid-column: 1 / -1;
  }

  .history-actions {
    display: grid;
    grid-column: 1 / -1;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    width: 100%;
  }

  .history-actions #exportPdfButton {
    order: 1;
  }

  .history-actions #exportButton {
    order: 2;
  }

  .history-actions #editSelectedButton {
    order: 3;
  }

  .history-actions #deleteSelectedButton {
    order: 4;
  }

  .history-toolbar .ghost-button {
    align-items: center;
    background: var(--accent);
    border-color: var(--accent);
    color: #fff;
    display: inline-flex;
    justify-content: center;
    overflow-wrap: anywhere;
    text-align: center;
    width: 100%;
  }

  .history-toolbar .ghost-button:hover {
    background: var(--accent-dark);
    border-color: var(--accent-dark);
    color: #fff;
  }

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

  .edit-date-fields {
    grid-template-columns: 1fr;
  }

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

  .table-wrap {
    margin-top: 12px;
    max-width: 100%;
    overflow: visible;
  }

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

  table {
    max-width: 100%;
    min-width: 0;
    table-layout: fixed;
    width: 100%;
  }

  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;
    max-width: 100%;
    margin-bottom: 12px;
    overflow: hidden;
    padding: 12px;
    width: 100%;
  }

  tr.selected-row,
  tr.selected-row td {
    background: var(--history-selected);
  }

  td {
    align-items: flex-start;
    border-bottom: 0;
    display: grid;
    gap: 8px;
    grid-template-columns: 84px 1fr;
    max-width: 100%;
    overflow-wrap: anywhere;
    padding: 8px 0;
    word-break: break-word;
  }

  .owner-mode td.owner-only {
    display: flex !important;
  }

  .select-cell {
    padding: 0 0 6px;
    width: auto;
  }

  .select-cell::before {
    display: none;
  }

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

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

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

}

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

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