/* ============ YuB-X Luau Forge ============ */
:root {
    --bg-0: #0b0d12;
    --bg-1: #11141c;
    --bg-2: #171b26;
    --bg-3: #1f2431;
    --bg-hover: #252b3a;
    --border: #2a3040;
    --border-light: #353d52;

    --text: #e6e9ef;
    --text-dim: #9aa3b8;
    --text-muted: #6b7489;

    --accent: #7c5cff;
    --accent-2: #5b8cff;
    --accent-glow: rgba(124, 92, 255, 0.35);

    --success: #22c55e;
    --success-bg: rgba(34, 197, 94, 0.12);
    --warning: #f59e0b;
    --warning-bg: rgba(245, 158, 11, 0.12);
    --error: #ef4444;
    --error-bg: rgba(239, 68, 68, 0.12);
    --info: #3b82f6;
    --info-bg: rgba(59, 130, 246, 0.12);

    --font-body: 'Inter', -apple-system, sans-serif;
    --font-mono: 'JetBrains Mono', 'Fira Code', monospace;

    --radius: 10px;
    --radius-lg: 14px;
    --shadow: 0 4px 20px rgba(0, 0, 0, 0.4);
    --shadow-lg: 0 8px 40px rgba(0, 0, 0, 0.6);
}

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

html, body {
    height: 100%;
    font-family: var(--font-body);
    background: var(--bg-0);
    color: var(--text);
    font-size: 14px;
    overflow: hidden;
}

body {
    display: flex;
    flex-direction: column;
    background:
        radial-gradient(1200px 600px at 10% -10%, rgba(124, 92, 255, 0.15), transparent 70%),
        radial-gradient(1000px 500px at 100% 110%, rgba(91, 140, 255, 0.10), transparent 70%),
        var(--bg-0);
}

/* ======================== HEADER ======================== */
.app-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 22px;
    background: rgba(17, 20, 28, 0.85);
    backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--border);
    z-index: 10;
}

.header-left {
    display: flex;
    align-items: center;
    gap: 14px;
}

.logo {
    width: 44px;
    height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, var(--accent), var(--accent-2));
    border-radius: 12px;
    font-size: 20px;
    color: white;
    box-shadow: 0 4px 20px var(--accent-glow);
}

.app-header h1 {
    font-size: 18px;
    font-weight: 700;
    letter-spacing: -0.01em;
}

.subtitle {
    font-size: 12px;
    color: var(--text-dim);
    margin-top: 2px;
}

.header-right {
    display: flex;
    align-items: center;
    gap: 10px;
}

.engine-badge, .commit-badge {
    padding: 7px 12px;
    background: var(--bg-2);
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 12px;
    color: var(--text-dim);
    font-family: var(--font-mono);
}
.engine-badge b, .commit-badge b { color: var(--text); font-weight: 600; }

/* ======================== TABS ======================== */
.tab-bar {
    display: flex;
    gap: 2px;
    padding: 0 22px;
    background: var(--bg-1);
    border-bottom: 1px solid var(--border);
    overflow-x: auto;
    flex-shrink: 0;
}

.tab {
    padding: 12px 18px;
    background: transparent;
    color: var(--text-dim);
    border: none;
    border-bottom: 2px solid transparent;
    font-family: var(--font-body);
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.15s;
    display: flex;
    align-items: center;
    gap: 8px;
    white-space: nowrap;
}
.tab:hover { color: var(--text); background: var(--bg-hover); }
.tab.active {
    color: var(--text);
    border-bottom-color: var(--accent);
}
.tab i { font-size: 13px; }

/* ======================== MAIN ======================== */
.app-main {
    flex: 1;
    overflow: hidden;
    position: relative;
}

.tab-panel {
    position: absolute;
    inset: 0;
    display: none;
    flex-direction: column;
    padding: 18px 22px;
    overflow: auto;
}
.tab-panel.active { display: flex; }

/* ======================== BUTTONS ======================== */
.btn {
    padding: 9px 15px;
    border-radius: 8px;
    border: 1px solid var(--border);
    background: var(--bg-2);
    color: var(--text);
    font-family: var(--font-body);
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 7px;
    transition: all 0.15s;
    text-decoration: none;
}
.btn:hover { background: var(--bg-hover); border-color: var(--border-light); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-primary {
    background: linear-gradient(135deg, var(--accent), var(--accent-2));
    border-color: transparent;
    color: white;
}
.btn-primary:hover { filter: brightness(1.1); box-shadow: 0 4px 16px var(--accent-glow); }

.btn-secondary {
    background: var(--bg-3);
}

.btn-success {
    background: linear-gradient(135deg, #22c55e, #16a34a);
    border-color: transparent;
    color: white;
}
.btn-success:hover { filter: brightness(1.1); box-shadow: 0 4px 16px rgba(34, 197, 94, 0.3); }

.btn-ghost {
    background: transparent;
    border-color: var(--border);
}
.btn-ghost:hover { background: var(--bg-2); }

.btn-lg { padding: 11px 20px; font-size: 14px; font-weight: 600; }
.btn-xl { padding: 14px 28px; font-size: 15px; font-weight: 600; }
.btn-sm { padding: 6px 11px; font-size: 12px; }

.btn-icon {
    width: 32px;
    height: 32px;
    border-radius: 6px;
    background: transparent;
    border: none;
    color: var(--text-dim);
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: all 0.15s;
}
.btn-icon:hover { background: var(--bg-hover); color: var(--text); }

/* ======================== INPUTS ======================== */
.input, .select {
    padding: 9px 12px;
    background: var(--bg-2);
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text);
    font-family: var(--font-body);
    font-size: 13px;
    outline: none;
    min-width: 180px;
    transition: border-color 0.15s;
}
.input:focus, .select:focus { border-color: var(--accent); }

.check {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    font-size: 13px;
    color: var(--text-dim);
    user-select: none;
}
.check input[type="checkbox"] {
    width: 16px;
    height: 16px;
    accent-color: var(--accent);
    cursor: pointer;
}

/* ======================== EDITOR TAB ======================== */
.toolbar {
    display: flex;
    gap: 14px;
    align-items: center;
    margin-bottom: 14px;
    flex-wrap: wrap;
}
.toolbar-group {
    display: flex;
    gap: 8px;
    align-items: center;
}
.toolbar-group.right { margin-left: auto; }

.editor-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 14px;
    flex: 1;
    min-height: 0;
    margin-bottom: 12px;
}

.editor-card {
    background: var(--bg-1);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    overflow: hidden;
    display: flex;
    flex-direction: column;
    min-height: 500px;
}

.editor-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 14px;
    background: var(--bg-2);
    border-bottom: 1px solid var(--border);
}
.editor-header > div:first-child {
    display: flex;
    align-items: center;
    gap: 10px;
}
.editor-header i { color: var(--accent); }
.editor-title {
    font-weight: 600;
    font-family: var(--font-mono);
    font-size: 13px;
}
.editor-stats {
    font-size: 11px;
    color: var(--text-dim);
    background: var(--bg-3);
    padding: 3px 8px;
    border-radius: 10px;
    margin-left: 4px;
}
.editor-actions {
    display: flex;
    gap: 4px;
}
.editor-container {
    flex: 1;
    min-height: 0;
}

.summary-bar {
    display: flex;
    gap: 20px;
    padding: 10px 16px;
    background: var(--bg-1);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 13px;
    color: var(--text-dim);
    align-items: center;
}
.summary-bar b { color: var(--text); }
.summary-bar i { color: var(--accent); margin-right: 4px; }
.summary-bar .spacer { flex: 1; }

/* ======================== BUILD TAB ======================== */
.build-wrapper {
    display: grid;
    grid-template-columns: 360px 1fr;
    gap: 16px;
    flex: 1;
    min-height: 0;
}

.build-config, .build-status {
    background: var(--bg-1);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 20px;
    overflow: auto;
}

.build-config h2, .build-status h2 {
    font-size: 16px;
    font-weight: 600;
    margin-bottom: 16px;
    display: flex;
    align-items: center;
    gap: 10px;
}
.build-config h2 i, .build-status h2 i { color: var(--accent); }

.form-row { margin-bottom: 14px; }
.form-row label { display: flex; flex-direction: column; gap: 6px; }
.form-row label > span { font-size: 12px; color: var(--text-dim); font-weight: 500; }
.form-row .input, .form-row .select { width: 100%; }

.form-row.checkboxes {
    display: flex;
    flex-direction: column;
    gap: 10px;
    padding: 14px;
    background: var(--bg-2);
    border-radius: var(--radius);
    margin-bottom: 16px;
}

.hint {
    font-size: 12px;
    color: var(--text-muted);
    margin-top: 10px;
    line-height: 1.5;
}
.hint i { color: var(--info); margin-right: 4px; }

/* Stages */
.stage-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-bottom: 16px;
}
.stage {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 12px 14px;
    background: var(--bg-2);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    transition: all 0.25s;
}
.stage.active {
    border-color: var(--accent);
    background: linear-gradient(135deg, rgba(124, 92, 255, 0.08), var(--bg-2));
    box-shadow: 0 0 0 3px var(--accent-glow);
}
.stage.done {
    border-color: var(--success);
    background: var(--success-bg);
}
.stage.error {
    border-color: var(--error);
    background: var(--error-bg);
}
.stage-icon {
    width: 36px;
    height: 36px;
    border-radius: 8px;
    background: var(--bg-3);
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-dim);
    flex-shrink: 0;
}
.stage.active .stage-icon { background: var(--accent); color: white; }
.stage.done .stage-icon { background: var(--success); color: white; }
.stage.error .stage-icon { background: var(--error); color: white; }
.stage-body { flex: 1; min-width: 0; }
.stage-title { font-size: 13px; font-weight: 600; margin-bottom: 2px; }
.stage-meta { font-size: 11px; color: var(--text-dim); font-family: var(--font-mono); }
.stage-status i { font-size: 18px; color: var(--text-muted); }
.stage.active .stage-status i { color: var(--accent); animation: spin 1s linear infinite; }
.stage.done .stage-status i { color: var(--success); }
.stage.error .stage-status i { color: var(--error); }

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

.progress-bar-wrap {
    height: 6px;
    background: var(--bg-3);
    border-radius: 3px;
    overflow: hidden;
    margin-bottom: 16px;
}
.progress-bar {
    height: 100%;
    width: 0;
    background: linear-gradient(90deg, var(--accent), var(--accent-2));
    transition: width 0.3s;
}

.build-summary {
    padding: 18px;
    background: linear-gradient(135deg, rgba(34, 197, 94, 0.10), rgba(34, 197, 94, 0.02));
    border: 1px solid rgba(34, 197, 94, 0.3);
    border-radius: var(--radius-lg);
    margin-top: 14px;
}
.build-summary h3 {
    font-size: 14px;
    margin-bottom: 14px;
    display: flex;
    align-items: center;
    gap: 8px;
    color: var(--success);
}

.stats-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 8px;
    margin-bottom: 14px;
}
.stat {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 10px;
    background: var(--bg-2);
    border-radius: 8px;
}
.stat .num {
    font-size: 20px;
    font-weight: 700;
    color: var(--text);
    font-family: var(--font-mono);
}
.stat .lbl {
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-dim);
    margin-top: 2px;
}

/* ======================== PIPELINE TAB ======================== */
.pipeline-header, .coverage-header, .diff-header, .config-header, .history-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 14px;
    gap: 14px;
    flex-wrap: wrap;
}
.pipeline-header h2, .coverage-header h2, .diff-header h2, .config-header h2, .history-header h2 {
    font-size: 16px;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 10px;
}
.pipeline-header h2 i, .coverage-header h2 i, .diff-header h2 i, .config-header h2 i, .history-header h2 i {
    color: var(--accent);
}
.filter-group {
    display: flex;
    gap: 10px;
    align-items: center;
}

.pipeline-log {
    flex: 1;
    background: var(--bg-1);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 12px;
    overflow: auto;
    font-family: var(--font-mono);
    font-size: 12px;
    line-height: 1.7;
}

.log-line {
    padding: 3px 10px;
    display: flex;
    align-items: center;
    gap: 10px;
    border-radius: 4px;
}
.log-line:hover { background: var(--bg-hover); }
.log-tag {
    display: inline-block;
    padding: 1px 7px;
    border-radius: 4px;
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    min-width: 48px;
    text-align: center;
    flex-shrink: 0;
}
.log-tag.ADD { background: var(--success-bg); color: var(--success); }
.log-tag.UPD { background: var(--warning-bg); color: var(--warning); }
.log-tag.MOD { background: rgba(124, 92, 255, 0.15); color: var(--accent); }
.log-tag.UNC { background: var(--bg-3); color: var(--text-muted); }
.log-tag.KEEP { background: var(--bg-3); color: var(--text-muted); }
.log-path { color: var(--text); }
.log-tags {
    font-size: 11px;
    color: var(--text-dim);
    margin-left: auto;
}
.log-tags .tag {
    display: inline-block;
    padding: 1px 6px;
    background: var(--bg-3);
    border-radius: 3px;
    margin-left: 4px;
}

/* ======================== COVERAGE TAB ======================== */
.coverage-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 14px;
    flex: 1;
    min-height: 0;
}
.coverage-card {
    background: var(--bg-1);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 16px;
    overflow: auto;
    display: flex;
    flex-direction: column;
}
.coverage-card h3 {
    font-size: 14px;
    margin-bottom: 12px;
    display: flex;
    align-items: center;
    gap: 8px;
}
.coverage-card h3 i { color: var(--accent); }

.coverage-list {
    display: flex;
    flex-direction: column;
    gap: 6px;
    flex: 1;
}

.coverage-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 12px;
    background: var(--bg-2);
    border-radius: 6px;
    border-left: 3px solid var(--border);
    font-size: 12px;
}
.coverage-item.matched { border-left-color: var(--success); }
.coverage-item.unmatched { border-left-color: var(--error); }
.coverage-item.inserted { border-left-color: var(--info); }
.coverage-name {
    font-family: var(--font-mono);
    font-weight: 600;
    color: var(--text);
    min-width: 150px;
}
.coverage-meta {
    color: var(--text-dim);
    font-size: 11px;
    margin-left: auto;
    font-family: var(--font-mono);
}
.coverage-status {
    font-size: 10px;
    padding: 2px 7px;
    border-radius: 3px;
    text-transform: uppercase;
    font-weight: 700;
}
.coverage-item.matched .coverage-status { background: var(--success-bg); color: var(--success); }
.coverage-item.unmatched .coverage-status { background: var(--error-bg); color: var(--error); }
.coverage-item.inserted .coverage-status { background: var(--info-bg); color: var(--info); }

/* ======================== DIFF TAB ======================== */
.diff-viewer {
    flex: 1;
    background: var(--bg-1);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    overflow: auto;
    min-height: 0;
}

.diff-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1px;
    background: var(--border);
    height: 100%;
}
.diff-pane {
    background: var(--bg-1);
    overflow: auto;
    font-family: var(--font-mono);
    font-size: 12px;
    display: flex;
    flex-direction: column;
}
.diff-pane-header {
    padding: 8px 14px;
    background: var(--bg-2);
    border-bottom: 1px solid var(--border);
    font-weight: 600;
    font-size: 12px;
    position: sticky;
    top: 0;
    z-index: 1;
}
.diff-pane-header.before { color: #ff8a8a; }
.diff-pane-header.after { color: #7ee37e; }
.diff-content {
    padding: 10px 14px;
    white-space: pre;
    line-height: 1.6;
    flex: 1;
    overflow: auto;
}
.diff-line { display: block; padding: 0 6px; }
.diff-line.add { background: rgba(34, 197, 94, 0.12); color: #b7f3c3; }
.diff-line.del { background: rgba(239, 68, 68, 0.12); color: #ffbaba; }

/* ======================== CONFIG TAB ======================== */
.config-section {
    background: var(--bg-1);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 16px;
    margin-bottom: 14px;
}
.section-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 12px;
}
.section-head h3 {
    font-size: 14px;
    font-family: var(--font-mono);
}
.section-head h3 small {
    font-size: 11px;
    color: var(--text-dim);
    font-family: var(--font-body);
    font-weight: 400;
}
.config-table {
    display: flex;
    flex-direction: column;
    gap: 6px;
}
.config-row {
    display: grid;
    grid-template-columns: 1fr 1.5fr auto;
    gap: 8px;
    align-items: center;
}
.config-row .input { min-width: 0; font-family: var(--font-mono); font-size: 12px; }
.config-actions {
    display: flex;
    gap: 10px;
    justify-content: flex-end;
    margin-top: 12px;
}

/* ======================== HISTORY ======================== */
.history-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
}
.history-item {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 14px 18px;
    background: var(--bg-1);
    border: 1px solid var(--border);
    border-radius: var(--radius);
}
.history-icon {
    width: 40px;
    height: 40px;
    border-radius: 8px;
    background: var(--success-bg);
    color: var(--success);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    flex-shrink: 0;
}
.history-body { flex: 1; }
.history-title { font-weight: 600; margin-bottom: 4px; }
.history-meta {
    font-size: 11px;
    color: var(--text-dim);
    font-family: var(--font-mono);
    display: flex;
    gap: 12px;
}

/* ======================== EMPTY STATES ======================== */
.empty-state {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 60px 20px;
    color: var(--text-muted);
    text-align: center;
}
.empty-state i {
    font-size: 48px;
    margin-bottom: 12px;
    opacity: 0.4;
}
.empty-state.mini { padding: 30px; }
.empty-state.mini i { font-size: 28px; }

/* ======================== TOAST ======================== */
.toast-container {
    position: fixed;
    top: 80px;
    right: 22px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    z-index: 1000;
    pointer-events: none;
}
.toast {
    padding: 12px 16px;
    background: var(--bg-2);
    border: 1px solid var(--border);
    border-left: 4px solid var(--accent);
    border-radius: 8px;
    box-shadow: var(--shadow);
    min-width: 240px;
    max-width: 400px;
    display: flex;
    gap: 10px;
    align-items: center;
    animation: slideIn 0.25s;
    font-size: 13px;
    pointer-events: auto;
}
.toast.success { border-left-color: var(--success); }
.toast.error { border-left-color: var(--error); }
.toast.warning { border-left-color: var(--warning); }
.toast.info { border-left-color: var(--info); }

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

/* ======================== MODAL ======================== */
.modal {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(4px);
    z-index: 2000;
    align-items: center;
    justify-content: center;
    padding: 20px;
}
.modal.open { display: flex; }
.modal-content {
    background: var(--bg-1);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    max-width: 600px;
    width: 100%;
    max-height: 80vh;
    overflow: auto;
    box-shadow: var(--shadow-lg);
}
.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 18px 22px;
    border-bottom: 1px solid var(--border);
}
.modal-header h2 {
    font-size: 16px;
    display: flex;
    align-items: center;
    gap: 10px;
}
.modal-header h2 i { color: var(--accent); }
.modal-body {
    padding: 22px;
    line-height: 1.7;
}
.modal-body h3 {
    font-size: 14px;
    margin: 18px 0 8px;
    color: var(--accent);
}
.modal-body h3:first-child { margin-top: 0; }
.modal-body ol { padding-left: 22px; }
.modal-body li { margin-bottom: 6px; }
.modal-body code {
    font-family: var(--font-mono);
    font-size: 12px;
    background: var(--bg-3);
    padding: 1px 6px;
    border-radius: 3px;
}

/* ======================== SCROLLBARS ======================== */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: var(--bg-0); }
::-webkit-scrollbar-thumb { background: var(--bg-3); border-radius: 5px; border: 2px solid var(--bg-0); }
::-webkit-scrollbar-thumb:hover { background: var(--border-light); }

/* ======================== RESPONSIVE ======================== */
@media (max-width: 1100px) {
    .editor-grid { grid-template-columns: 1fr; }
    .build-wrapper { grid-template-columns: 1fr; }
    .coverage-grid { grid-template-columns: 1fr; }
    .diff-grid { grid-template-columns: 1fr; }
    .stats-grid { grid-template-columns: repeat(2, 1fr); }
}
