/* Light, airy style inspired by pdfm.asdv.cx */
:root {
  color-scheme: light;
  --bg-gradient: linear-gradient(135deg, #f4f7fb 0%, #edf1ff 50%, #e6f7ff 100%);
  --card-bg: rgba(255, 255, 255, 0.92);
  --card-shadow: 0 24px 60px -30px rgba(15, 23, 42, 0.45);
  --border-soft: rgba(120, 144, 156, 0.25);
  --primary: #2563eb;
  --accent: #3b82f6;
  --text: #0f172a;
  --muted: #475569;
  --success: #12805a;
  --error: #b91c1c;
  font-family: "Pretendard Variable", Pretendard, 'Inter', system-ui, -apple-system, 'Segoe UI', sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body.app {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 32px 16px 48px;
  background: var(--bg-gradient);
  color: var(--text);
}
.container { width: min(880px, 100%); }

.hero { text-align: center; margin-bottom: 28px; }
.hero h1 { margin: 0; font-size: clamp(2rem, 2.6vw + 1.2rem, 2.5rem); letter-spacing: -0.02em; }
.hero p { margin: 12px auto 0; max-width: 560px; color: var(--muted); font-size: 1.05rem; }

.card {
  background: var(--card-bg);
  backdrop-filter: blur(10px);
  border-radius: 22px;
  padding: clamp(24px, 2vw + 16px, 40px);
  box-shadow: var(--card-shadow);
  border: 1px solid var(--border-soft);
}

.row { display: flex; flex-direction: column; gap: 8px; margin-bottom: 14px; }
/* two-column row using grid */
.row-grid { display: grid; grid-template-columns: 2fr 1fr; gap: 10px; align-items: end; margin-bottom: 14px; }
label { color: var(--text); font-size: 0.95rem; font-weight: 600; }
input, select { padding: 12px 14px; border-radius: 12px; border: 1px solid rgba(148,163,184,.45); background: rgba(255,255,255,.9); color: var(--text); font-size: .95rem; }
input:focus, select:focus { outline: none; border-color: rgba(148,163,184,.8); }

div#days_wrap > input#days {
  width:100%;
}

/* Ensure Payment Term dropdown fills its grid cell on major browsers */
#term_kind {
  width: 100%;
  width: -webkit-fill-available; /* Chromium/WebKit */
  width: -moz-available;         /* Firefox */
}

.actions { margin-top: 16px; display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
button.primary { border: none; background: linear-gradient(135deg, var(--primary) 0%, var(--accent) 100%); color: #fff; padding: 12px 26px; border-radius: 999px; font-weight: 600; font-size: 1rem; cursor: pointer; box-shadow: 0 12px 30px -18px rgba(37,99,235,.65); transition: transform .2s, box-shadow .2s; }
button.primary:hover { transform: translateY(-1px); box-shadow: 0 15px 35px -15px rgba(37,99,235,.7); }

.errors { margin-top: 1rem; }
.errors ul { padding: 0.75rem 1rem; border: 1px solid rgba(185,28,28,.25); background: #fff5f5; border-radius: 12px; }
.errors li { color: var(--error); }

.result { margin-top: 1rem; }
.muted { color: var(--muted); }
.small { font-size: 0.85rem; }

@media (max-width: 640px) {
  body.app { padding: 24px 12px; }
  .row-grid { grid-template-columns: 1fr; }
}

/* Segmented date inputs */
.segments { display: inline-flex; align-items: center; gap: 8px; }
.segments input[type=text] { width: 6ch; text-align: center; }
.segments #yyyy { width: 10ch; }
.seg-sep { color: var(--muted); font-weight: 700; }

/* Country tag selection */
.selected-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  min-height: 40px;
  padding: 8px;
  background: rgba(255, 255, 255, 0.6);
  border-radius: 10px;
  border: 1px solid rgba(148, 163, 184, 0.25);
  align-items: center;
}

.country-tag {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px 6px 14px;
  background: linear-gradient(135deg, rgba(37, 99, 235, 0.08) 0%, rgba(59, 130, 246, 0.12) 100%);
  border: 1px solid rgba(37, 99, 235, 0.2);
  border-radius: 999px;
  font-size: 0.9rem;
  font-weight: 500;
  color: var(--primary);
  transition: all 0.2s;
}

.country-tag:hover {
  background: linear-gradient(135deg, rgba(37, 99, 235, 0.12) 0%, rgba(59, 130, 246, 0.16) 100%);
  border-color: rgba(37, 99, 235, 0.3);
}

.remove-tag {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 20px;
  height: 20px;
  border: none;
  background: rgba(37, 99, 235, 0.15);
  border-radius: 50%;
  color: var(--primary);
  font-size: 16px;
  font-weight: 700;
  line-height: 1;
  cursor: pointer;
  transition: all 0.2s;
  padding: 0;
}

.remove-tag:hover {
  background: rgba(185, 28, 28, 0.15);
  color: var(--error);
  transform: scale(1.1);
}

.remove-tag:active {
  transform: scale(0.95);
}

/* Date badges for excluded days */
.date-badge {
  display: inline-block;
  padding: 4px 10px;
  margin: 4px 4px 4px 0;
  background: rgba(148, 163, 184, 0.12);
  border: 1px solid rgba(148, 163, 184, 0.25);
  border-radius: 6px;
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--muted);
  font-family: 'Courier New', monospace;
}

.date-badge.holiday {
  background: rgba(18, 128, 90, 0.12);
  border-color: rgba(18, 128, 90, 0.25);
  color: var(--success);
}

/* Calendar visualization */
.calendar-container {
  margin-top: 20px;
  padding: 16px;
  background: rgba(255, 255, 255, 0.5);
  border-radius: 16px;
  border: 1px solid rgba(148, 163, 184, 0.2);
}

.calendar-header {
  text-align: center;
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 12px;
  padding-bottom: 8px;
  border-bottom: 2px solid rgba(37, 99, 235, 0.2);
}

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

.calendar-day-header {
  text-align: center;
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--muted);
  padding: 8px 4px;
}

.calendar-day {
  aspect-ratio: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  font-size: 0.85rem;
  border-radius: 8px;
  border: 1px solid rgba(148, 163, 184, 0.15);
  background: rgba(255, 255, 255, 0.8);
  color: var(--text);
  position: relative;
  transition: all 0.2s;
  padding: 4px;
  gap: 2px;
}

.calendar-day.empty {
  background: transparent;
  border-color: transparent;
}

.calendar-day.weekend {
  background: rgba(148, 163, 184, 0.08);
  color: var(--muted);
}

.calendar-day.excluded-weekend {
  background: rgba(148, 163, 184, 0.25);
  border-color: rgba(148, 163, 184, 0.4);
  color: var(--muted);
  font-weight: 700;
}

.calendar-day.holiday {
  background: rgba(18, 128, 90, 0.1);
  border-color: rgba(18, 128, 90, 0.3);
  color: var(--success);
  font-weight: 600;
}

.calendar-day.excluded-holiday {
  background: rgba(18, 128, 90, 0.2);
  border-color: rgba(18, 128, 90, 0.4);
  color: var(--success);
  font-weight: 700;
}

.calendar-day.delivery-date {
  background: linear-gradient(135deg, rgba(37, 99, 235, 0.85) 0%, rgba(59, 130, 246, 0.85) 100%);
  border-color: var(--primary);
  color: white;
  font-weight: 700;
  box-shadow: 0 2px 8px rgba(37, 99, 235, 0.3);
}

.calendar-day.due-date {
  background: linear-gradient(135deg, rgba(220, 38, 38, 0.85) 0%, rgba(239, 68, 68, 0.85) 100%);
  border-color: #dc2626;
  color: white;
  font-weight: 700;
  box-shadow: 0 2px 8px rgba(220, 38, 38, 0.3);
}

/* 카운팅 숫자 (ruby 스타일) */
.day-count {
  font-size: 0.5rem;
  line-height: 1;
  color: rgba(0, 0, 0, 0.4);
  font-weight: 600;
  height: 0.6rem;
}

/* 날짜 숫자 */
.day-number {
  font-size: 0.85rem;
  line-height: 1.2;
}

/* Special dates에서 카운팅 숫자 색상 조정 */
.calendar-day.delivery-date .day-count,
.calendar-day.due-date .day-count {
  color: rgba(255, 255, 255, 0.7);
}

.calendar-day.excluded-weekend .day-count {
  color: rgba(0, 0, 0, 0.5);
}

.calendar-day.holiday .day-count,
.calendar-day.excluded-holiday .day-count {
  color: rgba(18, 128, 90, 0.6);
}

.calendar-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin-top: 16px;
  padding-top: 12px;
  border-top: 1px solid rgba(148, 163, 184, 0.2);
  font-size: 0.85rem;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 6px;
}

.legend-color {
  width: 20px;
  height: 20px;
  border-radius: 4px;
  border: 1px solid rgba(0, 0, 0, 0.1);
}

.legend-color.delivery {
  background: linear-gradient(135deg, rgba(37, 99, 235, 0.85) 0%, rgba(59, 130, 246, 0.85) 100%);
}

.legend-color.due {
  background: linear-gradient(135deg, rgba(220, 38, 38, 0.85) 0%, rgba(239, 68, 68, 0.85) 100%);
}

.legend-color.weekend {
  background: rgba(148, 163, 184, 0.25);
}

.legend-color.holiday {
  background: rgba(18, 128, 90, 0.1);
}

.legend-color.excluded-holiday {
  background: rgba(18, 128, 90, 0.2);
}

/* Custom tooltip */
.custom-tooltip {
  position: fixed;
  background: rgba(15, 23, 42, 0.95);
  color: white;
  padding: 8px 12px;
  border-radius: 8px;
  font-size: 0.85rem;
  font-weight: 500;
  pointer-events: none;
  z-index: 1000;
  white-space: normal;
  max-width: 300px;
  text-align: center;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
  opacity: 0;
  transition: opacity 0.2s ease-in-out;
  transform: translateX(-50%);
}

.custom-tooltip.visible {
  opacity: 1;
}

.custom-tooltip::after {
  content: '';
  position: absolute;
  top: 100%;
  left: 50%;
  transform: translateX(-50%);
  border: 6px solid transparent;
  border-top-color: rgba(15, 23, 42, 0.95);
}

/* Footer */
.site-footer {
  margin-top: 48px;
  padding-top: 24px;
  text-align: center;
  color: var(--muted);
  font-size: 0.85rem;
  line-height: 1.6;
  border-top: 1px solid rgba(148, 163, 184, 0.2);
}

.site-footer p {
  display: block;
  margin-block-start: 1em;
  margin-block-end: 1em;
  margin-inline-start: 0px;
  margin-inline-end: 0px;
  unicode-bidi: isolate;
}

.site-footer a {
    color: inherit;
    font-weight: 600;
    text-decoration: none;
}
.site-footer a:hover {
  color: var(--accent);
  text-decoration: underline;
}

@media (max-width: 640px) {
  .calendar-day {
    font-size: 0.75rem;
  }

  .calendar-day-header {
    font-size: 0.65rem;
    padding: 6px 2px;
  }

  .day-count {
    font-size: 0.45rem;
    height: 0.5rem;
  }

  .day-number {
    font-size: 0.75rem;
  }

  .calendar-legend {
    font-size: 0.75rem;
  }

  .custom-tooltip {
    font-size: 0.75rem;
    padding: 6px 10px;
  }

  .site-footer {
    font-size: 0.75rem;
    margin-top: 32px;
  }
}
