:root {
  --bg: #f5f7fb;
  --card: #ffffff;
  --text: #101828;
  --muted: #667085;
  --line: #d9e2ef;
  --blue: #0877ff;
  --blue-dark: #005ce6;
  --green: #d8f3dc;
  --yellow: #fff3cd;
  --assigned: #dbeafe;
  --danger: #dc2626;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  color: var(--text);
  background: var(--tg-theme-bg-color, var(--bg));
  font: 14px/1.35 system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

.app {
  min-height: 100vh;
  padding: 14px 12px calc(18px + env(safe-area-inset-bottom));
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.top-actions {
  display: flex;
  align-items: center;
  gap: 5px;
}

h1 {
  margin: 0;
  font-size: 24px;
  line-height: 1.05;
  color: var(--blue);
}

button, input {
  font: inherit;
}

.icon-button,
.ghost-button,
.text-button,
.actions button {
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--text);
  border-radius: 10px;
  min-height: 38px;
}

.icon-button {
  width: 42px;
  padding: 5px;
  display: grid;
  place-items: center;
}

.icon-button img {
  width: 30px;
  height: 30px;
  object-fit: contain;
  pointer-events: none;
}

.datebar {
  display: grid;
  grid-template-columns: 38px 1fr 38px auto;
  gap: 8px;
  margin-bottom: 12px;
}

.datebar input {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0 10px;
  background: var(--card);
  color: var(--text);
}

.text-button {
  padding: 0 12px;
  color: var(--blue);
  font-weight: 650;
}

.summary {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-bottom: 12px;
}

.summary > div {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px;
}

.summary span {
  display: block;
  font-size: 20px;
  font-weight: 800;
}

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

.status {
  padding: 10px 12px;
  margin-bottom: 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--card);
  color: var(--muted);
}

.task-list {
  display: grid;
  gap: 10px;
}

.task-card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 12px;
  box-shadow: 0 8px 22px rgba(16, 24, 40, .06);
}

.task-card.done { background: var(--green); }
.task-card.progressing { background: var(--yellow); }
.task-card.assigned { background: var(--assigned); }

.task-head {
  display: grid;
  grid-template-columns: 12px 1fr;
  gap: 8px;
  align-items: start;
}

.task-status-dot {
  width: 10px;
  height: 10px;
  margin-top: 5px;
  border-radius: 50%;
  background: var(--line);
}

.task-card.done .task-status-dot { background: #16a34a; }
.task-card.progressing .task-status-dot { background: #d97706; }
.task-card.assigned .task-status-dot { background: var(--blue); }

.task-title {
  font-weight: 780;
  overflow-wrap: anywhere;
}

.task-meta {
  margin-top: 6px;
  color: var(--muted);
  font-size: 13px;
  overflow-wrap: anywhere;
}

.progress {
  margin-top: 10px;
}

.progress-line {
  height: 7px;
  border-radius: 999px;
  background: rgba(255, 255, 255, .8);
  overflow: hidden;
  border: 1px solid rgba(8, 119, 255, .16);
}

.progress-line span {
  display: block;
  height: 100%;
  width: 0;
  background: linear-gradient(90deg, var(--blue), var(--blue-dark));
}

.progress-text {
  margin-top: 5px;
  color: var(--muted);
  font-size: 12px;
}

.actions {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 5px;
  margin-top: 10px;
}

.actions button {
  flex: 0 0 44px;
  width: 44px;
  height: 44px;
  min-height: 44px;
  padding: 5px;
  display: grid;
  place-items: center;
}

.actions button img {
  width: 30px;
  height: 30px;
  object-fit: contain;
  pointer-events: none;
}

.actions button:active,
.icon-button:active {
  background: #eaf2ff;
  border-color: #9ec5ff;
}

.actions button:disabled {
  opacity: .42;
  cursor: default;
}

.file-tools {
  display: flex;
  align-items: center;
  gap: 5px;
  margin-top: 10px;
  padding-top: 9px;
  border-top: 1px solid rgba(102, 112, 133, .22);
}

.file-tools button,
.file-item-download {
  width: 40px;
  height: 40px;
  padding: 5px;
  display: grid;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--card);
}

.file-tools img,
.file-item-download img {
  width: 28px;
  height: 28px;
  object-fit: contain;
  pointer-events: none;
}

.task-files {
  margin-top: 8px;
  border-top: 1px solid rgba(102, 112, 133, .22);
}

.file-state {
  padding: 10px 2px 4px;
  color: var(--muted);
  font-size: 12px;
}

.file-list {
  display: grid;
}

.file-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 40px;
  align-items: center;
  gap: 6px;
  min-height: 52px;
  border-bottom: 1px solid rgba(102, 112, 133, .18);
}

.file-item:last-child {
  border-bottom: 0;
}

.file-item-open {
  min-width: 0;
  min-height: 48px;
  padding: 5px 2px;
  display: grid;
  grid-template-columns: 32px minmax(0, 1fr);
  align-items: center;
  gap: 8px;
  border: 0;
  background: transparent;
  color: var(--text);
  text-align: left;
}

.file-item-open > img {
  width: 28px;
  height: 28px;
  object-fit: contain;
}

.file-item-open span,
.file-item-open small {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.file-item-open small {
  margin-top: 2px;
  color: var(--muted);
  font-size: 11px;
}

.file-viewer-panel {
  width: min(100%, 720px);
  max-height: calc(100vh - 32px - env(safe-area-inset-bottom));
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  border: 1px solid var(--line);
  border-radius: 14px;
  overflow: hidden;
  background: var(--card);
  box-shadow: 0 18px 48px rgba(16, 24, 40, .24);
}

.file-viewer-panel > header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
}

.file-viewer-panel h2 {
  min-width: 0;
  margin: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 16px;
}

.file-preview {
  min-height: 220px;
  display: grid;
  place-items: center;
  overflow: auto;
  padding: 10px;
  background: #eef2f7;
}

.file-preview img {
  display: block;
  max-width: 100%;
  max-height: 70vh;
  object-fit: contain;
}

.download-file-button {
  min-height: 48px;
  padding: 8px 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border-top: 1px solid var(--line);
  color: var(--blue);
  font-weight: 700;
  text-decoration: none;
}

.download-file-button img {
  width: 26px;
  height: 26px;
  object-fit: contain;
}

.help-backdrop {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: grid;
  place-items: end center;
  padding: 16px 12px calc(16px + env(safe-area-inset-bottom));
  background: rgba(16, 24, 40, .42);
}

.help-panel {
  width: min(100%, 520px);
  max-height: min(82vh, 640px);
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--card);
  box-shadow: 0 18px 48px rgba(16, 24, 40, .24);
}

.help-panel > header {
  position: sticky;
  top: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
  background: var(--card);
}

.help-panel h2 {
  margin: 0;
  font-size: 18px;
}

.dialog-close {
  width: 38px;
  height: 38px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--card);
  color: var(--text);
  font-size: 24px;
  line-height: 1;
}

.help-list {
  padding: 4px 14px 12px;
}

.help-list > div {
  display: grid;
  grid-template-columns: 52px 1fr;
  align-items: center;
  gap: 10px;
  min-height: 62px;
  border-bottom: 1px solid var(--line);
}

.help-list > div:last-child {
  border-bottom: 0;
}

.help-list img {
  width: 32px;
  height: 32px;
  object-fit: contain;
}

.paired-icons {
  display: flex;
  align-items: center;
}

.paired-icons img + img {
  margin-left: -12px;
}

.help-list p,
.help-list strong,
.help-list small {
  display: block;
  margin: 0;
}

.help-list small {
  margin-top: 3px;
  color: var(--muted);
  font-size: 12px;
}

.button-tooltip {
  position: fixed;
  z-index: 1100;
  max-width: min(260px, calc(100vw - 24px));
  padding: 7px 9px;
  border-radius: 7px;
  background: #101828;
  color: #fff;
  font-size: 12px;
  line-height: 1.25;
  text-align: center;
  pointer-events: none;
  box-shadow: 0 6px 18px rgba(16, 24, 40, .24);
}

@media (max-width: 360px) {
  .datebar { grid-template-columns: 36px 1fr 36px; }
  .todayButton, #todayButton { grid-column: 1 / -1; }
}
