/* Semantic adapter. Palette primitives are inputs; legacy names below are outputs.
   Keep these directions separate to avoid custom-property cycles. */
:root {
  --sd-background:#f6f6f6;
  --sd-foreground:#242424;
  --sd-secondary-foreground:#404040;
  --sd-card:#ffffff;
  --sd-card-foreground:var(--sd-foreground);
  --sd-popover:var(--sd-card);
  --sd-popover-foreground:var(--sd-foreground);
  --sd-primary:var(--palette-brand,#B8862B);
  --sd-primary-foreground:var(--palette-on-brand,#2B2118);
  --sd-primary-hover:var(--palette-brand-ink,#966B20);
  --sd-primary-text:var(--palette-brand-ink,#8A611E);
  --sd-secondary:var(--sd-card);
  --sd-secondary-hover:var(--sd-muted-background);
  --sd-secondary-border:var(--sd-input-border);
  --sd-accent:color-mix(in srgb,var(--sd-primary) 8%,var(--sd-card));
  --sd-accent-foreground:var(--sd-primary-text);
  --sd-accent-hover:var(--sd-muted-background);
  --sd-decorative-accent:var(--palette-rose,#966B20);
  --sd-muted-background:#eeeeee;
  --sd-muted-foreground:#626262;
  --sd-border:#dedede;
  --sd-input-border:#858585;
  --sd-ring:var(--sd-primary-text);
  --sd-destructive:var(--bad);
  --sd-destructive-foreground:var(--on-error);
  --sd-sidebar:#202020;
  --sd-sidebar-foreground:#e8e8e8;
  --sd-sidebar-muted-foreground:#b5b5b5;
  --sd-sidebar-heading-foreground:#ffffff;
  --sd-sidebar-primary:#343434;
  --sd-sidebar-primary-foreground:#ffffff;
  --sd-sidebar-accent:#2c2c2c;
  --sd-sidebar-accent-foreground:var(--sd-sidebar-foreground);
  --sd-sidebar-border:#414141;
  --sd-sidebar-ring:#f0f0f0;
  --sd-sidebar-indicator:color-mix(in srgb,var(--sd-primary) 55%,#ffffff);
  /* Data accents follow the palette; chart surfaces and status colors stay neutral/semantic. */
  --sd-chart-1:var(--sd-primary-text);
  --sd-chart-2:color-mix(in srgb,var(--sd-primary-text) 70%,var(--sd-foreground));
  --sd-chart-3:color-mix(in srgb,var(--sd-primary-text) 35%,#386ba8);
  --sd-chart-4:color-mix(in srgb,var(--sd-primary-text) 35%,#a0527d);
  --sd-chart-5:color-mix(in srgb,var(--sd-primary-text) 35%,#387b5c);
  --sd-chart-6:color-mix(in srgb,var(--sd-primary-text) 35%,#7161a8);
  --shadow:0 1px 3px rgba(0,0,0,.06);
  --interaction-shadow:0 1px 3px rgba(0,0,0,.10);
}
:root[data-theme="dark"] {
  --sd-background:#181818;
  --sd-foreground:#f0f0f0;
  --sd-secondary-foreground:#d7d7d7;
  --sd-card:#242424;
  --sd-muted-background:#303030;
  --sd-muted-foreground:#b8b8b8;
  --sd-border:#494949;
  --sd-input-border:#858585;
  --sd-accent:color-mix(in srgb,var(--sd-primary) 12%,var(--sd-card));
  --sd-chart-3:color-mix(in srgb,var(--sd-primary-text) 35%,#91b8e7);
  --sd-chart-4:color-mix(in srgb,var(--sd-primary-text) 35%,#e3a5c5);
  --sd-chart-5:color-mix(in srgb,var(--sd-primary-text) 35%,#8dcca9);
  --sd-chart-6:color-mix(in srgb,var(--sd-primary-text) 35%,#bcb0e8);
}
/* Compatibility outputs: --muted remains TEXT; --border remains a CONTROL border. */
:root[data-palette] {
  --bg:var(--sd-background); --ink:var(--sd-foreground);
  --panel:var(--sd-card); --ink-2:var(--sd-secondary-foreground);
  --muted:var(--sd-muted-foreground); --line:var(--sd-border); --line-2:var(--sd-muted-background);
  --brand:var(--sd-primary); --on-brand:var(--sd-primary-foreground);
  --brand-ink:var(--sd-primary-text); --brand-soft:var(--sd-accent); --rose:var(--sd-decorative-accent);
  --side:var(--sd-sidebar); --side-2:var(--sd-sidebar-accent);
  --nav-text:var(--sd-sidebar-foreground); --nav-muted:var(--sd-sidebar-muted-foreground);
  --nav-heading:var(--sd-sidebar-heading-foreground); --nav-active:var(--sd-sidebar-primary);
  --control-border:var(--sd-input-border); --border:var(--sd-input-border);
  --focus-ring:var(--sd-ring); --focus-halo:color-mix(in srgb,var(--sd-ring) 18%,transparent);
}
/* Only colors change here. Existing geometry, typography and interaction states remain. */
:root[data-palette] .btn:not(.primary,.ok,.danger,.ghost,.wa,.destructive,:disabled) {
  background:var(--sd-secondary); color:var(--sd-secondary-foreground); border-color:var(--sd-secondary-border);
}
:root[data-palette] .btn:not(.primary,.ok,.danger,.ghost,.wa,.destructive,:disabled):hover { background:var(--sd-secondary-hover); }
:root[data-palette] .btn.primary:hover, :root[data-palette] .login-submit:hover { background:var(--sd-primary-hover); }
:root[data-palette] .btn.danger { color:var(--sd-destructive); border-color:var(--sd-destructive); }
:root[data-palette] .btn.destructive { background:var(--sd-destructive); color:var(--sd-destructive-foreground); border-color:var(--sd-destructive); }
:root[data-palette] .btn.destructive:hover { background:var(--sd-destructive); }
:root[data-palette][data-theme] :is(.modal,.profile-popover,.dropdown,.qualification-service-options) { background:var(--sd-popover); color:var(--sd-popover-foreground); }
:root[data-palette] .nav a:hover { background:var(--sd-sidebar-accent); color:var(--sd-sidebar-accent-foreground); }
:root[data-palette] .nav a.active { background:var(--sd-sidebar-primary); color:var(--sd-sidebar-primary-foreground); box-shadow:inset 3px 0 0 var(--sd-sidebar-indicator); }
:root[data-palette] :is(.brandmark,.side-foot) { border-color:var(--sd-sidebar-border); }
:root[data-palette] .side :where(button,a,[tabindex]):focus-visible { outline-color:var(--sd-sidebar-ring); }
/* Disabled styling stays authoritative after the secondary-role overrides. */
:root[data-palette] :is(button,.btn,.chip,.seg button,.tabs button,input,select,textarea):disabled {
  color:var(--muted); background:var(--surface-2); border-color:var(--control-border);
}

:root[data-palette] .dropdown div.on { background:var(--sd-accent); color:var(--sd-accent-foreground); }
:root[data-palette] .dropdown div:hover { background:var(--sd-accent-hover); }

/* Gold uses a darker text/focus gold than its filled primary action. */
:root[data-palette="gold"] { --sd-primary-text:#8A611E; }
:root[data-palette="gold"][data-theme="dark"] { --sd-primary-text:#D6B061; }
:root[data-palette="gold"]:not([data-theme="dark"]) :is(.btn.primary,.login-submit):not(:disabled):hover { color:#FFFFFF; }
:root[data-palette] .login-page { --login-accent:var(--sd-primary-text); }
:root[data-palette] :is(.login-card,.login-footer) { background:var(--panel); backdrop-filter:none; }
:root[data-palette] .login-card { box-shadow:var(--shadow); }
:root[data-palette] .login-card-divider { background:var(--line); }
:root[data-palette] .login-submit:hover { transform:none; }
:root[data-palette] .bars .b i { background:var(--sd-chart-1); }
:root[data-palette] :is(.profile-popover,.notification-popover,.modal,.toast,.date-calendar) { box-shadow:0 2px 8px rgba(0,0,0,.14); }
:root[data-palette] .toast:not(.ok,.bad) { background:var(--panel); color:var(--ink); border:1px solid var(--line); }
:root[data-palette] .cal .col {
  background-image:url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='1' height='60' viewBox='0 0 1 60' preserveAspectRatio='none'%3E%3Cpath d='M0 29.5H1M0 59.5H1' stroke='%23dedede'/%3E%3C/svg%3E");
  background-size:100% calc(var(--calendar-half-hour) * 2);
}
:root[data-palette][data-theme="dark"] .cal .col {
  background-image:url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='1' height='60' viewBox='0 0 1 60' preserveAspectRatio='none'%3E%3Cpath d='M0 29.5H1M0 59.5H1' stroke='%23494949'/%3E%3C/svg%3E");
}
