:root {
  color-scheme: light dark;
  --bg: var(--tg-theme-bg-color, #fff);
  --text: var(--tg-theme-text-color, #111);
  --muted: var(--tg-theme-hint-color, #888);
  --accent: var(--tg-theme-button-color, #2481cc);
  --accent-text: var(--tg-theme-button-text-color, #fff);
  --section-bg: var(--tg-theme-secondary-bg-color, #f4f4f5);
  --warn: #e67e22;
  --error: #c0392b;
  --action: #c0392b;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

header {
  padding: max(16px, env(safe-area-inset-top, 0px), var(--tg-safe-area-inset-top, 0px)) 16px 8px;
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
}

header h1 { font-size: 20px; margin: 0; font-weight: 600; flex: 1; }

.back-to-launcher {
  color: var(--accent);
  text-decoration: none;
  font-size: 14px;
  font-weight: 600;
  flex-shrink: 0;
  padding: 6px 10px;
  border-radius: 8px;
  background: var(--section-bg);
}
.back-to-launcher:active { opacity: 0.6; }

.muted { color: var(--muted); font-size: 13px; }

main { padding: 8px 16px 96px; }

.filter-row {
  display: flex;
  gap: 8px;
  align-items: center;
  margin-bottom: 10px;
}
#filter-input {
  flex: 1;
  background: var(--section-bg);
  border: 1px solid rgba(128,128,128,0.2);
  color: var(--text);
  border-radius: 8px;
  padding: 8px 12px;
  font-size: 14px;
}
.cb { font-size: 13px; color: var(--muted); display: flex; align-items: center; gap: 4px; }

.jobs-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.job-card {
  background: var(--section-bg);
  border-radius: 12px;
  padding: 12px 14px;
  cursor: pointer;
  transition: transform 0.08s;
}
.job-card:active { transform: scale(0.98); }

.job-row1 {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
}
.job-id { font-weight: 700; font-variant-numeric: tabular-nums; }
.job-type { font-size: 11px; padding: 2px 6px; background: rgba(128,128,128,0.18); border-radius: 4px; text-transform: uppercase; }
.job-age { font-size: 12px; color: var(--muted); margin-left: auto; }

.job-row2 { font-size: 13px; color: var(--muted); margin-top: 2px; word-break: break-word; }

.job-row3 {
  display: flex;
  gap: 12px;
  margin-top: 6px;
  font-size: 12px;
  color: var(--muted);
  flex-wrap: wrap;
}
.badge { display: inline-flex; align-items: center; gap: 3px; }
.badge.action { color: var(--action); font-weight: 600; }
.badge.no-folder { color: var(--warn); }

button.back {
  background: transparent;
  color: var(--accent);
  border: 0;
  padding: 4px 0;
  font-size: 14px;
  cursor: pointer;
  margin-bottom: 8px;
}

#detail-body section {
  background: var(--section-bg);
  border-radius: 12px;
  padding: 12px 14px;
  margin-bottom: 8px;
}

#detail-body h2 {
  font-size: 14px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  margin: 0 0 8px;
}

.kv {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  padding: 4px 0;
  border-bottom: 1px solid rgba(128,128,128,0.12);
}
.kv:last-child { border-bottom: 0; }
.kv span { color: var(--muted); }
.kv strong { font-variant-numeric: tabular-nums; font-weight: 600; }

.comms-list, .files-list {
  list-style: none;
  margin: 0;
  padding: 0;
}
.comms-list li, .files-list li {
  padding: 6px 0;
  border-bottom: 1px solid rgba(128,128,128,0.12);
  font-size: 13px;
}
.comms-list li:last-child, .files-list li:last-child { border-bottom: 0; }
.comm-row1 { display: flex; gap: 6px; align-items: baseline; }
.comm-ts { color: var(--muted); font-size: 11px; flex-shrink: 0; }
.comm-direction { font-size: 10px; padding: 1px 5px; border-radius: 3px; text-transform: uppercase; flex-shrink: 0; }
.comm-direction.inbound { background: rgba(45,140,200,0.18); color: var(--accent); }
.comm-direction.outbound { background: rgba(46,204,113,0.2); color: #2ecc71; }
.comm-direction.internal { background: rgba(128,128,128,0.18); color: var(--muted); }
.comm-action { font-size: 10px; padding: 1px 5px; border-radius: 3px; }
.comm-action.action_required { background: rgba(192,57,43,0.18); color: var(--action); font-weight: 600; }
.comm-subject { font-weight: 500; }
.comm-from { color: var(--muted); font-size: 12px; }
.comm-proposed { color: var(--text); font-size: 12px; padding: 2px 0 0 0; font-style: italic; }

.file-name { font-weight: 500; }
.file-meta { color: var(--muted); font-size: 11px; }

.error { color: var(--error); }

footer {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  padding: 12px 16px env(safe-area-inset-bottom);
  background: var(--bg);
  border-top: 1px solid rgba(128,128,128,0.2);
  display: flex;
  align-items: center;
  gap: 12px;
}

button {
  background: var(--accent);
  color: var(--accent-text);
  border: 0;
  border-radius: 8px;
  padding: 10px 18px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
}
button:disabled { opacity: 0.5; }
