/* ============================================================
   BYOK — Bring Your Own Key
   Minimal, modern, mobile-first design that fits the rest of
   the user settings aesthetic (matches us-shortcuts-grid look).
   ============================================================ */

.byok-shell {
    display: flex;
    flex-direction: column;
    gap: 40px;
}

/* ---------- Hero ---------- */

.byok-hero {
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding-bottom: 24px;
    border-bottom: 1px solid var(--border-color);
}

.byok-hero-eyebrow {
    margin: 0;
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: var(--text-color-tertiary);
}

.byok-hero-title {
    margin: 0;
    font-size: 24px;
    font-weight: 600;
    line-height: 1.2;
    letter-spacing: -0.02em;
    color: var(--text-color);
}

.byok-hero-description {
    margin: 6px 0 0;
    max-width: 720px;
    font-size: 14px;
    line-height: 1.6;
    color: var(--text-color-secondary);
}

/* ---------- Sections ---------- */

.byok-section {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.byok-section-head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 16px;
}

.byok-section-head-text {
    flex: 1 1 auto;
    min-width: 0;
}

.byok-section-title {
    margin: 0;
    font-size: 15px;
    font-weight: 600;
    color: var(--text-color);
    letter-spacing: -0.005em;
}

.byok-section-description {
    margin: 4px 0 0;
    font-size: 13px;
    line-height: 1.55;
    color: var(--text-color-secondary);
}

.byok-section-count {
    flex: 0 0 auto;
    align-self: center;
    font-size: 12px;
    font-weight: 500;
    color: var(--text-color-tertiary);
    white-space: nowrap;
}

/* ---------- Add button (icon + label) ---------- */

.byok-add-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    height: 32px;
    padding: 0 12px;
    background: transparent;
    color: var(--text-color);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    font-size: 13px;
    font-weight: 500;
    font-family: inherit;
    cursor: pointer;
    transition: background-color 0.15s ease, border-color 0.15s ease;
}

.byok-add-btn svg {
    width: 14px;
    height: 14px;
}

@media (hover: hover) and (pointer: fine) {
    .byok-add-btn:hover {
        background: var(--hover);
        border-color: var(--text-color-secondary);
    }
}

.byok-add-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* ---------- List ---------- */

.byok-list {
    list-style: none;
    margin: 0;
    padding: 0;
    border: 1px solid var(--border-color);
    border-radius: 14px;
    background: var(--background);
    overflow: hidden;
}

.byok-list-item {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 14px 16px;
    border-bottom: 1px solid var(--border-color);
    transition: background-color 0.15s ease;
}

.byok-list-item:last-child {
    border-bottom: none;
}

@media (hover: hover) and (pointer: fine) {
    .byok-list-item:hover {
        background: var(--hover);
    }
}

.byok-item-icon {
    flex: 0 0 auto;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    border-radius: 10px;
    background: var(--hover);
    color: var(--text-color);
    overflow: hidden;
}

.byok-item-icon svg {
    width: 18px;
    height: 18px;
}

.byok-item-icon img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.byok-item-icon .workspace-icon-emoji {
    width: 100%;
    height: 100%;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    line-height: 1;
}

.byok-item-body {
    flex: 1 1 auto;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.byok-item-title-row {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

.byok-item-title {
    margin: 0;
    font-size: 14px;
    font-weight: 600;
    color: var(--text-color);
    line-height: 1.35;
    letter-spacing: -0.005em;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 100%;
}

.byok-item-meta {
    margin: 0;
    font-size: 12.5px;
    color: var(--text-color-secondary);
    line-height: 1.45;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.byok-item-tag {
    display: inline-flex;
    align-items: center;
    height: 20px;
    padding: 0 8px;
    border-radius: 999px;
    font-size: 11px;
    font-weight: 500;
    line-height: 1;
    background: var(--hover);
    color: var(--text-color-secondary);
}

.byok-item-tag.is-active {
    background: color-mix(in srgb, var(--success-color, #2ecc71) 14%, transparent);
    color: var(--success-color, #2ecc71);
}

.byok-item-tag.is-warning {
    background: color-mix(in srgb, var(--pending, #e67e22) 14%, transparent);
    color: var(--pending, #e67e22);
}

.byok-item-actions {
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    gap: 4px;
}

.byok-icon-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    padding: 0;
    background: transparent;
    color: var(--text-color-secondary);
    border: 1px solid transparent;
    border-radius: 8px;
    cursor: pointer;
    transition: background-color 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}

.byok-icon-btn svg {
    width: 16px;
    height: 16px;
}

@media (hover: hover) and (pointer: fine) {
    .byok-icon-btn:hover {
        background: var(--hover);
        color: var(--text-color);
    }

    .byok-icon-btn.is-danger:hover {
        background: color-mix(in srgb, var(--error-color, #e74c3c) 12%, transparent);
        color: var(--error-color, #e74c3c);
    }
}

/* ---------- Empty State ---------- */

.byok-empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 12px;
    padding: 40px 24px;
    border: 1px dashed var(--border-color);
    border-radius: 14px;
    text-align: center;
}

.byok-empty-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 44px;
    height: 44px;
    border-radius: 12px;
    background: var(--hover);
    color: var(--text-color-secondary);
}

.byok-empty-icon svg {
    width: 22px;
    height: 22px;
}

.byok-empty-title {
    margin: 0;
    font-size: 14px;
    font-weight: 600;
    color: var(--text-color);
}

.byok-empty-desc {
    margin: 0;
    max-width: 420px;
    font-size: 13px;
    line-height: 1.55;
    color: var(--text-color-secondary);
}

.byok-empty .byok-add-btn {
    margin-top: 4px;
}

/* ---------- Tracking / Stats Controls ---------- */

.byok-tracking-card {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 16px 18px;
    border: 1px solid var(--border-color);
    border-radius: 14px;
    background: var(--background);
}

.byok-tracking-text {
    flex: 1 1 auto;
    min-width: 0;
}

.byok-tracking-title {
    margin: 0;
    font-size: 14px;
    font-weight: 600;
    color: var(--text-color);
}

.byok-tracking-desc {
    margin: 4px 0 0;
    font-size: 13px;
    line-height: 1.5;
    color: var(--text-color-secondary);
}

.byok-stats-toolbar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 12px;
    border: 1px solid var(--border-color);
    border-radius: 12px;
    background: var(--background);
}

.byok-stats-toolbar-group {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
}

.byok-stats-toolbar .input.us {
    height: 34px;
    padding: 0 12px;
    font-size: 13px;
}

.byok-stats-toolbar .nav-btn {
    height: 34px;
}

/* ---------- Stats Grid ---------- */

.byok-stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 8px;
}

.byok-stat {
    display: flex;
    flex-direction: column;
    gap: 6px;
    padding: 14px 16px;
    border: 1px solid var(--border-color);
    border-radius: 12px;
    background: var(--background);
}

.byok-stat-label {
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--text-color-tertiary);
}

.byok-stat-value {
    font-size: 22px;
    font-weight: 600;
    line-height: 1.1;
    color: var(--text-color);
    letter-spacing: -0.02em;
}

/* ---------- Stats Tables ---------- */

.byok-stats-table-card {
    display: flex;
    flex-direction: column;
    gap: 10px;
    padding: 16px;
    border: 1px solid var(--border-color);
    border-radius: 12px;
    background: var(--background);
}

.byok-stats-table-title {
    margin: 0;
    font-size: 13px;
    font-weight: 600;
    color: var(--text-color);
    letter-spacing: -0.005em;
}

.byok-stats-table-wrap {
    overflow-x: auto;
}

.byok-stats-table {
    width: 100%;
    border-collapse: collapse;
    min-width: 360px;
}

.byok-stats-table th,
.byok-stats-table td {
    text-align: left;
    font-size: 12.5px;
    padding: 9px 10px;
    border-bottom: 1px solid var(--border-color);
}

.byok-stats-table th {
    font-weight: 600;
    color: var(--text-color-secondary);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    font-size: 11px;
}

.byok-stats-table tbody tr:last-child td {
    border-bottom: 0;
}

.byok-stats-empty-cell {
    color: var(--text-color-tertiary);
    font-style: italic;
}

/* ---------- Errors list ---------- */

.byok-error-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.byok-error-item {
    padding: 10px 12px;
    border: 1px solid var(--border-color);
    border-radius: 10px;
    background: var(--background);
}

.byok-error-head {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: 10px;
    margin-bottom: 4px;
}

.byok-error-model {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-color);
}

.byok-error-time {
    font-size: 11px;
    color: var(--text-color-tertiary);
    white-space: nowrap;
}

.byok-error-message {
    margin: 0;
    font-size: 12.5px;
    line-height: 1.45;
    color: var(--text-color-secondary);
    word-break: break-word;
}

/* ---------- Inline placeholder text ---------- */

.byok-placeholder {
    margin: 0;
    padding: 24px;
    text-align: center;
    font-size: 13px;
    color: var(--text-color-secondary);
    border: 1px dashed var(--border-color);
    border-radius: 12px;
}

/* ---------- Modal compatibility: keep mcp-modal-* shared styles ---------- */

.byok-setting-item {
    gap: 20px;
}

.byok-provider-url-suggestion {
    width: 100%;
}

.byok-control-wrap .input.us[multiple] {
    min-height: 120px;
}

.byok-remote-controls {
    flex-direction: column;
    align-items: stretch;
    gap: 8px;
}

.byok-remote-controls .input.us {
    flex: 1;
}

.byok-remote-status {
    margin: 0;
    font-size: 13px;
    color: var(--text-color-secondary);
}

/* ---------- Responsive ---------- */

@media (max-width: 720px) {
    .byok-shell {
        gap: 32px;
    }

    .byok-section-head {
        flex-direction: column;
        align-items: stretch;
        gap: 12px;
    }

    .byok-section-count {
        align-self: flex-start;
    }

    .byok-list-item {
        flex-wrap: wrap;
        gap: 12px;
    }

    .byok-item-actions {
        margin-left: auto;
    }

    .byok-tracking-card {
        flex-direction: column;
        align-items: stretch;
    }

    .byok-stats-toolbar {
        flex-direction: column;
        align-items: stretch;
    }

    .byok-stats-toolbar-group {
        justify-content: flex-start;
    }
}

/* ---------- Reduced motion ---------- */

@media (prefers-reduced-motion: reduce) {
    .byok-add-btn,
    .byok-icon-btn,
    .byok-list-item {
        transition: none;
    }
}

body.app-reduced-animations .byok-add-btn,
body.app-reduced-animations .byok-icon-btn,
body.app-reduced-animations .byok-list-item {
    transition: none;
}
