:root {
  --needs: #f4ad43;
  --needs-light: #fff6e8;

  --wants: #9b7bea;
  --wants-light: #f5f0ff;

  --savings: #52be7d;
  --savings-light: #edfaf2;
}

.income {
  border-color: #dff2ff;
}

.needs {
  border-color: var(--needs-light);
}

.wants {
  border-color: var(--wants-light);
}

.savings {
  border-color: var(--savings-light);
}

.section-header-total { margin-left: auto; font-size: 13px; font-weight: 500; color: #9ca3af; }

.income .section-header { background: linear-gradient(90deg, #dff2ff, #fff); }

.needs .section-header { background: linear-gradient(90deg, var(--needs-light), #fff); }

.wants .section-header { background: linear-gradient(90deg, var(--wants-light), #fff); }

.savings .section-header { background: linear-gradient(90deg, var(--savings-light), #fff); }

/* =========================
     RESULT SIDE
  ========================= */

.result-panel {
  background: white;
  border: 1px solid var(--needs-light);
  border-radius: 20px;
  padding: 0;
  position: sticky;
  top: 95px;
  overflow: hidden;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.06);
}

.result-header {
  background: linear-gradient(90deg, var(--needs-light), #fff);
}

.result-body {
  padding: 0 24px 24px;
}

/* =========================
     DONUT
  ========================= */

.overview {
  display: grid;
  grid-template-columns: 1fr 190px;
  align-items: center;
  gap: 25px;
  padding: 20px 0 25px;
  border-bottom: 1px solid var(--border);
}

.donut {
  width: 180px;
  height: 180px;
  border-radius: 50%;
  background: conic-gradient(
    var(--needs) 0 50%,
    var(--wants) 50% 80%,
    var(--savings) 80% 100%
  );
  position: relative;
  transform: rotate(-90deg);
}

.donut::after {
  content: "";
  position: absolute;
  width: 140px;
  height: 140px;
  background: white;
  border-radius: 50%;
  left: 20px;
  top: 20px;
}

.donut-center {
  position: absolute;
  z-index: 2;
  inset: 0;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  transform: rotate(90deg);
}

.donut-center span {
  color: var(--muted);
  font-size: 12px;
}

.donut-center strong {
  font-size: 23px;
  margin-top: 2px;
}

.benchmark-info h3 {
  font-size: 15px;
  margin-bottom: 7px;
}

.benchmark-info p {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.6;
}

/* =========================
     SUMMARY CARDS
  ========================= */

.summary-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin-top: 20px;
}

.summary-card {
  border: 1px solid var(--border);
  border-radius: 13px;
  overflow: hidden;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.07);
}

.summary-title {
  padding: 9px 12px;
  font-size: 12px;
  font-weight: 700;
}

.summary-content {
  padding: 16px 12px 12px;
}

.summary-value {
  font-size: 16px;
  font-weight: 450;
  margin-bottom: 4px;
  display: block;
}

.summary-value.positive {
  color: var(--success);
}

.summary-value.negative {
  color: var(--danger);
}

.summary-badge {
  display: inline-block;
  font-size: 10px;
  font-weight: 400;
  padding: 0px 8px;
  border-radius: 20px;
  margin-bottom: 3px;
}

.summary-badge.positive {
  background: #eaf8f0;
  color: var(--success);
  border: 1px solid rgba(65, 173, 112, 0.3);
}

.summary-badge.negative {
  background: #fff0f1;
  color: var(--danger);
  border: 1px solid rgba(232, 93, 99, 0.3);
}

.summary-sub {
  font-size: 10px;
  color: var(--muted);
  margin-top: 6px;
  padding-top: 10px;
  position: relative;
}

.summary-sub::before {
  content: "";
  display: block;
  height: 0.5px;
  margin-bottom: 8px;
  background: linear-gradient(
    to right,
    transparent,
    #d1d5db 30%,
    #d1d5db 70%,
    transparent
  );
  border-radius: 2px;
}

.needs-card .summary-title {
  background: var(--needs);
  color: white;
}

.wants-card .summary-title {
  background: var(--wants);
  color: white;
}

.savings-card .summary-title {
  background: var(--savings);
  color: white;
}

/* =========================
     BALANCE
  ========================= */

.balance-card {
  margin-top: 18px;
  padding: 17px;
  border: 1px solid var(--border);
  border-radius: 14px;
  display: flex;
  flex-direction: column;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.07);
}

.balance-card-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.balance-label {
  font-size: 13px;
  color: #4c5564;
}

.balance-value {
  font-size: 23px;
  font-weight: 800;
  margin-top: 3px;
}

.balance-status {
  font-size: 11px;
  padding: 5px 10px;
  border-radius: 20px;
  background: #eaf8f0;
  color: var(--success);
  font-weight: 400;
  border: 1px solid rgba(65, 173, 112, 0.3);
}

.balance-status.deficit {
  background: #fff0f1;
  color: var(--danger);
  border: 1px solid rgba(232, 93, 99, 0.3);
}

.budget-insight-badge {
  display: block;
  background: #f1f3f5;
  color: #6b7280;
  font-size: 12px;
  padding: 6px 12px;
  border-radius: 20px;
  margin-top: 14px;
  text-align: center;
}

/* =========================
     BREAKDOWN
  ========================= */

.breakdown {
  margin-top: 18px;
  border: 1px solid var(--border);
  border-radius: 14px;
  overflow: hidden;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.07);
}

.breakdown-header {
  padding: 14px 16px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  cursor: pointer;
  font-size: 14px;
  font-weight: 650;
}

.breakdown-content {
  border-top: 1px solid var(--border);
}

.breakdown-table {
  width: 100%;
  border-collapse: collapse;
}

.breakdown-table th,
.breakdown-table td {
  text-align: left;
  padding: 8px 14px;
  font-size: 12px;
  border-bottom: 1px solid #f0f2f5;
}

.breakdown-table tbody tr td {
  font-weight: 600;
  color: var(--text);
}

.breakdown-table tbody tr td:last-child {
  text-align: center;
}

.breakdown-table th:last-child {
  text-align: center;
}

.breakdown-table th {
  color: var(--muted);
  font-weight: 500;
  background: #fafbfc;
}

.difference-positive {
  color: var(--danger) !important;
  font-weight: 700;
}

.difference-negative {
  color: var(--success) !important;
  font-weight: 700;
}

.diff-badge {
  display: inline-block;
  font-size: 8px;
  font-weight: 400;
  padding: 0px 4px;
  border-radius: 20px;
  margin-top: 2px;
}

.diff-badge.positive {
  background: #eaf8f0;
  color: var(--success);
  border: 1px solid rgba(65, 173, 112, 0.3);
}

.diff-badge.negative {
  background: #fff0f1;
  color: var(--danger);
  border: 1px solid rgba(232, 93, 99, 0.3);
}

/* =========================MOBILE========================= */

/* =========================
     CATEGORY MODAL
  ========================= */

.cat-modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.35);
  z-index: 1000;
  align-items: center;
  justify-content: center;
  padding-top: 80px;
}

.cat-modal-overlay.open {
  display: flex;
}

.cat-modal {
  background: white;
  border-radius: 20px;
  width: 680px;
  max-width: 95vw;
  max-height: 65vh;
  display: flex;
  flex-direction: column;
  box-shadow: 0 8px 40px rgba(0, 0, 0, 0.18);
  overflow: hidden;
}

.cat-modal-header {
  padding: 18px 20px 14px;
  border-bottom: 1px solid var(--border);
}

.cat-modal-header h3 {
  font-size: 16px;
  font-weight: 700;
  margin-bottom: 12px;
}

.cat-modal-search {
  width: 100%;
  height: 38px;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0 12px;
  font-size: 14px;
  outline: none;
  background: #f7f8fa;
}

.cat-modal-search:focus {
  border-color: #9dd5fa;
  background: white;
}

.cat-modal-body {
  overflow-y: auto;
  padding: 16px;
  flex: 1;
}

.cat-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 10px;
}

.cat-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 12px 6px;
  border: 1px solid var(--border);
  border-radius: 12px;
  cursor: pointer;
  background: white;
  transition:
    border-color 0.15s,
    background 0.15s;
  font-size: 11px;
  font-weight: 500;
  color: #303846;
  text-align: center;
  line-height: 1.3;
}

.cat-item:hover {
  border-color: var(--primary);
  background: var(--primary-light);
}

.cat-item img {
  width: 32px;
  height: 32px;
  object-fit: contain;
}

.cat-icon-wrap {
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.cat-icon-wrap img {
  width: 40px;
  height: 40px;
  object-fit: contain;
  filter: brightness(0) opacity(0.8);
}

.cat-modal-close {
  float: right;
  background: none;
  border: none;
  font-size: 20px;
  cursor: pointer;
  color: var(--muted);
  line-height: 1;
  padding: 0;
}

.cat-modal-loading {
  text-align: center;
  padding: 40px;
  color: var(--muted);
  font-size: 14px;
  grid-column: 1 / -1;
}

.remove-row-btn {
  flex-shrink: 0;
  width: 20px;
  height: 20px;
  border: none;
  background: none;
  color: #c0c7d0;
  font-size: 13px;
  cursor: pointer;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  line-height: 1;
  transition: background 0.15s, color 0.15s;
}

.remove-row-btn:hover {
  background: #fff0f1;
  color: #e85d63;
}

.input-row-right {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.currency-btn {
  display: flex;
  align-items: center;
  gap: 5px;
  height: 30px;
  border: 1px solid #e0e4ea;
  border-radius: 7px;
  padding: 0 10px;
  font-size: 13px;
  font-weight: 600;
  color: #21262f;
  background: #fff;
  cursor: pointer;
  white-space: nowrap;
  outline: none;
}

.currency-dropdown {
  display: none;
  position: absolute;
  top: calc(100% + 4px);
  right: 0;
  background: #fff;
  border: 1px solid #e0e4ea;
  border-radius: 9px;
  box-shadow: 0 6px 20px rgba(0,0,0,0.1);
  z-index: 999;
  min-width: 110px;
  max-height: 220px;
  overflow-y: auto;
  padding: 4px 0;
}

.currency-dropdown.open { display: block; }

.currency-option {
  padding: 7px 14px;
  font-size: 13px;
  font-weight: 500;
  color: #21262f;
  cursor: pointer;
}

.currency-option:hover { background: #f4f6f9; }
.currency-option.selected { font-weight: 700; color: #2389dc; }

@media (max-width: 1000px) {
  .result-panel {
    position: static;
  }
}

@media (max-width: 650px) {
  .overview {
    grid-template-columns: 1fr;
    justify-items: center;
  }

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

  .input-row {
    gap: 10px;
  }

  .breakdown {
    overflow-x: auto;
  }

  .breakdown-table {
    min-width: 500px;
  }

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

  .cat-item {
    padding: 10px 4px;
    min-height: 80px;
    font-size: 10px;
    word-break: break-word;
    hyphens: auto;
  }

  .cat-item span {
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .cat-icon-wrap img {
    width: 32px;
    height: 32px;
  }

  .cat-modal {
    max-height: 75vh;
  }

  .cat-modal-overlay {
    padding-top: 60px;
  }
}
