:root {
  --bg: #f0f4f8;
  --surface: #ffffff;
  --primary: #1e5a8a;
  --primary-hover: #164770;
  --ingreso: #0d7a4a;
  --ingreso-bg: #e8f7ef;
  --gasto: #b42318;
  --gasto-bg: #fdecea;
  --border: #d8e2ec;
  --text: #1a2b3c;
  --text-muted: #5a6f82;
  --error: #c62828;
  --shadow: 0 8px 32px rgba(30, 90, 138, 0.1);
  --radius: 12px;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  background: linear-gradient(135deg, #e8f0f8 0%, #f5f8fb 50%, #eef3f9 100%);
  color: var(--text);
  line-height: 1.5;
}

.container {
  max-width: 720px;
  margin: 2rem auto;
  padding: 0 1.25rem 3rem;
}

.header {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin-bottom: 1.75rem;
}

.header-icon {
  font-size: 2.5rem;
  background: var(--surface);
  width: 64px;
  height: 64px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.header h1 {
  margin: 0;
  font-size: 1.6rem;
  color: var(--primary);
}

.header p {
  margin: 0.25rem 0 0;
  color: var(--text-muted);
  font-size: 0.95rem;
}

form {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 1.75rem;
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
}

.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.25rem;
}

.field-full {
  grid-column: 1 / -1;
}

.field label,
.field .label {
  display: block;
  font-weight: 600;
  font-size: 0.875rem;
  margin-bottom: 0.4rem;
  color: var(--text);
}

.required {
  color: var(--error);
}

input[type="date"],
input[type="number"],
input[type="text"],
select {
  width: 100%;
  padding: 0.7rem 0.85rem;
  border: 1.5px solid var(--border);
  border-radius: 8px;
  font-size: 0.95rem;
  font-family: inherit;
  background: #fafcfe;
  transition: border-color 0.2s, box-shadow 0.2s;
}

input:focus,
select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(30, 90, 138, 0.15);
}

input.invalid,
select.invalid {
  border-color: var(--error);
}

.radio-group {
  display: flex;
  gap: 0.75rem;
}

.radio-option {
  flex: 1;
  cursor: pointer;
}

.radio-option input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.radio-label {
  display: block;
  text-align: center;
  padding: 0.7rem 1rem;
  border: 1.5px solid var(--border);
  border-radius: 8px;
  font-weight: 600;
  font-size: 0.9rem;
  transition: all 0.2s;
}

.radio-option input:checked + .radio-label.ingreso {
  background: var(--ingreso-bg);
  border-color: var(--ingreso);
  color: var(--ingreso);
}

.radio-option input:checked + .radio-label.gasto {
  background: var(--gasto-bg);
  border-color: var(--gasto);
  color: var(--gasto);
}

.radio-option input:checked + .radio-label.coes {
  background: #e8f2fc;
  border-color: var(--primary);
  color: var(--primary);
}

.radio-option input:checked + .radio-label.oficina {
  background: #f3eef9;
  border-color: #6b4c9a;
  color: #6b4c9a;
}

.file-upload {
  position: relative;
  border: 2px dashed var(--border);
  border-radius: 8px;
  padding: 1.5rem;
  text-align: center;
  cursor: pointer;
  transition: border-color 0.2s, background 0.2s;
}

.file-upload:hover,
.file-upload.dragover {
  border-color: var(--primary);
  background: #f0f7ff;
}

.file-upload input[type="file"] {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
}

.file-upload-content p {
  margin: 0.5rem 0 0.25rem;
  color: var(--text-muted);
  font-size: 0.9rem;
}

.file-upload-content small {
  color: var(--text-muted);
  font-size: 0.8rem;
}

.file-icon {
  font-size: 1.75rem;
}

.image-preview {
  margin-top: 0.75rem;
  display: flex;
  align-items: center;
  gap: 1rem;
}

.image-preview img {
  max-width: 120px;
  max-height: 80px;
  object-fit: cover;
  border-radius: 6px;
  border: 1px solid var(--border);
}

.btn-remove {
  background: none;
  border: none;
  color: var(--error);
  font-size: 0.85rem;
  cursor: pointer;
  text-decoration: underline;
  padding: 0;
}

.error-msg {
  display: block;
  min-height: 1.2rem;
  margin-top: 0.3rem;
  font-size: 0.8rem;
  color: var(--error);
}

.form-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.75rem;
  margin-top: 1.75rem;
  padding-top: 1.25rem;
  border-top: 1px solid var(--border);
}

.btn {
  padding: 0.75rem 1.5rem;
  border: none;
  border-radius: 8px;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  transition: background 0.2s, transform 0.1s;
}

.btn:active:not(:disabled) {
  transform: scale(0.98);
}

.btn-primary {
  background: var(--primary);
  color: #fff;
  min-width: 160px;
  justify-content: center;
}

.btn-primary:hover:not(:disabled) {
  background: var(--primary-hover);
}

.btn-primary:disabled {
  opacity: 0.65;
  cursor: not-allowed;
}

.btn-secondary {
  background: #eef2f6;
  color: var(--text);
}

.btn-secondary:hover {
  background: #e2e8f0;
}

.btn-loader {
  width: 18px;
  height: 18px;
  border: 2px solid rgba(255, 255, 255, 0.4);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.toast {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  max-width: 360px;
  padding: 1rem 1.25rem;
  border-radius: 8px;
  font-size: 0.9rem;
  font-weight: 500;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
  z-index: 1000;
  animation: slideIn 0.3s ease;
}

.toast.success {
  background: var(--ingreso);
  color: #fff;
}

.toast.error {
  background: var(--error);
  color: #fff;
}

@keyframes slideIn {
  from {
    opacity: 0;
    transform: translateY(1rem);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.hidden {
  display: none !important;
}

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

  .form-actions {
    flex-direction: column-reverse;
  }

  .btn {
    width: 100%;
    justify-content: center;
  }
}