:root {
  --bg: #f7f7f3;
  --surface: #ffffff;
  --surface-muted: #f1f2ec;
  --text: #15171a;
  --text-muted: #6b7280;
  --line: rgba(21, 23, 26, 0.08);
  --line-strong: rgba(21, 23, 26, 0.14);
  --cyan: #4fa3b0;
  --lime: #86c33a;
  --lime-deep: #4f7a1a;
  --lime-soft: #e7f4d4;
  --lime-cta: #6f9c33;
  --danger: #e0524f;
  --danger-soft: #fbe7e5;
  --warning: #d99a32;
  --warning-soft: #faedd6;
  --shadow-xs: 0 1px 1px rgba(20, 20, 15, 0.04);
  --shadow-sm: 0 1px 2px rgba(20, 20, 15, 0.05), 0 2px 6px rgba(20, 20, 15, 0.05);
  --shadow-md: 0 2px 4px rgba(20, 20, 15, 0.05), 0 14px 30px -10px rgba(20, 20, 15, 0.16);
  --shadow-lg: 0 4px 10px rgba(20, 20, 15, 0.08), 0 26px 52px -14px rgba(20, 20, 15, 0.22);
  --radius-xl: 22px;
  --radius-lg: 16px;
  --radius-md: 12px;
  --radius-sm: 9px;
  --radius-full: 999px;
  --ease-spring: cubic-bezier(0.34, 1.56, 0.64, 1);
  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121417;
    --surface: #1b1e22;
    --surface-muted: #23262b;
    --text: #f1f3f1;
    --text-muted: #9aa1a6;
    --line: rgba(255, 255, 255, 0.08);
    --line-strong: rgba(255, 255, 255, 0.16);
    --cyan: #7ecbd3;
    --lime: #b7e857;
    --lime-deep: #b7e857;
    --lime-soft: rgba(183, 232, 87, 0.14);
    --lime-cta: #9dc94f;
    --danger: #ef6a6a;
    --danger-soft: rgba(239, 106, 106, 0.14);
    --warning: #e0ac57;
    --warning-soft: rgba(224, 172, 87, 0.14);
    --shadow-xs: 0 1px 1px rgba(0, 0, 0, 0.3);
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3), 0 2px 10px rgba(0, 0, 0, 0.28);
    --shadow-md: 0 2px 4px rgba(0, 0, 0, 0.35), 0 16px 36px -10px rgba(0, 0, 0, 0.55);
    --shadow-lg: 0 6px 14px rgba(0, 0, 0, 0.4), 0 30px 60px -16px rgba(0, 0, 0, 0.65);
  }
}

:root[data-theme="dark"] {
  --bg: #121417;
  --surface: #1b1e22;
  --surface-muted: #23262b;
  --text: #f1f3f1;
  --text-muted: #9aa1a6;
  --line: rgba(255, 255, 255, 0.08);
  --line-strong: rgba(255, 255, 255, 0.16);
  --cyan: #7ecbd3;
  --lime: #b7e857;
  --lime-deep: #b7e857;
  --lime-soft: rgba(183, 232, 87, 0.14);
  --lime-cta: #9dc94f;
  --danger: #ef6a6a;
  --danger-soft: rgba(239, 106, 106, 0.14);
  --warning: #e0ac57;
  --warning-soft: rgba(224, 172, 87, 0.14);
  --shadow-xs: 0 1px 1px rgba(0, 0, 0, 0.3);
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3), 0 2px 10px rgba(0, 0, 0, 0.28);
  --shadow-md: 0 2px 4px rgba(0, 0, 0, 0.35), 0 16px 36px -10px rgba(0, 0, 0, 0.55);
  --shadow-lg: 0 6px 14px rgba(0, 0, 0, 0.4), 0 30px 60px -16px rgba(0, 0, 0, 0.65);
}

:root[data-theme="light"] {
  --bg: #f7f7f3;
  --surface: #ffffff;
  --surface-muted: #f1f2ec;
  --text: #15171a;
  --text-muted: #6b7280;
  --line: rgba(21, 23, 26, 0.08);
  --line-strong: rgba(21, 23, 26, 0.14);
  --cyan: #4fa3b0;
  --lime: #86c33a;
  --lime-deep: #4f7a1a;
  --lime-soft: #e7f4d4;
  --lime-cta: #6f9c33;
  --danger: #e0524f;
  --danger-soft: #fbe7e5;
  --warning: #d99a32;
  --warning-soft: #faedd6;
  --shadow-xs: 0 1px 1px rgba(20, 20, 15, 0.04);
  --shadow-sm: 0 1px 2px rgba(20, 20, 15, 0.05), 0 2px 6px rgba(20, 20, 15, 0.05);
  --shadow-md: 0 2px 4px rgba(20, 20, 15, 0.05), 0 14px 30px -10px rgba(20, 20, 15, 0.16);
  --shadow-lg: 0 4px 10px rgba(20, 20, 15, 0.08), 0 26px 52px -14px rgba(20, 20, 15, 0.22);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(1100px circle at 12% -8%, color-mix(in srgb, var(--lime) 7%, transparent), transparent 60%),
    var(--bg);
  color: var(--text);
  font-family: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
  transition: background-color 0.15s ease, color 0.15s ease;
}

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

.app-shell {
  /* Точка отсчёта для индикатора обновления, который висит НАД контентом.
     ВАЖНО: сюда нельзя добавлять will-change: transform — любой transform
     (в т.ч. заявленный через will-change) делает элемент точкой отсчёта и
     для position: fixed внутри него. Живой баг 2026-08-09: из-за этого
     нижняя панель навигации перестала быть прикреплённой к экрану и ездила
     вместе с содержимым при свайпе. Сама панель теперь вынесена из
     .app-shell в разметке — это защищает и от самого transform во время
     вытягивания, — но добавлять сюда will-change всё равно не нужно. */
  position: relative;
  max-width: 840px;
  min-height: 100vh;
  margin: 0 auto;
  padding: 22px 16px calc(120px + env(safe-area-inset-bottom, 0px));
}

/* Свайп вниз для обновления, в духе iPhone: высота растёт с оттяжкой пальца
   (JS выставляет --pull-rotation и inline height), сама заявка на обновление —
   через уже существующий refreshOffice(). */
/* Индикатор висит НАД контентом и открывается, когда весь экран уезжает
   вниз (см. setupPullToRefresh: двигаем .app-shell через transform).
   Раньше он раздвигал страницу собственной высотой — это заставляло браузер
   пересчитывать раскладку на каждом кадре, отсюда рывки. */
.pull-refresh-indicator {
  position: absolute;
  top: -46px;
  right: 0;
  left: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  height: 40px;
  opacity: 0;
  pointer-events: none;
}

.pull-refresh-spinner {
  width: 24px;
  height: 24px;
  flex: none;
  border-radius: 50%;
  border: 2.5px solid color-mix(in srgb, var(--lime) 30%, transparent);
  border-top-color: var(--lime-cta);
  transform: rotate(var(--pull-rotation, 0deg)) scale(var(--pull-scale, 0.6));
  transition: border-color 0.2s ease;
}

/* Оттянули достаточно — кольцо наливается цветом, это видно боковым зрением
   и заменяет подпись "отпустите для обновления". */
.pull-refresh-indicator.ready .pull-refresh-spinner {
  border-color: color-mix(in srgb, var(--lime-cta) 45%, transparent);
  border-top-color: var(--lime-cta);
}

.pull-refresh-indicator.refreshing .pull-refresh-spinner {
  animation: pull-refresh-spin 0.7s linear infinite;
  transform: scale(1);
}

@keyframes pull-refresh-spin {
  from {
    transform: rotate(0deg) scale(1);
  }
  to {
    transform: rotate(360deg) scale(1);
  }
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 22px;
}

.eyebrow {
  margin: 0 0 3px;
  color: var(--text-muted);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

h1 {
  margin: 0;
  font-size: 27px;
  font-weight: 800;
  letter-spacing: -0.02em;
  line-height: 1.15;
}

h1::after {
  content: "";
  display: inline-block;
  width: 7px;
  height: 7px;
  margin-left: 8px;
  margin-bottom: 4px;
  border-radius: 2px;
  background: var(--lime);
  vertical-align: middle;
}

.avatar {
  display: grid;
  width: 52px;
  height: 52px;
  flex: 0 0 52px;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: var(--surface);
  box-shadow: 0 0 0 3px var(--lime-soft), var(--shadow-sm);
  font-size: 22px;
  font-weight: 700;
  overflow: hidden;
}

.avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.content {
  display: grid;
  gap: 14px;
}

.panel {
  border: 1px solid var(--line);
  border-radius: var(--radius-xl);
  background: var(--surface);
  box-shadow: var(--shadow-sm);
  padding: 18px 18px 20px;
  transition: box-shadow 0.2s var(--ease-out), border-color 0.2s ease;
}

.panel.hero-panel {
  background: linear-gradient(155deg, color-mix(in srgb, var(--lime) 10%, var(--surface)) 0%, var(--surface) 65%);
  box-shadow: var(--shadow-md);
}

.panel h2 {
  margin: 0 0 10px;
  font-size: 15px;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.muted {
  color: var(--text-muted);
}

.row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 0;
  border-top: 1px solid var(--line);
}

.row:first-child {
  border-top: 0;
}

.quick-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.login-plan {
  display: grid;
  gap: 6px;
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid var(--line);
}

.inline-command {
  max-width: 100%;
  margin: 0;
  overflow-x: auto;
  border-radius: var(--radius-sm);
  background: var(--surface-muted);
  padding: 9px 10px;
  font: 12px/1.4 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.segment-toggle {
  display: flex;
  gap: 4px;
  padding: 4px;
  border-radius: var(--radius-full);
  background: var(--surface-muted);
}

.segment-btn {
  display: flex;
  flex: 1;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 36px;
  border: 0;
  border-radius: var(--radius-full);
  background: transparent;
  color: var(--text-muted);
  font-size: 13px;
  font-weight: 700;
  transition: background-color 0.2s var(--ease-out), color 0.2s ease, box-shadow 0.2s var(--ease-out);
}

.segment-btn.active {
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow-xs);
}

.personal-task-list {
  margin-top: 12px;
}

.closed-toggle {
  display: flex;
  width: 100%;
  align-items: center;
  justify-content: space-between;
  border: 0;
  background: transparent;
  padding: 0;
  color: var(--text);
  font-weight: 700;
  font-size: 15px;
}

.closed-toggle-chevron {
  color: var(--text-muted);
  transition: transform 0.2s var(--ease-out);
}

.closed-toggle-chevron.expanded {
  transform: rotate(180deg);
}

.swipe-hint {
  margin-top: 8px;
}

.swipe-list {
  margin-top: 10px;
}

.swipe-row {
  position: relative;
  overflow: hidden;
  border-radius: var(--radius-lg);
}

.swipe-actions {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  display: flex;
}

.swipe-action-restore,
.swipe-action-delete {
  display: grid;
  width: 96px;
  place-items: center;
  padding: 0 8px;
  font-size: 12px;
  font-weight: 700;
  text-align: center;
}

.swipe-action-restore {
  background: var(--lime-cta);
  color: #16210a;
  border-radius: var(--radius-lg) 0 0 var(--radius-lg);
}

.swipe-action-delete {
  background: var(--danger);
  color: #fff;
  border-radius: 0 var(--radius-lg) var(--radius-lg) 0;
}

.swipe-content {
  position: relative;
  touch-action: pan-y;
  will-change: transform;
}

.project-task-segment h2 {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.count-badge {
  display: inline-grid;
  min-width: 24px;
  height: 24px;
  place-items: center;
  border-radius: var(--radius-full);
  background: var(--surface-muted);
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 700;
}

.project-task-list {
  display: grid;
  gap: 10px;
}

.project-task-card {
  display: grid;
  gap: 8px;
  border-radius: var(--radius-lg);
  background: var(--surface-muted);
  border-left: 3px solid transparent;
  padding: 13px 13px 13px 14px;
  transition: box-shadow 0.2s var(--ease-out);
}

.project-task-card.priority-now {
  border-left-color: var(--danger);
}

.project-task-card.priority-normal {
  border-left-color: var(--cyan);
}

.project-task-card.priority-low {
  border-left-color: var(--line-strong);
}

.project-task-card.kind-task {
  border-left-color: var(--lime-cta);
}

.project-task-card.kind-event {
  border-left-color: var(--cyan);
}

.personal-task-edit-card {
  background: var(--surface);
  border: 1px solid var(--line);
}

.personal-task-edit-form {
  display: grid;
  gap: 10px;
}

.project-task-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
}

.project-task-title {
  min-width: 0;
  overflow-wrap: anywhere;
  color: var(--text);
  font-weight: 700;
  line-height: 1.35;
  text-decoration: none;
}

.project-task-title:hover {
  text-decoration: underline;
}

.project-task-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
}

.verify-badge {
  display: inline-flex;
  align-items: center;
  border-radius: var(--radius-full);
  padding: 3px 10px;
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
}

.verify-badge-verified {
  background: var(--lime-soft);
  color: var(--lime-deep);
}

.verify-badge-attested {
  background: var(--surface);
  color: var(--text-muted);
  box-shadow: inset 0 0 0 1px var(--line);
}

.danger-text {
  color: var(--danger);
  word-break: break-word;
}

.chip {
  display: inline-flex;
  align-items: center;
  min-height: 25px;
  border-radius: var(--radius-full);
  padding: 3px 11px;
  background: var(--surface-muted);
  color: var(--text);
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
}

.chip.active,
.chip.assigned,
.chip.completed {
  background: var(--lime-soft);
  color: var(--lime-deep);
}

.chip.unavailable {
  background: var(--surface-muted);
  color: var(--text-muted);
}

.chip.danger {
  background: var(--danger-soft);
  color: var(--danger);
}

.service-chips {
  display: inline-flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 6px;
}

.agent-profile {
  display: flex;
  align-items: center;
  gap: 14px;
}

.agent-profile .avatar {
  width: 96px;
  height: 96px;
  flex-basis: 96px;
}

.metric {
  display: grid;
  gap: 6px;
  margin-top: 9px;
}

.metric-value {
  color: var(--text-muted);
  font-weight: 700;
}

.compact {
  margin: 2px 0 0;
  font-size: 12px;
  line-height: 1.4;
}

.bar {
  height: 8px;
  overflow: hidden;
  border-radius: var(--radius-full);
  background: var(--surface-muted);
}

.bar span {
  display: block;
  height: 100%;
  width: 0;
  border-radius: var(--radius-full);
  background: var(--cyan);
  transition: width 0.3s ease;
}

form {
  display: grid;
  gap: 10px;
}

label {
  display: grid;
  gap: 6px;
  color: var(--text-muted);
  font-size: 13px;
}

input,
textarea,
select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  padding: 11px 12px;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

input:focus,
textarea:focus,
select:focus {
  outline: none;
  border-color: var(--line-strong);
  box-shadow: 0 0 0 3px var(--lime-soft);
}

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

.primary {
  min-height: 48px;
  border: 0;
  border-radius: var(--radius-full);
  background: linear-gradient(180deg, color-mix(in srgb, var(--lime-cta) 92%, white 10%), var(--lime-cta));
  color: #16210a;
  font-weight: 700;
  box-shadow: var(--shadow-sm);
  transition: transform 0.18s var(--ease-spring), box-shadow 0.2s var(--ease-out), filter 0.15s ease;
}

.primary:hover:not(:disabled) {
  box-shadow: var(--shadow-md);
  filter: brightness(1.03);
  transform: translateY(-1px);
}

.primary:active:not(:disabled) {
  transform: scale(0.97);
  box-shadow: var(--shadow-xs);
}

.small-action {
  min-height: 34px;
  border: 1px solid var(--line);
  border-radius: var(--radius-full);
  background: var(--surface);
  color: var(--text);
  padding: 6px 14px;
  font-size: 12px;
  font-weight: 700;
  box-shadow: var(--shadow-xs);
  transition: background-color 0.15s ease, border-color 0.15s ease, box-shadow 0.2s var(--ease-out), transform 0.15s var(--ease-spring);
}

.small-action:hover:not(:disabled) {
  border-color: var(--line-strong);
  box-shadow: var(--shadow-sm);
  transform: translateY(-1px);
}

.small-action:active:not(:disabled) {
  transform: scale(0.96);
  box-shadow: none;
}

.small-action:disabled {
  color: var(--text-muted);
  cursor: wait;
}

.small-action.danger {
  border-color: var(--danger);
  color: var(--danger);
  background: var(--danger-soft);
}

.closed-personal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 8px;
}

.closed-personal-header .swipe-hint {
  margin-top: 0;
}

.bottom-nav {
  /* Плавающая панель с отступом от края (а не приклеена вплотную к низу/бокам
     экрана) — иначе крайние кнопки визуально "заходят" под закруглённые углы
     экрана/зону home-индикатора на iPhone и выглядят обрезанными (2026-08-07). */
  position: fixed;
  right: 12px;
  bottom: calc(12px + env(safe-area-inset-bottom, 0px));
  left: 12px;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 2px;
  max-width: 840px;
  margin: 0 auto;
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: blur(14px) saturate(1.4);
  -webkit-backdrop-filter: blur(14px) saturate(1.4);
  padding: 8px 6px;
  box-shadow: var(--shadow-lg);
}

.bottom-nav button {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  min-height: 52px;
  border: 0;
  border-radius: var(--radius-md);
  background: transparent;
  color: var(--text-muted);
  font-size: 11px;
  font-weight: 600;
  transition: background-color 0.2s var(--ease-out), color 0.2s ease, transform 0.15s var(--ease-spring);
}

.bottom-nav button:active {
  transform: scale(0.93);
}

.bottom-nav .nav-icon {
  display: inline-flex;
  line-height: 1;
}

.bottom-nav .nav-icon svg {
  width: 22px;
  height: 22px;
}

.bottom-nav button.active {
  background: var(--lime-soft);
  color: var(--text);
}

.bottom-nav button.active .nav-icon {
  color: var(--lime-deep);
}

@media (min-width: 900px) {
  .app-shell {
    padding-left: 260px;
  }

  .bottom-nav {
    top: 0;
    right: auto;
    bottom: 0;
    left: 0;
    width: 220px;
    max-width: none;
    margin: 0;
    grid-template-columns: 1fr;
    align-content: start;
    border: 0;
    border-right: 1px solid var(--line);
    border-radius: 0;
    box-shadow: none;
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
  }

  .bottom-nav button {
    flex-direction: row;
    justify-content: flex-start;
    gap: 10px;
    padding-left: 14px;
    font-size: 14px;
  }
}

.refresh-status {
  margin: 6px 0 0;
  color: var(--text-muted);
  font-size: 12px;
}

.social-card h2 {
  color: var(--cyan);
}

@keyframes tj-fade-in {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

/* Память: предложения запомнить — вкладка «Система → Память» */
.conflict-note {
  margin-top: 10px;
  padding: 10px 12px;
  border-radius: 10px;
  background: rgba(255, 176, 32, 0.12);
  border-left: 3px solid rgba(255, 176, 32, 0.6);
  font-size: 13px;
  line-height: 1.5;
}
.memory-actions,
.memory-edit {
  display: flex;
  gap: 8px;
  margin-top: 12px;
  flex-wrap: wrap;
}
.memory-edit { flex-direction: column; }

/* Многострочное поле вместо однострочного. Факты бывают длиннее строки, и в
   узком поле их приходилось править вслепую, прокручивая текст вбок. */
.memory-edit .memory-correction {
  width: 100%;
  min-height: 140px;
  padding: 12px 14px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  font-size: 15px;
  line-height: 1.5;
  font-family: inherit;
  resize: vertical;
  box-sizing: border-box;
}
.memory-edit .memory-correction:focus {
  outline: none;
  border-color: var(--accent, #6366f1);
}
.memory-edit-actions {
  display: flex;
  gap: 8px;
  margin-top: 10px;
  flex-wrap: wrap;
}
.memory-history-row {
  display: flex;
  gap: 10px;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
  font-size: 14px;
  line-height: 1.45;
}
.memory-history-row:last-child { border-bottom: none; }
.memory-history-row .ok { color: var(--ok, #4ade80); }
