/* ======================= */
/*        THEME VARS       */
/* ======================= */

:root {
  --bg: #f6f8fb;
  --fg: #1a1f2e;
  --mut: #6b7280;
  --card: #ffffff;
  --line: #e2e8f0;
  --ac: #2563eb;
  --ac-h: #1d4ed8;
  --danger: #dc2626;
  --shadow: 0 2px 12px rgba(0, 0, 0, .07), 0 1px 3px rgba(0, 0, 0, .05);
}

/* ======================= */
/*       BASE / RESET      */
/* ======================= */

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font: 16px/1.6 'Poppins', system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

h1,
h2,
h3,
h4 {
  margin: 0 0 8px;
  color: var(--fg);
  font-family: 'Poppins', system-ui, sans-serif;
  line-height: 1.25;
}

h1 {
  font-size: clamp(22px, 5vw, 32px);
  font-weight: 800;
  letter-spacing: -.02em;
}

h2 {
  font-size: clamp(18px, 3vw, 24px);
  font-weight: 700;
}

h3 {
  font-size: 17px;
  font-weight: 600;
}

p {
  margin: 0 0 12px;
  line-height: 1.65;
}

a {
  color: var(--ac);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

button,
input,
select,
textarea {
  font: inherit;
}

input,
select,
textarea {
  touch-action: manipulation;
}

@supports (-webkit-touch-callout: none) {
  input,
  select,
  textarea {
    font-size: 16px !important;
  }
}

/* ======================= */
/*        LAYOUT           */
/* ======================= */

.wrap {
  max-width: 900px;
  margin: auto;
  padding: 28px 20px;
}

.calc-page-wrap {
  max-width: 620px;
}

.grid {
  display: grid;
  gap: 14px;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
}

.row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  margin: 12px 0;
}

.row-2 {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
  margin: 12px 0;
}

@media (max-width: 640px) {
  .wrap {
    padding: 16px;
  }

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

/* ======================= */
/*          CARDS          */
/* ======================= */

.card,
.calc-card {
  background: var(--card);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
}

.card {
  border-radius: 20px;
  padding: 24px;
}

.calc-card {
  border-radius: 24px;
  padding: 28px 24px;
  box-shadow: 0 4px 24px rgba(0, 0, 0, .08), 0 1px 4px rgba(0, 0, 0, .04);
}

.card.link {
  display: block;
  transition: transform .15s ease, box-shadow .15s ease, border-color .15s ease;
}

.card.link h3 {
  margin: 0 0 5px;
  font-size: 15px;
  font-weight: 600;
  color: var(--fg);
}

.card.link p {
  margin: 0;
  color: var(--mut);
  font-size: 13px;
  line-height: 1.4;
}

.card.link:hover {
  transform: translateY(-2px);
  border-color: #c7d2fe;
  box-shadow: 0 6px 20px rgba(0, 0, 0, .1);
  text-decoration: none;
}

.blocks .card {
  padding: 20px;
}

@media (max-width: 640px) {
  .card {
    padding: 18px;
    border-radius: 16px;
  }

  .calc-card {
    padding: 20px 16px;
    border-radius: 20px;
  }
}

/* ======================= */
/*          FORMS          */
/* ======================= */

label {
  display: grid;
  gap: 6px;
  color: #374151;
  font-size: 13px;
  font-weight: 500;
}

input,
select,
textarea {
  width: 100%;
  min-height: 48px;
  padding: 0 14px;
  border: 1.5px solid var(--line);
  border-radius: 12px;
  background: #fff;
  color: var(--fg);
  font-size: 15px;
  transition: border-color .15s, box-shadow .15s;
}

textarea {
  min-height: 96px;
  padding-top: 12px;
  padding-bottom: 12px;
  resize: vertical;
}

input::placeholder,
textarea::placeholder {
  color: #9ca3af;
}

input:focus-visible,
select:focus-visible,
textarea:focus-visible {
  outline: none;
  border-color: var(--ac);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, .15);
}

select {
  appearance: none;
  padding-right: 36px;
  cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%236b7280' stroke-width='1.5' fill='none' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 14px center;
}

button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 48px;
  padding: 0 24px;
  border: 0;
  border-radius: 12px;
  background: var(--ac);
  color: #fff;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  letter-spacing: .01em;
  box-shadow: 0 2px 6px rgba(37, 99, 235, .3);
  transition: background .15s, transform .1s, box-shadow .15s;
}

button:hover {
  background: var(--ac-h);
  box-shadow: 0 4px 14px rgba(37, 99, 235, .38);
}

button:active {
  transform: translateY(1px);
  box-shadow: none;
}

/* ======================= */
/*       FIELD HELPERS     */
/* ======================= */

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.field-label {
  color: #374151;
  font-size: 13px;
  font-weight: 500;
  letter-spacing: .01em;
}

.field-input {
  height: 48px;
}

.field-hint,
.field-note,
.note {
  color: var(--mut);
  font-size: 12px;
  line-height: 1.5;
}

.field-note {
  display: block;
  margin-top: 6px;
}

.note {
  margin-top: 12px;
}

.field-error {
  color: var(--danger);
  font-size: 12px;
}

/* ======================= */
/*       CHECKBOXES        */
/* ======================= */

.checkboxes {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 8px;
  margin-top: 10px;
}

.checkboxes label,
.check-label {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  width: auto;
  max-width: fit-content;
  color: var(--fg);
  font-size: 14px;
  font-weight: 400;
  line-height: 1.4;
  cursor: pointer;
}

.checkboxes input[type="checkbox"],
.check-label input[type="checkbox"] {
  appearance: auto;
  flex: 0 0 18px;
  width: 18px !important;
  height: 18px !important;
  min-width: 18px !important;
  min-height: 18px !important;
  max-width: 18px !important;
  max-height: 18px !important;
  padding: 0 !important;
  margin: 0 !important;
  accent-color: var(--ac);
}

.checkbox-group {
  margin-top: 8px;
}

.field-note-muted {
  display: block;
  margin-top: 4px;
  color: var(--mut);
  font-size: 13px;
  line-height: 1.4;
}

.inline-check-input {
  display: grid;
  grid-template-columns: auto 1fr;
  align-items: center;
  gap: 12px;
}

.inline-check-input input[type="number"] {
  min-width: 120px;
}

/* Backward compatibility: если где-то уже стоит field-note как checkbox-label */
label.field-note {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  width: auto;
  max-width: fit-content;
  color: var(--fg);
  font-size: 14px;
  font-weight: 400;
  cursor: pointer;
}

label.field-note input[type="checkbox"] {
  appearance: auto;
  flex: 0 0 18px;
  width: 18px !important;
  height: 18px !important;
  min-width: 18px !important;
  min-height: 18px !important;
  max-width: 18px !important;
  max-height: 18px !important;
  padding: 0 !important;
  margin: 0 !important;
  accent-color: var(--ac);
}

/* ======================= */
/*        DETAILS          */
/* ======================= */

.fieldset {
  border: 1.5px solid var(--line);
  border-radius: 14px;
  padding: 16px;
}

.fieldset > legend {
  padding: 0 8px;
  color: var(--fg);
  font-size: 14px;
  font-weight: 600;
}

.fieldset > summary,
.fieldset > summary.clickable,
.summary-bold {
  cursor: pointer;
  user-select: none;
  list-style: none;
  color: var(--fg);
  font-weight: 600;
}

.fieldset > summary::-webkit-details-marker {
  display: none;
}

.fieldset > summary::after {
  content: "▾";
  float: right;
  transition: transform .2s ease;
}

.fieldset[open] > summary::after {
  transform: rotate(180deg);
}

/* ======================= */
/*        RESULTS          */
/* ======================= */

.res {
  display: block;
  margin-top: 16px;
  padding: 14px 18px;
  min-height: auto;
  max-width: 100%;
  border: 1.5px solid #bfdbfe;
  border-radius: 14px;
  background: #f0f7ff;
  color: var(--fg);
}

.res-line {
  display: flex;
  align-items: baseline;
  gap: 8px;
  line-height: 1.4;
}

.res-line + .res-line {
  margin-top: 7px;
}

.res-line span {
  color: var(--mut);
  font-size: 14px;
}

.res-line b {
  font-weight: 700;
}

.nowrap {
  white-space: nowrap;
}

.score {
  display: flex;
  align-items: baseline;
  gap: 8px;
}

.score-number {
  color: var(--ac);
  font-size: 28px;
  font-weight: 800;
  line-height: 1;
}

.score-suffix {
  opacity: .75;
}

/* ======================= */
/*     RESULT HERO BLOCK   */
/* ======================= */

.res-hero {
  margin-top: 20px;
  padding: 20px 22px;
  border-radius: 20px;
  background: linear-gradient(135deg, #2563eb 0%, #1d4ed8 100%);
  color: #fff;
  box-shadow: 0 6px 24px rgba(37, 99, 235, .35);
}

.res-hero__meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 6px;
}

.res-hero__label {
  color: rgba(255, 255, 255, .75);
  font-size: 12px;
  font-weight: 500;
  letter-spacing: .03em;
  text-transform: uppercase;
}

.res-hero__badge {
  padding: 2px 10px;
  border: 1px solid rgba(255, 255, 255, .25);
  border-radius: 999px;
  background: rgba(255, 255, 255, .2);
  color: #fff;
  font-size: 11px;
  font-weight: 600;
}

.res-hero__value {
  margin-bottom: 14px;
  font-size: clamp(28px, 6vw, 38px);
  font-weight: 800;
  line-height: 1.1;
  letter-spacing: -.02em;
}

.res-hero__details {
  display: flex;
  flex-direction: column;
  gap: 7px;
  padding-top: 12px;
  border-top: 1px solid rgba(255, 255, 255, .2);
}

.res-hero__row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 13px;
}

.res-hero__row span {
  color: rgba(255, 255, 255, .7);
}

.res-hero__row b {
  color: #fff;
  font-weight: 700;
}

/* ======================= */
/*      RESULT CARD        */
/* ======================= */

.res-card {
  margin-top: 20px;
  padding: 18px 20px;
  border: 1.5px solid #bfdbfe;
  border-radius: 16px;
  background: linear-gradient(135deg, #eff6ff 0%, #f0f9ff 100%);
}

.res-card .res-main {
  margin-bottom: 4px;
  font-size: 36px;
  font-weight: 800;
  line-height: 1;
}

.res-card .res-label {
  margin-bottom: 14px;
  color: var(--mut);
  font-size: 13px;
}

.res-card .res-details {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding-top: 14px;
  border-top: 1px solid #dbeafe;
}

/* ======================= */
/*        HERO / PAGE      */
/* ======================= */

.hero {
  margin-bottom: 24px;
}

.hero h1 {
  margin: 0 0 6px;
  font-size: clamp(24px, 5vw, 36px);
}

.hero .muted {
  margin: 0;
  color: var(--mut);
  font-size: 16px;
}

.section-title {
  margin: 24px 0 12px;
  color: var(--fg);
  font-size: 18px;
  font-weight: 700;
}

.calc-title {
  margin: 0 0 16px;
  color: var(--fg);
  font-size: 22px;
  font-weight: 700;
}

.calc-description {
  margin-top: 28px;
  padding: 20px 24px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: #fff;
  box-shadow: 0 1px 6px rgba(0, 0, 0, .04);
}

.calc-description h2 {
  margin: 0 0 8px;
  color: var(--fg);
  font-size: 16px;
  font-weight: 600;
}

.calc-description p {
  margin: 0;
  color: var(--mut);
  font-size: 15px;
  line-height: 1.7;
}

/* ======================= */
/*        INFO NOTE        */
/* ======================= */

.info-note {
  display: flex;
  gap: 10px;
  margin-top: 16px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: #f8fafc;
}

.info-note__icon {
  flex-shrink: 0;
  font-size: 15px;
  line-height: 1.5;
}

.info-note p {
  margin: 0;
  color: var(--mut);
  font-size: 12px;
  line-height: 1.6;
}

/* ======================= */
/*     LANGUAGE DROPDOWN   */
/* ======================= */

.lang-wrap {
  display: flex;
  justify-content: flex-end;
  margin: 0 0 16px;
}

.lang-dd {
  position: relative;
  display: inline-block;
}

.lang-dd__button {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 40px;
  padding: 0 12px;
  border: 1.5px solid var(--line);
  border-radius: 14px;
  background: #fff;
  color: var(--fg);
  font-family: inherit;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  box-shadow: 0 2px 8px rgba(15, 23, 42, .06);
  transition: border-color .12s, background .12s;
}

.lang-dd__button:hover {
  border-color: #bfdbfe;
  background: #f8fbff;
}

.lang-dd__chevron {
  color: var(--mut);
  font-size: 12px;
}

.lang-dd__menu {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  z-index: 50;
  width: 190px;
  padding: 6px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: #fff;
  box-shadow: 0 16px 40px rgba(15, 23, 42, .14);
}

.lang-dd__item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 12px;
  color: var(--fg);
  font-size: 14px;
  font-weight: 500;
  text-decoration: none;
  transition: background .1s;
}

.lang-dd__item:hover {
  background: #eff6ff;
  text-decoration: none;
}

.lang-dd__item b {
  margin-left: auto;
  color: var(--mut);
  font-size: 11px;
  font-weight: 600;
}

.lang-dd__item.is-active {
  background: #eff6ff;
  color: var(--ac);
}

.lang-dd__item.is-active b {
  color: var(--ac);
}

/* ======================= */
/*     SEGMENTED CONTROL   */
/* ======================= */

.seg-ctrl {
  display: inline-flex;
  gap: 2px;
  margin-bottom: 24px;
  padding: 4px;
  border-radius: 12px;
  background: #f1f5f9;
}

.seg-btn {
  min-height: 40px;
  padding: 8px 22px;
  border: 0;
  border-radius: 9px;
  background: transparent;
  color: var(--mut);
  font-size: 14px;
  font-weight: 500;
  line-height: 1;
  cursor: pointer;
  box-shadow: none;
  transition: background .15s, color .15s, box-shadow .15s;
}

.seg-btn.is-active {
  background: #fff;
  color: var(--fg);
  box-shadow: 0 1px 4px rgba(0, 0, 0, .12);
}

.seg-btn:hover:not(.is-active) {
  background: rgba(255, 255, 255, .55);
  color: var(--fg);
}

/* ======================= */
/*        CHIP GROUP       */
/* ======================= */

.chip-group {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 4px 0 16px;
}

.chip {
  padding: 7px 18px;
  border: 1.5px solid var(--line);
  border-radius: 999px;
  background: #fff;
  color: var(--mut);
  font-family: 'Poppins', sans-serif;
  font-size: 13px;
  font-weight: 500;
  line-height: 1;
  white-space: nowrap;
  cursor: pointer;
  transition: border-color .15s, color .15s, background .15s, box-shadow .15s;
}

.chip.is-active {
  border-color: var(--ac);
  background: var(--ac);
  color: #fff;
  box-shadow: 0 2px 8px rgba(37, 99, 235, .25);
}

.chip:hover:not(.is-active) {
  border-color: var(--ac);
  color: var(--ac);
}

/* ======================= */
/*       FIELD GRIDS       */
/* ======================= */

.fields-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 16px;
  margin: 0 0 16px;
}

.input-duo {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

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

/* ======================= */
/*        BACK LINK        */
/* ======================= */

.back-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 0;
  color: var(--mut);
  font-size: 14px;
  font-weight: 500;
  text-decoration: none;
  transition: color .15s;
}

.back-link:hover {
  color: var(--ac);
  text-decoration: none;
}

.back-link svg {
  flex-shrink: 0;
}

/* ======================= */
/*        UTILITIES        */
/* ======================= */

.inline-field {
  display: flex;
  align-items: center;
  gap: 8px;
}

.inline-check {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 22px;
}

.mt-10 {
  margin-top: 10px;
}

.hidden {
  display: none;
}

.clickable {
  cursor: pointer;
  font-weight: 600;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* ======================= */
/*     DAYS CALCULATOR     */
/* ======================= */

.calc-head {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 20px;
}

.calc-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 42px;
  height: 42px;
  border-radius: 16px;
  background: var(--ac);
  color: #fff;
  box-shadow: 0 8px 20px rgba(37, 99, 235, .24);
  font-size: 20px;
}

.date-pair {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: end;
  gap: 14px;
  margin: 12px 0 16px;
}

.swap-btn {
  width: 48px;
  height: 48px;
  min-height: 48px;
  padding: 0;
  border-radius: 999px;
  background: #fff;
  color: var(--fg);
  border: 1.5px solid var(--line);
  box-shadow: 0 2px 8px rgba(15, 23, 42, .08);
  font-size: 22px;
}

.swap-btn:hover {
  background: #eff6ff;
  color: var(--ac);
  border-color: #bfdbfe;
  box-shadow: 0 4px 14px rgba(37, 99, 235, .14);
}

.swap-btn.is-spinning {
  transform: rotate(180deg);
}

.toggle-card {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  margin: 0 0 18px;
  padding: 14px 16px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: #f8fafc;
  color: var(--fg);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}

.toggle-card:hover {
  background: #f1f5f9;
}

.toggle-card input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.toggle-dot {
  width: 24px;
  height: 24px;
  border: 2px solid #cbd5e1;
  border-radius: 9px;
  background: #fff;
  transition: background .15s, border-color .15s, box-shadow .15s;
}

.toggle-card input:checked + .toggle-dot {
  background: var(--ac);
  border-color: var(--ac);
  box-shadow: inset 0 0 0 6px #fff;
}

.date-result .res-hero {
  margin-top: 0;
}

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

  .swap-btn {
    justify-self: center;
    transform: rotate(90deg);
  }

  .swap-btn.is-spinning {
    transform: rotate(270deg);
  }
}