/* Native Resilience data portal — app-specific styles ONLY.
   Chrome, tokens, buttons, modals and the navbar come from mco-web-style
   (theme/mco-theme.css). The listing, toolbar, copy menu, preview and README
   prose are ported from the MCO data browser (mco-data-cdn/storage-browser
   theme.css) onto kit tokens. No raw hexes except the folder tint, which the
   kit has no token for. */

:root, [data-theme="dark"] { --folder: #c8a951; --ok: #4fae6b; --row-h: 36px; }
[data-theme="light"]       { --folder: #a8801f; --ok: #2e7d4a; }
[data-theme="high-contrast"] { --folder: #ffd75e; --ok: #6bff9a; }

/* App frame: navbar + a browser that owns the remaining height (§3). */
body { height: 100dvh; display: flex; flex-direction: column; overflow: hidden; margin: 0; }
main { flex: 1; min-height: 0; display: flex; flex-direction: column; }
main:focus { outline: none; }

.browser {
  flex: 1; min-height: 0; display: flex; flex-direction: column;
  gap: 0.7rem; padding: 0.9rem 1.25rem 1rem;
  width: 100%; max-width: 1400px; margin: 0 auto; box-sizing: border-box;
}

@keyframes spin { to { transform: rotate(360deg); } }
.spin { animation: spin 0.8s linear infinite; }

/* ---- Breadcrumbs -------------------------------------------------------- */
.crumbs {
  display: flex; align-items: center; gap: 0.1rem; flex-wrap: wrap;
  font-family: var(--font-mono); font-size: 0.8rem;
}
.crumbs a {
  color: var(--accent-line); text-decoration: none;
  padding: 0.1rem 0.3rem; border-radius: var(--radius-sm);
  transition: background var(--transition);
}
.crumbs a:hover { background: var(--accent-hover); text-decoration: underline; }
.crumbs .sep { color: var(--text-dim); padding: 0 0.1rem; }
.crumbs .here { color: var(--text-primary); font-weight: 700; padding: 0.1rem 0.3rem; }
.crumbs .copy-menu { margin-left: 0.25rem; }

/* ---- Home (archive cards) ---------------------------------------------- */
.home { overflow: auto; padding-bottom: 1rem; }
.home-head { max-width: 46rem; margin-bottom: 1.2rem; }
.home-head h2 { font-size: 1.5rem; font-weight: 700; margin: 0 0 0.4rem; color: var(--text-primary); }
.home-head p { margin: 0; color: var(--text-muted); font-size: 0.9rem; line-height: 1.6; }
.home-head a { color: var(--accent-line); text-decoration: underline; text-underline-offset: 2px; }
.collections { list-style: none; margin: 0; padding: 0; display: grid; gap: 0.6rem; max-width: 52rem; }
.collection {
  display: flex; align-items: center; gap: 0.75rem;
  background: var(--bg-surface); border: 1px solid var(--border);
  border-radius: var(--radius-md); padding: 0.9rem 1rem;
  color: inherit; text-decoration: none;
  transition: border-color var(--transition), background var(--transition);
}
.collection:hover, .collection.is-active { border-color: var(--accent-line); background: var(--accent-hover); }
a.nav-btn { text-decoration: none; }
.collection .ico { width: 20px; height: 20px; flex: none; color: var(--folder); }
.collection-text { display: flex; flex-direction: column; gap: 2px; min-width: 0; flex: 1; }
.collection-name { font-size: 0.98rem; font-weight: 600; color: var(--text-primary); font-family: var(--font-mono); }
.collection-desc { font-size: 0.8rem; color: var(--text-muted); line-height: 1.45; }
.collection-links { display: flex; gap: 0.75rem; flex-shrink: 0; font-size: 0.75rem; }
.collection-links a { color: var(--accent-line); }

/* ---- Toolbar ------------------------------------------------------------ */
.toolbar { display: flex; align-items: center; gap: 0.6rem; flex-wrap: wrap; }
.search { position: relative; display: flex; align-items: center; }
.search-ico {
  position: absolute; left: 0.6rem; width: 14px; height: 14px;
  color: var(--text-dim); pointer-events: none;
}
.search input {
  font: inherit; font-size: 0.82rem; font-family: var(--font-mono);
  color: var(--text-primary); background: var(--input-bg);
  border: 1px solid var(--ctrl-border); border-radius: var(--radius-md);
  min-height: 34px; padding: 0.3rem 1.9rem 0.3rem 2rem;
  width: 320px; max-width: 100%; box-sizing: border-box;
  transition: border-color var(--transition);
}
.search input:focus { border-color: var(--accent-line); }
.search input::placeholder { color: var(--text-dim); }
.search input::-webkit-search-cancel-button { display: none; }
.search-clear {
  position: absolute; right: 0.3rem; display: flex; padding: 0.3rem;
  background: none; border: none; color: var(--text-dim); cursor: pointer;
  border-radius: var(--radius-sm);
}
.search-clear:hover { color: var(--text-primary); }
.search-clear svg { width: 12px; height: 12px; }
.toggle {
  display: flex; align-items: center; gap: 0.4rem;
  font-size: 0.78rem; color: var(--text-secondary); cursor: pointer;
  user-select: none; white-space: nowrap; min-height: 34px;
}
.toggle input { accent-color: var(--accent); margin: 0; cursor: pointer; width: 15px; height: 15px; }
.toggle:hover { color: var(--text-primary); }
.toolbar-spacer { flex: 1 1 auto; }
.stats {
  display: inline-flex; align-items: center; gap: 0.35rem;
  font-size: 0.78rem; color: var(--text-muted); white-space: nowrap;
}
.stats svg { width: 12px; height: 12px; }
.bulk { display: inline-flex; gap: 0.35rem; }
.nav-btn.quiet { border-color: transparent; color: var(--text-muted); }
.nav-btn.quiet:hover { border-color: var(--ctrl-border); }
.nav-btn.is-done, .nav-btn.is-done:hover { color: var(--ok); border-color: var(--ok); }
.nav-btn.small { min-height: 28px; padding: 3px 7px; }

/* ---- Entry list --------------------------------------------------------- */
.entries {
  flex: 1; min-height: 0; display: flex; flex-direction: column;
  background: var(--bg-surface); border: 1px solid var(--border);
  border-radius: var(--radius-md); overflow: hidden;
}
.scroller { flex: 1; min-height: 0; overflow: auto; }
.row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 110px 84px 112px 44px;
  align-items: center; min-height: var(--row-h);
  padding: 0 0.5rem 0 0.7rem;
  border-bottom: 1px solid var(--border-glass);
  font-size: 0.82rem;
}
.row:hover { background: var(--accent-hover); }
.row.is-active { background: var(--accent-hover); box-shadow: inset 2px 0 0 var(--accent-line); }
.row-head {
  position: sticky; top: 0; z-index: 2;
  background: var(--bg-raised); border-bottom: 1px solid var(--border);
  min-height: 32px;
}
.row-head:hover { background: var(--bg-raised); }
.sort-btn {
  display: flex; align-items: center; gap: 0.25rem;
  background: none; border: none; cursor: pointer;
  font: inherit; font-size: 0.7rem; font-weight: 600;
  text-transform: uppercase; letter-spacing: 0.05em;
  color: var(--text-secondary); padding: 0.3rem 0; text-align: left;
}
.sort-btn:hover { color: var(--text-primary); }
.sort-btn.is-sorted { color: var(--accent-line); }
.sort-btn .arr { font-size: 0.6rem; }
/* The data-column colour rule below also matches these buttons; keep headers at --text-secondary (AA on --bg-raised). */
.row-head .sort-btn { color: var(--text-secondary); font-family: inherit; }
.row-head .sort-btn:hover { color: var(--text-primary); }
.row-head .sort-btn.is-sorted { color: var(--accent-line); }
.sort-btn.col-kind, .sort-btn.col-size, .sort-btn.col-date { justify-content: flex-end; }
.entry {
  display: flex; align-items: center; gap: 0.5rem; min-width: 0;
  color: var(--text-primary); text-decoration: none; padding: 0.35rem 0;
}
.entry:hover { color: var(--accent-line); }
.entry:hover .entry-name { text-decoration: underline; text-underline-offset: 2px; }
.entry-name {
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  font-family: var(--font-mono); font-size: 0.78rem;
}
.entry-path { display: flex; min-width: 0; }
.path-dirs { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--text-dim); flex: 0 1 auto; }
.path-base { flex: none; }
.entry .ico { width: 15px; height: 15px; flex: none; color: var(--text-dim); }
.entry .ico-dir { color: var(--folder); }
.entry .ico-file { color: var(--accent-line); }
.is-up .entry-name { color: var(--text-muted); }
.col-kind, .col-size, .col-date {
  text-align: right; color: var(--text-muted); font-size: 0.74rem;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; padding-left: 0.5rem;
}
.col-size { font-family: var(--font-mono); }
.col-act { display: flex; justify-content: flex-end; }
html:not(.is-touch) .row .col-act .copy-menu > .nav-btn { visibility: hidden; }
html:not(.is-touch) .row:hover .col-act .copy-menu > .nav-btn,
html:not(.is-touch) .row.is-active .col-act .copy-menu > .nav-btn,
.row .col-act .copy-menu > .nav-btn:focus-visible,
.row .col-act .copy-menu.is-open > .nav-btn { visibility: visible; }

/* ---- Notes, states ------------------------------------------------------ */
.note { color: var(--text-muted); font-size: 0.8rem; padding: 0.9rem 1rem; margin: 0; }
.state {
  display: flex; align-items: center; justify-content: center; gap: 0.6rem;
  flex-direction: column; flex: 1;
  color: var(--text-muted); font-size: 0.9rem;
  border: 1px dashed var(--border); border-radius: var(--radius-md);
  padding: 2.5rem 1rem; text-align: center;
}
.state svg { width: 16px; height: 16px; }
.state code { font-family: var(--font-mono); color: var(--text-secondary); }

/* ---- Copy menu ---------------------------------------------------------- */
.copy-menu { position: relative; display: inline-flex; }
.copy-pop {
  position: absolute; top: calc(100% + 4px); right: 0; z-index: var(--z-flyout);
  min-width: 260px; max-width: min(460px, 80vw);
  background: var(--bg-raised); border: 1px solid var(--border);
  border-radius: var(--radius-md); box-shadow: var(--shadow);
  padding: 0.25rem; display: flex; flex-direction: column; gap: 1px;
}
.copy-pop-item {
  display: flex; flex-direction: column; align-items: flex-start; gap: 1px;
  background: none; border: none; border-radius: var(--radius-sm); cursor: pointer;
  padding: 0.4rem 0.5rem; text-align: left; font: inherit; width: 100%; color: inherit;
}
.copy-pop-item:hover, .copy-pop-item:focus-visible { background: var(--accent-hover); }
.copy-pop-label { font-size: 0.76rem; font-weight: 600; color: var(--text-primary); }
.copy-pop-value {
  font-family: var(--font-mono); font-size: 0.66rem; color: var(--text-dim);
  max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

/* ---- Preview (dialog.mco-modal) ---------------------------------------- */
.preview-box {
  display: flex; flex-direction: column;
  width: min(1000px, calc(100vw - 3rem)); max-height: calc(100dvh - 4rem);
  background: var(--bg-surface); border: 1px solid var(--border);
  border-radius: 10px; box-shadow: var(--shadow); overflow: hidden;
}
.preview-head {
  display: flex; align-items: center; justify-content: space-between; gap: 1rem;
  padding: 0.6rem 0.75rem; border-bottom: 1px solid var(--border); background: var(--bg-raised);
}
.preview-title { display: flex; flex-direction: column; gap: 1px; min-width: 0; }
.preview-name { font-family: var(--font-mono); font-size: 0.85rem; font-weight: 700; overflow-wrap: anywhere; color: var(--text-primary); }
.preview-meta { font-size: 0.72rem; color: var(--text-secondary); }
.preview-actions { display: flex; align-items: center; gap: 0.35rem; flex-shrink: 0; }
.preview-actions a.nav-btn { text-decoration: none; }
.preview-content { flex: 1; min-height: 0; overflow: auto; background: var(--bg-deep); }
.preview-body {
  font-family: var(--font-mono); font-size: 0.74rem; line-height: 1.55;
  margin: 0; padding: 0.9rem; white-space: pre; color: var(--text-secondary);
}
.preview-state {
  display: flex; align-items: center; justify-content: center; gap: 0.5rem;
  padding: 3rem 1rem; color: var(--text-muted); font-size: 0.85rem;
}
.preview-state svg { width: 15px; height: 15px; }
.preview-state a { color: var(--accent-line); }
.preview-image { display: flex; align-items: center; justify-content: center; padding: 1rem; }
.preview-image img { max-width: 100%; max-height: 70vh; border-radius: 6px; }
.preview-foot {
  display: flex; align-items: center; justify-content: space-between; gap: 1rem;
  padding: 0.5rem 0.75rem; border-top: 1px solid var(--border);
  font-size: 0.74rem; color: var(--text-muted);
}
.preview-foot:empty { display: none; }
.preview-nav { display: flex; gap: 0.35rem; flex-shrink: 0; margin-left: auto; }
.preview-table { border-collapse: collapse; font-size: 0.74rem; width: 100%; }
.preview-table th, .preview-table td {
  border: 1px solid var(--border-glass); padding: 0.25rem 0.5rem;
  text-align: left; white-space: nowrap; font-family: var(--font-mono);
}
.preview-table th { position: sticky; top: 0; background: var(--bg-raised); color: var(--text-primary); font-weight: 700; }
.preview-table td { color: var(--text-secondary); }

/* ---- README / markdown prose -------------------------------------------- */
.readme { border-top: 1px solid var(--border); background: var(--bg-surface); }
.readme-head {
  font-family: var(--font-mono); font-size: 0.72rem; font-weight: 700;
  text-transform: uppercase; letter-spacing: 0.06em; color: var(--text-muted);
  margin: 0; padding: 0.6rem 1.1rem; border-bottom: 1px solid var(--border-glass);
}
.prose { padding: 1rem 1.2rem 1.5rem; font-size: 0.88rem; line-height: 1.65; color: var(--text-secondary); max-width: 62rem; }
.prose h1, .prose h2, .prose h3, .prose h4 { color: var(--text-primary); line-height: 1.25; margin: 1.4rem 0 0.6rem; }
.prose h1 { font-size: 1.4rem; } .prose h2 { font-size: 1.15rem; }
.prose h3 { font-size: 1rem; }   .prose h4 { font-size: 0.9rem; }
.prose > :first-child { margin-top: 0; }
.prose p, .prose ul, .prose ol, .prose blockquote, .prose pre, .prose table { margin: 0 0 0.85rem; }
.prose ul, .prose ol { padding-left: 1.3rem; }
.prose li { margin: 0.2rem 0; }
.prose a { color: var(--accent-line); text-decoration: underline; text-underline-offset: 2px; }
.prose code { font-family: var(--font-mono); font-size: 0.82em; background: var(--bg-raised); border-radius: 4px; padding: 0.1rem 0.3rem; }
.prose pre { background: var(--bg-deep); border: 1px solid var(--border); border-radius: 6px; padding: 0.75rem 0.9rem; overflow-x: auto; }
.prose pre code { background: none; padding: 0; font-size: 0.78rem; }
.prose blockquote { border-left: 3px solid var(--border); padding-left: 0.9rem; color: var(--text-muted); }
.prose hr { border: none; border-top: 1px solid var(--border); margin: 1.4rem 0; }
.prose table { border-collapse: collapse; font-size: 0.82rem; display: block; overflow-x: auto; }
.prose th, .prose td { border: 1px solid var(--border-glass); padding: 0.35rem 0.6rem; text-align: left; }
.prose th { background: var(--bg-raised); color: var(--text-primary); }
.prose img { max-width: 100%; border-radius: 6px; }

/* ---- Responsive --------------------------------------------------------- */
@media (max-width: 820px) {
  .row { grid-template-columns: minmax(0, 1fr) 74px 100px 44px; }
  .col-kind { display: none; }
}
@media (max-width: 640px) {
  .browser { padding: 0.7rem 0.75rem; }
  .row { grid-template-columns: minmax(0, 1fr) 70px 44px; }
  .col-date { display: none; }
  .search, .search input { width: 100%; }
  .toolbar-spacer { display: none; }
  .collection { flex-wrap: wrap; }
}
