/*
 * RL_TMS UI foundation
 * Central tokens, layout primitives and reusable components.
 * Existing pages can migrate incrementally without changing their behaviour.
 */
:root{
 --tms-color-navy:#173f5f;
 --tms-color-navy-dark:#071f4a;
 --tms-color-blue:#2d7faf;
 --tms-color-blue-soft:#eaf4fb;
 --tms-color-text:#18232d;
 --tms-color-muted:#5f7280;
 --tms-color-surface:#fff;
 --tms-color-canvas:#eef2f5;
 --tms-color-border:#d8e2e8;
 --tms-color-success:#2f7d51;
 --tms-color-warning:#b97912;
 --tms-color-danger:#b83333;
 --tms-color-action:#173f5f;
 --tms-color-action-secondary:#647786;
 --tms-radius-sm:.45rem;
 --tms-radius-md:.75rem;
 --tms-radius-lg:1rem;
 --tms-shadow-card:0 .2rem .8rem rgb(25 56 77 / 8%);
 --tms-space-1:.35rem;
 --tms-space-2:.6rem;
 --tms-space-3:.85rem;
 --tms-space-4:1rem;
 --tms-space-5:1.25rem;
 --tms-space-6:1.5rem;
 --tms-page-max:90rem;
 --tms-process-page-max:118rem;
 --tms-page-gutter:clamp(.75rem,2vw,1.75rem);
 --tms-font-body:Arial,sans-serif;
 --tms-font-size:clamp(.875rem,.82rem + .14vw,1rem);
}

html{min-width:20rem;text-size-adjust:100%;-webkit-text-size-adjust:100%}
body.tms-ui{margin:0;background:var(--tms-color-canvas);color:var(--tms-color-text);font:var(--tms-font-size)/1.45 var(--tms-font-body)}
body.tms-ui *,body.tms-ui *::before,body.tms-ui *::after{box-sizing:border-box}
body.tms-ui img,body.tms-ui svg{max-width:100%}
body.tms-ui :focus-visible{outline:.2rem solid #1689ff;outline-offset:.15rem}

/* Shared navigation and controls. */
.tms-context-nav{
 width:min(calc(100% - (2 * var(--tms-page-gutter))),var(--tms-page-max));
 margin:clamp(.7rem,1.5vw,1.1rem) auto 0;
 min-width:0;
}
.tms-context-nav+.tms-context-nav{display:none}
.tms-back-link{
 display:inline-flex;
 align-items:center;
 gap:.5rem;
 min-height:2.65rem;
 max-width:100%;
 padding:.62rem .9rem;
 border:1px solid #aebdc7;
 border-radius:var(--tms-radius-sm);
 background:#fff;
 color:var(--tms-color-navy);
 box-shadow:0 .1rem .35rem rgb(25 56 77 / 8%);
 font-weight:700;
 line-height:1.2;
 text-decoration:none;
}
.tms-back-link:hover{background:#edf4f8;border-color:#8ea8b8}
.tms-back-link>span:first-child{font-size:1.2em;line-height:1}
.tms-legacy-return{display:none!important}

body.tms-ui button,
body.tms-ui .button{
 min-height:2.55rem;
 max-width:100%;
 border-radius:var(--tms-radius-sm);
 font:inherit;
}
body.tms-ui input,
body.tms-ui select,
body.tms-ui textarea{max-width:100%;font:inherit}
body.tms-ui .actions{display:flex;align-items:center;gap:var(--tms-space-2);flex-wrap:wrap}
body.tms-ui h1,body.tms-ui h2,body.tms-ui h3{overflow-wrap:anywhere}

.tms-page,
body.tms-ui .wrap{
 width:min(calc(100% - (2 * var(--tms-page-gutter))),var(--tms-page-max));
 max-width:none;
 margin:clamp(.8rem,2vw,1.5rem) auto;
 padding:0;
 min-width:0;
}

.tms-page-header,
body.tms-ui .intro,
.tms-section,
body.tms-ui .dashboard-block{
 min-width:0;
 border-radius:var(--tms-radius-md);
 background:var(--tms-color-surface);
 box-shadow:var(--tms-shadow-card);
}

.tms-page-header,
body.tms-ui .intro{padding:clamp(1rem,2vw,1.5rem);margin-bottom:var(--tms-space-4)}
.tms-page-header h1,body.tms-ui .intro h1{font-size:clamp(1.5rem,1.25rem + .8vw,2.15rem);line-height:1.15}
.tms-section,body.tms-ui .dashboard-block{padding:clamp(.9rem,1.7vw,1.4rem);margin-bottom:var(--tms-space-4)}
.tms-section-head,body.tms-ui .panel-head{display:flex;align-items:flex-start;justify-content:space-between;gap:var(--tms-space-3);flex-wrap:wrap;min-width:0}
.tms-section-head>*:first-child,body.tms-ui .panel-head>*:first-child{min-width:0}
body.tms-ui .portal-review .panel-head{display:grid;grid-template-columns:minmax(0,1fr) auto;align-items:start}

.tms-kpi-grid,
body.tms-ui .metrics,
body.tms-ui .process-metrics,
body.tms-ui .outsourcing-metrics{
 display:grid;
 grid-template-columns:repeat(auto-fit,minmax(min(100%,13.5rem),1fr));
 gap:clamp(.65rem,1.35vw,1rem);
 min-width:0;
}

body.tms-ui .metric{
 min-width:0;
 padding:clamp(.85rem,1.3vw,1.1rem);
 border-left-width:.35rem;
 border-radius:var(--tms-radius-md);
 overflow-wrap:anywhere;
}
body.tms-ui .process-metric .metric-title{min-height:0}
body.tms-ui .process-counts{display:flex;gap:clamp(.75rem,2vw,1.25rem);flex-wrap:wrap}
body.tms-ui .process-counts>div{min-width:4.5rem}
body.tms-ui .metric strong{font-size:clamp(1.45rem,1.2rem + .9vw,2rem);line-height:1.1}

.tms-content-grid,
body.tms-ui .grid{
 display:grid;
 grid-template-columns:repeat(auto-fit,minmax(min(100%,31rem),1fr));
 gap:clamp(.75rem,1.4vw,1.1rem);
 min-width:0;
}

.tms-panel,body.tms-ui .panel{min-width:0;padding:clamp(.8rem,1.4vw,1.15rem);border:1px solid var(--tms-color-border);border-radius:var(--tms-radius-md)}
body.tms-ui .panel-head a,body.tms-ui .review-action{flex:0 0 auto;max-width:100%;white-space:normal;text-align:center}

.tms-table-shell,body.tms-ui .table-wrap{max-width:100%;overflow-x:auto;overscroll-behavior-inline:contain;border-radius:var(--tms-radius-sm);scrollbar-width:thin}
body.tms-ui table{width:100%;min-width:42rem;border-collapse:collapse}
body.tms-ui th,body.tms-ui td{padding:clamp(.55rem,1vw,.75rem);vertical-align:top;overflow-wrap:break-word}
body.tms-ui th{white-space:nowrap}

body.tms-ui .apk-status,
body.tms-ui .outsource-status{max-width:100%;white-space:normal;text-align:center}
body.tms-ui .empty,body.tms-ui .error{overflow-wrap:anywhere}

/* Process screens retain their functional layouts but share one responsive frame. */
body.tms-ui[data-tms-page="orders"] .layout,
body.tms-ui[data-tms-page="planning"] .layout{
 width:min(calc(100% - (2 * var(--tms-page-gutter))),var(--tms-process-page-max));
 max-width:none;
 margin:clamp(.8rem,2vw,1.5rem) auto;
 padding:0;
 min-width:0;
}
body.tms-ui[data-tms-page="orders"] main,
body.tms-ui[data-tms-page="planning"] main,
body.tms-ui[data-tms-page="orders"] aside,
body.tms-ui[data-tms-page="planning"] aside{min-width:0}
body.tms-ui .order,body.tms-ui .lane{min-width:0}
body.tms-ui .modal-card,body.tms-ui .dialog{max-width:calc(100vw - (2 * var(--tms-page-gutter)))}
body.tms-ui[data-tms-page="orders"] .tms-context-nav,
body.tms-ui[data-tms-page="planning"] .tms-context-nav{
 width:min(calc(100% - (2 * var(--tms-page-gutter))),var(--tms-process-page-max));
}

/* Process forms need more horizontal room than dashboard and master-data cards. */
@media(max-width:96rem){
 body.tms-ui[data-tms-page="orders"] .layout,
 body.tms-ui[data-tms-page="planning"] .layout{grid-template-columns:1fr}
 body.tms-ui[data-tms-page="orders"] .layout>aside,
 body.tms-ui[data-tms-page="planning"] .layout>aside{width:100%}
}

/* Mobile products use the same tokens without inheriting desktop grids. */
body.tms-mobile-ui{font-family:var(--tms-font-body);color:var(--tms-color-text);background:var(--tms-color-canvas)}
body.tms-mobile-ui :focus-visible{outline:.2rem solid #1689ff;outline-offset:.15rem}
body.tms-mobile-ui .top .actions{min-width:0}
body.tms-mobile-ui .top .button,body.tms-mobile-ui .top button{white-space:nowrap}
body.tms-mobile-ui input,body.tms-mobile-ui select,body.tms-mobile-ui textarea{max-width:100%}
body.tms-mobile-ui .portal-back{background:var(--tms-color-action-secondary)}

@media(max-width:56rem){
 :root{--tms-page-gutter:1rem}
 body.tms-ui .block-description{margin-bottom:.8rem}
 body.tms-ui table{min-width:38rem}
 body.tms-ui[data-tms-page="orders"] .layout,
 body.tms-ui[data-tms-page="planning"] .layout{grid-template-columns:1fr}
}

@media(max-width:38rem){
 :root{--tms-page-gutter:.65rem}
 .tms-section-head,body.tms-ui .panel-head{align-items:stretch}
 body.tms-ui .panel-head a,body.tms-ui .review-action{width:100%}
 body.tms-ui .review-count{flex:0 0 auto}
 body.tms-ui table{min-width:34rem}
 .tms-back-link{width:100%;justify-content:flex-start}
 body.tms-mobile-ui .top .actions{overflow-x:auto;flex-wrap:nowrap!important;justify-content:flex-start!important;width:100%;padding-bottom:.15rem;scrollbar-width:thin}
 body.tms-mobile-ui .top .portal-identity{position:absolute;width:1px;height:1px;overflow:hidden;clip:rect(0 0 0 0);white-space:nowrap}
}

@media(prefers-reduced-motion:reduce){
 body.tms-ui *,body.tms-ui *::before,body.tms-ui *::after{scroll-behavior:auto!important;transition-duration:.01ms!important;animation-duration:.01ms!important;animation-iteration-count:1!important}
}
