/* ============================================================================
   ChartControl brand v1.1 token layer (tokens 1.1.3) — Phase 0 of the v1.1 port (2026-11-05)
   (2026-11-08, ledger #114) 1.1.2 → 1.1.3: every colour value is unchanged (checked token by token against
   brand-system/tokens.css 1.1.3); 1.1.3 adds --cc-type-offset (0px) and --cc-large-text-step (2px), added below.
   Chart additions (product layer, not brand primitives): --chart-line-2…8 and --chart-ma-1…3 → line 1…3 (section 2).

   Source of truth (read-only, not copied by script):
     design/design-review/reference-viewer/directions/brand-system/tokens.source.json · DESIGN.md
   The prototype's own scope there is html[data-cc-brand="proposal"][data-cc-theme]. In the product the
   gate is html[data-cc-brand="v11"] and the theme stays the product's own data-theme (light|dark).

   ★★ Gate (see src/brand-v11.js — the only writer of data-cc-brand):
       on  — server-confirmed admin+ only (QTAuth.atLeast('admin'), Phase 1), and then on the admin preview
             routes (#/trade2, #/markets2 … = window.QTV2_ROUTES) or with the explicit opt-in
             (?cc-brand=v11 → localStorage qt.ccBrand; ?cc-brand=off clears it).
       off — every customer on every route (even with the opt-in key set), and everyone before auth is known. No rule in this file matches without the attribute,
             so production computed styles are unchanged.
   ★★ Rollback: APP_DESIGN=v1 → <html data-app-design="v1">. Every selector here is guarded by
       :where(html:not([data-app-design="v1"])) so the old look wins even if the attribute is present.
       The :where() keeps the guard at zero specificity.
   ★ Specificity is (0,2,0) on purpose, and this file loads right after tokens.css:
       · beats tokens.css [data-theme="light"] (0,1,0) and [data-brand="chartcontrol"][data-theme="light"] (0,2,0, earlier)
       · loses to the a11y overrides in widgets.css (:root[data-a11y-*], (0,2,0), later) — high contrast and
         colour-blind palettes keep working under the new brand.
       · up/down are applied only when the customer kept the default long/short palette
         (teal-magenta); an explicit green-red / cyan-orange / red-blue choice still wins.
   ★ Colours are written as oklch() equal to the brand hex (each value round-trips to the same 8-bit sRGB).
       The chart's withAlpha() (chart-kline.jsx / chart-canvas.jsx) can only add alpha to oklch strings —
       a hex value would silently render overlays opaque.
   ============================================================================ */

/* ---------- 1. Brand tokens (--cc-*) — theme-independent + dark (product default theme is dark) ---------- */
:where(html:not([data-app-design="v1"]))[data-cc-brand="v11"][data-theme] {
  --cc-brand-neon: oklch(67.25% 0.3048 328.33);            /* #F00FF0 — logo / hero line only */
  --cc-font: "Pretendard Variable", Pretendard, -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo", "Noto Sans KR", sans-serif;
  --cc-font-numbers: var(--cc-font);
  --cc-weight-body: 450;
  --cc-weight-control: 550;
  --cc-weight-heading: 650;
  --cc-weight-price: 650;
  --cc-text-caption: 12px;
  --cc-text-small: 13px;
  --cc-text-body: 14px;
  --cc-text-section: 18px;
  --cc-title-size: 24px;
  --cc-text-price: 40px;
  --cc-leading-caption: 18px;
  --cc-leading-small: 20px;
  --cc-leading-body: 22px;
  --cc-leading-section: 26px;
  --cc-title-line: 32px;
  --cc-leading-price: 48px;
  --cc-tracking-body: -0.01em;
  --cc-tracking-heading: -0.025em;
  --cc-tracking-number: -0.015em;
  --cc-space-1: 4px;
  --cc-space-2: 8px;
  --cc-space-3: 12px;
  --cc-space-4: 16px;
  --cc-space-5: 20px;
  --cc-space-6: 24px;
  --cc-space-7: 28px;
  --cc-space-8: 32px;
  --cc-space-10: 40px;
  --cc-space-12: 48px;
  --cc-control-height: 44px;
  --cc-compact-height: 36px;
  --cc-table-row-height: 64px;
  --cc-table-head-height: 44px;
  --cc-control-radius: 8px;
  --cc-panel-radius: 12px;
  --cc-dialog-radius: 16px;
  /* (2026-11-08, #115) selected-tab underline (DESIGN.md "탭": 2px line + ink label).
     (2026-11-12, #115-25) ONE underline colour everywhere — every v1.1 selected-tab rule (CCAI tabs included) reads this token;
     before, screens mixed --cc-accent, --cc-ai, --cc-line / --cc-control-line (grey), --cc-ink and local --hl/--rf/--ad accents. */
  --cc-tab-accent: var(--cc-accent);
  --cc-line-width: 1px;
  --cc-focus-width: 2px;
  --cc-focus-offset: 3px;
  --cc-icon-size: 18px;
  --cc-icon-stroke: 1.6;
  --cc-motion-fast: 120ms;
  --cc-motion-enter: 180ms;
  --cc-motion-ease: cubic-bezier(.2,.7,.2,1);
  --cc-type-offset: 0px;                           /* 1.1.3 */
  --cc-large-text-step: 2px;                       /* 1.1.3 */
  --cc-gutter: 28px;
  --cc-page-space: 24px;

  /* dark */
  --cc-page: oklch(18.39% 0.0124 277.68);          /* #111218 */
  --cc-surface: oklch(22.8% 0.0158 274.07);        /* #1A1C24 */
  --cc-soft: oklch(26.73% 0.0207 276.84);          /* #232530 */
  --cc-hover: oklch(30.34% 0.0221 274.02);         /* #2B2E3A */
  --cc-ink: oklch(96.61% 0.0054 297.73);           /* #F4F3F7 */
  --cc-muted: oklch(80.17% 0.0225 280.19);         /* #BBBDCD */
  --cc-faint: var(--cc-muted);                     /* deprecated alias (brand v1.1: two text levels) */
  --cc-line: oklch(33.93% 0.0232 274.9);           /* #343744 */
  --cc-control-line: oklch(59.13% 0.0299 271.59);  /* #777D90 */
  --cc-accent: oklch(67.25% 0.3048 328.33);        /* #F00FF0 */
  --cc-accent-hover: oklch(72.07% 0.297 328.13);   /* #FF3BFF */
  --cc-accent-soft: oklch(24.79% 0.0387 318.58);   /* #291B2D */
  --cc-on-accent: oklch(22.39% 0.0624 320.49);     /* #28102D */
  --cc-action: oklch(96.61% 0.0054 297.73);        /* #F4F3F7 */
  --cc-action-hover: oklch(89.91% 0.0109 280.46);  /* #DCDDE5 */
  --cc-on-action: oklch(25.85% 0.019 276.13);      /* #21232D */
  --cc-on-trade: oklch(22.39% 0.0624 320.49);      /* #28102D */
  --cc-ai: oklch(78.67% 0.1203 294.27);            /* #BEAAFF */
  --cc-ai-soft: oklch(28.44% 0.0491 293.23);       /* #2B2540 */
  --cc-on-ai: oklch(23.86% 0.0622 298.35);         /* #231738 */
  --cc-series-1: oklch(77.23% 0.084 342.05);       /* #DBA0C4 */
  --cc-up: oklch(77.02% 0.1073 7.34);              /* #EF97A8 */
  --cc-up-soft: oklch(29.21% 0.0249 343.5);        /* #35272F */
  --cc-down: oklch(78.12% 0.0879 257.18);          /* #94BAF0 */
  --cc-down-soft: oklch(31.06% 0.0365 258.32);     /* #253143 */
  --cc-success: oklch(79.06% 0.0769 166.59);       /* #8ACBB0 */
  --cc-success-soft: oklch(31.4% 0.0277 169.58);   /* #23362F */
  --cc-warning: oklch(82.65% 0.0755 81.84);        /* #DFC28E */
  --cc-warning-soft: oklch(32.39% 0.0205 82.63);   /* #393328 */
  --cc-danger: oklch(79.01% 0.0987 9.19);          /* #F2A0AD */
  --cc-danger-soft: oklch(29.86% 0.0313 352.18);   /* #3A272F */
  --cc-scrim: #08090FCC;
  --cc-shadow: 0 12px 36px #00000055, 0 2px 8px #00000033;
}

/* light — same names, light values */
:where(html:not([data-app-design="v1"]))[data-cc-brand="v11"][data-theme="light"] {
  --cc-page: oklch(97.02% 0.0041 271.37);          /* #F4F5F8 */
  --cc-surface: oklch(100% 0 0);                   /* #FFFFFF */
  --cc-soft: oklch(97.62% 0.0041 271.37);          /* #F6F7FA */
  --cc-hover: oklch(94.93% 0.0083 271.33);         /* #ECEEF4 */
  --cc-ink: oklch(25.85% 0.019 276.13);            /* #21232D */
  --cc-muted: oklch(50.99% 0.0255 277.06);         /* #626575 */
  --cc-faint: var(--cc-muted);
  --cc-line: oklch(91.36% 0.011 274.88);           /* #E0E2EA */
  --cc-control-line: oklch(61.88% 0.0245 274.51);  /* #818595 */
  --cc-accent: oklch(54.85% 0.2543 326.63);        /* #B600BC */
  --cc-accent-hover: oklch(47.79% 0.2216 326.65);  /* #97009C */
  --cc-accent-soft: oklch(95.85% 0.0054 274.96);   /* #F0F1F5 */
  --cc-on-accent: oklch(100% 0 0);                 /* #FFFFFF */
  --cc-action: oklch(25.85% 0.019 276.13);         /* #21232D */
  --cc-action-hover: oklch(35.86% 0.0228 274.97);  /* #393C49 */
  --cc-on-action: oklch(100% 0 0);                 /* #FFFFFF */
  --cc-on-trade: oklch(100% 0 0);                  /* #FFFFFF */
  --cc-ai: oklch(47.91% 0.1721 293.36);            /* #6541B3 */
  --cc-ai-soft: oklch(95.36% 0.0204 298.19);       /* #F1EDFC */
  --cc-on-ai: oklch(100% 0 0);                     /* #FFFFFF */
  --cc-series-1: oklch(50.67% 0.1197 348.05);      /* #954571 */
  --cc-up: oklch(54.57% 0.1592 13.72);             /* #BA3E54 */
  --cc-up-soft: oklch(96.43% 0.0121 4.75);         /* #FBF0F2 */
  --cc-down: oklch(53.11% 0.1113 251.05);          /* #356FAA */
  --cc-down-soft: oklch(96.51% 0.0097 252.81);     /* #EFF4FA */
  --cc-success: oklch(49.3% 0.0812 169.87);        /* #26705A */
  --cc-success-soft: oklch(96.9% 0.01 164.87);     /* #EFF7F3 */
  --cc-warning: oklch(52.48% 0.0937 76.06);        /* #896222 */
  --cc-warning-soft: oklch(97.43% 0.0183 86.15);   /* #FCF6E9 */
  --cc-danger: oklch(50.02% 0.1543 16.68);         /* #A93243 */
  --cc-danger-soft: oklch(96.51% 0.0132 5.8);      /* #FCF0F2 */
  --cc-scrim: #17182066;
  --cc-shadow: 0 12px 36px #21232D14, 0 2px 8px #21232D0A;
}

/* Responsive / input / motion conditions from the brand source (1100 / 700 / 359 + pointer:coarse). */
@media (max-width: 1100px) {
  :where(html:not([data-app-design="v1"]))[data-cc-brand="v11"][data-theme] { --cc-gutter: 20px; }
}
@media (max-width: 700px) {
  :where(html:not([data-app-design="v1"]))[data-cc-brand="v11"][data-theme] { --cc-gutter: 16px; --cc-text-price: 36px; --cc-leading-price: 44px; }
}
@media (max-width: 359px) {
  :where(html:not([data-app-design="v1"]))[data-cc-brand="v11"][data-theme] { --cc-text-price: 32px; --cc-leading-price: 40px; }
}
@media (pointer: coarse) {
  :where(html:not([data-app-design="v1"]))[data-cc-brand="v11"][data-theme] { --cc-compact-height: 44px; }
}
@media (prefers-reduced-motion: reduce) {
  :where(html:not([data-app-design="v1"]))[data-cc-brand="v11"][data-theme] { --cc-motion-fast: 0ms; --cc-motion-enter: 0ms; }
}

/* Density (display-preferences.css :6-22) — driven by the EXISTING preference html[data-density]
   (comfortable | compact | dense: Tweaks + Settings, saved to the account by app.jsx), not a new setting.
   Tokens only: record rows that use --cc-table-row-height / --cc-data-* follow it. --density-scale (tokens.css) is unchanged. */
:where(html:not([data-app-design="v1"]))[data-cc-brand="v11"][data-theme] {
  --cc-data-row-height: 64px;
  --cc-data-cell-block: 16px;
  --cc-data-row-gap: 12px;
}
:where(html:not([data-app-design="v1"]))[data-cc-brand="v11"][data-theme][data-density="compact"] {
  --cc-table-row-height: 56px;
  --cc-data-row-height: 56px;
  --cc-data-cell-block: 6px;
  --cc-data-row-gap: 8px;
}
:where(html:not([data-app-design="v1"]))[data-cc-brand="v11"][data-theme][data-density="dense"] {
  --cc-table-row-height: 48px;
  --cc-data-row-height: 48px;
  --cc-data-cell-block: 2px;
  --cc-data-row-gap: 4px;
}

/* ---------- 2. Product semantic tokens → brand v1.1 (resolved per theme through --cc-*) ---------- */
:where(html:not([data-app-design="v1"]))[data-cc-brand="v11"][data-theme] {
  /* surfaces */
  --color-bg-app:      var(--cc-page);
  --color-bg-surface:  var(--cc-surface);
  --color-bg-panel:    var(--cc-surface);      /* chart background — brand: chart plot is the plain work surface */
  --color-bg-elevated: var(--cc-surface);
  --color-bg-hover:    var(--cc-hover);
  --color-bg-active:   var(--cc-hover);        /* selected row / pressed — brand "selection surface" = neutral hover (#ECEEF4 / #2B2E3A, DESIGN.md :79-80). accent-soft is kept for compatibility only (--color-brand-subtle). */
  --color-bg-input:    var(--cc-surface);

  /* text — brand has two levels (ink / muted); tertiary collapses onto muted */
  --color-text-primary:   var(--cc-ink);
  --color-text-secondary: var(--cc-muted);
  --color-text-tertiary:  var(--cc-muted);
  --color-text-disabled:  color-mix(in oklab, var(--cc-muted) 55%, var(--cc-surface));
  --color-text-inverse:   var(--cc-on-action);

  /* borders */
  --color-border-subtle:  var(--cc-line);
  --color-border-default: var(--cc-line);
  --color-border-strong:  var(--cc-control-line);
  --color-border-focus:   var(--cc-accent);

  /* brand = selection / current location / focus (not CTA fill — see .btn--primary below) */
  --brand-primary-500:  var(--cc-accent);
  --brand-primary-400:  var(--cc-accent-hover);
  --brand-accent-500:   var(--cc-accent);
  --color-brand:        var(--cc-accent);
  --color-brand-hover:  var(--cc-accent-hover);
  --color-brand-subtle: var(--cc-accent-soft);

  /* neutral primary action (new names — no existing counterpart) */
  --color-action:       var(--cc-action);
  --color-action-hover: var(--cc-action-hover);
  --color-on-action:    var(--cc-on-action);

  /* CCAI */
  --ai-500:        var(--cc-ai);
  --ai-bg:         var(--cc-ai-soft);
  --color-ai:      var(--cc-ai);
  --color-ai-bg:   var(--cc-ai-soft);
  --color-on-ai:   var(--cc-on-ai);
  --shadow-glow-ai: 0 0 0 1px var(--cc-ai), 0 8px 24px color-mix(in oklab, var(--cc-ai) 25%, transparent);

  /* status — distinct from up/down */
  --success-500: var(--cc-success);
  --warning-500: var(--cc-warning);
  --danger-500:  var(--cc-danger);
  --color-success: var(--cc-success);
  --color-warning: var(--cc-warning);
  --color-danger:  var(--cc-danger);
  --color-success-bg: var(--cc-success-soft);
  --color-warning-bg: var(--cc-warning-soft);
  --color-danger-bg:  var(--cc-danger-soft);
  --color-signal-approved: var(--cc-success);
  --color-order-filled:    var(--cc-success);
  --color-order-pending:   var(--cc-warning);
  --order-rejected:        var(--cc-danger);   /* primitive pointed at trade-short; a rejection is an error, not "down" */
  --color-order-rejected:  var(--cc-danger);
  --color-order-canceled:  var(--cc-muted);

  /* chart chrome (candles/volume are in section 3) */
  --chart-grid:      var(--cc-line);
  --chart-axis-text: var(--cc-muted);
  --chart-crosshair: var(--cc-control-line);
  --chart-line-1:    var(--cc-series-1);       /* brand: default indicator / last-price accent is series-1, not the selection magenta */
  /* (2026-11-08, ledger #114) indicator lines 2…8 — the design's indicator colours (directions/charts/proposals/
     indicator-settings.js: ema / ma / macd / boll / mine-trend / vol / signal-close), dark values here, light below.
     The chart (chart-kline.jsx buildStyles) gives line N of every indicator --chart-line-N; MA20 / 60 / 120 = lines 1–3,
     so the legend swatches (--chart-ma-1…3) point at the same tokens. */
  --chart-line-2: oklch(74.07% 0.0708 257.36);  /* #8FADD8 */
  --chart-line-3: oklch(74.42% 0.0574 93.71);   /* #B8AC83 */
  --chart-line-4: oklch(75.48% 0.0533 182.25);  /* #8ABBB2 */
  --chart-line-5: oklch(72.45% 0.0637 293.08);  /* #A79FCB */
  --chart-line-6: oklch(75.25% 0.0659 49.33);   /* #D2A38A */
  --chart-line-7: oklch(67.93% 0.0406 239.91);  /* #829CAF */
  --chart-line-8: oklch(74.92% 0.0934 11.91);   /* #E2959E */
  --chart-ma-1: var(--chart-line-1);
  --chart-ma-2: var(--chart-line-2);
  --chart-ma-3: var(--chart-line-3);

  /* typography — Pretendard Variable for Korean, Latin and numbers (tabular-nums is already global in base.css) */
  --font-sans: var(--cc-font);
  --font-en:   var(--cc-font);
  --font-num:  var(--cc-font-numbers);
  --fw-regular:  var(--cc-weight-body);        /* 400 → 450 */
  --fw-medium:   var(--cc-weight-control);     /* 500 → 550 */
  --fw-semibold: var(--cc-weight-heading);     /* 600 → 650 */

  /* shape / motion */
  --r-md: var(--cc-control-radius);            /* 6 → 8  (controls) */
  --r-lg: var(--cc-control-radius);            /* 8      (unchanged value, now named) */
  --r-xl: var(--cc-panel-radius);              /* 12     (panels; unchanged value) */
  --shadow-3: var(--cc-shadow);                /* dialogs only */
  --dur-fast:   var(--cc-motion-fast);
  --dur-normal: var(--cc-motion-enter);
  --ease-out:   var(--cc-motion-ease);
}

/* (2026-11-08) indicator lines 2…8, light — same hues, darker step (≥ 4.8:1 on #FFFFFF) */
:where(html:not([data-app-design="v1"]))[data-cc-brand="v11"][data-theme="light"] {
  --chart-line-2: oklch(55.15% 0.0850 254.89);  /* #4F74A3 */
  --chart-line-3: oklch(54.79% 0.0759 93.24);   /* #80703A */
  --chart-line-4: oklch(53.33% 0.0702 169.40);  /* #3F7A66 */
  --chart-line-5: oklch(53.75% 0.0974 303.67);  /* #7A5F9C */
  --chart-line-6: oklch(54.18% 0.0973 50.00);   /* #9C5D38 */
  --chart-line-7: oklch(50.97% 0.0496 240.73);  /* #4C6A80 */
  --chart-line-8: oklch(53.01% 0.1285 10.45);   /* #A8475A */
}

/* ---------- 3. Up / down — only for the default long/short palette ----------
   An explicit customer choice (green-red · cyan-orange · red-blue) keeps its own colours; the a11y
   colour-blind palette (widgets.css, later, same specificity) also still wins. */
:where(html:not([data-app-design="v1"]):is([data-longshort="teal-magenta"], :not([data-longshort])))[data-cc-brand="v11"][data-theme] {
  --trade-long-500:  var(--cc-up);
  --trade-short-500: var(--cc-down);
  --color-trade-long:     var(--cc-up);
  --color-trade-short:    var(--cc-down);
  --color-trade-long-bg:  var(--cc-up-soft);
  --color-trade-short-bg: var(--cc-down-soft);
  --color-on-trade:       var(--cc-on-trade);
  --chart-candle-up: var(--cc-up);
  --chart-candle-dn: var(--cc-down);
  --trade-long-bg:   oklch(77.02% 0.1073 7.34 / 0.12);
  --trade-short-bg:  oklch(78.12% 0.0879 257.18 / 0.12);
  --chart-volume-up: oklch(77.02% 0.1073 7.34 / 0.35);
  --chart-volume-dn: oklch(78.12% 0.0879 257.18 / 0.35);
}
:where(html:not([data-app-design="v1"]):is([data-longshort="teal-magenta"], :not([data-longshort])))[data-cc-brand="v11"][data-theme="light"] {
  --trade-long-bg:   oklch(54.57% 0.1592 13.72 / 0.12);
  --trade-short-bg:  oklch(53.11% 0.1113 251.05 / 0.12);
  --chart-volume-up: oklch(54.57% 0.1592 13.72 / 0.35);
  --chart-volume-dn: oklch(53.11% 0.1113 251.05 / 0.35);
}

/* ---------- 4. One component contract that tokens alone cannot express ----------
   Brand v1.1: primary actions are neutral (ink / white), magenta is selection only. The generic
   .btn--primary fills with --color-brand, which now means "selection", so point it at the action pair.
   Scoped surfaces (.auth-shell / .landing-shell) keep their own primary rules — Phase 1. */
:where(html:not([data-app-design="v1"]))[data-cc-brand="v11"] .btn--primary {
  background: var(--color-action);
  border-color: var(--color-action);
  color: var(--color-on-action);
}
:where(html:not([data-app-design="v1"]))[data-cc-brand="v11"] .btn--primary:hover {
  background: var(--color-action-hover);
  border-color: var(--color-action-hover);
}
