:root {
  --bg: var(--tg-theme-secondary-bg-color, #f2f4f8);
  --surface: var(--tg-theme-bg-color, #ffffff);
  --text: var(--tg-theme-text-color, #14161a);
  --muted: var(--tg-theme-hint-color, #8a94a6);
  --accent: var(--tg-theme-button-color, #2f6bdd);
  --accent-text: var(--tg-theme-button-text-color, #ffffff);
  --line: color-mix(in srgb, var(--muted) 22%, transparent);
  --cell: color-mix(in srgb, var(--accent) 10%, transparent);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  padding: 16px 12px 32px;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.4 -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  -webkit-text-size-adjust: 100%;
}

.hidden { display: none !important; }

.head { margin: 0 4px 14px; }

h1 { font-size: 20px; margin: 0 0 4px; }
h2 { font-size: 17px; margin: 0 0 4px; }

.sub, .foot, .filter-hint {
  color: var(--muted);
  font-size: 13px;
  margin: 0;
}

.foot { margin: 14px 4px 0; }
.filter-hint { margin: 8px 6px 14px; }

.back {
  background: none;
  border: 0;
  color: var(--accent);
  font-size: 15px;
  padding: 0 0 8px;
  cursor: pointer;
}

.chips {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  padding: 0 4px 12px;
  scrollbar-width: none;
}

.chips::-webkit-scrollbar { display: none; }

.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  flex: none;
  padding: 7px 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  color: var(--text);
  font-size: 14px;
  font-weight: 600;
  white-space: nowrap;
  cursor: pointer;
}

.chip[aria-pressed='true'] {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-text);
}

.chip[aria-pressed='true'] .dot { box-shadow: 0 0 0 2px var(--accent-text); }

.chip .dot { margin: 0; }

.chip-count {
  font-weight: 500;
  font-size: 12px;
  opacity: 0.7;
}

.filter {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--surface);
  color: var(--text);
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
}

.filter-dot {
  width: 18px;
  height: 18px;
  border: 2px solid var(--muted);
  border-radius: 6px;
  flex: none;
}

.filter[aria-pressed='true'] {
  background: var(--accent);
  color: var(--accent-text);
  border-color: var(--accent);
}

.filter[aria-pressed='true'] .filter-dot {
  border-color: var(--accent-text);
  background: var(--accent-text);
  box-shadow: inset 0 0 0 3px var(--accent);
}

.filter-text { flex: 1; text-align: left; }

.filter-count {
  font-size: 13px;
  font-weight: 500;
  opacity: 0.75;
}

.card {
  background: var(--surface);
  border-radius: 16px;
  padding: 14px 4px 6px;
  overflow: hidden;
}

.card-title {
  margin: 0 12px 10px;
  color: var(--muted);
  font-size: 14px;
}

.matrix-wrap, .table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.matrix {
  border-collapse: collapse;
  width: 100%;
  font-size: 14px;
}

.matrix th, .matrix td {
  padding: 8px 6px;
  text-align: center;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}

.matrix thead th {
  color: var(--muted);
  font-weight: 600;
  font-size: 13px;
  vertical-align: bottom;
}

.matrix thead .week-month {
  display: block;
  font-weight: 400;
  font-size: 11px;
  opacity: 0.8;
}

.matrix th.corner, .matrix td.okrug {
  position: sticky;
  left: 0;
  z-index: 1;
  background: var(--surface);
  text-align: left;
  padding-left: 12px;
  min-width: 96px;
}

.matrix td.okrug {
  font-weight: 600;
  font-size: 14px;
}

.dot {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  margin-right: 8px;
  vertical-align: baseline;
}

.matrix tbody tr:last-child td { border-bottom: 0; }

.matrix tr.total td, .matrix td.total {
  font-weight: 700;
  background: color-mix(in srgb, var(--muted) 8%, transparent);
}

.count {
  display: inline-block;
  min-width: 46px;
  padding: 6px 10px;
  border: 0;
  border-radius: 10px;
  background: var(--cell);
  color: var(--text);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}

.count:active { opacity: 0.6; }

.matrix .empty { color: var(--muted); opacity: 0.45; }

.table-card { padding: 6px 0; }

.lots {
  border-collapse: collapse;
  font-size: 13px;
  width: max-content;
  min-width: 100%;
}

.lots th, .lots td {
  padding: 9px 10px;
  text-align: left;
  border-bottom: 1px solid var(--line);
  vertical-align: top;
}

.lots thead th {
  color: var(--muted);
  font-weight: 600;
  font-size: 12px;
  white-space: nowrap;
  position: sticky;
  top: 0;
  background: var(--surface);
}

.lots .num { text-align: right; white-space: nowrap; }
.lots td.title { max-width: 320px; min-width: 200px; }
.lots td.nowrap { white-space: nowrap; }

.lots tr.priority td:first-child {
  box-shadow: inset 3px 0 0 var(--accent);
}

.badge {
  display: inline-block;
  margin-left: 6px;
  padding: 1px 6px;
  border-radius: 6px;
  background: var(--cell);
  color: var(--accent);
  font-size: 11px;
  font-weight: 600;
}

.message {
  margin: 24px 8px;
  color: var(--muted);
  text-align: center;
}
