:root {
  --bg: #071633;
  --panel: #0f2247;
  --panel-2: #132b58;
  --text: #eef4ff;
  --muted: #a7b7d9;
  --line: rgba(255, 255, 255, 0.1);
  --primary: #5da2ff;
  --danger: #ff6b6b;
  --success: #42d392;
  --expense: #ff8a8a;
  --income: #7ee3a8;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.25);
  --radius: 18px;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: Arial, Helvetica, sans-serif;
  -webkit-tap-highlight-color: transparent;
}

body {
  min-height: 100vh;
}

button,
input,
select {
  font: inherit;
}

.app {
  width: min(1100px, calc(100% - 24px));
  margin: 0 auto;
  padding: 16px 0 32px;
}

.topbar {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: flex-start;
  padding: 10px 0 18px;
}

.topbar h1 {
  margin: 0 0 4px;
  font-size: 28px;
}

.subtitle {
  margin: 0;
  color: var(--muted);
  font-size: 14px;
}

.topbar-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.main {
  display: grid;
  gap: 16px;
}

.panel,
.card {
  background: linear-gradient(180deg, var(--panel), var(--panel-2));
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.panel {
  padding: 14px;
}

.panel-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  margin-bottom: 12px;
}

.panel-head h2 {
  margin: 0;
  font-size: 18px;
}

.import-meta {
  display: grid;
  gap: 8px;
  color: var(--muted);
}

.summary-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
}

.stat-card {
  display: grid;
  gap: 6px;
  padding: 16px;
  border-radius: 18px;
  border: 1px solid var(--line);
  background: linear-gradient(180deg, rgba(255,255,255,0.05), rgba(255,255,255,0.02));
}

.stat-card .label {
  font-size: 12px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.stat-card .value {
  font-size: 22px;
  font-weight: 800;
  line-height: 1.2;
}

.stat-card:nth-child(1) .value {
  color: #3eea8a; /* income */
}

.stat-card:nth-child(2) .value {
  color: #ff6b6b; /* expenses */
}

.stat-card:nth-child(3) .value {
  color: #6ea8ff; /* net */
}

.stat-card:nth-child(4) .value {
  color: #f6c85f; /* fees */
}

.stat-card {
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.stat-card:active {
  transform: scale(0.98);
}

.stat-card:hover {
  box-shadow: 0 10px 30px rgba(0,0,0,0.25);
}

.filters-row {
  display: grid;
  grid-template-columns: 2fr 1fr;
  gap: 10px;
}

.input {
  width: 100%;
  min-height: 44px;
  background: rgba(255, 255, 255, 0.06);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 0 14px;
  outline: none;
}

.input::placeholder {
  color: #c3d0ea;
}

.btn {
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 0 14px;
  cursor: pointer;
  color: white;
  background: rgba(255, 255, 255, 0.08);
}

.btn.primary {
  background: var(--primary);
  color: #071633;
  border-color: transparent;
  font-weight: 700;
}

.btn.danger {
  background: var(--danger);
  border-color: transparent;
  font-weight: 700;
}

.file-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.monthly-list {
  display: grid;
  gap: 10px;
}

.month-card {
  display: grid;
  grid-template-columns: 1.2fr 1fr 1fr 1fr;
  gap: 10px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.04);
}

.month-title {
  font-weight: 700;
}

.month-meta {
  color: var(--muted);
  font-size: 13px;
}

.tx-list {
  display: grid;
  gap: 10px;
}

.tx-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 14px;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 14px;
  background: rgba(255, 255, 255, 0.04);
}

.tx-left {
  min-width: 0;
}

.tx-right {
  display: grid;
  gap: 6px;
  justify-items: end;
  text-align: right;
}

.tx-desc {
  font-weight: 700;
  font-size: 15px;
  line-height: 1.3;
  word-break: break-word;
}

.tx-sub {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.35;
}

.tx-meta-line {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 2px;
}

.tx-fee {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.2;
}

.amount.income {
  color: var(--income);
  font-weight: 700;
}

.amount.expense {
  color: var(--expense);
  font-weight: 700;
}

.badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 28px;
  padding: 0 10px;
  border-radius: 999px;
  font-size: 12px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.06);
}

.empty-state {
  color: var(--muted);
  padding: 10px 2px;
}

.muted {
  color: var(--muted);
  font-size: 13px;
}

@media (max-width: 900px) {
  .summary-grid {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

  .tx-row {
    grid-template-columns: 1fr;
  }
  
  .tx-right {
    justify-items: start;
    text-align: left;
  }

  .month-card {
    grid-template-columns: 1fr;
  }

  .filters-row {
    grid-template-columns: 1fr;
  }

  .topbar {
    flex-direction: column;
  }
}

.imports-list {
  display: grid;
  gap: 10px;
}

.import-row {
  display: grid;
  grid-template-columns: 2fr 1fr auto auto;
  gap: 10px;
  align-items: center;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.04);
}

.import-main {
  display: grid;
  gap: 4px;
}

.import-name {
  font-weight: 700;
  word-break: break-word;
}

.import-sub {
  font-size: 13px;
  color: var(--muted);
}

.import-btn {
  min-height: 34px;
  padding: 0 12px;
  border-radius: 10px;
  font-size: 12px;
  cursor: pointer;
  border: 1px solid var(--line);
  background: rgba(255,255,255,0.06);
  color: white;
}

.import-btn.active {
  background: var(--primary);
  color: #071633;
  font-weight: 700;
  border-color: transparent;
}

.import-btn.danger {
  background: var(--danger);
  border-color: transparent;
}

@media (max-width: 900px) {
  .import-row {
    grid-template-columns: 1fr;
  }
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 1000;
}

.modal.hidden {
  display: none;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.6);
}

.modal-content {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  background: #071633;
  border-radius: 20px 20px 0 0;
  padding: 16px;
  max-height: 70vh;
  overflow-y: auto;
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
}

.modal-close {
  background: none;
  border: none;
  color: white;
  font-size: 20px;
}

.modal-list {
  display: grid;
  gap: 10px;
}

.modal-item {
  padding: 12px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: rgba(255,255,255,0.05);
  cursor: pointer;
}

.topbar-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.stat-card {
  display: grid;
  gap: 6px;
  padding: 16px;
  border-radius: 18px;
  border: 1px solid var(--line);
  background: linear-gradient(180deg, rgba(255,255,255,0.05), rgba(255,255,255,0.02));
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.stat-card .label {
  font-size: 12px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.stat-card .value {
  font-size: 22px;
  font-weight: 800;
  line-height: 1.2;
}

.stat-card:nth-child(1) .value {
  color: #3eea8a;
}

.stat-card:nth-child(2) .value {
  color: #ff6b6b;
}

.stat-card:nth-child(3) .value {
  color: #6ea8ff;
}

.stat-card:nth-child(4) .value {
  color: #f6c85f;
}

.stat-card:active {
  transform: scale(0.98);
}

.stat-card:hover {
  box-shadow: 0 10px 30px rgba(0,0,0,0.25);
}

.tx-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 14px;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 14px;
  background: rgba(255, 255, 255, 0.04);
}

.tx-left {
  min-width: 0;
}

.tx-main {
  display: grid;
  gap: 4px;
}

.tx-right {
  display: grid;
  gap: 6px;
  justify-items: end;
  text-align: right;
}

.tx-desc {
  font-weight: 700;
  font-size: 15px;
  line-height: 1.3;
  word-break: break-word;
}

.tx-sub {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.35;
}

.tx-meta-line {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 2px;
}

.tx-fee {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.2;
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 1000;
}

.modal.hidden {
  display: none;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(2, 8, 24, 0.72);
  backdrop-filter: blur(2px);
}

.modal-sheet {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  max-height: 76vh;
  overflow-y: auto;
  padding: 16px 16px calc(16px + env(safe-area-inset-bottom));
  background: linear-gradient(180deg, #0c1f45, #071633);
  border-top-left-radius: 22px;
  border-top-right-radius: 22px;
  border: 1px solid var(--line);
  box-shadow: 0 -20px 40px rgba(0, 0, 0, 0.35);
}

.modal-sheet-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 12px;
}

.modal-sheet-header h3 {
  margin: 0;
  font-size: 20px;
}

.modal-close {
  min-width: 40px;
  min-height: 40px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: rgba(255,255,255,0.06);
  color: #fff;
  font-size: 20px;
}

.modal-sheet-actions {
  display: flex;
  gap: 10px;
  margin-bottom: 12px;
}

.modal-import-list {
  display: grid;
  gap: 12px;
}

.modal-import-card {
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 12px;
  background: rgba(255,255,255,0.04);
}

.modal-import-main {
  display: grid;
  gap: 6px;
  cursor: pointer;
}

.modal-import-name {
  font-weight: 700;
  font-size: 16px;
  line-height: 1.3;
  word-break: break-word;
}

.modal-import-sub {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.35;
}

.modal-import-date {
  font-size: 13px;
}

.modal-import-actions {
  display: flex;
  gap: 10px;
  margin-top: 12px;
}

.import-btn {
  flex: 1;
  min-height: 42px;
  padding: 0 12px;
  border-radius: 12px;
  font-size: 14px;
  cursor: pointer;
  border: 1px solid var(--line);
  background: rgba(255,255,255,0.06);
  color: white;
}

.import-btn.active {
  background: var(--primary);
  color: #071633;
  font-weight: 700;
  border-color: transparent;
}

.import-btn.danger {
  background: var(--danger);
  border-color: transparent;
}

@media (max-width: 900px) {
  .summary-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .tx-row {
    grid-template-columns: 1fr;
  }

  .tx-right {
    justify-items: start;
    text-align: left;
  }

  .month-card {
    grid-template-columns: 1fr;
  }

  .filters-row {
    grid-template-columns: 1fr;
  }

  .topbar {
    flex-direction: column;
  }

  .topbar-actions {
    width: 100%;
  }

  .topbar-actions .btn,
  .topbar-actions .file-btn {
    flex: 1;
  }

  .modal-import-actions {
    flex-direction: column;
  }
}

.input-btn {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  text-align: left;
  cursor: pointer;
}

.modal-type-list {
  display: grid;
  gap: 10px;
}

.type-option {
  min-height: 48px;
  width: 100%;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: rgba(255,255,255,0.06);
  color: white;
  padding: 0 14px;
  text-align: left;
  font: inherit;
}

.type-option.active {
  background: var(--primary);
  color: #071633;
  border-color: transparent;
  font-weight: 700;
}

.merchant-card {
  border: 1px solid var(--line);
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.04);
  overflow: hidden;
}

.merchant-summary {
  width: 100%;
  border: 0;
  background: transparent;
  color: inherit;
  padding: 14px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 14px;
  align-items: center;
  text-align: left;
  cursor: pointer;
}

.merchant-summary-left {
  min-width: 0;
}

.merchant-summary-right {
  display: grid;
  gap: 8px;
  justify-items: end;
  text-align: right;
}

.merchant-name {
  font-size: 18px;
  font-weight: 700;
  line-height: 1.25;
  word-break: break-word;
}

.merchant-sub {
  margin-top: 4px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.35;
}

.merchant-total {
  font-size: 20px;
  font-weight: 800;
  line-height: 1.2;
}

.merchant-arrow {
  font-size: 14px;
  color: var(--muted);
}

.merchant-arrow.open {
  color: var(--text);
}

.merchant-children {
  display: none;
  padding: 0 14px 14px;
  border-top: 1px solid var(--line);
}

.merchant-children.open {
  display: grid;
  gap: 10px;
  padding-top: 12px;
}

.child-tx-row {
  background: rgba(255, 255, 255, 0.03);
}

@media (max-width: 900px) {
  .merchant-summary {
    grid-template-columns: 1fr;
  }

  .merchant-summary-right {
    justify-items: start;
    text-align: left;
  }

  .merchant-total {
    font-size: 18px;
  }
}

#updateModal .modal-sheet {
  max-width: 520px;
  margin: 0 auto;
  left: 12px;
  right: 12px;
  bottom: 16px;
  border-radius: 20px;
}

@media (max-width: 900px) {
  #updateModal .modal-sheet {
    left: 0;
    right: 0;
    bottom: 0;
    max-width: none;
    border-radius: 20px 20px 0 0;
  }
}