/* =========================================================
   Shell · topbar / sidebar / main
   ========================================================= */
.app {
  position: relative;
  z-index: 1;
  display: grid;
  grid-template-columns: var(--sidebar-w) minmax(0, 1fr);
  grid-template-rows: var(--topbar-h) minmax(0, 1fr);
  height: 100vh;
  height: 100dvh;
  opacity: 0;
}
body.boot-ready .app { animation: app-in .7s var(--ease-out) forwards; }
@keyframes app-in { from { opacity: 0; transform: scale(.994); } to { opacity: 1; transform: none; } }

.topbar {
  grid-column: 1 / -1;
  grid-row: 1;
  display: flex;
  align-items: center;
  min-width: 0;
  border-bottom: 1px solid var(--line);
  background: color-mix(in srgb, var(--surface) 82%, transparent);
  backdrop-filter: blur(18px) saturate(1.15);
  -webkit-backdrop-filter: blur(18px) saturate(1.15);
  z-index: 30;
}
.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  width: var(--sidebar-w);
  height: 100%;
  padding: 0 18px;
  flex: 0 0 auto;
  border-right: 1px solid var(--line);
}
.brand-mark {
  position: relative;
  display: grid;
  place-items: center;
  width: 31px;
  height: 31px;
  border-radius: 9px;
  background: linear-gradient(145deg, var(--primary-2), var(--primary) 55%, var(--primary-deep));
  color: #fff;
  box-shadow: 0 6px 14px -8px rgba(15, 174, 147, .7), inset 0 1px 0 rgba(255,255,255,.28);
  flex: 0 0 auto;
}
.brand-mark::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  box-shadow: inset 0 0 0 1px rgba(255,255,255,.14);
}
.brand-mark svg { width: 18px; height: 18px; }
.brand-mark--xl { width: 66px; height: 66px; border-radius: 19px; box-shadow: 0 18px 38px -18px rgba(15,174,147,.6); }
.brand-mark--xl svg { width: 34px; height: 34px; }
.brand-type { display: flex; flex-direction: column; min-width: 0; line-height: 1.15; }
.brand-type strong { font-size: 14.5px; font-weight: 750; letter-spacing: -.035em; }
.brand-type em { font-style: normal; font-size: 10px; color: var(--text-3); letter-spacing: .02em; margin-top: 2px; white-space: nowrap; }

.crumb {
  display: flex;
  align-items: center;
  gap: 9px;
  padding-left: 22px;
  font-size: 12.5px;
  color: var(--text-3);
  min-width: 0;
}
.crumb i { font-style: normal; opacity: .55; }
.crumb strong { font-weight: 600; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.top-actions { margin-left: auto; display: flex; align-items: center; gap: 2px; padding-right: 12px; }
.clock {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  justify-content: center;
  min-width: 126px;
  padding: 0 18px 0 8px;
  margin-right: 4px;
  user-select: none;
}
.clock strong {
  font-family: var(--font-mono);
  font-size: 20px;
  line-height: 1.05;
  font-weight: 650;
  letter-spacing: -.015em;
  font-variant-numeric: tabular-nums;
}
.clock span {
  margin-top: 3px;
  font-size: 10px;
  color: var(--text-3);
  letter-spacing: .01em;
  font-variant-numeric: tabular-nums;
}
.clock::after {
  content: "";
  position: absolute;
  right: 19px;
  bottom: 7px;
  width: 24px;
  height: 2px;
  border-radius: 3px;
  background: var(--primary);
  opacity: .72;
}
.ready {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 0 11px;
  font-size: 11.5px;
  color: var(--text-2);
  white-space: nowrap;
}
.ready i { width: 6px; height: 6px; border-radius: 50%; background: var(--primary); animation: pulse-dot 2.8s infinite; }
.task-toggle { margin-right: 1px; }
.task-badge {
  position: absolute;
  top: 3px;
  right: 3px;
  min-width: 16px;
  height: 16px;
  padding: 0 4px;
  border-radius: 8px;
  background: var(--primary);
  color: #fff;
  border: 2px solid var(--surface);
  font-size: 9px;
  font-style: normal;
  font-weight: 700;
  line-height: 12px;
  text-align: center;
  font-variant-numeric: tabular-nums;
}
.task-badge.is-busy { background: var(--violet); }

.sidebar {
  grid-column: 1;
  grid-row: 2;
  display: flex;
  flex-direction: column;
  min-height: 0;
  padding: 20px 12px 14px;
  border-right: 1px solid var(--line);
  background: color-mix(in srgb, var(--surface) 55%, transparent);
  z-index: 20;
}
.side-label {
  padding: 0 12px 9px;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: .16em;
  text-transform: uppercase;
  color: var(--text-3);
}
.side-nav { display: flex; flex-direction: column; gap: 3px; }
.side-item {
  position: relative;
  display: flex;
  align-items: center;
  gap: 11px;
  width: 100%;
  height: 43px;
  padding: 0 12px;
  border-radius: 9px;
  color: var(--text-2);
  font-size: 13px;
  font-weight: 550;
  text-align: left;
  transition: background .18s, color .18s, transform .18s, box-shadow .18s;
}
.side-item:hover { background: var(--surface-2); color: var(--text); }
.side-item:active { transform: scale(.99); }
.side-item.is-active {
  background: linear-gradient(100deg, var(--primary) 0%, var(--primary-2) 100%);
  color: #fff;
  box-shadow: 0 10px 22px -14px rgba(15,174,147,.8), inset 0 1px 0 rgba(255,255,255,.18);
}
.side-icon { display: grid; place-items: center; width: 20px; height: 20px; flex: 0 0 auto; opacity: .9; }
.side-icon .icon { width: 19px; height: 19px; }
.side-text { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.side-count {
  min-width: 19px;
  height: 18px;
  padding: 0 5px;
  border-radius: 6px;
  background: var(--surface-3);
  color: var(--text-2);
  font-size: 10px;
  font-weight: 650;
  line-height: 18px;
  text-align: center;
  font-variant-numeric: tabular-nums;
}
.side-item.is-active .side-count { background: rgba(255,255,255,.22); color: #fff; }
.side-spacer { flex: 1; }
.side-local {
  display: flex;
  align-items: flex-start;
  gap: 9px;
  margin: 10px 4px 12px;
  padding: 11px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface-2);
}
.side-local-icon { color: var(--primary); display: grid; place-items: center; padding-top: 1px; }
.side-local-icon .icon { width: 15px; height: 15px; }
.side-local div { min-width: 0; }
.side-local strong { display: block; font-size: 11.5px; font-weight: 650; }
.side-local em { display: block; margin-top: 2px; font-style: normal; font-size: 10px; color: var(--text-3); line-height: 1.45; }
.side-version {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 8px;
  font-family: var(--font-mono);
  font-size: 8.5px;
  letter-spacing: .08em;
  color: var(--text-3);
}
.side-version em { font-style: normal; opacity: .8; }

.main {
  grid-column: 2;
  grid-row: 2;
  position: relative;
  min-width: 0;
  min-height: 0;
  overflow: auto;
  overscroll-behavior: contain;
  scroll-behavior: smooth;
}
.main-inner {
  width: 100%;
  max-width: var(--main-max);
  margin: 0 auto;
  padding: 25px 30px 38px;
}
.view { animation: page-in .34s var(--ease-out) both; }
.view.is-leaving { animation: page-out .14s ease both; }
@keyframes page-in { from { opacity: 0; transform: translateY(9px); } to { opacity: 1; transform: none; } }
@keyframes page-out { to { opacity: 0; transform: translateY(-4px); } }

.page-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 24px;
  margin-bottom: 18px;
}
.page-head-copy { min-width: 0; }
.eyebrow {
  display: flex;
  align-items: center;
  gap: 7px;
  margin-bottom: 7px;
  font-family: var(--font-mono);
  font-size: 9.5px;
  font-weight: 600;
  letter-spacing: .13em;
  color: var(--primary-ink);
  text-transform: uppercase;
}
.eyebrow::before { content: ""; width: 14px; height: 1px; background: currentColor; opacity: .7; }
.page-head h1 {
  font-size: 27px;
  line-height: 1.16;
  font-weight: 720;
  letter-spacing: -.045em;
}
.page-head p {
  margin-top: 6px;
  max-width: 610px;
  color: var(--text-2);
  font-size: 12.5px;
  line-height: 1.65;
}
.page-actions { display: flex; align-items: center; gap: 9px; flex-wrap: wrap; padding-bottom: 2px; }

/* =========================================================
   Boot animation
   ========================================================= */
.boot {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: grid;
  place-items: center;
  background:
    radial-gradient(ellipse 55% 48% at 50% 45%, color-mix(in srgb, var(--primary) 8%, transparent), transparent 70%),
    var(--bg);
  transition: opacity .5s var(--ease), visibility .5s;
}
.boot.is-hidden { opacity: 0; visibility: hidden; pointer-events: none; }
.boot-grid {
  position: absolute;
  inset: 0;
  background-image:
    linear-gradient(var(--grid-line) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid-line) 1px, transparent 1px);
  background-size: 56px 56px;
  mask-image: radial-gradient(ellipse 55% 55% at 50% 48%, #000, transparent 78%);
  -webkit-mask-image: radial-gradient(ellipse 55% 55% at 50% 48%, #000, transparent 78%);
  opacity: .75;
}
.boot-core {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  width: min(360px, calc(100vw - 48px));
  text-align: center;
  margin-top: -4vh;
}
.boot-mark { opacity: 0; animation: boot-mark .7s .22s var(--ease-out) forwards; }
.boot-mark .brand-mark { animation: boot-breathe 2.4s 1s ease-in-out infinite; }
@keyframes boot-mark { from { opacity: 0; transform: translateY(9px) scale(.92); } to { opacity: 1; transform: none; } }
@keyframes boot-breathe { 0%,100% { box-shadow: 0 18px 38px -18px rgba(15,174,147,.55); } 50% { box-shadow: 0 18px 60px -16px rgba(15,174,147,.78); } }
.boot-word {
  display: flex;
  margin-top: 19px;
  font-size: 34px;
  font-weight: 730;
  letter-spacing: -.065em;
  line-height: 1;
  color: var(--text);
}
.boot-word span { opacity: 0; transform: translateY(8px); animation: boot-letter .38s var(--ease-out) forwards; }
.boot-word span:nth-child(1) { animation-delay: .5s; }
.boot-word span:nth-child(2) { animation-delay: .54s; }
.boot-word span:nth-child(3) { animation-delay: .58s; }
.boot-word span:nth-child(4) { animation-delay: .62s; color: var(--primary); }
.boot-word span:nth-child(5) { animation-delay: .66s; }
.boot-word span:nth-child(6) { animation-delay: .7s; }
.boot-word span:nth-child(7) { animation-delay: .74s; }
@keyframes boot-letter { to { opacity: 1; transform: none; } }
.boot-name { margin-top: 8px; font-size: 12px; font-weight: 550; letter-spacing: .22em; color: var(--text-2); opacity: 0; animation: fade-up .5s .9s var(--ease-out) forwards; }
.boot-tag { display: flex; align-items: center; gap: 7px; margin-top: 17px; font-size: 10.5px; color: var(--text-3); opacity: 0; animation: fade-up .5s 1.08s var(--ease-out) forwards; }
.boot-tag i { width: 3px; height: 3px; border-radius: 50%; background: var(--text-3); }
.boot-progress {
  width: 158px;
  height: 2px;
  margin-top: 26px;
  border-radius: 2px;
  background: var(--line);
  overflow: hidden;
}
.boot-progress i { display: block; width: 100%; height: 100%; background: linear-gradient(90deg, var(--primary), var(--primary-2)); transform-origin: left; animation: boot-load 1.55s .45s var(--ease) both; }
@keyframes boot-load { from { transform: scaleX(0); } to { transform: scaleX(1); } }
.boot-skip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-top: 18px;
  padding: 5px 8px;
  border-radius: 6px;
  font-size: 10px;
  color: var(--text-3);
  opacity: 0;
  animation: fade-in .4s 1.25s forwards;
  transition: color .18s, background .18s;
}
.boot-skip:hover { color: var(--text); background: var(--surface-2); }
.boot-skip kbd { border-color: var(--line-strong); }
.boot-foot {
  position: absolute;
  bottom: 23px;
  left: 27px;
  right: 27px;
  display: flex;
  justify-content: space-between;
  font-family: var(--font-mono);
  font-size: 8.5px;
  letter-spacing: .13em;
  color: var(--text-3);
  opacity: .8;
}
.boot-foot span { color: var(--primary); }

/* =========================================================
   Task queue panel
   ========================================================= */
.task-panel {
  position: fixed;
  z-index: 90;
  top: calc(var(--topbar-h) + 8px);
  right: 16px;
  width: 374px;
  max-width: calc(100vw - 24px);
  max-height: min(560px, calc(100vh - var(--topbar-h) - 24px));
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: var(--shadow-lg);
  overflow: hidden;
  animation: pop-in .2s var(--ease-out);
}
.task-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 13px 14px 11px; border-bottom: 1px solid var(--line); }
.task-head strong { display: block; font-size: 13px; font-weight: 650; }
.task-head span { display: block; margin-top: 2px; font-size: 10.5px; color: var(--text-3); }
.task-list { overflow: auto; padding: 6px; min-height: 52px; }
.task-row { display: grid; grid-template-columns: 27px minmax(0,1fr) auto; gap: 9px; align-items: start; padding: 9px 8px; border-radius: 8px; }
.task-row:hover { background: var(--surface-2); }
.task-ico { width: 27px; height: 27px; border-radius: 7px; display: grid; place-items: center; background: var(--surface-3); color: var(--text-2); }
.task-ico .icon { width: 14px; height: 14px; }
.task-row.is-running .task-ico { background: var(--primary-soft); color: var(--primary); }
.task-row.is-done .task-ico { background: var(--primary-soft); color: var(--primary); }
.task-row.is-failed .task-ico { background: var(--danger-soft); color: var(--danger); }
.task-main { min-width: 0; padding-top: 1px; }
.task-main strong { display: block; font-size: 11.5px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.task-main em { display: block; margin-top: 2px; font-style: normal; font-size: 10px; color: var(--text-3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.task-state { font-size: 9.5px; color: var(--text-3); padding-top: 4px; white-space: nowrap; font-variant-numeric: tabular-nums; display: flex; align-items: center; gap: 4px; }
.task-row.is-running .task-state { color: var(--primary-ink); }
.task-row.is-failed .task-state { color: var(--danger); }
.task-act { width: 18px; height: 18px; border: 0; padding: 0; border-radius: 5px; display: grid; place-items: center; background: transparent; color: var(--text-3); cursor: pointer; }
.task-act:hover { background: var(--surface-3); color: var(--text); }
.task-act .icon { width: 12px; height: 12px; }
.task-bar { grid-column: 2 / -1; height: 3px; border-radius: 3px; background: var(--surface-3); overflow: hidden; margin-top: 3px; }
.task-bar i { display: block; height: 100%; border-radius: inherit; background: linear-gradient(90deg, var(--primary), var(--primary-2)); transition: width .25s var(--ease); }
.task-row.is-failed .task-bar i { background: var(--danger); }
.task-empty { padding: 24px 12px; text-align: center; color: var(--text-3); font-size: 11.5px; }
.task-foot { display: flex; align-items: center; gap: 5px; padding: 9px 14px; border-top: 1px solid var(--line); background: var(--surface-2); color: var(--text-3); font-size: 9.5px; }
.task-foot .icon { width: 12px; height: 12px; }

/* =========================================================
   Modal
   ========================================================= */
.modal-root:empty { display: none; }
.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 120;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(9, 15, 21, .38);
  backdrop-filter: blur(7px);
  -webkit-backdrop-filter: blur(7px);
  animation: fade-in .18s ease;
}
html[data-theme="night"] .modal-backdrop { background: rgba(0, 0, 0, .55); }
.modal {
  width: min(520px, 100%);
  max-height: min(86vh, 780px);
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: var(--shadow-lg);
  animation: modal-in .26s var(--ease-out);
  overflow: hidden;
}
@keyframes modal-in { from { opacity: 0; transform: translateY(12px) scale(.985); } to { opacity: 1; transform: none; } }
.modal.is-wide { width: min(760px, 100%); }
.modal.is-xwide { width: min(920px, 100%); }
.modal-head { display: flex; align-items: flex-start; gap: 14px; padding: 19px 20px 15px; border-bottom: 1px solid var(--line); }
.modal-head-copy { flex: 1; min-width: 0; }
.modal-head h2 { font-size: 16px; font-weight: 680; letter-spacing: -.025em; }
.modal-head p { margin-top: 3px; color: var(--text-3); font-size: 11.5px; line-height: 1.55; }
.modal-close { margin: -4px -5px 0 0; flex: 0 0 auto; }
.modal-body { padding: 19px 20px; overflow: auto; }
.modal-body.is-flush { padding: 0; }
.modal-foot { display: flex; justify-content: flex-end; align-items: center; gap: 9px; padding: 13px 20px; border-top: 1px solid var(--line); background: var(--surface-2); }
.modal-foot .foot-note { margin-right: auto; color: var(--text-3); font-size: 10.5px; }

.settings-group { display: flex; flex-direction: column; gap: 2px; }
.settings-row { display: flex; align-items: center; gap: 16px; padding: 13px 0; border-bottom: 1px solid var(--line); }
.settings-row:last-child { border-bottom: 0; padding-bottom: 2px; }
.settings-copy { flex: 1; min-width: 0; }
.settings-copy strong { display: block; font-size: 12.5px; font-weight: 600; }
.settings-copy span { display: block; margin-top: 2px; color: var(--text-3); font-size: 11px; line-height: 1.55; }
.theme-choice { display: inline-flex; padding: 3px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface-2); gap: 2px; }
.theme-choice button { display: flex; align-items: center; gap: 5px; height: 28px; padding: 0 9px; border-radius: 6px; font-size: 11px; color: var(--text-2); }
.theme-choice button .icon { width: 14px; height: 14px; }
.theme-choice button.is-on { background: var(--surface); color: var(--text); box-shadow: 0 1px 3px rgba(0,0,0,.08); }

.help-steps { display: grid; gap: 10px; }
.help-step { display: flex; gap: 12px; padding: 13px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface-2); }
.help-step-num { flex: 0 0 auto; width: 24px; height: 24px; border-radius: 7px; display: grid; place-items: center; background: var(--primary-soft); color: var(--primary-ink); font-family: var(--font-mono); font-size: 11px; font-weight: 700; }
.help-step strong { display: block; font-size: 12px; font-weight: 600; }
.help-step p { margin-top: 2px; font-size: 11px; line-height: 1.6; color: var(--text-2); }
.help-note { display: flex; gap: 8px; margin-top: 14px; padding: 11px 12px; border-radius: 9px; background: var(--primary-soft); color: var(--primary-ink); font-size: 10.5px; line-height: 1.6; }
.help-note .icon { width: 14px; height: 14px; margin-top: 1px; }

/* =========================================================
   Toasts
   ========================================================= */
.toast-root {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 200;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 8px;
  pointer-events: none;
}
.toast {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  width: min(340px, calc(100vw - 28px));
  padding: 11px 13px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
  box-shadow: var(--shadow-md);
  pointer-events: auto;
  animation: toast-in .28s var(--ease-out);
}
.toast.is-out { animation: toast-out .22s ease forwards; }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px) scale(.98); } to { opacity: 1; transform: none; } }
@keyframes toast-out { to { opacity: 0; transform: translateY(6px); } }
.toast-ico { flex: 0 0 auto; width: 24px; height: 24px; border-radius: 7px; display: grid; place-items: center; background: var(--primary-soft); color: var(--primary); }
.toast-ico .icon { width: 14px; height: 14px; }
.toast.is-error .toast-ico { background: var(--danger-soft); color: var(--danger); }
.toast.is-info .toast-ico { background: var(--blue-soft); color: var(--blue); }
.toast-copy { flex: 1; min-width: 0; padding-top: 1px; }
.toast-copy strong { display: block; font-size: 11.5px; font-weight: 650; }
.toast-copy p { margin-top: 1px; color: var(--text-2); font-size: 10.5px; line-height: 1.55; word-break: break-word; }
.toast-x { color: var(--text-3); padding: 2px; margin: -2px -2px 0 0; }
.toast-x .icon { width: 13px; height: 13px; }

/* Progress */
.progress-track { height: 5px; border-radius: 5px; background: var(--surface-3); overflow: hidden; }
.progress-track i { display: block; height: 100%; border-radius: inherit; background: linear-gradient(90deg, var(--primary), var(--primary-2)); transition: width .25s var(--ease); }
.progress-meta { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-top: 5px; color: var(--text-3); font-size: 10px; font-variant-numeric: tabular-nums; }

@media (max-width: 760px) {
  .main-inner { padding: 20px 18px 34px; }
  .page-head { align-items: flex-start; flex-direction: column; gap: 14px; margin-bottom: 18px; }
  .page-head h1 { font-size: 24px; }
  .page-head p { font-size: 12px; }
  .page-actions { width: 100%; }
  .page-actions .btn { flex: 1; }
}

@media (max-width: 520px) {
  .modal-backdrop { padding: 12px; align-items: end; }
  .modal { max-height: 90vh; border-radius: 14px; }
  .modal-head { padding: 16px 16px 13px; }
  .modal-body { padding: 16px; }
  .modal-foot { padding: 11px 16px; }
  .toast-root { left: 12px; right: 12px; bottom: 12px; align-items: stretch; }
  .toast { width: 100%; }
}
