:root {
  color-scheme: light;
  --background: 40 20% 96%;
  --foreground: 30 5% 35%;
  --card: 40 15% 98%;
  --card-strong: 38 18% 99%;
  --primary: 30 8% 45%;
  --primary-strong: 30 9% 34%;
  --muted: 35 12% 93%;
  --muted-foreground: 30 5% 47%;
  --border: 35 10% 84%;
  --border-soft: 35 12% 89%;
  --success: 142 50% 36%;
  --destructive: 0 55% 48%;
  --warning: 38 70% 45%;
  --radius: 0.75rem;
  --shadow: 0 20px 55px hsl(30 12% 22% / 0.12);
  --shadow-soft: 0 10px 28px hsl(30 12% 22% / 0.08);
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  background: hsl(var(--background));
}

body {
  min-height: 100%;
  margin: 0;
  color: hsl(var(--foreground));
  background:
    linear-gradient(180deg, hsl(40 20% 97%) 0%, hsl(38 17% 93%) 100%),
    hsl(var(--background));
  font-family: "DM Sans", ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-feature-settings: "kern";
  -webkit-font-smoothing: antialiased;
}

body::before {
  position: fixed;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  content: "";
  background-image:
    linear-gradient(hsl(30 8% 30% / 0.025) 1px, transparent 1px),
    linear-gradient(90deg, hsl(30 8% 30% / 0.02) 1px, transparent 1px);
  background-size: 44px 44px;
  mask-image: linear-gradient(180deg, black 0%, transparent 78%);
}

button,
input,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

h1,
h2,
p {
  margin: 0;
}

.app-shell {
  display: grid;
  grid-template-columns: minmax(0, 1.05fr) minmax(320px, 0.85fr);
  gap: 18px;
  width: min(100%, 1180px);
  margin: 0 auto;
  padding: calc(20px + env(safe-area-inset-top)) 18px calc(36px + env(safe-area-inset-bottom));
}

.topbar {
  display: flex;
  grid-column: 1 / -1;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  min-height: 72px;
}

.brand-lockup {
  display: grid;
  gap: 7px;
  min-width: 0;
}

.brand-logo {
  display: block;
  width: min(252px, 62vw);
  height: auto;
  object-fit: contain;
}

.eyebrow,
.panel-label,
.field > span {
  color: hsl(var(--muted-foreground));
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0;
  line-height: 1;
  text-transform: uppercase;
}

h1 {
  color: hsl(var(--foreground));
  font-size: clamp(2rem, 6vw, 3.7rem);
  font-weight: 800;
  line-height: 0.95;
  letter-spacing: 0;
}

h2 {
  color: hsl(var(--foreground));
  font-size: 1.06rem;
  font-weight: 800;
  line-height: 1.15;
  letter-spacing: 0;
}

.icon-button {
  display: grid;
  width: 56px;
  height: 56px;
  flex: 0 0 auto;
  place-items: center;
  border: 1px solid hsl(var(--border));
  border-radius: var(--radius);
  color: hsl(var(--primary-strong));
  background: hsl(var(--card) / 0.9);
  box-shadow: var(--shadow-soft);
}

.icon-button:hover,
.icon-button:focus {
  border-color: hsl(var(--primary) / 0.45);
  background: hsl(var(--card-strong));
}

.icon-button span {
  display: block;
  font-size: 1.35rem;
  line-height: 1;
}

.balance-panel,
.panel,
.result-panel {
  border: 1px solid hsl(var(--border-soft));
  border-radius: var(--radius);
  background: hsl(var(--card) / 0.86);
  box-shadow: var(--shadow);
  backdrop-filter: blur(12px);
}

.balance-panel {
  grid-column: 1 / -1;
  padding: clamp(18px, 3vw, 28px);
}

.panel-label {
  display: block;
  margin-bottom: 10px;
}

#saldoActual {
  display: block;
  color: hsl(var(--foreground));
  font-size: clamp(3.1rem, 10vw, 6.8rem);
  font-weight: 800;
  line-height: 0.92;
  letter-spacing: 0;
}

.balance-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 18px;
}

.balance-meta span,
#nextTicket {
  display: inline-flex;
  min-height: 38px;
  align-items: center;
  border: 1px solid hsl(var(--border));
  border-radius: 999px;
  padding: 8px 13px;
  color: hsl(var(--muted-foreground));
  background: hsl(var(--muted) / 0.82);
  font-size: 0.86rem;
  font-weight: 800;
}

.panel {
  padding: clamp(14px, 2.4vw, 22px);
}

#movementForm {
  grid-column: 1;
}

.movement-panel {
  grid-column: 2;
}

.result-panel {
  grid-column: 1;
  padding: 16px 18px;
}

.segmented {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 7px;
  padding: 5px;
  border: 1px solid hsl(var(--border));
  border-radius: var(--radius);
  background: hsl(var(--muted));
}

.segment {
  min-height: 54px;
  border: 0;
  border-radius: calc(var(--radius) - 0.25rem);
  color: hsl(var(--muted-foreground));
  background: transparent;
  font-size: 1.05rem;
  font-weight: 800;
}

.segment.active {
  color: hsl(40 20% 98%);
  background: hsl(var(--primary));
  box-shadow: 0 8px 22px hsl(var(--primary) / 0.23);
}

.field {
  display: grid;
  gap: 8px;
  margin-top: 15px;
}

input,
textarea {
  width: 100%;
  border: 1px solid hsl(var(--border));
  border-radius: var(--radius);
  color: hsl(var(--foreground));
  background: hsl(0 0% 100% / 0.92);
  box-shadow: 0 1px 0 hsl(0 0% 100% / 0.8) inset, var(--shadow-soft);
  outline: none;
}

input {
  min-height: 56px;
  padding: 12px 14px;
  font-size: clamp(1.2rem, 4vw, 1.6rem);
  font-weight: 800;
  text-align: center;
}

textarea {
  min-height: 116px;
  padding: 14px;
  font-size: 1.02rem;
  font-weight: 600;
  line-height: 1.35;
  resize: vertical;
}

input:focus,
textarea:focus,
.file-picker:focus-within {
  border-color: hsl(var(--primary) / 0.72);
  box-shadow: 0 0 0 4px hsl(var(--primary) / 0.14), var(--shadow-soft);
}

.file-picker {
  position: relative;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 12px;
  min-height: 58px;
  align-items: center;
  border: 1px solid hsl(var(--border));
  border-radius: var(--radius);
  padding: 7px;
  color: hsl(var(--foreground));
  background: hsl(0 0% 100% / 0.92);
  box-shadow: var(--shadow-soft);
  overflow: hidden;
}

.file-picker input {
  position: absolute;
  inset: 0;
  min-height: 0;
  opacity: 0;
  cursor: pointer;
}

.file-action {
  display: inline-flex;
  min-height: 42px;
  align-items: center;
  justify-content: center;
  border-radius: calc(var(--radius) - 0.25rem);
  padding: 0 16px;
  color: hsl(40 20% 98%);
  background: hsl(var(--primary));
  font-size: 0.95rem;
  font-weight: 900;
}

.file-name {
  min-width: 0;
  overflow: hidden;
  color: hsl(var(--foreground));
  font-size: 1rem;
  font-weight: 800;
  text-overflow: ellipsis;
  white-space: nowrap;
}

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

.preview {
  margin-top: 15px;
  border: 1px solid hsl(var(--border));
  border-radius: var(--radius);
  overflow: hidden;
  background: hsl(var(--muted));
}

.preview img {
  display: block;
  width: 100%;
  max-height: 300px;
  object-fit: contain;
  background: hsl(var(--card));
}

.preview-file {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  min-height: 58px;
  padding: 14px;
  color: hsl(var(--muted-foreground));
  font-size: 0.92rem;
  font-weight: 800;
}

.actions {
  display: grid;
  grid-template-columns: minmax(0, 0.9fr) minmax(0, 1.1fr);
  gap: 12px;
  margin-top: 16px;
}

.primary,
.secondary {
  min-height: 56px;
  border-radius: var(--radius);
  border: 1px solid transparent;
  padding: 0 16px;
  font-size: 1.02rem;
  font-weight: 900;
}

.primary {
  color: hsl(40 20% 98%);
  background: hsl(var(--primary));
  box-shadow: 0 12px 24px hsl(var(--primary) / 0.2);
}

.primary:hover,
.primary:focus {
  background: hsl(var(--primary-strong));
}

.secondary {
  color: hsl(var(--primary-strong));
  border-color: hsl(var(--border));
  background: hsl(var(--muted) / 0.72);
}

.secondary:disabled,
.primary:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

.result-panel.success {
  border-color: hsl(var(--success) / 0.35);
  background: hsl(var(--success) / 0.09);
}

.result-panel.error {
  border-color: hsl(var(--destructive) / 0.35);
  background: hsl(var(--destructive) / 0.09);
}

.result-panel strong {
  display: block;
  margin-bottom: 4px;
  font-weight: 900;
}

.result-panel a {
  color: hsl(var(--primary-strong));
  font-weight: 900;
}

.panel-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.movement-list {
  display: grid;
  gap: 10px;
}

.movement-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  min-height: 64px;
  align-items: center;
  border-top: 1px solid hsl(var(--border-soft));
  padding-top: 12px;
}

.movement-row:first-child {
  border-top: 0;
  padding-top: 0;
}

.movement-main {
  min-width: 0;
}

.movement-title {
  overflow: hidden;
  color: hsl(var(--foreground));
  font-size: 0.97rem;
  font-weight: 800;
  line-height: 1.2;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.movement-date {
  margin-top: 5px;
  color: hsl(var(--muted-foreground));
  font-size: 0.82rem;
  font-weight: 800;
}

.movement-amount {
  font-size: 0.98rem;
  font-weight: 900;
  text-align: right;
  white-space: nowrap;
}

.movement-amount.salida {
  color: hsl(var(--destructive));
}

.movement-amount.entrada {
  color: hsl(var(--success));
}

.empty {
  min-height: 58px;
  display: grid;
  place-items: center;
  color: hsl(var(--muted-foreground));
  font-size: 0.92rem;
  font-weight: 800;
}

.hidden {
  display: none;
}

@media (max-width: 860px) {
  .app-shell {
    grid-template-columns: 1fr;
    gap: 14px;
    padding-left: 12px;
    padding-right: 12px;
  }

  .balance-panel,
  #movementForm,
  .movement-panel,
  .result-panel {
    grid-column: 1;
  }

  .topbar {
    min-height: 64px;
  }

  .brand-logo {
    width: min(210px, 58vw);
  }
}

@media (max-width: 520px) {
  .topbar {
    align-items: flex-start;
  }

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

  .balance-panel,
  .panel,
  .result-panel {
    padding: 14px;
  }

  .file-picker {
    grid-template-columns: 1fr;
  }

  .file-action {
    width: 100%;
  }

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

  .movement-amount {
    text-align: left;
  }
}
