:root {
  --bg: #f5f7f4;
  --surface: #ffffff;
  --surface-2: #eef3f0;
  --ink: #1b2620;
  --muted: #647168;
  --line: #dbe3de;
  --green: #168255;
  --red: #b64242;
  --blue: #315f9f;
  --amber: #a66d12;
  --shadow: 0 18px 45px rgba(23, 35, 29, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background: var(--bg);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
input {
  font: inherit;
}

.app-shell {
  min-height: 100vh;
  padding: 18px;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(260px, 320px) minmax(380px, 1fr) minmax(280px, 380px);
  gap: 14px;
  min-height: calc(100vh - 36px);
}

.sidebar,
.chat-area,
.ledger {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.sidebar,
.ledger {
  padding: 16px;
  overflow: auto;
}

.brand {
  display: flex;
  gap: 10px;
  align-items: center;
  margin-bottom: 18px;
}

.brand-mark {
  display: grid;
  width: 38px;
  height: 38px;
  place-items: center;
  border-radius: 8px;
  color: #fff;
  background: var(--green);
  font-weight: 800;
}

.brand strong,
.brand span {
  display: block;
}

.brand span,
.metric span,
.message-time,
.transaction-meta,
.empty {
  color: var(--muted);
  font-size: 0.84rem;
}

.metric-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.metric {
  min-height: 88px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-2);
}

.metric strong {
  display: block;
  margin-top: 8px;
  font-size: clamp(1rem, 2vw, 1.3rem);
  line-height: 1.15;
  overflow-wrap: anywhere;
}

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

.panel {
  margin-top: 18px;
}

.panel-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}

.ledger .panel-title:not(:first-child) {
  margin-top: 18px;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: clamp(1.25rem, 3vw, 1.8rem);
}

h2 {
  font-size: 0.95rem;
}

.chat-area {
  display: grid;
  grid-template-rows: auto 1fr auto;
  min-width: 0;
  overflow: hidden;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 16px;
  border-bottom: 1px solid var(--line);
}

.topbar p {
  color: var(--muted);
  margin-top: 4px;
}

.upload-button {
  flex: 0 0 auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
  background: #f7faf8;
  color: var(--blue);
  font-weight: 700;
  cursor: pointer;
}

.upload-button input {
  position: absolute;
  inline-size: 1px;
  block-size: 1px;
  opacity: 0;
}

.messages {
  display: flex;
  flex-direction: column;
  gap: 10px;
  overflow: auto;
  padding: 16px;
}

.message {
  max-width: min(75ch, 86%);
  border-radius: 8px;
  padding: 11px 12px;
  border: 1px solid var(--line);
  background: #f9fbfa;
}

.message.user {
  align-self: flex-end;
  color: #fff;
  background: var(--blue);
  border-color: var(--blue);
}

.message.assistant {
  align-self: flex-start;
}

.message p {
  line-height: 1.45;
  overflow-wrap: anywhere;
}

.message.user .message-time {
  color: rgba(255, 255, 255, 0.78);
}

.composer {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  padding: 14px;
  border-top: 1px solid var(--line);
  background: #fbfcfb;
}

.composer input {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 13px 12px;
  color: var(--ink);
  background: #fff;
}

.composer button {
  border: 0;
  border-radius: 8px;
  padding: 0 18px;
  color: #fff;
  background: var(--green);
  font-weight: 800;
  cursor: pointer;
}

.category-list,
.document-list,
.transaction-list {
  display: grid;
  gap: 8px;
}

.category-row,
.document-row,
.transaction-row {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  background: #fbfcfb;
}

.pending-row {
  border-color: rgba(166, 109, 18, 0.42);
  background: #fffaf1;
}

.category-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  align-items: center;
}

.bar {
  grid-column: 1 / -1;
  height: 7px;
  overflow: hidden;
  border-radius: 999px;
  background: var(--surface-2);
}

.bar span {
  display: block;
  height: 100%;
  background: var(--amber);
}

.transaction-row strong,
.document-row strong {
  display: block;
  margin-bottom: 4px;
  line-height: 1.25;
}

.transaction-value {
  font-weight: 800;
}

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

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

.review-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: 10px;
}

.review-actions button {
  min-height: 36px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  font-weight: 800;
  cursor: pointer;
}

.review-actions button[data-action="confirm"] {
  color: #fff;
  background: var(--green);
  border-color: var(--green);
}

.review-actions button[data-action="dismiss"] {
  color: var(--red);
}

.review-actions button:disabled {
  opacity: 0.7;
  cursor: wait;
}

@media (max-width: 1120px) {
  .workspace {
    grid-template-columns: 280px 1fr;
  }

  .ledger {
    grid-column: 1 / -1;
    min-height: 280px;
  }
}

@media (max-width: 760px) {
  .app-shell {
    padding: 10px;
  }

  .workspace {
    grid-template-columns: 1fr;
    min-height: auto;
  }

  .chat-area {
    min-height: 72vh;
  }

  .topbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .upload-button {
    width: 100%;
    text-align: center;
  }

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

  .composer button {
    min-height: 44px;
  }
}
