/* ==========================================================================
   SETUP HOMEPAGE V2 — Model Management
   Supplement to kb_document_v2.css design system
   ========================================================================== */

/* ---------- Sidebar nav items with icons ---------- */
.v2-sidebar-item.has-icon {
    gap: 12px;
}

.v2-sidebar-item.has-icon svg {
    width: 18px;
    height: 18px;
    flex-shrink: 0;
}

/* ---------- Title row override ---------- */
.v2-title-row-setup {
    align-items: flex-start;
}

.v2-subtitle {
    font-size: 13px;
    font-weight: 500;
    color: var(--color-gray-500);
    margin-top: 4px;
}

/* ---------- Models list container ---------- */
.v2-models-list {
    flex: 1;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 12px;
    min-height: 0;
    padding-bottom: 24px;
    scrollbar-width: none;
    -ms-overflow-style: none;
}

.v2-models-list::-webkit-scrollbar {
    display: none;
}

/* ---------- Model card ---------- */
.v2-model-card {
    display: flex;
    gap: 16px;
    background: var(--color-white);
    border: 1px solid var(--color-gray-200);
    border-radius: var(--radius-md);
    padding: 20px 24px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.06);
    transition: box-shadow 0.2s ease, border-color 0.2s ease;
    position: relative;
}

.v2-model-card:hover {
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.10);
    border-color: var(--color-gray-300);
}

/* ---------- Card number badge ---------- */
.v2-card-number {
    width: 32px;
    height: 32px;
    min-width: 32px;
    background: #F0F4FF;
    color: var(--color-blue-600);
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 14px;
    flex-shrink: 0;
    align-self: flex-start;
}

/* ---------- Card body ---------- */
.v2-card-body {
    flex: 1;
    min-width: 0;
    position: relative;
}

/* ---------- Card actions ---------- */
.v2-card-actions {
    position: absolute;
    top: 0;
    right: 0;
    display: flex;
    gap: 4px;
    opacity: 0;
    transition: opacity 0.15s ease;
}

.v2-model-card:hover .v2-card-actions {
    opacity: 1;
}

/* ---------- Card metadata grid ---------- */
.v2-card-meta {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.v2-meta-row {
    display: flex;
    align-items: baseline;
    gap: 16px;
}

.v2-meta-label {
    width: 100px;
    min-width: 100px;
    font-size: 13px;
    font-weight: 600;
    color: var(--color-gray-700);
    flex-shrink: 0;
}

.v2-meta-value {
    font-size: 13px;
    font-weight: 400;
    color: var(--color-gray-900);
    min-width: 0;
}

.v2-meta-value-bold {
    font-weight: 600;
}

.v2-meta-desc {
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    text-overflow: ellipsis;
    line-height: 1.5;
}

/* ---------- Mode badge ---------- */
.v2-mode-badge {
    display: inline-block;
    padding: 2px 10px;
    border-radius: var(--radius-full);
    font-size: 12px;
    font-weight: 600;
    line-height: 1.5;
}

.v2-mode-badge.active {
    background: #DCFCE7;
    color: #16A34A;
}

.v2-mode-badge.inactive {
    background: var(--color-red-50);
    color: var(--color-red-600);
}

/* ---------- Default badge ---------- */
.v2-default-yes {
    color: var(--color-green-600);
    font-weight: 500;
}

.v2-default-no {
    color: var(--color-gray-400);
}

/* ---------- Model form modal ---------- */
.v2-model-form-modal {
    max-width: 680px;
}

.v2-form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
}

.v2-form-group {
    margin-bottom: 16px;
}

.v2-form-label {
    display: block;
    font-size: 13px;
    font-weight: 600;
    color: var(--color-gray-700);
    margin-bottom: 6px;
}

.v2-form-label.v2-required::after {
    content: ' *';
    color: var(--color-red-500);
}

.v2-form-input,
.v2-form-select,
.v2-form-textarea {
    width: 100%;
    padding: 8px 12px;
    border: 1px solid var(--color-gray-200);
    border-radius: var(--radius-sm);
    font-size: 14px;
    font-family: var(--font-sans);
    color: var(--color-gray-900);
    background: var(--color-white);
    transition: var(--transition);
    outline: none;
}

.v2-form-input:focus,
.v2-form-select:focus,
.v2-form-textarea:focus {
    border-color: var(--color-blue-500);
    box-shadow: 0 0 0 3px rgba(29, 114, 242, 0.1);
}

.v2-form-input:disabled,
.v2-form-select:disabled,
.v2-form-textarea:disabled {
    background: var(--color-gray-50);
    color: var(--color-gray-500);
    cursor: not-allowed;
}

.v2-form-input::placeholder,
.v2-form-textarea::placeholder {
    color: var(--color-gray-400);
}

.v2-form-textarea {
    resize: vertical;
    min-height: 60px;
}

.v2-form-select {
    cursor: pointer;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%239CA3AF' stroke-width='2'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    padding-right: 32px;
}

/* ---------- Custom Select (replace native <select> in modals) ---------- */
.v2-custom-select {
    position: relative;
    width: 100%;
}

.v2-custom-select-trigger {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    padding: 8px 12px;
    border: 1px solid var(--color-gray-200);
    border-radius: var(--radius-sm);
    font-size: 14px;
    font-family: var(--font-sans);
    color: var(--color-gray-900);
    background: var(--color-white);
    cursor: pointer;
    transition: var(--transition);
    text-align: left;
}

.v2-custom-select-trigger:hover {
    border-color: var(--color-gray-300);
}

.v2-custom-select-trigger:focus {
    outline: none;
    border-color: var(--color-blue-500);
    box-shadow: 0 0 0 3px rgba(29, 114, 242, 0.1);
}

.v2-custom-select-trigger:disabled {
    background: var(--color-gray-50);
    color: var(--color-gray-500);
    cursor: not-allowed;
}

.v2-custom-select-text {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.v2-custom-select-text.placeholder {
    color: var(--color-gray-400);
}

.v2-custom-select-arrow {
    flex-shrink: 0;
    color: var(--color-gray-400);
    transition: transform 0.2s ease;
}

.v2-custom-select.open .v2-custom-select-arrow {
    transform: rotate(180deg);
}

.v2-custom-select-options {
    display: none;
    position: absolute;
    top: calc(100% + 4px);
    left: 0;
    right: 0;
    z-index: 100;
    background: var(--color-white);
    border: 1px solid var(--color-gray-200);
    border-radius: var(--radius-sm);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.12);
    list-style: none;
    margin: 0;
    padding: 4px 0;
    max-height: 200px;
    overflow-y: auto;
}

.v2-custom-select.open .v2-custom-select-options {
    display: block;
}

.v2-custom-select-option {
    padding: 8px 12px;
    font-size: 14px;
    color: var(--color-gray-700);
    cursor: pointer;
    transition: background 0.1s ease;
}

.v2-custom-select-option:hover {
    background: var(--color-gray-50);
}

.v2-custom-select-option.selected {
    color: var(--color-primary);
    font-weight: 500;
    background: var(--color-blue-50, #EFF6FF);
}

/* ---------- API key row ---------- */
.v2-api-key-row {
    display: flex;
    gap: 8px;
}

.v2-api-key-row .v2-form-input {
    flex: 1;
}

.v2-api-key-row .v2-btn-outline {
    flex-shrink: 0;
    padding: 8px 16px;
    font-size: 13px;
}

/* ---------- Radio group ---------- */
.v2-radio-group {
    display: flex;
    gap: 16px;
    padding-top: 4px;
}

.v2-radio-option {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 14px;
    color: var(--color-gray-700);
    cursor: pointer;
}

.v2-radio-option input[type="radio"] {
    accent-color: var(--color-primary);
    cursor: pointer;
}

/* ---------- Checkbox ---------- */
.v2-checkbox-label {
    display: flex;
    align-items: flex-start;
    gap: 8px;
    font-size: 13px;
    color: var(--color-gray-600);
    cursor: pointer;
    line-height: 1.5;
}

.v2-form-checkbox {
    margin-top: 3px;
    accent-color: var(--color-primary);
    cursor: pointer;
}

/* ---------- Required note ---------- */
.v2-required-note {
    font-size: 12px;
    color: var(--color-gray-400);
    margin-top: 8px;
    font-style: italic;
}

/* ---------- Skeleton loading ---------- */
.v2-skeleton-card {
    display: flex;
    gap: 16px;
    background: var(--color-white);
    border: 1px solid var(--color-gray-200);
    border-radius: var(--radius-md);
    padding: 20px 24px;
}

.v2-skeleton-number {
    width: 32px;
    height: 32px;
    border-radius: var(--radius-sm);
    background: var(--color-gray-100);
    animation: v2-shimmer-bg 1.5s infinite;
}

.v2-skeleton-body {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.v2-skeleton-line {
    height: 14px;
    border-radius: 4px;
    background: var(--color-gray-100);
    animation: v2-shimmer-bg 1.5s infinite;
}

.v2-skeleton-line.short { width: 40%; }
.v2-skeleton-line.medium { width: 65%; }
.v2-skeleton-line.long { width: 85%; }

@keyframes v2-shimmer-bg {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.4; }
}

/* ---------- Empty state override ---------- */
.v2-models-list .v2-empty-state {
    padding: 80px 20px;
    border: 1px solid var(--color-gray-200);
    border-radius: var(--radius-md);
    background: var(--color-white);
}

/* ---------- Form section divider ---------- */
.v2-form-section-divider {
    display: flex;
    align-items: center;
    gap: 12px;
    margin: 20px 0 16px;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 1.5px;
    color: var(--color-gray-400);
}

.v2-form-section-divider::before,
.v2-form-section-divider::after {
    content: '';
    flex: 1;
    height: 1px;
    background: var(--color-gray-200);
}

/* ---------- File link in cards ---------- */
.v2-file-link {
    color: var(--color-blue-500);
    text-decoration: none;
    font-size: 13px;
}

.v2-file-link:hover {
    text-decoration: underline;
    color: var(--color-blue-700);
}

/* ---------- Confirm modal override ---------- */
.v2-confirm-modal .v2-modal-title {
    color: var(--color-red-600);
}

/* ==========================================================================
   SETUP KNOWLEDGE V2 — Config blocks
   ========================================================================== */

.v2-config-blocks {
    display: flex;
    flex-direction: column;
    gap: 16px;
    padding-bottom: 24px;
}

.v2-config-card {
    background: var(--color-white);
    border: 1px solid var(--color-gray-200);
    border-radius: var(--radius-md);
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.06);
    transition: box-shadow 0.2s ease, border-color 0.2s ease;
    overflow: hidden;
}

.v2-config-card:hover {
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.10);
    border-color: var(--color-gray-300);
}

.v2-config-card-header {
    display: flex;
    align-items: flex-start;
    gap: 16px;
    padding: 20px 24px 0;
}

.v2-config-card-icon {
    width: 40px;
    height: 40px;
    min-width: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #F0F4FF;
    border-radius: var(--radius-sm);
    color: var(--color-blue-600);
    flex-shrink: 0;
}

.v2-config-card-title {
    font-size: 15px;
    font-weight: 600;
    color: var(--color-gray-900);
    margin: 0 0 4px;
}

.v2-config-card-desc {
    font-size: 13px;
    color: var(--color-gray-500);
    margin: 0;
    line-height: 1.4;
}

.v2-config-card-body {
    padding: 16px 24px 20px;
}

.v2-config-path-row {
    display: flex;
    align-items: center;
    gap: 12px;
}

.v2-path-input {
    flex: 1;
    cursor: default;
}

.v2-path-input.v2-path-valid {
    border-color: #22C55E;
    background: #F0FDF4;
}

/* ---------- API key input wrapper ---------- */
.v2-apikey-input-wrapper {
    position: relative;
    flex: 1;
}

.v2-apikey-input-wrapper .v2-form-input {
    padding-right: 40px;
}

.v2-apikey-toggle {
    position: absolute;
    right: 8px;
    top: 50%;
    transform: translateY(-50%);
    background: none;
    border: none;
    color: var(--color-gray-400);
    cursor: pointer;
    padding: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: color 0.15s ease;
}

.v2-apikey-toggle:hover {
    color: var(--color-gray-700);
}

/* ---------- Directory picker modal ---------- */
.v2-dir-current-path {
    padding: 10px 14px;
    background: var(--color-gray-50);
    border: 1px solid var(--color-gray-200);
    border-radius: var(--radius-sm);
    font-size: 13px;
    font-weight: 500;
    color: var(--color-gray-700);
    font-family: 'Courier New', monospace;
    margin-bottom: 12px;
    word-break: break-all;
}

.v2-dir-list {
    max-height: 320px;
    overflow-y: auto;
    border: 1px solid var(--color-gray-200);
    border-radius: var(--radius-sm);
    scrollbar-width: thin;
}

.v2-dir-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 14px;
    font-size: 14px;
    color: var(--color-gray-700);
    cursor: pointer;
    border-bottom: 1px solid var(--color-gray-100);
    transition: background 0.15s ease;
}

.v2-dir-item:last-child {
    border-bottom: none;
}

.v2-dir-item:hover {
    background: var(--color-gray-50);
}

.v2-dir-item svg {
    color: #F59E0B;
    flex-shrink: 0;
}

.v2-dir-parent {
    font-weight: 500;
    color: var(--color-gray-500);
}

.v2-dir-parent svg {
    color: var(--color-gray-400);
}
