/* ATP Activity — presentation layer.
   Non-destructive layer: the original prototype markup, text and behaviour are untouched.
   Light mode (default) is pixel-identical to the source page.
   Dark mode is opt-in only (html[data-atp-theme="dark"]) and never applied by default. */

/* ---------- keyboard focus ---------- */
:where(a, button, select, input, textarea, [tabindex]):focus-visible {
  outline: 2px solid #1677ff;
  outline-offset: 2px;
  border-radius: 4px;
}
.reviewbar a:focus-visible,
.nav-item:focus-visible,
.page-tabs a:focus-visible {
  outline: 2px solid #1677ff;
  outline-offset: -2px;
}

/* skip link for keyboard users, revealed only on focus */
.atp-skip {
  position: fixed;
  top: 6px;
  left: 8px;
  z-index: 200;
  padding: 8px 14px;
  background: #1677ff;
  color: #fff;
  border-radius: 5px;
  font-size: 13px;
  transform: translateY(-160%);
  transition: transform .16s ease;
}
.atp-skip:focus-visible {
  transform: translateY(0);
  outline: 2px solid #0b3f8f;
}

/* ---------- narrow viewport / 390px ----------
   The source prototype is a desktop console. On small screens the two-column
   console collapses to one column so nothing is clipped; the APP preview
   (#app-list) keeps its own original phone layout untouched. */
@media (max-width: 860px) {
  html, body { max-width: 100%; overflow-x: hidden; }

  .reviewbar {
    height: auto;
    min-height: 36px;
    flex-wrap: wrap;
    align-items: center;
    row-gap: 4px;
    padding: 4px 8px;
    font-size: 11px;
  }
  .reviewbar nav {
    flex-wrap: wrap;
    gap: 10px;
    row-gap: 4px;
  }
  .reviewbar nav > * { padding: 4px 0; }
  .atp-skip { left: 4px; }

  .desktop { grid-template-columns: 1fr; min-height: 0; }

  /* sidebar becomes a horizontal, scrollable switcher */
  .sidebar {
    min-height: 0;
    display: flex;
    align-items: stretch;
    overflow-x: auto;
    overflow-y: hidden;
    scrollbar-width: thin;
  }
  .sidebar .brand {
    height: 42px;
    flex: none;
    padding: 0 12px 0 10px;
    font-size: 12px;
  }
  .sidebar .nav-item {
    flex: none;
    align-items: center;
    padding: 0 12px;
    min-height: 42px;
    white-space: nowrap;
    border-left: 0;
  }
  .sidebar .nav-item.child { padding: 0 12px; font-size: 12px; }
  .sidebar .nav-item.active { border-left: 0; border-bottom: 2px solid #1677ff; }
  .sidebar .nav-item.active:before { background: #56a3ff; }
  .sidebar .nav-item.group,
  .sidebar .divider,
  .sidebar .nav-item .square,
  .sidebar .nav-item small { display: none; }

  .topbar {
    height: auto;
    flex-wrap: wrap;
    gap: 6px 10px;
    padding: 8px 10px;
    line-height: 1.5;
  }
  .topbar > span:first-child { flex: 1 1 100%; }
  .top-tools { gap: 10px; }

  .page-tabs {
    height: auto;
    overflow-x: auto;
    padding: 0 8px;
    gap: 2px;
    align-items: stretch;
  }
  .page-tabs a { padding: 8px 12px; white-space: nowrap; }

  .content { padding: 12px 10px 22px; }

  .summary-strip { grid-template-columns: repeat(2, 1fr); gap: 8px; }
  .summary-strip button { padding: 10px 12px; }
  .summary-strip strong { font-size: 20px; }

  .filters { grid-template-columns: 1fr; gap: 12px; }
  .filter { align-items: flex-start; }
  .filter label { min-width: 64px; text-align: left; padding-top: 7px; }
  .filter-actions { flex-wrap: wrap; }

  .toolbar { flex-wrap: wrap; gap: 8px; }
  .toolbar .buttons { flex-wrap: wrap; }
  .toolbar small { flex: 1 1 100%; }

  .table-wrap { -webkit-overflow-scrolling: touch; }

  .form-row { grid-template-columns: 1fr; gap: 4px; }
  .form-row label { text-align: left; padding-top: 0; }
  .form-grid { grid-template-columns: 1fr; }

  .modal-mask { padding: 10px; align-items: flex-end; inset: 0; }
  .dialog {
    width: 100%;
    max-width: 100%;
    max-height: calc(100dvh - 20px);
  }
  .dialog-head { padding: 0 14px; }
  .dialog-body { padding: 14px 16px; }
  .dialog-foot { flex-wrap: wrap; padding: 10px 12px; }
  .dialog-tabs { gap: 16px; overflow-x: auto; }

  .detail-columns { grid-template-columns: 1fr; gap: 16px; }
  .detail-heading { flex-direction: column; align-items: flex-start; gap: 8px; }
  .kv { grid-template-columns: 92px 1fr; gap: 10px; }

  .workflow-line { flex-wrap: wrap; }

  .app-stage { padding: 0; }
}

@media (max-width: 430px) {
  .summary-strip { grid-template-columns: repeat(2, 1fr); }
  .page-tabs a { padding: 8px 10px; font-size: 11px; }
  .sidebar .brand { font-size: 11px; }
}

/* ---------- dark theme (opt-in) ---------- */
html[data-atp-theme="dark"] {
  color-scheme: dark;
  --text: #dbe4f0;
  --muted: #94a3b8;
  --border: #2c3a4d;
  --bg: #0f1723;
  --nav: #0b121b;
  --blue: #5aa4ff;
  --green: #3ecf94;
  --red: #ff8189;
  --amber: #e5ab5a;
  background: #0f1723;
}
html[data-atp-theme="dark"] body {
  background: #0f1723;
  color: #dbe4f0;
}
html[data-atp-theme="dark"] .reviewbar {
  background: #16212f;
  color: #a8b8cc;
  border-bottom-color: #2c3a4d;
}
html[data-atp-theme="dark"] .reviewbar a { color: #7fb4ff; }
html[data-atp-theme="dark"] .reviewbar a.active { color: #a9ccff; }
html[data-atp-theme="dark"] .reviewbar button,
html[data-atp-theme="dark"] body:not(.app-preview-active) button {
  background: #1b2939;
  border-color: #33465c;
  color: #c6d3e2;
}
html[data-atp-theme="dark"] body:not(.app-preview-active) button:hover { border-color: #5aa4ff; color: #cfe2ff; }
html[data-atp-theme="dark"] body:not(.app-preview-active) button.primary {
  background: #2170d8;
  border-color: #2170d8;
  color: #fff;
}
html[data-atp-theme="dark"] body:not(.app-preview-active) button.link,
html[data-atp-theme="dark"] body:not(.app-preview-active) a { color: #7fb4ff; }
html[data-atp-theme="dark"] body:not(.app-preview-active) .topbar {
  background: #141f2c;
  border-bottom-color: #2c3a4d;
  color: #93a5bb;
}
html[data-atp-theme="dark"] body:not(.app-preview-active) .topbar b { color: #cfe2ff; }
html[data-atp-theme="dark"] body:not(.app-preview-active) .page-tabs {
  background: #141f2c;
  border-bottom-color: #2c3a4d;
}
html[data-atp-theme="dark"] body:not(.app-preview-active) .page-tabs a { color: #93a5bb; }
html[data-atp-theme="dark"] body:not(.app-preview-active) .page-tabs a.selected {
  background: #1c2b3c;
  border-color: #2c3a4d;
  border-bottom-color: #1c2b3c;
  color: #8dbdff;
}
html[data-atp-theme="dark"] body:not(.app-preview-active) .filter-panel,
html[data-atp-theme="dark"] body:not(.app-preview-active) .white-panel,
html[data-atp-theme="dark"] body:not(.app-preview-active) .table-wrap,
html[data-atp-theme="dark"] body:not(.app-preview-active) .summary-strip button {
  background: #16212f;
  border-color: #2c3a4d;
}
html[data-atp-theme="dark"] body:not(.app-preview-active) .summary-strip strong { color: #bcd6f5; }
html[data-atp-theme="dark"] body:not(.app-preview-active) table thead { background: #1a2635; }
html[data-atp-theme="dark"] body:not(.app-preview-active) th { color: #9db0c6; border-bottom-color: #2c3a4d; }
html[data-atp-theme="dark"] body:not(.app-preview-active) td { color: #c3d2e3; border-bottom-color: #243244; }
html[data-atp-theme="dark"] body:not(.app-preview-active) tbody tr:hover { background: #1c2a3a; }
html[data-atp-theme="dark"] body:not(.app-preview-active) .tag { background: #1d3450; color: #8dbdff; }
html[data-atp-theme="dark"] body:not(.app-preview-active) .tag.green { background: #143728; color: #62d9a6; }
html[data-atp-theme="dark"] body:not(.app-preview-active) .tag.orange { background: #3a2c14; color: #e7b464; }
html[data-atp-theme="dark"] body:not(.app-preview-active) .tag.red { background: #3d1f24; color: #ff9ba1; }
html[data-atp-theme="dark"] body:not(.app-preview-active) .tag.gray { background: #232f3e; color: #a2b2c6; }
html[data-atp-theme="dark"] body:not(.app-preview-active) .notice {
  background: #16283c;
  color: #a9c6e6;
  border-color: #294260;
}
html[data-atp-theme="dark"] body:not(.app-preview-active) .notice.alert {
  background: #33280f;
  color: #e0b877;
  border-color: #57431c;
}
html[data-atp-theme="dark"] body:not(.app-preview-active) .help-box,
html[data-atp-theme="dark"] body:not(.app-preview-active) .readonly,
html[data-atp-theme="dark"] body:not(.app-preview-active) .file-box,
html[data-atp-theme="dark"] body:not(.app-preview-active) .field-chip {
  background: #182431;
  border-color: #2c3a4d;
  color: #b3c3d6;
}
html[data-atp-theme="dark"] body:not(.app-preview-active) .context-auto-field[readonly] {
  background: #182431;
  color: #a9c0da;
}
html[data-atp-theme="dark"] body:not(.app-preview-active) .context-group-heading {
  background: #182431;
  color: #a9c0da;
  border-left-color: #4a6c92;
}
html[data-atp-theme="dark"] body:not(.app-preview-active) input,
html[data-atp-theme="dark"] body:not(.app-preview-active) select,
html[data-atp-theme="dark"] body:not(.app-preview-active) textarea {
  background: #101a26;
  border-color: #33465c;
  color: #dbe4f0;
}
html[data-atp-theme="dark"] body:not(.app-preview-active) .dialog {
  background: #16212f;
  box-shadow: 0 18px 48px #00000066;
}
html[data-atp-theme="dark"] body:not(.app-preview-active) .dialog-head,
html[data-atp-theme="dark"] body:not(.app-preview-active) .dialog-foot {
  border-color: #2c3a4d;
  background: #16212f;
}
html[data-atp-theme="dark"] .modal-mask { background: rgba(4, 9, 15, .66); }
html[data-atp-theme="dark"] body:not(.app-preview-active) .detail-card,
html[data-atp-theme="dark"] body:not(.app-preview-active) .workflow-line,
html[data-atp-theme="dark"] body:not(.app-preview-active) .workflow-line span {
  background: #16212f;
  border-color: #2c3a4d;
}
html[data-atp-theme="dark"] body:not(.app-preview-active) .kv { border-bottom-color: #243244; }
html[data-atp-theme="dark"] body:not(.app-preview-active) .kv span:first-child { color: #93a5bb; }
html[data-atp-theme="dark"] body:not(.app-preview-active) .timeline li { border-left-color: #2c3a4d; }
html[data-atp-theme="dark"] body:not(.app-preview-active) .timeline li:before { background: #5c7fa6; }
html[data-atp-theme="dark"] body:not(.app-preview-active) .timeline p { color: #93a5bb; }
html[data-atp-theme="dark"] body:not(.app-preview-active) .pager { color: #93a5bb; }
html[data-atp-theme="dark"] body:not(.app-preview-active) .toast {
  background: #143728;
  border-color: #2c6b4c;
  color: #9fe6c2;
}
html[data-atp-theme="dark"] body:not(.app-preview-active) .app-guide h2 { color: #d3e4f7; }
html[data-atp-theme="dark"] body:not(.app-preview-active) .app-guide .guide-links a.active {
  background: #1d3450;
  border-color: #3f6d9c;
  color: #b6d6fb;
}
html[data-atp-theme="dark"] body:not(.app-preview-active) .role-pill { border-color: #33465c; }
html[data-atp-theme="dark"] body:not(.app-preview-active) .role-pill select { background: transparent; }
html[data-atp-theme="dark"] body:not(.app-preview-active) .empty { color: #8fa1b7; }
html[data-atp-theme="dark"] body:not(.app-preview-active) .error { color: #ff9ba1; }

@media (prefers-reduced-motion: reduce) {
  .atp-skip { transition: none; }
}
