:root {
  --bg: #f7f7f5;
  --card-bg: #ffffff;
  --text: #1f2320;
  --muted: #6b7280;
  --border: #e2e2df;
  --accent: #2f6f4f;
  --danger: #b3402a;
  --income: #2f6f4f;
  --expense: #b3402a;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
}

.container {
  max-width: 900px;
  margin: 0 auto;
  padding: 1rem;
}

.topbar {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  padding: 0.75rem 1rem;
  background: var(--card-bg);
  border-bottom: 1px solid var(--border);
}

.topbar-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.5rem;
}

.brand {
  font-weight: 600;
  text-decoration: none;
  color: var(--text);
}

.topbar nav {
  display: flex;
  gap: 1rem;
  align-items: center;
  flex-wrap: wrap;
}

.topbar nav a {
  color: var(--accent);
  text-decoration: none;
}

.card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 1.25rem;
  margin-top: 1rem;
}

.login-card {
  max-width: 360px;
  margin: 3rem auto;
}

form label {
  display: block;
  margin-top: 0.75rem;
  margin-bottom: 0.25rem;
  font-size: 0.9rem;
  color: var(--muted);
}

form input[type="text"],
form input[type="password"],
form input[type="date"],
form input[type="month"],
form select,
form textarea {
  width: 100%;
  padding: 0.5rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 1rem;
}

/* Styling input[type=file] directly (width/padding/border) breaks the tap
   target on mobile Safari/Chrome: the native button's real hit area stops
   lining up with the styled box, so taps on it silently do nothing. Hiding
   the input and triggering it via a styled <label> avoids that entirely. */
.file-input {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.file-label {
  display: inline-block;
  padding: 0.5rem 1rem;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 1rem;
  cursor: pointer;
}

.file-name {
  display: block;
  margin-top: 0.4rem;
}

form textarea {
  min-height: 4rem;
}

form button {
  margin-top: 1.25rem;
  padding: 0.6rem 1.2rem;
  background: var(--accent);
  color: white;
  border: none;
  border-radius: 6px;
  font-size: 1rem;
  cursor: pointer;
}

.link-button {
  background: none;
  border: none;
  margin: 0;
  color: var(--accent);
  cursor: pointer;
  padding: 0;
  font-size: inherit;
  text-decoration: underline;
}

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

.inline-form {
  display: inline;
}

.error {
  color: var(--danger);
  font-weight: 500;
}

.hint {
  color: var(--muted);
  font-size: 0.9rem;
}

.filter-form {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  margin-top: 1rem;
}

.filter-fields {
  display: flex;
  gap: 0.6rem;
  flex-wrap: wrap;
}

.filter-field {
  display: flex;
  flex-direction: column;
  flex: 1 1 140px;
}

.filter-field label {
  margin: 0 0 0.25rem;
}

.filter-actions {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.filter-form button {
  margin-top: 0;
  padding: 0.4rem 0.8rem;
  font-size: 0.85rem;
}

.filter-form .link-button {
  font-size: 0.85rem;
}

.totals {
  display: flex;
  gap: 0.75rem;
  flex-wrap: wrap;
  margin-top: 1rem;
}

.total-tile {
  flex: 1 1 150px;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.75rem 1rem;
}

.total-tile span {
  display: block;
  color: var(--muted);
  font-size: 0.85rem;
}

.total-tile strong {
  font-size: 1.3rem;
}

.total-tile.income strong { color: var(--income); }
.total-tile.expense strong { color: var(--expense); }

.empty-state {
  color: var(--muted);
  margin-top: 2rem;
  text-align: center;
}

.entries-table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 1rem;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
}

.entries-table th,
.entries-table td {
  padding: 0.5rem 0.4rem;
  border-bottom: 1px solid var(--border);
  text-align: left;
  font-size: 0.95rem;
}

.entries-table .amount-col,
.entries-table .row-actions {
  text-align: right;
}

.entries-table tr.income td:nth-child(1) { color: var(--income); }
.entries-table tr.expense td:nth-child(1) { color: var(--expense); }

.row-actions a,
.row-actions button {
  margin-left: 0.5rem;
  font-size: 0.85rem;
}

.icon-link {
  display: inline-flex;
  align-items: center;
  color: var(--muted);
  text-decoration: none;
}

.icon-link:hover {
  color: var(--text);
}

.link-button.danger.icon-link:hover {
  color: var(--danger);
  opacity: 0.8;
}

.row-actions svg,
td svg {
  width: 1rem;
  height: 1rem;
}

.entry-form-layout {
  display: flex;
  gap: 1.5rem;
  flex-wrap: wrap;
}

.entry-form-card.with-preview .entry-form-layout {
  align-items: flex-start;
}

.file-preview {
  flex: 1 1 280px;
  min-width: 260px;
}

.file-preview embed,
.file-preview img {
  width: 100%;
  max-height: 480px;
  border: 1px solid var(--border);
  border-radius: 6px;
}

.file-preview pre {
  white-space: pre-wrap;
  font-size: 0.8rem;
  background: var(--bg);
  padding: 0.5rem;
  border-radius: 6px;
  max-height: 200px;
  overflow-y: auto;
}

.entry-form {
  flex: 1 1 320px;
}

@media (max-width: 600px) {
  .entries-table { font-size: 0.6rem; }

  .entries-table th,
  .entries-table td {
    padding: 0.4rem 0.25rem;
  }

  .entries-table th.date-col,
  .entries-table td.date-col,
  .entries-table th.desc-col,
  .entries-table td.desc-col,
  .entries-table th.amount-col,
  .entries-table td.amount-col {
    font-size: 0.6rem;
  }
}
