/* ==========================================================================
   Tag Pills — .av-category-pill
   ========================================================================== */

/* Preset color custom properties */
:root {
    --av-category-slate:  #64748b;
    --av-category-rose:   #e11d48;
    --av-category-amber:  #d97706;
    --av-category-lime:   #65a30d;
    --av-category-sky:    #0284c7;
    --av-category-violet: #7c3aed;
    --av-category-cyan:   #0891b2;
    --av-category-stone:  #78716c;
}

.av-category-pill {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 2px 8px;
    border-radius: 9999px;
    font-size: var(--font-xs, 11px);
    font-weight: 500;
    line-height: 1.5;
    background: var(--bg-hover-subtle);
    color: var(--text-secondary);
    border: 1px solid var(--border-light);
    white-space: nowrap;
    user-select: none;
}

.av-category-pill--colored {
    background: color-mix(in srgb, var(--av-category-color, #64748b) 15%, transparent);
    color: var(--av-category-color, #64748b);
    border-color: color-mix(in srgb, var(--av-category-color, #64748b) 30%, transparent);
}

/* Org-scope variant: thicker border + 🏢 leading badge.
   The badge is rendered inline as a small emoji span. */
.av-category-pill--org {
    border-style: dashed;
    border-color: color-mix(in srgb, var(--av-category-color, #64748b) 50%, var(--border-light));
}
.av-category-pill-badge {
    font-size: 0.85em;
    line-height: 1;
    margin-right: 1px;
    opacity: 0.8;
}

.av-category-pill--clickable {
    cursor: pointer;
    transition: opacity 0.15s;
}
.av-category-pill--clickable:hover,
.av-category-pill--clickable:focus-visible {
    opacity: 0.75;
    outline: 2px solid var(--av-category-color, var(--accent-primary));
    outline-offset: 1px;
}

.av-category-pill--removable {
    padding-right: 4px;
}

.av-category-pill-remove {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 16px;
    height: 16px;
    padding: 0;
    margin: 0;
    border: none;
    border-radius: 50%;
    background: transparent;
    color: inherit;
    font-size: 13px;
    line-height: 1;
    cursor: pointer;
    opacity: 0.6;
    transition: opacity 0.15s, background 0.15s;
}
.av-category-pill-remove:hover {
    opacity: 1;
    background: var(--bg-hover-medium);
}
.av-category-pill-remove:focus-visible {
    outline: 2px solid var(--accent-primary);
    outline-offset: 1px;
}

/* More-badge: "+N" pill used when display has > 3 visible categories */
.av-category-more-badge {
    display: inline-flex;
    align-items: center;
    padding: 2px 7px;
    border-radius: 9999px;
    font-size: var(--font-xs, 11px);
    font-weight: 600;
    line-height: 1.5;
    background: var(--bg-hover-subtle);
    color: var(--text-muted);
    border: 1px solid var(--border-light);
    cursor: default;
    white-space: nowrap;
}

/* Tag row used on cards and detail header */
.av-category-row {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    align-items: center;
    margin-top: 4px;
}

/* ==========================================================================
   Tag Input — .av-category-input combobox
   ========================================================================== */

.av-category-input {
    position: relative;
    width: 100%;
}

.av-category-input-field {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    align-items: center;
    min-height: 40px;
    padding: 4px 8px;
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    background: var(--bg-input, var(--bg-primary));
    cursor: text;
    transition: border-color 0.15s;
}
.av-category-input-field:focus-within {
    border-color: var(--accent-primary);
    box-shadow: 0 0 0 2px color-mix(in srgb, var(--accent-primary) 20%, transparent);
}

.av-category-input-pills {
    display: contents; /* pills flow inline with input */
}

.av-category-input-text {
    flex: 1 1 80px;
    min-width: 60px;
    border: none;
    background: transparent;
    color: var(--text-primary);
    font-family: var(--font-family);
    font-size: var(--font-sm);
    outline: none;
    padding: 2px 0;
}
.av-category-input-text::placeholder {
    color: var(--text-muted);
}

.av-category-input-suggestions {
    position: absolute;
    top: calc(100% + 4px);
    left: 0;
    right: 0;
    z-index: 200;
    margin: 0;
    padding: 4px 0;
    list-style: none;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-md);
    max-height: 220px;
    overflow-y: auto;
}

.av-category-input-option {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 12px;
    font-size: var(--font-sm);
    color: var(--text-primary);
    cursor: pointer;
    transition: background 0.1s;
}
.av-category-input-option:hover,
.av-category-input-option.is-active {
    background: var(--bg-hover-subtle);
}

.av-category-input-option-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    flex-shrink: 0;
    background: var(--av-category-color, var(--border));
}

.av-category-input-option-scope {
    font-size: var(--font-xs);
    opacity: 0.75;
}

.av-category-input-option-label {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
}

.av-category-input-option-origin {
    min-width: 0;
    max-width: 40%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    color: var(--text-muted);
    font-size: var(--font-xs);
}

.av-category-input-option-count {
    margin-left: auto;
    font-size: var(--font-xs);
    color: var(--text-muted);
}

/* ==========================================================================
   Tag Manager — used in account settings section
   ========================================================================== */

.av-category-manager-list {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.av-category-create-row {
    margin-bottom: var(--space-md);
    padding: var(--space-sm);
    border: 1px solid var(--border-light);
    border-radius: var(--radius-sm);
    background: color-mix(in srgb, var(--bg-hover-subtle) 72%, transparent);
}

.av-category-create-controls {
    display: flex;
    gap: var(--space-sm);
    align-items: stretch;
}

.av-category-create-mode {
    margin-bottom: var(--space-sm);
}

.av-category-create-controls .av-input {
    flex: 1;
    min-width: 0;
}

.av-category-create-child-row {
    display: grid;
    grid-template-columns: minmax(140px, 0.9fr) minmax(160px, 1.1fr);
    gap: var(--space-sm);
    flex: 1;
    min-width: 0;
}

.av-category-create-child-row[hidden] {
    display: none;
}

.av-category-create-row .av-input-hint {
    margin: var(--space-xs) 0 0;
    min-height: 1.4em;
    color: var(--text-muted);
    font-size: var(--font-xs);
}

.av-category-create-row .av-input-hint.is-error {
    color: var(--danger);
}

.av-category-create-meta {
    display: flex;
    flex-direction: column;
    gap: var(--space-xs);
}

.av-category-create-row code {
    color: var(--text-primary);
    background: var(--bg-hover-medium);
    border: 1px solid var(--border-light);
    border-radius: var(--radius-xs);
    padding: 1px 5px;
}

.av-category-create-suggestions {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    align-items: center;
}

.av-category-create-suggestions-label {
    color: var(--text-muted);
    font-size: var(--font-xs);
    font-weight: 600;
    margin-right: 2px;
}

.av-category-suggestion-chip {
    display: inline-flex;
    align-items: center;
    min-height: 26px;
    padding: 3px 9px;
    border: 1px solid var(--border-light);
    border-radius: 9999px;
    background: var(--bg-card);
    color: var(--text-secondary);
    font: inherit;
    font-size: var(--font-xs);
    line-height: 1.2;
    cursor: pointer;
    transition: border-color 0.15s, background 0.15s, color 0.15s;
}

.av-category-suggestion-chip:hover,
.av-category-suggestion-chip:focus-visible {
    border-color: var(--accent-primary);
    background: var(--accent-primary-dim);
    color: var(--text-primary);
    outline: none;
}

.av-category-advanced-actions {
    margin-top: var(--space-md);
    padding-top: var(--space-md);
    border-top: 1px solid var(--border-light);
}

.av-category-advanced-actions > summary {
    width: max-content;
    list-style: none;
    cursor: pointer;
}

.av-category-advanced-actions > summary::-webkit-details-marker {
    display: none;
}

.av-category-advanced-actions-menu {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-sm);
    margin-top: var(--space-sm);
}

.av-category-manager-row {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    padding: var(--space-xs) var(--space-sm);
    border-radius: var(--radius-sm);
    background: var(--bg-hover-subtle);
    transition: background 0.15s;
}
.av-category-manager-row:hover {
    background: var(--bg-hover-medium);
}

.av-category-manager-swatch {
    width: 14px;
    height: 14px;
    border-radius: 3px;
    flex-shrink: 0;
    background: var(--av-category-color, var(--border));
    cursor: pointer;
    border: 1px solid var(--line);
    transition: transform 0.1s;
}
.av-category-manager-swatch:hover {
    transform: scale(1.2);
}

.av-category-manager-name {
    flex: 1;
    min-width: 0;
    font-size: var(--font-sm);
    font-weight: 500;
    color: var(--text-primary);
    overflow-wrap: anywhere;
}

.av-category-manager-count {
    flex-shrink: 0;
    font-size: var(--font-xs);
    color: var(--text-muted);
}

@media (max-width: 520px) {
    .av-category-create-controls {
        flex-direction: column;
    }

    .av-category-create-child-row {
        grid-template-columns: 1fr;
    }

    .av-category-create-controls .av-btn {
        width: 100%;
        justify-content: center;
    }

    .av-category-advanced-actions > summary {
        width: 100%;
        justify-content: center;
    }

    .av-category-advanced-actions-menu .av-btn {
        width: 100%;
        justify-content: center;
    }
}

/* Color-picker palette */
.av-category-color-picker {
    display: flex;
    flex-direction: column;
    gap: var(--space-sm);
}
.av-category-color-presets {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}
.av-category-color-preset {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    border: 2px solid transparent;
    cursor: pointer;
    transition: transform 0.1s, border-color 0.1s;
}
.av-category-color-preset:hover,
.av-category-color-preset.is-selected {
    transform: scale(1.15);
    border-color: var(--text-primary);
}
.av-category-color-hex-row {
    display: flex;
    gap: var(--space-sm);
    align-items: center;
}
.av-category-color-hex-row label {
    font-size: var(--font-xs);
    color: var(--text-muted);
    flex-shrink: 0;
}

/* Tag grants modal */
.av-category-grants-dialog {
    display: flex;
    flex-direction: column;
    gap: var(--space-md);
}

.av-category-grants-hero {
    display: flex;
    justify-content: space-between;
    gap: var(--space-md);
    align-items: flex-start;
    padding: var(--space-sm);
    border: 1px solid var(--border-light);
    border-radius: var(--radius-sm);
    background: var(--bg-hover-subtle);
}

.av-category-grants-hero p {
    margin: 0;
    color: var(--text-secondary);
    font-size: var(--font-sm);
    line-height: 1.5;
}

.av-category-grants-kicker,
.av-category-grant-label {
    color: var(--text-muted);
    font-size: var(--font-xs);
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.av-category-grants-scope,
.av-category-grant-access {
    display: inline-flex;
    align-items: center;
    min-height: 24px;
    padding: 2px 8px;
    border: 1px solid var(--border-light);
    border-radius: 999px;
    background: var(--bg-card);
    color: var(--text-secondary);
    font-size: var(--font-xs);
    font-weight: 700;
    white-space: nowrap;
}

.av-category-grants-grid {
    display: grid;
    grid-template-columns: minmax(0, 1.45fr) minmax(220px, 0.75fr);
    gap: var(--space-md);
}

.av-category-grants-panel,
.av-category-grants-help,
.av-category-grants-existing {
    padding: var(--space-sm);
    border: 1px solid var(--border-light);
    border-radius: var(--radius-sm);
    background: var(--bg-card);
}

.av-category-grants-panel {
    display: flex;
    flex-direction: column;
    gap: var(--space-sm);
}

.av-category-grants-panel h3,
.av-category-grants-help h3,
.av-category-grants-existing h3 {
    margin: 0;
    color: var(--text-primary);
    font-size: var(--font-sm);
    font-weight: 700;
}

.av-category-grants-form-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: var(--space-sm);
}

.av-category-grants-preview {
    min-height: 30px;
    padding: 6px 8px;
    border: 1px dashed var(--border-light);
    border-radius: var(--radius-sm);
    background: var(--bg-hover-subtle);
    color: var(--text-muted);
    font-size: var(--font-xs);
}

.av-category-grants-preview code,
.av-category-grant-row code {
    color: var(--text-primary);
    background: var(--bg-hover-medium);
    border: 1px solid var(--border-light);
    border-radius: var(--radius-xs);
    padding: 1px 5px;
    font-size: var(--font-xs);
    overflow-wrap: anywhere;
}

.av-category-grants-help {
    display: flex;
    flex-direction: column;
    gap: var(--space-sm);
}

.av-category-grants-help-item {
    display: grid;
    gap: 5px;
}

.av-category-grants-help-item p {
    margin: 0;
    color: var(--text-muted);
    font-size: var(--font-xs);
    line-height: 1.45;
}

.av-category-grant-access.is-view {
    border-color: color-mix(in srgb, var(--accent-primary) 25%, var(--border-light));
    background: color-mix(in srgb, var(--accent-primary) 10%, transparent);
}

.av-category-grant-access.is-control {
    border-color: color-mix(in srgb, #d97706 35%, var(--border-light));
    background: color-mix(in srgb, #d97706 12%, transparent);
}

.av-category-grant-access.is-manage {
    border-color: color-mix(in srgb, var(--danger) 35%, var(--border-light));
    background: color-mix(in srgb, var(--danger) 10%, transparent);
}

.av-category-grants-existing-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-sm);
    margin-bottom: var(--space-sm);
}

.av-category-grants-existing-head span {
    color: var(--text-muted);
    font-family: var(--font-mono);
    font-size: var(--font-xs);
}

.av-category-grants-list {
    display: flex;
    flex-direction: column;
    gap: 6px;
    max-height: 340px;
    overflow-y: auto;
}

.av-category-grant-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-sm);
    padding: var(--space-sm);
    border: 1px solid var(--border-light);
    border-radius: var(--radius-sm);
    background: var(--bg-hover-subtle);
}

.av-category-grant-main {
    display: grid;
    grid-template-columns: minmax(150px, 0.8fr) minmax(0, 1.2fr);
    gap: var(--space-sm);
    min-width: 0;
}

.av-category-grant-user,
.av-category-grant-pattern {
    display: grid;
    gap: 4px;
    min-width: 0;
}

.av-category-grant-actions {
    display: inline-flex;
    align-items: center;
    gap: var(--space-xs);
    flex-shrink: 0;
}

.av-category-grants-empty {
    padding: var(--space-md);
    text-align: center;
    color: var(--text-muted);
}

@media (max-width: 760px) {
    .av-category-grants-grid,
    .av-category-grants-form-grid,
    .av-category-grant-main {
        grid-template-columns: 1fr;
    }

    .av-category-grants-hero,
    .av-category-grant-row {
        flex-direction: column;
        align-items: stretch;
    }

    .av-category-grant-actions {
        justify-content: space-between;
    }
}

/* MOB-601 small-phone breakpoint (iPhone 13 mini, Pixel 5a, etc.).
   The 760px stack already collapses the two-column grid; on a 390px
   viewport we additionally want the grant-form fields and any inline
   action rows to lose their internal horizontal padding so the controls
   don't overflow. Keep this rule narrow — anything that should also
   apply at 760px belongs in the block above. */
@media (max-width: 390px) {
    .av-category-grants-panel,
    .av-category-grants-help,
    .av-category-grants-existing {
        padding: var(--space-xs);
    }

    .av-category-grants-form-grid {
        gap: var(--space-xs);
    }
}
