/* 
 * NewsChannel Design System 
 * Style: Minimalist, Modern, Responsive (Linear/Vercel inspired)
 */

:root {
    /* Colors - Neutral Scale (Zinc/Slate) */
    --white: #ffffff;
    --gray-50: #fafafa;
    --gray-100: #f4f4f5;
    --gray-200: #e4e4e7;
    --gray-300: #d4d4d8;
    --gray-400: #a1a1aa;
    --gray-500: #71717a;
    --gray-600: #52525b;
    --gray-700: #3f3f46;
    --gray-800: #27272a;
    --gray-900: #18181b;
    --black: #000000;

    /* Semantic Colors */
    --primary: #2563eb;       /* Blue 600 */
    --primary-hover: #1d4ed8; 
    --primary-subtle: #eff6ff;
    
    --danger: #ef4444;
    --danger-subtle: #fef2f2;
    --warning: #f59e0b;
    --warning-subtle: #fffbeb;
    --success: #10b981;
    --success-subtle: #ecfdf5;
    --info: #3b82f6;
    --info-subtle: #eff6ff;

    /* Theme Variables */
    --bg-body: var(--gray-50);
    --bg-main: var(--bg-body); /* Alias for chat.html compatibility */
    --bg-card: var(--white);
    --bg-sidebar: var(--gray-50);
    --border: var(--gray-200);
    
    --text-main: var(--gray-900);
    --text-muted: var(--gray-500);
    
    /* Layout */
    --sidenav-width: 260px;
    --header-height: 56px;
    --radius: 8px;
    --radius-sm: 6px;
    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    --transition: all 0.2s ease;
}

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

body {
    background-color: var(--bg-body);
    color: var(--text-main);
    font-family: var(--font-sans);
    font-size: 14px;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    height: 100vh;
    overflow: hidden;
}

h1, h2, h3, h4, h5, h6 {
    font-weight: 600;
    color: var(--gray-900);
    letter-spacing: -0.025em;
}

a { text-decoration: none; color: inherit; }
button { font-family: inherit; }

/* Layout Structure */
.app-container {
    display: flex;
    height: 100vh;
    width: 100vw;
    overflow: hidden;
}

/* Sidebar */
.sidenav {
    width: var(--sidenav-width);
    background: var(--bg-sidebar);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    height: 100%;
    position: fixed;
    left: 0;
    top: 0;
    z-index: 50;
    transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

.sidenav-header {
    height: var(--header-height);
    display: flex;
    align-items: center;
    padding: 0 1.5rem;
    font-weight: 600;
    font-size: 1rem;
    color: var(--gray-900);
    border-bottom: 1px solid transparent; 
}

.sidenav-header i { margin-right: 0.75rem; font-size: 1.25rem; color: var(--gray-700); }

.nav-links {
    list-style: none;
    padding: 1rem 0.75rem;
    flex: 1;
}

.nav-links li { margin-bottom: 2px; }

.nav-links a {
    display: flex;
    align-items: center;
    padding: 0.5rem 0.75rem;
    border-radius: var(--radius-sm);
    color: var(--text-muted);
    font-weight: 500;
    transition: var(--transition);
    gap: 0.75rem;
}

.nav-links a:hover {
    background: var(--gray-200);
    color: var(--gray-900);
}

.nav-links li.active a {
    background: var(--white);
    color: var(--gray-900);
    box-shadow: var(--shadow-sm);
    font-weight: 600;
}

.nav-links li.active a i { color: var(--primary); }

/* Main Content */
.main-content {
    flex: 1;
    margin-left: var(--sidenav-width); /* Desktop default */
    height: 100%;
    overflow-y: auto;
    padding: 2rem;
    background: var(--bg-body);
    width: calc(100% - var(--sidenav-width));
}

.section {
    display: none;
    animation: fadeScale 0.25s ease-out;
    max-width: 1400px;
    margin: 0 auto;
}

.section.active { display: block; }

@keyframes fadeScale {
    from { opacity: 0; transform: scale(0.99) translateY(5px); }
    to { opacity: 1; transform: scale(1) translateY(0); }
}

/* Section Header */
.section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 2rem;
    padding-bottom: 1rem;
    border-bottom: 1px solid var(--border);
}

.section-header h2 { font-size: 1.5rem; }

.header-actions {
    display: flex;
    gap: 0.75rem;
    align-items: center;
}

/* Navbar Mobile */
.navbar {
    display: none; /* Desktop hidden */
    height: var(--header-height);
    background: var(--bg-card);
    border-bottom: 1px solid var(--border);
    align-items: center;
    justify-content: space-between;
    padding: 0 1rem;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    z-index: 100;
}
.brand {
    font-weight: bold;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    color: var(--gray-900);
}
#menu-toggle {
    background: none; border: none; font-size: 1.5rem; cursor: pointer; color: var(--gray-700);
}

/* UI Components */

/* Buttons */
.btn-primary, .btn-secondary, .btn-danger, .btn-ghost {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0 1rem;
    height: 36px;
    border-radius: var(--radius-sm);
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    transition: var(--transition);
    white-space: nowrap;
    border: 1px solid transparent;
}

.btn-primary {
    background: var(--gray-900); /* Modern black button */
    color: var(--white);
}
.btn-primary:hover {
    background: var(--gray-800);
    transform: translateY(-1px);
}
.btn-primary:disabled { opacity: 0.6; cursor: not-allowed; transform: none; }

.btn-secondary {
    background: var(--white);
    color: var(--gray-700);
    border: 1px solid var(--border);
}
.btn-secondary:hover {
    background: var(--gray-50);
    border-color: var(--gray-300);
    color: var(--gray-900);
}

.btn-danger {
    background: var(--danger);
    color: white;
}
.btn-danger:hover { background: #dc2626; }

/* Forms */
.form-group { margin-bottom: 1.25rem; }
.form-group label {
    display: block;
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--gray-700);
    margin-bottom: 0.5rem;
}

.form-control, .form-select, select, .form-input {
    width: 100%;
    height: 38px;
    padding: 0 0.75rem;
    font-size: 0.875rem;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--bg-card);
    color: var(--text-main);
    transition: var(--transition);
}

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

textarea.form-control, textarea.form-input {
    height: auto;
    min-height: 100px;
    padding: 0.75rem;
    line-height: 1.5;
    resize: vertical;
}

.select-wrapper {
    position: relative;
    display: inline-block;
}

/* Tables */
.table-container {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
    margin-top: 1rem;
    /* Dynamic height with max viewport constraint */
    max-height: calc(100vh - 220px);
    overflow: auto; /* Enable scroll on both axes */
}

.data-table {
    width: 100%;
    border-collapse: separate; /* Better for sticky elements */
    border-spacing: 0;
    min-width: 600px;
}

.data-table th {
    background: var(--gray-50);
    padding: 0.75rem 1.5rem;
    text-align: left;
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    border-bottom: 1px solid var(--border);
    /* Sticky Header */
    position: sticky;
    top: 0;
    z-index: 10;
}

.data-table td {
    padding: 1rem 1.5rem;
    border-bottom: 1px solid var(--border);
    font-size: 0.875rem;
    color: var(--gray-700);
    background: var(--bg-card); /* Opaque background for scrolling */
}

/* Sticky First Column */
.data-table th:first-child,
.data-table td:first-child {
    position: sticky;
    left: 0;
    z-index: 15;
    border-right: 1px solid var(--border); /* Visual separator */
}

.data-table th:first-child {
    z-index: 20; /* Highest priority (corner) */
}

.data-table tr:last-child td { border-bottom: none; }
.data-table tr:hover td { background: var(--gray-50); }

/* Editorial Intelligence Panel (EIP) */
.eip-container {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 1.5rem;
    margin-bottom: 2rem;
}

.eip-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.25rem;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    transition: var(--transition);
}

.eip-card:hover {
    border-color: var(--gray-300);
    box-shadow: var(--shadow-md);
}

.eip-header {
    font-size: 0.75rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.eip-list { list-style: none; }
.eip-item {
    font-size: 0.875rem;
    line-height: 1.6;
    color: var(--gray-600);
    padding: 0.5rem 0;
    border-bottom: 1px solid var(--gray-100);
}
.eip-item:last-child { border-bottom: none; }

/* EIP Variants */
.eip-alert .eip-header { color: var(--danger); }
.eip-alert { border-left: 3px solid var(--danger); }

.eip-recommendation .eip-header { color: var(--warning); }
.eip-recommendation { border-left: 3px solid var(--warning); }

.eip-observation .eip-header { color: var(--info); }
.eip-observation { border-left: 3px solid var(--info); }

/* Dialogs */
dialog {
    border: none;
    border-radius: var(--radius);
    box-shadow: var(--shadow-md);
    padding: 0;
    width: 90%;
    max-width: 500px;
    background: var(--bg-card);
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
}

dialog::backdrop {
    background: rgba(0, 0, 0, 0.3);
    backdrop-filter: blur(2px);
}

.dialog-header {
    padding: 1.25rem 1.5rem;
    border-bottom: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.dialog-header h3 { font-size: 1.125rem; font-weight: 600; }

.close-dialog {
    background: none; border: none; font-size: 1.5rem; color: var(--text-muted); cursor: pointer;
}

.dialog-content, .dialog-body {
    padding: 1.5rem;
}

.dialog-footer {
    padding: 1rem 1.5rem;
    background: var(--gray-50);
    border-top: 1px solid var(--border);
    display: flex;
    justify-content: flex-end;
    gap: 0.75rem;
}

/* Settings & Models */
.settings-group {
    background: var(--bg-card);
    padding: 1.5rem;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    margin-bottom: 1.5rem;
}
.settings-group h3 {
    margin-bottom: 1rem;
    padding-bottom: 0.5rem;
    border-bottom: 1px solid var(--border);
}

.models-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
    gap: 1rem;
    margin-top: 1rem;
}

.model-card {
    position: relative;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1rem;
    background: var(--bg-card);
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    min-height: 140px;
}
.model-card:hover { border-color: var(--primary); }

.model-title { font-weight: 600; font-size: 0.9rem; margin-bottom: 0.25rem; }
.model-desc { font-size: 0.8rem; color: var(--text-muted); margin-bottom: 1rem; }
.model-badge {
    font-size: 0.7rem; padding: 2px 6px; border-radius: 4px; font-weight: bold; text-transform: uppercase;
}
.badge-downloaded { background: var(--success-subtle); color: var(--success); }
.badge-loaded { background: var(--info-subtle); color: var(--info); border: 1px solid var(--info); }
.badge-default { background: var(--gray-100); color: var(--gray-500); }

.model-actions { margin-top: auto; display: flex; gap: 0.5rem; }
.btn-sm { padding: 0.25rem 0.75rem; font-size: 0.8rem; height: 28px; }

/* Status & Utils */
.status-msg {
    margin-bottom: 1rem;
    padding: 0.75rem;
    border-radius: var(--radius-sm);
    display: none;
    font-size: 0.9rem;
    border: 1px solid transparent;
}
.status-msg.success { background: var(--success-subtle); color: #065f46; border-color: var(--success); }
.status-msg.error { background: var(--danger-subtle); color: #991b1b; border-color: var(--danger); }
.status-msg.info { background: var(--info-subtle); color: #1e40af; border-color: var(--info); }

.action-btn-group { display: flex; gap: 0.5rem; }
.btn-icon {
    background: none; border: none; cursor: pointer; font-size: 1.1rem; color: var(--text-muted);
}
.btn-icon:hover { color: var(--primary); }
.btn-icon.delete:hover, .btn-icon.delete-btn:hover { color: var(--danger); }

/* Ranges */
.range-container { display: flex; flex-direction: column; gap: 0.5rem; }
.form-range { width: 100%; cursor: pointer; }
.range-labels { display: flex; justify-content: space-between; font-size: 0.75rem; color: var(--text-muted); }
.badge-value { background: var(--gray-100); color: var(--gray-900); padding: 2px 6px; border-radius: 4px; font-weight: bold; }

.help-text-sm {
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-top: 0.25rem;
}

/* Loader */
.spinner, .loader-spinner {
    width: 24px;
    height: 24px;
    border: 3px solid var(--gray-200);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    margin: 0 auto 1rem;
}
.loader-content { text-align: center; padding: 2rem; }
@keyframes spin { to { transform: rotate(360deg); } }

/* Progress Bar */
progress {
    width: 100%;
    height: 8px;
    border-radius: var(--radius-sm);
    overflow: hidden;
    appearance: none;
    border: none;
    background-color: var(--gray-200);
}
progress::-webkit-progress-bar {
    background-color: var(--gray-200);
}
progress::-webkit-progress-value {
    background-color: var(--primary);
    transition: width 0.3s ease;
}
progress::-moz-progress-bar {
    background-color: var(--primary);
}

/* Responsive Overrides */
@media (max-width: 1024px) {
    .main-content {
        margin-left: 0;
        width: 100%;
        padding-top: calc(var(--header-height) + 1rem);
    }

    .navbar { display: flex; }

    .sidenav {
        transform: translateX(-100%);
        top: var(--header-height);
        height: calc(100vh - var(--header-height));
        box-shadow: none;
    }

    .sidenav.open {
        transform: translateX(0);
        box-shadow: 4px 0 24px rgba(0,0,0,0.1);
    }
}

@media (max-width: 640px) {
    .header-actions { flex-direction: column; align-items: stretch; }
    .header-actions .btn-primary, .header-actions .btn-secondary { width: 100%; }
    .table-container { border-radius: 0; border-left: none; border-right: none; margin-left: -1rem; margin-right: -1rem; width: calc(100% + 2rem); }
    .section-header { flex-direction: column; align-items: flex-start; gap: 1rem; }
    .section-header h2 { font-size: 1.25rem; }
    .main-content { padding: 1rem; padding-top: calc(var(--header-height) + 1rem); }
}
