:root {
  --bg: #0f172a;
  --card: #1e293b;
  --border: rgba(148, 163, 184, 0.2);
  --text: #f8fafc;
  --muted: #94a3b8;
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --success: #4ade80;
  --warning: #fbbf24;
  --radius: 16px;
  --radius-sm: 12px;
}

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

html {
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
}

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

.page {
  max-width: 1040px;
  margin: 0 auto;
  padding: 2.5rem 1.25rem 3rem;
}

.header {
  text-align: center;
  margin-bottom: 2rem;
}

.title {
  margin: 0 0 0.5rem;
  font-size: clamp(1.75rem, 4vw, 2rem);
  font-weight: 700;
  letter-spacing: -0.02em;
}

.subtitle {
  margin: 0;
  font-size: 0.95rem;
  color: var(--muted);
}

.grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.5rem;
  align-items: stretch;
}

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

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.card--form {
  padding: 1.75rem;
}

.form {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.form-actions {
  margin-top: auto;
  padding-top: 0.25rem;
}

.card--result-wrap {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  padding: 1.5rem;
  flex: 1;
}

.result-inner {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
  padding: 0;
}

.field {
  margin-bottom: 1.1rem;
}

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

.input-wrap {
  position: relative;
}

.input-wrap input {
  padding-right: 2.5rem;
}

.input-icon {
  position: absolute;
  right: 0.85rem;
  top: 50%;
  transform: translateY(-50%);
  color: var(--muted);
  pointer-events: none;
}

.input-wrap--date .input-icon--calendar {
  pointer-events: auto;
  cursor: pointer;
  z-index: 2;
  border-radius: 6px;
  padding: 2px;
  transition: color 0.15s ease, background 0.15s ease;
}

.input-wrap--date .input-icon--calendar:hover {
  color: var(--text);
  background: rgba(148, 163, 184, 0.12);
}

.input-wrap--date .input-icon--calendar:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}

.flatpickr-calendar {
  z-index: 100;
  border-radius: 12px;
  box-shadow: 0 16px 48px rgba(0, 0, 0, 0.35);
  font-family: "Inter", system-ui, sans-serif;
}

.flatpickr-day.selected,
.flatpickr-day.startRange,
.flatpickr-day.endRange {
  background: var(--primary);
  border-color: var(--primary);
}

.flatpickr-day.selected:hover,
.flatpickr-day.startRange:hover,
.flatpickr-day.endRange:hover {
  background: var(--primary-hover);
  border-color: var(--primary-hover);
}

.fp-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.75rem;
  padding: 0.55rem 0.65rem;
  border-top: 1px solid #e6e6e6;
  background: #fff;
}

.fp-footer__btn {
  margin: 0;
  padding: 0.25rem 0.35rem;
  border: none;
  background: none;
  font: inherit;
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--primary);
  cursor: pointer;
  border-radius: 6px;
}

.fp-footer__btn:hover {
  background: rgba(37, 99, 235, 0.08);
}

.fp-footer__btn:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 1px;
}

input[type="text"],
select {
  width: 100%;
  padding: 0.65rem 0.85rem;
  font-family: inherit;
  font-size: 0.95rem;
  color: var(--text);
  background: rgba(15, 23, 42, 0.6);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  outline: none;
  transition: border-color 0.15s ease;
}

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

select {
  cursor: pointer;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='%2394a3b8' viewBox='0 0 24 24'%3E%3Cpath d='M7 10l5 5 5-5H7z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.75rem center;
  padding-right: 2.25rem;
}

.form-error {
  font-size: 0.875rem;
  color: #f87171;
  margin: -0.25rem 0 0.75rem;
}

.hidden {
  display: none !important;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  font-family: inherit;
  font-size: 0.95rem;
  font-weight: 600;
  border: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background 0.15s ease, opacity 0.15s ease;
}

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

.btn--primary {
  width: 100%;
  padding: 0.85rem 1rem;
  margin-top: 0.25rem;
  color: #fff;
  background: var(--primary);
}

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

.btn--ghost {
  padding: 0.55rem 0.9rem;
  color: var(--text);
  background: rgba(15, 23, 42, 0.65);
  border: 1px solid var(--border);
}

.btn--ghost:hover:not(:disabled) {
  background: rgba(51, 65, 85, 0.8);
}

.result-placeholder {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  min-height: 0;
  color: var(--muted);
}

.calc-icon {
  opacity: 0.55;
  margin-bottom: 1rem;
}

.result-placeholder p {
  margin: 0;
  font-size: 0.95rem;
}

.result-content {
  flex: 1;
}

.result-content:not(.hidden) {
  display: flex;
  flex-direction: column;
}

.result-capture {
  padding: 1.75rem 2rem;
  margin: 0;
  border: 1px solid rgba(148, 163, 184, 0.45);
  border-radius: var(--radius-sm);
  /* Đặt nền đặc (không alpha) để html2canvas không sinh pixel trong suốt / vân caro */
  background-color: #1e293b;
  background-image: none;
}

.result-label {
  margin: 0;
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  color: var(--muted);
  text-align: center;
}

.result-amount {
  margin: 0.35rem 0 1rem;
  font-size: clamp(1.75rem, 4vw, 2.25rem);
  font-weight: 700;
  color: var(--success);
  text-align: center;
}

.divider {
  border: none;
  border-top: 1px solid var(--border);
  margin: 1rem 0;
}

.result-rows {
  margin: 0;
}

.result-rows .row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 1rem;
  font-size: 0.9rem;
  margin-bottom: 0.5rem;
}

.result-rows .row:last-child {
  margin-bottom: 0;
}

.result-rows dt {
  margin: 0;
  color: var(--muted);
  font-weight: 400;
}

.result-rows dd {
  margin: 0;
  text-align: right;
  font-weight: 500;
}

.text-used {
  color: var(--warning);
  font-weight: 600;
}

.text-remain {
  color: var(--success);
  font-weight: 600;
}

.copy-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.6rem;
  flex-wrap: wrap;
  flex-shrink: 0;
}

.toast {
  font-size: 0.85rem;
  color: var(--success);
  text-align: right;
  margin: 0;
  min-height: 1.25rem;
}

.toast.is-error {
  color: #f87171;
}
