:root {
  --font: "Poppins", system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --background: #f5f7fb;
  --foreground: #141922;
  --card: #ffffff;
  --muted-foreground: #637083;
  --border: #dbe2ec;
  --primary: #0a63ff;
  --secondary: #7b4bd6;
  --accent: #20a876;
  --destructive: #dd3737;
  --shadow: 0 1px 3px rgba(18, 27, 41, 0.08);
  --shadow-lg: 0 18px 60px rgba(17, 24, 39, 0.22);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  background: var(--background);
  color: var(--foreground);
  font-family: var(--font);
  letter-spacing: 0;
}

button, input, select { font: inherit; }
button { cursor: pointer; }

.login-page {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    radial-gradient(circle at 20% 15%, rgba(10, 99, 255, 0.16), transparent 28%),
    radial-gradient(circle at 80% 70%, rgba(32, 168, 118, 0.13), transparent 32%),
    var(--background);
}

.login-card {
  width: min(420px, 100%);
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 18px;
  box-shadow: var(--shadow-lg);
  padding: 30px;
  text-align: center;
}

.login-logo {
  width: 82px;
  height: 82px;
  border-radius: 20px;
  object-fit: cover;
  margin: 0 auto 16px;
  box-shadow: 0 14px 32px rgba(10, 99, 255, 0.22);
}

.login-form {
  display: grid;
  gap: 14px;
  margin-top: 24px;
  text-align: left;
}

.auth-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  margin-top: 22px;
  padding: 5px;
  border-radius: 14px;
  background: #eef3fb;
}

.auth-tabs button {
  min-height: 38px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: var(--muted-foreground);
  font-weight: 800;
}

.auth-tabs button.active {
  background: #fff;
  color: var(--primary);
  box-shadow: var(--shadow);
}

.login-form .btn {
  width: 100%;
}

.login-error {
  padding: 10px 12px;
  border: 1px solid rgba(221, 55, 55, 0.22);
  border-radius: 12px;
  background: rgba(221, 55, 55, 0.08);
  color: var(--destructive);
  font-size: 13px;
  font-weight: 700;
}

.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 260px minmax(0, 1fr);
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  background: var(--primary);
  color: #fff;
  padding: 22px 16px;
  display: flex;
  flex-direction: column;
  gap: 24px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 4px 6px;
  min-width: 0;
}

.brand-logo {
  width: 48px;
  height: 48px;
  border-radius: 14px;
  object-fit: cover;
  background: #fff;
  box-shadow: 0 12px 24px rgba(0, 0, 0, 0.14);
  flex: 0 0 auto;
}

.brand-title {
  font-size: 19px;
  font-weight: 800;
  line-height: 1.1;
}

.brand-subtitle {
  font-size: 11px;
  opacity: 0.84;
  margin-top: 3px;
}

.nav { display: grid; gap: 8px; }

.nav-link {
  min-height: 44px;
  border: 0;
  border-radius: 12px;
  padding: 0 12px;
  display: flex;
  align-items: center;
  gap: 11px;
  background: transparent;
  color: #fff;
  text-align: left;
  font-weight: 600;
}

.nav-link:hover, .nav-link.active { background: rgba(255, 255, 255, 0.15); }
.nav-link.active { box-shadow: inset 3px 0 0 #fff; }

.nav-icon {
  width: 22px;
  height: 22px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.14);
  font-size: 13px;
}

.sidebar-footer {
  margin-top: auto;
  padding: 14px;
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.1);
}

.user-email {
  margin-top: 6px;
  font-size: 11px;
  opacity: 0.82;
  overflow-wrap: anywhere;
}

.logout-btn {
  width: 100%;
  min-height: 34px;
  margin-top: 12px;
  border: 1px solid rgba(255, 255, 255, 0.24);
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.13);
  color: #fff;
  font-weight: 700;
}

.main {
  min-width: 0;
  padding: 28px;
}

.mobile-topbar {
  display: none;
  margin-bottom: 18px;
  justify-content: space-between;
  align-items: center;
}

.mobile-nav {
  display: none;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  margin-bottom: 18px;
}

.mobile-nav .nav-link {
  color: var(--foreground);
  background: var(--card);
  justify-content: center;
  padding: 0 8px;
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
}

.mobile-nav .nav-link span:last-child { display: none; }

.page {
  max-width: 1280px;
  margin: 0 auto;
}

.page.narrow { max-width: 896px; }

.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 24px;
}

h1 {
  margin: 0;
  font-size: clamp(26px, 3vw, 32px);
  line-height: 1.18;
}

.subtle {
  margin: 6px 0 0;
  color: var(--muted-foreground);
  font-size: 14px;
}

.month-picker, .toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
}

.icon-btn, .btn {
  min-height: 40px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--card);
  color: var(--foreground);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 0 14px;
  font-weight: 700;
  box-shadow: var(--shadow);
}

.icon-btn {
  width: 40px;
  padding: 0;
}

.btn.primary {
  border-color: transparent;
  background: var(--primary);
  color: #fff;
}

.btn.secondary {
  border-color: transparent;
  background: var(--secondary);
  color: #fff;
}

.btn.danger {
  border-color: transparent;
  background: var(--destructive);
  color: #fff;
}

.btn.ghost { box-shadow: none; }

.month-label {
  min-width: 146px;
  text-align: center;
  font-size: 14px;
  font-weight: 700;
}

.grid { display: grid; gap: 16px; }
.stats { grid-template-columns: repeat(4, minmax(0, 1fr)); margin-bottom: 24px; }
.stats.compact { grid-template-columns: repeat(3, minmax(0, 1fr)); }

.notice {
  margin: -6px 0 20px;
  padding: 14px 16px;
  border: 1px solid rgba(245, 158, 11, 0.28);
  border-left: 5px solid #f59e0b;
  border-radius: 14px;
  background: #fff8eb;
  color: #613f08;
  font-size: 14px;
  line-height: 1.55;
  box-shadow: var(--shadow);
}

.notice strong {
  color: #92400e;
}

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: var(--shadow);
}

.stat-card {
  padding: 20px;
  display: flex;
  justify-content: space-between;
  gap: 16px;
  min-height: 126px;
}

.stat-label {
  margin: 0;
  color: var(--muted-foreground);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
}

.stat-value {
  margin: 8px 0 0;
  font-size: 25px;
  font-weight: 800;
  overflow-wrap: anywhere;
}

.stat-note {
  margin-top: 7px;
  color: var(--primary);
  font-size: 12px;
  font-weight: 700;
  background: none;
  border: 0;
  padding: 0;
}

.stat-icon {
  width: 44px;
  height: 44px;
  border-radius: 13px;
  display: grid;
  place-items: center;
  color: #fff;
  flex: 0 0 auto;
}

.blue { background: #3b82f6; }
.green { background: #22c55e; }
.emerald { background: #10b981; }
.red { background: #ef4444; }
.purple { background: #8b5cf6; }
.orange { background: #f59e0b; }

.panel {
  padding: 20px;
  margin-bottom: 24px;
}

.panel-title {
  margin: 0 0 16px;
  font-size: 15px;
  font-weight: 700;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 12px;
  align-items: end;
}

.form-grid.load { grid-template-columns: repeat(4, minmax(0, 1fr)); }

label {
  display: block;
  margin-bottom: 6px;
  color: var(--muted-foreground);
  font-size: 12px;
  font-weight: 700;
}

input, select {
  width: 100%;
  min-height: 44px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: #fff;
  padding: 0 13px;
  color: var(--foreground);
  outline: none;
}

input:focus, select:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(10, 99, 255, 0.12);
}

.table-card { overflow: hidden; }

.table-header {
  min-height: 58px;
  padding: 0 20px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.table-header h2 {
  margin: 0;
  font-size: 15px;
}

.transaction-list { display: grid; }

.transaction-row {
  min-height: 72px;
  padding: 14px 20px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  align-items: center;
  gap: 16px;
  border-bottom: 1px solid rgba(219, 226, 236, 0.65);
}

.transaction-row:last-child { border-bottom: 0; }

.transaction-main {
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 12px;
}

.direction {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  font-weight: 800;
}

.direction.in {
  color: #179553;
  background: #dcfce7;
}

.direction.out {
  color: #dc2626;
  background: #fee2e2;
}

.transaction-title {
  margin: 0;
  font-size: 14px;
  font-weight: 700;
  overflow-wrap: anywhere;
}

.transaction-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 7px;
  margin-top: 4px;
  color: var(--muted-foreground);
  font-size: 12px;
}

.tag {
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 10px;
  font-weight: 800;
}

.tag.cash {
  background: #dbeafe;
  color: #1d4ed8;
}

.tag.load {
  background: #ede9fe;
  color: #6d28d9;
}

.profit {
  color: #16a34a;
  font-weight: 700;
}

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

.amount.positive { color: #16a34a; }
.amount.negative { color: #ef4444; }

.empty {
  padding: 54px 20px;
  color: var(--muted-foreground);
  text-align: center;
  font-size: 14px;
}

.history-groups {
  display: grid;
  gap: 22px;
}

.date-heading {
  margin: 0 0 10px;
  color: var(--muted-foreground);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.search-wrap {
  position: relative;
  flex: 1;
}

.search-wrap input { padding-left: 42px; }

.search-icon {
  position: absolute;
  left: 14px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--muted-foreground);
}

.capital-editor {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 8px;
}

.capital-editor input {
  width: 120px;
  min-height: 30px;
  border-radius: 8px;
  padding: 0 8px;
  font-size: 12px;
}

.toast {
  position: fixed;
  top: 18px;
  right: 18px;
  z-index: 60;
  display: none;
  max-width: min(360px, calc(100vw - 32px));
  padding: 12px 14px;
  border-radius: 12px;
  background: #111827;
  color: #fff;
  box-shadow: var(--shadow-lg);
  font-weight: 700;
  font-size: 13px;
}

.toast.show {
  display: block;
  animation: toast-in 0.18s ease-out;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 50;
  background: rgba(0, 0, 0, 0.72);
  display: grid;
  place-items: center;
  padding: 20px;
}

.modal {
  width: min(520px, 100%);
  border-radius: 16px;
  border: 1px solid var(--border);
  background: var(--background);
  padding: 24px;
  box-shadow: var(--shadow-lg);
}

.modal h2 {
  margin: 0 0 8px;
  font-size: 20px;
}

.modal p {
  margin: 0 0 20px;
  color: var(--muted-foreground);
  font-size: 14px;
}

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

@keyframes toast-in {
  from {
    transform: translateY(-8px);
    opacity: 0;
  }
}

@media (max-width: 1040px) {
  .stats, .stats.compact { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .form-grid, .form-grid.load { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 760px) {
  .app-shell { display: block; }
  .sidebar { display: none; }
  .main { padding: 16px; }
  .mobile-topbar { display: flex; }
  .mobile-nav { display: grid; }
  .page-header, .toolbar {
    align-items: stretch;
    flex-direction: column;
  }
  .month-picker { justify-content: space-between; }
  .stats, .stats.compact, .form-grid, .form-grid.load { grid-template-columns: 1fr; }
  .transaction-row { grid-template-columns: minmax(0, 1fr) auto; }
  .transaction-row .icon-btn { grid-column: 2; }
  .amount {
    grid-column: 2;
    grid-row: 1;
  }
}
