:root {
  --bg: #0a0a0f;
  --surface: #12121a;
  --surface2: #1a1a26;
  --surface3: #202030;
  --border: #2a2a3a;
  --accent: #6ee7b7;
  --accent2: #818cf8;
  --warn: #fbbf24;
  --danger: #f87171;
  --text: #e2e8f0;
  --muted: #64748b;
  --radius: 12px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: Syne, system-ui, sans-serif;
}

button, input, select {
  font: inherit;
}

.hidden { display: none !important; }
.mono { font-family: "DM Mono", monospace; }
.muted { color: var(--muted); font-size: 11px; }

.app-header {
  position: sticky;
  top: 0;
  z-index: 10;
  padding: 16px;
  background: linear-gradient(135deg, #0f0f1a, #1a1030);
  border-bottom: 1px solid var(--border);
  backdrop-filter: blur(20px);
}

.header-top, .toolbar, .actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.header-top { justify-content: space-between; margin-bottom: 12px; }

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

.brand img {
  width: 132px;
  height: 52px;
  border-radius: 8px;
  border: 1px solid rgba(110, 231, 183, .25);
  background: #f4f4f4;
  object-fit: contain;
  padding: 4px 6px;
}

.logo-text {
  font-size: 20px;
  font-weight: 800;
  background: linear-gradient(90deg, var(--accent), var(--accent2));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.header-status {
  display: grid;
  justify-items: end;
  gap: 5px;
  margin-left: auto;
}

.app-version {
  color: var(--muted);
  font-family: "DM Mono", monospace;
  font-size: 10px;
  font-weight: 700;
}

.sync-badge {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 7px 10px;
  border-radius: 20px;
  font-family: "DM Mono", monospace;
  font-size: 11px;
  font-weight: 700;
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--muted);
  cursor: pointer;
}

.sync-badge.connected { color: var(--accent); border-color: rgba(110, 231, 183, .4); }
.sync-badge.syncing { color: var(--accent2); border-color: rgba(129, 140, 248, .4); animation: pulse 1.2s infinite; }
.sync-badge.error { color: var(--danger); border-color: rgba(248, 113, 113, .4); }

.sync-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--muted);
}

.sync-dot.connected { background: var(--accent); }
.sync-dot.syncing { background: var(--accent2); }
.sync-dot.error { background: var(--danger); }

@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: .55; } }

.toolbar {
  flex-wrap: wrap;
  margin-bottom: 12px;
  position: relative;
}

.connection-notice {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin: 0 0 12px;
  padding: 10px 12px;
  border: 1px solid rgba(248, 113, 113, .45);
  border-radius: 8px;
  background: rgba(248, 113, 113, .1);
  color: var(--danger);
  font-family: "DM Mono", monospace;
  font-size: 11px;
  font-weight: 800;
}

.notice-login {
  min-height: 32px;
  padding: 7px 11px;
  border: 1px solid rgba(110, 231, 183, .45);
  border-radius: 8px;
  background: rgba(110, 231, 183, .12);
  color: var(--accent);
  font-size: 11px;
  font-weight: 800;
  cursor: pointer;
  white-space: nowrap;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.field span {
  color: var(--muted);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: .5px;
  text-transform: uppercase;
}

.field.compact {
  min-width: 150px;
}

.calendar-panel {
  position: absolute;
  top: 100%;
  left: 0;
  z-index: 50;
  width: min(320px, calc(100vw - 28px));
  padding: 12px;
  margin-top: 6px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: 0 16px 40px rgba(0, 0, 0, .4);
}

.calendar-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 10px;
}

.calendar-head button {
  width: 34px;
  height: 30px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface2);
  color: var(--text);
  cursor: pointer;
}

.calendar-title {
  color: var(--accent);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

.calendar-grid {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 5px;
}

.calendar-dow,
.calendar-day {
  min-height: 30px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 7px;
  font-family: "DM Mono", monospace;
  font-size: 11px;
}

.calendar-dow {
  color: var(--muted);
  font-weight: 800;
}

.calendar-day {
  border: 1px solid transparent;
  background: var(--surface2);
  color: var(--text);
  cursor: pointer;
}

.calendar-day.out {
  opacity: .35;
}

.calendar-day.active {
  color: #0a0a0f;
  background: var(--accent);
}

input, select {
  width: 100%;
  min-height: 39px;
  padding: 10px 11px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  outline: none;
  font-family: "DM Mono", monospace;
  font-size: 12px;
}

input[type="number"] {
  -moz-appearance: textfield;
}

input[type="number"]::-webkit-outer-spin-button,
input[type="number"]::-webkit-inner-spin-button {
  margin: 0;
  -webkit-appearance: none;
}

input:focus, select:focus {
  border-color: var(--accent);
}

select option {
  background: var(--surface);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 39px;
  padding: 10px 13px;
  border-radius: 10px;
  border: 1px solid var(--border);
  font-weight: 800;
  color: var(--text);
  background: var(--surface2);
  cursor: pointer;
}

.btn.primary {
  background: linear-gradient(135deg, var(--accent), #34d399);
  color: #0a0a0f;
  border-color: transparent;
}

.btn.secondary {
  background: var(--surface2);
}

.btn.small {
  min-height: 42px;
  padding: 10px 13px;
  font-size: 13px;
}

.file-btn {
  position: relative;
  width: 100%;
}

.file-btn input {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
}

.stats-row {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
}

.day-status {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
  margin-top: 8px;
}

.status-chip {
  display: grid;
  grid-template-columns: minmax(90px, 1fr) minmax(110px, auto);
  align-items: center;
  gap: 8px;
  min-height: 36px;
  padding: 8px 10px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 8px;
}

.status-chip span {
  color: var(--muted);
  font-size: 9px;
  font-weight: 800;
  letter-spacing: .5px;
  text-transform: uppercase;
}

.status-chip strong {
  font-family: "DM Mono", monospace;
  font-size: 10px;
  justify-self: end;
  text-align: right;
  white-space: nowrap;
}

.status-chip.ok { border-color: rgba(110, 231, 183, .35); }
.status-chip.warn { border-color: rgba(251, 191, 36, .35); }
.status-chip.danger { border-color: rgba(248, 113, 113, .35); }

.stat {
  padding: 9px 10px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 8px;
  text-align: center;
}

.stat strong {
  display: block;
  color: var(--accent);
  font-size: 16px;
  line-height: 1.2;
}

.stat span {
  display: block;
  color: var(--muted);
  font-size: 9px;
  font-weight: 700;
  letter-spacing: .5px;
  margin-top: 3px;
  text-transform: uppercase;
}

.main-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 12px;
  padding: 14px;
}

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.panel.wide {
  grid-column: 1 / -1;
}

.panel-head {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(190px, 230px) 18px;
  align-items: center;
  gap: 12px;
  padding: 14px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  user-select: none;
}

.panel-head > .pill,
.panel-head > .btn {
  justify-self: start;
  min-width: 180px;
  text-align: center;
}

.panel-head > .module-chevron {
  justify-self: end;
  flex-shrink: 0;
}

.panel h2 {
  margin: 0;
  font-size: 14px;
  letter-spacing: .7px;
  text-transform: uppercase;
}

.module-title-wrap {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.module-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  border-radius: 8px;
  flex: 0 0 auto;
  font-family: "DM Mono", monospace;
  font-size: 12px;
  font-weight: 800;
  background: var(--surface2);
  border: 1px solid var(--border);
}

.module-icon.bills, .title-bills { color: #f472b6; }
.module-icon.closure, .title-closure { color: var(--accent); }
.module-icon.differences, .title-differences { color: var(--danger); }
.module-icon.payments, .title-payments { color: var(--accent2); }
.module-icon.balances, .title-balances { color: #38bdf8; }
.module-icon.summary, .title-summary { color: var(--warn); }

.module-chevron {
  color: var(--muted);
  font-size: 11px;
  transition: transform .18s ease;
}

.module.is-open .module-chevron {
  transform: rotate(180deg);
}

.module-body {
  display: none;
}

.module.is-open .module-body {
  display: block;
}

.panel p {
  margin: 3px 0 0;
  color: var(--muted);
  font-size: 11px;
}

.stack {
  display: grid;
  gap: 10px;
  padding: 14px;
}

.stack .btn {
  margin-top: 2px;
}

.table-wrap {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 650px;
  table-layout: fixed;
  font-family: "DM Mono", monospace;
}

th, td {
  padding: 9px 10px;
  border-bottom: 1px solid var(--border);
  text-align: center;
}

th {
  background: var(--surface2);
  color: var(--muted);
  font-size: 10px;
  text-transform: uppercase;
}

td {
  font-size: 12px;
}

td input {
  min-height: 34px;
  text-align: center;
}

td:first-child,
th:first-child {
  text-align: left;
}

td input[data-kind="note"],
td input[type="text"][placeholder*="Comentario"] {
  text-align: left;
}

td input[readonly], td input:disabled, input:disabled, select:disabled {
  opacity: .7;
  cursor: not-allowed;
}

tfoot td {
  color: var(--accent);
  font-weight: 800;
}

.actions {
  padding: 14px;
  border-top: 1px solid var(--border);
  flex-wrap: wrap;
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
  align-items: stretch;
}

.actions .btn,
.stack .btn {
  width: 100%;
  min-height: 42px;
}

.action-note {
  width: 100%;
}

.bill-mode {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  padding: 14px;
  border-bottom: 1px solid var(--border);
}

.seg-btn {
  min-height: 38px;
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface2);
  color: var(--muted);
  font-weight: 800;
  cursor: pointer;
}

.seg-btn.active {
  color: #0a0a0f;
  background: linear-gradient(135deg, var(--accent), #34d399);
  border-color: transparent;
}

.locked {
  position: relative;
}

.locked .module-body {
  opacity: .72;
}

.pill {
  flex-shrink: 0;
  padding: 6px 9px;
  border-radius: 20px;
  font-family: "DM Mono", monospace;
  font-size: 10px;
  font-weight: 800;
  border: 1px solid var(--border);
}

.pill.ok { color: var(--accent); border-color: rgba(110, 231, 183, .35); background: rgba(110, 231, 183, .08); }
.pill.warn { color: var(--warn); border-color: rgba(251, 191, 36, .35); background: rgba(251, 191, 36, .08); }
.pill.danger { color: var(--danger); border-color: rgba(248, 113, 113, .35); background: rgba(248, 113, 113, .08); }

.danger-text {
  color: var(--danger);
}

.amount-positive {
  color: var(--accent) !important;
}

.amount-negative {
  color: var(--danger) !important;
}

.amount-zero {
  color: var(--muted) !important;
}

.pill.amount-positive {
  background: rgba(110, 231, 183, .08);
  border-color: rgba(110, 231, 183, .35);
}

.pill.amount-negative {
  background: rgba(248, 113, 113, .08);
  border-color: rgba(248, 113, 113, .35);
}

.pill.amount-zero {
  background: var(--surface2);
  border-color: var(--border);
}

.list {
  display: grid;
  gap: 8px;
  padding: 0 14px 14px;
}

.list-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  padding: 10px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 8px;
}

.list-item strong {
  display: block;
  font-size: 12px;
}

.list-item span {
  display: block;
  color: var(--muted);
  font-family: "DM Mono", monospace;
  font-size: 10px;
  margin-top: 2px;
}

.list-item button {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  border: 1px solid rgba(248, 113, 113, .35);
  background: rgba(248, 113, 113, .12);
  color: var(--danger);
  cursor: pointer;
}

.balance-total {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin: 0 14px 14px;
  padding: 13px;
  background: rgba(110, 231, 183, .08);
  border: 1px solid rgba(110, 231, 183, .25);
  border-radius: 8px;
}

.balance-total span {
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
}

.balance-total strong {
  color: var(--accent);
  font-size: 19px;
}

.summary-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  padding: 0 14px 14px;
}

.summary-card {
  padding: 13px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 8px;
}

.summary-card span {
  color: var(--muted);
  font-size: 10px;
  font-weight: 800;
  letter-spacing: .5px;
  text-transform: uppercase;
}

.summary-card strong {
  display: block;
  margin-top: 7px;
  color: var(--accent);
  font-size: 20px;
}

.toast {
  position: fixed;
  left: 14px;
  right: 14px;
  bottom: 14px;
  z-index: 30;
  padding: 12px 14px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text);
  font-size: 13px;
  box-shadow: 0 12px 35px rgba(0, 0, 0, .35);
}

@media (max-width: 900px) {
  .main-grid { grid-template-columns: 1fr; }
  .stats-row, .summary-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .day-status { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 560px) {
  .app-header { padding: 13px; }
  .header-top { align-items: flex-start; }
  .brand img { width: 104px; height: 44px; }
  .logo-text { font-size: 17px; }
  .toolbar > * { flex: 1 1 100%; }
  .stats-row, .summary-grid { grid-template-columns: 1fr; }
  .day-status, .bill-mode { grid-template-columns: 1fr; }
  .panel-head {
    grid-template-columns: 1fr;
    align-items: start;
  }
  .panel-head > .pill,
  .panel-head > .btn,
  .panel-head > .module-chevron {
    justify-self: start;
  }
  .header-status { justify-items: end; }
}
