:root {
  color-scheme: light;
  --bg: var(--tg-theme-bg-color, #eef7f6);
  --text: var(--tg-theme-text-color, #14211f);
  --muted: var(--tg-theme-hint-color, #687775);
  --surface: var(--tg-theme-secondary-bg-color, rgba(255, 255, 255, 0.82));
  --surface-strong: #ffffff;
  --line: rgba(41, 73, 69, 0.14);
  --accent: var(--tg-theme-button-color, #0f766e);
  --accent-text: var(--tg-theme-button-text-color, #ffffff);
  --blue: #2563eb;
  --cyan: #0891b2;
  --green: #0f8f68;
  --amber: #b7791f;
  --red: #c2410c;
  --shadow: 0 18px 46px rgba(25, 46, 43, 0.12);
  --radius: 8px;
  --tg-viewport-height: 100vh;
  font-family: Inter, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  scroll-behavior: smooth;
}

body {
  min-height: var(--tg-viewport-height);
  margin: 0;
  background:
    linear-gradient(180deg, rgba(228, 247, 244, 0.96) 0%, rgba(248, 250, 252, 0.98) 46%, #eef2f7 100%),
    var(--bg);
  color: var(--text);
}

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

button {
  min-height: 48px;
  border: 1px solid transparent;
  border-radius: var(--radius);
  cursor: pointer;
  font-weight: 800;
}

button:active {
  transform: translateY(1px);
}

button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible {
  outline: 3px solid rgba(8, 145, 178, 0.22);
  outline-offset: 2px;
}

h1,
h2,
h3,
p {
  margin: 0;
}

h1 {
  font-size: 28px;
  line-height: 1.08;
}

h2 {
  font-size: 20px;
  line-height: 1.18;
}

h3 {
  font-size: 15px;
  line-height: 1.2;
}

small {
  color: var(--muted);
}

.app-shell {
  width: min(1100px, 100%);
  margin: 0 auto;
  padding: calc(14px + env(safe-area-inset-top)) 14px calc(96px + env(safe-area-inset-bottom));
}

.app-header {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 14px;
  align-items: center;
  margin-bottom: 14px;
}

.eyebrow {
  margin-bottom: 4px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 900;
  letter-spacing: 0;
  text-transform: uppercase;
}

.dashboard-card {
  margin-bottom: 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
  padding: 16px;
  backdrop-filter: blur(18px);
}

.section-head {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  align-items: center;
  margin-bottom: 12px;
}

.section-head.compact {
  margin-bottom: 8px;
}

.subline,
.muted {
  color: var(--muted);
}

.subline {
  margin-top: 2px;
  overflow-wrap: anywhere;
  font-size: 13px;
}

.online-badge,
.soft-pill,
.status-pill,
.kind-chip {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 900;
}

.online-badge {
  gap: 7px;
  min-height: 32px;
  padding: 4px 11px;
  border: 1px solid rgba(183, 121, 31, 0.2);
  background: rgba(255, 247, 237, 0.9);
  color: var(--amber);
}

.online-badge.online {
  border-color: rgba(15, 143, 104, 0.2);
  background: rgba(222, 247, 237, 0.92);
  color: var(--green);
}

.online-badge.error {
  border-color: rgba(194, 65, 12, 0.22);
  background: rgba(255, 237, 213, 0.92);
  color: var(--red);
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: currentColor;
}

.soft-pill {
  min-height: 28px;
  justify-content: center;
  padding: 3px 10px;
  border: 1px solid rgba(8, 145, 178, 0.18);
  background: rgba(236, 254, 255, 0.88);
  color: var(--cyan);
}

.active-project-card {
  background:
    linear-gradient(135deg, rgba(255, 255, 255, 0.9), rgba(239, 253, 250, 0.84)),
    var(--surface);
}

.status-pills {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin-top: 14px;
}

.status-pill {
  min-width: 0;
  min-height: 58px;
  align-items: flex-start;
  justify-content: center;
  flex-direction: column;
  gap: 2px;
  padding: 8px 10px;
  border: 1px solid rgba(15, 118, 110, 0.14);
  background: rgba(255, 255, 255, 0.68);
}

.status-pill strong {
  max-width: 100%;
  overflow-wrap: anywhere;
  color: var(--text);
  font-size: 13px;
}

.quick-actions {
  display: grid;
  gap: 12px;
}

.icon-button {
  min-width: 48px;
  padding: 0 12px;
  border-color: var(--line);
  background: rgba(255, 255, 255, 0.68);
  color: var(--text);
  font-size: 20px;
}

textarea {
  width: 100%;
  min-height: 112px;
  resize: vertical;
  border: 1px solid rgba(15, 118, 110, 0.18);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.74);
  color: var(--text);
  padding: 13px;
  line-height: 1.45;
}

input,
select {
  width: 100%;
  min-height: 48px;
  border: 1px solid rgba(15, 118, 110, 0.18);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.76);
  color: var(--text);
  padding: 10px 12px;
}

input[type="file"] {
  padding: 10px;
}

.inline-form,
.upload-panel,
.role-switch {
  display: grid;
  gap: 8px;
}

.inline-form {
  grid-template-columns: minmax(0, 1fr) auto;
  margin-bottom: 12px;
}

.upload-panel {
  grid-template-columns: minmax(0, 1.2fr) minmax(104px, 0.7fr) auto;
  align-items: center;
  margin-bottom: 12px;
}

.role-switch {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.role-button {
  min-height: 42px;
  border-color: var(--line);
  background: rgba(255, 255, 255, 0.68);
  color: var(--muted);
}

.role-button.active {
  border-color: rgba(15, 118, 110, 0.42);
  background: rgba(236, 253, 245, 0.9);
  color: var(--accent);
}

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

.primary-action {
  background: linear-gradient(135deg, var(--accent), var(--cyan));
  color: var(--accent-text);
  box-shadow: 0 12px 22px rgba(15, 118, 110, 0.22);
}

.secondary-action {
  border-color: rgba(37, 99, 235, 0.22);
  background: rgba(239, 246, 255, 0.86);
  color: var(--blue);
}

.compact-button {
  min-height: 40px;
  padding: 0 12px;
}

.dashboard-layout {
  display: grid;
  gap: 14px;
}

.pipeline-list,
.projects-list,
.materials-list,
.tree-list,
.logs-list,
.admin-grid {
  display: grid;
  gap: 8px;
}

.pipeline-step {
  display: grid;
  grid-template-columns: 28px minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
  min-height: 48px;
}

.pipeline-index {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: rgba(15, 118, 110, 0.1);
  color: var(--accent);
  font-size: 12px;
  font-weight: 900;
}

.pipeline-step.ready .pipeline-index {
  background: rgba(15, 143, 104, 0.14);
  color: var(--green);
}

.project-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
  width: 100%;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.68);
  color: var(--text);
  text-align: left;
  padding: 10px 12px;
}

.project-row.active {
  border-color: rgba(15, 118, 110, 0.45);
  background: rgba(236, 253, 245, 0.86);
  box-shadow: inset 3px 0 0 var(--accent);
}

.project-row strong,
.material-title,
.tree-row span,
.log-row strong {
  overflow-wrap: anywhere;
}

.project-row small {
  display: block;
  margin-top: 2px;
}

.divider {
  height: 1px;
  margin: 14px 0;
  background: var(--line);
}

.material-row,
.tree-row,
.log-row,
.task-row,
.admin-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
  min-height: 42px;
  border-bottom: 1px solid var(--line);
  padding: 5px 0;
}

.material-title {
  display: block;
  font-weight: 800;
}

.kind-chip {
  min-height: 26px;
  justify-content: center;
  padding: 3px 9px;
  background: rgba(241, 245, 249, 0.95);
  color: #475569;
}

.kind-chip.document,
.kind-chip.code {
  background: rgba(239, 246, 255, 0.92);
  color: var(--blue);
}

.kind-chip.image,
.kind-chip.screenshot {
  background: rgba(236, 254, 255, 0.92);
  color: var(--cyan);
}

.kind-chip.audio,
.kind-chip.incoming {
  background: rgba(255, 247, 237, 0.96);
  color: var(--amber);
}

.tree-list {
  max-height: 280px;
  overflow: auto;
  padding-right: 2px;
}

.tree-row {
  min-height: 34px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12px;
}

.tree-row.directory {
  color: var(--accent);
  font-weight: 900;
}

.screenshots-list {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
}

.screenshot-item {
  display: grid;
  gap: 8px;
}

.screenshot-item img,
.screenshot-placeholder {
  width: 100%;
  aspect-ratio: 16 / 10;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(241, 245, 249, 0.88);
  object-fit: cover;
}

.screenshot-placeholder {
  display: grid;
  place-items: center;
  color: var(--muted);
  font-size: 13px;
}

.screenshot-caption {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  align-items: center;
}

#resultOutput {
  max-height: 240px;
  margin: 0 0 12px;
  overflow: auto;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(17, 24, 39, 0.92);
  color: #e5f3f1;
  padding: 12px;
  font-size: 12px;
  line-height: 1.45;
}

.log-row,
.task-row,
.admin-row {
  align-items: start;
}

.log-row small,
.task-row small,
.admin-row small {
  display: block;
  margin-top: 2px;
}

.active-task {
  display: grid;
  gap: 8px;
  margin-bottom: 10px;
}

.auth-debug-grid .soft-pill {
  max-width: 100%;
  overflow-wrap: anywhere;
  text-align: right;
}

.task-row.active {
  border: 1px solid rgba(15, 118, 110, 0.22);
  border-radius: var(--radius);
  background: rgba(236, 253, 245, 0.72);
  padding: 10px;
}

.methodology-panel {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 12px;
  align-items: start;
  margin-top: 14px;
  padding-top: 14px;
  border-top: 1px solid var(--line);
}

.methodology-panel p {
  margin-top: 4px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.35;
}

.bottom-nav {
  position: fixed;
  right: 0;
  bottom: 0;
  left: 0;
  z-index: 20;
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 6px;
  width: min(720px, calc(100% - 20px));
  margin: 0 auto;
  padding: 8px 8px calc(8px + env(safe-area-inset-bottom));
  border: 1px solid rgba(41, 73, 69, 0.12);
  border-bottom: 0;
  border-radius: 8px 8px 0 0;
  background: rgba(255, 255, 255, 0.9);
  box-shadow: 0 -14px 36px rgba(25, 46, 43, 0.13);
  backdrop-filter: blur(18px);
}

.nav-item {
  min-height: 44px;
  border-color: transparent;
  background: transparent;
  color: var(--muted);
  font-size: 13px;
}

.nav-item.active {
  background: rgba(15, 118, 110, 0.1);
  color: var(--accent);
}

@media (min-width: 680px) {
  .app-shell {
    padding-right: 20px;
    padding-left: 20px;
  }

  .status-pills {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }

  .screenshots-list {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (min-width: 920px) {
  .app-shell {
    padding-top: 24px;
  }

  .dashboard-layout {
    grid-template-columns: minmax(0, 1fr) minmax(280px, 0.78fr);
  }

  .quick-actions {
    grid-template-columns: minmax(0, 1fr);
  }
}

@media (max-width: 420px) {
  h1 {
    font-size: 24px;
  }

  h2 {
    font-size: 18px;
  }

  .action-grid {
    grid-template-columns: 1fr;
  }

  .inline-form,
  .upload-panel {
    grid-template-columns: 1fr;
  }

  .methodology-panel {
    grid-template-columns: 1fr;
  }
}
