/* ===== Crystal 1.7.0 · App shell and surface components =====
   Exact values from the Crystal reference mocks. Use these classes (or replicate them 1:1);
   do not restyle surfaces, radii or borders. All colors come from the theme variables above. */

/* Screen-reader-only text (visually hidden, still read out) */
.crystal-sr { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }

/* 1 · Page: the whole window is canvas, with a 14px frame around everything */
.crystal-app { display: flex; gap: 14px; padding: 14px; min-height: 100vh; box-sizing: border-box; background: var(--bg-canvas); color: var(--text-primary); font-size: 13px; line-height: 20px; font-family: var(--font-ui); font-feature-settings: "tnum" 1, "cv11" 1; }
.crystal-app *, .crystal-app *::before, .crystal-app *::after { box-sizing: border-box; }

/* 2 · Sidebar: NO background and NO border of its own. It sits directly on the canvas. */
.crystal-sidebar { width: 232px; flex-shrink: 0; display: flex; flex-direction: column; gap: 2px; padding: 8px 6px; background: transparent; border: 0; font-size: 12.5px; line-height: 16px; color: var(--text-secondary); position: sticky; top: 14px; height: calc(100vh - 28px); }
.crystal-brand { display: flex; justify-content: space-between; align-items: flex-start; padding: 6px 4px 6px 10px; }
.crystal-brand-logo { display: block; height: 24px; width: auto; }          /* CSC Sugar full logo: 24px tall */
.crystal-brand-logo.sugaright { height: 40px; }                                   /* Sugaright full logo: 40px tall (petal mark included) */
.crystal-brand-mark { display: none; }                                            /* mark-only file, shown when collapsed */
.crystal-brand-app { font-size: 12px; line-height: 16px; color: var(--text-tertiary); margin-top: 8px; white-space: nowrap; } /* app name: one line, sentence case, under the logo */
.crystal-toggle { width: 30px; height: 30px; border-radius: 9px; border: 1px solid var(--border-default); background: var(--bg-surface); display: grid; place-items: center; color: var(--text-secondary); cursor: pointer; }
.crystal-sidebar .crystal-search { margin: 10px 4px 4px; }
.crystal-nav-label { font-size: 10.5px; color: var(--text-tertiary); padding: 14px 10px 4px; }
.crystal-nav-item { display: flex; align-items: center; justify-content: space-between; gap: 10px; height: 36px; padding: 0 10px; border-radius: 9px; border: 1px solid transparent; color: var(--text-secondary); text-decoration: none; }
.crystal-nav-item > span { display: flex; align-items: center; gap: 10px; }
.crystal-nav-item svg { width: 16px; height: 16px; color: var(--text-tertiary); flex-shrink: 0; }
.crystal-nav-item:hover { background: color-mix(in srgb, var(--bg-surface) 60%, transparent); }
.crystal-nav-item[aria-current="page"] { background: var(--bg-surface); border-color: var(--border-default); color: var(--text-primary); font-weight: 600; }
.crystal-nav-item[aria-current="page"] svg { color: var(--text-primary); }
.crystal-count { font-size: 10.5px; color: var(--text-tertiary); }
.crystal-sidebar-footer { margin-top: auto; display: flex; flex-direction: column; gap: 6px; padding-top: 8px; }
.crystal-sidebar-footer .crystal-nav-item { color: var(--text-secondary); }
.crystal-user { background: var(--bg-surface); border: 1px solid var(--border-default); border-radius: 12px; padding: 9px 10px; display: flex; gap: 9px; align-items: center; }
.crystal-user-name { font-weight: 600; color: var(--text-primary); font-size: 12.5px; line-height: 16px; }
.crystal-user-role { font-size: 10.5px; color: var(--text-tertiary); line-height: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 110px; }
.crystal-user-actions { margin-left: auto; display: flex; gap: 2px; }
.crystal-icon-btn { width: 28px; height: 28px; border-radius: 9px; position: relative; border: 1px solid transparent; background: transparent; color: var(--text-secondary); display: grid; place-items: center; cursor: pointer; }
.crystal-icon-btn:hover { background: var(--bg-inset); border-color: var(--border-default); }
.crystal-icon-btn svg { width: 16px; height: 16px; }
.crystal-avatar { width: 28px; height: 28px; border-radius: 999px; background: var(--accent-default); color: var(--text-inverse); display: grid; place-items: center; font-size: 10.5px; font-weight: 600; flex-shrink: 0; }
/* collapsed rail: same items and icons, labels hidden */
.crystal-sidebar[data-collapsed="true"] { width: 60px; align-items: center; }
.crystal-sidebar[data-collapsed="true"] .crystal-nav-label, .crystal-sidebar[data-collapsed="true"] .crystal-nav-item .crystal-label, .crystal-sidebar[data-collapsed="true"] .crystal-brand-app, .crystal-sidebar[data-collapsed="true"] .crystal-brand-logo, .crystal-sidebar[data-collapsed="true"] .crystal-user > div, .crystal-sidebar[data-collapsed="true"] .crystal-user-actions { display: none; }
.crystal-sidebar[data-collapsed="true"] .crystal-brand { flex-direction: column; align-items: center; gap: 6px; padding: 6px 0; }
.crystal-sidebar[data-collapsed="true"] .crystal-brand-mark { display: grid; place-items: center; width: 40px; height: 40px; border-radius: 11px; background: var(--bg-surface); border: 1px solid var(--border-default); }
.crystal-sidebar[data-collapsed="true"] .crystal-brand-mark img { width: 26px; height: auto; }   /* Sugaright mark: 24px */
.crystal-sidebar[data-collapsed="true"] .crystal-user { padding: 6px; border: 0; background: transparent; }
.crystal-sidebar[data-collapsed="true"] .crystal-search { width: 40px; padding: 0; justify-content: center; } .crystal-sidebar[data-collapsed="true"] .crystal-search > :not(svg) { display: none; }
.crystal-sidebar[data-collapsed="true"] .crystal-nav-item { width: 40px; height: 40px; justify-content: center; padding: 0; position: relative; }
.crystal-sidebar[data-collapsed="true"] .crystal-count { position: absolute; top: 2px; right: 0; min-width: 16px; height: 16px; border-radius: 999px; padding: 0 4px; background: var(--bg-surface); border: 1px solid var(--border-default); color: var(--text-secondary); font-size: 9.5px; font-weight: 600; line-height: 14px; text-align: center; }

/* 3 · Main: ONE white (dark: surface) rounded content area holds the whole page */
.crystal-main { flex: 1; min-width: 0; background: var(--bg-surface); border: 1px solid var(--border-default); border-radius: 18px; padding: 22px 26px; }
.crystal-header { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; }
.crystal-crumb { font-size: 12px; color: var(--text-tertiary); margin-bottom: 4px; }
.crystal-title { font-size: 28px; font-weight: 600; letter-spacing: -0.02em; line-height: 34px; margin: 0; font-variation-settings: "opsz" 32; }
.crystal-summary { font-size: 13.5px; line-height: 20px; color: var(--text-secondary); margin: 5px 0 0; }
.crystal-summary b { color: var(--text-primary); }
.crystal-actions { display: flex; gap: 8px; align-items: center; flex-shrink: 0; }
.crystal-section { margin-top: 16px; }
.crystal-grid { display: grid; gap: 12px; }
.crystal-grid.cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.crystal-grid.cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.crystal-grid.cols-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.crystal-grid.main-side { grid-template-columns: minmax(0, 1.5fr) minmax(0, 1fr); }

/* 4 · Panels: every block of content inside main is a bordered panel (same fill as main) */
.crystal-panel { background: var(--bg-surface); border: 1px solid var(--border-default); border-radius: 14px; padding: 14px 16px; }
.crystal-panel-title { font-size: 13px; font-weight: 600; margin: 0; }
.crystal-panel-head { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 8px; }
.crystal-meta { font-size: 11.5px; color: var(--text-tertiary); }

/* 5 · Inset: a recessed well inside a panel or main (KPI tiles, notes, empty areas, tab bars) */
.crystal-inset { background: var(--bg-inset); border: 1px solid var(--border-default); border-radius: 12px; padding: 10px 12px; }

/* 6 · KPI tile: inset well holding a raised surface card */
.crystal-kpi { background: var(--bg-inset); border: 1px solid var(--border-default); border-radius: 12px; padding: 10px 12px; }
.crystal-kpi-head { display: flex; justify-content: space-between; font-size: 11.5px; color: var(--text-tertiary); }
.crystal-kpi-card { background: var(--bg-surface); border: 1px solid var(--border-default); border-radius: 10px; padding: 11px 12px; margin-top: 7px; }
.crystal-kpi-value { font-size: 26px; font-weight: 600; letter-spacing: -0.03em; line-height: 28px; font-variation-settings: "opsz" 32; }
.crystal-kpi-of { font-size: 11.5px; color: var(--text-tertiary); margin-left: 7px; }
.crystal-kpi-foot { display: flex; justify-content: space-between; margin-top: 8px; font-size: 11.5px; color: var(--text-tertiary); }
.crystal-kpi-foot b { color: var(--text-primary); }
.crystal-ticks { display: flex; gap: 2px; height: 18px; margin-top: 9px; }
.crystal-ticks span { flex: 1; border-radius: 1.5px; /* radius.tick */ background: var(--border-default); }
.crystal-ticks span.on { background: var(--data-c1); }
/* KPI tile in a bad state: the number takes the state's color AND the verdict word sits in the header as a
   tinted StatusPill (never color alone). Normal tiles stay text.primary. One state per tile. */
.crystal-kpi-head .crystal-pill { height: 20px; font-size: 10.5px; }
.crystal-kpi-head { align-items: center; gap: 8px; }
.crystal-kpi.critical .crystal-kpi-value { color: var(--feedback-critical); }
.crystal-kpi.warning  .crystal-kpi-value { color: color-mix(in srgb, var(--feedback-warning) 80%, var(--text-primary)); }   /* 4.9:1 light */
.crystal-kpi.critical .crystal-ticks span.on { background: var(--feedback-critical); }
.crystal-kpi.warning  .crystal-ticks span.on { background: var(--feedback-warning); }

/* 7 · Table: header row on inset with rounded ends, rows divided by a 1px line */
.crystal-table { width: 100%; border-collapse: separate; border-spacing: 0; font-size: 12px; }
.crystal-table th { text-align: left; font-weight: 500; font-size: 11px; color: var(--text-tertiary); background: var(--bg-inset); padding: 7px 10px; }
.crystal-table th:first-child { border-radius: 7px 0 0 7px; } .crystal-table th:last-child { border-radius: 0 7px 7px 0; }
.crystal-table td { padding: 9px 10px; border-bottom: 1px solid var(--border-default); vertical-align: middle; }
.crystal-table tr:last-child td { border-bottom: 0; }
.crystal-table .num { text-align: right; }
.crystal-id { font-family: var(--font-id); font-size: 0.92em; letter-spacing: -0.01em; }

/* 8 · Controls */
.crystal-btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; height: 34px; padding: 0 15px; border-radius: 9px; font: 600 12.5px/1 var(--font-ui); border: 1px solid transparent; cursor: pointer; white-space: nowrap; flex-shrink: 0; text-decoration: none; position: relative;
  transition: background-color 120ms ease-out, border-color 120ms ease-out, color 120ms ease-out, transform 100ms ease-out; }
.crystal-btn.primary { background: var(--action-primary-bg); color: var(--action-primary-text); }
.crystal-btn.secondary { background: var(--bg-surface); border-color: var(--border-input); color: var(--text-primary); }
.crystal-btn.ghost { background: transparent; color: var(--text-secondary); }
.crystal-btn.danger { background: color-mix(in srgb, var(--feedback-critical) 10%, var(--bg-surface)); border-color: color-mix(in srgb, var(--feedback-critical) 30%, var(--bg-surface)); color: var(--feedback-critical); }
.crystal-btn.sm { height: 28px; font-size: 11.5px; padding: 0 11px; }

.crystal-field { display: flex; align-items: center; gap: 10px; height: 34px; padding: 0 10px; border-radius: 9px; background: var(--bg-surface); border: 1px solid var(--border-input); position: relative; color: var(--text-primary); font-size: 12.5px; }
.crystal-field input, .crystal-field select { all: unset; flex: 1; font: inherit; color: inherit; }
.crystal-search { color: var(--text-tertiary); justify-content: space-between; }
.crystal-kbd { font-family: var(--font-id); font-size: 10.5px; line-height: 14px; border: 1px solid var(--border-default); border-radius: 6px; padding: 0 4px; }
.crystal-seg { display: inline-flex; background: var(--bg-inset); border: 1px solid var(--border-default); border-radius: 9px; padding: 2px; gap: 2px; }
.crystal-seg button { all: unset; padding: 4px 10px; border-radius: 7px; font-size: 11px; color: var(--text-tertiary); font-weight: 500; cursor: pointer; border: 1px solid transparent; }
.crystal-seg button[aria-pressed="true"] { background: var(--bg-surface); color: var(--text-primary); border-color: var(--border-default); font-weight: 600; }

/* 8b · Button states (hover acknowledges, pressed confirms, focus orients) */
.crystal-btn.primary:hover { background: color-mix(in srgb, var(--action-primary-bg) 86%, var(--bg-canvas)); }
.crystal-btn.primary:active { background: var(--action-primary-bg); transform: scale(.98); }   /* back to full ink + press: firmer than hover */
.crystal-btn.secondary:hover { border-color: var(--text-tertiary); background: color-mix(in srgb, var(--text-primary) 4%, var(--bg-surface)); }
.crystal-btn.secondary:active { background: color-mix(in srgb, var(--text-primary) 8%, var(--bg-surface)); transform: scale(.98); }
.crystal-btn.ghost:hover { background: var(--bg-inset); color: var(--text-primary); }
.crystal-btn.ghost:active { background: var(--border-default); transform: scale(.98); }
.crystal-btn.danger:hover { background: color-mix(in srgb, var(--feedback-critical) 16%, var(--bg-surface)); }
.crystal-btn.danger:active { background: color-mix(in srgb, var(--feedback-critical) 22%, var(--bg-surface)); transform: scale(.98); }
.crystal-btn:disabled, .crystal-btn[aria-disabled="true"] { background: var(--bg-inset); border-color: var(--border-default); color: var(--text-tertiary); cursor: not-allowed; transform: none; }
.crystal-btn[aria-busy="true"] { pointer-events: none; }
.crystal-btn[aria-busy="true"]::before { content: ""; width: 14px; height: 14px; border-radius: 999px; border: 2px solid currentColor; border-right-color: transparent; animation: crystal-spin 800ms linear infinite; }
.crystal-btn[data-state="success"] { background: color-mix(in srgb, var(--feedback-success) 12%, var(--bg-surface)); border-color: color-mix(in srgb, var(--feedback-success) 35%, var(--bg-surface)); color: color-mix(in srgb, var(--feedback-success) 70%, var(--text-primary)); }
@keyframes crystal-spin { to { transform: rotate(360deg); } }
/* one focus ring for every interactive element: 2px solid, 2px offset */
.crystal-btn:focus-visible, .crystal-nav-item:focus-visible, .crystal-chip:focus-visible, .crystal-seg button:focus-visible, .crystal-rating button:focus-visible,
.crystal-icon-btn:focus-visible, .crystal-toggle:focus-visible, .crystal-sheet-item:focus-visible, .crystal-list-row:focus-visible, .crystal-tabs button:focus-visible,
.crystal-link:focus-visible, .crystal-toast button:focus-visible, .crystal-user:focus-visible, .crystal-mobile-top button:focus-visible { outline: 2px solid var(--focus-ring); outline-offset: 2px; }
.crystal-field:focus-within { outline: 2px solid var(--focus-ring); outline-offset: 2px; border-color: var(--focus-ring); }
.crystal-field.error { border-color: var(--feedback-critical); }
@media (prefers-reduced-motion: reduce) { .crystal-btn { transition: none; } .crystal-btn:active { transform: none; } .crystal-btn[aria-busy="true"]::before { animation: none; border-right-color: currentColor; opacity: .6; } }

/* 8c · Select: native arrow replaced by a chevron at the same 10px inset as the text */
.crystal-field.select select { appearance: none; -webkit-appearance: none; padding-right: 26px; cursor: pointer; }
.crystal-field.select::after { content: ""; position: absolute; right: 10px; top: 50%; width: 16px; height: 16px; margin-top: -8px; pointer-events: none; background: var(--text-tertiary);
  -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E") center / 16px no-repeat;
          mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E") center / 16px no-repeat; }

/* 8d · Field label, hint and error text */
.crystal-field-label { display: block; font-size: 12.5px; line-height: 16px; font-weight: 600; color: var(--text-primary); margin-bottom: 6px; }
.crystal-hint { font-size: 11.5px; line-height: 16px; color: var(--text-tertiary); margin-top: 6px; }
.crystal-error-text { font-size: 11.5px; line-height: 16px; color: var(--feedback-critical); margin-top: 6px; }

/* 8e · Links: underline only inside running text */
.crystal-link { color: var(--accent-default); text-decoration: none; font-weight: 500; }
.crystal-link:hover { color: var(--accent-hover); }
.crystal-prose a, .crystal-summary a, .crystal-hint a, .crystal-table td a:not(.crystal-btn) { color: var(--accent-default); text-decoration: underline; text-underline-offset: 2px; }
.crystal-prose a:hover, .crystal-summary a:hover, .crystal-hint a:hover { color: var(--accent-hover); }

/* 8f · Determinate progress (anything over 1 second) */
.crystal-progress { height: 6px; border-radius: 999px; background: var(--bg-inset); border: 1px solid var(--border-default); overflow: hidden; }
.crystal-progress > span { display: block; height: 100%; width: var(--value, 0%); background: var(--accent-default); border-radius: 999px; transition: width 200ms ease-out; }

/* 9 · Status pill */
.crystal-pill { display: inline-flex; align-items: center; gap: 5px; height: 22px; padding: 0 9px 0 8px; border-radius: 999px; font-size: 11px; font-weight: 550; background: var(--bg-surface); border: 1px solid var(--border-default); color: var(--text-primary); white-space: nowrap; }
.crystal-pill::before { content: ""; width: 6px; height: 6px; border-radius: 999px; background: var(--tone, var(--status-not-started)); }
.crystal-pill.warning { background: color-mix(in srgb, var(--feedback-warning) 12%, var(--bg-surface)); border-color: color-mix(in srgb, var(--feedback-warning) 35%, var(--bg-surface)); color: color-mix(in srgb, var(--feedback-warning) 80%, var(--text-primary)); --tone: var(--feedback-warning); }
.crystal-pill.critical, .crystal-pill.blocked { background: color-mix(in srgb, var(--feedback-critical) 11%, var(--bg-surface)); border-color: color-mix(in srgb, var(--feedback-critical) 32%, var(--bg-surface)); color: var(--feedback-critical); --tone: var(--feedback-critical); }

/* 10 · Loading placeholder: border-colored blocks with a gentle opacity pulse (no gradient, no shimmer) */
.crystal-skeleton { display: block; background: var(--border-default); border-radius: 6px; min-height: 12px; animation: crystal-pulse 1.2s ease-in-out infinite alternate; }
.crystal-skeleton.text { height: 12px; margin: 6px 0; } .crystal-skeleton.title { height: 22px; width: 40%; } .crystal-skeleton.value { height: 28px; width: 55%; }
@keyframes crystal-pulse { from { opacity: .55; } to { opacity: 1; } }
@media (prefers-reduced-motion: reduce) { .crystal-skeleton { animation: none; opacity: .8; } }

/* 11 · Rating picker: a radiogroup of equal tiles, number above word */
.crystal-rating { display: grid; grid-template-columns: repeat(var(--count, 6), minmax(0, 1fr)); gap: 8px; }
.crystal-rating button { all: unset; box-sizing: border-box; height: 56px; border-radius: 9px; border: 1px solid var(--border-input); background: var(--bg-surface); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; cursor: pointer; color: var(--text-primary); }
.crystal-rating button b { font-size: 16px; font-weight: 600; line-height: 1; }
.crystal-rating button span { font-size: 10.5px; color: var(--text-tertiary); line-height: 1.2; text-align: center; }
.crystal-rating button:hover { border-color: var(--text-tertiary); }
.crystal-rating button[aria-checked="true"] { background: var(--accent-subtle); border-color: var(--accent-default); color: var(--accent-default); }
.crystal-rating button[aria-checked="true"] span { color: var(--accent-default); }

.crystal-rating button[disabled] { color: var(--text-disabled); background: var(--bg-inset); cursor: default; }

/* 12 · Dot plot with reference lines (distribution, e.g. calibration) */
.crystal-dotplot { position: relative; height: 120px; border-bottom: 1px solid var(--border-default); }
.crystal-dotplot .dot { position: absolute; width: 10px; height: 10px; border-radius: 999px; background: var(--data-c1); opacity: .75; transform: translate(-50%, 50%); }
.crystal-dotplot .ref { position: absolute; top: 0; bottom: 0; border-left: 1.5px dashed var(--text-tertiary); }
.crystal-dotplot .ref.target { border-left: 2px solid var(--text-primary); }
.crystal-dotplot .ref.left > span { left: auto; right: 6px; }   /* put a label left of its line when two labels are close */
.crystal-dotplot .ref > span { position: absolute; top: -18px; left: 4px; font-size: 10.5px; color: var(--text-secondary); white-space: nowrap; }

/* 13 · List: rows divided inside one panel on desktop; one card per row on phones */
.crystal-list { background: var(--bg-surface); border: 1px solid var(--border-default); border-radius: 14px; padding: 4px 16px; }
.crystal-list-row { display: flex; align-items: center; gap: 12px; min-height: 52px; padding: 10px 0; border-bottom: 1px solid var(--border-default); color: inherit; text-decoration: none; }
.crystal-list-row:last-child { border-bottom: 0; }
.crystal-list-row .crystal-row-main { flex: 1; min-width: 0; }
.crystal-list-row .crystal-row-title { font-size: 12.5px; font-weight: 600; }

/* 14 · Chip (filter chip with count) */
.crystal-chip { display: inline-flex; align-items: center; gap: 7px; height: 30px; padding: 0 11px; border-radius: 9px; border: 1px solid var(--border-input); background: var(--bg-surface); font-size: 12px; color: var(--text-secondary); white-space: nowrap; cursor: pointer; position: relative; }
.crystal-chip b { color: var(--text-primary); font-weight: 650; }
.crystal-chip[aria-pressed="true"] { border-color: var(--text-primary); color: var(--text-primary); box-shadow: inset 0 0 0 1px var(--text-primary); }

/* 15 · Badge (count on an icon: rail items, phone tabs, notification bell) */
.crystal-badge { position: absolute; top: 2px; right: 0; min-width: 16px; height: 16px; border-radius: 999px; padding: 0 4px; background: var(--bg-surface); border: 1px solid var(--border-default); color: var(--text-secondary); font-size: 9.5px; font-weight: 600; line-height: 14px; text-align: center; }
.crystal-badge.attention { background: var(--feedback-critical); border-color: var(--feedback-critical); color: var(--text-inverse); }

/* 16 · Overlays: drawer, dialog, sheet. bg.overlay, radius 14, shadow.float, scrim behind */
.crystal-scrim { position: fixed; inset: 0; z-index: 40; background: var(--overlay-scrim); }
.crystal-scrim[hidden], .crystal-drawer[hidden], .crystal-dialog[hidden], .crystal-sheet[hidden] { display: none; }
.crystal-drawer { position: fixed; z-index: 41; top: 14px; right: 14px; bottom: 14px; width: min(400px, calc(100vw - 28px)); background: var(--bg-overlay); border: 1px solid var(--border-default); border-radius: 14px; box-shadow: var(--shadow-float); display: flex; flex-direction: column; }
.crystal-drawer-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 16px 18px; border-bottom: 1px solid var(--border-default); }
.crystal-drawer-body { flex: 1; overflow: auto; padding: 16px 18px; }
.crystal-drawer-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 14px 18px; border-top: 1px solid var(--border-default); }
.crystal-dialog { position: fixed; z-index: 41; left: 50%; top: 50%; transform: translate(-50%, -50%); width: min(440px, calc(100vw - 28px)); background: var(--bg-overlay); border: 1px solid var(--border-default); border-radius: 14px; box-shadow: var(--shadow-float); padding: 18px 20px; }
.crystal-dialog-title { font-size: 15px; font-weight: 600; margin: 0 0 6px; }
.crystal-dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }
/* More sheet (phones): opened by the More tab */
.crystal-sheet { position: fixed; z-index: 41; left: 0; right: 0; bottom: 0; max-height: 85vh; overflow: auto; background: var(--bg-overlay); border: 1px solid var(--border-default); border-bottom: 0; border-radius: 14px 14px 0 0; box-shadow: var(--shadow-float); padding: 8px 12px calc(env(safe-area-inset-bottom, 0px) + 12px); }
.crystal-sheet-handle { width: 36px; height: 4px; border-radius: 999px; background: var(--border-strong); margin: 2px auto 6px; }
.crystal-sheet-head { display: flex; justify-content: space-between; align-items: center; padding: 4px 4px 8px; }
.crystal-sheet-title { font-size: 15px; font-weight: 600; }
.crystal-sheet-label { font-size: 11px; color: var(--text-tertiary); padding: 12px 8px 4px; }
.crystal-sheet-item { all: unset; box-sizing: border-box; display: flex; align-items: center; gap: 12px; width: 100%; min-height: 48px; padding: 0 8px; border-radius: 12px; font-size: 15px; color: var(--text-primary); cursor: pointer; }
.crystal-sheet-item svg { width: 20px; height: 20px; color: var(--text-tertiary); flex-shrink: 0; }
.crystal-sheet-item .crystal-count { margin-left: auto; font-size: 12px; }
.crystal-sheet-item:active, .crystal-sheet-item:hover { background: var(--bg-inset); }
.crystal-sheet-divider { height: 1px; background: var(--border-default); margin: 8px 8px; }
.crystal-sheet-user { display: flex; align-items: center; gap: 12px; padding: 8px; }

/* 17 · Sticky action bar (long forms and drawers on phones) */
.crystal-actionbar { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }

/* 17b · Tabs (views of one record) */
.crystal-tabs { display: flex; gap: 18px; border-bottom: 1px solid var(--border-default); }
.crystal-tabs button { all: unset; cursor: pointer; padding: 8px 0; font-size: 12.5px; line-height: 16px; color: var(--text-tertiary); border-bottom: 2px solid transparent; margin-bottom: -1px; white-space: nowrap; }
.crystal-tabs button[aria-selected="true"] { color: var(--text-primary); font-weight: 600; border-bottom-color: var(--text-primary); }

/* 17c · Toast: bottom center on desktop; above the tab bar on phones */
.crystal-toast { position: fixed; z-index: 50; left: 50%; bottom: 24px; transform: translateX(-50%); display: flex; align-items: center; gap: 14px; min-height: 44px; padding: 10px 16px; border-radius: 14px; background: var(--action-primary-bg); color: var(--action-primary-text); box-shadow: var(--shadow-float); font-size: 13px; }
.crystal-toast button { all: unset; cursor: pointer; font-weight: 600; padding: 4px 8px; margin: -4px -8px; border-radius: 7px; }
.crystal-toast button:hover { background: color-mix(in srgb, var(--action-primary-text) 14%, transparent); }
.crystal-toast[hidden] { display: none; }

/* 17d · Row selection (bulk actions) */
.crystal-table .crystal-select { width: 36px; }

/* 18 · Phone-only elements (hidden on desktop) */
.crystal-mobile-top { display: none; }
.crystal-sidebar .crystal-more { display: none; }
.crystal-mobile-actions { display: flex; gap: 2px; }

/* 19 · Tablets and small laptops (769–1280px): sidebar collapses to the rail */
@media (max-width: 1280px) and (min-width: 769px) { .crystal-sidebar:not([data-collapsed="false"]) { width: 60px; } }

/* 20 · Phones (768px and below): no main surface. Cards sit on the canvas; sidebar becomes a bottom tab bar. */
@media (max-width: 768px) {
  .crystal-app { display: block; padding: 0; min-height: 100vh; }
  .crystal-mobile-top { display: flex; justify-content: space-between; align-items: center; padding: calc(env(safe-area-inset-top, 0px) + 10px) 20px 6px; }
  .crystal-mobile-top img { height: 20px; width: auto; display: block; }   /* Sugaright: 34px */
  .crystal-mobile-top .crystal-brand-app { font-size: 13px; line-height: 18px; color: var(--text-tertiary); margin-top: 8px; }   /* phone meta */
  .crystal-mobile-top button { all: unset; position: relative; width: 44px; height: 44px; display: grid; place-items: center; border-radius: 12px; color: var(--text-secondary); cursor: pointer; }
  .crystal-mobile-top svg { width: 20px; height: 20px; }
  .crystal-main { background: transparent; border: 0; border-radius: 0; padding: 4px 16px calc(env(safe-area-inset-bottom, 0px) + var(--crystal-tabbar-h) + 24px); font-size: 15px; line-height: 22px; }
  .crystal-meta { font-size: 13px; line-height: 18px; }
  .crystal-header { flex-direction: column; gap: 12px; }
  .crystal-crumb { display: none; }
  .crystal-title { font-size: 30px; line-height: 36px; margin-top: 10px; }
  .crystal-summary { font-size: 15px; line-height: 22px; margin-top: 4px; }
  .crystal-actions { flex-wrap: wrap; width: 100%; }
  .crystal-actions .crystal-btn.primary { order: -1; flex: 1 1 100%; }   /* the one primary goes first, full width */
  .crystal-actionbar { position: sticky; bottom: calc(env(safe-area-inset-bottom, 0px) + var(--crystal-tabbar-h) + 10px); margin: 16px -16px 0; padding: 10px 16px; background: var(--bg-canvas); border-top: 1px solid var(--border-default); z-index: 10; }
  .crystal-actionbar .crystal-btn.primary { flex: 1; }
  .crystal-section { margin-top: 14px; }
  .crystal-grid, .crystal-grid.cols-2, .crystal-grid.cols-3, .crystal-grid.cols-4, .crystal-grid.main-side { grid-template-columns: 1fr; gap: 10px; }
  .crystal-grid.kpi-strip { grid-template-columns: repeat(2, minmax(0, 1fr)); }        /* KPI strips stay 2 across */
  .crystal-grid.kpi-strip .crystal-kpi { padding: 8px 10px; }
  .crystal-grid.kpi-strip .crystal-kpi-head > span:last-child { display: none; }
  .crystal-grid.kpi-strip .crystal-kpi-value { font-size: 22px; line-height: 26px; }
  .crystal-grid.kpi-strip .crystal-kpi-card { padding: 9px 10px; }
  .crystal-grid.kpi-strip .crystal-kpi-foot { font-size: 11px; flex-wrap: wrap; gap: 2px 8px; }
  /* lists: one card per row */
  .crystal-list { background: transparent; border: 0; border-radius: 0; padding: 0; display: grid; gap: 8px; }
  .crystal-list-row { background: var(--bg-surface); border: 1px solid var(--border-default); border-radius: 14px; padding: 12px 14px; min-height: 64px; }
  .crystal-list-row:last-child { border-bottom: 1px solid var(--border-default); }
  .crystal-list-row .crystal-row-title { font-size: 15px; }
  .crystal-panel { padding: 14px 16px; }
  /* every control is a 44px tap target */
  .crystal-field { height: 44px; border-radius: 12px; }
  .crystal-field.select::after { right: 12px; }
  .crystal-btn, .crystal-btn.sm { height: 44px; border-radius: 12px; font-size: 15px; padding: 0 16px; }
  .crystal-icon-btn { width: 44px; height: 44px; border-radius: 12px; }
  .crystal-seg { border-radius: 12px; padding: 2px; max-width: 100%; overflow-x: auto; }   /* safety net only: apps must swap 4+ options for a select (5c) */ .crystal-seg button { min-height: 38px; padding: 0 14px; display: inline-flex; align-items: center; border-radius: 7px; font-size: 13px; white-space: nowrap; }
  .crystal-tabs { overflow-x: auto; scroll-snap-type: x proximity; scrollbar-width: none; } .crystal-tabs button { min-height: 44px; font-size: 15px; scroll-snap-align: start; }
  .crystal-toast { left: 16px; right: 16px; transform: none; bottom: calc(env(safe-area-inset-bottom, 0px) + var(--crystal-tabbar-h) + 12px); justify-content: space-between; font-size: 15px; }
  .crystal-chip { height: 36px; border-radius: 12px; font-size: 13px; }   /* phone control radius */
  .crystal-chip::after { content: ""; position: absolute; inset: -4px 0; }            /* 44px hit area */
  /* row actions: hidden when the row opens a detail view; otherwise keep ONE action full width (+ overflow) */
  .crystal-table tr[data-href] .crystal-row-actions { display: none !important; }
  .crystal-table:not(.scroll) td.crystal-row-actions { display: flex; gap: 8px; padding-top: 8px; }
  .crystal-table:not(.scroll) td.crystal-row-actions::before { content: none; }
  .crystal-table td.crystal-row-actions .crystal-btn:not(.keep):not(.crystal-row-more) { display: none; }
  .crystal-table td.crystal-row-actions .crystal-btn.keep { flex: 1; }
  .crystal-table td.crystal-row-actions .crystal-row-more { width: 44px; padding: 0; flex: 0 0 44px; }
  /* bulk selection: checkboxes appear only in selection mode */
  .crystal-table:not([data-selecting]) .crystal-select { display: none !important; }
  .crystal-table[data-selecting]:not(.scroll) td.crystal-select { display: flex; justify-content: flex-start; min-height: 44px; align-items: center; }
  .crystal-table[data-selecting]:not(.scroll) td.crystal-select::before { content: none; }
  /* tables: stacked rows (label: value) inside their card */
  .crystal-table:not(.scroll) thead, .crystal-table:not(.scroll) tr:first-child:has(th) { display: none; }
  .crystal-table:not(.scroll), .crystal-table:not(.scroll) tbody, .crystal-table:not(.scroll) tr, .crystal-table:not(.scroll) td { display: block; width: 100%; }
  .crystal-table:not(.scroll) tr { padding: 10px 0; border-bottom: 1px solid var(--border-default); }
  .crystal-table:not(.scroll) tr:last-child { border-bottom: 0; }
  .crystal-table:not(.scroll) td { border: 0; padding: 3px 0; display: flex; justify-content: space-between; gap: 12px; text-align: right; font-size: 15px; line-height: 22px; }
  .crystal-table:not(.scroll) td::before { content: attr(data-label); color: var(--text-tertiary); text-align: left; font-size: 13px; }
  .crystal-table:not(.scroll) td:first-child { display: block; text-align: left; font-size: 15px; padding-bottom: 6px; }
  .crystal-table:not(.scroll) td:first-child::before { content: none; }
  /* opt-out for dense boards (OperationsGrid): horizontal scroll with the first column pinned */
  .crystal-table.scroll { display: block; overflow-x: auto; white-space: nowrap; }
  .crystal-table.scroll td:first-child, .crystal-table.scroll th:first-child { position: sticky; left: 0; background: var(--bg-surface); z-index: 1; }
  /* overlays on phones */
  .crystal-drawer { inset: 0; width: auto; border-radius: 0; border: 0; padding-top: env(safe-area-inset-top, 0px); }
  .crystal-drawer-foot { padding-bottom: calc(env(safe-area-inset-bottom, 0px) + 14px); }
  .crystal-drawer-foot .crystal-btn.primary { flex: 1; }
  .crystal-dialog { top: auto; bottom: 0; left: 0; right: 0; transform: none; width: auto; border-radius: 14px 14px 0 0; border-bottom: 0; padding: 18px 16px calc(env(safe-area-inset-bottom, 0px) + 16px); }
  .crystal-dialog-actions { flex-direction: column-reverse; }
  .crystal-dialog-actions .crystal-btn { width: 100%; }
  /* bottom tab bar: max 5 items marked data-tab, the rest live behind "More" */
  .crystal-sidebar { position: fixed; left: 0; right: 0; bottom: 0; top: auto; width: auto; height: auto; min-height: calc(var(--crystal-tabbar-h) + env(safe-area-inset-bottom, 0px)); box-sizing: border-box; z-index: 20;
    flex-direction: row; align-items: stretch; gap: 4px; padding: 8px 10px calc(env(safe-area-inset-bottom, 0px) + 10px);
    background: var(--bg-canvas); border-top: 1px solid var(--border-default); }
  .crystal-sidebar .crystal-brand, .crystal-sidebar .crystal-search, .crystal-sidebar .crystal-nav-label, .crystal-sidebar .crystal-sidebar-footer,
  .crystal-sidebar .crystal-nav-item:not([data-tab]) { display: none; }
  .crystal-sidebar .crystal-more { display: flex; }
  .crystal-sidebar .crystal-nav-item[data-tab], .crystal-sidebar .crystal-more { flex: 1; height: auto; min-height: 52px; flex-direction: column; justify-content: center; gap: 3px; padding: 6px 0; border-radius: 12px; font-size: 11px; color: var(--text-tertiary); }
  .crystal-sidebar .crystal-nav-item > span { flex-direction: column; gap: 3px; }
  .crystal-sidebar .crystal-nav-item svg { width: 20px; height: 20px; }
  .crystal-sidebar .crystal-nav-item[aria-current="page"] { background: var(--bg-surface); border-color: var(--border-default); color: var(--text-primary); }
  .crystal-sidebar .crystal-nav-item { position: relative; }
  .crystal-sidebar .crystal-nav-item[data-tab] .crystal-count { position: absolute; top: 4px; left: calc(50% + 6px); min-width: 16px; height: 16px; border-radius: 999px; padding: 0 4px; background: var(--bg-surface); border: 1px solid var(--border-default); color: var(--text-secondary); font-size: 9.5px; font-weight: 600; line-height: 14px; text-align: center; }
  .crystal-sidebar[data-collapsed="true"] .crystal-nav-item .crystal-label { display: inline; }
}
