/* Shared button geometry. Page palettes and business/permission state remain local.
   Keep this after page styles; do not apply button paint to ordinary links/cards. */
:root {
  --control-height: 34px;
  --control-radius: 7px;
  --control-font: 13px;
  --control-focus: #38bdf8;
}
/* Native hidden state must win over flex/grid action styles and inline layout. */
[hidden] { display: none !important; }
@media screen {
  :root body button, :root body .nav-button, :root body .ui-button {
    box-sizing: border-box;
    min-height: var(--control-height);
    max-width: 100%;
    padding: 6px 11px;
    border-radius: var(--control-radius);
    font-family: inherit;
    font-size: var(--control-font);
    font-weight: 600;
    line-height: 1.35;
    text-align: center;
    white-space: normal;
    overflow-wrap: anywhere;
    cursor: pointer;
    vertical-align: middle;
  }
  body .nav-button, body .ui-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    text-decoration: none;
  }
  /* Only explicit action styles receive semantic paint. Preserve specialized tabs. */
  body button.ui-primary, body button[type="submit"],
  body form button:not([type]):not(.secondary) {
    background: #0369a1;
    border: 1px solid #0284c7;
    color: #fff;
  }
  body button.secondary, body .nav-button {
    background: #1c2d44;
    border: 1px solid #3b526e;
    color: #e2edf9;
  }
  body button:is(.ui-danger, .hostel-delete, #deleteRole) {
    background: #431d29;
    border: 1px solid #a24760;
    color: #ffe4e6;
  }
  body button:enabled:hover, body .nav-button:hover, body .ui-button:hover {
    filter: brightness(1.12);
  }
  /* Focus never relies on color alone, including sort and metric buttons. */
  :root body button:focus-visible, :root body a:focus-visible,
  :root body summary:focus-visible, :root body input:focus-visible,
  :root body select:focus-visible, :root body [role="button"]:focus-visible {
    outline: 2px solid var(--control-focus);
    outline-offset: 2px;
  }
  body button:disabled, body button[aria-disabled="true"],
  body .ui-button[aria-disabled="true"] {
    opacity: .5;
    cursor: not-allowed;
    filter: none;
  }
  body button[aria-busy="true"] { cursor: progress; }

  /* Row actions are compact, not 10px text. Sorting remains a flat header. */
  body :is(td, .permission-bulk, .permission-group-actions) button {
    min-height: 28px;
    padding: 4px 8px;
    font-size: 12px;
    line-height: 1.3;
  }
  body button:is(.sort-header, .stock-sort) {
    background: transparent;
    border-radius: 3px;
    font-size: inherit;
    text-align: left;
    padding: 3px 5px;
    min-height: 24px;
    font-weight: 600;
  }
  body .material-stock-sheet .stock-sort {
    padding: 8px 14px 8px 8px;
    min-height: 34px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  :root body :is(.attendance-suggestions, .batch-row-suggestions) button {
    text-align: left;
    width: 100%;
  }
  /* These are full-card/metric hit areas, not toolbar buttons. */
  body button.metric-button {
    min-height: 0;
    padding: 0;
    border-radius: 0;
    font: inherit;
    text-align: left;
    overflow-wrap: normal;
  }
  body button.project-card {
    min-height: 0;
    padding: 18px;
    border-radius: 16px;
    font: inherit;
    text-align: left;
  }

  /* Quiet utility actions: no danger paint for the routine sign-out action. */
  body button:is(#logout, #logoutButton, #fclFullLogout, .logout-btn, .logout-button) {
    min-height: 28px;
    width: auto;
    flex: 0 0 auto;
    justify-self: start;
    padding: 4px 9px;
    border: 1px solid #405874;
    border-radius: 6px;
    background: #18283c;
    color: #dbe7f5;
    font-size: 12px;
    font-weight: 600;
    line-height: 1.35;
    white-space: nowrap;
    overflow-wrap: normal;
  }
  body button:is(#logout, #logoutButton, #fclFullLogout, .logout-btn, .logout-button):hover {
    background: #263d58;
    border-color: #7d9dbf;
  }
  /* Layout corrections for previously nonwrapping toolbars. */
  .payment-bar { flex-wrap: wrap; }
  .header:has(.header-right) { flex-wrap: wrap; gap: 10px; }
  .header .header-right { flex-wrap: wrap; max-width: 100%; }
  .header .header-left { min-width: 0; }
  .payment-bar a { min-height: 34px; display: inline-flex; align-items: center; }
  .payment-bar span { white-space: normal; }
  .fcl-bar nav a { font-size: 13px; }
  .dashboard-toolbar, .section-actions, .attendance-nav, .hostel-nav,
  .staff-header-actions, .ding-staff-nav { gap: 6px; }
  .dashboard-toolbar > *, .section-actions > * { min-width: 0; }
  @media (max-width: 600px) {
    .fcl-bar nav { flex-wrap: wrap; overflow-x: visible; }
    .dashboard-toolbar .date-control { flex-wrap: wrap; }
    body .nav-button { white-space: normal; }
  }
  /* Coarse pointers/small screens get real separated targets, not overlapping
     pseudo-element hit boxes; compact typography stays the same. */
  @media (pointer: coarse), (max-width: 600px) {
    :root body button, :root body .nav-button, :root body .ui-button,
    body :is(td, .permission-bulk, .permission-group-actions) button,
    body button:is(.sort-header, .stock-sort),
    body .material-stock-sheet .stock-sort,
    body button:is(#logout, #logoutButton, #fclFullLogout, .logout-btn, .logout-button),
    body .dashboard-language button { min-height: 44px; }
    body .dashboard-language button { min-width: 44px; }
    body button.metric-button { min-height: 44px; }
    body button.project-card { min-height: 44px; }
    #salaryBatchBar { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    #salaryBatchBar > * { min-width: 0; max-width: 100%; }
    #salaryBatchBar label { display: grid; white-space: normal; }
    #salaryBatchBar input { width: 100%; min-width: 0; }
    #salaryBatchPreview { white-space: normal; overflow-wrap: anywhere; }
    :root body th[role="button"] { height: 44px; }
    .staff-page { height: auto; min-height: 100dvh; overflow: visible; }
    .staff-sheet-wrap { max-height: 65dvh; flex: auto; }
    .payment-frame { height: calc(100dvh - 130px); min-height: 440px; }
  }
}
