/* Evorah Gold UI/UX Phase V12
   Final consistency layer. Uses theme tokens only and avoids broad text overrides. */
:root{
  --gold-page-max: 1600px;
  --gold-space-1: 6px;
  --gold-space-2: 10px;
  --gold-space-3: 16px;
  --gold-space-4: 22px;
  --gold-space-5: 30px;
  --gold-control-h: 44px;
  --gold-radius-sm: 10px;
  --gold-radius-md: 14px;
  --gold-radius-lg: 18px;
}

/* Predictable sizing and page geometry */
*,*::before,*::after{box-sizing:border-box}
html{scroll-behavior:smooth}
body{min-width:0;overflow-x:hidden}
main{width:min(100%,var(--gold-page-max));min-width:0;margin-inline:auto}
main>*{min-width:0}
img,svg,video,canvas{max-width:100%}

/* Shared page rhythm */
.page-head,.page-header,.gradient-head,.compact-hero{margin-bottom:var(--gold-space-4)}
.panel,.card,.record,.content-section,.form-card{min-width:0}
.panel+.panel,.card+.card,.content-section+.content-section{margin-top:var(--gold-space-3)}
.section-heading,.panel-heading,.card-heading{display:flex;align-items:flex-start;justify-content:space-between;gap:var(--gold-space-3);min-width:0}
.section-heading>*:first-child,.panel-heading>*:first-child,.card-heading>*:first-child{min-width:0}

/* Typography and wrapping */
h1,h2,h3,h4,h5,h6,p,li,dt,dd,th,td,label,legend{overflow-wrap:anywhere}
h1,h2,h3,h4{line-height:1.18}
p{line-height:1.5}
.muted,.helptext,.small,small{line-height:1.45}

/* Forms */
input:not([type="checkbox"]):not([type="radio"]),select,textarea{
  width:100%;min-width:0;min-height:var(--gold-control-h);border-radius:var(--gold-radius-sm);
}
textarea{min-height:110px;resize:vertical}
input[type="checkbox"],input[type="radio"]{flex:0 0 auto}
form p{min-width:0}
.form-grid,.detail-grid,.settings-grid,.staff-basic-grid{align-items:start}
.form-actions{display:flex;align-items:center;justify-content:flex-end;gap:var(--gold-space-2);flex-wrap:wrap}

/* Buttons and links */
button,.button,.btn,a.button,input[type="submit"]{
  min-height:var(--gold-control-h);display:inline-flex;align-items:center;justify-content:center;gap:8px;
  line-height:1.2;text-align:center;white-space:normal;
}
button:focus-visible,.button:focus-visible,a:focus-visible,input:focus-visible,select:focus-visible,textarea:focus-visible{
  outline:3px solid color-mix(in srgb,var(--ev-accent) 42%,transparent);outline-offset:2px;
}

/* Tables */
.table-wrap,.responsive-table{width:100%;max-width:100%;overflow:auto;border-radius:var(--gold-radius-md)}
table{width:100%;max-width:100%;border-collapse:collapse}
th,td{vertical-align:top}

/* Tabs: no wrapping, no phantom targets */
.tabs-panel,.clean-tabs,.filter-tabs,.access-tabs{max-width:100%;overscroll-behavior-inline:contain}
.tabs-panel a,.clean-tabs a,.filter-tabs a,.access-tab{white-space:nowrap}
.tab-unavailable,[aria-disabled="true"].access-tab{opacity:.5;cursor:not-allowed;pointer-events:none}

/* Empty states remain legible and contained */
.empty-state,.empty-young-directory,.empty-panel{min-height:150px;display:flex;flex-direction:column;align-items:center;justify-content:center;text-align:center;padding:var(--gold-space-5);gap:var(--gold-space-2)}

/* Role cards and authority cards: prevent overflow */
.role-choice,.authority-card,.local-authority-card,.authority-option{contain:layout paint}
.role-choice-copy,.authority-card span,.local-authority-card span,.authority-option span{min-width:0}

/* Light and dark modes share geometry. Only colours change. */
html[data-theme="dark"]{
  --gold-shadow:0 10px 28px rgba(0,0,0,.28);
}
html[data-theme="light"]{
  --gold-shadow:0 10px 28px rgba(19,40,48,.09);
}
html[data-theme] :is(.panel,.card,.record,.content-section,.form-card,.page-head,.page-header,.gradient-head,.compact-hero){box-shadow:var(--gold-shadow)}

/* Dark mode component contrast — targeted, never blanket recolouring of descendants */
html[data-theme="dark"] :is(.panel,.card,.record,.content-section,.form-card,.stat-card,.young-stat-card,.allocated-stat,.planner-stat,.referral-kpi,.admin-user-card,.match-card){
  background-color:var(--ev-surface);color:var(--ev-text);border-color:var(--ev-border);
}
html[data-theme="dark"] :is(input:not([type="checkbox"]):not([type="radio"]),select,textarea){
  background-color:var(--ev-surface-2);color:var(--ev-text);border-color:var(--ev-border);
}
html[data-theme="dark"] :is(input,textarea)::placeholder{color:var(--ev-text-soft);opacity:.82}
html[data-theme="dark"] option{background:var(--ev-surface);color:var(--ev-text)}
html[data-theme="dark"] :is(.button.secondary,.button-light,.secondary){background:var(--ev-surface-2);color:var(--ev-text);border-color:var(--ev-border)}
html[data-theme="dark"] :is(.button.secondary,.button-light,.secondary) *{color:inherit}

/* Intentionally pale action cards need explicit foreground colours. */
html[data-theme="dark"] .add-young-person-primary,
html[data-theme="dark"] .light-action-card,
html[data-theme="dark"] .pale-action-card{
  background:#edf7f6!important;color:#163840!important;border-color:#b9d8d5!important;
}
html[data-theme="dark"] :is(.add-young-person-primary,.light-action-card,.pale-action-card) *{color:inherit!important}
html[data-theme="dark"] :is(.add-young-person-primary,.light-action-card,.pale-action-card) :is(small,.muted){color:#536c72!important}

/* Status colours retain contrast in both themes */
html[data-theme="dark"] .notice.warning{background:#42391f;color:#ffe3a0;border-color:#75612d}
html[data-theme="dark"] :is(.success-note,.message.success){background:#173a31;color:#c5f3df;border-color:#315f51}
html[data-theme="dark"] :is(.errorlist,.message.error,.notice.error){background:#48262b;color:#ffd4d8;border-color:#7a4048}

/* Consistent responsive collapse */
@media(max-width:1180px){
  .four-col,.stats,.young-stats,.referral-kpis{grid-template-columns:repeat(2,minmax(0,1fr))}
}
@media(max-width:820px){
  main{padding:16px}
  .page-head,.page-header,.gradient-head,.compact-hero{padding:18px}
  .section-heading,.panel-heading,.card-heading{flex-direction:column}
  .form-actions{justify-content:stretch}.form-actions>*{flex:1 1 auto}
  .four-col,.three-col,.two-col,.stats,.young-stats,.referral-kpis,.detail-grid,.form-grid,.settings-grid,.staff-basic-grid{grid-template-columns:1fr!important}
}

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

/* v1.0.32 complete dark-mode coverage — authoritative final layer */
html[data-theme="dark"]{
  --ev-bg:#10171b;--ev-surface:#182126;--ev-surface-2:#202c32;--ev-surface-3:#27363d;
  --ev-text:#f3f7f8;--ev-text-soft:#b9c8cd;--ev-border:#3b4c54;--ev-accent:#50b9b0;
  --bg:var(--ev-bg);--surface:var(--ev-surface);--surface-alt:var(--ev-surface-2);
  --text:var(--ev-text);--muted:var(--ev-text-soft);--border:var(--ev-border);--accent:var(--ev-accent);
  color-scheme:dark;
}
html[data-theme="dark"] body,html[data-theme="dark"] main{background:var(--ev-bg)!important;color:var(--ev-text)!important}
html[data-theme="dark"] main :is(.panel,.card,.record,.module-card,.dashboard-card,.stat-card,.young-stat-card,.allocated-stat,.planner-stat,.operational-stat,.referral-kpi,.keyworker-match-card,.match-card,.account-record,.notification-panel,.dialog-card,dialog,.modal-content,.table-wrap,.timeline-item,.detail-grid>div,details:not(.nav-section):not(.notification-centre),.empty-state,.settings-card,.appraisal-card){background:var(--ev-surface)!important;color:var(--ev-text)!important;border-color:var(--ev-border)!important;box-shadow:none!important}
html[data-theme="dark"] main :is(h1,h2,h3,h4,h5,h6,strong,b,label,legend,th,dt){color:var(--ev-text)!important}
html[data-theme="dark"] main :is(p,small,.small,.muted,.helptext,.hint,.subtitle,.page-eyebrow,.eyebrow,td,dd){color:var(--ev-text-soft)!important}
html[data-theme="dark"] main :is(input,select,textarea,.form-control){background:#121b1f!important;color:var(--ev-text)!important;border-color:#4a5e67!important;caret-color:var(--ev-text)!important}
html[data-theme="dark"] main :is(input,textarea)::placeholder{color:#8ea2aa!important;opacity:1}
html[data-theme="dark"] main select option{background:#121b1f!important;color:var(--ev-text)!important}
html[data-theme="dark"] main table{background:var(--ev-surface)!important;color:var(--ev-text)!important;border-color:var(--ev-border)!important}
html[data-theme="dark"] main :is(th,.report-meta-table th){background:var(--ev-surface-3)!important;color:var(--ev-text)!important;border-color:var(--ev-border)!important}
html[data-theme="dark"] main :is(td,.report-meta-table td){background:var(--ev-surface)!important;color:var(--ev-text)!important;border-color:var(--ev-border)!important}
html[data-theme="dark"] main tr:hover td{background:#223139!important}
html[data-theme="dark"] main hr{border-color:var(--ev-border)!important}
html[data-theme="dark"] main :is(.button-light,.secondary-action,.button.secondary){background:var(--ev-surface-3)!important;color:var(--ev-text)!important;border-color:#536770!important}
html[data-theme="dark"] main :is(.primary-action,button[type="submit"],.button,.button-link){color:#062f32!important}
html[data-theme="dark"] main :is(.danger,.danger-action,.button-danger){color:#fff!important}
html[data-theme="dark"] main a:not(.button):not(.button-link):not(.nav-link){color:#7ed4cd}
html[data-theme="dark"] .top-notification-bar{background:rgba(16,23,27,.96)!important;border-color:var(--ev-border)!important}
html[data-theme="dark"] .theme-switcher{background:var(--ev-surface)!important;border-color:var(--ev-border)!important;color:var(--ev-text)!important}
html[data-theme="dark"] .theme-switcher button{background:var(--ev-surface-2)!important;color:var(--ev-text)!important;border-color:var(--ev-border)!important}
html[data-theme="dark"] .theme-switcher button.active{background:var(--ev-accent)!important;color:#062f32!important}
html[data-theme="dark"] main :is(.sticky-action-bar,.filter-toolbar){background:rgba(16,23,27,.96)!important;border-color:var(--ev-border)!important}
html[data-theme="dark"] main :is(.status-pill,.priority-pill,.risk,.badge,.tag,.pill){border:1px solid currentColor}
html[data-theme="dark"] main :is(.notice.warning,.message.warning){background:#40371d!important;color:#ffe6a6!important;border-color:#75642f!important}
html[data-theme="dark"] main :is(.success-note,.notice.success,.message.success){background:#173a31!important;color:#d1f7e8!important;border-color:#376456!important}
html[data-theme="dark"] main :is(.notice.error,.message.error,.errorlist){background:#47272c!important;color:#ffd8dc!important;border-color:#7c454d!important}

/* British-English presentation and text-entry consistency */
html[lang="en-GB"] :is(input,textarea){font-variant-ligatures:common-ligatures}

/* v1.0.46 workflow clarity */
.page-navigation{display:flex;margin:0 0 16px}.document-reclassify-form{display:flex;gap:6px;align-items:center;grid-column:1/-1;margin-top:8px}.document-reclassify-form select{min-width:0;flex:1}.document-reclassify-form button{padding:7px 12px}.needs-review-card{border-style:dashed}.needs-review-card .document-card-top{background:rgba(255,184,77,.10)}
