* { margin: 0; padding: 0; box-sizing: border-box; }

:root {
  --bg: #f7f4ef;
  --card: #ffffff;
  --text: #2a1e14;
  --muted: #8a7d70;
  --border: #e6e0d6;
  --green: #16a34a;
  --green-bg: #e7f6ec;
  --red: #dc2626;
  --red-bg: #fdeaea;
  --coffee: #6b4f3a;
  --coffee-dark: #4a3728;
  --shadow: 0 1px 3px rgba(42,30,20,.06), 0 4px 12px rgba(42,30,20,.04);
  --input-bg: #f7f4ef;
  --scheme: light;
  --icon-color: #2a1e14;
}

body.dark {
  --bg: #1a1410;
  --card: #241c16;
  --text: #f0e9df;
  --muted: #a89a8a;
  --border: #3a2e26;
  --green: #4ade80;
  --green-bg: #14361f;
  --red: #f87171;
  --red-bg: #3d1717;
  --coffee: #a68160;
  --coffee-dark: #8a6a4d;
  --shadow: 0 1px 3px rgba(0,0,0,.3), 0 4px 12px rgba(0,0,0,.2);
  --input-bg: #1e1712;
  --scheme: dark;
  --icon-color: #f0e9df;
}

html {
  -webkit-text-size-adjust: 100%;
  color-scheme: light;
}
body.dark { color-scheme: dark; }

body {
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 16px;
  min-height: 100vh;
  padding: 24px 16px;
  -webkit-font-smoothing: antialiased;
  transition: background .2s, color .2s;
  display: flex;
  flex-direction: column;
}

.page {
  max-width: 1400px;
  margin: 0 auto;
  width: 100%;
  flex: 1;
  display: flex;
  flex-direction: column;
}

main { flex: 1; }

/* Screen-reader only */
.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;
}

/* Header */
header {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 20px;
}
.logo {
  width: 44px; height: 44px;
  background: var(--coffee);
  border-radius: 12px;
  display: flex; align-items: center; justify-content: center;
  font-size: 22px;
  box-shadow: var(--shadow);
  flex-shrink: 0;
}
.header-info { flex: 1; min-width: 0; }
h1 { font-size: 22px; font-weight: 700; }
header p { font-size: 14px; color: var(--muted); }

.icon-btn {
  width: 40px; height: 40px;
  border: 1px solid var(--border);
  background: var(--card);
  border-radius: 10px;
  cursor: pointer;
  font-size: 16px;
  display: flex; align-items: center; justify-content: center;
  transition: all .15s;
  color: var(--text);
  flex-shrink: 0;
}
.icon-btn:hover { background: var(--bg); }
.icon-btn:focus-visible {
  outline: 2px solid var(--coffee);
  outline-offset: 2px;
}

/* Filters */
.filters {
  display: grid;
  grid-template-columns: 260px auto;
  gap: 8px;
  margin-bottom: 20px;
  align-items: center;
}

/* Month input with custom SVG calendar icon */
.filter-input {
  height: 42px;
  padding: 0 40px 0 12px; /* espaço à direita para o ícone */
  border: 1.5px solid var(--border);
  border-radius: 10px;
  font-size: 14px;
  font-family: inherit;
  background-color: var(--card);
  color: var(--text);
  outline: none;
  transition: border-color .15s;
  width: 100%;
  min-width: 0;
  color-scheme: var(--scheme);
  position: relative;

  /* Ícone SVG do calendário embutido como background */
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='18' height='18' viewBox='0 0 24 24' fill='none' stroke='%232a1e14' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'><rect x='3' y='4' width='18' height='18' rx='2' ry='2'></rect><line x1='16' y1='2' x2='16' y2='6'></line><line x1='8' y1='2' x2='8' y2='6'></line><line x1='3' y1='10' x2='21' y2='10'></line></svg>");
  background-repeat: no-repeat;
  background-position: right 12px center;
  background-size: 18px 18px;
}

body.dark .filter-input {
  /* Mesmo ícone, mas com cor clara (#f0e9df) */
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='18' height='18' viewBox='0 0 24 24' fill='none' stroke='%23f0e9df' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'><rect x='3' y='4' width='18' height='18' rx='2' ry='2'></rect><line x1='16' y1='2' x2='16' y2='6'></line><line x1='8' y1='2' x2='8' y2='6'></line><line x1='3' y1='10' x2='21' y2='10'></line></svg>");
}

.filter-input:focus { border-color: var(--coffee); }

/* Esconde o ícone nativo (nós colocamos o nosso por cima) */
.filter-input::-webkit-calendar-picker-indicator {
  opacity: 0;
  cursor: pointer;
  width: 36px;
  height: 100%;
  position: absolute;
  right: 0;
  top: 0;
}

.btn-reset-filter {
  height: 42px;
  padding: 0 16px;
  border: 1.5px solid var(--border);
  border-radius: 10px;
  background: transparent;
  color: var(--muted);
  font-size: 14px;
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
  transition: all .15s;
  white-space: nowrap;
  justify-self: start;
}
.btn-reset-filter:hover { background: var(--bg); color: var(--text); }

/* Summary */
.summary {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  margin-bottom: 20px;
}
.summary-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 16px;
  box-shadow: var(--shadow);
  transition: background .2s, border-color .2s;
  min-width: 0;
}
.summary-card .label {
  font-size: 13px;
  color: var(--muted);
  margin-bottom: 6px;
  display: flex;
  align-items: center;
  gap: 6px;
}
.summary-card .value {
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -0.02em;
  word-break: break-word;
}
.value.green { color: var(--green); }
.value.red { color: var(--red); }

/* Main grid — horizontal on desktop */
.main-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
  margin-bottom: 20px;
}

/* Form */
.form-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 20px;
  box-shadow: var(--shadow);
  min-width: 0;
}
.form-card h2 { font-size: 16px; font-weight: 600; margin-bottom: 14px; }

.type-toggle {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-bottom: 14px;
}
.type-toggle button {
  padding: 10px;
  border: 1.5px solid var(--border);
  background: transparent;
  border-radius: 10px;
  font-size: 15px;
  font-weight: 500;
  cursor: pointer;
  color: var(--muted);
  transition: all .15s ease;
  font-family: inherit;
}
.type-toggle button:hover { background: var(--bg); }
.type-toggle button:focus-visible {
  outline: 2px solid var(--coffee);
  outline-offset: 2px;
}
.type-toggle button.active[data-type="income"] {
  border-color: var(--green);
  background: var(--green-bg);
  color: var(--green);
}
.type-toggle button.active[data-type="expense"] {
  border-color: var(--red);
  background: var(--red-bg);
  color: var(--red);
}

.fields {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field.full { grid-column: 1 / -1; }
.field label,
.field .field-label {
  font-size: 14px;
  font-weight: 500;
  color: var(--text);
}

.label-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.btn-new-cat {
  background: none;
  border: none;
  color: var(--coffee);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  padding: 2px 6px;
  border-radius: 6px;
  font-family: inherit;
  transition: background .15s;
  white-space: nowrap;
}
.btn-new-cat:hover { background: var(--bg); }

.field input,
.field select {
  height: 42px;
  padding: 0 12px;
  border: 1.5px solid var(--border);
  border-radius: 10px;
  font-size: 15px;
  font-family: inherit;
  background: var(--input-bg);
  color: var(--text);
  outline: none;
  transition: border-color .15s;
  width: 100%;
  min-width: 0;
  color-scheme: var(--scheme);
}
.field input:focus,
.field select:focus {
  border-color: var(--coffee);
  background: var(--card);
}

/* Date input — same custom icon trick */
.field input[type="date"],
.field input[type="month"] {
  padding-right: 40px;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='18' height='18' viewBox='0 0 24 24' fill='none' stroke='%232a1e14' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'><rect x='3' y='4' width='18' height='18' rx='2' ry='2'></rect><line x1='16' y1='2' x2='16' y2='6'></line><line x1='8' y1='2' x2='8' y2='6'></line><line x1='3' y1='10' x2='21' y2='10'></line></svg>");
  background-repeat: no-repeat;
  background-position: right 12px center;
  background-size: 18px 18px;
}

body.dark .field input[type="date"],
body.dark .field input[type="month"] {
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='18' height='18' viewBox='0 0 24 24' fill='none' stroke='%23f0e9df' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'><rect x='3' y='4' width='18' height='18' rx='2' ry='2'></rect><line x1='16' y1='2' x2='16' y2='6'></line><line x1='8' y1='2' x2='8' y2='6'></line><line x1='3' y1='10' x2='21' y2='10'></line></svg>");
}

.field input[type="date"]::-webkit-calendar-picker-indicator,
.field input[type="month"]::-webkit-calendar-picker-indicator {
  opacity: 0;
  cursor: pointer;
  width: 36px;
  height: 100%;
  position: absolute;
  right: 0;
  top: 0;
}

.btn-submit {
  width: 100%;
  height: 46px;
  margin-top: 14px;
  background: var(--coffee);
  color: #fff;
  border: none;
  border-radius: 10px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
  transition: background .15s;
}
.btn-submit:hover { background: var(--coffee-dark); }
.btn-submit:active { transform: translateY(1px); }
.btn-submit:focus-visible {
  outline: 2px solid var(--coffee);
  outline-offset: 2px;
}

/* Chart */
.chart-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 20px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  min-width: 0;
}
.chart-card h3 { font-size: 15px; font-weight: 600; margin-bottom: 14px; }
.chart-wrapper {
  flex: 1;
  min-height: 240px;
  position: relative;
  width: 100%;
}

/* List */
.list-section { margin-top: 0; }

.list-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
  gap: 12px;
}
.list-header h2 { font-size: 16px; font-weight: 600; }
.btn-clear {
  font-size: 13px;
  color: var(--muted);
  background: none;
  border: none;
  cursor: pointer;
  padding: 6px 10px;
  border-radius: 8px;
  font-family: inherit;
  white-space: nowrap;
}
.btn-clear:hover { background: var(--red-bg); color: var(--red); }

.list-actions { display: flex; align-items: center; gap: 2px; }
.btn-tool {
  font-size: 13px;
  color: var(--muted);
  background: none;
  border: none;
  cursor: pointer;
  padding: 6px 10px;
  border-radius: 8px;
  font-family: inherit;
  white-space: nowrap;
}
.btn-tool:hover { background: var(--bg); color: var(--text); }

.list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.item {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px 14px;
  box-shadow: var(--shadow);
  animation: slideIn .2s ease;
  transition: background .2s, border-color .2s;
  min-width: 0;
}
@keyframes slideIn {
  from { opacity: 0; transform: translateY(-4px); }
  to { opacity: 1; transform: translateY(0); }
}
.item .icon {
  width: 36px; height: 36px;
  border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  font-size: 16px;
  flex-shrink: 0;
}
.item.income .icon { background: var(--green-bg); color: var(--green); }
.item.expense .icon { background: var(--red-bg); color: var(--red); }

.item .info { flex: 1; min-width: 0; }
.item .info .desc {
  font-size: 15px;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.item .info .meta {
  font-size: 13px;
  color: var(--muted);
  margin-top: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.item .amount {
  font-size: 16px;
  font-weight: 600;
  white-space: nowrap;
  flex-shrink: 0;
}
.item.income .amount { color: var(--green); }
.item.expense .amount { color: var(--red); }

.item .del {
  background: none;
  border: none;
  color: var(--muted);
  cursor: pointer;
  padding: 6px;
  border-radius: 8px;
  font-size: 16px;
  line-height: 1;
  transition: all .15s;
  flex-shrink: 0;
}
.item .del:hover { background: var(--red-bg); color: var(--red); }

.empty {
  text-align: center;
  padding: 40px 20px;
  color: var(--muted);
  font-size: 15px;
  border: 1.5px dashed var(--border);
  border-radius: 12px;
  list-style: none;
}

/* Footer */
.site-footer {
  margin-top: 32px;
  padding: 16px 0 4px;
  text-align: center;
  font-size: 13px;
  color: var(--muted);
  border-top: 1px solid var(--border);
}

/* Toast */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(100px);
  background: var(--coffee-dark);
  color: #fff;
  padding: 12px 20px;
  border-radius: 10px;
  font-size: 14px;
  font-weight: 500;
  box-shadow: 0 10px 30px rgba(0,0,0,.2);
  transition: transform .3s ease;
  z-index: 100;
  max-width: calc(100vw - 32px);
  text-align: center;
}
.toast.show { transform: translateX(-50%) translateY(0); }

/* Modal */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.5);
  backdrop-filter: blur(2px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 200;
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s ease;
}
.modal-overlay.open {
  opacity: 1;
  pointer-events: auto;
}
.modal-overlay[aria-hidden="true"] { pointer-events: none; }

.modal {
  background: var(--card);
  border-radius: 16px;
  padding: 22px;
  width: 100%;
  max-width: 380px;
  box-shadow: 0 20px 60px rgba(0,0,0,.35);
  transform: translateY(8px) scale(.98);
  transition: transform .2s ease;
}
.modal-overlay.open .modal {
  transform: translateY(0) scale(1);
}
.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
}
.modal-header h3 { font-size: 16px; font-weight: 600; }
.modal-close {
  background: none;
  border: none;
  font-size: 18px;
  color: var(--muted);
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 8px;
  line-height: 1;
}
.modal-close:hover { background: var(--bg); color: var(--text); }

.modal .field { margin-bottom: 14px; }

.modal-toggle {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}
.modal-toggle button {
  padding: 9px;
  border: 1.5px solid var(--border);
  background: transparent;
  border-radius: 10px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  color: var(--muted);
  font-family: inherit;
  transition: all .15s;
}
.modal-toggle button.active[data-type="income"] {
  border-color: var(--green);
  background: var(--green-bg);
  color: var(--green);
}
.modal-toggle button.active[data-type="expense"] {
  border-color: var(--red);
  background: var(--red-bg);
  color: var(--red);
}

.modal-actions {
  display: flex;
  gap: 8px;
  margin-top: 4px;
}
.modal-actions button {
  flex: 1;
  height: 42px;
  border-radius: 10px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
  transition: all .15s;
}
.btn-cancel {
  background: transparent;
  border: 1.5px solid var(--border);
  color: var(--muted);
}
.btn-cancel:hover { background: var(--bg); color: var(--text); }
.btn-confirm {
  background: var(--coffee);
  border: none;
  color: #fff;
}
.btn-confirm:hover { background: var(--coffee-dark); }

/* ============ RESPONSIVE ============ */

@media (max-width: 1000px) {
  .main-grid { grid-template-columns: 1fr; }
}

@media (max-width: 720px) {
  .filters { grid-template-columns: 1fr; }
  .btn-reset-filter { justify-self: stretch; }
}

@media (max-width: 520px) {
  body { padding: 18px 14px; }
  h1 { font-size: 20px; }
  header p { font-size: 12px; }
  .summary { grid-template-columns: 1fr; }
  .fields { grid-template-columns: 1fr; }
  .summary-card .value { font-size: 20px; }
  .chart-wrapper { min-height: 200px; }
  .item { padding: 10px 12px; gap: 10px; }
  .item .icon { width: 32px; height: 32px; font-size: 14px; }
  .item .info .desc { font-size: 13px; }
  .item .info .meta { font-size: 11px; }
  .item .amount { font-size: 14px; }
}

@media (max-width: 400px) {
  body { padding: 16px 12px; }
  .logo { width: 40px; height: 40px; font-size: 20px; }
  h1 { font-size: 19px; }
  .icon-btn { width: 38px; height: 38px; }
  .summary-card { padding: 14px; }
  .summary-card .value { font-size: 19px; }
  .form-card, .chart-card { padding: 16px; }
  .modal { padding: 18px; }
}

@media (max-width: 360px) {
  body { padding: 14px 10px; }
  h1 { font-size: 18px; }
  header p { font-size: 11px; }
  header { gap: 10px; margin-bottom: 16px; }
  .logo { width: 36px; height: 36px; font-size: 18px; }
  .icon-btn { width: 36px; height: 36px; font-size: 15px; }
  .summary-card .value { font-size: 18px; }
  .summary-card { padding: 12px; }
  .form-card, .chart-card { padding: 14px; border-radius: 14px; }
  .type-toggle button { padding: 9px; font-size: 13px; }
  .btn-submit { height: 44px; font-size: 13px; }
  .item { padding: 10px; gap: 8px; }
  .item .icon { width: 30px; height: 30px; font-size: 13px; }
  .item .amount { font-size: 13px; }
  .item .del { font-size: 14px; padding: 5px; }
  .chart-wrapper { min-height: 180px; }
  .filters { margin-bottom: 14px; }
  .modal { padding: 16px; border-radius: 14px; }
}

@media (max-width: 300px) {
  body { padding: 12px 8px; }
  h1 { font-size: 16px; }
  header p { display: none; }
  .summary-card .value { font-size: 16px; }
  .btn-submit { font-size: 12px; }
  .type-toggle button { font-size: 12px; padding: 8px; }
}

@media (hover: none) and (pointer: coarse) {
  .icon-btn, .btn-submit, .btn-confirm, .btn-cancel,
  .type-toggle button, .modal-toggle button, .btn-clear,
  .btn-reset-filter, .btn-new-cat {
    -webkit-tap-highlight-color: transparent;
  }
  .item .del { opacity: 1; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}