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

:root {
  --bg: #eef2f7;
  --surface: #ffffff;
  --text: #0f172a;
  --text-muted: #64748b;
  --primary: #3b82f6;
  --primary-hover: #2563eb;
  --primary-light: #eff6ff;
  --accent: #10b981;
  --accent-light: #ecfdf5;
  --warn: #f59e0b;
  --warn-light: #fffbeb;
  --border: #e2e8f0;
  --error: #ef4444;
  --error-bg: #fef2f2;
  --radius: 14px;
  --radius-sm: 8px;
  --shadow: 0 1px 3px rgba(15, 23, 42, 0.06), 0 8px 24px rgba(15, 23, 42, 0.06);
}

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

.app {
  max-width: 1080px;
  margin: 0 auto;
  padding: 1.5rem 1rem 2.5rem;
}

/* Header */
.header {
  text-align: center;
  margin-bottom: 1.75rem;
}

.header-badge {
  display: inline-block;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--primary);
  background: var(--primary-light);
  padding: 0.25rem 0.75rem;
  border-radius: 999px;
  margin-bottom: 0.75rem;
}

.header h1 {
  font-size: 1.85rem;
  font-weight: 800;
  letter-spacing: -0.03em;
}

.subtitle {
  margin-top: 0.4rem;
  font-size: 0.95rem;
  color: var(--text-muted);
  max-width: 480px;
  margin-inline: auto;
}

/* Two-column workspace */
.workspace {
  display: grid;
  gap: 1.25rem;
}

@media (min-width: 860px) {
  .workspace {
    grid-template-columns: 1fr 480px;
    align-items: start;
  }

  .panel-result {
    position: sticky;
    top: 1.25rem;
  }
}

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

.panel-form {
  padding: 1.5rem;
}

.panel-result {
  padding: 1rem;
  min-height: 320px;
  display: flex;
  flex-direction: column;
}

/* Steps */
.step {
  padding-bottom: 1.5rem;
  margin-bottom: 1.5rem;
  border-bottom: 1px solid var(--border);
}

.step:last-of-type {
  border-bottom: none;
  margin-bottom: 0;
  padding-bottom: 0;
}

.step-header {
  display: flex;
  align-items: flex-start;
  gap: 0.85rem;
  margin-bottom: 1.1rem;
}

.step-num {
  flex-shrink: 0;
  width: 2rem;
  height: 2rem;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--primary);
  color: #fff;
  font-size: 0.9rem;
  font-weight: 700;
  border-radius: 50%;
}

.step-header h2 {
  font-size: 1rem;
  font-weight: 700;
}

.step-desc {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-top: 0.1rem;
}

/* Fields */
.field-row {
  display: grid;
  gap: 1rem;
}

@media (min-width: 520px) {
  .field-row {
    grid-template-columns: 1fr 1fr;
  }
}

.stop-date-field {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.stop-date-field > label {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text);
}

.stop-input-row {
  display: flex;
  align-items: stretch;
  gap: 0.65rem;
}

.stop-input-row input[type="date"] {
  flex: 1;
  min-width: 0;
  padding: 0.7rem 0.85rem;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 1rem;
  color: var(--text);
  background: var(--surface);
  transition: border-color 0.15s, box-shadow 0.15s;
}

.stop-input-row input[type="date"]:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.18);
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.form-group-grow {
  flex: 1;
}

.form-group label {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text);
}

.form-group input[type="date"],
.price-input-wrap input {
  padding: 0.7rem 0.85rem;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 1rem;
  color: var(--text);
  background: var(--surface);
  transition: border-color 0.15s, box-shadow 0.15s;
  width: 100%;
}

.form-group input:focus,
.price-input-wrap input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.18);
}

.field-hint {
  font-size: 0.78rem;
  color: var(--text-muted);
  min-height: 1.1rem;
}

.field-hint.active {
  color: var(--primary);
  font-weight: 500;
}

/* Price input */
.price-input-wrap {
  display: flex;
  align-items: center;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.price-input-wrap:focus-within {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.18);
}

.price-prefix {
  padding: 0.7rem 0 0.7rem 0.85rem;
  font-weight: 600;
  color: var(--text-muted);
  background: #f8fafc;
}

.price-input-wrap input {
  border: none;
  box-shadow: none !important;
  padding-left: 0.5rem;
}

/* Quick actions */
.quick-actions {
  margin-top: 0.85rem;
}

.quick-label {
  display: block;
  font-size: 0.78rem;
  color: var(--text-muted);
  margin-bottom: 0.5rem;
}

.chip-group {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.chip {
  padding: 0.4rem 0.85rem;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text);
  background: #f8fafc;
  border: 1.5px solid var(--border);
  border-radius: 999px;
  cursor: pointer;
  transition: all 0.15s;
}

.chip:hover {
  border-color: var(--primary);
  color: var(--primary);
  background: var(--primary-light);
}

.chip:active {
  transform: scale(0.97);
}

/* Custom duration input */
.custom-duration {
  margin-top: 0.75rem;
}

.custom-duration-row {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  flex-wrap: wrap;
}

.custom-duration-row input,
.custom-duration-row select {
  padding: 0.35rem 0.5rem;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  background: var(--surface);
}

.custom-duration-row select {
  min-width: 70px;
}

.btn-custom {
  padding: 0.35rem 0.7rem;
  font-size: 0.8rem;
  font-weight: 600;
  background: var(--primary-light);
  color: var(--primary);
  border: 1.5px solid #bfdbfe;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all 0.15s;
}

.btn-custom:hover {
  background: #dbeafe;
}

.btn-today {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  padding: 0 1rem;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--primary);
  background: var(--primary-light);
  border: 1.5px solid #bfdbfe;
  border-radius: var(--radius-sm);
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.15s;
  flex-shrink: 0;
}

.btn-today:hover {
  background: #dbeafe;
}

/* Form actions */
.error-message {
  margin: 1rem 0;
  padding: 0.75rem 1rem;
  background: var(--error-bg);
  color: var(--error);
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  border: 1px solid #fecaca;
}

.form-actions {
  display: flex;
  gap: 0.75rem;
  margin-top: 1.25rem;
}

.btn-primary,
.btn-secondary {
  flex: 1;
  padding: 0.85rem 1.25rem;
  font-size: 0.95rem;
  font-weight: 700;
  border-radius: var(--radius-sm);
  cursor: pointer;
  border: none;
  transition: all 0.15s;
}

.btn-primary {
  background: var(--primary);
  color: #fff;
}

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

.btn-secondary {
  background: #f8fafc;
  color: var(--text-muted);
  border: 1.5px solid var(--border);
}

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

/* Result empty state */
.result-empty {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 2rem 1rem;
  color: var(--text-muted);
}

.empty-icon {
  color: #cbd5e1;
  margin-bottom: 1rem;
}

.empty-title {
  font-weight: 600;
  color: var(--text);
  font-size: 1rem;
}

.empty-desc {
  font-size: 0.85rem;
  margin-top: 0.35rem;
  max-width: 240px;
}

/* Result content - side by side layout */
.result-content {
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
  flex: 1;
}

.result-body {
  display: flex;
  gap: 1rem;
  flex: 1;
  min-height: 0;
  justify-content: space-between;
  padding: 0 0.25rem;
}

.result-visuals {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 0.7rem;
  min-width: 0;
}

.result-top h2 {
  font-size: 1.05rem;
  font-weight: 700;
}

.calculated-at {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 0.2rem;
}

/* Timeline */
.timeline {
  background: #f8fafc;
  border-radius: var(--radius-sm);
  padding: 0.7rem;
  border: 1px solid var(--border);
}

.timeline-labels {
  display: flex;
  justify-content: space-between;
  font-size: 0.72rem;
  color: var(--text-muted);
  margin-bottom: 0.5rem;
}

.timeline-track {
  position: relative;
  height: 10px;
  background: #d1fae5;
  border-radius: 999px;
  overflow: visible;
}

.timeline-used {
  height: 100%;
  background: linear-gradient(90deg, #3b82f6, #60a5fa);
  border-radius: 999px;
  width: 0%;
  transition: width 0.4s ease;
}

.timeline-marker {
  position: absolute;
  top: 50%;
  width: 14px;
  height: 14px;
  background: #fff;
  border: 3px solid var(--warn);
  border-radius: 50%;
  transform: translate(-50%, -50%);
  left: 0%;
  transition: left 0.4s ease;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.15);
}

.timeline-legend {
  display: flex;
  gap: 1rem;
  margin-top: 0.65rem;
  font-size: 0.78rem;
  color: var(--text-muted);
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 0.35rem;
}

.dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  display: inline-block;
}

.dot-used { background: var(--primary); }
.dot-remain { background: var(--accent); }

/* Stat grid */
.stat-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.65rem;
}

.stat-card {
  background: #f8fafc;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.55rem;
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
}

.stat-label {
  font-size: 0.72rem;
  color: var(--text-muted);
  font-weight: 500;
}

.stat-value {
  font-size: 0.95rem;
  font-weight: 700;
}

.stat-used { color: var(--primary); }
.stat-remain { color: var(--accent); }

/* Refund hero */
.refund-hero {
  background: var(--accent-light);
  border: 1.5px solid #a7f3d0;
  border-radius: var(--radius-sm);
  padding: 0.75rem;
}

.refund-label {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.refund-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-top: 0.35rem;
}

.refund-amount {
  font-size: 1.6rem;
  font-weight: 800;
  color: var(--accent);
  letter-spacing: -0.02em;
}

.refund-pct {
  display: block;
  font-size: 0.78rem;
  color: #047857;
  margin-top: 0.35rem;
}

.btn-copy {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.5rem 0.75rem;
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--accent);
  background: #fff;
  border: 1.5px solid #a7f3d0;
  border-radius: var(--radius-sm);
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.15s;
}

.btn-copy:hover {
  background: #d1fae5;
}

.btn-copy.copied {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

.btn-copy.copied .copy-text::after {
  content: " ✓";
}

/* Footer */
.footer {
  margin-top: 2rem;
  text-align: center;
}

.footer p {
  font-size: 0.8rem;
  color: var(--text-muted);
}

.footer a {
  color: var(--primary);
  font-weight: 600;
  text-decoration: none;
}

.footer a:hover {
  text-decoration: underline;
}

/* Summary table positioned on the RIGHT side */
.summary-section {
  width: 170px;
  flex-shrink: 0;
  background: #f8fafc;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.6rem 0.5rem;
  font-size: 0.72rem;
  overflow: hidden;
}

.summary-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.4rem;
  gap: 0.3rem;
}

.summary-title {
  font-size: 0.7rem;
  font-weight: 700;
  color: var(--text);
  line-height: 1.1;
}

.btn-copy-summary {
  display: inline-flex;
  align-items: center;
  gap: 0.2rem;
  padding: 0.2rem 0.4rem;
  font-size: 0.62rem;
  font-weight: 700;
  color: var(--accent);
  background: #fff;
  border: 1px solid #a7f3d0;
  border-radius: 4px;
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.15s;
  flex-shrink: 0;
}

.btn-copy-summary:hover {
  background: #d1fae5;
}

.btn-copy-summary:active {
  transform: scale(0.98);
}

.result-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.7rem;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 4px;
  overflow: hidden;
  table-layout: fixed;
}

.result-table td {
  padding: 4px 6px;
  border-bottom: 1px solid #f1f5f9;
  vertical-align: middle;
  line-height: 1.2;
}

.result-table tr:last-child td {
  border-bottom: none;
}

.result-table td:first-child {
  color: var(--text-muted);
  font-weight: 500;
  width: 52%;
  background: #fafbfc;
  padding-right: 3px;
}

.result-table td:last-child {
  font-weight: 600;
  color: var(--text);
  text-align: right;
  font-size: 0.68rem;
}

.result-table tr:nth-last-child(2) td,
.result-table tr:last-child td {
  background: var(--accent-light);
  font-weight: 700;
}

.result-table tr:last-child td {
  color: var(--accent);
}

.summary-note {
  margin-top: 0.35rem;
  font-size: 0.58rem;
  color: var(--text-muted);
  text-align: center;
  line-height: 1.2;
}