/* Tytan Cortex - Component Library */

/* ============================================
   BUTTONS
   ============================================ */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-2);
    padding: var(--space-2) var(--space-5);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    font-size: var(--font-size-sm);
    font-weight: var(--font-weight-medium);
    font-family: inherit;
    cursor: pointer;
    transition: all var(--transition-fast);
    background-color: var(--color-surface);
    color: var(--color-text-primary);
    text-decoration: none;
    white-space: nowrap;
}

.btn:hover {
    background-color: var(--color-surface-hover);
    border-color: var(--color-accent);
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    background-color: var(--color-border);
}

.btn-primary {
    background-color: var(--color-accent);
    color: white;
    border-color: var(--color-accent);
}

.btn-primary:hover {
    background-color: var(--color-accent-hover);
    border-color: var(--color-accent-hover);
}

.btn-primary:disabled {
    background-color: var(--color-border);
    border-color: var(--color-border);
}

.btn-secondary {
    background-color: var(--color-surface-hover);
    color: var(--color-text-primary);
    border-color: var(--color-border);
}

.btn-secondary:hover {
    background-color: var(--color-border);
}

.btn-icon {
    padding: 8px;
    width: 36px;
    height: 36px;
    border-radius: 6px;
}

.btn-sm {
    padding: 6px 12px;
    font-size: 0.75rem;
    border-radius: 6px;
}

.btn-danger {
    background-color: var(--error-color);
    color: white;
    border-color: var(--error-color);
}

.btn-danger:hover {
    background-color: #dc2626;
    border-color: #dc2626;
}

/* ============================================
   INPUTS
   ============================================ */

.input,
.textarea,
.select {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    font-size: var(--font-size-sm);
    font-family: inherit;
    color: var(--color-text-primary);
    background-color: var(--color-surface);
    transition: border-color var(--transition-fast);
}

.input:focus,
.textarea:focus,
.select:focus {
    outline: none;
    border-color: var(--color-accent);
    box-shadow: 0 0 0 3px var(--color-accent-light);
}

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

.textarea {
    min-height: 100px;
    resize: vertical;
}

.select {
    cursor: pointer;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%2364748b' d='M6 9L1 4h10z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    padding-right: 36px;
    appearance: none;
}

.input-group {
    display: flex;
    gap: 8px;
}

.input-group .input {
    flex: 1;
}

/* ============================================
   CARDS
   ============================================ */

.card {
    background-color: var(--surface-color);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    box-shadow: 0 1px 2px rgba(15, 23, 42, 0.05);
    overflow: hidden;
}

.card-header {
    padding: 16px 20px;
    border-bottom: 1px solid var(--border-color);
    font-weight: 600;
    font-size: 0.9375rem;
}

.card-body {
    padding: 20px;
}

.card-footer {
    padding: 12px 20px;
    border-top: 1px solid var(--border-color);
    background-color: var(--secondary-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.card-compact .card-header,
.card-compact .card-body,
.card-compact .card-footer {
    padding: 12px 16px;
}

/* ============================================
   BADGES
   ============================================ */

.badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 4px 10px;
    font-size: 0.6875rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.025em;
    border-radius: 6px;
    white-space: nowrap;
}

.badge-success {
    background-color: rgba(34, 197, 94, 0.1);
    color: #16a34a;
}

.badge-error {
    background-color: rgba(239, 68, 68, 0.1);
    color: #dc2626;
}

.badge-warning {
    background-color: rgba(245, 158, 11, 0.1);
    color: #d97706;
}

.badge-info {
    background-color: rgba(99, 102, 241, 0.1);
    color: var(--primary-color);
}

.badge-neutral {
    background-color: var(--secondary-color);
    color: var(--text-secondary);
}

/* Badge status variants */
.badge-uploading {
    background-color: rgba(99, 102, 241, 0.1);
    color: var(--primary-color);
    animation: pulse 2s cubic-bezier(0.4, 0, 0.6, 1) infinite;
}

.badge-parsing,
.badge-chunking,
.badge-embedding,
.badge-upserting {
    background-color: rgba(245, 158, 11, 0.1);
    color: #d97706;
    animation: pulse 2s cubic-bezier(0.4, 0, 0.6, 1) infinite;
}

.badge-complete {
    background-color: rgba(34, 197, 94, 0.1);
    color: #16a34a;
}

.badge-failed {
    background-color: rgba(239, 68, 68, 0.1);
    color: #dc2626;
}

@keyframes pulse {
    0%, 100% {
        opacity: 1;
    }
    50% {
        opacity: 0.6;
    }
}

/* ============================================
   MEMORY SCOPE CONTROL
   ============================================ */

.scope-control {
    display: inline-flex;
    align-items: center;
    gap: 4px;
}

.scope-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 20px;
    height: 20px;
    padding: 0;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    background: transparent;
    color: var(--text-secondary);
    font-size: 0.75rem;
    cursor: pointer;
    transition: background-color 0.15s, color 0.15s, border-color 0.15s;
    line-height: 1;
}

.scope-btn:hover {
    background-color: var(--secondary-color);
    color: var(--text-primary);
}

.scope-btn-promote:hover {
    border-color: #16a34a;
    color: #16a34a;
}

.scope-btn-demote:hover {
    border-color: #d97706;
    color: #d97706;
}

/* ============================================
   TOASTS
   ============================================ */

.toast-container {
    position: fixed;
    bottom: 24px;
    right: 24px;
    z-index: 9999;
    display: flex;
    flex-direction: column;
    gap: 12px;
    max-width: 420px;
    pointer-events: none;
}

.toast {
    pointer-events: auto;
    background-color: var(--surface-color);
    border: 1px solid var(--border-color);
    border-radius: 10px;
    padding: 16px 20px;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.1), 0 4px 6px rgba(0, 0, 0, 0.05);
    display: flex;
    align-items: flex-start;
    gap: 12px;
    min-width: 300px;
    animation: slideInRight 0.3s ease-out;
}

.toast.removing {
    animation: slideOutRight 0.3s ease-in;
}

.toast-icon {
    flex-shrink: 0;
    width: 20px;
    height: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.toast-content {
    flex: 1;
    min-width: 0;
}

.toast-title {
    font-weight: 600;
    font-size: 0.875rem;
    margin-bottom: 2px;
    color: var(--text-primary);
}

.toast-message {
    font-size: 0.8125rem;
    color: var(--text-secondary);
    line-height: 1.4;
}

.toast-close {
    flex-shrink: 0;
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 0;
    font-size: 1.25rem;
    line-height: 1;
    opacity: 0.6;
    transition: opacity 0.2s;
}

.toast-close:hover {
    opacity: 1;
}

.toast-success {
    border-left: 4px solid var(--success-color);
}

.toast-success .toast-icon {
    color: var(--success-color);
}

.toast-error {
    border-left: 4px solid var(--error-color);
}

.toast-error .toast-icon {
    color: var(--error-color);
}

.toast-info {
    border-left: 4px solid var(--primary-color);
}

.toast-info .toast-icon {
    color: var(--primary-color);
}

.toast-warning {
    border-left: 4px solid var(--warning-color);
}

.toast-warning .toast-icon {
    color: var(--warning-color);
}

@keyframes slideInRight {
    from {
        transform: translateX(100%);
        opacity: 0;
    }
    to {
        transform: translateX(0);
        opacity: 1;
    }
}

@keyframes slideOutRight {
    from {
        transform: translateX(0);
        opacity: 1;
    }
    to {
        transform: translateX(100%);
        opacity: 0;
    }
}

/* ============================================
   LOADERS & PROGRESS
   ============================================ */

.loader {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    color: var(--text-secondary);
    font-size: 0.875rem;
}

.loader-spinner {
    width: 20px;
    height: 20px;
    border: 2px solid var(--border-color);
    border-top-color: var(--primary-color);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

.loader-spinner.sm {
    width: 16px;
    height: 16px;
    border-width: 2px;
}

.loader-spinner.lg {
    width: 32px;
    height: 32px;
    border-width: 3px;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

.loader-dots {
    display: inline-flex;
    gap: 4px;
}

.loader-dots span {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background-color: var(--primary-color);
    animation: bounce 1.4s infinite ease-in-out both;
}

.loader-dots span:nth-child(1) {
    animation-delay: -0.32s;
}

.loader-dots span:nth-child(2) {
    animation-delay: -0.16s;
}

.loader-bar {
    width: 100%;
    height: 4px;
    background-color: var(--secondary-color);
    border-radius: 2px;
    overflow: hidden;
    position: relative;
}

.loader-bar::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    height: 100%;
    width: 40%;
    background-color: var(--primary-color);
    animation: loading 1.5s ease-in-out infinite;
}

@keyframes loading {
    0% {
        left: -40%;
    }
    100% {
        left: 100%;
    }
}

.progress-bar {
    width: 100%;
    height: 8px;
    background-color: var(--secondary-color);
    border-radius: 4px;
    overflow: hidden;
}

.progress-bar-fill {
    height: 100%;
    background-color: var(--primary-color);
    border-radius: 4px;
    transition: width 0.3s ease;
    position: relative;
    overflow: hidden;
}

.progress-bar-fill::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    bottom: 0;
    right: 0;
    background-image: linear-gradient(
        45deg,
        rgba(255, 255, 255, 0.2) 25%,
        transparent 25%,
        transparent 50%,
        rgba(255, 255, 255, 0.2) 50%,
        rgba(255, 255, 255, 0.2) 75%,
        transparent 75%,
        transparent
    );
    background-size: 20px 20px;
    animation: progress-stripes 1s linear infinite;
}

@keyframes progress-stripes {
    0% {
        background-position: 0 0;
    }
    100% {
        background-position: 20px 20px;
    }
}

/* ============================================
   MODALS
   ============================================ */

.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    padding: 20px;
    animation: fadeIn 0.2s ease-out;
}

@keyframes fadeIn {
    from {
        opacity: 0;
    }
    to {
        opacity: 1;
    }
}

.modal-content {
    background-color: var(--surface-color);
    border-radius: 16px;
    width: 100%;
    max-width: 520px;
    max-height: 90vh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
    animation: modalSlideIn 0.3s ease-out;
}

@keyframes modalSlideIn {
    from {
        transform: translateY(-20px);
        opacity: 0;
    }
    to {
        transform: translateY(0);
        opacity: 1;
    }
}

.modal-header {
    padding: 20px 24px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.modal-title {
    font-size: 1.125rem;
    font-weight: 600;
    color: var(--text-primary);
}

.modal-close {
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    font-size: 1.5rem;
    line-height: 1;
    padding: 4px;
    transition: color 0.2s;
}

.modal-close:hover {
    color: var(--text-primary);
}

.modal-body {
    padding: 24px;
    overflow-y: auto;
    flex: 1;
}

.modal-footer {
    padding: 16px 24px;
    border-top: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 12px;
}

/* Modal sizes */
.modal-content.modal-sm {
    max-width: 400px;
}

.modal-content.modal-lg {
    max-width: 720px;
}

.modal-content.modal-xl {
    max-width: 960px;
}

/* ============================================
   DRAWERS
   ============================================ */

.drawer-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(4px);
    z-index: 1000;
    animation: fadeIn 0.2s ease-out;
}

.drawer {
    position: fixed;
    top: 0;
    bottom: 0;
    background-color: var(--surface-color);
    box-shadow: -4px 0 12px rgba(0, 0, 0, 0.1);
    z-index: 1001;
    display: flex;
    flex-direction: column;
    width: 100%;
    max-width: 480px;
}

.drawer.drawer-right {
    right: 0;
    animation: slideInFromRight 0.3s ease-out;
}

.drawer.drawer-left {
    left: 0;
    animation: slideInFromLeft 0.3s ease-out;
}

@keyframes slideInFromRight {
    from {
        transform: translateX(100%);
    }
    to {
        transform: translateX(0);
    }
}

@keyframes slideInFromLeft {
    from {
        transform: translateX(-100%);
    }
    to {
        transform: translateX(0);
    }
}

.drawer-header {
    padding: 20px 24px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.drawer-title {
    font-size: 1.125rem;
    font-weight: 600;
    color: var(--text-primary);
}

.drawer-close {
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    font-size: 1.5rem;
    line-height: 1;
    padding: 4px;
    transition: color 0.2s;
}

.drawer-close:hover {
    color: var(--text-primary);
}

.drawer-body {
    padding: 24px;
    overflow-y: auto;
    flex: 1;
}

.drawer-footer {
    padding: 16px 24px;
    border-top: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 12px;
}

/* ============================================
   FORM ELEMENTS
   ============================================ */

.form-group {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-bottom: 16px;
}

.form-label {
    display: block;
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--text-primary);
    margin-bottom: 6px;
}

.form-input {
    width: 100%;
    padding: 10px 12px;
    font-size: 0.9375rem;
    font-family: inherit;
    color: var(--text-primary);
    background-color: var(--surface-color);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    transition: all 0.2s ease;
}

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

.form-input:hover {
    border-color: var(--border-secondary);
}

.form-input:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.1);
}

.form-input:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

.form-label-optional {
    color: var(--text-secondary);
    font-weight: 400;
}

.form-hint {
    font-size: 0.75rem;
    color: var(--text-secondary);
    margin-top: 4px;
}

.form-error {
    font-size: 0.75rem;
    color: var(--error-color);
    margin-top: 4px;
}

.checkbox,
.checkbox-label {
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
}

.checkbox input[type="checkbox"],
.checkbox-label input[type="checkbox"] {
    width: 18px;
    height: 18px;
    cursor: pointer;
    accent-color: var(--primary-color);
}

.radio {
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
}

.radio input[type="radio"] {
    width: 18px;
    height: 18px;
    cursor: pointer;
    accent-color: var(--primary-color);
}

/* ============================================
   DIVIDER
   ============================================ */

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

.divider-vertical {
    width: 1px;
    height: 100%;
    background-color: var(--border-color);
}

/* ============================================
   STATUS INDICATOR
   ============================================ */

.status-indicator {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 0.8125rem;
}

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    flex-shrink: 0;
}

.status-dot.healthy {
    background-color: var(--success-color);
    box-shadow: 0 0 0 2px rgba(34, 197, 94, 0.2);
}

.status-dot.unhealthy {
    background-color: var(--error-color);
    box-shadow: 0 0 0 2px rgba(239, 68, 68, 0.2);
}

.status-dot.warning {
    background-color: var(--warning-color);
    box-shadow: 0 0 0 2px rgba(245, 158, 11, 0.2);
}

.status-dot.pulsing {
    animation: pulse 2s cubic-bezier(0.4, 0, 0.6, 1) infinite;
}

/* ============================================
   TAG / CHIP
   ============================================ */

.tag {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 4px 10px;
    background-color: var(--secondary-color);
    border-radius: 6px;
    font-size: 0.75rem;
    color: var(--text-primary);
}

.tag-removable {
    padding-right: 4px;
}

.tag-remove {
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 2px 4px;
    font-size: 1rem;
    line-height: 1;
    transition: color 0.2s;
}

.tag-remove:hover {
    color: var(--error-color);
}

/* ============================================
   RESPONSIVE HELPERS
   ============================================ */

@media (max-width: 768px) {
    .modal-content {
        max-width: 100%;
        max-height: 100vh;
        border-radius: 0;
    }

    .drawer {
        max-width: 100%;
    }

    .toast-container {
        left: 12px;
        right: 12px;
        bottom: 12px;
    }

    .toast {
        min-width: 0;
        width: 100%;
    }
}

/* ============================================
   UTILITY CLASSES
   ============================================ */

.hidden {
    display: none !important;
}

.flex {
    display: flex;
}

.flex-col {
    flex-direction: column;
}

.items-center {
    align-items: center;
}

.justify-between {
    justify-content: space-between;
}

.gap-2 {
    gap: 8px;
}

.gap-3 {
    gap: 12px;
}

.gap-4 {
    gap: 16px;
}

.mt-2 {
    margin-top: 8px;
}

.mt-3 {
    margin-top: 12px;
}

.mt-4 {
    margin-top: 16px;
}

.mb-2 {
    margin-bottom: 8px;
}

.mb-3 {
    margin-bottom: 12px;
}

.mb-4 {
    margin-bottom: 16px;
}

.text-sm {
    font-size: 0.875rem;
}

.text-xs {
    font-size: 0.75rem;
}

.font-medium {
    font-weight: 500;
}

.font-semibold {
    font-weight: 600;
}

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

.w-full {
    width: 100%;
}
