:root {
  --bg: var(--tg-theme-bg-color, #f4f5f1);
  --surface: var(--tg-theme-section-bg-color, #ffffff);
  --surface-muted: var(--tg-theme-secondary-bg-color, #eef1eb);
  --text: var(--tg-theme-text-color, #20241f);
  --muted: var(--tg-theme-hint-color, #70776b);
  --line: rgba(32, 36, 31, 0.1);
  --strong: #20241f;
  --accent: #55785a;
  --accent-soft: #e4ece1;
  --ok: #3d8f59;
  --danger: #c7433a;
  --warn: #b8782e;
  --info: #3f6f8f;
  --shadow: 0 10px 26px rgba(32, 36, 31, 0.08);
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html,
body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 15px;
  letter-spacing: 0;
}

body {
  overflow-x: hidden;
}

button,
input {
  font: inherit;
}

button {
  cursor: pointer;
}

.hidden {
  display: none !important;
}

.screen {
  min-height: 100svh;
  padding-bottom: max(18px, env(safe-area-inset-bottom));
  animation: screen-in 180ms ease-out;
}

.workspace {
  width: min(720px, 100%);
  margin: 0 auto;
  padding: 12px;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 62px;
  padding: 10px 14px;
  background: color-mix(in srgb, var(--surface) 94%, transparent);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(14px);
}

.eyebrow {
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  line-height: 1.1;
  text-transform: uppercase;
}

.topbar-title {
  margin-top: 2px;
  color: var(--strong);
  font-size: 19px;
  font-weight: 760;
  line-height: 1.1;
}

.topbar-user {
  max-width: 46%;
  padding: 6px 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--muted);
  background: var(--surface-muted);
  font-size: 12px;
  font-weight: 650;
  line-height: 1.2;
  text-align: right;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.back-btn {
  width: 38px;
  height: 38px;
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-muted);
  color: var(--strong);
  font-size: 30px;
  line-height: 1;
}

.summary-panel {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 1px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--line);
  box-shadow: var(--shadow);
}

.summary-item {
  min-width: 0;
  padding: 12px 10px;
  background: var(--surface);
}

.summary-label {
  display: block;
  color: var(--muted);
  font-size: 11px;
  font-weight: 680;
  line-height: 1.2;
  text-transform: uppercase;
}

.summary-item strong {
  display: block;
  margin-top: 4px;
  color: var(--strong);
  font-size: 24px;
  font-weight: 760;
  line-height: 1;
}

.search-box {
  display: grid;
  grid-template-columns: auto 1fr;
  align-items: center;
  gap: 10px;
  margin-top: 12px;
  padding: 9px 11px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.search-box span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
}

.search-box input {
  min-width: 0;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--text);
}

.search-box input::placeholder {
  color: color-mix(in srgb, var(--muted) 70%, transparent);
}

.tabs-wrap {
  position: sticky;
  top: 62px;
  z-index: 15;
  margin: 12px -12px 0;
  padding: 8px 12px;
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  border-bottom: 1px solid color-mix(in srgb, var(--line) 60%, transparent);
  backdrop-filter: blur(14px);
}

.tabs {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  scrollbar-width: none;
}

.tabs::-webkit-scrollbar {
  display: none;
}

.tab {
  flex: 0 0 auto;
  min-height: 34px;
  padding: 7px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--muted);
  font-size: 13px;
  font-weight: 720;
  white-space: nowrap;
  transition: transform 140ms ease, background 140ms ease, color 140ms ease, border-color 140ms ease;
}

.tab.active {
  border-color: var(--strong);
  background: var(--strong);
  color: #ffffff;
}

.tab:active,
.order-card:active,
.task-group-header:active,
.stage-row:active,
.task-row:active,
.back-btn:active {
  transform: scale(0.98);
}

.list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding-top: 10px;
}

.loading-list {
  display: grid;
  gap: 8px;
}

.loading-list div {
  height: 76px;
  border-radius: 8px;
  background: linear-gradient(90deg, var(--surface-muted), var(--surface), var(--surface-muted));
  background-size: 220% 100%;
  animation: shimmer 1.15s ease-in-out infinite;
}

.empty {
  padding: 34px 18px;
  border: 1px dashed var(--line);
  border-radius: 8px;
  color: var(--muted);
  background: color-mix(in srgb, var(--surface) 72%, transparent);
  font-size: 14px;
  font-weight: 620;
  line-height: 1.35;
  text-align: center;
}

.order-card,
.task-group,
.stage-row,
.order-info {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.order-card {
  padding: 12px;
  transition: transform 140ms ease, border-color 140ms ease, box-shadow 140ms ease;
}

.order-card:hover {
  border-color: color-mix(in srgb, var(--accent) 45%, var(--line));
}

.order-card-top,
.task-group-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
}

.order-number,
.task-group-order-number {
  color: var(--strong);
  font-size: 15px;
  font-weight: 780;
  line-height: 1.2;
}

.order-card-client,
.task-group-client {
  margin-top: 7px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 620;
  line-height: 1.25;
}

.order-card-product {
  margin-top: 3px;
  color: var(--text);
  font-size: 14px;
  font-weight: 650;
  line-height: 1.25;
  overflow-wrap: anywhere;
}

.order-card-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid var(--line);
}

.order-date {
  color: var(--muted);
  font-size: 12px;
  font-weight: 650;
}

.order-status-badge,
.task-group-reason,
.stage-status-pill {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  max-width: 54vw;
  padding: 4px 8px;
  border-radius: 8px;
  color: var(--accent);
  background: var(--accent-soft);
  font-size: 12px;
  font-weight: 760;
  line-height: 1.15;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.order-status-badge::before,
.stage-status-pill::before {
  content: "";
  width: 7px;
  height: 7px;
  flex: 0 0 auto;
  margin-right: 6px;
  border-radius: 50%;
  background: currentColor;
}

.order-status-badge.problem,
.stage-status-pill.problem {
  color: var(--danger);
  background: #f7e7e5;
}

.stage-status-pill.done {
  color: var(--ok);
  background: #e2f0e7;
}

.stage-status-pill.waiting,
.stage-status-pill.in-progress {
  color: var(--info);
  background: #e5edf2;
}

.priority-urgent {
  color: var(--danger);
}

.priority-high {
  color: var(--warn);
}

.task-group {
  overflow: hidden;
}

.task-group-header {
  padding: 12px;
  background: var(--surface);
}

.task-group-reason {
  color: var(--strong);
  background: var(--surface-muted);
}

.task-group-body {
  display: flex;
  flex-direction: column;
  border-top: 1px solid var(--line);
}

.task-row,
.stage-row {
  display: flex;
  align-items: center;
  gap: 11px;
}

.task-row {
  padding: 10px 12px;
  border-top: 1px solid var(--line);
}

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

.task-row.clickable {
  cursor: pointer;
}

.task-row-name,
.stage-name {
  min-width: 0;
  color: var(--text);
  font-size: 14px;
  font-weight: 680;
  line-height: 1.25;
  overflow-wrap: anywhere;
}

.task-row-arrow {
  flex: 0 0 auto;
  color: var(--muted);
  font-size: 18px;
}

.stage-row {
  min-height: 58px;
  padding: 10px 12px;
  transition: transform 140ms ease, border-color 140ms ease;
}

.stage-checkbox {
  width: 28px;
  height: 28px;
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  border: 2px solid color-mix(in srgb, var(--muted) 62%, transparent);
  border-radius: 50%;
  color: transparent;
  font-size: 15px;
  font-weight: 800;
  user-select: none;
  transition: background 140ms ease, border-color 140ms ease, color 140ms ease, transform 140ms ease;
}

.stage-checkbox.done {
  border-color: var(--ok);
  background: var(--ok);
  color: #ffffff;
}

.stage-checkbox.problem {
  border-color: var(--danger);
  background: var(--danger);
  color: #ffffff;
}

.stage-checkbox.skipped {
  border-color: var(--muted);
  background: var(--muted);
  color: #ffffff;
}

.stage-checkbox:active {
  transform: scale(0.92);
}

.stage-main {
  min-width: 0;
  flex: 1;
}

.stage-meta {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 5px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 620;
  line-height: 1.25;
}

.order-info {
  overflow: hidden;
}

.order-info-head {
  padding: 14px 12px 12px;
  border-bottom: 1px solid var(--line);
}

.order-info-title {
  color: var(--strong);
  font-size: 20px;
  font-weight: 780;
  line-height: 1.1;
}

.order-info-subtitle {
  margin-top: 6px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 640;
  line-height: 1.35;
  overflow-wrap: anywhere;
}

.order-info-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 1px;
  background: var(--line);
}

.order-info-row {
  min-width: 0;
  padding: 11px 12px;
  background: var(--surface);
}

.order-info-row .label {
  display: block;
  color: var(--muted);
  font-size: 11px;
  font-weight: 720;
  line-height: 1.2;
  text-transform: uppercase;
}

.order-info-row .value {
  display: block;
  margin-top: 4px;
  color: var(--text);
  font-size: 14px;
  font-weight: 700;
  line-height: 1.25;
  overflow-wrap: anywhere;
}

.section-title {
  padding: 16px 2px 2px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 760;
  text-transform: uppercase;
}

.error-box {
  min-height: 100svh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 28px;
  text-align: center;
}

.error-mark {
  width: 48px;
  height: 48px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  color: #ffffff;
  background: var(--danger);
  font-size: 26px;
  font-weight: 800;
}

.error-box h1 {
  margin: 16px 0 6px;
  color: var(--strong);
  font-size: 22px;
  line-height: 1.15;
}

#error-text {
  max-width: 320px;
  margin: 0;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.4;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: max(18px, env(safe-area-inset-bottom));
  z-index: 100;
  max-width: calc(100vw - 28px);
  padding: 10px 14px;
  border-radius: 8px;
  background: var(--strong);
  color: #ffffff;
  box-shadow: var(--shadow);
  font-size: 13px;
  font-weight: 680;
  line-height: 1.3;
  text-align: center;
  opacity: 0;
  transform: translate(-50%, 10px);
  pointer-events: none;
  transition: opacity 180ms ease, transform 180ms ease;
}

.toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

@keyframes shimmer {
  0% {
    background-position: 100% 0;
  }
  100% {
    background-position: -100% 0;
  }
}

@keyframes screen-in {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@media (max-width: 380px) {
  .workspace {
    padding: 10px;
  }

  .summary-item {
    padding: 10px 8px;
  }

  .summary-item strong {
    font-size: 21px;
  }

  .topbar-user {
    max-width: 42%;
  }

  .order-info-grid {
    grid-template-columns: 1fr;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 1ms !important;
    transition-duration: 1ms !important;
  }
}
