/*
 * TradeFlow v7.14.13 responsive presentation layer.
 * This file is deliberately loaded last. It changes presentation only:
 * the Dashboard, navigation, permissions and existing business actions remain intact.
 */
:root{
  --tfm-border:#d7e2dc;
  --tfm-ink:#173e31;
  --tfm-muted:#637068;
  --tfm-surface:#fff;
  --tfm-soft:#f5f8f6;
  --tfm-shadow:0 5px 18px rgba(23,62,49,.08);
}

.tfm-status{display:inline-flex;align-items:center;gap:5px;border-radius:999px;padding:4px 9px;font-size:.78rem;font-weight:900;line-height:1.25;white-space:nowrap}
.tfm-status-draft,.tfm-status-cancelled,.tfm-status-archived{background:#ecefed!important;color:#4f5b55!important}
.tfm-status-pending,.tfm-status-submitted,.tfm-status-mixed{background:#fff0d9!important;color:#7b4a00!important}
.tfm-status-approved,.tfm-status-active,.tfm-status-paid{background:#e5f5eb!important;color:#145c2a!important}
.tfm-status-rejected,.tfm-status-denied,.tfm-status-failed,.tfm-status-overdue{background:#ffe6e3!important;color:#8d1d15!important}
.tfm-status-invoiced,.tfm-status-billed,.tfm-status-edited,.tfm-status-sent{background:#e5edff!important;color:#244b96!important}
.tfm-status-deleted,.tfm-status-disabled{background:#3f4844!important;color:#fff!important}

.tfm-page-actions{position:relative;min-width:112px}
.tfm-page-actions>summary{display:flex;align-items:center;justify-content:center;min-height:44px;padding:9px 13px;border:1px solid #aebdb5;border-radius:9px;background:#fff;color:#173e31;font-weight:800;cursor:pointer;list-style:none}
.tfm-page-actions>summary::-webkit-details-marker{display:none}
.tfm-page-actions>summary::after{content:"▾";margin-left:8px}
.tfm-page-actions[open]>summary::after{transform:rotate(180deg)}
.tfm-page-actions-menu{position:absolute;right:0;top:calc(100% + 6px);z-index:35;display:grid;min-width:min(260px,calc(100vw - 28px));padding:6px;border:1px solid #cad7d0;border-radius:11px;background:#fff;box-shadow:0 15px 36px rgba(20,32,50,.2)}
.tfm-page-actions-menu>.btn,.tfm-page-actions-menu>button,.tfm-page-actions-menu>a{width:100%;justify-content:flex-start;text-align:left;border-color:transparent;background:#fff}
.tfm-page-actions-menu>.btn:hover,.tfm-page-actions-menu>button:hover,.tfm-page-actions-menu>a:hover{background:#f0f6f3}

.tfm-holiday-count{display:none}

@media(max-width:900px){
  /* Comfortable touch targets and readable form controls. */
  button,.btn,input[type="button"],input[type="submit"],input[type="checkbox"],input[type="radio"],select,summary{touch-action:manipulation}
  .main button,.main .btn,.modal button,.tf713-modal button,.tf-mh-modal button,.tf7148-preview button{min-height:44px}
  .main input:not([type="checkbox"]):not([type="radio"]),.main select,.main textarea,
  .modal input:not([type="checkbox"]):not([type="radio"]),.modal select,.modal textarea,
  .tf713-modal input:not([type="checkbox"]):not([type="radio"]),.tf713-modal select,.tf713-modal textarea,
  .tf-mh-modal input:not([type="checkbox"]):not([type="radio"]),.tf-mh-modal select,.tf-mh-modal textarea{font-size:16px}

  /* Standard data tables become two-column card grids without horizontal scrolling. */
  .tablewrap.tfm-card-wrap{max-width:100%;overflow:visible!important;border:0;background:transparent}
  table.tfm-card-table{display:block;width:100%;min-width:0!important;border:0!important;background:transparent}
  table.tfm-card-table>thead{position:absolute!important;width:1px!important;height:1px!important;padding:0!important;margin:-1px!important;overflow:hidden!important;clip:rect(0,0,0,0)!important;white-space:nowrap!important;border:0!important}
  table.tfm-card-table>tbody{display:grid;width:100%;grid-template-columns:repeat(2,minmax(0,1fr));gap:12px}
  table.tfm-card-table>tbody>tr{display:grid;width:100%;min-width:0;align-content:start;gap:0;padding:12px 13px;border:1px solid var(--tfm-border);border-radius:12px;background:var(--tfm-surface);box-shadow:var(--tfm-shadow)}
  table.tfm-card-table>tbody>tr[hidden]{display:none!important}
  table.tfm-card-table>tbody>tr>td{display:grid;grid-template-columns:minmax(96px,.75fr) minmax(0,1.25fr);align-items:start;gap:9px;width:100%!important;min-width:0!important;padding:8px 0!important;border:0!important;border-bottom:1px solid #e8eeeb!important;background:transparent!important;overflow-wrap:anywhere;text-align:left!important}
  table.tfm-card-table>tbody>tr>td:last-child{border-bottom:0!important}
  table.tfm-card-table>tbody>tr>td::before{content:attr(data-mobile-label);color:var(--tfm-muted);font-size:.78rem;font-weight:900;line-height:1.35}
  table.tfm-card-table>tbody>tr>td.tfm-primary-cell{color:var(--tfm-ink);font-weight:800}
  table.tfm-card-table>tbody>tr>td.tfm-action-cell{display:flex;grid-column:1/-1;align-items:stretch;justify-content:flex-start;gap:7px;flex-wrap:wrap;padding-top:11px!important}
  table.tfm-card-table>tbody>tr>td.tfm-action-cell::before{content:none}
  table.tfm-card-table>tbody>tr>td.tfm-action-cell>.btn,
  table.tfm-card-table>tbody>tr>td.tfm-action-cell>button,
  table.tfm-card-table>tbody>tr>td.tfm-action-cell>a{flex:1 1 112px;white-space:normal}
  table.tfm-card-table>tbody>tr>td.tfm-select-cell{display:flex;align-items:center;justify-content:space-between}
  table.tfm-card-table>tbody>tr>td.tfm-select-cell::before{content:attr(data-mobile-label)}
  table.tfm-card-table>tbody>tr>td.tfm-empty-cell{display:none}
  table.tfm-card-table>tbody>tr.tfm-group-row{grid-column:1/-1;padding:9px 12px;border-color:#c8dbd1;background:#eaf2ee;box-shadow:none}
  table.tfm-card-table>tbody>tr.tfm-group-row>td{display:block;padding:0!important;border:0!important;color:#1e503c;font-weight:900}
  table.tfm-card-table>tbody>tr.tfm-group-row>td::before{content:none}

  /* Keep page-level focus on the main action; secondary controls remain under Actions. */
  .pagehead>.toolbar.tfm-page-toolbar{display:grid;grid-template-columns:minmax(0,1fr) auto;align-items:stretch}
  .pagehead>.toolbar.tfm-page-toolbar>.primary{width:100%}
  .tfm-page-actions{width:auto}

  /* Long forms keep their decisions reachable without covering the form content. */
  form>.tfm-form-actions,form .tfm-form-actions{
    position:sticky;bottom:0;z-index:12;display:flex;align-items:stretch;justify-content:flex-end;gap:8px;flex-wrap:wrap;
    margin:16px -2px -2px;padding:12px 2px calc(2px + env(safe-area-inset-bottom));
    border-top:1px solid #dce5df;background:rgba(255,255,255,.97);box-shadow:0 -9px 20px rgba(23,62,49,.08)
  }
  form .tfm-form-actions>.btn,form .tfm-form-actions>button{flex:1 1 130px}
  form .tfm-form-actions>.primary,form .tfm-form-actions>[type="submit"].primary{flex-basis:190px}

  /* Material posting layout stays job → posting → material cards. */
  .tf7148-original-materials>.tablewrap{overflow:visible!important}
  .tf7148-material-job>summary,.tf7148-material-posting{min-height:56px}
  #tf713-material-edit .tf713-edit-table td:last-child{display:grid;grid-template-columns:repeat(2,minmax(0,1fr));gap:8px}
  #tf713-material-edit .tf713-edit-table td:last-child .tf713-mobile-label{grid-column:1/-1}
  #tf713-material-edit [data-tf713-credit-material-row],#tf713-material-edit [data-tf713-delete-material-row]{width:100%;min-height:44px}

  /* Holiday controls and calendar fit the phone instead of scrolling sideways. */
  .tf-mh-calendar-scroll{max-width:100%;overflow:visible!important}
  .tf-mh-calendar{width:100%;min-width:0!important}
  .tf-mh-calendar-weekday{min-width:0;padding:7px 2px;font-size:.73rem}
  .tf-mh-day{min-width:0;min-height:76px;padding:5px}
  .tf-mh-day-number{margin-bottom:3px}
  .tf-mh-filter-grid{grid-template-columns:repeat(2,minmax(0,1fr))}
  .tf-mh-settings-members{max-height:none;overflow:visible}

  /* Filters and dense setting grids stack before becoming cramped. */
  .filters,.filtergrid,.tf713-filter-grid{grid-template-columns:repeat(2,minmax(0,1fr))!important}
}

@media(max-width:640px){
  table.tfm-card-table>tbody{grid-template-columns:1fr}
  table.tfm-card-table>tbody>tr>td{grid-template-columns:minmax(88px,.7fr) minmax(0,1.3fr)}

  /* Forms use the full phone screen; desktop and tablet modals remain unchanged. */
  .modalback,.tf713-modalback,.tf-mh-modalback,.tf7148-preview-back{align-items:stretch!important;place-items:stretch!important;padding:0!important}
  .modalback>.modal,.tf713-modalback>.tf713-modal,.tf-mh-modalback>.tf-mh-modal,.tf7148-preview-back>.tf7148-preview{
    width:100%!important;height:100dvh!important;max-width:none!important;max-height:none!important;margin:0!important;
    padding:16px 12px calc(14px + env(safe-area-inset-bottom))!important;border-radius:0!important;overflow:auto!important
  }
  .modalback>.modal>header,.tf713-modalback>.tf713-modal>header,.tf-mh-modalback>.tf-mh-modal>.tf-mh-modalhead,.tf7148-preview-back>.tf7148-preview>header{
    position:sticky;top:-16px;z-index:14;margin:0 -12px 14px;padding:14px 12px;border-bottom:1px solid #dce5df;background:#fff
  }
  body:has(.modalback),body:has(.tf713-modalback),body:has(.tf-mh-modalback),body:has(.tf7148-preview-back){overflow:hidden}

  .pagehead>.toolbar.tfm-page-toolbar{grid-template-columns:1fr auto!important}
  .pagehead>.toolbar.tfm-page-toolbar>.primary{min-width:0}
  .tfm-page-actions>summary{min-width:98px}
  .tfm-page-actions-menu{position:fixed;right:10px;left:10px;top:auto;bottom:calc(10px + env(safe-area-inset-bottom));max-height:70dvh;overflow:auto}

  form .tfm-form-actions{display:grid;grid-template-columns:repeat(2,minmax(0,1fr))}
  form .tfm-form-actions>.btn,form .tfm-form-actions>button{width:100%}
  form .tfm-form-actions>.primary,form .tfm-form-actions>[type="submit"].primary{grid-column:1/-1;grid-row:1}

  .tf-mh-filter-grid,.filters,.filtergrid,.tf713-filter-grid{grid-template-columns:1fr!important}
  .tf-mh-calendar-card{padding:9px}
  .tf-mh-calendar-head{gap:8px}
  .tf-mh-calendar-weekday{padding:6px 1px;font-size:.65rem}
  .tf-mh-day{position:relative;min-height:58px;padding:4px;text-align:center}
  .tf-mh-day-number{font-size:.8rem}
  .tf-mh-day .tf-mh-event{position:absolute;width:1px;height:1px;padding:0;margin:-1px;overflow:hidden;clip:rect(0,0,0,0);white-space:nowrap;border:0}
  .tfm-holiday-count{display:inline-grid;place-items:center;min-width:19px;height:19px;margin:2px auto 0;padding:0 4px;border-radius:999px;background:#fff0d9;color:#7b4a00;font-size:.68rem;font-weight:900}
  .tf-mh-day.other .tfm-holiday-count{opacity:.7}
}

@media(max-width:390px){
  .pagehead>.toolbar.tfm-page-toolbar{grid-template-columns:1fr!important}
  .tfm-page-actions{width:100%}
  .tfm-page-actions>summary{width:100%}
  table.tfm-card-table>tbody>tr>td{grid-template-columns:1fr;gap:3px}
}

@media(prefers-reduced-motion:reduce){
  .tfm-page-actions>summary::after{transition:none}
}
