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

/* CSS Base */
:root { --primary: #4f46e5; --bg-app: #f1f5f9; --text-main: #0f172a; --border: #e2e8f0; }
body { font-family: 'Montserrat', sans-serif; background: var(--bg-app); color: var(--text-main); margin: 0; display: flex; height: 100vh; overflow: hidden; }

/* Layout */
.sidebar { width: 350px; height: 100vh; background: #fff; border-right: 1px solid var(--border); display: flex; flex-direction: column; overflow: hidden; }
.sidebar-header { padding: 20px 20px 12px; flex: 0 0 auto; display: flex; align-items: center; justify-content: space-between; border-bottom: 1px solid var(--border); }
.sidebar-body { flex: 1 1 0; min-height: 0; overflow-y: auto; padding: 0 20px 20px; }
.sidebar-footer { flex: 0 0 auto; padding: 16px 20px; border-top: 1px solid var(--border); display: flex; gap: 10px; background: #fff; }
.sidebar-footer button { margin-top: 0; flex: 1; }
.main { flex: 1; display: flex; flex-direction: column; overflow: hidden; }
.header { height: 60px; background: #fff; border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; padding: 0 24px; }

/* Text */
.slogan { font-size: 0.7rem; color: #64748b; font-style: italic; }

/* Form */
label { font-size: 0.8rem; font-weight: 600; color: #64748b; margin-top: 15px; display: block; }
input, textarea, select { width: 100%; padding: 10px; margin-top: 5px; border: 1px solid #cbd5e1; border-radius: 6px; }
button { background: var(--primary); color: white; padding: 12px; border: none; border-radius: 6px; margin-top: 20px; cursor: pointer; font-weight: 600; width: 100%; }
button:disabled { opacity: 0.5; }

/* Panels */
.workspace { flex: 1; padding: 20px; overflow: hidden; display: grid; grid-template-columns: 2fr 1fr; gap: 20px; }

.card { background: #fff; border-radius: 8px; border: 1px solid var(--border); overflow: hidden; display: flex; flex-direction: column; min-height: 0; }
.card-head { padding: 12px 16px; background: #f8fafc; border-bottom: 1px solid var(--border); font-weight: 600; font-size: 0.9rem; }
.card-body { padding: 16px; flex: 1; overflow-y: auto; }

/* Console Log Style */
.console-box { background: #1e293b; color: #cbd5e1; font-family: 'Montserrat', sans-serif; font-size: 0.82rem; padding: 15px; border-radius: 0 0 6px 6px; height: 100%; overflow-y: auto; overflow-x: hidden; display: flex; flex-direction: column; gap: 6px; }
.log-entry { display: flex; gap: 8px; align-items: baseline; }
.log-time { color: #64748b; font-size: 0.75rem; flex-shrink: 0; }
.log-info { color: #94a3b8; }
.log-tool { color: #a78bfa; }
.log-error { color: #ef4444; }
.log-success { color: #34d399; }
.log-step { color: #60a5fa; font-weight: 600; }

/* Result textarea */
.result-area { width: 100%; height: 100%; background: #fff; border: none; resize: none; font-family: 'Montserrat', sans-serif; font-size: 0.85rem; color: var(--text-main); padding: 16px; outline: none; line-height: 1.6; }
.result-area::placeholder { color: #94a3b8; }

/* Gallery */
.gallery-item img { width: 100%; display: block; }
.gallery-caption { padding: 5px 10px; font-size: 0.75rem; background: #f8fafc; color: #64748b; }

/* KPIs */
.kpi-bar { display: flex; gap: 20px; }
.kpi { background: #fff; padding: 10px 20px; border-radius: 8px; border: 1px solid var(--border); }
.kpi-val { font-size: 1.2rem; font-weight: 700; color: var(--primary); }
.kpi-lbl { font-size: 0.75rem; color: #64748b; text-transform: uppercase; }

/* Column Wrapper */
.col-flex { display: flex; flex-direction: column; gap: 20px; height: 100%; overflow: hidden; }

/* Tasks */
.task-item { padding: 8px 0; border-bottom: 1px solid #f1f5f9; font-size: 0.9rem; display: flex; align-items: center; gap: 8px; }

/* Auth Overlay */
.auth-overlay {
    position: fixed; inset: 0; background: rgba(15,23,42,0.6); backdrop-filter: blur(4px);
    display: flex; align-items: center; justify-content: center; z-index: 1000;
}
.auth-box {
    background: #fff; border-radius: 12px; padding: 32px; width: 380px; max-width: 90vw;
    box-shadow: 0 25px 50px -12px rgba(0,0,0,0.25);
}
.auth-box h2 { color: var(--primary); margin-bottom: 4px; }
.auth-box p { color: #64748b; font-size: 0.85rem; margin-bottom: 16px; }
.auth-tabs { display: flex; gap: 0; margin-bottom: 16px; }
.auth-tab {
    flex: 1; padding: 10px; text-align: center; font-weight: 600; font-size: 0.85rem;
    cursor: pointer; border-bottom: 2px solid var(--border); color: #94a3b8; background: none; margin-top: 0;
}
.auth-tab.active { border-bottom-color: var(--primary); color: var(--primary); }
.auth-error { color: #ef4444; font-size: 0.8rem; margin-top: 8px; display: none; }
.user-info { display: flex; align-items: center; gap: 8px; font-size: 0.85rem; }
.user-info span { color: var(--primary); font-weight: 600; }
.btn-logout { background: none; border: 1px solid var(--border); color: #64748b; padding: 6px 12px; font-size: 0.75rem; margin-top: 0; width: auto; cursor: pointer; border-radius: 4px; }
.btn-logout:hover { background: #f1f5f9; }

/* Session Selector */
.session-row { display: flex; gap: 6px; align-items: stretch; margin-top: 5px; }
.session-row select { flex: 1; margin-top: 0; }
.btn-sm { background: none; border: 1px solid #cbd5e1; color: #64748b; padding: 0 10px; font-size: 0.85rem; margin-top: 0; width: auto; min-width: 36px; cursor: pointer; border-radius: 6px; display: flex; align-items: center; justify-content: center; }
.btn-sm:hover { background: #f1f5f9; }
.btn-sm.danger:hover { background: #fef2f2; color: #ef4444; border-color: #fecaca; }

/* Gallery clickable */
.gallery-item { margin-bottom: 15px; border: 1px solid var(--border); border-radius: 6px; overflow: hidden; cursor: pointer; transition: box-shadow 0.15s; }
.gallery-item:hover { box-shadow: 0 2px 8px rgba(0,0,0,0.1); }

/* Lightbox Modal */
.lightbox-overlay {
    position: fixed; inset: 0; background: rgba(0,0,0,0.85); z-index: 2000;
    display: none; align-items: center; justify-content: center; flex-direction: column;
}
.lightbox-overlay.active { display: flex; }
.lightbox-img { max-width: 90vw; max-height: 80vh; border-radius: 8px; box-shadow: 0 4px 30px rgba(0,0,0,0.4); }
.lightbox-caption { color: #fff; font-size: 0.85rem; margin-top: 12px; }
.lightbox-close { position: absolute; top: 20px; right: 24px; color: #fff; font-size: 2rem; cursor: pointer; background: none; border: none; width: auto; margin: 0; padding: 0; line-height: 1; }
.lightbox-nav { position: absolute; top: 50%; transform: translateY(-50%); color: #fff; font-size: 2.5rem; cursor: pointer; background: rgba(255,255,255,0.1); border: none; border-radius: 50%; width: 48px; height: 48px; display: flex; align-items: center; justify-content: center; margin: 0; padding: 0; }
.lightbox-nav:hover { background: rgba(255,255,255,0.2); }
.lightbox-prev { left: 20px; }
.lightbox-next { right: 20px; }
.lightbox-toolbar { position: absolute; bottom: 20px; display: flex; gap: 12px; align-items: center; }
.lightbox-toolbar label { color: #cbd5e1; font-size: 0.8rem; margin: 0; cursor: pointer; display: flex; align-items: center; gap: 6px; }
.lightbox-toolbar input[type="checkbox"] { width: auto; margin: 0; }

/* Payment Modal */
.payment-overlay {
    position: fixed; inset: 0; background: rgba(15,23,42,0.6); backdrop-filter: blur(4px);
    display: none; align-items: center; justify-content: center; z-index: 1500;
}
.payment-overlay.active { display: flex; }
.payment-box {
    background: #fff; border-radius: 12px; padding: 32px; width: 420px; max-width: 90vw;
    box-shadow: 0 25px 50px -12px rgba(0,0,0,0.25);
}
.payment-box h3 { color: var(--primary); margin-bottom: 4px; font-size: 1.1rem; }
.payment-box .payment-subtitle { color: #64748b; font-size: 0.85rem; margin-bottom: 20px; }
.payment-amount {
    text-align: center; padding: 16px; background: #f8fafc; border-radius: 8px;
    margin-bottom: 20px; border: 1px solid var(--border);
}
.payment-amount .amount-value { font-size: 1.8rem; font-weight: 700; color: var(--primary); }
.payment-amount .amount-label { font-size: 0.75rem; color: #94a3b8; text-transform: uppercase; margin-top: 4px; }
.payment-methods { display: flex; flex-direction: column; gap: 10px; margin-bottom: 20px; }
.payment-method {
    display: flex; align-items: center; gap: 12px; padding: 14px 16px;
    border: 2px solid var(--border); border-radius: 8px; cursor: pointer; transition: all 0.15s;
    background: #fff;
}
.payment-method:hover { border-color: #a5b4fc; background: #f8fafc; }
.payment-method.selected { border-color: var(--primary); background: #eef2ff; }
.payment-method input[type="radio"] { display: none; }
.payment-method-icon { font-size: 1.4rem; width: 32px; text-align: center; flex-shrink: 0; }
.payment-method-info { flex: 1; }
.payment-method-name { font-weight: 600; font-size: 0.9rem; }
.payment-method-desc { font-size: 0.75rem; color: #94a3b8; }
.payment-method-check { width: 20px; height: 20px; border-radius: 50%; border: 2px solid #cbd5e1; display: flex; align-items: center; justify-content: center; flex-shrink: 0; }
.payment-method.selected .payment-method-check { border-color: var(--primary); background: var(--primary); }
.payment-method.selected .payment-method-check::after { content: ''; width: 8px; height: 8px; background: #fff; border-radius: 50%; }
.payment-actions { display: flex; gap: 10px; }
.payment-actions button { margin-top: 0; }
.btn-cancel { background: none; border: 1px solid var(--border); color: #64748b; }
.btn-cancel:hover { background: #f1f5f9; }
.payment-success { text-align: center; padding: 20px 0; }
.payment-success .check-icon { font-size: 3rem; color: #10b981; margin-bottom: 8px; }
.payment-success p { color: #64748b; font-size: 0.9rem; }

/* File Upload Zone */
.file-drop-zone {
    border: 2px dashed #cbd5e1; border-radius: 8px; padding: 16px;
    text-align: center; cursor: pointer; transition: all 0.15s; margin-top: 5px;
}
.file-drop-zone:hover, .file-drop-zone.drag-over {
    border-color: var(--primary); background: #eef2ff;
}
.file-list { margin-top: 8px; display: flex; flex-direction: column; gap: 4px; }
.file-item {
    display: flex; align-items: center; justify-content: space-between;
    padding: 6px 10px; background: #f8fafc; border-radius: 6px;
    font-size: 0.8rem; border: 1px solid var(--border);
}
.file-item .file-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-item .file-size { color: #94a3b8; margin-left: 8px; flex-shrink: 0; }
.file-item .file-remove {
    background: none; border: none; color: #ef4444; cursor: pointer;
    margin: 0; padding: 0 4px; width: auto; font-size: 0.85rem;
}

/* Downloads Area */
.downloads-area { display: flex; flex-direction: column; gap: 8px; }
.download-item {
    display: flex; align-items: center; gap: 10px; padding: 10px 12px;
    background: #f0fdf4; border: 1px solid #bbf7d0; border-radius: 6px;
}
.download-item i { color: #10b981; font-size: 1.1rem; }
.download-item a { color: var(--primary); font-weight: 500; text-decoration: none; font-size: 0.85rem; }
.download-item a:hover { text-decoration: underline; }

/* HITL Modal */
.hitl-overlay {
    position: fixed; inset: 0; background: rgba(15,23,42,0.6); backdrop-filter: blur(4px);
    display: none; align-items: center; justify-content: center; z-index: 1600;
}
.hitl-overlay.active { display: flex; }
.hitl-box {
    background: #fff; border-radius: 12px; padding: 28px; width: 520px; max-width: 90vw;
    box-shadow: 0 25px 50px -12px rgba(0,0,0,0.25); max-height: 90vh; overflow-y: auto;
}
.hitl-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 16px; }
.hitl-header h3 { color: var(--text-main); margin: 0; font-size: 1rem; }
.hitl-timer {
    background: #fef3c7; color: #92400e; font-weight: 700; font-size: 0.85rem;
    padding: 4px 10px; border-radius: 6px; font-variant-numeric: tabular-nums;
}
.hitl-screenshot {
    margin-bottom: 16px; border-radius: 8px; overflow: hidden; border: 1px solid var(--border);
    max-height: 250px; overflow-y: auto;
}
.hitl-screenshot img { width: 100%; display: block; }
.hitl-question {
    background: #fffbeb; border: 1px solid #fde68a; border-radius: 8px; padding: 12px 16px;
    font-size: 0.9rem; color: #92400e; margin-bottom: 8px; line-height: 1.5;
}
.hitl-context { font-size: 0.8rem; color: #64748b; margin-bottom: 16px; line-height: 1.4; }
.hitl-context:empty { display: none; }
.hitl-input-area { margin-bottom: 16px; }
.hitl-input-area textarea { margin-top: 6px; }
.hitl-actions { display: flex; gap: 10px; }
.hitl-actions button { margin-top: 0; }

/* Custom Tools */
.custom-tools-list { display: flex; flex-direction: column; gap: 6px; margin-top: 5px; }
.custom-tool-item {
    display: flex; align-items: center; justify-content: space-between;
    padding: 8px 10px; background: #f8fafc; border: 1px solid var(--border);
    border-radius: 6px; font-size: 0.8rem;
}
.custom-tool-info { flex: 1; overflow: hidden; }
.custom-tool-name { font-weight: 600; color: var(--primary); display: block; }
.custom-tool-desc { color: #94a3b8; font-size: 0.75rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; display: block; }
.custom-tool-actions { display: flex; gap: 4px; flex-shrink: 0; margin-left: 8px; }
.btn-add-tool {
    background: none; border: 1px dashed #cbd5e1; color: #64748b; padding: 8px;
    font-size: 0.8rem; margin-top: 6px; cursor: pointer; border-radius: 6px; width: 100%;
}
.btn-add-tool:hover { border-color: var(--primary); color: var(--primary); background: #eef2ff; }

/* Tool Builder Modal */
.tool-modal-overlay {
    position: fixed; inset: 0; background: rgba(15,23,42,0.6); backdrop-filter: blur(4px);
    display: none; align-items: center; justify-content: center; z-index: 1700;
}
.tool-modal-overlay.active { display: flex; }
.tool-modal-box {
    background: #fff; border-radius: 12px; padding: 28px; width: 480px; max-width: 90vw;
    box-shadow: 0 25px 50px -12px rgba(0,0,0,0.25); max-height: 90vh; overflow-y: auto;
}
.tool-return-option {
    flex: 1; display: flex; align-items: center; justify-content: center; gap: 6px;
    padding: 8px 12px; border: 2px solid var(--border); border-radius: 6px;
    cursor: pointer; font-size: 0.82rem; font-weight: 500; color: #64748b;
    background: #fff; margin-top: 0; transition: all 0.15s;
}
.tool-return-option:hover { border-color: #a5b4fc; }
.tool-return-option.selected { border-color: var(--primary); color: var(--primary); background: #eef2ff; }
.tool-fields { display: flex; flex-direction: column; gap: 8px; margin-top: 5px; }
.tool-field-group { border: 1px solid var(--border); border-radius: 6px; padding: 8px; background: #fafbfc; }
.tool-field-row {
    display: flex; gap: 6px; align-items: center;
}
.tool-field-row input, .tool-field-row select { margin-top: 0; }
.tool-field-row .btn-sm { height: 38px; width: 38px; min-width: 38px; flex-shrink: 0; }
.tool-field-required-btn {
    display: flex; align-items: center; justify-content: center;
    width: 38px; height: 38px; min-width: 38px; flex-shrink: 0;
    border: 1px solid #cbd5e1; border-radius: 6px; background: #fff;
    color: #cbd5e1; cursor: pointer; font-size: 0.7rem;
    margin: 0; padding: 0; transition: all 0.15s;
}
.tool-field-required-btn:hover { border-color: #a5b4fc; color: #a5b4fc; }
.tool-field-required-btn.active { background: var(--primary); border-color: var(--primary); color: #fff; }
.tool-field-options { padding-top: 8px; margin-top: 8px; border-top: 1px solid var(--border); }
.tool-field-opt-row { margin-bottom: 6px; }
.tool-field-opt-row:last-child { margin-bottom: 0; }
.tool-field-opt-row label { font-size: 0.72rem; margin-top: 0; }
.tool-field-opt-row input { font-size: 0.8rem; padding: 6px 8px; }
.btn-add-field {
    background: none; border: 1px dashed #cbd5e1; color: #64748b; padding: 6px;
    font-size: 0.75rem; margin-top: 6px; cursor: pointer; border-radius: 4px; width: 100%;
}
.btn-add-field:hover { border-color: var(--primary); color: var(--primary); }

/* Run History */
.run-history-item {
    display: flex; align-items: center; gap: 8px; padding: 8px 10px;
    border-radius: 6px; cursor: pointer; transition: background 0.15s;
    border: 1px solid transparent; font-size: 0.8rem;
}
.run-history-item:hover { background: #f8fafc; border-color: var(--border); }
.run-history-item.active { background: #eef2ff; border-color: #a5b4fc; }
.run-history-status { flex-shrink: 0; font-size: 0.75rem; }
.run-history-info { flex: 1; overflow: hidden; display: flex; flex-direction: column; gap: 1px; }
.run-history-time { font-size: 0.72rem; color: #64748b; }
.run-history-url { font-size: 0.72rem; color: #94a3b8; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.run-history-cost { font-size: 0.72rem; color: #64748b; flex-shrink: 0; font-weight: 600; }

/* Mobile */
@media(max-width: 900px) { .workspace { grid-template-columns: 1fr; overflow-y: auto; } .col-flex { height: auto; overflow: visible; } body { overflow: auto; height: auto; flex-direction: column; } .sidebar { width: 100%; height: auto; overflow: visible; } .sidebar-body { overflow: visible; } }
