/* Vinyl Studio refinements. All foundations come from Marzha + FBS / unified. */
:root {
  --ui-motion-feedback: var(--ds-motion-fast);
  --ui-motion-reveal: var(--ds-motion-normal);
  --ui-motion-ease: cubic-bezier(.2, 0, 0, 1);
}

/* Operate mode: stable type, useful density and one set of control states. */
html { scroll-padding-top: calc(var(--ds-header-height) + var(--ds-space-4)); }
.ds-page { font-synthesis: weight; }
button, input, select, textarea { transition: background-color var(--ui-motion-feedback) ease-out, border-color var(--ui-motion-feedback) ease-out, box-shadow var(--ui-motion-feedback) ease-out; }
button { position: relative; -webkit-tap-highlight-color: transparent; }
button:not(:disabled):active { background-color: var(--ds-surface-hover); }
button:is(.primary, [type="submit"], .ds-button--primary):not(:disabled):active { background-color: var(--ds-action-hover); }
button:disabled { opacity: .7; }
:is(input, textarea, select):focus-visible { outline-width: 2px; outline-offset: 2px; }
button[data-ui-pending="true"] { cursor: progress; color: transparent !important; }
button[data-ui-pending="true"] > * { opacity: 0; }
button[data-ui-pending="true"]::after {
  content: ""; position: absolute; inset-inline-start: calc(50% - 7px); top: calc(50% - 7px);
  width: 14px; height: 14px; color: var(--ds-accent); border: 2px solid currentColor;
  border-inline-end-color: transparent; border-radius: 50%;
}
button:is(.primary, [type="submit"], .ds-button--primary)[data-ui-pending="true"]::after { color: var(--ds-action-text); }
.ds-input[aria-invalid="true"] { background-color: var(--ds-surface); }
.surface > :first-child { margin-block-start: 0; }
.surface > h1, .surface > .heading, .production-heading { margin-block-end: var(--ds-space-5); }
.production-heading p { max-width: 70ch; margin-block-start: var(--ds-space-2); }
.workspace :is(h2, h3, legend) { text-wrap: balance; }
.workspace :is(p, dd) { text-wrap: pretty; }
.workspace :is(section, fieldset, .panel) { padding: var(--ds-space-5); }
.workspace section section { padding: var(--ds-space-4); }
.workspace section section:not(.metric):not(.route-stage):not(.capacity-readout) { box-shadow: none; }
.workspace .details { row-gap: var(--ds-space-2); }
.workspace .actions { gap: var(--ds-space-2); }
.workspace .tabs { gap: var(--ds-space-1); padding-block-end: var(--ds-space-2); }
.workspace .tabs button[aria-pressed="true"] { color: var(--ds-accent); background: var(--ds-accent-soft); border-color: transparent; box-shadow: none; }

/* Navigation: generous click targets without a second row of repeated titles. */
.top { gap: var(--ds-space-6); scrollbar-width: thin; overscroll-behavior: contain; }
.top nav { gap: var(--ds-space-5); }
.top nav a { min-height: 40px; padding: var(--ds-space-2) var(--ds-space-3); }
.top nav a[aria-current="page"] .nav-icon { stroke-width: 2; }
.nav-group-title { margin-inline: var(--ds-space-3); }
.shell-header { min-height: 56px; }
.shell-title { font-size: var(--ds-label-size); color: var(--ds-text-muted); }
.account { gap: var(--ds-space-1); }
.account button { min-height: 40px; }
.account studio-appearance { margin-block-end: var(--ds-space-2); }
.workspace { padding-block: var(--ds-space-6) var(--ds-space-8); }
.recovery:empty { min-height: 0; }
.shell-notices:has(> .recovery:only-child:empty) { display: none; }
.workspace > .surface > .owner-workspace { padding: 0; border: 0; border-radius: 0; background: transparent; }
.owner-workspace > .owner-tools { margin-block: var(--ds-space-6); }
.owner-workspace .owner-tool-list a { padding: var(--ds-space-4) var(--ds-space-3); }
.owner-workspace > section:has(> [data-source-system]) { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--ds-space-4); padding: 0; border: 0; background: transparent; }
.owner-workspace > section:has(> [data-source-system]) > h3 { grid-column: 1 / -1; margin-block: var(--ds-space-4) 0; }
.owner-workspace [data-source-system] { margin: 0; }
.owner-workspace [data-source-system] > h4 { margin-block: 0 var(--ds-space-3); }
.owner-workspace [data-source-system] > p:last-child { margin-block-end: 0; }

/* Lists read as lists. Table structure stays visible; mobile keeps every value. */
.table-scroll, .scroll { border-radius: var(--ds-radius-control); }
.ui-scrollable { border: 1px solid var(--ds-border); background: var(--ds-surface); }
.ui-scrollable::before { content: "Таблица шире экрана — прокрути вправо"; display: block; position: sticky; inset-inline-start: 0; width: fit-content; max-width: 100%; padding: var(--ds-space-2) var(--ds-space-3); color: var(--ds-text-muted); background: var(--ds-surface-soft); font-size: var(--ds-caption-size); }
.ds-table { border-collapse: collapse; }
.ds-table th { padding: var(--ds-space-3); line-height: var(--ds-label-line-height); }
.ds-table td { height: var(--ds-row-height-compact); padding: var(--ds-space-3); line-height: var(--ds-body-line-height); }
.ds-table td small { margin-block-start: var(--ds-space-1); line-height: var(--ds-caption-line-height); }
.ds-table :is(td, th):last-child { padding-inline-end: var(--ds-space-4); }
.ds-table td button:not(.text-link) { min-height: var(--ds-control-height-compact); }
.orders-table .order-title-link { justify-content: start; text-align: start; font-size: var(--ds-body-size); font-weight: 600; line-height: var(--ds-body-line-height); white-space: normal; overflow-wrap: break-word; }
table caption { text-align: start; font-weight: 600; padding: var(--ds-space-2) var(--ds-space-3); color: var(--ds-text); }
details > summary { min-height: var(--ds-control-height); align-content: center; }
details > summary:focus-visible { border-radius: var(--ds-radius-control); }
details[open] > summary { margin-block-end: var(--ds-space-3); }

/* Feedback remains near the action; errors never disappear on a timer. */
#message:not(:empty) {
  display: flex; align-items: center; gap: var(--ds-space-4); left: auto; right: var(--ds-space-6);
  bottom: max(var(--ds-space-6), env(safe-area-inset-bottom)); transform: none;
  max-width: min(520px, calc(100% - 32px)); padding: var(--ds-space-3) var(--ds-space-4);
  color: var(--ds-text); background: var(--ds-surface); border: 1px solid var(--ds-border); border-radius: var(--ds-radius-panel);
}
#message[data-tone="success"] { color: var(--ds-success); background: var(--ds-success-soft); }
#message[data-tone="warning"] { color: var(--ds-warning); background: var(--ds-warning-soft); }
#message[data-tone="error"] { color: var(--ds-danger); background: var(--ds-danger-soft); }
.ui-notice-text { min-width: 0; overflow-wrap: anywhere; }
.ui-notice-close { flex: none; background: transparent; color: inherit; border-color: currentColor; min-height: 36px; padding: var(--ds-space-1) var(--ds-space-2); font-size: var(--ds-caption-size); }
.surface-loading { padding: var(--ds-space-2) 0; gap: var(--ds-space-3); }
.surface-loading > span { font-size: var(--ds-label-size); }
.skeleton-heading { width: min(45%, 260px); margin-block: var(--ds-space-2); }
.skeleton-row { height: var(--ds-row-height); background: var(--ds-border); opacity: .65; }
.error:empty, [role="alert"]:empty { display: none; }
.error:not(:empty), [role="alert"]:not(:empty) { line-height: 1.5; }
dialog { padding: var(--ds-space-6); }
dialog > h2 { padding-inline-end: var(--ds-space-5); }
dialog > form { gap: var(--ds-space-4); }
dialog::backdrop { background: color-mix(in srgb, var(--ds-text) 36%, transparent); }

@media (hover: hover) and (pointer: fine) {
  .top nav a:not([aria-current="page"]):hover, .account button:hover { background: var(--ds-surface-soft); color: var(--ds-text); }
  .ds-table tbody tr:hover td { background: var(--ds-surface-soft); }
  .ds-table tbody tr[aria-selected="true"]:hover td { background: var(--ds-accent-soft); }
  .ui-notice-close:hover { color: var(--ds-text); background: var(--ds-surface-hover); }
}

@media (prefers-reduced-motion: no-preference) {
  button { transition: background-color var(--ui-motion-feedback) ease-out, border-color var(--ui-motion-feedback) ease-out, transform var(--ui-motion-feedback) ease-out; }
  button:not(:disabled):not([aria-disabled="true"]):not(.planner-queue-entry):not(.planner-operation-choice):not(.team-calendar-day):active { transform: scale(.96); }
  button[data-ui-pending="true"]::after { animation: ui-pending .7s linear infinite; }
  .skeleton-row { animation: ui-skeleton 1.4s ease-in-out infinite alternate; }
  dialog[open], #message:not(:empty) { animation: ui-reveal var(--ui-motion-reveal) var(--ui-motion-ease); }
  details[open] > :not(summary) { animation: ui-detail var(--ui-motion-feedback) ease-out; }
  .ui-theme-changing, .ui-theme-changing :is(body, .top, .shell-header, .workspace, section, fieldset, table, th, td, dialog, input, select, textarea, .ds-button, .signin, .identity) { transition: background-color var(--ui-motion-reveal) ease-out, color var(--ui-motion-reveal) ease-out, border-color var(--ui-motion-reveal) ease-out; }
  @keyframes ui-pending { to { transform: rotate(1turn); } }
  @keyframes ui-skeleton { to { opacity: .3; } }
  @keyframes ui-reveal { from { opacity: .4; transform: translateY(4px); } to { opacity: 1; transform: none; } }
  @keyframes ui-detail { from { opacity: .5; } to { opacity: 1; } }
}

@media (max-width: 760px) {
  .workspace { padding: var(--ds-content-padding-mobile); padding-block-end: calc(var(--ds-space-6) + env(safe-area-inset-bottom)); }
  .workspace :is(section, fieldset, .panel) { padding: var(--ds-space-4); }
  .workspace section section { padding: var(--ds-space-3); }
  .owner-workspace > section:has(> [data-source-system]) { grid-template-columns: minmax(0, 1fr); }
  .shell-header { min-height: 56px; padding-inline: var(--ds-content-padding-mobile); gap: var(--ds-space-2); }
  .shell-timezone { max-width: 35%; white-space: normal; text-align: end; font-size: var(--ds-caption-size); }
  .shell-title { min-width: 0; }
  button, select, input:not([type="checkbox"]):not([type="radio"]), summary { min-height: var(--ds-control-height-touch); }
  .workspace :is(input, select, textarea), dialog :is(input, select, textarea) { font-size: 16px; }
  .ds-table td button:not(.text-link) { min-height: var(--ds-control-height-touch); }
  dialog { width: calc(100% - 24px); max-height: calc(100dvh - 24px); padding: var(--ds-space-4); }
  #message:not(:empty) { right: var(--ds-content-padding-mobile); bottom: max(var(--ds-content-padding-mobile), env(safe-area-inset-bottom)); gap: var(--ds-space-2); }
  .ui-notice-close { min-height: var(--ds-control-height-touch); }
  table[data-responsive="records"] { display: block; border: 0; }
  table[data-responsive="records"] > thead { position: absolute; width: 1px; height: 1px; clip-path: inset(50%); overflow: hidden; }
  table[data-responsive="records"] > tbody { display: grid; gap: var(--ds-space-3); }
  table[data-responsive="records"] > tbody > tr { display: grid; border: 1px solid var(--ds-border); border-radius: var(--ds-radius-control); overflow: clip; background: var(--ds-surface); }
  table[data-responsive="records"] > tbody > tr > :is(td, th) { display: grid; grid-template-columns: minmax(5rem, 32%) minmax(0, 1fr); gap: var(--ds-space-2); min-height: 0; height: auto; padding: var(--ds-space-3); border: 0; border-block-end: 1px solid var(--ds-border); background: transparent; text-align: start; }
  table[data-responsive="records"] > tbody > tr > :is(td, th)::before { content: attr(data-label); font-size: var(--ds-caption-size); color: var(--ds-text-muted); font-weight: 500; align-self: center; grid-column: 1; }
  table[data-responsive="records"] > tbody > tr > :is(td, th) > * { grid-column: 2; min-width: 0; }
  table[data-responsive="records"] > tbody > tr > :is(td, th):first-child { background: var(--ds-surface-soft); font-weight: 600; }
  table[data-responsive="records"] > tbody > tr > :is(td, th):last-child { border-block-end: 0; }
  table[data-responsive="records"] > tbody > tr[data-ui-empty-row="true"] > td { display: block; }
  table[data-responsive="records"] > tbody > tr[data-ui-empty-row="true"] > td::before { content: none; }
}

@media (max-width: 380px) {
  .workspace .details { grid-template-columns: minmax(0, 1fr); gap: var(--ds-space-1); }
  .workspace .details dd { margin-block-end: var(--ds-space-3); }
  .shell-timezone { display: none; }
}

@media (hover: none) {
  .ds-table tbody tr:hover td { background: var(--ds-surface); }
  .ds-table tbody tr[aria-selected="true"]:hover td { background: var(--ds-accent-soft); }
  .ds-button:hover { background: var(--ds-surface); }
  .ds-button--primary:hover { background: var(--ds-action); }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; scroll-behavior: auto !important; }
}

@media (forced-colors: active) {
  #message:not(:empty), .ui-scrollable { border: 1px solid CanvasText; }
  button[data-ui-pending="true"]::after { border-color: ButtonText; border-inline-end-color: transparent; }
}
