/* Sharecrate workspace. Root rules are scoped to .uwapp-root.uwapp-sharecrate (the body carries the app class too).
   Light and dark tokens follow html[data-theme] / prefers-color-scheme (DESIGN_SYSTEM.md §9). CSP: no inline styles. */
.uwapp-root.uwapp-sharecrate {
  --sc-bg: var(--canvas); --sc-surface: var(--surface); --sc-surface-2: var(--surface-2); --sc-ink: var(--ink); --sc-muted: var(--muted);
  --sc-line: var(--line); --sc-control: var(--control); --sc-accent: var(--primary); --sc-accent-ink: var(--primary-text); --sc-on-accent: var(--on-accent);
  --sc-danger: var(--danger); --sc-sel: var(--info-bg); --sc-focus: var(--focus-color); --sc-drop: #fff4e0; --sc-warn-ink: #7a3b00; --sc-good: #0d5a2e;
  --sc-shadow: var(--shadow-2); --sc-dlg-shadow: var(--shadow-3);
  background: var(--sc-bg); color: var(--sc-ink); color-scheme: light; font-family: var(--font-sans); position: relative;
}
:root[data-theme="dark"] .uwapp-root.uwapp-sharecrate {
  --sc-bg: var(--d-canvas); --sc-surface: var(--d-surface); --sc-surface-2: var(--d-surface-2); --sc-ink: var(--d-ink); --sc-muted: var(--d-muted);
  --sc-line: var(--d-line); --sc-control: var(--d-control); --sc-accent: var(--d-primary); --sc-accent-ink: var(--d-focus); --sc-on-accent: var(--d-on-accent);
  --sc-danger: var(--d-danger); --sc-sel: var(--d-info-bg); --sc-focus: var(--d-focus); --sc-drop: #3a2a12; --sc-warn-ink: #ffd8a8; --sc-good: #9be3b5;
  --sc-shadow: var(--d-shadow-2); --sc-dlg-shadow: 0 16px 48px rgb(0 0 0 / .55);
  color-scheme: dark;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .uwapp-root.uwapp-sharecrate {
    --sc-bg: var(--d-canvas); --sc-surface: var(--d-surface); --sc-surface-2: var(--d-surface-2); --sc-ink: var(--d-ink); --sc-muted: var(--d-muted);
    --sc-line: var(--d-line); --sc-control: var(--d-control); --sc-accent: var(--d-primary); --sc-accent-ink: var(--d-focus); --sc-on-accent: var(--d-on-accent);
    --sc-danger: var(--d-danger); --sc-sel: var(--d-info-bg); --sc-focus: var(--d-focus); --sc-drop: #3a2a12; --sc-warn-ink: #ffd8a8; --sc-good: #9be3b5;
    --sc-shadow: var(--d-shadow-2); --sc-dlg-shadow: 0 16px 48px rgb(0 0 0 / .55);
    color-scheme: dark;
  }
}

/* Platform element defaults leak into app workspaces: reset them at zero specificity. */
:where(.sc-app, .sc-dlg, .sc-menu) button { font: inherit; font-size: .9rem; font-weight: 600; padding: 0; border: 0; border-radius: 8px; background: none; color: inherit; cursor: pointer; width: auto; min-height: 0; margin: 0; box-shadow: none; }
:where(.sc-app, .sc-dlg, .sc-menu) button:hover { background: none; }
:where(.sc-app, .sc-dlg) :is(input, select, textarea) { font: inherit; color: var(--sc-ink); background: var(--sc-surface); border: 1px solid var(--sc-control); border-radius: 8px; width: auto; margin: 0; padding: 6px 8px; min-height: 36px; }
:where(.sc-app, .sc-dlg) :is(input[type="checkbox"], input[type="radio"]) { min-height: 0; width: 18px; height: 18px; padding: 0; accent-color: var(--sc-accent); }
:where(.sc-app, .sc-dlg) table { border-collapse: collapse; width: 100%; margin: 0; font-size: .9rem; }
:where(.sc-app, .sc-dlg) :is(th, td) { text-align: start; padding: 6px 8px; border-bottom: 1px solid var(--sc-line); vertical-align: middle; background: none; color: inherit; }
:where(.sc-app, .sc-dlg) thead th { font-size: .8rem; color: var(--sc-muted); font-weight: 600; background: none; }
:where(.sc-app, .sc-dlg) :is(h1, h2, h3) { color: var(--sc-ink); margin: 0; line-height: 1.25; }
:where(.sc-app, .sc-dlg) a { color: var(--sc-accent-ink); }
:where(.sc-app, .sc-dlg, .sc-menu) :focus-visible { outline: 3px solid var(--sc-focus); outline-offset: 2px; }
.uwapp-root.uwapp-sharecrate [hidden] { display: none !important; }

.sc-sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.sc-app { display: flex; flex-direction: column; height: 100%; min-height: 0; }

/* toolbar */
.sc-bar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; padding: 10px 14px; border-bottom: 1px solid var(--sc-line); background: var(--sc-surface); }
.sc-bar:empty { display: none; }
.sc-btn { display: inline-flex; align-items: center; gap: 6px; padding: 7px 12px !important; min-height: 36px !important; border: 1px solid var(--sc-control) !important; background: var(--sc-surface) !important; color: var(--sc-ink) !important; border-radius: 8px; white-space: nowrap; }
.sc-btn:hover:not([disabled]) { background: var(--sc-surface-2) !important; }
.sc-btn.sc-primary { background: var(--sc-accent) !important; border-color: var(--sc-accent) !important; color: var(--sc-on-accent) !important; }
.sc-btn.sc-primary:hover:not([disabled]) { filter: brightness(1.08); background: var(--sc-accent) !important; }
.sc-btn[disabled], .sc-btn[aria-disabled="true"] { color: var(--sc-muted) !important; background: var(--sc-surface-2) !important; border-color: var(--sc-line) !important; cursor: not-allowed; }
.sc-btn.sc-primary[disabled] { color: var(--sc-muted) !important; background: var(--sc-surface-2) !important; }
.sc-btn.sc-ws { max-width: 220px; overflow: hidden; text-overflow: ellipsis; }
.sc-icon-btn { min-width: 32px; min-height: 32px !important; padding: 2px 8px !important; font-size: 1.1rem !important; border-radius: 8px; color: var(--sc-ink); }
.sc-icon-btn:hover { background: var(--sc-surface-2) !important; }
.sc-search { flex: 1 1 180px; min-width: 140px; max-width: 360px; }
.sc-meter { display: inline-flex; flex-direction: column; gap: 3px; align-items: stretch; margin-inline-start: auto; padding: 4px 8px !important; border-radius: 8px; color: var(--sc-ink) !important; min-width: 120px; }
.sc-meter:hover { background: var(--sc-surface-2) !important; }
.sc-meter-label { font-size: .78rem; color: var(--sc-muted); font-weight: 600; }
.sc-meter-track { display: block; height: 6px; border-radius: 3px; background: var(--sc-line); overflow: hidden; }
.sc-meter-fill { display: block; height: 100%; width: 0; background: var(--sc-accent); }
.sc-meter-full { background: var(--sc-danger); }

/* body */
.sc-body { display: grid; grid-template-columns: minmax(180px, 230px) minmax(0, 1fr) minmax(240px, 300px); flex: 1 1 0; min-height: 0; }
.sc-side { border-inline-end: 1px solid var(--sc-line); background: var(--sc-surface); padding: 12px 8px; overflow: auto; }
.sc-side-h { font-size: .8rem !important; color: var(--sc-muted) !important; text-transform: uppercase; letter-spacing: .04em; margin: 0 8px 8px !important; }
.sc-tree, .sc-tree ul { list-style: none; margin: 0; padding: 0; }
.sc-tree ul { padding-inline-start: 14px; }
.sc-tree-btn { display: flex; align-items: center; gap: 6px; width: 100% !important; padding: 6px 8px !important; border-radius: 8px; text-align: start; font-weight: 500 !important; color: var(--sc-ink); min-height: 32px !important; }
.sc-tree-btn span:not(.sc-ico) { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sc-tree-btn:hover { background: var(--sc-surface-2) !important; }
.sc-tree-btn.sc-on { background: var(--sc-sel) !important; font-weight: 700 !important; }
.sc-trash-btn { margin-top: 12px; }
.sc-main { padding: 14px; min-width: 0; min-height: 0; position: relative; overflow: auto; }
.sc-main.sc-can-drop.sc-drop-on, .sc-drop-on > td, li.sc-drop-on .sc-card, .sc-tree-btn.sc-drop-on { background: var(--sc-drop) !important; outline: 2px dashed var(--sc-accent); outline-offset: -2px; }
.sc-main-head { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; margin-bottom: 10px; }
.sc-h1 { font-size: 1.25rem !important; }
.sc-crumbs ol { display: flex; flex-wrap: wrap; align-items: center; gap: 4px; list-style: none; margin: 0; padding: 0; font-size: 1.05rem; }
.sc-crumbs li + li::before { content: "/"; color: var(--sc-muted); margin-inline-end: 4px; }
.sc-crumb { padding: 2px 6px !important; border-radius: 6px; color: var(--sc-accent-ink) !important; text-decoration: underline; font-weight: 600 !important; font-size: 1rem !important; }
.sc-crumbs [aria-current] { font-weight: 700; }
.sc-ro { margin: 0; font-size: .85rem; color: var(--sc-muted); }
.sc-filters { display: flex; flex-wrap: wrap; gap: 8px; }
.sc-hint { color: var(--sc-muted); font-size: .85rem; margin: 4px 0; }
.sc-note { padding: 8px 12px; border-radius: 8px; background: var(--sc-surface-2); }
.sc-error { color: var(--sc-danger); }
.sc-empty { padding: 40px 16px; text-align: center; color: var(--sc-muted); border: 2px dashed var(--sc-line); border-radius: 12px; }
.sc-empty .sc-btn { margin-top: 8px; }

/* list */
.sc-table-wrap { overflow-x: auto; position: relative; border: 1px solid var(--sc-line); border-radius: 10px; background: var(--sc-surface); }
.sc-table tbody tr:hover { background: var(--sc-surface-2); }
.sc-table tr.sc-sel { background: var(--sc-sel); }
.sc-table td, .sc-table th { white-space: nowrap; }
.sc-c-sel { width: 34px; }
.sc-c-name { width: 100%; max-width: 0; }
.sc-c-act { width: 40px; text-align: end; }
.sc-name { display: flex; align-items: center; gap: 8px; max-width: 100%; text-align: start; padding: 4px 2px !important; font-weight: 500 !important; color: var(--sc-ink); }
.sc-name-t { overflow: hidden; text-overflow: ellipsis; }
.sc-name:hover .sc-name-t { text-decoration: underline; }
.sc-path { color: var(--sc-muted); font-size: .8rem; font-weight: 400; margin-inline-start: 6px; }
.sc-badge { font-size: .75rem; }

/* icons (CSS shapes, colour = type) */
.sc-ico { display: inline-block; flex: none; width: 20px; height: 16px; border-radius: 3px; background: var(--sc-muted); position: relative; }
.sc-ico-folder { background: #d98e04; border-radius: 2px 6px 3px 3px; }
.sc-ico-drive { background: var(--sc-accent); }
.sc-ico-image { background: #2f855a; }
.sc-ico-document { background: #c53030; }
.sc-ico-spreadsheet { background: #2b6cb0; }
.sc-ico-presentation { background: #c05621; }
.sc-ico-text, .sc-ico-code { background: #4a5568; }
.sc-ico-audio { background: #805ad5; }
.sc-ico-video { background: #b83280; }
.sc-ico-archive { background: #975a16; }
.sc-ico-trash { background: var(--sc-muted); border-radius: 2px 2px 5px 5px; width: 16px; }
.sc-ico-xl { width: 64px; height: 52px; border-radius: 8px; }

/* grid */
.sc-grid { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 10px; }
.sc-card { display: flex; flex-direction: column; align-items: stretch; gap: 6px; width: 100% !important; padding: 8px !important; border: 1px solid var(--sc-line) !important; background: var(--sc-surface) !important; border-radius: 10px; text-align: start; color: var(--sc-ink); }
.sc-card.sc-sel { background: var(--sc-sel) !important; border-color: var(--sc-accent) !important; }
.sc-thumb { display: grid; place-items: center; height: 96px; border-radius: 6px; background: var(--sc-surface-2); overflow: hidden; }
.sc-thumb .sc-ico { width: 40px; height: 32px; }
.sc-thumb-img { width: 100%; height: 100%; object-fit: cover; }
.sc-card-name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sc-card-meta { font-size: .8rem; color: var(--sc-muted); font-weight: 400; }

/* details */
.sc-details { border-inline-start: 1px solid var(--sc-line); background: var(--sc-surface); padding: 14px; overflow: auto; overflow-wrap: anywhere; }
.sc-det-h { font-size: 1.05rem !important; margin: 8px 0 10px !important; }
.sc-det-thumb { display: grid; place-items: center; min-height: 120px; border-radius: 10px; background: var(--sc-surface-2); overflow: hidden; }
.sc-det-img { max-width: 100%; max-height: 220px; object-fit: contain; }
.sc-dl { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 4px 12px; font-size: .88rem; margin: 0 0 12px; }
.sc-dl dt { color: var(--sc-muted); }
.sc-dl dd { margin: 0; }
.sc-det-actions { display: flex; flex-wrap: wrap; gap: 8px; }

/* uploads + status */
.sc-uploads { border-top: 1px solid var(--sc-line); background: var(--sc-surface); padding: 10px 14px; max-height: 40vh; overflow: auto; }
.sc-up-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 6px; }
.sc-up-head h2 { font-size: 1rem !important; }
.sc-up-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.sc-up { display: grid; grid-template-columns: minmax(0, 2fr) minmax(80px, 1fr) minmax(0, 1.4fr) auto; gap: 10px; align-items: center; font-size: .88rem; }
.sc-up-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sc-up progress { width: 100%; height: 10px; accent-color: var(--sc-accent); }
.sc-up-error .sc-up-state { color: var(--sc-danger); }
.sc-up-done .sc-up-state { color: var(--sc-good); }
.sc-up-warn { color: var(--sc-warn-ink); }
.sc-status { margin: 0; padding: 6px 14px; min-height: 1.6em; font-size: .88rem; border-top: 1px solid var(--sc-line); background: var(--sc-surface); color: var(--sc-ink); }
.sc-status[data-kind="error"] { color: var(--sc-danger); font-weight: 600; }

/* welcome */
.sc-body:has(> .sc-side[hidden]):has(> .sc-details[hidden]) { grid-template-columns: minmax(0, 1fr); }
.sc-uploads { flex: none; }
.sc-welcome { max-width: 860px; margin: 24px auto; padding: 0 8px; }
.sc-welcome h1 { font-size: 1.6rem !important; margin: 8px 0 !important; }
.sc-welcome h2 { font-size: 1.2rem !important; margin: 24px 0 8px !important; }
.sc-plans { list-style: none; padding: 0; margin: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 12px; }
.sc-plan { border: 1px solid var(--sc-line); border-radius: 12px; padding: 12px; background: var(--sc-surface); }
.sc-plan-on { border-color: var(--sc-accent); box-shadow: 0 0 0 2px var(--sc-accent); }
.sc-plan h3 { font-size: 1rem !important; }
.sc-plan-tree { font-size: .85rem; color: var(--sc-muted); padding-inline-start: 18px; margin: 6px 0 10px; }

/* menus */
.sc-menu { position: absolute; z-index: 60; background: var(--sc-surface); color: var(--sc-ink); border: 1px solid var(--sc-line); border-radius: 10px; box-shadow: var(--sc-shadow); padding: 4px; display: flex; flex-direction: column; max-height: 75vh; overflow: auto; }
.sc-menu [role="menuitem"] { text-align: start; padding: 8px 10px !important; border-radius: 6px; font-weight: 500 !important; color: var(--sc-ink); min-height: 34px !important; }
.sc-menu [role="menuitem"]:hover, .sc-menu [role="menuitem"]:focus { background: var(--sc-surface-2) !important; }
.sc-menu [aria-disabled="true"] { color: var(--sc-muted); cursor: not-allowed; }
.sc-menu-sep { height: 1px; background: var(--sc-line); margin: 4px 0; }

/* dialogs */
.sc-dlg { border: 1px solid var(--sc-line); border-radius: 14px; padding: 0; width: min(560px, calc(100vw - 24px)); max-height: calc(100dvh - 32px); background: var(--sc-surface); color: var(--sc-ink); box-shadow: var(--sc-dlg-shadow); }
.sc-dlg-wide { width: min(940px, calc(100vw - 24px)); }
.sc-dlg::backdrop { background: rgb(0 0 0 / .45); }
.sc-dlg-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 12px 16px; border-bottom: 1px solid var(--sc-line); position: sticky; top: 0; background: var(--sc-surface); z-index: 1; }
.sc-dlg-head h2 { font-size: 1.1rem !important; overflow-wrap: anywhere; }
.sc-dlg-x { font-size: 1.4rem !important; }
.sc-dlg-body { padding: 14px 16px; display: grid; gap: 10px; }
.sc-dlg-foot { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 8px; padding: 0 16px 14px; }
.sc-dlg-foot:empty { display: none; }
.sc-form .sc-dlg-foot { padding: 6px 0 0; }
.sc-dlg-msg { margin: 0 16px; font-size: .88rem; }
.sc-dlg-msg:empty { display: none; }
.sc-dlg-msg[data-kind="error"] { color: var(--sc-danger); font-weight: 600; margin-bottom: 8px; }
.sc-form { display: grid; gap: 10px; }
.sc-field { display: grid; gap: 4px; }
.sc-field label { font-weight: 600; font-size: .9rem; }
.sc-field :is(input, select) { width: 100%; }
.sc-form fieldset { border: 1px solid var(--sc-line); border-radius: 10px; padding: 8px 12px 12px; display: grid; gap: 8px; margin: 0; }
.sc-form legend { font-weight: 700; padding: 0 4px; }
.sc-check { display: inline-flex; gap: 8px; align-items: center; }
.sc-pick { display: grid; max-height: 50vh; overflow: auto; border: 1px solid var(--sc-line); border-radius: 10px; padding: 4px; }
.sc-pick-row { display: flex; align-items: center; gap: 8px; padding: 6px 8px; border-radius: 6px; cursor: pointer; }
.sc-pick-row:has(input:checked) { background: var(--sc-sel); font-weight: 600; }
.sc-pick-row:has(input:disabled) { color: var(--sc-muted); cursor: not-allowed; }
.sc-links { list-style: none; padding: 0; margin: 0; display: grid; gap: 6px; }
.sc-links li { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; justify-content: space-between; font-size: .88rem; }
.sc-link-out:empty { display: none; }
.sc-v-act { display: flex; gap: 6px; flex-wrap: wrap; }
.sc-meter-big progress { width: 100%; height: 12px; accent-color: var(--sc-accent); }

/* preview */
.sc-pv-nav { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; padding: 8px 16px; border-bottom: 1px solid var(--sc-line); }
.sc-pv-count { color: var(--sc-muted); font-size: .88rem; }
.sc-pv-img { max-width: 100%; max-height: 70vh; object-fit: contain; margin: 0 auto; display: block; background: repeating-conic-gradient(#ccc 0 25%, #fff 0 50%) 50% / 16px 16px; }
.sc-pv-pdf iframe { width: 100%; height: 70vh; border: 1px solid var(--sc-line); border-radius: 8px; background: #fff; }
.sc-pv-video { width: 100%; max-height: 70vh; background: #000; }
.sc-pv-audio { width: 100%; }
.sc-pv-text { max-height: 65vh; overflow: auto; white-space: pre-wrap; overflow-wrap: anywhere; font-size: .85rem; background: var(--sc-surface-2); color: var(--sc-ink); padding: 12px; border-radius: 8px; margin: 0; }
.sc-pv-md { max-height: 65vh; overflow: auto; padding: 4px 8px; line-height: 1.55; }
.sc-pv-md pre { background: var(--sc-surface-2); padding: 8px; border-radius: 6px; overflow: auto; }
.sc-pv-md table { width: auto; }
.sc-pv-md :is(h1, h2, h3, h4) { margin: .7em 0 .35em; }
.sc-pv-md > :first-child { margin-top: 0; }
.sc-pv-none { text-align: center; padding: 32px; }

/* responsive */
@media (max-width: 1100px) {
  .sc-body { grid-template-columns: minmax(170px, 210px) minmax(0, 1fr); grid-auto-rows: max-content; overflow: auto; }
  .sc-side { max-height: none; }
  .sc-main { overflow: visible; }
  .sc-details { grid-column: 1 / -1; border-inline-start: 0; border-top: 1px solid var(--sc-line); }
}
@media (max-width: 760px) {
  .sc-body { grid-template-columns: minmax(0, 1fr); align-content: start; }
  .sc-side { order: 2; border-inline-end: 0; border-top: 1px solid var(--sc-line); max-height: 40vh; }
  .sc-main { order: 1; padding: 10px; }
  .sc-details { order: 3; }
  .sc-c-by, .sc-table th.sc-c-by { display: none; }
  .sc-meter { margin-inline-start: 0; flex: 1 1 100%; }
  .sc-search { max-width: none; }
  .sc-up { grid-template-columns: minmax(0, 1fr) auto; }
  .sc-up progress, .sc-up-state { grid-column: 1 / -1; }
  .sc-grid { grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); }
  :where(.sc-app, .sc-dlg) :is(input[type="checkbox"], input[type="radio"]) { width: 24px; height: 24px; }
}
@media (prefers-reduced-motion: reduce) {
  .uwapp-root.uwapp-sharecrate * { transition: none !important; animation: none !important; }
}
