:root {
  color-scheme: light;
  --bg: #f7efe9;
  --panel: #fffaf7;
  --line: #e7d2c7;
  --line-soft: #f0e1d8;
  --text: #4a2418;
  --muted: #7a5a4d;
  --primary: #b85c38;
  --primary-2: #a94d2d;
  --primary-3: #8f3f22;
  --single: #f7e9e0;
  --syn: #f3ece7;
  --syn-border: #d9c2b5;
  --ok: #178a63;
  --danger: #cc3344;
  --progress-bg: #f1e3db;
  --progress-fill: linear-gradient(90deg, #d97a4a, #b85c38);
  --shadow: 0 16px 48px rgba(104, 53, 34, .055);
  --viewport: 100vh;
}

@supports (height: 100dvh) {
  :root { --viewport: 100dvh; }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Arial, sans-serif;
  font-size: 15px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  overflow: hidden;
  background:
    radial-gradient(ellipse at 100% 0, #eddbce, transparent 48%),
    var(--bg);
}

button, input, select { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: .6; }
a { color: var(--primary); }
:focus-visible { outline: 3px solid #b97550; outline-offset: 3px; }
.hidden, [hidden] { display: none !important; }

* { scrollbar-width: thin; scrollbar-color: #d9c2b5 transparent; }
*::-webkit-scrollbar { width: 7px; height: 7px; }
*::-webkit-scrollbar-thumb { background: #d9c2b5; border-radius: 20px; }
*::-webkit-scrollbar-track { background: transparent; }

.layout {
  display: grid;
  grid-template-columns: 286px minmax(0, 1fr);
  gap: 14px;
  height: var(--viewport);
  padding: 14px;
  padding-top: max(14px, env(safe-area-inset-top));
  padding-left: max(14px, env(safe-area-inset-left));
  padding-right: max(14px, env(safe-area-inset-right));
  padding-bottom: max(14px, env(safe-area-inset-bottom));
}

.sidebar, .main {
  min-width: 0;
  min-height: 0;
  border: 1px solid var(--line);
  border-radius: 24px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.sidebar {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: linear-gradient(170deg, #fff, #fbf4ef);
}

.brand {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex: 0 0 auto;
  padding: 22px 16px;
}

.brand > div {
  max-width: 160px;
  font-size: 13px;
  font-weight: 750;
  line-height: 1.4;
  letter-spacing: -.15px;
}

.logout-btn {
  min-height: 40px;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 11px;
  background: #fff;
  color: var(--muted);
  font-size: 11px;
  font-weight: 650;
}

.menu {
  display: grid;
  gap: 6px;
  flex: 0 1 auto;
  min-height: 0;
  max-height: 45%;
  padding: 0 14px 16px;
  border-bottom: 1px solid var(--line-soft);
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
}

.menu-intro {
  padding: 0 3px 9px;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.6;
}

.menu button, .menu a {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  width: 100%;
  min-height: 42px;
  padding: 10px 13px;
  border: 1px solid transparent;
  border-radius: 12px;
  background: transparent;
  color: var(--text);
  font-size: 13px;
  font-weight: 650;
  text-align: left;
  text-decoration: none;
  transition: background .15s, border-color .15s;
}

.menu button.primary {
  min-height: 46px;
  margin-bottom: 7px;
  background: linear-gradient(135deg, #c96a3f, #a94d2d);
  color: #fff;
  box-shadow: 0 8px 20px #b85c3820;
}

.menu a.delphina-primary { background: #eaf3ff; color: #2561b4; }
.menu a.bot-primary { background: #edf8f0; color: #267541; }
.menu a.sapphire-primary { background: #f2edff; color: #6940d5; }
.menu a.sophia-primary { background: #f7eaee; color: #762c43; }

.release-label {
  padding: 2px 5px;
  border: 1px solid currentColor;
  border-radius: 5px;
  font-size: 9px;
  letter-spacing: .04em;
  text-transform: uppercase;
  opacity: .8;
}

.side-section {
  display: flex;
  flex-direction: column;
  flex: 1 1 auto;
  min-height: 100px;
  padding: 18px 14px;
  overflow: hidden;
}

.section-title {
  flex: 0 0 auto;
  margin: 0 3px 12px;
  color: var(--muted);
  font-size: 10px;
  font-weight: 750;
  letter-spacing: .13em;
  text-transform: uppercase;
}

.profiles-list {
  display: grid;
  align-content: start;
  gap: 7px;
  flex: 1 1 auto;
  min-height: 0;
  min-width: 0;
  overflow-y: auto;
  overflow-x: hidden;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
}

.profile-item {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  min-width: 0;
  min-height: 46px;
  padding: 10px;
  border: 1px solid transparent;
  border-radius: 12px;
  background: transparent;
  color: var(--text);
  text-align: left;
  text-decoration: none;
}

.profile-item.active { background: #f8e9df; border-color: #dfbda9; }

.item-text {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 12px;
  font-weight: 650;
}

.dot {
  width: 8px;
  height: 8px;
  flex: 0 0 8px;
  border-radius: 50%;
  background: #d3b6a4;
}

.profile-item.active .dot { background: var(--primary); }

.profile-badge {
  flex: 0 0 auto;
  padding: 3px 5px;
  border: 1px solid var(--line);
  border-radius: 6px;
  font-size: 9px;
  font-weight: 650;
  white-space: nowrap;
}

.profile-badge.single { background: var(--single); color: #9b4f2f; }
.profile-badge.synastry { background: var(--syn); color: var(--muted); border-color: var(--syn-border); }

.profile-footer {
  flex: 0 0 auto;
  display: grid;
  gap: 15px;
  padding: 16px;
  margin-top: auto;
  border-top: 1px solid var(--line);
  background: #fffaf7;
}

.profile-footer-top { display: flex; align-items: center; gap: 11px; }
.profile-footer-top > div:last-child { min-width: 0; }

.avatar {
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  flex: 0 0 38px;
  border-radius: 13px;
  background: #f5e5da;
  color: var(--primary-3);
  font-size: 13px;
  font-weight: 750;
}

.profile-name { font-size: 13px; font-weight: 750; overflow-wrap: anywhere; }
.profile-level { margin-top: 2px; color: var(--muted); font-size: 11px; }
.level-box { display: grid; gap: 8px; }
.level-row { display: flex; justify-content: space-between; gap: 8px; font-size: 10px; color: var(--muted); }
.progress { height: 6px; border-radius: 99px; background: var(--progress-bg); overflow: hidden; }
.progress-fill { width: 0; height: 100%; border-radius: inherit; background: var(--progress-fill); transition: width .2s; }

.main {
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding: 20px;
  overflow: hidden;
  background: linear-gradient(160deg, #fffdfb, #faf2ec);
}

.top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex: 0 0 auto;
  padding: 2px 0 8px;
}

.top-left, .top-right { display: flex; align-items: center; gap: 10px; min-width: 0; }
.top-left { flex: 1; }
.top-right { flex: 0 0 auto; }

.model-badge {
  flex: 0 0 auto;
  color: var(--text);
  font: 26px Georgia, serif;
  letter-spacing: -.6px;
}

.selected-profile-pill {
  min-width: 0;
  max-width: 330px;
  padding: 4px 0 4px 14px;
  border-left: 1px solid var(--line);
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.top-up-btn, .mobile-top-up-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 40px;
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fff;
  color: var(--primary-3);
  text-decoration: none;
  font-size: 12px;
  font-weight: 650;
  white-space: nowrap;
}

.balance, .mobile-balance {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  min-height: 40px;
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #f7ece4;
  color: #9b4f2f;
  font-size: 13px;
  font-weight: 750;
  font-variant-numeric: tabular-nums;
}

.diamond {
  display: inline-block;
  width: 9px;
  height: 9px;
  flex: 0 0 9px;
  border: 1px solid #c96a3f;
  border-radius: 2px;
  background: linear-gradient(180deg, #e6a07c, #b85c38);
  transform: rotate(45deg);
}

.sophia-release {
  position: relative;
  isolation: isolate;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  flex: 0 0 auto;
  min-height: 38px;
  padding: 8px 11px;
  border: 1px solid #e6cbd4;
  border-radius: 12px;
  background: #fff7fa;
  color: #762c43;
  text-decoration: none;
  font-size: 12px;
  font-weight: 750;
  white-space: nowrap;
}

.sophia-release::after {
  content: "";
  position: absolute;
  inset: 0;
  z-index: -1;
  border-radius: inherit;
  box-shadow: 0 4px 15px #a4416952;
  animation: sophia-glow 3.4s ease-in-out infinite;
  pointer-events: none;
}

.sophia-release small { font-size: 9px; font-weight: 650; opacity: .8; }
@keyframes sophia-glow { 0%, 100% { opacity: .25; } 50% { opacity: .85; } }

/* Единая прокрутка содержимого: карточки не вытесняют темы за экран. */
.content-shell {
  display: flex;
  flex-direction: column;
  gap: 16px;
  flex: 1 1 auto;
  min-height: 0;
  min-width: 0;
  padding: 2px 3px 16px;
  overflow-y: auto;
  overflow-x: hidden;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
}

.status-card, .build-panel, .final-panel {
  flex: 0 0 auto;
  min-width: 0;
  padding: 26px;
  border: 1px solid var(--line);
  border-radius: 22px;
  background: #fffdfb;
  box-shadow: var(--shadow);
}

.status-card { background: linear-gradient(125deg, #fffdfb, #f6e8dd); }

.status-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 20px;
  flex-wrap: wrap;
}

.status-head > div:first-child { flex: 1 1 260px; min-width: 0; }
.status-title { font-size: clamp(23px, 2.5vw, 30px); font-weight: 750; letter-spacing: -.7px; line-height: 1.2; overflow-wrap: anywhere; }
.status-subtitle { margin-top: 10px; color: var(--muted); font-size: 13px; line-height: 1.7; overflow-wrap: anywhere; }
.status-actions { display: flex; align-items: center; gap: 9px; flex-wrap: wrap; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 46px;
  padding: 11px 16px;
  border: 1px solid var(--line);
  border-radius: 13px;
  background: #fff;
  color: var(--text);
  font-size: 13px;
  font-weight: 650;
  line-height: 1.4;
  text-align: center;
  text-decoration: none;
  transition: background .15s, box-shadow .15s;
}

.btn.primary {
  border-color: transparent;
  background: linear-gradient(135deg, #c96a3f, #a94d2d);
  color: #fff;
  box-shadow: 0 8px 20px #b85c3820;
}

.btn.success { background: linear-gradient(135deg, #31956b, #236b50); border-color: transparent; color: #fff; }

.build-panel { display: grid; gap: 14px; }
.build-panel-top { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.build-panel-title { font-size: 15px; font-weight: 750; color: var(--primary-3); }
.build-panel-percent { flex: 0 0 auto; font-size: 14px; font-weight: 750; color: var(--primary); font-variant-numeric: tabular-nums; }
.build-panel-bar { height: 7px; border-radius: 99px; overflow: hidden; background: var(--progress-bg); }
.build-panel-bar-fill { width: 0; height: 100%; border-radius: inherit; background: var(--progress-fill); transition: width .9s linear; }
.build-panel-text { color: var(--muted); font-size: 13px; line-height: 1.6; }
.tasks-wrap { min-width: 0; }
.tasks-list { display: grid; gap: 9px; min-width: 0; }

.task-item {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  min-width: 0;
  padding: 15px;
  border: 1px solid var(--line-soft);
  border-radius: 14px;
  background: #fff;
}

.task-left { display: grid; gap: 6px; flex: 1; min-width: 0; }
.task-theme { font-size: 13px; font-weight: 650; line-height: 1.5; overflow-wrap: anywhere; }
.task-status { font-size: 11px; line-height: 1.5; }
.task-status.pending { color: #9b4f2f; }
.task-status.processing { color: #1f6fe3; }
.task-status.done { color: var(--ok); }
.task-status.failed { color: var(--danger); }

.task-pill { flex: 0 0 auto; padding: 4px 7px; border: 1px solid var(--line-soft); border-radius: 7px; font-size: 9px; white-space: nowrap; }
.task-pill.pending { background: #f7e9e0; color: #9b4f2f; }
.task-pill.processing { background: #eaf2ff; color: #1f6fe3; }
.task-pill.done { background: #e8f7ef; color: var(--ok); }
.task-pill.failed { background: #fff0f2; color: var(--danger); }

.final-panel { display: grid; gap: 14px; background: linear-gradient(125deg, #fffdfb, #eff7f0); }
.final-panel-title { color: #236b50; font-size: 22px; font-weight: 750; letter-spacing: -.4px; }
.final-panel-text { color: var(--muted); font-size: 14px; line-height: 1.7; }

.modal-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 1400;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: #4a241866;
}

.modal-backdrop.open { display: flex; }

.modal {
  width: min(760px, 100%);
  max-height: calc(var(--viewport) - 40px);
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  border: 1px solid var(--line);
  border-radius: 24px;
  background: #fbf5f0;
  box-shadow: 0 24px 80px #4a241833;
}

.modal-head {
  position: sticky;
  top: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 16px 20px;
  border-bottom: 1px solid var(--line);
  background: #fffdfb;
}

.modal-title { font-size: 19px; font-weight: 750; letter-spacing: -.4px; }
.icon-btn { width: 42px; height: 42px; flex: 0 0 auto; border: 1px solid var(--line); border-radius: 12px; background: #fff; color: var(--muted); }
.modal-body { display: grid; gap: 14px; padding: 20px; }

/* Парный профиль скрыт существующей логикой. */
.grid-2 { display: grid; grid-template-columns: minmax(0, 1fr); gap: 14px; }
.card { min-width: 0; padding: 20px; border: 1px solid var(--line); border-radius: 18px; background: #fffdfb; }
.card h4 { margin: 0 0 18px; font-size: 15px; font-weight: 750; }
.field { display: grid; gap: 7px; min-width: 0; margin-bottom: 14px; }
.field:last-child { margin-bottom: 0; }
.label { color: var(--muted); font-size: 12px; font-weight: 650; }
.row { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.profile-type-fixed { display: inline-flex; padding: 9px 12px; border-radius: 11px; background: var(--single); color: var(--primary-3); }

input[type="text"], input[type="date"], input[type="time"], select {
  display: block;
  width: 100%;
  min-width: 0;
  max-width: 100%;
  min-height: 46px;
  padding: 10px 12px;
  border: 1px solid #dfc7b9;
  border-radius: 11px;
  background: #fff;
  color: var(--text);
  font-size: 16px;
  outline: none;
}

input:focus, select:focus { border-color: #c18f71; box-shadow: 0 0 0 3px #b85c380c; }
.city-autocomplete { position: relative; }

/* Подсказки не выходят за границы модалки. */
.city-dropdown {
  display: none;
  position: static;
  min-width: 0;
  max-height: 220px;
  overflow-y: auto;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fff;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
}

.city-dropdown.open { display: block; }
.city-option { display: block; width: 100%; min-height: 44px; padding: 11px 12px; border: 0; border-bottom: 1px solid var(--line-soft); background: #fff; color: var(--text); font-size: 14px; text-align: left; overflow-wrap: anywhere; }
.city-option:last-child { border-bottom: 0; }
.city-option-empty { padding: 12px; color: var(--muted); font-size: 13px; }

.modal-foot {
  position: sticky;
  bottom: 0;
  z-index: 40;
  display: flex;
  justify-content: flex-end;
  gap: 9px;
  padding: 15px 20px;
  border-top: 1px solid var(--line);
  background: #fffdfb;
}

.mobile-topbar, .mobile-sidebar-overlay { display: none; }

@media (hover: hover) {
  .menu button:hover, .menu a:hover { border-color: #d9bdad; filter: brightness(.98); }
  .btn.primary:hover:not(:disabled), .btn.success:hover { filter: brightness(.95); }
  .profile-item:hover, .city-option:hover, .btn:not(.primary):not(.success):hover, .icon-btn:hover, .logout-btn:hover,
  .top-up-btn:hover, .mobile-top-up-btn:hover { background: #fff1e8; }
  .sophia-release:hover { background: #f9e9ef; }
}

@media (min-width: 769px) and (max-width: 1180px) {
  .layout { grid-template-columns: 246px minmax(0, 1fr); gap: 10px; }
  .brand { padding-inline: 12px; }
  .menu, .side-section { padding-inline: 10px; }
  .main { padding: 14px; }
  .top { flex-wrap: wrap; }
  .top-left { flex-basis: 100%; }
  .top-right { width: 100%; }
  .top-right .sophia-release { margin-right: auto; }
  .selected-profile-pill { max-width: none; }
  .status-card, .build-panel, .final-panel { padding: 20px; }
}

@media (max-width: 768px) {
  .layout { height: var(--viewport); padding: 0; gap: 0; grid-template-columns: minmax(0, 1fr); }

  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    z-index: 1200;
    width: min(320px, 88vw);
    height: var(--viewport);
    border-radius: 0 22px 22px 0;
    transform: translateX(-105%);
    transition: transform .22s ease;
    box-shadow: 12px 0 45px #4a241825;
    padding-top: env(safe-area-inset-top);
    padding-left: env(safe-area-inset-left);
    padding-bottom: env(safe-area-inset-bottom);
    visibility: hidden;
  }

  body.mobile-menu-open .sidebar { transform: translateX(0); visibility: visible; }
  .mobile-sidebar-overlay { display: block; position: fixed; inset: 0; z-index: 1100; opacity: 0; pointer-events: none; background: #4a241866; transition: opacity .2s; }
  body.mobile-menu-open .mobile-sidebar-overlay { opacity: 1; pointer-events: auto; }

  .main {
    border: 0;
    border-radius: 0;
    box-shadow: none;
    gap: 10px;
    padding: 8px;
    padding-top: max(8px, env(safe-area-inset-top));
    padding-left: max(8px, env(safe-area-inset-left));
    padding-right: max(8px, env(safe-area-inset-right));
    padding-bottom: max(8px, env(safe-area-inset-bottom));
  }

  .top { display: none; }
  .mobile-topbar { display: flex; flex-direction: column; flex: 0 0 auto; gap: 5px; padding: 0 2px 3px; }
  .mobile-topbar-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; min-width: 0; }
  .mobile-topbar-actions { display: flex; align-items: center; gap: 6px; min-width: 0; }
  .mobile-menu-btn { min-height: 42px; padding: 8px; border: 0; background: transparent; color: var(--text); font-size: 13px; font-weight: 750; white-space: nowrap; }
  .mobile-top-up-btn { min-height: 38px; padding: 7px 9px; font-size: 11px; }
  .mobile-balance { min-height: 38px; min-width: 0; padding: 7px 9px; font-size: 12px; }
  #mobileBalanceValue { min-width: 0; overflow-wrap: anywhere; }
  .mobile-profile-row { display: flex; align-items: center; gap: 8px; min-width: 0; }
  .mobile-current-profile { flex: 1; min-width: 0; padding: 7px 3px; color: var(--muted); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .mobile-profile-row .sophia-release { min-height: 34px; padding: 6px 9px; font-size: 11px; border-radius: 10px; gap: 5px; }
  .mobile-profile-row .sophia-release small { font-size: 8px; }

  .content-shell { gap: 12px; padding-bottom: 12px; }
  .status-card, .build-panel, .final-panel { padding: 19px 16px; border-radius: 18px; }
  .status-head { gap: 16px; }
  .status-head > div:first-child { flex-basis: 100%; }
  .status-title { font-size: 23px; }
  .status-actions { width: 100%; }
  .status-actions .btn { flex: 1 1 auto; }
  .build-panel-title { font-size: 13px; }
  .task-item { padding: 12px; gap: 8px; }
  .task-theme { font-size: 13px; }
  .task-pill { font-size: 8px; padding-inline: 5px; }

  .modal-backdrop { padding: 10px; padding-top: max(10px, env(safe-area-inset-top)); padding-bottom: max(10px, env(safe-area-inset-bottom)); }
  .modal { max-height: calc(var(--viewport) - 20px - env(safe-area-inset-top) - env(safe-area-inset-bottom)); border-radius: 19px; }
  .modal-head { padding: 12px 14px; }
  .modal-title { font-size: 17px; }
  .modal-body { padding: 12px; gap: 12px; }
  .card { padding: 16px; border-radius: 15px; }
  .modal-foot { padding: 12px 14px; }
  .modal-foot .btn { flex: 1; padding-inline: 9px; }
}

@media (max-width: 360px) {
  .mobile-topbar-actions { gap: 4px; }
  .mobile-top-up-btn, .mobile-balance { padding-inline: 7px; }
  .mobile-profile-row .sophia-release small { display: none; }
  .task-item { flex-direction: column; }
  .task-pill { align-self: flex-start; }
}

@media (max-height: 600px) {
  .brand { padding-block: 12px; }
  .menu { gap: 4px; }
  .menu button, .menu a { min-height: 38px; padding-block: 8px; }
  .profile-footer { padding-block: 12px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
  .sophia-release::after { opacity: .35; }
}