/* 
 * Onlyus AI Enterprise Design System 
 * Theme: "Slate & Blue" Professional Console
 */

:root {
    /* Colors - Slate (Neutral) */
    --slate-50: #f8fafc;
    --slate-100: #f1f5f9;
    --slate-200: #e2e8f0;
    --slate-300: #cbd5e1;
    --slate-400: #94a3b8;
    --slate-500: #64748b;
    --slate-600: #475569;
    --slate-700: #334155;
    --slate-800: #1e293b;
    --slate-900: #0f172a;

    /* Colors - Primary (Brand Blue) */
    --primary-50: #eff6ff;
    --primary-100: #dbeafe;
    --primary-500: #3b82f6;
    --primary-600: #2563eb;
    --primary-700: #1d4ed8;

    /* Colors - Status */
    --danger-bg: #fef2f2;
    --danger-text: #b91c1c;
    --success-bg: #f0fdf4;
    --success-text: #15803d;
    --warning-bg: #fffbeb;
    --warning-text: #b45309;

    /* Application Variables */
    --bg-body: var(--slate-100);
    --bg-surface: #ffffff;
    --text-primary: var(--slate-900);
    --text-secondary: var(--slate-500);
    --border-color: var(--slate-200);

    --topbar-height: 60px;
}

/* Reset & Base */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    color: var(--text-primary);
    background-color: var(--bg-body);
    font-size: 14px;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

a {
    text-decoration: none;
    color: inherit;
    transition: color 0.2s;
}

/* Layout */
.app-layout {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

.topbar {
    height: var(--topbar-height);
    background: var(--slate-900);
    color: white;
    position: sticky;
    top: 0;
    z-index: 1000;
}

.topbar-inner {
    max-width: 1400px;
    margin: 0 auto;
    height: 100%;
    display: flex;
    align-items: center;
    padding: 0 24px;
    gap: 32px;
}

.brand {
    display: flex;
    align-items: center;
    gap: 12px;
    font-weight: 600;
    font-size: 16px;
    letter-spacing: -0.02em;
}

.logo-icon {
    width: 24px;
    height: 24px;
    background: var(--primary-500);
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 800;
    font-size: 14px;
    color: white;
}

.main-nav {
    display: flex;
    gap: 4px;
}

.nav-item {
    padding: 8px 16px;
    color: var(--slate-400);
    font-weight: 500;
    border-radius: 6px;
    transition: all 0.2s;
    font-size: 13px;
}

.nav-item:hover {
    color: white;
    background: rgba(255, 255, 255, 0.1);
}

.nav-item.active {
    color: white;
    background: var(--slate-800);
}

/* User Menu & Dropdown */
.user-menu {
    margin-left: auto;
    position: relative;
    cursor: pointer;
}

.user-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: var(--primary-100);
    color: var(--primary-700);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    font-weight: 600;
    border: 1px solid var(--primary-200);
    transition: all 0.2s;
}

.user-menu:hover .user-avatar {
    border-color: var(--primary-500);
    background: var(--primary-50);
}

.user-dropdown {
    position: absolute;
    top: 100%;
    right: 0;
    margin-top: 8px;
    background: white;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    min-width: 160px;
    display: none;
    z-index: 1000;
    padding: 4px 0;
}

.user-menu.active .user-dropdown {
    display: block;
}

.dropdown-item {
    display: block;
    padding: 8px 16px;
    font-size: 13px;
    color: var(--slate-700);
    text-decoration: none;
    transition: background 0.2s;
}

.dropdown-item:hover {
    background: var(--slate-50);
    color: var(--slate-900);
}

.dropdown-item.danger {
    color: var(--danger-text);
}

.dropdown-item.danger:hover {
    background: var(--danger-bg);
}

.main-content {
    flex: 1;
    padding: 32px 0;
}

.content-container {
    max-width: 1400px;
    margin: 0 auto;
    padding: 0 24px;
}

.app-footer {
    padding: 24px;
    background: var(--bg-surface);
    border-top: 1px solid var(--border-color);
}

.footer-inner {
    max-width: 1400px;
    margin: 0 auto;
    text-align: center;
    color: var(--text-secondary);
    font-size: 12px;
}

/* UI Components */

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 0 16px;
    height: 36px;
    border-radius: 6px;
    font-weight: 500;
    font-size: 13px;
    cursor: pointer;
    transition: all 0.2s;
    border: 1px solid transparent;
}

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

.btn-primary:hover {
    background: var(--primary-700);
}

.btn-secondary {
    background: white;
    border-color: var(--slate-300);
    color: var(--slate-700);
}

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

.btn-danger {
    background: var(--danger-bg);
    color: var(--danger-text);
    border: 1px solid transparent;
}

.btn-danger:hover {
    background: #fee2e2;
}

.btn-icon {
    width: 32px;
    height: 32px;
    padding: 0;
    border-radius: 6px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: 1px solid var(--border-color);
    background: white;
    color: var(--slate-600);
    cursor: pointer;
    transition: all 0.2s;
}

.btn-icon:hover {
    background: var(--slate-50);
    color: var(--slate-900);
}

.btn-icon.danger:hover {
    background: var(--danger-bg);
    color: var(--danger-text);
    border-color: #fca5a5;
}

/* Cards */
.card {
    background: var(--bg-surface);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
}

/* Forms */
.form-input,
.form-select {
    display: block;
    width: 100%;
    height: 36px;
    padding: 0 12px;
    font-size: 13px;
    line-height: 1.5;
    color: var(--text-primary);
    background-color: var(--bg-surface);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    transition: border-color 0.2s, box-shadow 0.2s;
}

.form-input:focus,
.form-select:focus {
    outline: none;
    border-color: var(--primary-500);
    box-shadow: 0 0 0 2px var(--primary-100);
}

/* Search Box (Reusable) */
.search-wrapper {
    position: relative;
}

.search-wrapper input {
    padding-left: 36px;
}

.search-wrapper::before {
    content: "🔍";
    position: absolute;
    left: 12px;
    top: 50%;
    transform: translateY(-50%);
    font-size: 14px;
    opacity: 0.5;
}

/* Data Tables (Professional) */
.data-table-wrapper {
    background: var(--bg-surface);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    overflow: hidden;
}

.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}

.data-table th {
    background: var(--slate-50);
    padding: 12px 16px;
    text-align: left;
    font-weight: 600;
    color: var(--slate-600);
    border-bottom: 1px solid var(--border-color);
    white-space: nowrap;
    text-transform: uppercase;
    font-size: 11px;
    letter-spacing: 0.05em;
}

.data-table td {
    padding: 12px 16px;
    border-bottom: 1px solid var(--border-color);
    vertical-align: middle;
    color: var(--slate-700);
}

.data-table tbody tr:last-child td {
    border-bottom: none;
}

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

/* Badges */
.badge {
    display: inline-flex;
    align-items: center;
    padding: 2px 8px;
    border-radius: 9999px;
    font-size: 11px;
    font-weight: 600;
    line-height: 1.4;
}

.badge.success {
    background: var(--success-bg);
    color: var(--success-text);
}

.badge.warning {
    background: var(--warning-bg);
    color: var(--warning-text);
}

.badge.danger {
    background: var(--danger-bg);
    color: var(--danger-text);
}

.badge.neutral {
    background: var(--slate-100);
    color: var(--slate-600);
}

/* Components: Page Header */
.page-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 24px;
}

.page-title {
    font-size: 20px;
    font-weight: 600;
    color: var(--slate-900);
}

/* Utilities */
.flex-row {
    display: flex;
    gap: 12px;
    align-items: center;
}

.flex-wrap {
    flex-wrap: wrap;
}

.ml-auto {
    margin-left: auto;
}

.text-mono {
    font-family: 'SF Mono', 'Roboto Mono', Menlo, monospace;
}

.text-sm {
    font-size: 12px;
}

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

/* Toast */
.toast {
    position: fixed;
    bottom: 24px;
    right: 24px;
    padding: 12px 20px;
    background: var(--slate-900);
    color: white;
    border-radius: 6px;
    font-weight: 500;
    font-size: 13px;
    box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
    z-index: 2000;
    animation: slideIn 0.3s ease;
}

.toast.error {
    background: #b91c1c;
}

.toast.success {
    background: #15803d;
}

@keyframes slideIn {
    from {
        transform: translateY(100%);
        opacity: 0;
    }

    to {
        transform: translateY(0);
        opacity: 1;
    }
}

/* Admin Dashboard Specifics moved to global for consistency */
.stat-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 16px;
    margin-bottom: 24px;
}

.stat-card {
    background: white;
    padding: 20px;
    border-radius: 8px;
    border: 1px solid var(--border-color);
}

.stat-card .label {
    font-size: 12px;
    color: var(--slate-500);
    font-weight: 600;
    text-transform: uppercase;
    margin-bottom: 8px;
    letter-spacing: 0.02em;
}

.stat-card .value {
    font-size: 24px;
    font-weight: 600;
    color: var(--slate-900);
    font-feature-settings: "tnum";
}

/* Pagination */
.pagination {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px;
    border-top: 1px solid var(--border-color);
}

.pagination-controls {
    display: flex;
    gap: 4px;
}

.page-btn {
    min-width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 6px;
    font-size: 13px;
    color: var(--slate-600);
    cursor: pointer;
    border: 1px solid transparent;
}

.page-btn:hover {
    background: var(--slate-50);
}

.page-btn.active {
    background: var(--primary-50);
    color: var(--primary-600);
    border-color: var(--primary-100);
    font-weight: 600;
}

/* 
 * Search Page Specifics 
 * Migrated from index.html and refactored
 */

.search-page {
    padding-top: 16px;
}

.search-container {
    display: grid;
    grid-template-columns: 320px 1fr;
    gap: 24px;
    align-items: start;
}

/* Left Panel */
.search-panel {
    background: var(--bg-surface);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    position: sticky;
    top: calc(var(--topbar-height) + 24px);
}

.search-tabs {
    display: flex;
    border-bottom: 1px solid var(--border-color);
}

.search-tab {
    flex: 1;
    padding: 12px;
    background: none;
    border: none;
    cursor: pointer;
    font-size: 13px;
    font-weight: 500;
    color: var(--text-secondary);
    transition: all 0.2s;
    text-align: center;
}

.search-tab:hover {
    color: var(--primary-600);
    background: var(--slate-50);
}

.search-tab.active {
    color: var(--primary-600);
    position: relative;
    font-weight: 600;
}

.search-tab.active::after {
    content: '';
    position: absolute;
    bottom: -1px;
    left: 0;
    right: 0;
    height: 2px;
    background: var(--primary-600);
}

.search-form {
    padding: 20px;
}

.form-section {
    margin-bottom: 20px;
}

.form-label {
    display: block;
    font-size: 12px;
    font-weight: 600;
    color: var(--slate-700);
    margin-bottom: 6px;
    text-transform: uppercase;
    letter-spacing: 0.02em;
}

/* Image Upload */
.image-upload-container {
    border: 2px dashed var(--border-color);
    border-radius: 6px;
    padding: 24px;
    text-align: center;
    cursor: pointer;
    transition: all 0.2s;
    background: var(--slate-50);
}

.image-upload-container:hover,
.image-upload-container.drag-over {
    border-color: var(--primary-500);
    background: var(--primary-50);
}

.image-upload-container.has-image {
    padding: 12px;
    background: white;
    border-style: solid;
}

.upload-icon-large {
    font-size: 24px;
    margin-bottom: 8px;
    opacity: 0.5;
}

.upload-text {
    font-size: 13px;
    color: var(--slate-600);
    font-weight: 500;
}

.upload-hint {
    font-size: 11px;
    color: var(--slate-400);
    margin-top: 4px;
}

.preview-container {
    position: relative;
    display: inline-block;
}

.preview-image {
    max-width: 100%;
    max-height: 180px;
    border-radius: 4px;
    display: block;
}

.remove-preview {
    position: absolute;
    top: -8px;
    right: -8px;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: var(--danger-text);
    color: white;
    border: 2px solid white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

/* Search Tips */
.search-tips {
    margin-top: 20px;
    padding: 12px;
    background: var(--slate-50);
    border-radius: 6px;
    border: 1px solid var(--border-color);
}

.search-tips-title {
    font-size: 11px;
    font-weight: 700;
    color: var(--slate-600);
    margin-bottom: 8px;
    text-transform: uppercase;
}

.search-tips ul {
    margin: 0;
    padding-left: 16px;
    font-size: 12px;
    color: var(--slate-500);
}

.search-tips li {
    margin-bottom: 4px;
}

/* Results Panel */
.results-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
    padding-bottom: 16px;
    border-bottom: 1px solid var(--border-color);
}

.results-count {
    font-size: 13px;
    font-weight: 600;
    color: var(--slate-500);
}

.results-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 16px;
}

.results-grid.list-view {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

/* Result Card */
.result-card {
    background: var(--bg-surface);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    overflow: hidden;
    transition: all 0.2s;
    cursor: pointer;
}

.result-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
    border-color: var(--primary-200);
}

.result-card-image {
    width: 100%;
    height: 160px;
    object-fit: cover;
    background: var(--slate-100);
    border-bottom: 1px solid var(--border-color);
}

.result-card-body {
    padding: 12px;
}

.result-card-name {
    font-size: 13px;
    font-weight: 600;
    color: var(--slate-900);
    margin-bottom: 8px;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    height: 36px;
}

.result-card-meta {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 11px;
}

.result-card-id {
    font-family: monospace;
    color: var(--slate-400);
}

/* List View Overrides */
.results-grid.list-view .result-card {
    display: flex;
    align-items: center;
    height: 80px;
}

.results-grid.list-view .result-card-image {
    width: 80px;
    height: 100%;
    border-bottom: none;
    border-right: 1px solid var(--border-color);
}

.results-grid.list-view .result-card-body {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 16px;
}

.results-grid.list-view .result-card-name {
    margin-bottom: 0;
    height: auto;
    -webkit-line-clamp: 1;
    width: 50%;
}

/* Responsive */
@media (max-width: 1024px) {
    .search-container {
        grid-template-columns: 1fr;
    }

    .search-panel {
        position: static;
        margin-bottom: 24px;
    }
}

/* Modal */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 2000;
    opacity: 1;
    /* For simple display:none toggle */
    transition: opacity 0.2s;
}

.modal-content {
    background: white;
    padding: 24px;
    border-radius: 12px;
    width: 100%;
    max-width: 500px;
    box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
    position: relative;
    border: 1px solid var(--border-color);
}

.modal-close {
    position: absolute;
    top: 16px;
    right: 16px;
    font-size: 24px;
    color: var(--slate-400);
    cursor: pointer;
    line-height: 1;
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
    transition: all 0.2s;
}

.modal-close:hover {
    color: var(--slate-700);
    background: var(--slate-100);
}

.modal-content img {
    display: block;
    max-width: 100%;
    height: auto;
}