/* Shared screen refinement. Keep print geometry and theme palettes independent. */
@media screen {
  #appShell { --field-width: 280px; }
  #appShell .view { min-width: 0; }
  #appShell :is(.section-heading, .workflow-heading, .area-section-heading) { gap: 12px; flex-wrap: wrap; }
  #appShell .section-heading { margin-bottom: 16px; }
  #appShell :is(.section-heading, .workflow-heading) :is(h2, h3) { line-height: 1.3; }
  #appShell :is(.section-heading, .workflow-heading) .eyebrow { margin-bottom: 5px; }
  #appShell :is(.workflow-heading, .area-section-heading) h2 { font-size: 23px; }
  #appShell :is(.workflow-view, .settings-grid) h3 { font-size: 17px; }
  #appShell :is(.workflow-metrics, .report-summary-grid, .cash-summary-grid) { gap: 10px; }
  #appShell :is(.workflow-metrics article, .report-summary-card, .cash-day-summary-card) { min-width: 0; min-height: 0; padding: 14px; border: 1px solid var(--line); border-radius: 8px; box-shadow: none; }
  #appShell :is(.workflow-metrics, .report-summary-grid) strong { overflow-wrap: anywhere; }
  #appShell :is(.report-panel, .time-card, .manage-card, .about-card) { min-width: 0; padding: 16px; border-radius: 8px; box-shadow: none; }
  #appShell :is(.report-panel, .time-card, .manage-card, .about-card):hover { box-shadow: none; transform: none; }
  #appShell :is(.reports-layout, .time-layout, .workflow-columns) { gap: 16px; }
  #appShell .workflow-heading { margin: 4px 0 18px; }
  #appShell .workflow-view h3 { margin-top: 22px; }
  #appShell .workflow-row { padding: 12px 0; gap: 12px; border-color: var(--line); }
  #appShell .workflow-row p { margin: 4px 0; }
  #appShell .workflow-actions { gap: 8px; margin-block: 14px; }
  #appShell .workflow-empty { padding: 12px 0; color: var(--muted); opacity: 1; }
  #appShell :is(.workflow-badge, .status-pill) { font-size: 11px; font-weight: 500; }
  #appShell :is(.notice, .workflow-notice) { padding: 11px 12px; border-radius: 8px; font-size: 12px; line-height: 1.5; }
  #appShell :is(.manage-tabs, .task-controls, .operation-controls) { gap: 8px; }
  #appShell .manage-tabs { width: fit-content; max-width: 100%; padding: 4px; border-radius: 8px; box-shadow: none; }
  #appShell .manage-tab { border-radius: 6px; font-size: 12px; font-weight: 500; }
  #appShell :is(.template-item, .sidebar-option-row) { border-radius: 8px; box-shadow: none; }
  #appShell :is(.department-task-card, .operation-task) { border-radius: 8px; box-shadow: none; }
  #appShell .operation-task { padding: 9px 11px; }
  #appShell :is(.cash-toolbar, .task-controls) { align-items: center; }
  #appShell :is(.cash-form-title, .cash-card-header) { gap: 10px; }

  /* Settings follow department-style rows instead of full-width input strips. */
  #settingsView .settings-group { border-bottom: 1px solid var(--line); }
  #settingsView .settings-group > summary { padding-block: 15px; }
  #settingsView .settings-group-content { gap: 12px; padding-bottom: 18px; }
  #settingsView .settings-group-content > label:has(> :is(select, input[type="text"], input[type="number"])):not(.check-row),
  #settingsView .settings-group-content > .two-cols > label:has(> :is(select, input[type="text"], input[type="number"])) { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, var(--field-width)); align-items: center; gap: 14px; margin: 0; }
  #settingsView .settings-group-content > .two-cols:has(> label > :is(select, input[type="text"], input[type="number"])) { grid-template-columns: minmax(0, 1fr); gap: 12px; }
  #settingsView .settings-group-content label:has(> input[type="number"]) { grid-template-columns: minmax(0, 1fr) 112px; }
  #settingsView .settings-group-content label > input[type="number"] { width: 112px; justify-self: end; text-align: right; }
  #settingsView .settings-group-content > label > small { grid-column: 1 / -1; }
  #settingsView .settings-group-content :is(input, select) { min-width: 0; }
  #settingsView :is(.settings-copy, .workspace-request-status) { font-size: 12px; line-height: 1.5; }
  #settingsView .sidebar-option-list { gap: 6px; }
  #settingsView .sidebar-option-row { min-height: 42px; padding: 5px 9px; }
  #appShell :is(.tasks-table, .timesheet-table, .area-table) { font-size: 12px; }
  #appShell :is(.tasks-table, .timesheet-table, .area-table) :is(th, td) { padding: 10px 9px; border-color: var(--line); }
  #appShell :is(.tasks-table, .timesheet-table, .area-table) th { font-size: 11px; font-weight: 600; }
  #appShell :is(.area-filters, .area-section-heading, .area-toolbar) { gap: 10px; }
  #appShell :is(.area-shop-facts, .staff-profile-facts) { margin-block: 10px; }

  /* Keep specialised department, staff and cash editors' existing field grids. */
  dialog { border-radius: 12px; }
  dialog .dialog-body { padding: 20px; gap: 14px; }
  dialog .dialog-body > header { padding-bottom: 12px; border-bottom: 1px solid var(--line); }
  dialog .dialog-body > header h3 { margin: 0; font-size: 18px; line-height: 1.35; }
  dialog .dialog-body > footer { margin-top: 8px; padding-top: 14px; border-top: 1px solid var(--line); }
  :is(#shiftDialog, #taskDialog, #timeOffDialog, #accountDialog, #templateDialog, #calendarDialog, #copyWeekDialog, #copyShiftsDialog, #moveLocationDialog) { width: min(560px, calc(100vw - 28px)); }
  :is(#shiftDialog, #taskDialog, #timeOffDialog, #accountDialog, #templateDialog, #calendarDialog, #copyWeekDialog, #copyShiftsDialog, #moveLocationDialog) .dialog-body > label:has(> :is(input:not([type="checkbox"]):not([type="color"]), select)) { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 240px); align-items: center; gap: 14px; margin: 0; font-size: 12px; }
  :is(#shiftDialog, #taskDialog, #timeOffDialog, #accountDialog, #templateDialog, #calendarDialog, #copyWeekDialog, #copyShiftsDialog, #moveLocationDialog) .dialog-body > label > :is(input, select) { width: 100%; min-width: 0; }
  :is(#shiftDialog, #taskDialog, #timeOffDialog, #accountDialog, #templateDialog) .dialog-body > label:has(> input[type="number"]) { grid-template-columns: minmax(0, 1fr) 112px; }
  :is(#shiftDialog, #taskDialog, #timeOffDialog, #accountDialog, #templateDialog) .dialog-body > label > input[type="number"] { width: 112px; justify-self: end; text-align: right; }
  dialog label { min-width: 0; font-size: 12px; line-height: 1.5; }
  dialog :is(input, select, textarea) { min-width: 0; }
  dialog textarea { min-height: 80px; resize: vertical; }
  dialog .two-cols { gap: 12px; }
  dialog :is(.profile-subsection, .department-section) h4 { font-size: 14px; }
  dialog .close-dialog { flex-shrink: 0; }
  body[data-theme="clean-studio"][data-studio-dark="true"] :is(#locationFilter, #shiftLocation, #calendarPerson, #calendarLocation, #moveLocationTarget, .permanent-location) { background-color: var(--dropdown-control-bg) !important; }
}

/* The shift editor has its own consistent field grid, independent of the
   compact label/value rows used by other settings dialogs. */
@media screen {
  #shiftDialog { width:min(620px,calc(100vw - 28px)); max-height:calc(100dvh - 32px); overflow:auto; }
  #shiftDialog .dialog-body { display:grid; gap:18px; }
  #shiftDialog .dialog-body > header, #shiftDialog .dialog-body > footer { position:static; }
  #shiftDialog .shift-editor-section { display:grid; gap:12px; min-width:0; margin:0; padding:0; border:0; }
  #shiftDialog .shift-editor-section legend { padding:0 0 12px; font-size:11px; font-weight:600; color:var(--muted); }
  #shiftDialog .shift-editor-pair { display:grid; grid-template-columns:repeat(2,minmax(0,1fr)); gap:12px; align-items:stretch; }
  #shiftDialog .shift-editor-pair > label { grid-template-rows:1fr 40px; }
  #shiftDialog .shift-editor-times { display:grid; grid-template-columns:repeat(3,minmax(0,1fr)); gap:12px; }
  #shiftDialog .dialog-body label { grid-template-columns:minmax(0,1fr); gap:6px; margin:0; font-size:12px; font-weight:500; }
  #shiftDialog .dialog-body :is(input,select,textarea) { width:100%; min-width:0; max-width:100%; margin:0; box-sizing:border-box; }
  #shiftDialog .dialog-body :is(input,select) { height:40px; min-height:40px; }
  #shiftDialog .dialog-body textarea { min-height:72px; }
  #shiftDialog #shiftBreak { text-align:start; justify-self:stretch; }
  #shiftDialog footer.shift-dialog-actions { display:flex; flex-wrap:wrap; justify-content:space-between; gap:12px; margin-top:0; }
  #shiftDialog :is(.shift-secondary-actions,.shift-primary-actions) { display:flex; align-items:center; flex-wrap:wrap; gap:8px; }
  #shiftDialog footer button { height:38px; min-height:38px; white-space:nowrap; padding-inline:14px; }
  #shiftDialog #deleteShiftBtn[style*="hidden"], #shiftDialog [hidden] { display:none !important; }
}
@media screen and (max-width:480px) {
  #shiftDialog .dialog-body { gap:16px; }
  #shiftDialog .shift-editor-times { grid-template-columns:repeat(2,minmax(0,1fr)); }
  #shiftDialog .shift-editor-times > label:last-child { grid-column:1 / -1; }
  #shiftDialog :is(.shift-secondary-actions,.shift-primary-actions) { width:100%; }
  #shiftDialog .shift-primary-actions { display:grid; grid-template-columns:repeat(2,minmax(0,1fr)); }
}

@media screen and (max-width: 600px) {
  #appShell { --field-width: 170px; }
  #appShell :is(.workflow-metrics article, .report-summary-card, .report-panel, .time-card, .manage-card, .about-card) { padding: 12px; }
  #appShell .workflow-row { align-items: start; flex-wrap: wrap; }
  #appShell .workflow-row-actions { max-width: 100%; flex-wrap: wrap; }
  #settingsView .settings-group-content > label:has(> :is(select, input[type="text"], input[type="number"])):not(.check-row),
  #settingsView .settings-group-content > .two-cols > label:has(> :is(select, input[type="text"], input[type="number"])) { grid-template-columns: minmax(0, 1fr); gap: 6px; }
  #settingsView .settings-group-content label > input[type="number"] { justify-self: start; }
  dialog .dialog-body { padding: 16px; gap: 12px; }
  :is(#shiftDialog, #taskDialog, #timeOffDialog, #accountDialog, #templateDialog) .dialog-body > label > input[type="number"] { justify-self: start; }
  :is(#shiftDialog, #taskDialog, #timeOffDialog, #accountDialog, #templateDialog, #calendarDialog, #copyWeekDialog, #copyShiftsDialog, #moveLocationDialog) .dialog-body > label:has(> :is(input:not([type="checkbox"]):not([type="color"]), select)) { grid-template-columns: minmax(0, 1fr); gap: 5px; }
}

/* Product-wide finishing rules. Use theme tokens, not a second colour system;
   leave departmental colours, print dimensions and specialised grids intact. */
@media screen {
  body {
    --focus-ring: color-mix(in srgb, var(--accent) 65%, var(--ink));
    --ui-control-height: 38px;
    -webkit-text-size-adjust: 100%;
  }
  body[data-accent="custom"] { --studio-focus: var(--focus-ring); }
  .skip-to-content { position: fixed; top: 8px; left: 8px; z-index: 10000; padding: 10px 16px; border-radius: 6px; background: var(--ink); color: var(--panel-solid); transform: translateY(-180%); }
  .skip-to-content:focus { transform: none; }
  #appShell { line-height: 1.5; }
  #appShell :is(.main, .view, .settings-grid, .workflow-columns, .my-work-layout) { min-width: 0; }
  #appShell :is(h1, h2, h3, h4) { text-wrap: balance; }
  #appShell :is(button, input, select, textarea), dialog :is(button, input, select, textarea) { font-family: inherit; }
  #appShell :is(button, a), dialog :is(button, a) { -webkit-tap-highlight-color: transparent; touch-action: manipulation; }
  #appShell :is(button, input, select, textarea, summary, a[href], [tabindex]):focus-visible,
  dialog :is(button, input, select, textarea, summary, a[href], [tabindex]):focus-visible {
    outline: 2px solid var(--focus-ring);
    outline-offset: 3px;
  }
  #appShell :is(.toolbar, .section-heading, .workflow-actions, .cash-toolbar) > :is(.primary-button, .secondary-button, .icon-button),
  dialog footer > :is(.primary-button, .secondary-button, .icon-button) {
    min-height: var(--ui-control-height);
    box-sizing: border-box;
    line-height: 1.35;
    font-size: 13px;
    font-weight: 500;
  }
  #appShell :is(.primary-button, .secondary-button, .icon-button):disabled,
  dialog button:disabled { cursor: not-allowed; opacity: .5; transform: none; filter: none; }
  #appShell :is(.section-heading, .section-title, .workflow-heading) > div { min-width: 0; }
  #appShell :is(.section-heading, .workflow-heading) :is(h2, h3) { overflow-wrap: anywhere; }
  #appShell :is(.share-panel, .edit-panel, .account-profile-panel) {
    overscroll-behavior: contain;
    scrollbar-width: thin;
    scrollbar-gutter: stable;
  }
  #appShell :is(.share-panel, .edit-panel, .account-profile-panel) button {
    text-align: start;
    line-height: 1.45;
    overflow-wrap: anywhere;
    transition: background-color 100ms ease, color 100ms ease;
  }
  #appShell .nav-button { min-width: 0; }
  body[data-context-toolbar="workspace"] .topbar .toolbar > :is(.week-stepper, #weekPicker, .mobile-date-control, .location-control, .share-menu) { display: none; }
  body[data-context-toolbar="workspace"] #weekTitle .week-range { display: none; }
  #appShell .nav-button .nav-label { overflow-wrap: anywhere; }
  #appShell .native-search-field:focus-within {
    border-color: var(--accent);
    box-shadow: 0 0 0 2px color-mix(in srgb, var(--accent) 13%, transparent);
  }
  #appShell :is(.empty-copy, .workflow-empty) {
    line-height: 1.65;
    font-size: 13px;
    color: var(--muted);
    overflow-wrap: anywhere;
  }

  /* Preserve full names and make time/financial columns easy to compare. */
  #appShell :is(.person-name, .day-planner-person strong, .staff-directory-name, .department-task-title) { overflow-wrap: anywhere; }
  #appShell :is(.shift-time, .day-planner-time, .hours-pill, .day-hours, .report-summary-card strong, .cash-metric-card strong, .cash-total, .home-hours-values strong) { font-variant-numeric: tabular-nums; }
  #rotaGrid :is(.shift-card, .day-planner-shift) { text-align: start; }
  #rotaGrid .day-planner-person { align-items: baseline; }
  #rotaGrid .day-planner-person i { width: 8px; height: 8px; flex-basis: 8px; align-self: center; }
  #rotaGrid .day-planner-person strong { white-space: normal; overflow: visible; text-overflow: clip; line-height: 1.4; font-size: 12px; }
  #rotaGrid :is(.shift-time, .day-planner-time) { font-weight: 600; }
  #rotaGrid :is(.shift-note, .day-planner-meta, .shift-comment) { line-height: 1.5; }
  #rotaGrid .shift-comment { white-space: pre-wrap; overflow-wrap: anywhere; }
  #rotaGrid :is(.shift-card, .day-planner-shift):hover { transform: none; }
  #rotaGrid :is(.shift-card.empty, .day-planner-add) { transition: background-color 100ms ease, border-color 100ms ease; }
  #rotaGrid :is(.shift-card.empty, .day-planner-add):focus-visible { opacity: 1; }
  #appShell .drop-target { outline: 2px solid var(--accent); outline-offset: -2px; }
  body.drag-active #appShell :is(.shift-card, .day-planner-shift, .department-task-card) { animation: none !important; transition: none !important; }

  #myworkView .my-work-heading { align-items: baseline; gap: 10px 20px; }
  #myworkView .home-today-status { margin-bottom: 20px; line-height: 1.6; }
  #appShell #myworkView .my-work-next { border-radius: 8px; }
  #appShell #myworkView .my-work-metrics article strong { font-variant-numeric: tabular-nums; }
  #myworkView .home-week-scroll { overscroll-behavior-x: contain; scrollbar-gutter: stable; }
  #myworkView :is(.my-work-section-heading, .home-week-heading) { gap: 10px; }
  #myworkView :is(.home-team-row, .my-work-shift, .home-day-detail) { line-height: 1.5; }
  #myworkView .home-attention { border-radius: 8px; }
  #myworkView :is(.my-work-task, .home-handover article) { overflow-wrap: anywhere; }
  #appShell :is(.tasks-table, .timesheet-table, .area-table) th { text-align: start; color: var(--muted); white-space: normal; }
  #appShell :is(.tasks-table, .timesheet-table, .area-table) td { vertical-align: middle; font-variant-numeric: tabular-nums; }
  #appShell :is(.tasks-table-wrap, .timesheet-table-wrap, .area-table-wrap) { overscroll-behavior-x: contain; scrollbar-width: thin; }
  #appShell :is(.report-panel, .time-card) > .section-title { align-items: baseline; flex-wrap: wrap; gap: 8px; }
  #appShell :is(.report-summary-card, .cash-day-summary-card) :is(p, small) { line-height: 1.6; }

  #settingsView > .settings-tabs { background: transparent !important; }
  #settingsView .settings-nav-label { font-weight: 600; }
  #settingsView .settings-group > summary { line-height: 1.5; cursor: pointer; }
  #settingsView .settings-group[open] > summary { color: var(--ink); }
  #settingsView .settings-group-content { align-items: start; }
  #settingsView .check-row { align-items: start; padding-block: 4px; }
  #settingsView .check-row input { flex-shrink: 0; margin-top: 3px; }
  #settingsView :is(.settings-copy, label small) { color: var(--muted); line-height: 1.6; }
  #settingsView .settings-panel > .eyebrow { color: var(--muted); }

  dialog { overscroll-behavior: contain; scrollbar-width: thin; }
  dialog::backdrop { background: rgb(0 0 0 / .38); }
  dialog :is(header, footer) { gap: 12px; flex-wrap: wrap; }
  dialog :is(h2, h3, label, .settings-copy) { overflow-wrap: anywhere; }
  dialog input:not([type="checkbox"]):not([type="radio"]):not([type="color"]):not([type="range"]), dialog select { min-height: 40px; }
  dialog :is(input, select, textarea) { scroll-margin-block: 80px; }
  dialog textarea { line-height: 1.6; }
  /* WebKit otherwise includes a native select's longest option in the
     surrounding grid's scrollable width, despite the control fitting. */
  dialog select { overflow: hidden; text-overflow: ellipsis; }
  dialog :is(input, select, textarea)[aria-invalid="true"] { border-color: var(--danger); }
  dialog :is([role="alert"], .dialog-error, .form-error) { color: var(--danger); line-height: 1.6; overflow-wrap: anywhere; }
}

@media print { .skip-to-content { display: none !important; } }

@media screen and (hover: hover) {
  #appShell :is(.staff-directory-row > summary, .location-card, .cash-department-card):hover { background-color: color-mix(in srgb, var(--accent) 4%, var(--panel-solid)); }
  #settingsView > .settings-tabs .settings-tab:not(.active):hover { background: var(--soft); color: var(--ink); }
}

@media screen and (max-width: 900px) {
  body { --ui-control-height: 44px; }
  body.mobile-shell #appShell :is(.settings-tab, .manage-tab) { min-height: 44px; }
  body.mobile-shell #myworkView .home-week-nav button { min-height: 44px; min-width: 44px; }
  body.mobile-shell #settingsView > .settings-tabs { scroll-padding-inline: 4px; }
  body.mobile-shell #appShell .view > .section-heading .cash-toolbar { flex-wrap: wrap; }
  dialog { max-height: calc(100dvh - 24px - env(safe-area-inset-top) - env(safe-area-inset-bottom)); }
  dialog .dialog-body { padding-bottom: max(16px, env(safe-area-inset-bottom)); }
  dialog :is(input:not([type="checkbox"]):not([type="radio"]), select, textarea) { font-size: 16px; }
  dialog footer :is(.primary-button, .secondary-button, .icon-button), #shiftDialog footer button { min-height: 44px; height: auto; }
}

/* Solid department colours need their own ink; neutral cards retain theme ink. */
@media screen {
  body:not([data-theme="clean-studio"][data-studio-dark="true"]) .shift-card[data-shift-key]:not(.shift-card-plain),
  body:not([data-theme="clean-studio"][data-studio-dark="true"]) .open-shift-card:not(.open-shift-card-plain) { color: var(--department-card-ink, #17212b); }
  body:not([data-theme="clean-studio"][data-studio-dark="true"]) .shift-card[data-shift-key]:not(.shift-card-plain) :is(.shift-location, .shift-note, .shift-comment),
  body:not([data-theme="clean-studio"][data-studio-dark="true"]) .open-shift-card:not(.open-shift-card-plain) span { color: inherit; }
  .shift-card.shift-card-plain :is(.shift-location, .shift-note, .shift-comment) { color: inherit; }
}

/* Repeated cards share the tallest content-driven track, without clipping text. */
@media screen {
  #appShell :is(.workflow-metrics, .report-summary-grid, .cash-summary-grid, .location-hours-grid, .subscription-tier-grid) { align-items:stretch;grid-auto-rows:1fr; }
  #appShell :is(.workflow-metrics, .report-summary-grid, .cash-summary-grid, .location-hours-grid, .subscription-tier-grid) > * { align-self:stretch;box-sizing:border-box;height:100%;min-width:0; }
  #rotaGrid .shift-cell { align-items:stretch; }
  #rotaGrid .shift-cell > .shift-card:only-child { box-sizing:border-box;height:100%; }
  #appShell .topbar .toolbar :is(button, input, select, .location-control) { box-sizing:border-box;height:var(--ui-control-height);min-height:var(--ui-control-height); }
}
@media screen and (max-width:900px) {
  body.mobile-shell #appShell .topbar .toolbar :is(button, input, select, .location-control, .mobile-date-control) { height:44px;min-height:44px; }
}

/* Honour the OS preference across every screen, including older theme rules. */
@media screen and (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; scroll-behavior: auto !important; }
}
