/* Shared visual system for the clinical workspace. Print uses the existing templates. */
.nutrient-section h4 { margin: 14px 0 5px; }
@media print {
  #print-area .nutrient-section h4 { break-after: avoid; }
  #print-area .nutrient-section :is(td,th) { padding: 3pt; }
  #print-area .nutrient-section td { text-align: right; white-space: nowrap; }
}
@media screen {
  :root {
    --font-ui: "Segoe UI Variable", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    --type-page: clamp(30px, 3vw, 44px);
    --type-section: 19px;
    --type-body: 15px;
    --type-small: 13px;
    --type-label: 12px;
    --gutter: clamp(24px, 3.4vw, 54px);
    --gap: 20px;
    --panel-pad: clamp(18px, 2vw, 26px);
    --radius: 18px;
    --control: 10px;
    --canvas: #f7f5f1;
    --surface: #fffefa;
    --ink: #342e29;
    --muted: #756b61;
    --line: #e8e2d9;
    --primary: #7d4222;
    --primary-hover: #68371d;
    --soft: #f0e5da;
    --warm-dark: #4a382b;
    --olive: #606b31;
    --olive-wash: #eef0e2;
    --rose-ink: #803c4c;
    --rose-wash: #f8e9ec;
    --field-line: #a3988b;
    --protein: #7d4222;
    --carbs: #606b31;
    --fat: #a24d63;
    --shadow: 0 2px 5px #4a382b08;
    --sidebar-width: 236px;
    font-family: var(--font-ui);
  }
  body { font-size: var(--type-body); line-height: 1.5; }
  :is(button, input, select, textarea) { font-family: inherit; }
  :is(button, input, select, textarea, summary, a):focus-visible {
    outline: 2px solid var(--primary);
    outline-offset: 3px;
  }
  :is(button, a, summary) { -webkit-tap-highlight-color: #7d422226; }
  ::selection { color: var(--ink); background: var(--soft); }

  /* App shell */
  .portal-sidebar { background: var(--surface); padding: 28px 16px 20px; }
  .portal-brand { padding: 3px 9px 24px; }
  .portal-brand img { width: min(100%, 180px); }
  .workspace-label {
    padding: 16px 9px;
    margin: 0 0 22px;
    border-width: 1px 0;
    border-radius: 0;
    background: transparent;
  }
  .workspace-mark, .practitioner-avatar { background: var(--soft); color: var(--primary); }
  .workspace-label strong, .practitioner strong { font-size: var(--type-small); font-weight: 650; }
  .workspace-label div > span, .practitioner div > span, .sidebar-environment {
    font-size: var(--type-label); margin-top: 0;
  }
  .nav-section-label { color: var(--muted); font-size: 11px; font-weight: 700; padding-inline: 11px; }
  .portal-nav { gap: 4px; }
  .portal-nav button {
    min-height: 46px; padding: 10px 10px; border-radius: var(--control);
    font-size: var(--type-small); color: var(--muted); font-weight: 540;
  }
  .portal-nav button > .ui-icon { color: currentColor; flex-shrink: 0; }
  .portal-nav button:hover { background: var(--canvas); color: var(--ink); }
  .portal-nav button[aria-current="page"] {
    background: var(--soft); color: var(--primary); border-color: transparent;
    font-weight: 700; box-shadow: inset 3px 0 var(--primary);
  }
  .portal-nav .nav-count,
  .portal-nav button[aria-current="page"] .nav-count {
    color: inherit; background: var(--canvas); font-size: 11px; border-radius: 6px;
    font-variant-numeric: tabular-nums;
  }
  .sidebar-environment { padding-inline: 9px; }
  .environment-dot { background: var(--olive); }
  .portal-topbar { height: 68px; padding-inline: var(--gutter); gap: 18px; }
  .topbar-location, .topbar-date { font-size: var(--type-small); }
  #portal-location { font-weight: 650; }
  .breadcrumb-divider { color: var(--muted); }
  .portal-search { background: var(--canvas); border-radius: var(--control); min-height: 42px; }
  .portal-search input { font-size: var(--type-small); }
  .portal-search button { width: 36px; height: 38px; }
  .portal-main { max-width: 1540px; padding: 27px var(--gutter) 52px; }
  .portal-main > .local-note {
    padding: 0; margin: 0 0 23px; font-size: var(--type-label);
    line-height: 1.45;
  }
  .portal-footer { padding-inline: var(--gutter); font-size: var(--type-label); }

  /* Type scale and everyday controls */
  .portal-page-heading, .portal-main > section > .section-heading, .patient-profile-heading {
    align-items: flex-end;
    gap: 16px 24px;
    margin: 0 0 25px;
    padding-bottom: 20px;
    border-bottom: 1px solid var(--line);
  }
  .portal-page-heading h1, .portal-main > section > .section-heading h1,
  .patient-profile-heading h1, .patient-portal-header h1 {
    color: var(--ink); font-size: var(--type-page); line-height: 1.08;
    letter-spacing: -.044em; font-weight: 690; overflow-wrap: anywhere;
  }
  .portal-page-heading p, .portal-main > section > .section-heading p, .patient-profile-heading p {
    font-size: var(--type-body); line-height: 1.45; margin: 8px 0 0;
  }
  .portal-main h2, dialog h2 { font-size: var(--type-section); line-height: 1.25; letter-spacing: -.02em; }
  .portal-main h3, dialog h3 { font-size: 16px; line-height: 1.3; letter-spacing: -.012em; }
  .portal-main label, dialog label { font-size: var(--type-small); font-weight: 600; }
  :is(.portal-main, dialog) :is(input:not([type=radio],[type=checkbox],[type=range],[type=color]), select, textarea) {
    border-color: var(--field-line); border-radius: var(--control); font-size: 14px;
  }
  :is(.portal-main, dialog) :is(input:not([type=radio],[type=checkbox],[type=range],[type=color]), select) {
    min-height: 42px;
  }
  .portal-main .method, .dialog-help, .source-tag, .result-count, .save-status { font-size: var(--type-small); }
  .primary, .secondary {
    min-height: 42px; border-radius: var(--control); padding: 9px 15px;
    font-size: var(--type-small); font-weight: 650; line-height: 1.25; white-space: normal;
  }
  .primary:not(:disabled):hover { background: var(--primary-hover); border-color: var(--primary-hover); }
  .secondary, .icon-button { border-color: var(--field-line); background: var(--surface); }
  .secondary:not(:disabled):hover, .icon-button:hover { color: var(--primary); background: var(--soft); }
  .text-button, .today-link { color: var(--primary); font-size: var(--type-small); font-weight: 650; }
  .text-button:hover, .today-link:hover { text-decoration: underline; text-underline-offset: 3px; }
  .icon-button { border-radius: var(--control); }
  dialog { border-radius: var(--radius); background: var(--surface); box-shadow: 0 18px 60px #342e2938; }
  dialog::backdrop { background: #342e2975; }
  .dialog-heading { border-bottom: 1px solid var(--line); padding-bottom: 12px; }
  .dialog-heading .close { min-width: 40px; min-height: 40px; color: var(--primary); }
  .portal-mobile-menu .mobile-menu-note { font-size: var(--type-small); }

  /* Hoje: featured weekly agenda and a quieter queue for follow-up work. */
  #view-dashboard .today-heading { margin-bottom: var(--gap); }
  #view-dashboard #dashboard-day {
    margin: 0 0 7px; font-size: var(--type-label); font-weight: 680;
    letter-spacing: .065em; text-transform: uppercase; color: var(--primary);
  }
  #view-dashboard .today-heading .today-intro { margin: 8px 0 0; }
  .today-overview, .today-detail { gap: var(--gap); }
  .today-overview { grid-template-columns: minmax(0,1.5fr) repeat(2,minmax(0,1fr)); }
  .today-detail { grid-template-columns: minmax(0,2fr) minmax(0,1fr); margin-top: var(--gap); }
  .today-card {
    padding: var(--panel-pad); border-radius: var(--radius); box-shadow: var(--shadow);
  }
  .today-card-header { gap: 2px 10px; }
  .today-card-header h2 { font-size: var(--type-section); }
  .today-card-header > span { font-size: var(--type-small); }
  .today-week { color: var(--surface); background: var(--warm-dark); border-color: var(--warm-dark); }
  .today-week-total { margin-top: 14px; }
  .today-week-total strong, .today-money-total strong {
    font-size: clamp(27px, 3.15vw, 47px); line-height: 1.08; font-weight: 675;
  }
  .today-week-total span { color: var(--soft); font-size: var(--type-small); }
  .today-bars { gap: 4px; margin-top: 14px; }
  .today-day {
    min-height: 76px; border-radius: var(--control); color: var(--surface);
    padding: 7px 2px; font-size: var(--type-label);
  }
  .today-day:hover { background: #fffefa20; }
  .today-day[aria-pressed="true"] { background: var(--soft); border-color: var(--soft); color: var(--ink); }
  .today-day:focus-visible { outline-color: var(--surface); }
  .today-bar-track { width: min(17px,100%); height: 49px; background: #fffefa28; }
  .today-bar-track span { background: var(--soft); }
  .today-day[aria-pressed="true"] .today-bar-track { background: #7d422224; }
  .today-day[aria-pressed="true"] .today-bar-track span { background: var(--primary); }
  .today-money-total { margin-top: 13px; }
  .today-money-total > span, .today-figures dt { font-size: var(--type-small); }
  .today-figures dd { font-size: var(--type-body); }
  .today-empty { padding: 14px; font-size: var(--type-small); }
  .today-empty h3 { margin: 0 0 4px; }
  #today-form-count strong { font-size: 32px; }

  /* The same surfaces carry through patients, agenda, plans, catalog and finance. */
  :is(.patient-row, .registration-surface, .patient-document-card, .appointment-card,
      .upcoming-panel, .plan-context, .plan-switcher, .meal, .finance-metric, .finance-chart-panel,
      .source-status-panel, .template-sheet, .material-preview, .portal-access-panel,
      .patient-home-actions button, .crm-day-metrics > div, .crm-patient-overview > div) {
    border-radius: var(--radius); border-color: var(--line); box-shadow: var(--shadow);
  }
  :is(.patient-row, .patient-document-card, .appointment-card, .template-sheet,
      .finance-metric, .upcoming-panel) { background: var(--surface); }
  :is(.patient-row, .patient-document-card, .appointment-card) { padding: 15px 18px; }
  :is(.patient-row, .patient-document-card, .appointment-card) strong { color: var(--ink); }
  :is(.patient-row, .patient-document-card, .appointment-card) p { font-size: var(--type-small); }
  :is(.profile-tabs, .document-workspace-tabs, .patient-portal-nav) { border-color: var(--line); }
  :is(.profile-tabs, .document-workspace-tabs, .patient-portal-nav) button {
    min-height: 44px; font-size: var(--type-small); color: var(--muted);
  }
  :is(.profile-tabs, .document-workspace-tabs, .patient-portal-nav) button[aria-current] {
    color: var(--primary); border-color: var(--primary); font-weight: 700;
  }
  .search-line, .food-filters.multi-source, .agenda-toolbar {
    background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
    padding: 16px 18px; gap: 14px;
  }
  .food-library-settings { margin: 10px 0 16px; }
  .food-library-settings > summary { cursor: pointer; color: var(--primary); padding-block: 10px; }
  .food-library-settings .source-status-panel { margin: 12px 0 0; }
  .finance-metric.expense { background: var(--rose-wash); }
  .finance-metric.pending { background: var(--soft); }
  .finance-metric.balance { background: var(--warm-dark); color: var(--surface); }
  .finance-metric.balance small { color: var(--soft); }
  .finance-metric > span, .finance-metric small { font-size: var(--type-label); }
  .finance-metric strong { font-size: clamp(21px, 2.1vw, 32px); overflow-wrap: anywhere; }
  .status-badge, .dashboard-appointment .status-badge, .crm-billing-status {
    font-size: var(--type-label); line-height: 1.35;
  }
  .status-badge.done, .crm-billing-status.paid { color: var(--olive); background: var(--olive-wash); }
  .status-badge.overdue { color: var(--rose-ink); background: var(--rose-wash); }
  .crm-billing-amount { font-variant-numeric: tabular-nums; }
  .plan-layout { gap: var(--gap); }
  .plan-switcher-note { font-size: var(--type-small); }
  .plan-layout, .meal-header > *, .meal-item > *, .patient-row > * { min-width: 0; }
  .meal-nutrition { background: var(--canvas); border-color: var(--line); border-radius: 12px; }
  .meal-title-input { color: var(--ink); }
  .meal-stats strong, .summary-macros strong, .finance-metric strong, .appointment-time {
    font-variant-numeric: tabular-nums;
  }
  .meal-stat > span, .meal-micros, .summary-note { font-size: var(--type-label); }
  .daily-summary { background: var(--surface); color: var(--ink); border-color: var(--line); }
  .macro-legend > div, .macro-legend strong { font-size: var(--type-label); }
  .patient-portal-shell { color: var(--ink); }
  .patient-home-actions button:hover { background: var(--soft); border-color: var(--primary); }

  @media (max-width: 1190px) {
    .today-overview { grid-template-columns: repeat(2,minmax(0,1fr)); }
    .today-week { grid-column: 1 / -1; }
  }
  @media (max-width: 960px) {
    :root { --gutter: 24px; }
    .mobile-menu-toggle { background: var(--surface); }
  }
  @media (max-width: 670px) {
    :root { --gutter: 16px; --gap: 14px; --panel-pad: 16px; }
    .portal-topbar { height: 62px; gap: 8px; }
    .portal-main { padding-top: 18px; padding-bottom: 32px; }
    .portal-main > .local-note { margin-bottom: 18px; }
    .portal-page-heading, .portal-main > section > .section-heading, .patient-profile-heading {
      align-items: flex-start; flex-direction: column; gap: 13px; margin-bottom: 18px; padding-bottom: 16px;
    }
    .today-detail { grid-template-columns: minmax(0,1fr); }
    .today-actions :is(.primary, .secondary), .portal-main .actions :is(.primary, .secondary) { min-height: 44px; }
    .food-filters.multi-source, .search-line, .agenda-toolbar { padding: 12px; }
    .portal-main .meal-stat > span, .portal-main .meal-micros { font-size: var(--type-label); }
  }
  @media (max-width: 475px) {
    .today-overview { grid-template-columns: minmax(0,1fr); }
    .today-week { grid-column: auto; }
    .portal-footer { flex-wrap: wrap; }
    .portal-search { min-width: 44px; min-height: 44px; }
  }
  @media (min-width: 370px) and (max-width: 600px) {
    .portal-main .food-filters.multi-source {
      grid-template-columns: repeat(2,minmax(0,1fr)); gap: 10px;
    }
    .portal-main .food-filters.multi-source label:last-child { grid-column: 1 / -1; }
  }
  @media (prefers-reduced-motion: reduce) {
    .portal-nav button, .today-day, .primary, .secondary { transition: none; }
  }
}
