/* ============================================================
   Factory V9.5.2 — Modern Dashboard Design
   Inspired by Nexus-style SaaS dashboard
   ============================================================ */

/* ---- Design Tokens ---- */
:root {
    /* Sidebar */
    --sidebar-bg: #1C1C2E;
    --sidebar-w: 240px;
    --sidebar-text: #8B8CA7;
    --sidebar-text-hover: #FFFFFF;
    --sidebar-active-bg: rgba(124, 92, 252, 0.12);
    --sidebar-active-text: #7C5CFC;
    --sidebar-section: #55566D;
    --sidebar-border: rgba(255,255,255,0.06);

    /* Main */
    --bg: #F5F6FA;
    --bg-card: #FFFFFF;
    --bg-input: #F0F1F5;
    --text: #1C1C2E;
    --text-secondary: #6E6E82;
    --text-muted: #9B9BB4;
    --border: #E8E8EF;

    /* Accent */
    --primary: #7C5CFC;
    --primary-hover: #6A4AEA;
    --primary-light: rgba(124,92,252,0.08);
    --success: #2BC48A;
    --success-light: rgba(43,196,138,0.10);
    --danger: #F45B69;
    --danger-light: rgba(244,91,105,0.10);
    --warning: #F5A623;
    --warning-light: rgba(245,166,35,0.10);
    --info: #3B9AED;
    --info-light: rgba(59,154,237,0.10);

    /* Shape */
    --radius: 14px;
    --radius-sm: 8px;
    --radius-xs: 6px;
    --shadow: 0 1px 3px rgba(28,28,46,0.06), 0 1px 2px rgba(28,28,46,0.04);
    --shadow-md: 0 4px 12px rgba(28,28,46,0.08);
    --shadow-lg: 0 8px 30px rgba(28,28,46,0.12);

    /* Transition */
    --ease: cubic-bezier(0.4, 0, 0.2, 1);
}

/* ---- Reset ---- */
*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Noto Sans SC', sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.6;
    min-height: 100vh;
    font-size: 14px;
    -webkit-font-smoothing: antialiased;
}

/* ============================================================
   LAYOUT: sidebar + main
   ============================================================ */
.app-layout {
    display: flex;
    min-height: 100vh;
}

/* ---- Sidebar ---- */
.sidebar {
    width: var(--sidebar-w);
    min-height: 100vh;
    background: var(--sidebar-bg);
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    z-index: 200;
    overflow-y: auto;
    overflow-x: hidden;
}

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 24px 20px 20px;
    border-bottom: 1px solid var(--sidebar-border);
    margin-bottom: 8px;
}

.sidebar-logo {
    width: 34px;
    height: 34px;
    background: var(--primary);
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    font-weight: 800;
    font-size: 16px;
    flex-shrink: 0;
}

.sidebar-title {
    font-size: 18px;
    font-weight: 700;
    color: #fff;
    letter-spacing: -0.3px;
}

.sidebar-version {
    font-size: 11px;
    color: var(--sidebar-text);
    background: rgba(255,255,255,0.06);
    padding: 2px 7px;
    border-radius: 4px;
    margin-left: auto;
}

/* Nav groups */
.sidebar-section {
    padding: 16px 20px 6px;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 1.2px;
    color: var(--sidebar-section);
}

.sidebar-nav {
    display: flex;
    flex-direction: column;
    gap: 2px;
    padding: 0 10px;
}

.sidebar-link {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 12px;
    border-radius: var(--radius-sm);
    color: var(--sidebar-text);
    text-decoration: none;
    font-size: 14px;
    font-weight: 450;
    transition: all 0.15s var(--ease);
    white-space: nowrap;
}

.sidebar-link:hover {
    color: var(--sidebar-text-hover);
    background: rgba(255,255,255,0.05);
}

.sidebar-link.active {
    color: var(--sidebar-active-text);
    background: var(--sidebar-active-bg);
    font-weight: 550;
}

.sidebar-link .icon {
    width: 20px;
    height: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    flex-shrink: 0;
    opacity: 0.7;
}

.sidebar-link.active .icon { opacity: 1; }

/* Sidebar footer */
.sidebar-footer {
    margin-top: auto;
    padding: 16px;
    border-top: 1px solid var(--sidebar-border);
}

.sidebar-status {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    border-radius: var(--radius-sm);
    background: rgba(255,255,255,0.04);
}

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

.status-dot.idle { background: var(--sidebar-text); }
.status-dot.running { background: var(--success); animation: pulse-dot 2s infinite; }
.status-dot.stopping { background: var(--warning); animation: pulse-dot 1.5s infinite; }

@keyframes pulse-dot {
    0%, 100% { opacity: 1; box-shadow: 0 0 0 0 currentColor; }
    50% { opacity: 0.6; box-shadow: 0 0 0 4px currentColor; }
}

.status-label {
    font-size: 13px;
    color: var(--sidebar-text);
}

.status-label strong {
    color: #fff;
    display: block;
    font-size: 12px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

/* ---- Main Area ---- */
.main-area {
    margin-left: var(--sidebar-w);
    flex: 1;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* Top header bar */
.top-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 32px;
    background: var(--bg-card);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 100;
    min-height: 60px;
    gap: 12px;
    flex-wrap: wrap;
}

.top-bar-left {
    display: flex;
    align-items: center;
    gap: 16px;
}

.page-title {
    font-size: 20px;
    font-weight: 700;
    letter-spacing: -0.3px;
    color: var(--text);
}

.top-bar-right {
    display: flex;
    align-items: center;
    gap: 12px;
}

/* Content area */
.content {
    padding: 24px 32px;
    max-width: 1400px;
    flex: 1;
}

/* ============================================================
   CARDS
   ============================================================ */
.card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 24px;
    margin-bottom: 20px;
    box-shadow: var(--shadow);
    transition: box-shadow 0.2s var(--ease);
}

.card:hover {
    box-shadow: var(--shadow-md);
}

.card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 20px;
}

.card-title {
    font-size: 16px;
    font-weight: 600;
    color: var(--text);
    display: flex;
    align-items: center;
    gap: 8px;
}

.card-title .card-icon {
    width: 20px;
    height: 20px;
    opacity: 0.5;
}

/* ============================================================
   STAT CARDS (top row metrics)
   ============================================================ */
.stats-row {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 20px;
    margin-bottom: 24px;
}

.stat-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 22px 24px;
    box-shadow: var(--shadow);
    transition: all 0.2s var(--ease);
    position: relative;
    overflow: hidden;
}

.stat-card:hover {
    box-shadow: var(--shadow-md);
    transform: translateY(-1px);
}

.stat-card .stat-header {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 12px;
}

.stat-card .stat-icon-wrap {
    width: 32px;
    height: 32px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
}

.stat-card .stat-icon-wrap.purple { background: var(--primary-light); color: var(--primary); }
.stat-card .stat-icon-wrap.green { background: var(--success-light); color: var(--success); }
.stat-card .stat-icon-wrap.red { background: var(--danger-light); color: var(--danger); }
.stat-card .stat-icon-wrap.orange { background: var(--warning-light); color: var(--warning); }
.stat-card .stat-icon-wrap.blue { background: var(--info-light); color: var(--info); }

.stat-card .stat-label {
    font-size: 13px;
    color: var(--text-secondary);
    font-weight: 450;
}

.stat-card .stat-value {
    font-size: 28px;
    font-weight: 700;
    color: var(--text);
    letter-spacing: -0.5px;
    line-height: 1.2;
}

.stat-card .stat-badge {
    display: inline-flex;
    align-items: center;
    gap: 3px;
    font-size: 12px;
    font-weight: 600;
    padding: 3px 8px;
    border-radius: 20px;
    margin-left: 10px;
    vertical-align: middle;
}

.stat-badge.up { background: var(--success-light); color: var(--success); }
.stat-badge.down { background: var(--danger-light); color: var(--danger); }
.stat-badge.neutral { background: var(--bg-input); color: var(--text-muted); }

/* ============================================================
   PROGRESS BAR
   ============================================================ */
.progress-section {
    margin-bottom: 24px;
}

.progress-header {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    margin-bottom: 10px;
}

.progress-count {
    font-size: 15px;
    font-weight: 600;
    color: var(--text);
}

.progress-pct {
    font-size: 14px;
    font-weight: 600;
    color: var(--primary);
}

.progress-track {
    height: 10px;
    background: var(--bg-input);
    border-radius: 99px;
    overflow: hidden;
}

.progress-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--primary), #A78BFA);
    border-radius: 99px;
    transition: width 0.6s var(--ease);
}

.progress-meta {
    display: flex;
    gap: 28px;
    margin-top: 10px;
    font-size: 13px;
    color: var(--text-muted);
}

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

/* ============================================================
   BUTTONS
   ============================================================ */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 9px 20px;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 14px;
    font-weight: 550;
    cursor: pointer;
    text-decoration: none;
    transition: all 0.15s var(--ease);
    line-height: 1.4;
    white-space: nowrap;
    font-family: inherit;
}

.btn:disabled { opacity: 0.45; cursor: not-allowed; pointer-events: none; }

.btn-primary {
    background: var(--primary);
    color: #fff;
    box-shadow: 0 1px 3px rgba(124,92,252,0.3);
}
.btn-primary:hover:not(:disabled) {
    background: var(--primary-hover);
    box-shadow: 0 3px 10px rgba(124,92,252,0.3);
    transform: translateY(-1px);
}

.btn-danger {
    background: var(--danger);
    color: #fff;
    box-shadow: 0 1px 3px rgba(244,91,105,0.3);
}
.btn-danger:hover:not(:disabled) { background: #E04A58; }

.btn-success {
    background: var(--success);
    color: #fff;
}
.btn-success:hover:not(:disabled) { background: #24AA77; }

.btn-secondary {
    background: var(--bg-input);
    color: var(--text-secondary);
    border: 1px solid var(--border);
}
.btn-secondary:hover:not(:disabled) {
    background: #E4E5EA;
    color: var(--text);
}

.btn-ghost {
    background: transparent;
    color: var(--text-secondary);
    padding: 9px 14px;
}
.btn-ghost:hover { background: var(--bg-input); color: var(--text); }

.btn-sm { padding: 6px 14px; font-size: 12px; border-radius: var(--radius-xs); }
.btn-xs { padding: 4px 10px; font-size: 11px; border-radius: var(--radius-xs); }

.form-actions {
    display: flex;
    gap: 10px;
    margin-top: 20px;
}

.actions-row {
    display: flex;
    gap: 10px;
    align-items: center;
    flex-wrap: wrap;
    flex-shrink: 0;
}

/* ============================================================
   FORMS
   ============================================================ */
.form-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 18px;
}

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

.form-group label {
    font-size: 13px;
    font-weight: 550;
    color: var(--text-secondary);
}

select,
input[type="text"],
input[type="number"],
input[type="search"] {
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 10px 14px;
    color: var(--text);
    font-size: 14px;
    font-family: inherit;
    transition: all 0.15s var(--ease);
    outline: none;
    width: 100%;
}

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

textarea {
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 12px 14px;
    color: var(--text);
    font-size: 14px;
    width: 100%;
    resize: vertical;
    font-family: 'JetBrains Mono', 'Fira Code', 'Consolas', monospace;
    outline: none;
    transition: border-color 0.15s var(--ease);
    line-height: 1.6;
}

fieldset.form-fieldset {
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 18px;
    margin: 12px 0;
}

fieldset.form-fieldset legend {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-secondary);
    padding: 0 8px;
}

small.hint {
    font-size: 12px;
    color: var(--text-muted);
}

small.hint code {
    background: var(--bg-input);
    padding: 1px 5px;
    border-radius: 3px;
    font-size: 11px;
}

/* ============================================================
   PAGE HEADER
   ============================================================ */
.page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 24px;
}

h2.section-title {
    font-size: 20px;
    font-weight: 700;
    color: var(--text);
    letter-spacing: -0.3px;
}

h3 {
    font-size: 15px;
    font-weight: 600;
    color: var(--text);
    margin-bottom: 16px;
}

.subtitle {
    font-size: 14px;
    color: var(--text-muted);
    margin-bottom: 20px;
}

/* ============================================================
   STATS GRID (compact, 4-column)
   ============================================================ */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 16px;
    margin-bottom: 20px;
}

.stats-grid-2 {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 16px;
    margin-bottom: 20px;
}

/* ============================================================
   DATA TABLE
   ============================================================ */
.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}

.data-table thead th {
    text-align: left;
    padding: 12px 16px;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.8px;
    color: var(--text-muted);
    border-bottom: 1px solid var(--border);
    background: var(--bg);
}

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

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

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

.data-table code {
    font-size: 12px;
    background: var(--bg-input);
    padding: 2px 6px;
    border-radius: 4px;
    color: var(--primary);
}

.data-table .actions {
    display: flex;
    gap: 6px;
}

.empty-msg {
    text-align: center;
    padding: 40px 20px;
    color: var(--text-muted);
    font-size: 14px;
}

/* ============================================================
   BADGES
   ============================================================ */
.badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-size: 11px;
    font-weight: 600;
    padding: 4px 10px;
    border-radius: 20px;
    letter-spacing: 0.2px;
}

.badge.status-pending { background: var(--bg-input); color: var(--text-muted); }
.badge.status-running { background: var(--success-light); color: var(--success); }
.badge.status-completed { background: var(--primary-light); color: var(--primary); }
.badge.status-failed { background: var(--danger-light); color: var(--danger); }
.badge.status-cancelled { background: var(--warning-light); color: var(--warning); }

/* ============================================================
   STATUS BANNER
   ============================================================ */
.status-banner {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 16px 20px;
    border-radius: var(--radius);
    margin-bottom: 20px;
    font-size: 14px;
    font-weight: 500;
}

.status-banner.idle {
    background: var(--bg-input);
    color: var(--text-secondary);
    border: 1px solid var(--border);
}

.status-banner.running {
    background: var(--success-light);
    color: var(--success);
    border: 1px solid rgba(43,196,138,0.2);
}

.status-banner.stopping {
    background: var(--warning-light);
    color: var(--warning);
    border: 1px solid rgba(245,166,35,0.2);
}

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

/* ============================================================
   CONFIG PAGE
   ============================================================ */
.config-toolbar {
    display: flex;
    gap: 10px;
    margin-bottom: 16px;
    align-items: center;
}

.config-toolbar input { flex: 1; }

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

.config-table th {
    text-align: left;
    padding: 10px 14px;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.8px;
    color: var(--text-muted);
    border-bottom: 1px solid var(--border);
    background: var(--bg);
}

.config-table td {
    padding: 8px 14px;
    border-bottom: 1px solid var(--border);
}

.config-key {
    font-family: 'JetBrains Mono', 'Fira Code', monospace;
    font-size: 12px;
    color: var(--primary);
}

.config-type {
    color: var(--text-muted);
    font-size: 11px;
}

.config-input {
    width: 100%;
    background: transparent;
    border: 1px solid transparent;
    padding: 5px 8px;
    border-radius: var(--radius-xs);
    font-family: inherit;
    font-size: 13px;
    color: var(--text);
    transition: all 0.15s;
}

.config-input:focus {
    border-color: var(--primary);
    background: var(--bg-input);
    box-shadow: 0 0 0 3px var(--primary-light);
}

.profiles-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 14px;
}

.profile-card {
    padding: 18px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    cursor: pointer;
    text-align: center;
    transition: all 0.2s var(--ease);
    background: var(--bg);
}

.profile-card:hover {
    border-color: var(--primary);
    box-shadow: var(--shadow-md);
}

.profile-card.active {
    border-color: var(--primary);
    background: var(--primary-light);
    box-shadow: 0 0 0 3px var(--primary-light);
}

.profile-name { font-weight: 600; margin-bottom: 4px; color: var(--text); }
.profile-key {
    font-size: 12px;
    color: var(--text-muted);
    font-family: 'JetBrains Mono', monospace;
}
.profile-overrides { font-size: 11px; color: var(--text-muted); margin-top: 4px; }

/* ============================================================
   PROMPTS PAGE
   ============================================================ */
.prompts-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
    margin-bottom: 20px;
}

.prompt-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 10px;
}

.prompt-editor {
    min-height: 400px;
    font-size: 13px;
    line-height: 1.6;
}

.variables-list { display: flex; gap: 8px; flex-wrap: wrap; }

.var-tag {
    background: var(--primary-light);
    color: var(--primary);
    padding: 4px 12px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 500;
    font-family: 'JetBrains Mono', monospace;
}

/* ============================================================
   LOGS PAGE
   ============================================================ */
.logs-toolbar {
    display: flex;
    gap: 10px;
    align-items: center;
    margin-bottom: 14px;
}

.logs-toolbar input[type="text"] { flex: 1; }
.logs-toolbar select { min-width: 120px; }
.logs-toolbar label {
    font-size: 13px;
    color: var(--text-muted);
    white-space: nowrap;
    display: flex;
    align-items: center;
    gap: 4px;
}

.log-container {
    background: #1C1C2E;
    border: 1px solid rgba(255,255,255,0.06);
    border-radius: var(--radius);
    padding: 16px;
    height: 520px;
    overflow-y: auto;
    font-family: 'JetBrains Mono', 'Fira Code', 'Consolas', monospace;
    font-size: 12px;
    line-height: 1.7;
    color: #C4C4DA;
}

.log-empty {
    color: #55566D;
    text-align: center;
    padding: 60px 20px;
    font-size: 13px;
}

.log-line { padding: 1px 0; }
.log-line.log-error { color: var(--danger); }
.log-line.log-warning { color: var(--warning); }
.log-line.log-info { color: #8B8CA7; }

/* ============================================================
   KEYWORD STATS
   ============================================================ */
.keyword-stats {
    display: flex;
    gap: 28px;
    margin-bottom: 14px;
    font-size: 14px;
    color: var(--text-secondary);
}

.keyword-stats strong {
    color: var(--text);
}

/* ============================================================
   INFO PANEL (worker/rps/buffer)
   ============================================================ */
.info-panel .info-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 20px;
}

.info-panel .info-item {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.info-panel .info-label {
    font-size: 12px;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    font-weight: 500;
}

.info-panel .info-value {
    font-size: 18px;
    font-weight: 600;
    color: var(--text);
}

.info-panel .info-sub {
    font-size: 12px;
    color: var(--text-muted);
    font-style: italic;
}

/* ============================================================
   QUALITY GRID (analytics)
   ============================================================ */
.quality-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 14px;
}

.quality-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    background: var(--bg);
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
}

.quality-item .label {
    font-size: 13px;
    color: var(--text-secondary);
    font-weight: 450;
}

.quality-item .value {
    font-size: 18px;
    font-weight: 700;
    color: var(--text);
}

/* ============================================================
   HEAL / FAIL BAR CHARTS
   ============================================================ */
.bar-chart-row {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 0;
    border-bottom: 1px solid var(--border);
}

.bar-chart-row:last-child { border-bottom: none; }

.bar-name {
    min-width: 140px;
    font-size: 13px;
    color: var(--text-secondary);
    font-weight: 450;
    flex-shrink: 0;
}

.bar-track {
    flex: 1;
    height: 8px;
    background: var(--bg-input);
    border-radius: 99px;
    overflow: hidden;
}

.bar-fill {
    height: 100%;
    border-radius: 99px;
    transition: width 0.4s var(--ease);
}

.bar-fill.purple { background: linear-gradient(90deg, var(--primary), #A78BFA); }
.bar-fill.red { background: linear-gradient(90deg, var(--danger), #F9A8B0); }
.bar-fill.green { background: linear-gradient(90deg, var(--success), #6EE7B7); }

.bar-count {
    min-width: 80px;
    text-align: right;
    font-size: 13px;
    font-weight: 600;
    color: var(--text);
}

/* ============================================================
   EXPORT BUTTONS
   ============================================================ */
.export-buttons {
    display: flex;
    gap: 8px;
}

/* ============================================================
   MODAL
   ============================================================ */
.modal {
    position: fixed;
    inset: 0;
    z-index: 1000;
    background: rgba(28,28,46,0.4);
    backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.modal-content {
    max-width: 600px;
    width: 100%;
    max-height: 85vh;
    overflow-y: auto;
}

.modal-content.modal-wide {
    max-width: 900px;
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 16px;
}

.modal-meta {
    display: flex;
    gap: 16px;
    font-size: 13px;
    color: var(--text-muted);
    margin-bottom: 16px;
    padding-bottom: 16px;
    border-bottom: 1px solid var(--border);
}

/* ============================================================
   PAGINATION
   ============================================================ */
.pagination {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 16px;
    padding: 16px 0;
    font-size: 13px;
    color: var(--text-muted);
}

/* ============================================================
   PREVIEW
   ============================================================ */
.preview-card {
    cursor: pointer;
    transition: all 0.15s var(--ease);
}

.preview-card:hover {
    border-color: var(--primary);
    box-shadow: var(--shadow-md);
}

.preview-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 10px;
}

.preview-keyword {
    font-size: 15px;
    font-weight: 600;
    color: var(--text);
}

.preview-meta {
    font-size: 12px;
    color: var(--text-muted);
}

.preview-text {
    font-size: 13px;
    color: var(--text-secondary);
    line-height: 1.6;
}

.article-body {
    font-size: 14px;
    line-height: 1.8;
    color: var(--text-secondary);
}

.article-body h1, .article-body h2, .article-body h3 {
    color: var(--text);
    margin: 20px 0 10px;
}

/* ============================================================
   FILTER BAR
   ============================================================ */
.filter-bar {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 14px 20px;
    font-size: 13px;
}

.filter-bar label {
    color: var(--text-muted);
    font-weight: 500;
}

.filter-bar select {
    padding: 6px 12px;
    min-width: 120px;
}

.total-count {
    margin-left: auto;
    color: var(--text-muted);
    font-size: 13px;
}

/* ============================================================
   HAMBURGER MENU BUTTON
   ============================================================ */
.menu-toggle {
    display: none;
    align-items: center;
    justify-content: center;
    width: 38px;
    height: 38px;
    border: none;
    border-radius: var(--radius-sm);
    background: var(--bg-input);
    color: var(--text);
    font-size: 20px;
    cursor: pointer;
    transition: background 0.15s var(--ease);
    flex-shrink: 0;
    line-height: 1;
}

.menu-toggle:hover { background: var(--border); }

/* Sidebar overlay backdrop */
.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(28,28,46,0.45);
    backdrop-filter: blur(2px);
    z-index: 199;
    opacity: 0;
    transition: opacity 0.25s var(--ease);
}

.sidebar-overlay.visible {
    display: block;
    opacity: 1;
}

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

/* ---- Tablet: ≤1024px — sidebar collapses to overlay ---- */
@media (max-width: 1024px) {
    .menu-toggle { display: flex; }

    .sidebar {
        transform: translateX(-100%);
        transition: transform 0.3s var(--ease);
        box-shadow: none;
    }

    .sidebar.open {
        transform: translateX(0);
        box-shadow: 4px 0 24px rgba(28,28,46,0.25);
    }

    .main-area {
        margin-left: 0;
    }

    .stats-row { grid-template-columns: repeat(2, 1fr); }
    .stats-grid { grid-template-columns: repeat(2, 1fr); }
    .stats-grid-2 { grid-template-columns: 1fr; }
    .quality-grid { grid-template-columns: repeat(2, 1fr) !important; }
    .profiles-grid { grid-template-columns: repeat(2, 1fr); }

    .content { padding: 20px; }
    .top-bar { padding: 12px 20px; }
}

/* ---- Mobile: ≤640px — single column, compact ---- */
@media (max-width: 640px) {
    .stats-row { grid-template-columns: repeat(2, 1fr); gap: 10px; }
    .stats-grid { grid-template-columns: 1fr 1fr; gap: 10px; }
    .quality-grid { grid-template-columns: 1fr 1fr !important; gap: 8px; }

    .stat-card { padding: 16px; }
    .stat-card .stat-value { font-size: 22px; }

    .form-grid { grid-template-columns: 1fr; }
    .prompts-grid { grid-template-columns: 1fr; }
    .profiles-grid { grid-template-columns: 1fr; }
    .info-panel .info-grid { grid-template-columns: 1fr 1fr 1fr; gap: 12px; }
    .info-panel .info-value { font-size: 15px; }

    .content { padding: 14px; }
    .top-bar { padding: 10px 14px; }
    .page-title { font-size: 17px; }

    .card { padding: 16px; border-radius: 12px; margin-bottom: 12px; }
    h3 { font-size: 14px; }

    .progress-meta { gap: 14px; font-size: 12px; flex-wrap: wrap; }

    .bar-name { min-width: 90px; font-size: 12px; }
    .bar-count { min-width: 60px; font-size: 12px; }

    .logs-toolbar { flex-wrap: wrap; }
    .log-container { height: 380px; }

    .filter-bar { flex-wrap: wrap; gap: 8px; }
    .total-count { margin-left: 0; }

    .modal-content { max-width: 100%; }

    /* Data table horizontal scroll */
    .data-table { display: block; overflow-x: auto; white-space: nowrap; }

    .keyword-stats { flex-wrap: wrap; gap: 12px; }

    .export-buttons { gap: 4px; }
    .btn-sm { padding: 5px 10px; font-size: 11px; }
}

/* ---- Tiny mobile: ≤400px ---- */
@media (max-width: 400px) {
    .stats-row { grid-template-columns: 1fr 1fr; gap: 8px; }
    .stat-card .stat-value { font-size: 20px; }
    .stat-card .stat-label { font-size: 11px; }
    .stat-card .stat-icon-wrap { width: 26px; height: 26px; font-size: 13px; border-radius: 6px; }

    .top-bar-right .btn { padding: 5px 8px; font-size: 11px; }

    .content { padding: 10px; }
}

/* ---- Large desktop: ≥1440px — wider content ---- */
@media (min-width: 1440px) {
    .content { max-width: 1600px; }
}
