/* RH visual layer. Status colours and document/print styles remain module-owned. */
@media screen {
  :root {
    --uuc-rh-deep: #004c49;
    --uuc-rh-primary: #006b61;
    --uuc-rh-secondary: #00a887;
    --uuc-rh-accent: #34d399;
    --uuc-rh-mint: #d1fae5;
    --uuc-rh-canvas: #f3f4f6;
    --uuc-rh-border: #d6e4e7;
    --uuc-rh-shadow: 0 5px 16px rgba(16, 53, 60, .08);
  }

  html:not([data-theme=dark]) {
    --rh-control-hover: #e5f8f1;
    --rh-control-ink: #163d3d;
    --rh-control-muted: #4b6666;
    --rh-control-line: #b7d1cd;
    --rh-control-accent: #006b61;
    --rh-control-selected: #d1fae5;
    --rh-control-on-selected: #005749;
  }
  html:not([data-theme=dark]),
  html:not([data-theme=dark]) body {
    background-color: var(--uuc-rh-canvas) !important;
  }
  html:not([data-theme=dark]) .workspace #lobby.lobby {
    background: var(--uuc-rh-canvas) !important;
  }
  html:not([data-theme=dark]) .rh-ambient-canvas {
    opacity: .08;
  }

  html:not([data-theme=dark]) #sidebar {
    background: linear-gradient(165deg, #004c49, #003a3e) !important;
    border-color: #006b61 !important;
  }
  html:not([data-theme=dark]) #sidebar :is(.nav-item,.sidebar-role,.sidebar-user-name) {
    color: #eaf9f4 !important;
  }
  html:not([data-theme=dark]) #sidebar .nav-item:hover {
    background: rgba(52, 211, 153, .18) !important;
  }
  html:not([data-theme=dark]) #sidebar .nav-item.is-active {
    background: #007c69 !important;
    color: #fff !important;
  }
  html:not([data-theme=dark]) #sidebar :is(.collapse-button,.rh-theme-toggle,.sidebar-movements,.sidebar-logout) {
    color: #eaf9f4 !important;
    border-color: rgba(209, 250, 229, .32) !important;
    background-color: rgba(0, 38, 39, .25) !important;
  }
  html:not([data-theme=dark]) #operationalDashboard.om-working {
    --mw-ink: #102f36;
    --mw-muted: #49666d;
    --mw-line: #d6e4e7;
    --mw-paper: #fff;
    --mw-soft: #f3f7f8;
    --mw-teal: #006b61;
  }
  html:not([data-theme=dark]) :is(.panel,.login-panel,.catalog-card,.contract-record) {
    border-color: var(--uuc-rh-border);
    box-shadow: var(--uuc-rh-shadow);
  }
  html:not([data-theme=dark]) :is(.user-toolbar,.dashboard-table-panel,.signature-panel,.org-toolbar,.org-stage) {
    background-color: #fff;
    border-radius: 14px;
  }
  html:not([data-theme=dark]) :is(.table-wrap,.sheet-wrap) {
    border-color: var(--uuc-rh-border);
    border-radius: 10px;
  }
  html:not([data-theme=dark]) :is(.tabs,.org-tabs) {
    gap: 5px;
  }
  html:not([data-theme=dark]) :is(.tabs,.org-tabs) :is(a,button) {
    border-radius: 9px;
  }
  html:not([data-theme=dark]) :is(.visit-panel,.history-panel,.route-panel,.validation-panel,.generate-card,.fingerprint-preview-card,.worker-card) {
    background-color: #fff;
    border-color: var(--uuc-rh-border);
    box-shadow: var(--uuc-rh-shadow);
  }
  html:not([data-theme=dark]) :is(.catalog-item,.collaborator-row,.contractor-catalog-card) {
    border-color: #dce8e7;
    background-color: #f8fbfa;
  }
  html:not([data-theme=dark]) :is(.table-wrap,.sheet-wrap) thead th {
    background-color: #f1f5f6;
    color: #39565a;
    border-color: #dce8e7;
  }
  html:not([data-theme=dark]) :is(.modal-card,.dialog,.dialog-card,.office-calendar,.listas-week-popup,.rh-birthday-picker) {
    background-color: #fff;
    border-color: var(--uuc-rh-border);
    box-shadow: 0 14px 34px rgba(16, 53, 60, .18);
  }
  html:not([data-theme=dark]) :is(.tabs,.org-tabs) :is(a,button):is(.active,.is-active,[aria-selected=true],[aria-current=page]) {
    background-color: var(--uuc-rh-primary);
    color: #fff;
  }
  html:not([data-theme=dark]) #operationalDashboard.om-working :is(.om-panel,.om-balance-band) {
    background: #fff;
    border: 1px solid var(--uuc-rh-border);
    border-radius: 14px;
    box-shadow: var(--uuc-rh-shadow);
  }
  html:not([data-theme=dark]) #operationalDashboard.om-working .om-view-tabs button[aria-pressed=true] {
    background: var(--uuc-rh-primary);
    color: #fff;
  }
  #operationalDashboard.om-working .om-balance-band {
    display: grid;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    gap: 10px;
    padding: 0;
    border: 0;
    background: transparent;
    box-shadow: none;
  }
  #operationalDashboard.om-working .om-balance-band .om-math { display: none; }
  #operationalDashboard.om-working .om-current-stock { display: contents; }
  #operationalDashboard.om-working .om-balance-band :is(.om-metric-select,.om-net-number,.om-current-stock > button) {
    min-width: 0;
    min-height: 84px;
    width: 100%;
    margin: 0;
    padding: 14px;
    border: 1px solid var(--mw-line);
    border-radius: 12px;
    background: var(--mw-paper);
    box-shadow: var(--uuc-rh-shadow);
  }
  html:not([data-theme=dark]) :is(button,a):is(.primary,.primary-action):not(.rh-doc-button) {
    background-color: var(--uuc-rh-primary);
    color: #fff;
    border-color: var(--uuc-rh-primary);
  }
  html:not([data-theme=dark]) :is(button,a):is(.primary,.primary-action):not(.rh-doc-button):hover:not(:disabled) {
    background-color: #00554f;
  }
  html:not([data-theme=dark]) :is(input,textarea):focus-visible {
    outline-color: var(--uuc-rh-primary);
  }
  html[data-theme=dark] #sidebar {
    background: linear-gradient(165deg, #102e2d, #102326) !important;
    border-color: #315752 !important;
  }
  html[data-theme=dark] #sidebar :is(.nav-item,.sidebar-role,.sidebar-user-name) {
    color: #eaf9f4 !important;
  }
  html[data-theme=dark] #sidebar .nav-item:hover {
    background: rgba(52, 211, 153, .15) !important;
  }
  html[data-theme=dark] #sidebar .nav-item.is-active {
    background: #007c69 !important;
    color: #fff !important;
  }
  html[data-theme=dark] :is(button,a):is(.primary,.primary-action):not(.rh-doc-button) {
    background-color: #007c69;
    border-color: #3cb99d;
    color: #fff;
  }
  html[data-theme=dark] :is(.panel,.login-panel,.catalog-card,.contract-record) {
    border-color: #385853;
    box-shadow: 0 5px 16px rgba(0, 0, 0, .18);
  }
  html[data-theme=dark] :is(.visit-panel,.history-panel,.route-panel,.validation-panel,.generate-card,.fingerprint-preview-card,.worker-card) {
    border-color: #385853;
    box-shadow: 0 5px 16px rgba(0, 0, 0, .18);
  }
  html[data-theme=dark] body:has(#tab-generate) .table-wrap:has(> #usersTable) {
    background-color: #1d2d32 !important;
  }
  html[data-theme=dark] :is(.dialog,.modal-card,.dialog-card,.table-wrap,.sheet-wrap) {
    scrollbar-color: #72958f #1d2d32 !important;
  }
  @media (min-width: 761px) {
    body:has(.user-toolbar) #tableBody td { padding-block: 8px; }
    body:has(.user-toolbar) #tableBody .table-actions { padding: 0; }
  }
  @media (max-width: 760px) {
    :is(.tabs,.org-tabs) { max-width: 100%; }
    :is(.panel,.login-panel,.catalog-card,.contract-record) { min-width: 0; }
    #operationalDashboard.om-working .om-balance-band { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    #operationalDashboard.om-working .om-balance-band :is(.om-metric-select,.om-net-number,.om-current-stock > button) { min-height: 72px; padding: 10px; }
    #root .metrics-strip { grid-template-columns: repeat(2, minmax(0, 1fr)) !important; gap: 8px; }
  }
  @media (prefers-reduced-motion: reduce) {
    #sidebar .nav-item { transition: none; }
  }
}

@media screen and (max-width: 760px) {
  body.mobile-sidebar-mode #sidebar:not(.is-mobile-open) {
    visibility: hidden;
    pointer-events: none;
  }
  body:has(#tab-generate) #usersTable td {
    height: auto;
    padding-block: 8px;
  }
  body:has(#tab-generate) #usersTable .screen-tags {
    max-height: 64px;
    overflow-y: auto;
    align-content: start;
  }
  body:has(#tab-generate) #usersTable .action-grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 4px;
  }
  body:has(#tab-generate) #usersTable .action-grid button {
    min-height: 44px;
    padding: 5px 3px;
    font-size: 11px;
  }
}

/* Shared screen design. Business status colours and printable documents are module-owned. */
@media screen {
  html:not([data-theme=dark]) {
    --bg: #f3f4f6;
    --surface: #ffffff;
    --surface-strong: #f5f8f9;
    --ink: #163238;
    --muted: #526b72;
    --line: #d7e3e7;
    --primary: #006b61;
    --primary-strong: #004e49;
    --shadow: 0 5px 18px rgba(24, 55, 65, .08);
  }
  html[data-theme=dark] {
    --bg: #142125;
    --surface: #1c2b30;
    --surface-strong: #21343a;
    --ink: #edf6f4;
    --muted: #b6cacc;
    --line: #40585f;
    --primary: #177b6a;
    --primary-strong: #a7e6d4;
    --shadow: 0 5px 18px rgba(0, 0, 0, .22);
  }
  body:has(:is(.app-shell,.users-shell,#root,#reports,#weekly)) {
    font-family: "Nunito", ui-rounded, system-ui, sans-serif;
  }
  .app-shell { background: var(--bg, #f3f4f6) !important; }
  html:not([data-theme=dark]) .app-shell .ambient-canvas,
  html:not([data-theme=dark]) .app-shell .rh-ambient-canvas { opacity: .06 !important; }
  .app-shell .topbar h1 { font-size: 28px; line-height: 1.2; }
  :is(.app-shell,.users-shell) :is(.panel,.catalog-card,.login-panel),
  :is(.user-toolbar,.org-toolbar,.visit-panel,.history-panel,.route-panel,.validation-panel) {
    border-radius: 14px;
    box-shadow: var(--shadow);
  }
  :is(.app-shell,.users-shell) > .shell-content > .panel,
  :is(.dashboard-table-panel,.signature-panel) { padding: 18px; }
  :is(.tabs,.org-tabs) {
    align-items: center;
    gap: 5px;
    border-radius: 12px;
    padding: 5px;
    box-shadow: 0 2px 8px rgba(18, 49, 55, .05);
  }
  :is(.tabs,.org-tabs) :is(a,button) {
    min-height: 40px;
    border-radius: 8px;
    font-size: 13px;
    line-height: 1.25;
    font-weight: 800;
  }
  html:not([data-theme=dark]) :is(.tabs,.org-tabs) :is(a,button):is(.active,.is-active,[aria-selected=true],[aria-current=page]) {
    background: linear-gradient(120deg,#006b61,#008572);
    color: #fff;
    box-shadow: 0 3px 8px rgba(0,107,97,.16);
  }
  html[data-theme=dark] :is(.tabs,.org-tabs) :is(a,button):is(.active,.is-active,[aria-selected=true],[aria-current=page]) {
    background: #177b6a;
    color: #fff;
    border-color: #4bba9f;
  }
  :is(.user-toolbar,.org-toolbar,.office-toolbar) :is(input,select,button) { font-size: 14px; }
  :is(.dialog,.modal-card,.dialog-card,.rh-confirm-dialog) {
    border-radius: 16px;
    border-color: var(--line);
  }
  :is(.app-shell,.users-shell) :is(input,textarea):not([type=checkbox]):not([type=radio]) {
    border-radius: 8px;
    min-width: 0;
  }
  html:not([data-theme=dark]) :is(.panel,.catalog-card,.user-toolbar) :is(input,textarea):not([type=checkbox]):not([type=radio]) {
    border-color: #bdcfd5;
    background-color: #fff;
    color: #163238;
  }
  html[data-theme=dark] :is(.panel,.catalog-card,.user-toolbar) :is(input,textarea):not([type=checkbox]):not([type=radio]) {
    border-color: #67858a;
    background-color: #23363b;
    color: #edf6f4;
  }
  :is(.panel,.catalog-card,.user-toolbar) input::placeholder,
  :is(.panel,.catalog-card,.user-toolbar) textarea::placeholder { color: var(--muted); opacity: 1; }
  :is(.app-shell,.users-shell) .section-head { gap: 12px; margin-bottom: 14px; }
  :is(.app-shell,.users-shell) .section-head h2 { font-size: 20px; line-height: 1.3; }
  @media (max-width:760px) {
    :is(.app-shell,.users-shell) { padding-inline: 12px; }
    :is(.app-shell,.users-shell) :is(.panel,.catalog-card,.login-panel) { padding: 14px; }
    :is(.app-shell,.users-shell) .section-head { flex-wrap: wrap; }
    :is(.tabs,.org-tabs) :is(a,button) { min-height:44px; font-size:12px; }
    :is(.dialog,.modal-card,.dialog-card,.rh-confirm-dialog) { max-width:calc(100vw - 20px); }
    :is(.app-shell,.users-shell) :is(input,textarea):not([type=checkbox]):not([type=radio]) { font-size:16px; }
  }
}

@media screen {
  #attendanceRulesDialog .attendance-dialog-head,
  #remoteClockDialog .attendance-dialog-head {
    display: flex;
    flex-direction: row;
    align-items: flex-start;
    justify-content: space-between;
    gap: 12px;
  }
  #attendanceRulesDialog .attendance-dialog-head h2,
  #remoteClockDialog .attendance-dialog-head > div {
    flex: 1 1 auto;
    min-width: 0;
    overflow-wrap: anywhere;
  }
  #attendanceRulesDialog #closeAttendanceRules,
  #remoteClockDialog #remoteClockClose {
    flex: 0 0 40px;
    width: 40px;
    height: 40px;
    min-height: 40px;
    margin: 0;
  }
  html[data-theme=dark] #remoteClockDialog :is([data-sync-clock],[data-office-rules]) {
    background: #243b40;
    color: #e3f3f0;
    border-color: #527078;
  }
  html[data-theme=dark] #remoteClockDialog :is([data-sync-clock],[data-office-rules]):hover:not(:disabled) {
    background: #315a5b;
    color: #fff;
  }
  #movementsDialog :is(#movementsAccount,#movementsScope,#movementsModule) {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    line-height: 1.3;
    font-size: 13px;
  }
  #movementsDialog :is(#movementsAccount,#movementsScope,#movementsModule) option {
    white-space: normal;
  }
}

@media screen {
  html[data-theme=dark] .edit-row > td { background: #1d2d32; color: #edf6f4; }
  html[data-theme=dark] .application-edit {
    background: #1d2d32;
    color: #edf6f4;
    border-color: #527078;
  }
  html[data-theme=dark] .application-edit .edit-copy strong,
  html[data-theme=dark] .application-edit label { color: #edf6f4; }
  html[data-theme=dark] .application-edit .edit-copy span { color: #b6cacc; }
  html[data-theme=dark] .signature-viewer-frame-wrap:has(#signatureContractViewer[hidden]) {
    background: #21343a;
    border-color: #527078;
  }
  html[data-theme=dark] #signatureViewerEmpty { background: #21343a; color: #b6cacc; }
  @media(max-width:600px) {
    .application-edit {
      width: calc(100vw - 112px);
      max-width: 100%;
      min-width: 0;
      box-sizing: border-box;
    }
    .application-edit :is(input,select) { min-width:0; max-width:100%; font-size:16px; }
    .application-edit .edit-actions { flex-wrap:wrap; }
    .application-edit .edit-actions button { min-height:44px; }
  }
}
