:root {
  --bg: #f5f7fb;
  --panel: #ffffff;
  --panel-alt: #eef4ff;
  --border: #dfe7f5;
  --text: #14213d;
  --muted: #5d6b82;
  --primary: #5b68f5;
  --primary-dark: #3b49d9;
  --success: #14b87a;
  --danger: #ef4d5d;
  --warning: #f7b955;
  --shadow: 0 10px 25px rgba(15, 25, 54, 0.08);
}

* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  min-height: 100%;
  font-family: Inter, "Segoe UI", sans-serif;
  background: linear-gradient(180deg, #eef3ff 0%, var(--bg) 180px);
  color: var(--text);
}

body {
  min-height: 100vh;
}

button, input, select {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-shell {
  display: grid;
  grid-template-columns: 320px minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  background: #111827;
  color: white;
  padding: 26px 20px;
  border-right: 1px solid rgba(255, 255, 255, 0.06);
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 24px;
}

.brand-mark {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 42px;
  height: 42px;
  border-radius: 12px;
  background: linear-gradient(135deg, #6d7aff, #8d7af7);
  font-weight: 700;
  font-size: 1.2rem;
}

.brand strong,
.brand small {
  display: block;
}

.brand small {
  color: rgba(255, 255, 255, 0.7);
}

.sidebar-actions,
.topbar-actions,
.form-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.primary-button,
.secondary-button,
.ghost-button,
.remove-row {
  border: none;
  border-radius: 12px;
  padding: 0.7rem 1rem;
  font-weight: 600;
  transition: transform 0.2s ease, opacity 0.2s ease;
}

.primary-button {
  background: linear-gradient(135deg, var(--primary), var(--primary-dark));
  color: white;
  box-shadow: var(--shadow);
}

.secondary-button {
  background: rgba(255, 255, 255, 0.08);
  color: white;
  border: 1px solid rgba(255, 255, 255, 0.14);
}

.ghost-button {
  background: var(--panel-alt);
  color: var(--text);
  border: 1px solid var(--border);
}

.remove-row {
  background: rgba(239, 77, 93, 0.08);
  color: var(--danger);
  width: 38px;
  padding: 0.5rem;
}

.primary-button:hover,
.secondary-button:hover,
.ghost-button:hover,
.remove-row:hover {
  transform: translateY(-1px);
}

.sidebar-header {
  margin: 28px 0 12px;
}

.sidebar-header h3 {
  margin: 0;
  font-size: 0.9rem;
  color: rgba(255, 255, 255, 0.72);
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.budget-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.budget-item {
  display: flex;
  flex-direction: column;
  gap: 4px;
  width: 100%;
  text-align: left;
  padding: 0.9rem 0.9rem;
  border-radius: 14px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  background: rgba(255, 255, 255, 0.02);
  color: white;
}

.budget-item.is-active {
  background: rgba(91, 104, 245, 0.18);
  border-color: rgba(91, 104, 245, 0.54);
}

.budget-item.is-primary {
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.12);
}

.budget-name {
  font-weight: 700;
}

.budget-meta {
  color: rgba(255, 255, 255, 0.78);
  font-size: 0.8rem;
}

.main-panel {
  padding: 28px;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  margin-bottom: 24px;
}

.eyebrow {
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-size: 0.77rem;
  font-weight: 700;
  color: var(--muted);
}

h1 {
  margin: 0.35rem 0 0;
  font-size: clamp(1.8rem, 2vw, 2.5rem);
}

.state-panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 1.5rem;
  box-shadow: var(--shadow);
  margin-bottom: 1rem;
}

.hidden {
  display: none !important;
}

.dashboard {
  display: grid;
  gap: 20px;
}

.summary-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 16px;
}

.summary-card {
  border-radius: 18px;
  padding: 1rem 1.2rem;
  background: var(--panel);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
}

.summary-card .label {
  display: block;
  margin-bottom: 0.5rem;
  color: var(--muted);
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.summary-card strong {
  font-size: clamp(1.3rem, 2vw, 1.8rem);
}

.accent-purple { border-top: 4px solid #7c3aed; }
.accent-green { border-top: 4px solid #10b981; }
.accent-red { border-top: 4px solid #ef4d5d; }
.accent-blue { border-top: 4px solid #3b82f6; }
.accent-gold { border-top: 4px solid #f7b955; }

.content-grid {
  display: grid;
  grid-template-columns: minmax(360px, 1.1fr) minmax(320px, 0.9fr);
  gap: 18px;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 20px;
  box-shadow: var(--shadow);
  padding: 1.2rem;
}

.panel--wide {
  grid-column: 1 / -1;
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.9rem;
}

.panel-header h2 {
  margin: 0;
  font-size: 1.15rem;
}

.budget-form {
  display: grid;
  gap: 18px;
}

.field-row {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

label {
  display: flex;
  flex-direction: column;
  gap: 7px;
  font-weight: 600;
  color: var(--muted);
}

input, select {
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 0.8rem 0.85rem;
  background: #ffffff;
  color: var(--text);
}

input:focus, select:focus {
  outline: 2px solid rgba(91, 104, 245, 0.2);
  border-color: rgba(91, 104, 245, 0.6);
}

.subsection {
  display: grid;
  gap: 10px;
}

.subsection h3 {
  margin: 0;
  font-size: 0.95rem;
}

.dynamic-list {
  display: grid;
  gap: 10px;
}

.row-item {
  display: grid;
  grid-template-columns: minmax(0, 1.3fr) minmax(80px, 0.7fr) auto auto;
  gap: 8px;
  align-items: center;
}

.row-item select {
  min-width: 110px;
}

.category-chart {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(110px, 1fr));
  gap: 12px;
  align-items: end;
  min-height: 220px;
}

.chart-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}

.chart-bar-wrap {
  width: 100%;
  height: 150px;
  border-radius: 12px;
  background: linear-gradient(180deg, #f2f6ff 0%, #edf3ff 100%);
  display: flex;
  align-items: end;
  padding: 6px;
}

.chart-bar {
  width: 100%;
  border-radius: 10px 10px 6px 6px;
  min-height: 10px;
}

.chart-label,
.chart-total {
  font-size: 0.75rem;
  color: var(--muted);
  text-align: center;
}

.transaction-list {
  display: grid;
  gap: 12px;
}

.transaction-row {
  display: grid;
  grid-template-columns: minmax(0, 1.6fr) minmax(100px, auto) minmax(130px, 200px);
  gap: 12px;
  align-items: center;
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 0.8rem 0.9rem;
  background: linear-gradient(180deg, #ffffff, #f8faff);
}

.transaction-main {
  min-width: 0;
}

.transaction-name {
  font-weight: 700;
  margin-bottom: 4px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.transaction-meta {
  font-size: 0.8rem;
  color: var(--muted);
}

.transaction-amount {
  font-weight: 700;
  justify-self: end;
}

.transaction-amount.credit {
  color: var(--success);
}

.transaction-amount.debit {
  color: var(--danger);
}

.transaction-category-selector {
  width: 100%;
}

.comparison-table table {
  width: 100%;
  border-collapse: collapse;
}

.comparison-table th,
.comparison-table td {
  padding: 0.8rem 0.7rem;
  border-bottom: 1px solid var(--border);
  text-align: left;
}

.comparison-table th {
  color: var(--muted);
  font-size: 0.82rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.is-primary-row {
  background: rgba(91, 104, 245, 0.04);
}

.empty-inline {
  color: var(--muted);
  font-style: italic;
  padding: 1rem 0.4rem;
}

@media (max-width: 980px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    border-right: none;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  }

  .content-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 640px) {
  .main-panel {
    padding: 18px;
  }

  .field-row,
  .transaction-row,
  .row-item {
    grid-template-columns: 1fr;
  }

  .topbar {
    flex-direction: column;
    align-items: flex-start;
  }
}
