/*
 * Вначале читается заголовок архива и действие. Дальше — счётчики,
 * последние задачи и быстрый доступ к образцу. Иллюстрация вторична.
 */
:root {
  color-scheme: light;
  --bg: #f7f7f0;
  --surface: #fffefa;
  --sidebar: #eeefe5;
  --text: #1a2b25;
  --muted: #57695f;
  --line: #dce2d7;
  --soft: #eef2e6;
  --accent: #235342;
  --accent-hover: #194236;
  --on-accent: #fff;
  --accent-soft: #dce9cf;
  --accent-ink: #24513d;
  --lime: #dbefae;
  --focus: #237c56;
  --warning-bg: #f9ecd1;
  --warning-text: #744b15;
  --danger-bg: #fae9e4;
  --danger-text: #8e342a;
  --radius: 16px;
  --font: "Segoe UI Variable", "Segoe UI", system-ui, sans-serif;
}

body.dark {
  color-scheme: dark;
  --bg: #131e1a;
  --surface: #1a2822;
  --sidebar: #16231d;
  --text: #edf3e8;
  --muted: #adbdb1;
  --line: #37493e;
  --soft: #27382d;
  --accent: #cceaa3;
  --accent-hover: #ddf2bf;
  --on-accent: #1c3325;
  --accent-soft: #344a34;
  --accent-ink: #d4edb7;
  --focus: #bfe397;
  --warning-bg: #4a3822;
  --warning-text: #f4d39a;
  --danger-bg: #512e28;
  --danger-text: #ffc0b5;
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 0.9375rem/1.5 var(--font);
}
button, input, select { font: inherit; }
button { color: inherit; cursor: pointer; }
button:disabled { cursor: default; }
button:focus-visible, input:focus-visible, select:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 3px;
}

.app-shell {
  display: grid;
  grid-template-columns: 228px minmax(0, 1fr);
  min-height: 100dvh;
}
.sidebar {
  position: sticky;
  top: 0;
  height: 100dvh;
  padding: 28px 16px 16px;
  border-right: 1px solid var(--line);
  background: var(--sidebar);
  display: flex;
  flex-direction: column;
  gap: 30px;
  overflow-y: auto;
}
.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding-inline: 8px;
  line-height: 1.18;
}
.brand b {
  display: block;
  font-size: 1.19rem;
  letter-spacing: -.035em;
}
.brand b span { color: var(--accent-ink); }
.brand small {
  display: block;
  margin-top: 4px;
  color: var(--muted);
  font-size: .73rem;
}
.brand-mark {
  position: relative;
  display: grid;
  flex: 0 0 42px;
  height: 42px;
  place-items: center;
  border-radius: 13px;
  background: #214939;
}
.brand-mark span {
  width: 24px;
  height: 14px;
  border-radius: 3px 4px 4px 4px;
  background: var(--lime);
  position: relative;
  transform: translateY(2px);
}
.brand-mark span::before {
  position: absolute;
  content: "";
  width: 11px;
  height: 5px;
  left: 0;
  top: -4px;
  border-radius: 3px 3px 0 0;
  background: inherit;
}
.brand-mark span::after {
  position: absolute;
  content: "";
  width: 10px;
  height: 2px;
  right: 4px;
  bottom: 4px;
  border-radius: 2px;
  background: #527a4c;
}
.sidebar nav { display: grid; gap: 5px; }
.nav-item {
  display: flex;
  align-items: center;
  gap: 11px;
  width: 100%;
  min-height: 45px;
  padding: 8px 12px;
  border: 1px solid transparent;
  border-radius: 11px;
  background: transparent;
  color: var(--muted);
  text-align: left;
  font-size: .88rem;
  font-weight: 550;
}
.nav-item:hover { background: var(--soft); color: var(--text); }
.nav-item.active {
  background: var(--accent-soft);
  color: var(--accent-ink);
  font-weight: 700;
}
.nav-icon {
  display: grid;
  place-items: center;
  height: 24px;
  width: 24px;
  font: 1.16rem/1 var(--font);
}
.nav-item em {
  margin-left: auto;
  padding: 1px 7px;
  border: 1px solid var(--line);
  border-radius: 6px;
  font-size: .72rem;
  font-style: normal;
  font-variant-numeric: tabular-nums;
}
.sidebar-bottom { margin-top: auto; }
.account-card {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 11px 9px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
}
.avatar {
  background: var(--accent-soft);
  color: var(--accent-ink);
  width: 31px;
  height: 31px;
  flex: 0 0 31px;
  border-radius: 9px;
  display: grid;
  place-items: center;
  font-weight: 700;
}
.account-details { min-width: 0; }
.account-card strong, .account-card small { display: block; overflow-wrap: anywhere; }
.account-card strong { font-size: .81rem; }
.account-card small { font-size: .71rem; color: var(--muted); }
.account-card button {
  margin-left: auto;
  min-width: 32px;
  min-height: 32px;
  padding: 0;
}
.version {
  color: var(--muted);
  font-size: .72rem;
  margin: 11px 2px 0;
}

.content {
  width: 100%;
  max-width: 1550px;
  margin-inline: auto;
  padding: 27px clamp(22px, 3vw, 51px) 38px;
}
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
  margin-bottom: 23px;
}
.topbar h1 {
  margin: 0;
  font-size: clamp(1.55rem, 2.5vw, 2rem);
  letter-spacing: -.035em;
  line-height: 1.2;
}
.top-actions, .hero-actions {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
}
.connection {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  color: var(--muted);
  font-size: .81rem;
}
.connection i {
  background: #70a758;
  border-radius: 50%;
  width: 8px;
  height: 8px;
  box-shadow: 0 0 0 3px var(--accent-soft);
}
body[data-page="overview"] #connect-btn[data-connected="true"] { display: none; }
.primary, .secondary, .danger, .icon-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  min-height: 42px;
  padding: 8px 14px;
  border: 1px solid transparent;
  border-radius: 10px;
  font-size: .87rem;
  font-weight: 650;
}
.primary { background: var(--accent); color: var(--on-accent); }
.primary:hover:not(:disabled) { background: var(--accent-hover); }
.primary:disabled { background: var(--soft); color: var(--muted); }
.secondary, .icon-button {
  border-color: var(--line);
  background: var(--surface);
  color: var(--text);
}
.secondary:hover, .icon-button:hover { background: var(--soft); }
.danger { background: var(--danger-bg); color: var(--danger-text); }
.icon-button { min-width: 42px; padding: 6px; font-size: 1.06rem; }

.page { display: none; }
.page.active { display: block; }
.hero {
  container-type: inline-size;
  position: relative;
  isolation: isolate;
  display: grid;
  grid-template-columns: minmax(0, 1.55fr) minmax(0, 1fr);
  align-items: center;
  gap: 14px;
  min-height: 282px;
  margin-bottom: 18px;
  overflow: hidden;
  border-radius: 24px;
  background: radial-gradient(ellipse at 93% 25%, #2c5949 0%, transparent 55%), #142f28;
  color: #f8f9f2;
}
.hero-copy {
  z-index: 1;
  padding: clamp(25px, 4vw, 44px);
  padding-right: 0;
}
.hero h2 {
  margin: 0;
  font-size: clamp(2.125rem, 5.7cqi, 4.25rem);
  line-height: .99;
  letter-spacing: -.055em;
  font-weight: 720;
}
.hero h2 span { color: var(--lime); }
.hero p { margin: 16px 0 20px; max-width: 37ch; color: #d2e1d4; }
.hero .primary { background: var(--lime); color: #172f24; }
.hero .primary:hover { background: #e6f5c5; }
.hero .secondary { color: #f3f8ee; background: transparent; border-color: #829d8b; }
.hero .secondary:hover { background: #274a3d; }
.hero button:focus-visible { outline-color: var(--lime); }

.hero-art {
  display: grid;
  align-self: stretch;
  place-items: center;
  min-width: 0;
  overflow: hidden;
  background-image: radial-gradient(#9cb5a440 1px, transparent 1px);
  background-size: 18px 18px;
  mask-image: linear-gradient(90deg, transparent, #000 15%, #000);
}
.archive-illustration {
  position: relative;
  width: min(100%, 320px);
  aspect-ratio: 1.28;
  container-type: inline-size;
}
.art-orbit, .art-orbit::after {
  position: absolute;
  border: 1px solid #a8c3a54d;
  border-radius: 50%;
}
.art-orbit {
  inset: 13% 5%;
  transform: rotate(-21deg);
}
.art-orbit::after { content: ""; inset: 11%; }
.art-spark { position: absolute; color: #d7eda9; line-height: 1; }
.art-spark-top { right: 11%; top: 14%; font-size: 1.6rem; }
.art-spark-bottom { left: 11%; bottom: 14%; font-size: .95rem; }
.art-folder {
  position: absolute;
  inset: 20% 15% 16% 18%;
  transform: rotate(-11deg);
  filter: drop-shadow(0 14px 19px #0c251d99);
}
.folder-back {
  position: absolute;
  inset: 29% 2% 3% 0;
  background: #90b77e;
  border-radius: 9px 10px 14px 14px;
}
.folder-back::before {
  content: "";
  position: absolute;
  top: -16%;
  left: 0;
  width: 41%;
  height: 22%;
  border-radius: 8px 13px 0 0;
  background: inherit;
}
.folder-sheet {
  position: absolute;
  border-radius: 7px;
  box-shadow: 0 3px 9px #1a422c26;
}
.folder-sheet-back {
  inset: 6% 10% 21% 32%;
  background: #a9cf98;
  transform: rotate(11deg);
}
.folder-sheet-front {
  inset: 0 22% 22% 17%;
  transform: rotate(-4deg);
  background: #f5f7df;
}
.folder-sheet-front span {
  display: block;
  width: 51%;
  height: 4px;
  margin: 16% 0 0 13%;
  border-radius: 3px;
  background: #42694b;
  box-shadow: 0 10px 0 #c3d2b3, 0 20px 0 #c3d2b3;
}
.folder-front {
  display: flex;
  align-items: end;
  position: absolute;
  padding: 0 0 9% 10%;
  inset: 44% 0 0 1%;
  transform: skew(-6deg);
  border: 1px solid #e2f3c0;
  border-radius: 9px 10px 15px 15px;
  background: linear-gradient(160deg, #e8f5c2, #a5cc87);
}
.folder-label {
  display: flex;
  gap: 4px;
  align-items: center;
  height: 19%;
  width: 31%;
  padding-inline: 6%;
  border-radius: 3px;
  background: #f5f7df;
}
.folder-label i { flex: 1; height: 55%; background: #54784e; opacity: .8; }

.stats {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
  margin-bottom: 18px;
}
.stat, .panel, .form-card, .feature {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}
.stat {
  position: relative;
  display: grid;
  gap: 3px;
  padding: 14px 16px;
  text-align: left;
}
.stat:hover { border-color: var(--focus); }
.stat-label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: .85rem;
  font-weight: 650;
  padding-right: 15px;
}
.stat-icon, .chat-icon, .empty-icon {
  display: grid;
  flex: 0 0 auto;
  place-items: center;
  width: 31px;
  height: 31px;
  border-radius: 8px;
  background: var(--soft);
  color: var(--accent-ink);
  font: 1.05rem/1 var(--font);
}
.stat-value {
  font-size: 1.8rem;
  line-height: 1.12;
  font-weight: 660;
  letter-spacing: -.045em;
  font-variant-numeric: tabular-nums;
}
.stat-note { color: var(--muted); font-size: .77rem; }
.stat-arrow { position: absolute; top: 15px; right: 15px; color: var(--muted); }
.grid-two, .settings-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.38fr) minmax(0, 1fr);
  gap: 14px;
}
.panel, .form-card { padding: 18px; }
.panel h3, .form-card h3 { margin: 0 0 12px; font-size: 1rem; }
.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 6px 10px;
  margin-bottom: 8px;
}
.panel-head h3 { margin: 0; }
.link-btn {
  padding: 5px 3px;
  border: 0;
  background: transparent;
  color: var(--accent-ink);
  border-radius: 5px;
  font-size: .83rem;
  font-weight: 650;
}
.link-btn:hover { text-decoration: underline; }
.empty { padding: 23px 8px; color: var(--muted); text-align: center; }
.empty-icon { margin: 0 auto 8px; width: 40px; height: 40px; font-size: 1.28rem; }
.empty small { display: block; margin-top: 3px; }
.activity-empty {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-top: 11px;
  padding: 16px;
  min-height: 91px;
  border: 1px dashed var(--line);
  border-radius: 11px;
  text-align: left;
}
.activity-empty .empty-icon { margin: 0; }
.activity-empty strong { color: var(--text); font-size: .88rem; }
.quick-row, .source-row, .task-row, .archive-row {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  padding: 10px 0;
  border-top: 1px solid var(--line);
}
.quick-row, .task-row:first-child, .archive-row:first-child { border-top: 0; }
.quick-row {
  width: 100%;
  border: 0;
  border-radius: 9px;
  background: transparent;
  padding: 7px;
  text-align: left;
}
.quick-row:hover { background: var(--soft); }
.quick-arrow { color: var(--muted); }
.row-main { min-width: 0; flex: 1; overflow-wrap: anywhere; }
.row-main strong { display: block; font-size: .87rem; }
.row-main small { display: block; color: var(--muted); font-size: .77rem; }
.pill {
  border-radius: 20px;
  padding: 4px 8px;
  background: var(--soft);
  color: var(--muted);
  font-size: .72rem;
}
.pill.green { background: var(--accent-soft); color: var(--accent-ink); }
.pill.amber { background: var(--warning-bg); color: var(--warning-text); }
.section-title, .toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 15px;
}
.section-title h2 { margin: 0 0 3px; font-size: 1.13rem; }
.toolbar { justify-content: flex-start; }
.search, .filter, .field input, .field select {
  min-width: 0;
  padding: 9px 12px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: var(--surface);
  color: var(--text);
}
.search { width: min(100%, 320px); }
.table-panel { overflow-x: auto; }
.table-head, .table-row {
  display: grid;
  grid-template-columns: minmax(160px, 2fr) repeat(3, minmax(88px, 1fr)) minmax(105px, auto);
  align-items: center;
  gap: 13px;
  min-width: 575px;
  padding: 13px 0;
  border-bottom: 1px solid var(--line);
  font-size: .82rem;
}
.table-head { color: var(--muted); padding-top: 0; }
.table-row:last-child { border-bottom: 0; }
.table-row > div { overflow-wrap: anywhere; }
.table-row small { display: block; }
.settings-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.field { margin-bottom: 14px; }
.field label { display: block; margin-bottom: 5px; font-size: .86rem; font-weight: 650; }
.field input, .field select { width: 100%; }
.help { color: var(--muted); font-size: .81rem; }
.toggle-line { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 8px 0; }
.switch {
  position: relative;
  width: 36px;
  height: 20px;
  flex: 0 0 36px;
  border-radius: 20px;
  background: #78897d;
}
.switch::after {
  position: absolute;
  content: "";
  width: 14px;
  height: 14px;
  top: 3px;
  left: 3px;
  background: white;
  border-radius: 50%;
}
.switch.on { background: #367446; }
.switch.on::after { left: 19px; }
.toast {
  position: fixed;
  inset: 18px 18px auto auto;
  z-index: 12;
  max-width: min(390px, calc(100% - 36px));
  padding: 10px 14px;
  border-radius: 10px;
  background: var(--text);
  color: var(--surface);
  opacity: 0;
  pointer-events: none;
}
.toast.show { opacity: 1; }
.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: grid;
  place-items: center;
  padding: 14px;
  background: #12251ebb;
}
.modal {
  width: min(500px, 100%);
  max-height: calc(100dvh - 28px);
  overflow: auto;
  padding: clamp(18px, 4vw, 28px);
  border: 1px solid var(--line);
  border-radius: 18px;
  background: var(--surface);
  box-shadow: 0 20px 54px #101e1890;
}
.modal h2 { margin: 0 32px 6px 0; font-size: 1.35rem; letter-spacing: -.025em; }
.modal p { margin: 0 0 16px; color: var(--muted); font-size: .86rem; }
.modal-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 10px; margin-top: 18px; }
.close {
  float: right;
  width: 33px;
  height: 33px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  font-size: 1.14rem;
}
.close:hover { background: var(--soft); }

.transfer-dialog {
  width: min(750px, calc(100% - 28px));
  color: var(--text);
}
.transfer-dialog::backdrop { background: #12251ecc; }
.chat-picker-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  margin: 16px 0;
}
.chat-picker, .transfer-pair > div, .transfer-preview {
  min-width: 0;
  margin: 0;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
}
.chat-picker legend {
  padding: 0 5px;
  color: var(--accent-ink);
  font-weight: 700;
}
.chat-picker > p { min-height: 2.6em; margin-bottom: 10px; }
.chat-picker .picker-select { margin-bottom: 0; }
.transfer-dialog .transfer-hint { font-size: .8rem; }
.transfer-date { padding: 11px 14px; border: 1px solid var(--line); border-radius: 12px; }
.transfer-date input { width: min(210px, 100%); }
.transfer-date .help { margin: 6px 0 0; }
.transfer-tools { display: flex; flex-wrap: wrap; gap: 8px 14px; }
.transfer-dialog .transfer-error, .transfer-dialog .transfer-note {
  margin: 12px 0 0;
  padding: 9px 11px;
  border-radius: 8px;
  background: var(--warning-bg);
  color: var(--warning-text);
}
.transfer-pair > div { background: var(--soft); overflow-wrap: anywhere; }
.transfer-pair span, .transfer-pair strong, .transfer-pair small { display: block; }
.transfer-pair span, .transfer-pair small { color: var(--muted); font-size: .78rem; }
.transfer-preview { margin-bottom: 14px; }
.transfer-preview summary { cursor: pointer; font-weight: 650; }
.transfer-preview ol { max-height: 150px; overflow: auto; margin: 8px 0 0; padding-left: 26px; }
.transfer-preview li { padding: 3px 6px 3px 1px; font-size: .87rem; overflow-wrap: anywhere; }
.transfer-preview .pill { margin-left: 7px; }
.topic-plan { max-height: 150px; overflow: auto; margin: 8px 0 0; padding: 0; list-style: none; }
.topic-plan li { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 3px 12px; }
.topic-plan li + li { border-top: 1px solid var(--line); }
.topic-plan span { color: var(--muted); }
.transfer-task {
  width: 100%;
  border-right: 0;
  border-bottom: 0;
  border-left: 0;
  background: transparent;
  padding: 10px 6px;
  text-align: left;
}
.transfer-task:hover { background: var(--soft); }
.pair-arrow { color: var(--accent-ink); }

.auth-dialog { width: min(500px, calc(100% - 28px)); }
.auth-method {
  display: flex;
  flex-wrap: wrap;
  gap: 9px;
  min-width: 0;
  margin: 15px 0;
  padding: 8px 12px 12px;
  border: 1px solid var(--line);
  border-radius: 11px;
}
.auth-method legend { padding: 0 5px; color: var(--muted); font-size: .82rem; }
.auth-method label {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 9px;
  border-radius: 7px;
  cursor: pointer;
}
.auth-method label:has(:checked) { background: var(--accent-soft); color: var(--accent-ink); }
.auth-method input { accent-color: var(--accent); margin: 0; }
.telegram-qr { display: grid; place-items: center; margin-block: 12px; }
.telegram-qr img { width: min(230px, 100%); height: auto; image-rendering: pixelated; }
.auth-dialog #qr-status { text-align: center; }

.login-page {
  display: grid;
  min-height: 100dvh;
  place-items: center;
  padding: 20px;
  background: radial-gradient(ellipse at 85% 5%, #dce9cf, transparent 55%), var(--bg);
}
.login-card {
  width: min(100%, 410px);
  padding: clamp(22px, 6vw, 36px);
  border: 1px solid var(--line);
  border-radius: 22px;
  background: var(--surface);
  box-shadow: 0 14px 42px #29473316;
}
.login-card .brand { padding: 0; }
.login-card h1 { margin: 25px 0 21px; font-size: 1.65rem; letter-spacing: -.035em; }
.login-card button { width: 100%; margin-top: 6px; }
.login-error { padding: 8px 10px; border-radius: 8px; background: var(--danger-bg); color: var(--danger-text); }

@media (max-width: 1024px) {
  .app-shell { grid-template-columns: 194px minmax(0, 1fr); }
  .sidebar { padding-inline: 12px; }
}
@media (max-width: 760px) {
  .app-shell { display: block; }
  .sidebar { position: static; height: auto; overflow: visible; gap: 13px; padding: 14px 14px 8px; border-right: 0; border-bottom: 1px solid var(--line); }
  .sidebar nav { display: flex; flex-wrap: wrap; gap: 3px; }
  .nav-item { width: auto; min-height: 36px; padding: 5px 8px; gap: 6px; }
  .nav-icon { height: 20px; width: 18px; }
  .sidebar-bottom { display: none; }
  .sidebar-bottom:has(#logout-btn:not([hidden])) { display: block; }
  .sidebar-bottom .version { display: none; }
  .content { padding: 17px 15px 28px; }
  .topbar { margin-bottom: 16px; }
}
@media (max-width: 560px) {
  .hero { grid-template-columns: minmax(0, 1fr); min-height: 0; }
  .hero-copy { padding: 24px 20px 26px; }
  .hero h2 { font-size: clamp(1.95rem, 8.5cqi, 2.75rem); }
  .hero-art { display: none; }
  .hero p { margin: 12px 0 15px; }
  .stats { gap: 6px; }
  .stat { padding: 9px 8px; }
  .stat-label { display: block; padding-right: 0; font-size: .79rem; }
  .stat-icon { margin-bottom: 5px; }
  .stat-note { font-size: .69rem; }
  .stat-arrow { right: 8px; top: 10px; }
  .grid-two, .settings-grid { grid-template-columns: minmax(0, 1fr); }
  .panel, .form-card { padding: 13px; }
  .chat-picker-grid { grid-template-columns: minmax(0, 1fr); }
  .chat-picker > p { min-height: 0; }
}
@media (forced-colors: active) {
  .hero-art, .brand-mark { display: none; }
  .hero, .nav-item.active, .stat { border: 1px solid ButtonText; }
}
