/* MekDojo Expert UI — Shared Design System */

:root {
    --primary: #1e3c72;
    --primary-light: #2a5298;
    --primary-bg: #e8f0fe;
    --bg: #f4f6f8;
    --bg-content: #f8fafc;
    --text: #333;
    --text-muted: #666;
    --text-light: #888;
    --text-placeholder: #999;
    --border: #e0e0e0;
    --border-light: #eef2f6;
    --border-faint: #f0f0f0;
    --white: #fff;
    --danger: #b91c1c;
    --danger-bg: #f8d7da;
    --danger-text: #721c24;
    --success: #28a745;
    --success-bg: #d4edda;
    --success-text: #155724;
    --warning: #ffc107;
    --warning-bg: #fff3cd;
    --warning-text: #856404;
    --shadow-sm: 0 2px 10px rgba(0, 0, 0, 0.1);
    --shadow-card: 0 4px 6px rgba(0, 0, 0, 0.05);
    --shadow-modal: 0 20px 40px rgba(0, 0, 0, 0.2);
    --radius: 6px;
    --radius-lg: 12px;
    --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

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

body {
    font-family: var(--font);
    background-color: var(--bg);
    color: var(--text);
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ===== Navbar ===== */
.navbar {
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-light) 100%);
    color: white;
    padding: 15px 30px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    box-shadow: var(--shadow-sm);
    z-index: 10;
    position: relative;
}

.navbar-brand { display: flex; flex-direction: column; }
.brand-title { font-size: 20px; font-weight: 700; line-height: 1.2; }
.brand-subtitle { font-size: 11px; font-weight: 400; opacity: 0.7; margin-top: 2px; }
.navbar-center {
    font-size: 16px; font-weight: 600; letter-spacing: 0.5px; opacity: 0.9;
    position: absolute; left: 50%; transform: translateX(-50%);
}

.nav-links {
    display: flex;
    align-items: center;
    position: relative;
}

.nav-links a.nav-link {
    color: rgba(255, 255, 255, 0.7);
    text-decoration: none;
    margin-left: 20px;
    font-size: 14px;
    font-weight: 500;
    transition: color 0.2s;
}
.nav-links a.nav-link:hover { color: white; }
.nav-links a.nav-link.active {
    color: white;
    border-bottom: 2px solid white;
    padding-bottom: 2px;
}

/* Profile dropdown */
.profile-menu { position: relative; margin-left: 20px; }

.profile-icon {
    width: 36px; height: 36px; border-radius: 50%;
    background: rgba(255, 255, 255, 0.2);
    display: flex; justify-content: center; align-items: center;
    cursor: pointer; font-weight: bold; color: white;
    border: 1px solid rgba(255, 255, 255, 0.5);
    transition: background 0.2s;
}
.profile-icon:hover { background: rgba(255, 255, 255, 0.3); }

.dropdown {
    position: absolute; top: calc(100% + 10px); right: 0;
    background: white; border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    min-width: 150px; display: none; overflow: hidden; z-index: 1000;
}
.dropdown.active { display: block; }
.dropdown a {
    display: block; padding: 12px 16px; color: var(--text);
    text-decoration: none; font-size: 14px; transition: background 0.2s;
}
.dropdown a:hover { background: var(--bg); }

/* ===== Layout (sidebar + main) ===== */
.layout { display: flex; flex: 1; overflow: hidden; }

.sidebar {
    width: 300px; background: white;
    border-right: 1px solid var(--border);
    display: flex; flex-direction: column;
}
.sidebar-header {
    padding: 20px; border-bottom: 1px solid var(--border-faint);
    display: flex; justify-content: space-between; align-items: center;
}
.sidebar-header h2 { font-size: 16px; font-weight: 600; color: #555; }

.main-content {
    flex: 1; display: flex; flex-direction: column;
    background: var(--bg-content); overflow-y: auto;
}
.content-header {
    padding: 30px 40px; background: white;
    border-bottom: 1px solid var(--border);
}
.content-header h2 { font-size: 24px; color: var(--primary); margin-bottom: 8px; }
.content-header p { color: var(--text-muted); font-size: 14px; }
.content-body { padding: 40px; max-width: 1000px; }
.empty-state { text-align: center; padding: 60px 20px; color: var(--text-light); }

/* ===== Buttons ===== */
.btn-primary, .btn-submit, .btn-action, .btn {
    background: var(--primary);
    color: white; border: none;
    padding: 10px 20px; border-radius: var(--radius);
    font-size: 14px; font-weight: 600;
    cursor: pointer; text-align: center;
    text-decoration: none; display: inline-block;
    transition: opacity 0.2s;
}
.btn-primary:hover, .btn-submit:hover, .btn-action:hover, .btn:hover { opacity: 0.9; }

.btn-small {
    background: var(--border-light); color: var(--primary);
    border: none; padding: 6px 12px; border-radius: 4px;
    font-size: 12px; font-weight: 600; cursor: pointer;
    transition: background 0.2s;
}
.btn-small:hover { background: #dce4ec; }

.btn-cancel, .btn-secondary {
    background: #f0f0f0; color: #555;
    border: none; padding: 10px 20px;
    border-radius: var(--radius); cursor: pointer; font-weight: 500;
}
.btn-cancel:hover, .btn-secondary:hover { background: #e0e0e0; }

.btn-danger {
    background: var(--danger); color: white;
    border: none; padding: 10px 20px;
    border-radius: var(--radius); cursor: pointer; font-weight: 500;
}
.btn-danger:hover { opacity: 0.9; }

.btn-outline {
    background: transparent; color: var(--primary);
    border: 1px solid var(--primary);
    padding: 10px 20px; border-radius: var(--radius);
    cursor: pointer; font-weight: 500;
    transition: background 0.2s;
}
.btn-outline:hover { background: #f0f4f8; }

.btn-icon {
    background: transparent; border: none; cursor: pointer;
    font-size: 16px; padding: 4px; color: var(--text-muted);
    transition: color 0.2s;
}
.btn-icon:hover { color: var(--primary); }

.btn-icon-danger {
    background: transparent; border: none; cursor: pointer;
    font-size: 14px; padding: 4px; color: var(--text-placeholder);
    transition: color 0.2s;
}
.btn-icon-danger:hover { color: var(--danger); }

/* ===== Cards ===== */
.grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 20px; margin-top: 20px;
}

.card {
    background: white; border-radius: 8px;
    padding: 20px; box-shadow: var(--shadow-card);
    border: 1px solid var(--border-light);
    transition: transform 0.2s, box-shadow 0.2s;
}
.card:hover { transform: translateY(-3px); box-shadow: 0 8px 15px rgba(0, 0, 0, 0.08); }
.card h3 { font-size: 18px; color: var(--text); margin-bottom: 15px; }
.card-actions { margin-top: 20px; display: flex; flex-direction: column; gap: 10px; }

/* ===== Modals ===== */
.modal-overlay {
    position: fixed; top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    display: none; justify-content: center; align-items: center;
    z-index: 100; backdrop-filter: blur(2px);
}
.modal-overlay.active { display: flex; }

.modal {
    background: white; width: 100%; max-width: 500px;
    border-radius: var(--radius-lg); padding: 30px;
    box-shadow: var(--shadow-modal);
}
.modal h3 { margin-bottom: 20px; color: var(--primary); }
.modal-actions {
    display: flex; justify-content: flex-end;
    gap: 10px; margin-top: 30px;
}

/* ===== Forms ===== */
.form-group { margin-bottom: 20px; }
.form-group label {
    display: block; margin-bottom: 8px;
    font-weight: 500; font-size: 14px; color: #444;
}
.form-group input,
.form-group select,
.form-group textarea {
    width: 100%; padding: 12px;
    border: 1px solid #ddd; border-radius: var(--radius);
    font-size: 14px; font-family: var(--font);
}
.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(30, 60, 114, 0.1);
}

/* ===== Badges ===== */
.badge {
    display: inline-block; padding: 2px 6px;
    background: var(--primary-bg); color: var(--primary);
    border-radius: 10px; font-size: 11px; font-weight: 600; margin-left: 8px;
}
.badge.extracted { background: var(--success-bg); color: var(--success-text); }
.badge.pending { background: #e2e3e5; color: #383d41; }

/* ===== Progress Steps ===== */
.progress-step {
    padding: 10px 14px; border-radius: var(--radius); font-size: 14px;
    display: flex; align-items: center; gap: 10px;
    background: #f8f9fa; color: var(--text-muted);
}
.progress-step .step-icon { font-size: 18px; min-width: 24px; text-align: center; }
.progress-step.done { color: var(--success-text); background: var(--success-bg); }
.progress-step.active { color: var(--primary); background: var(--primary-bg); }
.progress-step.error { color: var(--danger-text); background: var(--danger-bg); }

/* ===== Machine list (sidebar) ===== */
.machine-list { flex: 1; overflow-y: auto; padding: 10px; }
.machine-item { margin-bottom: 8px; }
.machine-header {
    padding: 12px 15px; border-radius: var(--radius); cursor: pointer;
    display: flex; justify-content: space-between; align-items: center;
    transition: background 0.2s; border: 1px solid transparent;
}
.machine-header:hover { background: var(--bg-content); }
.machine-header.active {
    background: #f0f4f8; border-color: #dce4ec;
    font-weight: 600; color: var(--primary);
}

.subsystem-list { padding-left: 20px; padding-top: 5px; display: none; }
.machine-item.expanded .subsystem-list { display: block; }
.subsystem-item {
    padding: 8px 12px; margin-bottom: 4px; border-radius: 4px;
    font-size: 14px; color: var(--text-muted); cursor: pointer;
    transition: all 0.2s; border-left: 2px solid transparent;
}
.subsystem-item:hover { background: var(--bg-content); color: var(--text); }
.subsystem-item.active {
    background: var(--primary-bg); color: var(--primary);
    border-left-color: var(--primary); font-weight: 500;
}

/* ===== Discovery / Upload items ===== */
.discovery-item {
    display: flex; align-items: center; gap: 10px;
    padding: 10px 12px; border: 1px solid #eee;
    border-radius: var(--radius); margin-bottom: 6px;
    transition: background 0.2s;
}
.discovery-item:hover { background: var(--bg-content); }
.discovery-item input[type="checkbox"] { width: 16px; height: 16px; cursor: pointer; }
.discovery-item .machine-name { flex: 1; font-weight: 500; font-size: 14px; }
.file-selected { border-color: var(--success-text) !important; background: #f8fff8 !important; }

.dataset-list-item {
    display: flex; justify-content: space-between; align-items: center;
    padding: 12px; border: 1px solid #eee;
    border-radius: var(--radius); margin-bottom: 10px;
}
.dataset-list-actions { display: flex; gap: 8px; }

/* ===== Centered page layout (login, register, error, etc.) ===== */
.page-centered {
    min-height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 20px;
}

.page-card {
    background: white;
    border-radius: var(--radius-lg);
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.12);
    padding: 40px;
    max-width: 480px;
    width: 100%;
}
.page-card h1 {
    color: var(--primary);
    margin-bottom: 10px;
    font-size: 24px;
}
.page-card .subtitle {
    color: var(--text-muted);
    margin-bottom: 24px;
    font-size: 14px;
}
.page-card .nav-top {
    margin-bottom: 16px;
}
.page-card .nav-top a {
    color: var(--primary);
    text-decoration: none;
    font-size: 14px;
}
.page-card .nav-top a:hover { text-decoration: underline; }

/* ===== Alerts ===== */
.alert-error {
    background: #fee; color: #c33;
    padding: 10px 14px; border-radius: var(--radius);
    margin-bottom: 16px; font-size: 14px;
}
.alert-success {
    background: var(--success-bg); color: var(--success-text);
    padding: 10px 14px; border-radius: var(--radius);
    margin-bottom: 16px; font-size: 14px;
}
.alert-warning {
    background: var(--warning-bg); color: var(--warning-text);
    padding: 10px 14px; border-radius: var(--radius);
    margin-bottom: 16px; font-size: 14px;
}

/* ===== Tables ===== */
table { width: 100%; border-collapse: collapse; margin-bottom: 20px; }
th, td { text-align: left; padding: 12px 15px; border-bottom: 1px solid var(--border); }
th { background: #f8f9fa; font-weight: 600; color: #555; }
tr:hover { background: var(--bg-content); }

/* ===== Info box ===== */
.info-box {
    background: #f0f7ff; border-radius: var(--radius);
    padding: 15px; margin-top: 15px;
}
.info-box strong { color: var(--primary); }

/* ===== Node Detail Panel (Graph Flag/Inspect) ===== */
.node-detail-panel {
    position: absolute; top: 0; right: 0; width: 300px; height: 100%;
    background: var(--white); border-left: 1px solid var(--border);
    box-shadow: -4px 0 12px rgba(0, 0, 0, 0.08);
    display: flex; flex-direction: column; z-index: 30;
    transition: transform 0.2s ease;
}
.node-detail-panel.hidden { transform: translateX(100%); pointer-events: none; }
.node-detail-header {
    padding: 14px 16px; border-bottom: 1px solid var(--border);
    display: flex; justify-content: space-between; align-items: center;
}
.node-detail-header h3 {
    font-size: 14px; font-weight: 600; color: var(--text);
    margin: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; flex: 1;
}
.node-detail-close {
    background: none; border: none; font-size: 20px; cursor: pointer;
    color: var(--text-muted); padding: 0 0 0 8px; line-height: 1;
}
.node-detail-close:hover { color: var(--danger); }
.node-detail-body { flex: 1; overflow-y: auto; padding: 16px; }
.node-type-badge {
    display: inline-block; padding: 3px 10px; border-radius: 12px;
    font-size: 11px; font-weight: 600; margin-bottom: 12px;
    background: var(--primary-bg); color: var(--primary);
}
.node-type-badge.flagged { background: var(--danger-bg); color: var(--danger-text); }
.node-props-table { width: 100%; font-size: 12px; }
.node-props-table td { padding: 4px 0; vertical-align: top; }
.node-props-table td:first-child { color: var(--text-muted); width: 90px; font-weight: 500; }
.node-props-table td:last-child { color: var(--text); word-break: break-word; }
.node-source-page {
    margin-top: 10px; padding: 8px 10px; background: #f8f9fa;
    border-radius: var(--radius); font-size: 12px; color: var(--text-muted);
}
.node-detail-actions { padding: 12px 16px; border-top: 1px solid var(--border); }
.node-detail-actions textarea {
    width: 100%; padding: 8px; border: 1px solid var(--border);
    border-radius: var(--radius); font-size: 12px; font-family: var(--font);
    resize: vertical; margin-bottom: 8px;
}
.node-detail-actions textarea:focus { outline: none; border-color: var(--primary); }
.btn-flag {
    width: 100%; padding: 8px 16px; border-radius: var(--radius);
    font-size: 13px; font-weight: 600; cursor: pointer; border: none;
    transition: opacity 0.2s;
}
.btn-flag:hover { opacity: 0.9; }
.btn-flag.flag { background: var(--danger); color: var(--white); }
.btn-flag.unflag { background: var(--success); color: var(--white); }
.node-flag-reason {
    margin-top: 8px; padding: 8px 10px; background: #fff5f5;
    border: 1px solid #fed7d7; border-radius: var(--radius);
    font-size: 12px; color: var(--danger);
}

/* ===== Flagged Filter Button ===== */
.flagged-filter-btn {
    padding: 5px 12px; border-radius: 5px; border: 1px solid var(--danger);
    background: var(--white); cursor: pointer; font-size: 12px;
    color: var(--danger); transition: all 0.2s; display: inline-flex;
    align-items: center; gap: 4px;
}
.flagged-filter-btn:hover { background: #fff5f5; }
.flagged-filter-btn.active { background: var(--danger); color: var(--white); }
.flagged-count-badge {
    display: inline-block; min-width: 16px; height: 16px; line-height: 16px;
    text-align: center; border-radius: 8px; font-size: 10px; font-weight: 700;
    background: var(--danger); color: var(--white); padding: 0 4px;
}
.flagged-filter-btn.active .flagged-count-badge { background: var(--white); color: var(--danger); }

/* Flagged node list items */
.flagged-node-item {
    padding: 10px 12px; margin: 4px 0; border-radius: var(--radius);
    border: 1px solid #fed7d7; background: #fff5f5; display: flex;
    align-items: flex-start; gap: 10px; font-size: 13px;
}
.flagged-node-info { flex: 1; }
.flagged-node-name { font-weight: 600; color: var(--text); }
.flagged-node-meta { font-size: 11px; color: var(--text-muted); margin-top: 2px; }
.flagged-node-reason { font-size: 11px; color: var(--danger); margin-top: 4px; font-style: italic; }
.btn-unflag {
    padding: 4px 10px; border-radius: 4px; border: 1px solid var(--success);
    background: var(--white); color: var(--success); font-size: 11px;
    font-weight: 600; cursor: pointer; white-space: nowrap; transition: all 0.2s;
}
.btn-unflag:hover { background: var(--success); color: var(--white); }

/* ===== Citation Badges & Sources Bar ===== */
.cite-badge {
    display: inline-block; padding: 1px 6px; margin: 0 1px;
    background: var(--primary-bg); color: var(--primary);
    border: 1px solid rgba(30, 60, 114, 0.2); border-radius: 4px;
    font-size: 11px; font-weight: 600; vertical-align: baseline;
    cursor: default;
}
.sources-bar {
    align-self: flex-start; max-width: 85%; margin-top: -4px;
    font-size: 12px;
}
.sources-toggle {
    display: inline-flex; align-items: center; gap: 4px;
    cursor: pointer; color: var(--primary); font-weight: 500;
    padding: 4px 0; user-select: none;
}
.sources-toggle::before { content: '\25B6'; font-size: 8px; transition: transform 0.2s; }
.sources-bar.expanded .sources-toggle::before { transform: rotate(90deg); }
.sources-list {
    display: none; flex-wrap: wrap; gap: 4px;
    padding: 6px 0 2px;
}
.sources-bar.expanded .sources-list { display: flex; }
.source-badge {
    display: inline-block; padding: 2px 8px; background: var(--primary-bg);
    color: var(--primary); border: 1px solid rgba(30, 60, 114, 0.15);
    border-radius: 4px; font-size: 11px; font-weight: 500;
}

/* ===== Utility ===== */
.text-muted { color: var(--text-muted); }
.text-center { text-align: center; }
.mt-1 { margin-top: 8px; }
.mt-2 { margin-top: 16px; }
.mt-3 { margin-top: 24px; }
.mb-1 { margin-bottom: 8px; }
.mb-2 { margin-bottom: 16px; }
.mb-3 { margin-bottom: 24px; }
