:root{
  color-scheme: light;
  --bg: #f3f5f8;
  --surface: #ffffff;
  --surface-soft: #f8fafc;
  --surface-raised: #ffffff;
  --text: #172033;
  --text-strong: #0d1526;
  --muted: #657286;
  --muted-soft: #8a95a6;
  --border: #d9e0ea;
  --border-strong: #c4cedb;
  --primary: #2563eb;
  --primary-strong: #1d4ed8;
  --primary-soft: #e8efff;
  --success-soft: #e9f7f0;
  --danger: #dc2626;
  --danger-soft: #fff0f0;
  --warning-soft: #fff7df;
  --focus: rgba(37, 99, 235, .18);
  --shadow: 0 10px 26px rgba(21, 32, 51, .08);
  --shadow-soft: 0 2px 8px rgba(21, 32, 51, .06);
  --topbar-h: 72px;
  --radius: 8px;
}

[data-theme="dark"]{
  color-scheme: dark;
  --bg: #111318;
  --surface: #181b22;
  --surface-soft: #13161c;
  --surface-raised: #1d2129;
  --text: #e7eaf0;
  --text-strong: #ffffff;
  --muted: #a2acba;
  --muted-soft: #7f8896;
  --border: #2a303a;
  --border-strong: #3a4350;
  --primary: #6ea8ff;
  --primary-strong: #9bc2ff;
  --primary-soft: rgba(110, 168, 255, .14);
  --success-soft: rgba(34, 197, 94, .12);
  --danger: #ff6b6b;
  --danger-soft: rgba(255, 107, 107, .12);
  --warning-soft: rgba(245, 158, 11, .14);
  --focus: rgba(110, 168, 255, .24);
  --shadow: 0 12px 28px rgba(0, 0, 0, .28);
  --shadow-soft: 0 2px 8px rgba(0, 0, 0, .18);
}

*{ box-sizing: border-box; }
html, body{ min-height: 100%; }
html{ background: var(--bg); }
body{
  margin: 0;
  padding-top: var(--topbar-h);
  background: var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, Arial, "Noto Sans", sans-serif;
  font-size: 14px;
  line-height: 1.45;
}

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

a{ color: inherit; }
.hidden{ display: none !important; }

.topbar{
  position: fixed;
  inset: 0 0 auto;
  z-index: 1000;
  height: var(--topbar-h);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 0 24px;
  background: color-mix(in oklab, var(--surface) 92%, transparent);
  border-bottom: 1px solid var(--border);
  backdrop-filter: blur(14px);
}

.brand{
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 12px;
}

.logo{
  width: 38px;
  height: 38px;
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface-raised);
  box-shadow: var(--shadow-soft);
  overflow: hidden;
}

.logo-img{
  width: 72%;
  height: 72%;
  object-fit: contain;
  user-select: none;
  pointer-events: none;
}

.brand-text{ min-width: 0; }
.brand-title{
  color: var(--text-strong);
  font-size: 15px;
  font-weight: 760;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.brand-subtitle{
  margin-top: 1px;
  color: var(--muted);
  font-size: 12px;
}

.topbar-actions{
  flex: 0 0 auto;
}

.container{
  width: min(1180px, calc(100% - 40px));
  margin: 22px auto 0;
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding-bottom: 8px;
  counter-reset: form-section;
}

.card{
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: var(--shadow-soft);
}

.form-card{
  counter-increment: form-section;
}

.card-header{
  display: flex;
  flex-direction: column;
  gap: 5px;
  margin-bottom: 14px;
}

.card-header.row{
  flex-direction: row;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
}

.card-header h2{
  display: flex;
  align-items: center;
  gap: 9px;
  margin: 0;
  color: var(--text-strong);
  font-size: 16px;
  font-weight: 760;
  letter-spacing: 0;
}

.card-header h2::before{
  content: counter(form-section);
  width: 24px;
  height: 24px;
  display: inline-grid;
  place-items: center;
  flex: 0 0 auto;
  border-radius: 50%;
  background: var(--primary-soft);
  color: var(--primary-strong);
  font-size: 12px;
  font-weight: 760;
}

.muted{
  color: var(--muted);
  font-size: 13px;
}

.small{ font-size: 12px; }

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

.field{
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.field.full{ grid-column: 1 / -1; }

.field-label{
  color: var(--text);
  font-size: 12px;
  font-weight: 690;
}

.required-star{
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  margin-left: 4px;
  color: var(--danger);
  font-weight: 800;
  cursor: help;
  outline: none;
}

.required-star::after{
  content: "Обязательное поле";
  position: absolute;
  left: 50%;
  bottom: calc(100% + 8px);
  z-index: 120;
  width: max-content;
  max-width: 180px;
  padding: 6px 8px;
  border: 1px solid color-mix(in oklab, var(--danger) 28%, var(--border));
  border-radius: 6px;
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow-soft);
  font-size: 12px;
  font-weight: 650;
  line-height: 1.2;
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, 4px);
  transition: opacity .16s ease, transform .16s ease;
}

.required-star::before{
  content: "";
  position: absolute;
  left: 50%;
  bottom: calc(100% + 3px);
  z-index: 121;
  width: 8px;
  height: 8px;
  border-right: 1px solid color-mix(in oklab, var(--danger) 28%, var(--border));
  border-bottom: 1px solid color-mix(in oklab, var(--danger) 28%, var(--border));
  background: var(--surface);
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, 4px) rotate(45deg);
  transition: opacity .16s ease, transform .16s ease;
}

.required-star:hover::after,
.required-star:hover::before,
.required-star:focus-visible::after,
.required-star:focus-visible::before{
  opacity: 1;
  transform: translate(-50%, 0);
}

.required-star:hover::before,
.required-star:focus-visible::before{
  transform: translate(-50%, 0) rotate(45deg);
}

input,
select,
textarea{
  width: 100%;
  min-height: 40px;
  padding: 9px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  outline: none;
  background: var(--surface-soft);
  color: var(--text-strong);
  transition: border-color .16s ease, box-shadow .16s ease, background .16s ease;
}

select{
  cursor: pointer;
}

select option{
  background: var(--surface);
  color: var(--text);
}

.custom-select{
  position: relative;
  width: 100%;
}

.native-select{
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

.custom-select-trigger{
  width: 100%;
  min-height: 40px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 9px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface-soft);
  color: var(--text-strong);
  text-align: left;
  cursor: pointer;
  transition: border-color .16s ease, box-shadow .16s ease, background .16s ease;
}

.custom-select-trigger:hover{
  border-color: var(--border-strong);
  background: var(--surface);
}

.custom-select.open .custom-select-trigger,
.custom-select-trigger:focus-visible{
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 4px var(--focus);
  background: var(--surface);
}

.custom-select-value{
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.custom-select-chevron{
  width: 8px;
  height: 8px;
  flex: 0 0 auto;
  border-right: 2px solid currentColor;
  border-bottom: 2px solid currentColor;
  transform: translateY(-2px) rotate(45deg);
  color: var(--muted);
  transition: transform .16s ease, color .16s ease;
}

.custom-select.open .custom-select-chevron{
  transform: translateY(2px) rotate(225deg);
  color: var(--primary);
}

.custom-select-menu{
  position: absolute;
  left: 0;
  right: 0;
  top: calc(100% + 6px);
  z-index: 80;
  display: none;
  max-height: 260px;
  overflow-y: auto;
  padding: 6px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.custom-select.open .custom-select-menu{
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.custom-select-option{
  width: 100%;
  min-height: 34px;
  padding: 8px 10px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--text);
  text-align: left;
  cursor: pointer;
}

.custom-select-option:hover,
.custom-select-option:focus-visible{
  outline: none;
  background: var(--surface-soft);
  color: var(--text-strong);
}

.custom-select-option[aria-selected="true"]{
  background: var(--primary-soft);
  color: var(--primary-strong);
  font-weight: 700;
}

.custom-select.disabled .custom-select-trigger{
  cursor: not-allowed;
  color: var(--muted);
  background: color-mix(in oklab, var(--surface-soft) 72%, var(--border));
  opacity: .72;
}

textarea{
  min-height: 112px;
  resize: vertical;
}

input::placeholder,
textarea::placeholder{
  color: var(--muted-soft);
}

input:focus,
select:focus,
textarea:focus{
  border-color: var(--primary);
  box-shadow: 0 0 0 4px var(--focus);
  background: var(--surface);
}

.field.field-invalid input,
.field.field-invalid textarea,
.field.field-invalid .custom-select-trigger{
  border-color: var(--danger);
  box-shadow: 0 0 0 4px color-mix(in oklab, var(--danger) 18%, transparent);
}

.field.field-invalid .seg{
  border-color: color-mix(in oklab, var(--danger) 44%, var(--border));
  background: color-mix(in oklab, var(--danger) 8%, var(--surface-soft));
  box-shadow: 0 0 0 3px color-mix(in oklab, var(--danger) 12%, transparent);
}

.field-shake{
  animation: fieldNudge .46s cubic-bezier(.2, .8, .25, 1);
}

@keyframes fieldNudge{
  0%{ transform: translateX(0); }
  18%{ transform: translateX(-4px); }
  38%{ transform: translateX(3px); }
  58%{ transform: translateX(-2px); }
  78%{ transform: translateX(1px); }
  100%{ transform: translateX(0); }
}

input[readonly]{
  color: var(--muted);
  background: color-mix(in oklab, var(--surface-soft) 80%, var(--border));
}

input:disabled,
select:disabled,
textarea:disabled{
  cursor: not-allowed;
  color: var(--muted);
  background: color-mix(in oklab, var(--surface-soft) 72%, var(--border));
  opacity: .72;
}

.btn{
  min-height: 38px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 8px 12px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  background: var(--surface-raised);
  color: var(--text);
  font-weight: 680;
  line-height: 1.1;
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
  transition: transform .06s ease, background .16s ease, border-color .16s ease, color .16s ease, opacity .16s ease;
}

.btn:hover{
  border-color: var(--primary);
  color: var(--primary-strong);
}
.btn:active{ transform: translateY(1px); }
.btn:disabled{
  cursor: not-allowed;
  opacity: .5;
}
.btn-sm{
  min-height: 32px;
  padding: 6px 10px;
  font-size: 12px;
}
.btn-primary{
  border-color: var(--primary);
  background: var(--primary);
  color: #ffffff;
}
.btn-primary:hover{
  background: var(--primary-strong);
  color: #ffffff;
}
.btn-danger{
  border-color: color-mix(in oklab, var(--danger) 40%, var(--border));
  background: var(--danger-soft);
  color: var(--danger);
}
.btn-danger:hover{
  border-color: var(--danger);
  color: var(--danger);
}
.btn-ghost{
  background: transparent;
}

.btn-ghost.active{
  border-color: color-mix(in oklab, var(--danger) 45%, var(--border));
  background: var(--danger-soft);
  color: var(--danger);
}

.row{ display: flex; align-items: center; }
.row.gap{ gap: 10px; }
.row.space-between{ justify-content: space-between; }

.stack{
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 4px;
}

.item{
  padding: 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface-soft);
}

.item-head{
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 12px;
}

.item-title{
  min-width: 34px;
  height: 26px;
  display: inline-grid;
  place-items: center;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  color: var(--primary-strong);
  font-size: 12px;
  font-weight: 800;
}

.item .grid-2,
.item .grid-3{
  row-gap: 11px;
}

.segmented{
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
}

.seg{
  min-height: 38px;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface-soft);
  color: var(--text);
  font-weight: 660;
  cursor: pointer;
  transition: background .16s ease, border-color .16s ease, color .16s ease, box-shadow .16s ease;
}

.seg:hover{
  border-color: var(--primary);
}

.seg:focus-visible{
  outline: none;
  box-shadow: 0 0 0 4px var(--focus);
}

.seg.active{
  border-color: var(--primary);
  background: var(--primary-soft);
  color: var(--primary-strong);
}

.segmented.mini .seg{
  min-height: 34px;
  padding: 7px 10px;
  font-size: 12px;
}

.notice-title{
  margin-bottom: 6px;
  color: var(--text-strong);
  font-weight: 800;
}

.notice-text{
  color: var(--text);
  line-height: 1.5;
}

.notice-card{
  border-color: color-mix(in oklab, #f59e0b 28%, var(--border));
  background: var(--warning-soft);
}

.result{
  min-height: 56px;
  margin-top: 10px;
  resize: none;
  overflow: hidden;
  border-color: var(--border-strong);
  background: var(--surface-soft);
  font-family: inherit;
  font-size: 13px;
  line-height: 1.5;
}

.counter{
  color: var(--muted);
  font-size: 12px;
  font-weight: 650;
}

.help-hint-btn,
.theme-toggle-btn{
  width: 36px;
  height: 36px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface-soft);
  color: var(--text);
  cursor: pointer;
  transition: background .16s ease, border-color .16s ease, color .16s ease;
}

.help-hint-btn{
  font-size: 16px;
  font-weight: 800;
}

.help-hint-btn:hover,
.theme-toggle-btn:hover{
  border-color: var(--primary);
  color: var(--primary-strong);
}

.theme-icon{
  width: 18px;
  height: 18px;
  display: grid;
  place-items: center;
}

.theme-icon svg{
  width: 18px;
  height: 18px;
  display: block;
}

.help-hint-overlay{
  position: fixed;
  inset: 0;
  z-index: 2000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: rgba(9, 13, 20, .52);
  backdrop-filter: blur(7px);
}

.help-hint-modal{
  width: min(720px, 100%);
  max-height: min(80vh, 760px);
  position: relative;
  overflow-y: auto;
  padding: 22px 24px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow);
}

.help-hint-close{
  position: absolute;
  top: 10px;
  right: 10px;
  width: 34px;
  height: 34px;
  border: 1px solid transparent;
  border-radius: var(--radius);
  background: transparent;
  color: var(--muted);
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
}

.help-hint-close:hover{
  border-color: var(--border);
  color: var(--text-strong);
}

.help-hint-modal h3{
  margin: 0 38px 10px 0;
  color: var(--text-strong);
  font-size: 18px;
}

.help-hint-modal p{
  margin: 0 0 12px;
  color: var(--muted);
}

.help-hint-modal ul{
  margin: 0;
  padding-left: 20px;
}

.help-hint-modal li{
  margin-bottom: 8px;
}

.app-footer{
  width: min(1180px, calc(100% - 40px));
  margin: 0 auto;
  padding: 16px 0 28px;
  color: var(--muted);
  font-size: 12px;
  text-align: center;
}

.footer-link{
  color: var(--text-strong);
  font-weight: 700;
  text-decoration: none;
  cursor: pointer;
}

.footer-link.dotted{
  text-decoration-line: underline;
  text-decoration-style: dotted;
  text-underline-offset: 3px;
}

.link-button{
  padding: 0;
  border: 0;
  background: none;
  font: inherit;
}

@media (max-width: 900px){
  .container,
  .app-footer{
    width: min(100% - 28px, 680px);
  }

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

  .card-header.row{
    flex-direction: column;
    align-items: stretch;
  }

  .card-header.row > .row{
    justify-content: flex-start;
    flex-wrap: wrap;
  }
}

@media (max-width: 560px){
  :root{ --topbar-h: 66px; }

  body{
    font-size: 13px;
  }

  .topbar{
    padding: 0 14px;
  }

  .brand{
    gap: 10px;
  }

  .logo{
    width: 34px;
    height: 34px;
  }

  .brand-title{
    max-width: 190px;
    font-size: 14px;
  }

  .brand-subtitle{
    font-size: 11px;
  }

  .container{
    width: calc(100% - 20px);
    margin-top: 12px;
    gap: 10px;
  }

  .card{
    padding: 14px;
  }

  .row.gap{
    gap: 8px;
  }

  .btn{
    width: 100%;
    white-space: normal;
  }

  .topbar .btn,
  .topbar .help-hint-btn,
  .topbar .theme-toggle-btn{
    width: 34px;
  }

  .topbar-actions.row.gap{
    gap: 7px;
  }

  .seg{
    flex: 1 1 auto;
  }

  .item{
    padding: 12px;
  }

  .help-hint-modal{
    padding: 20px 18px;
  }
}

/* ===== Переключатель разделов в шапке ===== */

.nav-switch{
  position: relative;
  flex: 0 0 auto;
}

.nav-switch-trigger{
  min-height: 36px;
  display: inline-flex;
  align-items: center;
  gap: 9px;
  padding: 4px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface-soft);
  color: var(--text);
  cursor: pointer;
  transition: background .16s ease, border-color .16s ease, color .16s ease;
}

.nav-switch-trigger:hover,
.nav-switch.open .nav-switch-trigger{
  border-color: var(--primary);
  color: var(--primary-strong);
}

.nav-switch-trigger:focus-visible{
  outline: none;
  box-shadow: 0 0 0 4px var(--focus);
}

.nav-switch-icon{
  width: 18px;
  height: 18px;
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  color: var(--muted);
}

.nav-switch-trigger:hover .nav-switch-icon,
.nav-switch.open .nav-switch-icon{
  color: var(--primary-strong);
}

.nav-switch-icon svg{
  width: 18px;
  height: 18px;
  display: block;
}

.nav-switch-text{
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  line-height: 1.15;
  text-align: left;
}

.nav-switch-caption{
  color: var(--muted);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: .04em;
  text-transform: uppercase;
}

.nav-switch-title{
  max-width: 190px;
  overflow: hidden;
  color: inherit;
  font-size: 13px;
  font-weight: 720;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.nav-switch-chevron{
  width: 7px;
  height: 7px;
  flex: 0 0 auto;
  border-right: 2px solid currentColor;
  border-bottom: 2px solid currentColor;
  color: var(--muted);
  transform: translateY(-2px) rotate(45deg);
  transition: transform .16s ease, color .16s ease;
}

.nav-switch.open .nav-switch-chevron{
  color: var(--primary);
  transform: translateY(2px) rotate(225deg);
}

.nav-switch-menu{
  position: absolute;
  right: 0;
  top: calc(100% + 8px);
  z-index: 90;
  display: none;
  width: min(320px, calc(100vw - 28px));
  padding: 8px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.nav-switch.open .nav-switch-menu{
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.nav-switch-menu-title{
  padding: 4px 8px 6px;
  color: var(--muted);
  font-size: 10px;
  font-weight: 750;
  letter-spacing: .05em;
  text-transform: uppercase;
}

.nav-switch-option{
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 9px 10px;
  border: 1px solid transparent;
  border-radius: 6px;
  color: var(--text);
  text-decoration: none;
  cursor: pointer;
}

.nav-switch-option:hover{
  border-color: var(--border);
  background: var(--surface-soft);
}

.nav-switch-option.active{
  border-color: color-mix(in oklab, var(--primary) 34%, var(--border));
  background: var(--primary-soft);
}

.nav-switch-option-title{
  color: var(--text-strong);
  font-size: 13px;
  font-weight: 720;
}

.nav-switch-option.active .nav-switch-option-title{
  color: var(--primary-strong);
}

.nav-switch-option-sub{
  color: var(--muted);
  font-size: 12px;
}

@media (max-width: 720px){
  .nav-switch-text{
    display: none;
  }

  .nav-switch-trigger{
    padding: 4px 8px;
    gap: 6px;
  }
}
