:root {
  --bg: #f5f4f0;
  --surface: #ffffff;
  --border: #e8e6e0;
  --text: #1a1a18;
  --text-muted: #888882;
  --accent: #1a1a18;

  --income: #16a34a;
  --income-bg: #dcfce7;
  --expense: #dc2626;
  --expense-bg: #fee2e2;

  --radius: 16px;
  --radius-sm: 8px;

  --shadow: 0 1px 3px rgba(0, 0, 0, 0.07), 0 4px 12px rgba(0, 0, 0, 0.05);
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.06);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: sans-serif;
  font-size: 14px;
  color: var(--text);
  background: var(--bg);
}

.app-body {
  background: var(--bg);
}

a {
  color: inherit;
  text-decoration: none;
}

button {
  cursor: pointer;
  font-family: inherit;
}

input,
select,
button {
  font-size: 14px;
}

/* Auth */
.auth-body {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
}

.auth-wrap {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
}

.auth-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 36px;
  width: 340px;
  box-shadow: var(--shadow);
}

.auth-logo {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  margin-bottom: 24px;
}

.auth-logo-img {
  width: 32px;
  height: 32px;
  object-fit: contain;
}

.auth-logo-name {
  font-size: 18px;
  font-weight: 600;
}

.auth-title {
  font-size: 20px;
  font-weight: 500;
  margin-bottom: 4px;
}

.auth-sub {
  font-size: 13px;
  color: var(--text-muted);
  margin-bottom: 20px;
}

.auth-switch {
  text-align: center;
  font-size: 13px;
  margin-top: 14px;
  color: var(--text-muted);
}

.link {
  color: var(--text);
  text-decoration: underline;
  text-underline-offset: 3px;
}

.demo {
  font-size: 12px;
  text-align: center;
  margin-top: 20px;
  padding: 12px 16px;
  border: 1px dashed var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  line-height: 1.7;
}

.demo p:first-child {
  font-weight: 600;
  text-transform: uppercase;
  margin-bottom: 4px;
}

.btn-primary {
  font-size: 13px;
  font-weight: 600;
  color: #fff;
  background: var(--accent);
  border: none;
  border-radius: var(--radius-sm);
  padding: 9px 18px;
  transition: opacity 0.15s;
}

.btn-primary:hover {
  opacity: 0.85;
}

.btn-full {
  width: 100%;
}

.alert {
  font-size: 13px;
  border-radius: var(--radius-sm);
  padding: 9px 13px;
  margin-bottom: 14px;
}

.alert-error {
  color: var(--expense);
  background: var(--expense-bg);
}

.alert-success {
  color: var(--income);
  background: var(--income-bg);
}

/* Form */
.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
  margin-bottom: 18px;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 5px;
  margin-bottom: 12px;
}

.form-label {
  font-size: 11px;
  font-weight: 500;
  text-transform: uppercase;
  color: var(--text-muted);
}

.form-input {
  color: var(--text);
  background: var(--surface);
  padding: 8px 10px;
  width: 100%;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  transition: border-color 0.15s;
}

.form-input:focus {
  outline: none;
  border-color: var(--accent);
}

.form-input::placeholder {
  color: var(--text-muted);
}

/* Navigation bar  */
.topnav {
  height: 52px;
  background: var(--surface);
  display: flex;
  align-items: center;
  padding: 0 24px;
  gap: 16px;
  border-bottom: 1px solid var(--border);
}

.nav-brand {
  display: flex;
  align-items: center;
  gap: 8px;
}

.nav-logo {
  width: 28px;
  height: 28px;
  object-fit: contain;
}

.nav-brand-name {
  font-size: 14px;
  font-weight: 600;
}

.nav-links {
  display: flex;
  align-items: center;
  justify-content: center;
  flex: 1;
  gap: 10px;
}

.nav-link {
  font-size: 13px;
  padding: 6px 14px;
  color: var(--text-muted);
  transition: color 0.15s;
}

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

.nav-link.active {
  color: var(--text);
  border-bottom: 1px solid var(--accent);
}

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

.nav-avatar {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  font-size: 10px;
  font-weight: 600;
}

.nav-username {
  font-size: 13px;
  color: var(--text-muted);
}

.nav-logout {
  font-size: 12px;
  background: none;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  padding: 4px 11px;
  transition:
    border-color 0.15s,
    color 0.15s;
}

.nav-logout:hover {
  border-color: var(--text);
  color: var(--text);
}

/* Dashboard */
.shell {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.content {
  max-width: 960px;
  width: 100%;
  margin: 0 auto;
  padding: 28px 24px;
}

.page-title {
  font-size: 20px;
  margin-bottom: 20px;
}

.stat-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 14px;
  margin-bottom: 16px;
}

.stat-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  padding: 12px 16px;
}

.stat-icon {
  width: 24px;
  height: 24px;
  margin-bottom: 10px;
}

.stat-label {
  font-size: 10px;
  text-transform: uppercase;
  color: var(--text-muted);
  letter-spacing: 0.5px;
  margin-bottom: 6px;
}

.stat-value {
  font-size: 20px;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  padding: 18px 20px;
  margin-bottom: 16px;
}

.card-title {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-muted);
  margin-bottom: 14px;
}

.card-sub {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-muted);
  padding: 10px 12px;
}

/* Transaction */
.tx-list {
  display: flex;
  flex-direction: column;
  gap: 7px;
}

.empty-row {
  font-size: 13px;
  color: var(--text-muted);
  text-align: center;
  padding: 20px 0;
}

.tx-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 9px 12px;
  gap: 10px;
  box-shadow: var(--shadow-sm);
  transition: border-color 0.15s;
}

.tx-item:hover {
  border-color: #ccc;
}

.tx-item.tx-income {
  border-left: 3px solid var(--income);
}

.tx-item.tx-expense {
  border-left: 3px solid var(--expense);
}

.tx-left {
  display: flex;
  flex-direction: column;
  flex: 1;
  gap: 1px;
  min-width: 0;
}

.tx-title {
  font-size: 13px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.tx-date {
  font-size: 11px;
  color: var(--text-muted);
  font-family: "DM Mono", monospace;
}

.tx-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

.tx-badge {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.5px;
  padding: 2px 7px;
  border-radius: 20px;
}

.badge-in {
  background: var(--income-bg);
  color: var(--income);
}

.badge-ex {
  background: var(--expense-bg);
  color: var(--expense);
}

.tx-amount {
  font-size: 12px;
  font-weight: 600;
  text-align: right;
  min-width: 70px;
}

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

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

.tx-actions {
  display: flex;
  gap: 6px;
}

.tx-actions a,
.tx-actions button {
  font-size: 11px;
  color: var(--text-muted);
  background: none;
  padding: 3px 9px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  line-height: 1.6;
  transition:
    border-color 0.15s,
    color 0.15s;
}

.tx-actions a:hover {
  color: var(--text);
  border-color: var(--text);
}

.tx-actions button:hover {
  color: var(--expense);
  border-color: var(--expense);
}

.pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  color: var(--text-muted);
  gap: 12px;
  margin-top: 16px;
}

.pagination a {
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 5px 13px;
  transition: border-color 0.15s;
}

.pagination a:hover {
  border-color: var(--text);
}

/* Summary */
.sum-list {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
}

.sum-card {
  display: flex;
  align-items: center;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  padding: 16px 20px;
  gap: 18px;
}

.sum-info {
  flex: 1;
  min-width: 0;
}

.sum-month {
  font-weight: 600;
  margin-bottom: 10px;
}

.sum-row {
  display: flex;
  justify-content: space-between;
  font-size: 12px;
  color: var(--text-muted);
  padding: 5px 0;
}

.sum-net {
  display: flex;
  justify-content: space-between;
  font-size: 13px;
  font-weight: 600;
  border-top: 1px solid var(--border);
  padding-top: 8px;
}

.sum-chart-wrap {
  width: 130px;
}

.tx-table {
  font-size: 13px;
  width: 100%;
  border-collapse: collapse;
}

.tx-table th {
  font-size: 11px;
  color: var(--text-muted);
  text-align: left;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  border-bottom: 1px solid var(--border);
  padding: 0 12px 10px;
}

.tx-table th.text-right {
  text-align: right;
}

.tx-table td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
}

.tx-table td:last-child,
.tx-table th:last-child {
  text-align: right;
  white-space: nowrap;
  width: 1%;
}

.tx-table tr:last-child td {
  border-bottom: none;
}

.tx-table tbody tr td:nth-child(1) {
  max-width: 200px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.tx-table tbody tr td:nth-child(4) {
  font-weight: 600;
}

.text-muted {
  font-size: 11px;
  color: var(--text-muted);
  font-family: "DM Mono", monospace;
}

.text-right {
  text-align: right;
}

.link-small {
  font-size: 12px;
  color: var(--text-muted);
  text-decoration: underline;
  text-underline-offset: 3px;
}

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

.mobile-only {
  display: none;
}

.desktop-only {
  display: table-cell;
}

/* Mobile */
@media (max-width: 640px) {
  .topnav {
    padding: 0 14px;
    gap: 12px;
  }

  .nav-username {
    display: none;
  }

  .nav-brand-name {
    display: none;
  }

  .nav-links {
    gap: 0;
  }

  .nav-link {
    font-size: 12px;
    padding: 5px 8px;
  }

  .nav-logout {
    white-space: nowrap;
  }

  .page-title {
    font-size: 16px;
  }

  .stat-row {
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
  }

  .stat-card {
    padding: 10px 8px;
  }

  .stat-icon {
    width: 18px;
    height: 18px;
    margin-bottom: 6px;
  }

  .stat-label {
    font-size: 9px;
    margin-bottom: 4px;
  }

  .stat-value {
    font-size: 13px;
  }

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

  .tx-item {
    flex-wrap: wrap;
    gap: 8px;
  }

  .tx-actions {
    width: 100%;
    border-top: 1px solid var(--border);
    padding-top: 8px;
  }

  .sum-list {
    grid-template-columns: 1fr;
  }

  .mobile-only {
    display: block;
  }

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

  .tx-table thead {
    display: none;
  }

  .tx-table tbody tr {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    padding: 4px 8px;
    gap: 8px;
    margin-bottom: 7px;
  }

  .tx-table tbody tr td {
    display: inline-flex;
    align-items: center;
    border-bottom: none;
    padding: 0;
  }

  .tx-table tbody tr td:nth-child(1) {
    flex: 1;
    flex-direction: column;
    align-items: flex-start;
    gap: 2px;
  }

  .tx-table tbody tr td:nth-child(1) span:first-child {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 100%;
  }

  .tx-table tbody tr td:nth-child(3) {
    margin-left: auto;
  }

  .tx-table tbody tr td:nth-child(4) {
    font-size: 12px;
  }

  .tx-table tbody tr td:nth-child(5) {
    width: 100%;
  }
}
