/**
 * ProtonIQ Component Library
 * --------------------------
 * Reusable primitives built on css/tokens.css. Every page should compose
 * these instead of re-declaring button/input/card/table styling inline.
 *
 *   Buttons ....... .btn  + .btn-primary | .btn-secondary | .btn-ghost | .btn-danger
 *                   sizes: .btn-xs | .btn-sm | (default) | .btn-lg     icon-only: .btn-icon
 *   Forms ......... .input  .select  .textarea  .field  .field-label  .field-hint
 *   Surfaces ...... .card  .card-header  .card-title  .card-body  .card-footer
 *   Data .......... .data-table  .badge(-*)  .stat  .kv-list
 *   Navigation .... .segmented (+ .tab-group/.tab-btn aliases)  .tabs/.tab
 *   Page .......... .page-header  .page-title  .page-subtitle  .page-actions
 *                   .page-body  .section-title  .toolbar
 *   Feedback ...... .empty-state  .skeleton  .kbd  .avatar  .chip  .menu
 *
 * Legacy class names (.btn-sm-primary, .dashboard-card, .tab-group, …) are
 * aliased below so older markup inherits the new look without edits.
 */

/* ======================================================================
   Base
   ====================================================================== */

html {
    -webkit-text-size-adjust: 100%;
}

body {
    font-family: var(--font-sans);
    font-feature-settings: var(--font-features);
    color: var(--text-body);
    background: var(--bg-canvas);
    letter-spacing: var(--tracking-tight);
}

h1, h2, h3, h4 {
    color: var(--text-primary);
    letter-spacing: var(--tracking-tighter);
}

::selection {
    background: rgb(var(--blue-200));
}

.tabular-nums,
td, .stat-value, .badge {
    font-variant-numeric: tabular-nums;
}

:focus-visible {
    outline: 2px solid rgb(var(--blue-500) / 0.6);
    outline-offset: 2px;
}

button:focus:not(:focus-visible) {
    outline: none;
}

/* One focus treatment for every inline-Tailwind form control. Templates use
   a mix of focus:ring-1/2 + blue/indigo/green colors; this normalizes them. */
:is(input, select, textarea)[class*="focus:ring-"]:not([class*="focus:ring-0"]):focus,
:is(input, select, textarea)[class*="focus:border-"]:focus {
    outline: none !important;
    border-color: var(--border-focus) !important;
    box-shadow: var(--ring-focus) !important;
}

/* ======================================================================
   Buttons
   ====================================================================== */

.btn,
.btn-sm,
.canvas-edit-btn,
.canvas-fullscreen-close-btn {
    --btn-h: 32px;
    --btn-px: 12px;
    --btn-fs: var(--text-md);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    height: var(--btn-h);
    padding: 0 var(--btn-px);
    font-family: inherit;
    font-size: var(--btn-fs);
    font-weight: var(--weight-semibold);
    line-height: 1;
    letter-spacing: var(--tracking-tight);
    white-space: nowrap;
    border-radius: var(--radius-full);
    border: 0;
    cursor: pointer;
    user-select: none;
    text-decoration: none;
    background: var(--bg-surface);
    color: var(--text-body);
    box-shadow: var(--shadow-button);
    transition: background-color var(--duration-fast) var(--ease-out),
                box-shadow var(--duration-fast) var(--ease-out),
                color var(--duration-fast) var(--ease-out);
}

.btn svg,
.btn-sm svg,
.canvas-fullscreen-close-btn svg {
    width: 16px;
    height: 16px;
    flex-shrink: 0;
}

.btn:disabled,
.btn-sm:disabled,
.btn.is-disabled {
    opacity: 0.5;
    cursor: not-allowed;
    pointer-events: none;
}

.btn:focus-visible,
.btn-sm:focus-visible {
    outline: none;
    box-shadow: var(--shadow-button), var(--ring-focus);
}

/* Sizes */
.btn-xs { --btn-h: 24px; --btn-px: 8px; --btn-fs: var(--text-xs); gap: 4px; }
.btn-sm,
.canvas-edit-btn,
.canvas-fullscreen-close-btn { --btn-h: 28px; --btn-px: 12px; --btn-fs: var(--text-sm); }
.btn.btn-sm { --btn-h: 28px; --btn-px: 10px; --btn-fs: var(--text-sm); }
.btn-lg { --btn-h: 36px; --btn-px: 16px; }
.btn-xs svg, .btn-sm svg { width: 14px; height: 14px; }

.btn-icon { width: var(--btn-h); padding: 0; }
.btn:active:not(:disabled) { transform: scale(0.98); }
.btn-block { width: 100%; }

/* Variants */
.btn-secondary,
.btn-sm-secondary {
    background: var(--bg-surface);
    color: var(--text-body);
    box-shadow: var(--shadow-button);
}

.btn:hover,
.btn-sm:hover,
.btn-secondary:hover,
.btn-sm-secondary:hover,
.canvas-edit-btn:hover,
.canvas-fullscreen-close-btn:hover {
    background: var(--bg-subtle);
    color: var(--text-primary);
    box-shadow: 0 0 0 1px rgb(var(--ink) / 0.4);
}

.btn-primary,
.btn-sm-primary,
.canvas-edit-btn.primary {
    background: var(--action-primary);
    color: var(--text-inverse);
    box-shadow: var(--shadow-button-primary);
}

.btn-primary:hover,
.btn-sm-primary:hover,
.canvas-edit-btn.primary:hover {
    background: var(--action-primary-hover);
    color: var(--text-inverse);
    box-shadow: var(--shadow-lg);
}

/* Trailing arrow / icon accent on navy buttons is lime (website <Button arrow>) */
.btn-primary .btn-accent { color: var(--signal); }

.btn-primary:focus-visible,
.btn-sm-primary:focus-visible {
    box-shadow: var(--shadow-button-primary), var(--ring-focus);
}

.btn-sm-primary:disabled,
.btn-primary:disabled {
    opacity: 0.5;
}

.btn-ghost,
.btn-sm-ghost {
    background: transparent;
    color: var(--text-secondary);
    box-shadow: none;
}

.btn-ghost:hover,
.btn-sm-ghost:hover {
    background: rgb(var(--ink) / 0.05);
    color: var(--text-primary);
    box-shadow: none;
}

.btn-danger,
.btn-sm-danger {
    background: var(--bg-surface);
    color: rgb(var(--red-600));
    box-shadow: var(--shadow-button);
}

.btn-danger:hover,
.btn-sm-danger:hover {
    background: rgb(var(--red-50));
    color: rgb(var(--red-700));
    box-shadow: 0 0 0 1px rgb(var(--red-300));
}

.btn-danger-solid,
.btn-sm-danger-filled {
    background: rgb(var(--red-600));
    color: var(--text-inverse);
    box-shadow: 0 1px 1px rgb(var(--gray-900) / 0.1), 0 0 0 1px rgb(var(--red-700));
}

.btn-danger-solid:hover,
.btn-sm-danger-filled:hover {
    background: rgb(var(--red-700));
}

.btn-success,
.btn-sm-success {
    background: rgb(var(--green-600));
    color: var(--text-inverse);
    box-shadow: 0 1px 1px rgb(var(--gray-900) / 0.1), 0 0 0 1px rgb(var(--green-700));
}

.btn-success:hover,
.btn-sm-success:hover {
    background: rgb(var(--green-700));
}

.btn-sm-success:disabled {
    background: rgb(var(--green-300));
    box-shadow: none;
    opacity: 1;
}

/* Text link styled as a button-less action */
.link {
    color: var(--text-link);
    font-weight: var(--weight-medium);
    cursor: pointer;
    text-decoration: none;
}

.link:hover {
    color: var(--text-link-hover);
}

/* ======================================================================
   Form controls
   ====================================================================== */

.input,
.select,
.textarea {
    display: block;
    width: 100%;
    height: 32px;
    padding: 0 10px;
    font-family: inherit;
    font-size: var(--text-md);
    color: var(--text-primary);
    background: var(--bg-surface);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-md);
    transition: border-color var(--duration-fast), box-shadow var(--duration-fast);
}

.input-sm { height: 28px; font-size: var(--text-sm); }

.textarea {
    height: auto;
    min-height: 80px;
    padding: 8px 10px;
    line-height: 1.5;
    resize: vertical;
}

.input::placeholder,
.textarea::placeholder {
    color: var(--text-tertiary);
}

.input:hover,
.select:hover,
.textarea:hover {
    border-color: var(--border-field);
}

.input:focus,
.select:focus,
.textarea:focus {
    outline: none;
    border-color: var(--border-focus);
    box-shadow: var(--ring-focus);
}

/* Input with a leading icon */
.input-group {
    position: relative;
    display: flex;
    align-items: center;
}

.input-group > svg,
.input-group > .input-icon {
    display: flex;
    position: absolute;
    left: 10px;
    width: 14px;
    height: 14px;
    color: var(--text-tertiary);
    pointer-events: none;
}

.input-group > .input {
    padding-left: 30px;
}

.field {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.field-label {
    font-size: var(--text-sm);
    font-weight: var(--weight-medium);
    color: var(--text-primary);
}

.field-hint {
    font-size: var(--text-xs);
    color: var(--text-secondary);
}

/* ======================================================================
   Surfaces
   ====================================================================== */

.card,
.dashboard-card {
    background: var(--bg-surface);
    border: 1px solid var(--border-default);
    border-radius: var(--radius-lg);
}

.dashboard-card {
    padding: 20px;
}

.dashboard-card:hover {
    box-shadow: var(--shadow-xs);
}

.card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 14px 20px;
    border-bottom: 1px solid var(--border-subtle);
}

.card-title {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: var(--text-lg);
    font-weight: var(--weight-bold);
    color: var(--text-primary);
    letter-spacing: var(--tracking-tighter);
}

.card-title svg {
    width: 16px;
    height: 16px;
    color: var(--text-secondary);
}

.card-description {
    font-size: var(--text-sm);
    color: var(--text-secondary);
}

.card-body { padding: 16px 20px; }
.card-body-flush { padding: 0; }

.card-footer {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 8px;
    padding: 12px 20px;
    border-top: 1px solid var(--border-subtle);
    background: var(--bg-subtle);
    border-radius: 0 0 var(--radius-lg) var(--radius-lg);
}

.stat-card {
    background: var(--bg-surface);
    border: 1px solid var(--border-default);
    border-radius: var(--radius-lg);
    padding: 16px 20px;
}

.stat-label {
    font-size: var(--text-sm);
    font-weight: var(--weight-medium);
    color: var(--text-secondary);
}

.stat-value {
    margin-top: 4px;
    font-size: var(--text-2xl);
    font-weight: var(--weight-semibold);
    color: var(--text-primary);
    letter-spacing: var(--tracking-tighter);
}

/* Key/value property list (Stripe "Details" panel) */
.kv-list {
    display: grid;
    grid-template-columns: minmax(96px, 40%) 1fr;
    column-gap: 16px;
    row-gap: 10px;
    font-size: var(--text-sm);
}

.kv-list dt {
    color: var(--text-secondary);
}

.kv-list dd {
    color: var(--text-primary);
    min-width: 0;
    overflow-wrap: anywhere;
}

/* ======================================================================
   Page scaffolding
   ====================================================================== */

.page-header {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: 16px;
    flex-wrap: wrap;
    padding: 28px var(--page-padding-x) 16px;
}

.page-header.is-bordered {
    border-bottom: 1px solid var(--border-subtle);
}

.page-title {
    font-size: var(--text-3xl);
    line-height: 1.1;
    font-weight: var(--weight-bold);
    color: var(--text-primary);
    letter-spacing: -0.028em;   /* website type-h2 */
    margin: 0;
}

.page-subtitle {
    margin-top: 4px;
    font-size: var(--text-md);
    color: var(--text-secondary);
}

.page-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

.page-body {
    padding: 0 var(--page-padding-x) 32px;
}

/* Constrained pages center in the available width so wide windows (or a
   collapsed assistant) don't leave an empty band on one side. Header and
   body use the same class so their edges line up. */
.page-constrained,
.page-narrow,
.page-tight {
    width: 100%;
    margin-left: auto;
    margin-right: auto;
}

.page-constrained { max-width: var(--page-max-width); }
.page-narrow { max-width: 1000px; }
.page-tight { max-width: 800px; }

.section-title {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: var(--text-lg);
    font-weight: var(--weight-semibold);
    color: var(--text-primary);
    letter-spacing: var(--tracking-tighter);
}

.section-title .count,
.count-pill {
    display: inline-flex;
    align-items: center;
    height: 20px;
    padding: 0 7px;
    font-size: var(--text-xs);
    font-weight: var(--weight-medium);
    color: var(--text-secondary);
    background: var(--bg-muted);
    border-radius: var(--radius-full);
}

.section-eyebrow {
    font-size: var(--text-xs);
    font-weight: var(--weight-semibold);
    color: var(--text-secondary);
    text-transform: none;
    letter-spacing: 0;
}

.toolbar {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
    min-height: 32px;
}

.toolbar-spacer { flex: 1; }

.divider {
    height: 1px;
    background: var(--border-subtle);
    border: 0;
}

/* ======================================================================
   Tabs — segmented control + underline tabs
   ====================================================================== */

.segmented,
.tab-group {
    display: inline-flex;
    align-items: center;
    gap: 2px;
    padding: 3px;
    background: rgb(var(--gray-150));
    border-radius: var(--radius-full);
}

.segmented > button,
.tab-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    height: 26px;
    padding: 0 10px;
    font-family: inherit;
    font-size: var(--text-sm);
    font-weight: var(--weight-medium);
    color: var(--text-secondary);
    background: transparent;
    border: 0;
    border-radius: var(--radius-full);
    cursor: pointer;
    white-space: nowrap;
    transition: color var(--duration-fast), background-color var(--duration-fast);
}

.segmented > button:hover,
.tab-btn:hover {
    color: var(--text-primary);
}

.segmented > button.active,
.tab-btn.active {
    background: var(--bg-surface);
    color: var(--text-primary);
    box-shadow: var(--shadow-sm);
}

.tab-badge {
    font-size: var(--text-2xs);
    font-weight: var(--weight-semibold);
    padding: 0 6px;
    line-height: 18px;
    border-radius: var(--radius-full);
    background: rgb(var(--gray-200));
    color: var(--text-body);
}

.tab-btn.active .tab-badge {
    background: var(--accent);
    color: var(--text-inverse);
}

.tabs {
    display: flex;
    align-items: stretch;
    gap: 20px;
    border-bottom: 1px solid var(--border-default);
}

.tabs > .tab {
    position: relative;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 10px 0;
    font-size: var(--text-md);
    font-weight: var(--weight-medium);
    color: var(--text-secondary);
    background: none;
    border: 0;
    cursor: pointer;
    white-space: nowrap;
}

.tabs > .tab:hover {
    color: var(--text-primary);
}

.tabs > .tab.active {
    color: var(--accent);
}

.tabs > .tab.active::after {
    content: '';
    position: absolute;
    left: 0;
    right: 0;
    bottom: -1px;
    height: 2px;
    background: var(--accent);
    border-radius: 2px 2px 0 0;
}

/* ======================================================================
   Badges & chips
   ====================================================================== */

.badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    height: 20px;
    padding: 0 8px;
    font-size: var(--text-xs);
    font-weight: var(--weight-semibold);
    line-height: 1;
    white-space: nowrap;
    border-radius: var(--radius-full);
    background: rgb(var(--gray-150));
    color: var(--text-primary);
}

.badge svg { width: 12px; height: 12px; }

/* Website status chips (status-pill.tsx): ink text on a tint */
.badge-success { background: rgb(var(--green-100)); color: rgb(var(--green-800)); }
.badge-warning { background: rgb(var(--amber-100)); color: rgb(var(--amber-800)); }
.badge-danger  { background: rgb(var(--red-100));   color: rgb(var(--red-700)); }
.badge-info    { background: rgb(220 235 250);       color: var(--text-primary); }  /* status-review */
.badge-neutral { background: rgb(var(--gray-150));  color: var(--text-primary); }  /* status-signal */
.badge-signal  { background: var(--signal);         color: rgb(var(--ink)); }

.badge-dot::before {
    content: '';
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: currentColor;
}

/* Filter chip — dashed when empty, solid when applied (Stripe filter bar) */
.chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    height: 26px;
    padding: 0 10px;
    font-family: inherit;
    font-size: var(--text-sm);
    font-weight: var(--weight-medium);
    color: var(--text-body);
    background: var(--bg-surface);
    border: 1px dashed var(--border-strong);
    border-radius: var(--radius-full);
    cursor: pointer;
    white-space: nowrap;
    transition: background-color var(--duration-fast), border-color var(--duration-fast), color var(--duration-fast);
}

.chip svg {
    width: 14px;
    height: 14px;
    color: var(--text-secondary);
}

.chip:hover {
    background: var(--bg-subtle);
    border-color: rgb(var(--gray-400));
}

.chip.active {
    color: var(--accent-text);
    background: var(--accent-subtle);
    border-style: solid;
    border-color: rgb(var(--blue-200));
}

.chip.active svg {
    color: var(--accent);
}

/* ======================================================================
   Data table
   ====================================================================== */

.data-table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    font-size: var(--text-md);
}

.data-table thead th {
    position: sticky;
    top: 0;
    z-index: 2;
    height: 36px;
    padding: 0 12px;
    font-size: var(--text-xs);
    font-weight: var(--weight-semibold);
    color: var(--text-secondary);
    text-align: left;
    white-space: nowrap;
    background: var(--bg-surface);
    border-bottom: 1px solid var(--border-default);
}

.data-table tbody td {
    height: 44px;
    padding: 8px 12px;
    color: var(--text-body);
    border-bottom: 1px solid var(--border-subtle);
    vertical-align: middle;
}

.data-table tbody tr {
    transition: background-color var(--duration-fast);
}

.data-table tbody tr:hover {
    background: var(--bg-hover);
}

.data-table tbody tr.is-clickable {
    cursor: pointer;
}

.data-table .cell-primary {
    color: var(--text-primary);
    font-weight: var(--weight-medium);
}

.data-table .cell-muted {
    color: var(--text-secondary);
}

.data-table .cell-num {
    text-align: right;
}

/* ======================================================================
   Feedback: empty, skeleton, avatar, kbd
   ====================================================================== */

.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    gap: 6px;
    padding: 48px 24px;
}

.empty-state-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    margin-bottom: 6px;
    border-radius: var(--radius-md);
    background: var(--bg-muted);
    color: var(--text-secondary);
}

.empty-state-icon svg { width: 20px; height: 20px; }

.empty-state-title {
    font-size: var(--text-md);
    font-weight: var(--weight-semibold);
    color: var(--text-primary);
}

.empty-state-text {
    max-width: 360px;
    font-size: var(--text-sm);
    color: var(--text-secondary);
}

.empty-state .btn { margin-top: 10px; }

@keyframes skeleton-shimmer {
    0% { background-position: 100% 0; }
    100% { background-position: -100% 0; }
}

.skeleton {
    display: block;
    border-radius: var(--radius-xs);
    background: linear-gradient(90deg,
        rgb(var(--gray-100)) 0%,
        rgb(var(--gray-50)) 50%,
        rgb(var(--gray-100)) 100%);
    background-size: 200% 100%;
    animation: skeleton-shimmer 1.4s ease-in-out infinite;
}

.skeleton-text { height: 10px; margin: 5px 0; }
.skeleton-title { height: 14px; margin: 4px 0; }

.avatar {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    width: 28px;
    height: 28px;
    font-size: var(--text-xs);
    font-weight: var(--weight-semibold);
    color: var(--accent-text);
    background: rgb(var(--blue-100));
    border-radius: var(--radius-full);
}

.avatar-sm { width: 22px; height: 22px; font-size: 10px; }
.avatar-lg { width: 40px; height: 40px; font-size: var(--text-md); }
.avatar-square { border-radius: var(--radius-sm); }

.kbd {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 18px;
    height: 18px;
    padding: 0 4px;
    font-family: var(--font-sans);
    font-size: var(--text-2xs);
    font-weight: var(--weight-medium);
    color: var(--text-secondary);
    background: var(--bg-surface);
    border: 1px solid var(--border-default);
    border-bottom-width: 2px;
    border-radius: var(--radius-xs);
}

/* Entity glyph (square icon tile used for deals/companies/contacts) */
.entity-glyph {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    width: 32px;
    height: 32px;
    border-radius: var(--radius-sm);
    background: var(--bg-muted);
    color: var(--text-secondary);
    border: 1px solid var(--border-subtle);
}

.entity-glyph svg { width: 16px; height: 16px; }
.entity-glyph-sm { width: 28px; height: 28px; }
.entity-glyph-sm svg { width: 14px; height: 14px; }
.entity-glyph-lg { width: 48px; height: 48px; border-radius: var(--radius-md); }
.entity-glyph-lg svg { width: 22px; height: 22px; }

/* ======================================================================
   Menus / popovers
   ====================================================================== */

.menu {
    min-width: 180px;
    padding: 4px;
    background: var(--bg-surface);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-xl);
}

.menu-item {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
    height: 32px;
    padding: 0 10px;
    font-size: var(--text-md);
    color: var(--text-body);
    background: none;
    border: 0;
    border-radius: var(--radius-xs);
    cursor: pointer;
    text-align: left;
}

.menu-item:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.menu-item svg {
    width: 16px;
    height: 16px;
    color: var(--text-secondary);
}

.menu-separator {
    height: 1px;
    margin: 4px 0;
    background: var(--border-subtle);
}

/* ======================================================================
   Modal / dialog
   ====================================================================== */

.modal-backdrop,
.dialog-backdrop {
    background: var(--bg-overlay) !important;
    backdrop-filter: blur(1px);
}

/* Dialogs created by UI.prompt() */
.dialog-root {
    position: fixed;
    inset: 0;
    z-index: 260; /* above confirm modal (250) and fullscreen overlays */
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
}

.dialog-root > .dialog-backdrop {
    position: absolute;
    inset: 0;
    animation: backdrop-in var(--duration-base) var(--ease-out);
}

@keyframes backdrop-in {
    from { opacity: 0; }
    to { opacity: 1; }
}

.dialog-root > .dialog {
    position: relative;
    animation: dialog-in var(--duration-base) var(--ease-out);
}

@keyframes dialog-in {
    from { opacity: 0; transform: translateY(6px) scale(0.98); }
    to { opacity: 1; transform: none; }
}

.dialog-sm { max-width: 420px; }

.dialog {
    width: 100%;
    max-width: 520px;
    max-height: calc(100vh - 64px);
    display: flex;
    flex-direction: column;
    background: var(--bg-surface);
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-2xl);
    overflow: hidden;
}

.dialog-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 12px;
    padding: 20px 24px 12px;
}

.dialog-title {
    font-size: var(--text-xl);
    font-weight: var(--weight-semibold);
    color: var(--text-primary);
    letter-spacing: var(--tracking-tighter);
}

.dialog-description {
    margin-top: 4px;
    font-size: var(--text-md);
    color: var(--text-secondary);
}

.dialog-body {
    padding: 8px 24px 20px;
    overflow-y: auto;
}

.dialog-footer {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 8px;
    padding: 14px 24px;
    background: var(--bg-subtle);
    border-top: 1px solid var(--border-subtle);
}

/* ======================================================================
   Legacy aliases → new primitives
   ====================================================================== */

/* Activity filter pills used on entity timelines */
.filter-btn {
    border-radius: var(--radius-full);
    transition: background-color var(--duration-fast), color var(--duration-fast), border-color var(--duration-fast);
}

.filter-btn.active {
    background: var(--bg-inverse);
    color: var(--text-inverse);
    border-color: var(--bg-inverse);
}

/* Spinner (kept for in-button/inline progress) */
.spinner {
    border: 2px solid rgb(var(--gray-200));
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
}

/* Thin, unobtrusive scrollbars everywhere */
* {
    scrollbar-width: thin;
    scrollbar-color: rgb(var(--gray-300)) transparent;
}

*::-webkit-scrollbar {
    width: 10px;
    height: 10px;
}

*::-webkit-scrollbar-thumb {
    background: rgb(var(--gray-300));
    border-radius: 999px;
    border: 3px solid transparent;
    background-clip: content-box;
}

*::-webkit-scrollbar-thumb:hover {
    background: rgb(var(--gray-400));
    background-clip: content-box;
    border: 3px solid transparent;
}

*::-webkit-scrollbar-track {
    background: transparent;
}

/* ======================================================================
   Lists (rows inside cards) + card grid
   ====================================================================== */

.card-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(340px, 1fr));
    gap: 20px;
    align-items: start;
}

.list {
    display: flex;
    flex-direction: column;
}

.list-row {
    display: flex;
    align-items: center;
    gap: 12px;
    min-height: 52px;
    padding: 8px 20px;
    text-decoration: none;
    border-top: 1px solid var(--border-subtle);
    cursor: pointer;
    transition: background-color var(--duration-fast);
}

.list > .list-row:first-child {
    border-top: 0;
}

.list-row:hover {
    background: var(--bg-hover);
}

.list-row-main {
    flex: 1;
    min-width: 0;
}

.list-row-title {
    font-size: var(--text-md);
    font-weight: var(--weight-medium);
    color: var(--text-primary);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.list-row-meta {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-top: 2px;
    font-size: var(--text-xs);
    color: var(--text-secondary);
    min-width: 0;
    white-space: nowrap;
    overflow: hidden;
}

.list-row-meta > .sep::before {
    content: '·';
    color: var(--text-tertiary);
}

.list-row-end {
    flex-shrink: 0;
    font-size: var(--text-md);
    font-weight: var(--weight-medium);
    color: var(--text-primary);
    font-variant-numeric: tabular-nums;
}

.list-row-action {
    flex-shrink: 0;
    opacity: 0;
    transition: opacity var(--duration-fast);
}

.list-row:hover .list-row-action,
.list-row:focus-within .list-row-action {
    opacity: 1;
}

.list-footer {
    display: block;
    width: 100%;
    padding: 10px 20px;
    font-family: inherit;
    font-size: var(--text-sm);
    font-weight: var(--weight-medium);
    color: var(--text-link);
    text-align: left;
    background: none;
    border: 0;
    border-top: 1px solid var(--border-subtle);
    cursor: pointer;
}

.list-footer:hover {
    color: var(--text-link-hover);
    background: var(--bg-hover);
}

.status-dot {
    display: inline-block;
    flex-shrink: 0;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: rgb(var(--gray-400));
}

.status-dot-success { background: rgb(var(--green-500)); }
.status-dot-warning { background: rgb(var(--amber-500)); }
.status-dot-danger  { background: rgb(var(--red-500)); }
.status-dot-info    { background: var(--accent); }

/* Compact clickable tile (favorites, pinned records) */
.tile {
    position: relative;
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 10px;
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: background-color var(--duration-fast), border-color var(--duration-fast);
}

.tile:hover {
    background: var(--bg-hover);
    border-color: var(--border-default);
}

.tile-title {
    font-size: var(--text-md);
    font-weight: var(--weight-medium);
    color: var(--text-primary);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.tile-meta {
    font-size: var(--text-xs);
    color: var(--text-secondary);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.tile-action {
    opacity: 0;
}

.tile:hover .tile-action,
.tile:focus-within .tile-action {
    opacity: 1;
}

/* ======================================================================
   Record pages (deal / company / contact / person) — js/ui/entity-layout.js
   ====================================================================== */

.detail-scroll,
#personDetail {
    container-type: inline-size;
    container-name: record;
}

.detail-header {
    padding: 20px var(--page-padding-x) 0;
}

.detail-breadcrumb {
    margin-bottom: 10px;
}

.detail-breadcrumb .back-to-list-btn {
    display: inline-flex;
    align-items: center;
    gap: 2px;
    margin-left: -4px;
    padding: 2px 6px 2px 2px;
    font-family: inherit;
    font-size: var(--text-sm);
    font-weight: var(--weight-semibold);
    color: var(--text-link);
    background: none;
    border: 0;
    border-radius: var(--radius-xs);
    cursor: pointer;
}

.detail-breadcrumb .back-to-list-btn:hover {
    color: var(--text-link-hover);
    background: var(--accent-subtle);
}

.detail-title-row {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 16px;
    flex-wrap: wrap;
}

.detail-title {
    font-size: var(--text-2xl);
    line-height: 1.2;
    font-weight: var(--weight-bold);
    letter-spacing: -0.02em;
    color: var(--text-primary);
    margin: 0;
    overflow-wrap: anywhere;
}

.detail-meta {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
    margin-top: 4px;
    font-size: var(--text-sm);
    color: var(--text-secondary);
}

.detail-actions {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-shrink: 0;
}

/* Key facts: label over value, hairline-separated, wraps instead of truncating */
.summary-strip {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(132px, 1fr));
    margin: 18px 0 0;
    background: var(--bg-surface);
    border: 1px solid var(--border-default);
    border-radius: var(--radius-lg);
    overflow: hidden;
}

.summary-item {
    min-width: 0;
    padding: 12px 16px;
    box-shadow: -1px 0 0 var(--border-subtle), 0 -1px 0 var(--border-subtle);
}

.summary-item.is-wide {
    grid-column: 1 / -1;
    cursor: pointer;
}

.summary-label {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 4px;
    font-size: var(--text-xs);
    font-weight: var(--weight-semibold);
    color: var(--text-secondary);
}

.summary-value {
    margin: 4px 0 0;
    font-size: var(--text-md);
    font-weight: var(--weight-semibold);
    color: var(--text-primary);
    font-variant-numeric: tabular-nums;
    overflow-wrap: anywhere;
}

.summary-sub {
    margin: 2px 0 0;
    font-size: var(--text-xs);
    color: var(--text-secondary);
}

.tone-danger  { color: rgb(var(--red-700)); font-weight: var(--weight-semibold); }
.tone-warning { color: rgb(var(--amber-700)); font-weight: var(--weight-semibold); }
.tone-success { color: rgb(var(--green-700)); }
.tone-info    { color: var(--accent-text); }
.tone-muted   { color: var(--text-secondary); }

.summary-item.expanded .summary-value {
    -webkit-line-clamp: unset;
    display: block;
    white-space: pre-wrap;
}

.summary-item .info-card-chevron { transition: transform var(--duration-fast); }
.summary-item.expanded .info-card-chevron { transform: rotate(180deg); }

/* Two columns once the record has room; one column next to an open assistant */
.detail-layout {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    grid-template-areas: "aside" "main";
    gap: 16px;
    padding: 16px var(--page-padding-x) 40px;
}

.detail-layout.is-single {
    grid-template-areas: "main";
}

.detail-main  { grid-area: main;  display: flex; flex-direction: column; gap: 16px; min-width: 0; }
.detail-aside { grid-area: aside; display: flex; flex-direction: column; gap: 16px; min-width: 0; }

@container record (min-width: 920px) {
    .detail-layout:not(.is-single) {
        grid-template-columns: minmax(0, 1fr) 300px;
        grid-template-areas: "main aside";
        align-items: start;
    }
    .detail-aside {
        position: sticky;
        top: 16px;
    }
}

.detail-card {
    padding: 16px 18px;
    background: var(--bg-surface);
    border: 1px solid var(--border-default);
    border-radius: var(--radius-lg);
}

.detail-card-title-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    flex-wrap: wrap;
    margin-bottom: 12px;
}

.detail-card-title {
    font-size: var(--text-md);
    font-weight: var(--weight-bold);
    color: var(--text-primary);
    letter-spacing: -0.005em;
    margin: 0;
}

.detail-card > .detail-card-title {
    margin-bottom: 10px;
}

.detail-card-title-row > .detail-card-title {
    margin-bottom: 0;
}

/* HubSpot field list in the Details card */
.kv-rows {
    display: flex;
    flex-direction: column;
}

.kv-row {
    display: grid;
    grid-template-columns: minmax(90px, 42%) minmax(0, 1fr);
    gap: 12px;
    padding: 8px 0;
    font-size: var(--text-sm);
    border-top: 1px solid var(--border-subtle);
}

.kv-row:first-child { border-top: 0; }
.kv-row-label { color: var(--text-secondary); overflow-wrap: anywhere; }
.kv-row-value { color: var(--text-primary); min-width: 0; overflow-wrap: anywhere; }

/* Compact segmented control (timeline filters) */
.segmented-sm > button,
.segmented-sm > .tab-btn {
    height: 24px;
    padding: 0 9px;
    font-size: var(--text-xs);
}

.btn-ghost.active {
    background: var(--accent-subtle);
    color: var(--accent-text);
}

.timeline-list {
    display: flex;
    flex-direction: column;
}

/* ======================================================================
   Activity timeline (Components._renderSingleActivity)
   ====================================================================== */

.timeline-item {
    position: relative;
    display: flex;
    gap: 12px;
    padding: 10px 0 14px;
}

/* Connector line between event icons */
.timeline-item::before {
    content: '';
    position: absolute;
    left: 13px;
    top: 38px;
    bottom: -4px;
    width: 1px;
    background: var(--border-default);
}

.timeline-item:last-child::before,
.timeline-item:has(+ .activity-load-more)::before {
    display: none;
}

.timeline-icon {
    position: relative;
    z-index: 1;
    display: grid;
    place-items: center;
    flex-shrink: 0;
    width: 28px;
    height: 28px;
    color: rgb(var(--ink));
    border-radius: var(--radius-full);
    box-shadow: 0 0 0 3px var(--bg-surface);
}

.timeline-body {
    flex: 1;
    min-width: 0;
    padding-top: 3px;
}

.timeline-head {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 12px;
}

.timeline-title {
    min-width: 0;
    font-size: var(--text-md);
    font-weight: var(--weight-semibold);
    color: var(--text-primary);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    margin: 0;
}

.timeline-time {
    flex-shrink: 0;
    font-size: var(--text-xs);
    color: var(--text-secondary);
    font-variant-numeric: tabular-nums;
}

.timeline-meta {
    margin-top: 2px;
    font-size: var(--text-xs);
    color: var(--text-secondary);
    overflow-wrap: anywhere;
}

.timeline-action {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    margin-top: 6px;
    padding: 0;
    font-family: inherit;
    font-size: var(--text-xs);
    font-weight: var(--weight-semibold);
    color: var(--text-link);
    background: none;
    border: 0;
    cursor: pointer;
}

.timeline-action:hover {
    color: var(--text-link-hover);
}

.timeline-action svg {
    transition: transform var(--duration-fast);
}

.timeline-content {
    margin-top: 8px;
    padding: 10px 12px;
    max-height: 12rem;
    overflow-y: auto;
    font-size: var(--text-sm);
    line-height: 1.55;
    color: var(--text-body);
    white-space: pre-wrap;
    background: var(--bg-subtle);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-sm);
}

/* Related-record rows (Components.renderEntityCard / renderDealCard) */
.entity-list {
    display: flex;
    flex-direction: column;
    margin: 0 -8px;
}

.entity-row {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 7px 8px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: background-color var(--duration-fast);
}

.entity-row:hover {
    background: var(--bg-hover);
}

.entity-row-title {
    font-size: var(--text-md);
    font-weight: var(--weight-semibold);
    color: var(--text-primary);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.entity-row-meta {
    margin-top: 1px;
    font-size: var(--text-xs);
    color: var(--text-secondary);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.entity-row-amount {
    flex-shrink: 0;
    font-size: var(--text-sm);
    font-weight: var(--weight-semibold);
    color: var(--text-primary);
    font-variant-numeric: tabular-nums;
}

.entity-row-chevron {
    flex-shrink: 0;
    color: var(--text-tertiary);
}

/* Automation list rows (Workflows) */
.automation-row {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    padding: 12px 14px;
    background: var(--bg-surface);
    border: 1px solid var(--border-default);
    border-radius: var(--radius-lg);
    cursor: pointer;
    transition: border-color var(--duration-fast), box-shadow var(--duration-fast);
}

.automation-row:hover {
    border-color: var(--border-strong);
}

.automation-row.is-selected {
    border-color: rgb(var(--blue-400));
    box-shadow: var(--ring-focus);
}

.automation-row-title {
    min-width: 0;
    font-size: var(--text-md);
    font-weight: var(--weight-semibold);
    color: var(--text-primary);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.automation-row .badge { flex-shrink: 0; }

.automation-row-description {
    margin-top: 2px;
    font-size: var(--text-sm);
    color: var(--text-body);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.automation-row-meta {
    margin-top: 6px;
    font-size: var(--text-xs);
    color: var(--text-secondary);
}
