:root {
  color-scheme: light;
  --bg: #f3f8f8;
  --surface: #ffffff;
  --surface-muted: #e9f5f3;
  --text: #05233d;
  --muted: #5e7884;
  --line: #cfdee3;
  --green: #14b89f;
  --green-dark: #07947e;
  --red: #c95757;
  --blue: #1688c7;
  --gold: #f2b83f;
  --navy: #002849;
  --navy-deep: #001f39;
  --ink: #05233d;
  --shadow: 0 18px 50px rgba(0, 40, 73, 0.12);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    linear-gradient(180deg, rgba(20, 184, 159, 0.08), rgba(243, 248, 248, 0) 260px),
    var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  letter-spacing: 0;
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

.login-screen {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    linear-gradient(180deg, rgba(20, 184, 159, 0.12), rgba(243, 248, 248, 0) 280px),
    var(--bg);
}

.login-card {
  display: grid;
  gap: 16px;
  width: min(100%, 380px);
  padding: 28px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.login-logo {
  width: 76px;
  height: 76px;
  border-radius: 16px;
  object-fit: cover;
  background: #ffffff;
}

.login-card h1,
.login-card p {
  margin: 0;
}

.login-error {
  min-height: 20px;
  color: var(--red);
  font-size: 0.9rem;
  font-weight: 700;
}

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

.sidebar {
  display: flex;
  flex-direction: column;
  gap: 24px;
  padding: 24px;
  background: linear-gradient(180deg, var(--navy) 0%, var(--navy-deep) 100%);
  color: #f3fbfb;
}

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

.brand-logo {
  width: 54px;
  height: 54px;
  border-radius: 12px;
  object-fit: cover;
  background: #ffffff;
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.22);
}

.brand h1,
.brand p,
.topbar h2,
.topbar p,
.section-heading h3,
.section-heading p,
.panel h3 {
  margin: 0;
}

.brand h1 {
  font-size: 1.25rem;
}

.brand p {
  color: #a8c8d4;
  font-size: 0.88rem;
}

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

.nav-item {
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: #d6e8ee;
  min-height: 42px;
  padding: 0 12px;
  text-align: left;
}

.nav-item.active,
.nav-item:hover {
  background: rgba(20, 184, 159, 0.18);
  color: #ffffff;
  box-shadow: inset 3px 0 0 var(--green);
}

.sidebar-panel {
  display: grid;
  gap: 8px;
}

label,
.sidebar-panel label {
  color: var(--muted);
  font-size: 0.85rem;
  font-weight: 700;
}

.sidebar label {
  color: #c5dce4;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  color: var(--text);
  padding: 10px 12px;
}

textarea {
  resize: vertical;
  min-height: 180px;
}

.input-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
}

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

.topbar,
.section-heading,
.panel-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.topbar {
  margin-bottom: 24px;
}

.topbar h2 {
  font-size: clamp(1.8rem, 3vw, 2.6rem);
}

.eyebrow {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.scope-summary {
  margin: 4px 0 0;
  color: var(--muted);
  font-weight: 700;
}

.topbar-actions,
.toolbar,
.preset-actions,
.form-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
}

.current-user {
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 800;
}

.primary-button,
.secondary-button,
.danger-button,
.icon-button {
  min-height: 40px;
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 0 14px;
  font-weight: 800;
}

.primary-button {
  background: linear-gradient(180deg, var(--green), var(--green-dark));
  color: white;
  box-shadow: 0 10px 20px rgba(20, 184, 159, 0.22);
}

.secondary-button {
  border-color: var(--line);
  background: var(--surface);
  color: var(--ink);
}

.danger-button {
  border-color: #e8c4bf;
  background: #fff6f4;
  color: #9f3328;
}

.icon-button {
  background: var(--gold);
  color: var(--navy);
}

.view {
  display: none;
}

.view.active {
  display: grid;
  gap: 20px;
}

.metric-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
}

.metric {
  display: grid;
  gap: 8px;
  min-height: 120px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  padding: 18px;
  box-shadow: var(--shadow);
  position: relative;
  overflow: hidden;
}

.metric::before {
  content: "";
  position: absolute;
  inset: 0 0 auto;
  height: 4px;
  background: var(--green);
}

.metric.expense::before {
  background: var(--red);
}

.metric.balance::before {
  background: var(--blue);
}

.metric span {
  color: var(--muted);
  font-weight: 800;
}

.metric strong {
  align-self: end;
  font-size: clamp(1.4rem, 3vw, 2.2rem);
}

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

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

.balance strong {
  color: var(--navy);
}

.dashboard-layout,
.import-grid,
.rules-layout,
.report-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.4fr) minmax(320px, 0.8fr);
  gap: 20px;
}

.panel {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  padding: 18px;
  box-shadow: var(--shadow);
}

.panel.wide {
  min-height: 360px;
}

.panel-heading {
  margin-bottom: 14px;
}

.panel-heading span {
  color: var(--muted);
  font-size: 0.88rem;
  font-weight: 700;
}

.category-list,
.rules-list {
  display: grid;
  gap: 10px;
}

.category-row,
.rule-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  background: var(--surface-muted);
}

.rule-editor {
  min-width: 0;
}

.rule-actions {
  display: flex;
  gap: 8px;
}

.category-row small,
.rule-row small {
  display: block;
  color: var(--muted);
  margin-top: 3px;
}

.bar-track {
  height: 8px;
  border-radius: 999px;
  background: #dce5df;
  overflow: hidden;
  margin-top: 8px;
}

.bar-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--green), var(--blue));
}

.table-wrap {
  width: 100%;
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 760px;
}

canvas {
  display: block;
  width: 100%;
  max-width: 100%;
}

th,
td {
  border-bottom: 1px solid var(--line);
  padding: 12px 10px;
  text-align: left;
  vertical-align: middle;
}

th {
  color: var(--muted);
  font-size: 0.8rem;
  text-transform: uppercase;
}

.amount-cell {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.positive {
  color: var(--green);
}

.negative {
  color: var(--red);
}

.drop-zone {
  display: grid;
  place-items: center;
  min-height: 160px;
  border: 2px dashed #8ccfc5;
  border-radius: 8px;
  background: #f5fbfb;
  margin-bottom: 16px;
  padding: 20px;
  text-align: center;
}

.drop-zone input {
  display: none;
}

.drop-zone span {
  color: var(--muted);
  font-weight: 600;
}

.form-grid,
.rule-form,
.transaction-form {
  display: grid;
  gap: 14px;
}

.transaction-form {
  grid-template-columns: repeat(6, minmax(120px, 1fr));
  align-items: end;
}

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

.preview-box {
  margin-top: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f7fbfb;
  min-height: 110px;
  padding: 12px;
  color: var(--muted);
  white-space: pre-wrap;
}

.preview-table {
  margin-top: 14px;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  border-radius: 999px;
  padding: 0 10px;
  background: #e6eef2;
  color: var(--ink);
  font-size: 0.78rem;
  font-weight: 800;
}

.status-pill.new {
  background: rgba(20, 184, 159, 0.16);
  color: #047c6a;
}

.status-pill.duplicate {
  background: #e7edf2;
  color: #587282;
}

.status-pill.warning {
  background: rgba(242, 184, 63, 0.2);
  color: #8c620b;
}

.status-pill.error {
  background: #fde9e7;
  color: #a43d3d;
}

.preset-actions {
  margin-top: 14px;
}

.toolbar input {
  min-width: min(360px, 100%);
}

.toolbar select {
  width: 180px;
}

.toast {
  position: fixed;
  right: 20px;
  bottom: 20px;
  transform: translateY(20px);
  opacity: 0;
  pointer-events: none;
  max-width: 360px;
  border-radius: 8px;
  background: var(--navy);
  color: #ffffff;
  padding: 12px 14px;
  box-shadow: var(--shadow);
  transition: opacity 160ms ease, transform 160ms ease;
}

.toast.show {
  transform: translateY(0);
  opacity: 1;
}

.hidden {
  display: none !important;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

@media (max-width: 1040px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: sticky;
    top: 0;
    z-index: 2;
    display: grid;
    grid-template-columns: 1fr;
  }

  .nav {
    grid-template-columns: repeat(6, minmax(0, 1fr));
  }

  .nav-item {
    text-align: center;
  }

  .metric-grid,
  .dashboard-layout,
  .import-grid,
  .rules-layout,
  .report-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 720px) {
  .workspace,
  .sidebar {
    padding: 16px;
  }

  .topbar,
  .section-heading,
  .panel-heading {
    align-items: stretch;
    flex-direction: column;
  }

  .topbar-actions,
  .toolbar {
    display: grid;
    grid-template-columns: 1fr;
  }

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

  .rule-row {
    grid-template-columns: 1fr;
  }

  .rule-actions {
    display: grid;
    grid-template-columns: 1fr;
  }

  .nav {
    overflow-x: auto;
    grid-template-columns: repeat(6, minmax(120px, 1fr));
  }
}
