/* MASTERMD v49.5 — GLOBAL THEME REBUILD
   Purpose: one final design layer for every module. It overrides m19/m24/admin/patient
   token families, not just button colors. Must be loaded LAST on all pages. */

:root{
  --mmd-theme-transition: background-color .18s ease, color .18s ease, border-color .18s ease, box-shadow .18s ease;
}

html[data-mmd-theme="light"]{
  color-scheme: light;
  --mmd-bg:#eceff3!important;
  --mmd-bg-2:#f6f4f1!important;
  --mmd-surface:#fffdfa!important;
  --mmd-surface-2:#f5f1ed!important;
  --mmd-text:#24272d!important;
  --mmd-muted:#686d77!important;
  --mmd-line:#d8d1cb!important;
  --mmd-blue:#7b1e2b!important;
  --mmd-cyan:#a33a46!important;
  --mmd-green:#64705d!important;
  --mmd-amber:#9b6a2d!important;
  --mmd-red:#9f2633!important;
  --mmd-shadow:0 16px 40px rgba(58,42,39,.10)!important;
  --mmd-liquid-a:rgba(123,30,43,.075)!important;
  --mmd-liquid-b:rgba(65,69,80,.075)!important;
  --mmd-liquid-c:rgba(117,83,70,.055)!important;

  --m24-bg:#eceff3!important;
  --m24-bg-2:#f6f4f1!important;
  --m24-surface:#fffdfa!important;
  --m24-surface-2:#f5f1ed!important;
  --m24-surface-3:#eee8e3!important;
  --m24-surface-glass:rgba(255,253,250,.94)!important;
  --m24-text:#24272d!important;
  --m24-text-2:#505560!important;
  --m24-text-3:#77717a!important;
  --m24-line:#d8d1cb!important;
  --m24-line-strong:#c9bbb3!important;
  --m24-primary:#7b1e2b!important;
  --m24-primary-2:#a33a46!important;
  --m24-success:#64705d!important;
  --m24-warning:#9b6a2d!important;
  --m24-danger:#9f2633!important;
  --m24-shadow-sm:0 10px 22px rgba(58,42,39,.08)!important;
  --m24-shadow:0 18px 44px rgba(58,42,39,.12)!important;

  --bg:#eceff3!important; --sidebar:#f6f4f1!important; --surface:#fffdfa!important;
  --line:#d8d1cb!important; --line2:#c9bbb3!important; --text:#24272d!important; --muted:#686d77!important;
  --blue:#7b1e2b!important; --cyan:#a33a46!important; --success:#64705d!important; --warning:#9b6a2d!important; --danger:#9f2633!important;
}

html[data-mmd-theme="mono"]{
  color-scheme: light;
  --mmd-bg:#e9eaec!important;
  --mmd-bg-2:#f3f2ef!important;
  --mmd-surface:#fbfaf6!important;
  --mmd-surface-2:#efeeea!important;
  --mmd-text:#202226!important;
  --mmd-muted:#666a70!important;
  --mmd-line:#d3d2cf!important;
  --mmd-blue:#2d3035!important;
  --mmd-cyan:#565b62!important;
  --mmd-green:#3d4540!important;
  --mmd-amber:#55514c!important;
  --mmd-red:#34373c!important;
  --mmd-shadow:0 14px 34px rgba(29,31,35,.10)!important;
  --mmd-liquid-a:rgba(45,48,53,.06)!important;
  --mmd-liquid-b:rgba(80,84,92,.055)!important;
  --mmd-liquid-c:rgba(120,120,116,.04)!important;

  --m24-bg:#e9eaec!important;
  --m24-bg-2:#f3f2ef!important;
  --m24-surface:#fbfaf6!important;
  --m24-surface-2:#efeeea!important;
  --m24-surface-3:#e5e4e1!important;
  --m24-surface-glass:rgba(251,250,246,.94)!important;
  --m24-text:#202226!important;
  --m24-text-2:#51545a!important;
  --m24-text-3:#777a80!important;
  --m24-line:#d3d2cf!important;
  --m24-line-strong:#bebdb9!important;
  --m24-primary:#2d3035!important;
  --m24-primary-2:#565b62!important;
  --m24-success:#3d4540!important;
  --m24-warning:#55514c!important;
  --m24-danger:#34373c!important;
  --m24-shadow-sm:0 9px 20px rgba(29,31,35,.07)!important;
  --m24-shadow:0 16px 40px rgba(29,31,35,.10)!important;

  --bg:#e9eaec!important; --sidebar:#f3f2ef!important; --surface:#fbfaf6!important;
  --line:#d3d2cf!important; --line2:#bebdb9!important; --text:#202226!important; --muted:#666a70!important;
  --blue:#2d3035!important; --cyan:#565b62!important; --success:#3d4540!important; --warning:#55514c!important; --danger:#34373c!important;
}

html[data-mmd-theme="light"] body,
html[data-mmd-theme="light"] body.admin-body,
html[data-mmd-theme="light"] .mastermd-liquid-body,
html[data-mmd-theme="light"] .mastermd-liquid-scope,
html[data-mmd-theme="mono"] body,
html[data-mmd-theme="mono"] body.admin-body,
html[data-mmd-theme="mono"] .mastermd-liquid-body,
html[data-mmd-theme="mono"] .mastermd-liquid-scope{
  background:
    radial-gradient(circle at 12% -10%, var(--mmd-liquid-a), transparent 30%),
    radial-gradient(circle at 92% 0%, var(--mmd-liquid-b), transparent 34%),
    linear-gradient(135deg, var(--mmd-bg), var(--mmd-bg-2))!important;
  color:var(--mmd-text)!important;
}

html[data-mmd-theme="light"] .mmd-site-header,
html[data-mmd-theme="mono"] .mmd-site-header{
  background:rgba(255,253,250,.92)!important;
  border-bottom:1px solid var(--mmd-line)!important;
  box-shadow:0 10px 28px rgba(40,40,45,.06)!important;
}
html[data-mmd-theme="mono"] .mmd-site-header{background:rgba(251,250,246,.92)!important;}

html[data-mmd-theme="light"] .mmd-nav-wrap,
html[data-mmd-theme="mono"] .mmd-nav-wrap{color:var(--mmd-text)!important;}
html[data-mmd-theme="light"] .mmd-nav-link,
html[data-mmd-theme="light"] .mmd-nav-btn,
html[data-mmd-theme="mono"] .mmd-nav-link,
html[data-mmd-theme="mono"] .mmd-nav-btn{color:var(--mmd-text)!important;border-color:var(--mmd-line)!important;}

html[data-mmd-theme="light"] .m18-hero,
html[data-mmd-theme="light"] .patient-hero,
html[data-mmd-theme="light"] .section-card,
html[data-mmd-theme="light"] .m18-card,
html[data-mmd-theme="light"] .table-card,
html[data-mmd-theme="light"] .admin-card,
html[data-mmd-theme="light"] .card,
html[data-mmd-theme="light"] .dash-card,
html[data-mmd-theme="light"] .branch-card,
html[data-mmd-theme="light"] .plan-card,
html[data-mmd-theme="light"] .patient-card,
html[data-mmd-theme="light"] .patient-panel,
html[data-mmd-theme="light"] .report-card,
html[data-mmd-theme="light"] .mmd-report-card,
html[data-mmd-theme="light"] .auth-card,
html[data-mmd-theme="mono"] .m18-hero,
html[data-mmd-theme="mono"] .patient-hero,
html[data-mmd-theme="mono"] .section-card,
html[data-mmd-theme="mono"] .m18-card,
html[data-mmd-theme="mono"] .table-card,
html[data-mmd-theme="mono"] .admin-card,
html[data-mmd-theme="mono"] .card,
html[data-mmd-theme="mono"] .dash-card,
html[data-mmd-theme="mono"] .branch-card,
html[data-mmd-theme="mono"] .plan-card,
html[data-mmd-theme="mono"] .patient-card,
html[data-mmd-theme="mono"] .patient-panel,
html[data-mmd-theme="mono"] .report-card,
html[data-mmd-theme="mono"] .mmd-report-card,
html[data-mmd-theme="mono"] .auth-card{
  background:linear-gradient(180deg,var(--m24-surface-glass),var(--m24-surface))!important;
  border:1px solid var(--m24-line)!important;
  color:var(--m24-text)!important;
  box-shadow:var(--m24-shadow-sm)!important;
  backdrop-filter:none!important;
  -webkit-backdrop-filter:none!important;
}

html[data-mmd-theme="light"] h1,
html[data-mmd-theme="light"] h2,
html[data-mmd-theme="light"] h3,
html[data-mmd-theme="light"] h4,
html[data-mmd-theme="light"] strong,
html[data-mmd-theme="mono"] h1,
html[data-mmd-theme="mono"] h2,
html[data-mmd-theme="mono"] h3,
html[data-mmd-theme="mono"] h4,
html[data-mmd-theme="mono"] strong{color:var(--m24-text)!important;}
html[data-mmd-theme="light"] p,
html[data-mmd-theme="light"] li,
html[data-mmd-theme="light"] small,
html[data-mmd-theme="light"] td,
html[data-mmd-theme="light"] th,
html[data-mmd-theme="mono"] p,
html[data-mmd-theme="mono"] li,
html[data-mmd-theme="mono"] small,
html[data-mmd-theme="mono"] td,
html[data-mmd-theme="mono"] th{color:var(--m24-text-2)!important;}

html[data-mmd-theme="light"] input,
html[data-mmd-theme="light"] select,
html[data-mmd-theme="light"] textarea,
html[data-mmd-theme="mono"] input,
html[data-mmd-theme="mono"] select,
html[data-mmd-theme="mono"] textarea{
  background:var(--m24-surface-2)!important;
  border:1px solid var(--m24-line)!important;
  color:var(--m24-text)!important;
  box-shadow:inset 0 1px 0 rgba(255,255,255,.55)!important;
}

html[data-mmd-theme="light"] .btn,
html[data-mmd-theme="light"] .m18-btn,
html[data-mmd-theme="light"] .mmd-nav-btn,
html[data-mmd-theme="light"] button,
html[data-mmd-theme="light"] .mastermd-btn,
html[data-mmd-theme="mono"] .btn,
html[data-mmd-theme="mono"] .m18-btn,
html[data-mmd-theme="mono"] .mmd-nav-btn,
html[data-mmd-theme="mono"] button,
html[data-mmd-theme="mono"] .mastermd-btn{
  background:linear-gradient(180deg,var(--m24-surface),var(--m24-surface-2))!important;
  border:1px solid var(--m24-line)!important;
  color:var(--m24-text)!important;
  box-shadow:var(--m24-shadow-sm)!important;
}
html[data-mmd-theme="light"] .btn-primary,
html[data-mmd-theme="light"] .mmd-nav-cta,
html[data-mmd-theme="light"] button[type="submit"],
html[data-mmd-theme="mono"] .btn-primary,
html[data-mmd-theme="mono"] .mmd-nav-cta,
html[data-mmd-theme="mono"] button[type="submit"]{
  background:linear-gradient(135deg,var(--m24-primary),var(--m24-primary-2))!important;
  color:#fff!important;
  border-color:transparent!important;
}

html[data-mmd-theme="light"] table,
html[data-mmd-theme="mono"] table{background:transparent!important;border-collapse:separate!important;border-spacing:0 8px!important;}
html[data-mmd-theme="light"] table thead th,
html[data-mmd-theme="mono"] table thead th{background:transparent!important;color:var(--m24-text-3)!important;border:0!important;}
html[data-mmd-theme="light"] table tbody td,
html[data-mmd-theme="mono"] table tbody td{
  background:var(--m24-surface)!important;
  border-top:1px solid var(--m24-line)!important;
  border-bottom:1px solid var(--m24-line)!important;
  color:var(--m24-text-2)!important;
}
html[data-mmd-theme="light"] table tbody tr td:first-child,
html[data-mmd-theme="mono"] table tbody tr td:first-child{border-left:1px solid var(--m24-line)!important;border-top-left-radius:14px!important;border-bottom-left-radius:14px!important;}
html[data-mmd-theme="light"] table tbody tr td:last-child,
html[data-mmd-theme="mono"] table tbody tr td:last-child{border-right:1px solid var(--m24-line)!important;border-top-right-radius:14px!important;border-bottom-right-radius:14px!important;}

/* Admin — rebuilt mobile and theme */
html[data-mmd-theme="light"] .admin-shell,
html[data-mmd-theme="mono"] .admin-shell{background:transparent!important;color:var(--mmd-text)!important;}
html[data-mmd-theme="light"] .admin-sidebar,
html[data-mmd-theme="mono"] .admin-sidebar{
  background:linear-gradient(180deg,var(--m24-surface),var(--m24-surface-2))!important;
  border-right:1px solid var(--m24-line)!important;
  box-shadow:10px 0 30px rgba(33,35,40,.05)!important;
}
html[data-mmd-theme="light"] .admin-main,
html[data-mmd-theme="mono"] .admin-main{
  background:linear-gradient(135deg,var(--mmd-bg),var(--mmd-bg-2))!important;
  color:var(--mmd-text)!important;
}
html[data-mmd-theme="light"] .admin-nav a,
html[data-mmd-theme="mono"] .admin-nav a{color:var(--m24-text-2)!important;border-color:transparent!important;background:transparent!important;}
html[data-mmd-theme="light"] .admin-nav a:hover,
html[data-mmd-theme="light"] .admin-nav a.active,
html[data-mmd-theme="mono"] .admin-nav a:hover,
html[data-mmd-theme="mono"] .admin-nav a.active{
  background:linear-gradient(135deg,color-mix(in srgb,var(--m24-primary) 12%,var(--m24-surface)),var(--m24-surface-2))!important;
  color:var(--m24-primary)!important;
  border-color:color-mix(in srgb,var(--m24-primary) 22%,var(--m24-line))!important;
}
html[data-mmd-theme="mono"] .admin-nav a:hover,
html[data-mmd-theme="mono"] .admin-nav a.active{color:#1f2328!important;}
html[data-mmd-theme="light"] .admin-nav-section-title,
html[data-mmd-theme="light"] .admin-kicker{color:#7b1e2b!important;}
html[data-mmd-theme="mono"] .admin-nav-section-title,
html[data-mmd-theme="mono"] .admin-kicker{color:#2d3035!important;}
html[data-mmd-theme="light"] .admin-userbox,
html[data-mmd-theme="mono"] .admin-userbox{background:var(--m24-surface)!important;border:1px solid var(--m24-line)!important;color:var(--m24-text)!important;}

/* Theme pills */
html[data-mmd-theme="light"] .mmd-theme-switcher,
html[data-mmd-theme="mono"] .mmd-theme-switcher{background:var(--m24-surface-2)!important;border:1px solid var(--m24-line)!important;box-shadow:var(--m24-shadow-sm)!important;}
html[data-mmd-theme="light"] .theme-pill,
html[data-mmd-theme="mono"] .theme-pill{background:transparent!important;color:var(--m24-text-2)!important;box-shadow:none!important;border:0!important;}
html[data-mmd-theme="light"] .theme-pill.is-active,
html[data-mmd-theme="mono"] .theme-pill.is-active{background:linear-gradient(135deg,var(--m24-primary),var(--m24-primary-2))!important;color:#fff!important;}

/* Mobile hardening */
@media(max-width:900px){
  html[data-mmd-theme] body{overflow-x:hidden!important;}
  .admin-shell{display:block!important;min-height:100vh!important;width:100%!important;}
  .admin-sidebar{position:relative!important;top:auto!important;left:auto!important;width:100%!important;max-width:none!important;height:auto!important;min-height:0!important;padding:14px!important;border-right:0!important;border-bottom:1px solid var(--m24-line)!important;overflow:visible!important;}
  .admin-brand{margin-bottom:10px!important;}
  .admin-nav{display:flex!important;gap:8px!important;overflow-x:auto!important;overflow-y:hidden!important;white-space:nowrap!important;padding:4px 2px 10px!important;scroll-snap-type:x proximity!important;-webkit-overflow-scrolling:touch!important;}
  .admin-nav-section-title{display:none!important;}
  .admin-nav a{flex:0 0 auto!important;min-height:40px!important;border-radius:999px!important;padding:10px 13px!important;scroll-snap-align:start!important;}
  .admin-main{width:100%!important;min-width:0!important;padding:14px!important;margin:0!important;}
  .admin-topbar{display:grid!important;grid-template-columns:1fr!important;gap:12px!important;margin-bottom:12px!important;}
  .admin-topbar h1{font-size:clamp(25px,7vw,34px)!important;line-height:1.05!important;}
  .admin-userbox{width:100%!important;justify-content:flex-start!important;}
  .admin-theme-row{display:flex!important;width:100%!important;justify-content:stretch!important;}
  .admin-theme-row .mmd-theme-switcher{width:100%!important;display:grid!important;grid-template-columns:repeat(3,1fr)!important;}
  .table-card,.admin-card,.card,.patient-card,.patient-panel,.report-card,.m18-card,.section-card{border-radius:20px!important;padding:16px!important;max-width:100%!important;}
  .table-responsive,.table-wrap,.admin-table-wrap,.m18-table-wrap{width:100%!important;overflow-x:auto!important;-webkit-overflow-scrolling:touch!important;}
  table{min-width:680px!important;}
  input,select,textarea{font-size:16px!important;max-width:100%!important;}
  .btn,.m18-btn,.mmd-nav-btn,.mastermd-btn,button{max-width:100%!important;white-space:normal!important;min-height:44px!important;}
  .actions,.admin-actions,.patient-actions,.m18-actions,.form-actions{display:flex!important;flex-wrap:wrap!important;gap:8px!important;}
  .actions > *,.admin-actions > *,.patient-actions > *,.m18-actions > *,.form-actions > *{flex:1 1 160px!important;}
}

@media(max-width:560px){
  .admin-main{padding:10px!important;}
  .admin-sidebar{padding:10px!important;}
  .admin-nav a{font-size:12px!important;padding:9px 11px!important;}
  table{min-width:620px!important;}
  .mmd-theme-switcher{width:100%!important;}
  .theme-pill{padding:0 8px!important;}
}
