/* Local Fonts for Offline Support */
@font-face {
  font-family: 'Outfit';
  font-style: normal;
  font-weight: 300;
  font-display: swap;
  src: url('/v1/fonts/outfit-300.ttf') format('truetype');
}
@font-face {
  font-family: 'Outfit';
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url('/v1/fonts/outfit-400.ttf') format('truetype');
}
@font-face {
  font-family: 'Outfit';
  font-style: normal;
  font-weight: 500;
  font-display: swap;
  src: url('/v1/fonts/outfit-500.ttf') format('truetype');
}
@font-face {
  font-family: 'Outfit';
  font-style: normal;
  font-weight: 600;
  font-display: swap;
  src: url('/v1/fonts/outfit-600.ttf') format('truetype');
}
@font-face {
  font-family: 'Outfit';
  font-style: normal;
  font-weight: 700;
  font-display: swap;
  src: url('/v1/fonts/outfit-700.ttf') format('truetype');
}

:root {
            --primary: #6366f1;
            --primary-hover: #4f46e5;
            --bg: #0f172a;
            --card-bg: #1e293b;
            --text-main: #f8fafc;
            --text-muted: #94a3b8;
            --border: #334155;
            --success: #10b981;
            --danger: #ef4444;
            --glass: rgba(30, 41, 59, 0.7);
        }

        * { box-sizing: border-box; margin: 0; padding: 0; }
        body { 
            font-family: 'Outfit', sans-serif; 
            background: var(--bg); 
            color: var(--text-main);
            line-height: 1.6;
            overflow-x: hidden;
        }
        
        /* Custom Scrollbar */
        ::-webkit-scrollbar {
            width: 8px;
            height: 8px;
        }
        ::-webkit-scrollbar-track {
            background: var(--bg);
        }
        ::-webkit-scrollbar-thumb {
            background: var(--border);
            border-radius: 10px;
        }
        ::-webkit-scrollbar-thumb:hover {
            background: var(--text-muted);
        }
        
        /* Firefox Scrollbar Support */
        * {
            scrollbar-width: thin;
            scrollbar-color: var(--border) var(--bg);
        }

        /* Ambient Background */
        body::before {
            content: '';
            position: fixed; top: -10%; left: -10%; width: 40%; height: 40%;
            background: radial-gradient(circle, rgba(99, 102, 241, 0.15) 0%, transparent 70%);
            z-index: -1;
        }

        .container { 
            max-width: 1100px; 
            margin: 40px auto; 
            padding: 0 24px;
            animation: fadeIn 0.6s ease-out;
        }

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

        h1 { font-weight: 700; font-size: 1.8rem; letter-spacing: -0.025em; }

        .card {
            background: var(--card-bg);
            border-radius: 16px;
            box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
            padding: 32px;
            border: 1px solid var(--border);
            backdrop-filter: blur(8px);
        }

        /* Tabs */
        .tabs {
            display: flex;
            gap: 12px;
            margin-bottom: 32px;
            background: rgba(15, 23, 42, 0.5);
            padding: 6px;
            border-radius: 12px;
            width: fit-content;
        }
        .tab-btn {
            padding: 10px 24px;
            border-radius: 8px;
            cursor: pointer;
            font-weight: 600;
            color: var(--text-muted);
            transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
            border: none;
            background: transparent;
            font-size: 0.95rem;
        }
        .tab-btn:hover { color: var(--text-main); background: rgba(255,255,255,0.05); }
        .tab-btn.active {
            background: var(--primary);
            color: white;
            box-shadow: 0 4px 12px rgba(99, 102, 241, 0.3);
        }

        .section { display: none; }
        .section.active { display: block; }

        /* Forms */
        .form-grid {
            display: grid;
            grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
            gap: 16px;
            margin-bottom: 24px;
        }
        .form-group { display: flex; flex-direction: column; gap: 8px; }
        label { font-size: 0.85rem; font-weight: 500; color: var(--text-muted); }
        input, select, textarea {
            padding: 12px 16px;
            border: 1px solid var(--border);
            border-radius: 10px;
            font-size: 0.95rem;
            width: 100%;
            background: rgba(15, 23, 42, 0.5);
            color: white;
            transition: all 0.2s;
        }
        input:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.2); }

        button {
            padding: 12px 24px;
            border-radius: 10px;
            font-weight: 600;
            cursor: pointer;
            transition: all 0.2s;
            border: none;
            background: var(--primary);
            color: white;
            display: inline-flex;
            align-items: center;
            justify-content: center;
            gap: 8px;
        }
        button:hover { background: var(--primary-hover); transform: translateY(-2px); box-shadow: 0 8px 15px -3px rgba(0, 0, 0, 0.3); }
        button:active { transform: translateY(0); }
        button.secondary { background: #334155; color: white; }
        button.secondary:hover { background: #475569; }
        button.danger { background: rgba(239, 68, 68, 0.15); color: #f87171; border: 1px solid rgba(239, 68, 68, 0.2); }
        button.danger:hover { background: var(--danger); color: white; }
        button.outline { background: transparent; border: 1px solid var(--border); color: var(--text-main); }
        button.outline:hover { background: rgba(255,255,255,0.05); }

        /* Table */
        .table-container { overflow-x: auto; margin-top: 24px; border-radius: 12px; border: 1px solid var(--border); }
        table { width: 100%; border-collapse: collapse; text-align: left; }
        th { 
            padding: 16px; 
            background: rgba(15, 23, 42, 0.3);
            color: var(--text-muted); 
            font-weight: 600;
            font-size: 0.75rem;
            text-transform: uppercase;
            letter-spacing: 0.05em;
        }
        td { padding: 16px; border-bottom: 1px solid var(--border); font-size: 0.95rem; }
        tr:last-child td { border-bottom: none; }
        tr:hover { background: rgba(255, 255, 255, 0.02); }

        /* Badges */
        .badge {
            padding: 4px 10px; border-radius: 20px; font-size: 0.75rem; font-weight: 600;
        }
        .badge-blue { background: rgba(59, 130, 246, 0.2); color: #60a5fa; }

        /* Modal */
        .modal-overlay {
            position: fixed; top: 0; left: 0; width: 100%; height: 100%;
            background: rgba(0,0,0,0.7); backdrop-filter: blur(6px);
            display: none; justify-content: center; align-items: center; z-index: 2000;
        }
        .modal {
            background: var(--card-bg); border-radius: 20px; width: 500px; max-width: 90%;
            max-height: 90vh; overflow-y: auto;
            padding: 32px; border: 1px solid var(--border); box-shadow: 0 25px 50px -12px rgba(0,0,0,0.5);
            animation: modalScale 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
            scrollbar-gutter: stable;
        }
        .modal-lg { width: 700px; }
        @keyframes modalScale { from { transform: scale(0.9); opacity: 0; } to { transform: scale(1); opacity: 1; } }
        .modal-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 24px; }
        .modal-footer { display: flex; justify-content: flex-end; gap: 12px; margin-top: 32px; }

        /* Login Overlay */
        #login-overlay {
            position: fixed; top: 0; left: 0; width: 100%; height: 100%;
            background: var(--bg); display: flex; justify-content: center; align-items: center;
            z-index: 3000;
        }
        .login-box { 
            background: var(--card-bg); padding: 48px; border-radius: 24px; width: 420px; 
            border: 1px solid var(--border); text-align: center;
            box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
        }
        .login-box h2 { font-size: 2rem; margin-bottom: 12px; }
        .login-box p { color: var(--text-muted); margin-bottom: 32px; }

        #status {
            position: fixed; bottom: 32px; left: 50%; transform: translateX(-50%);
            padding: 14px 28px; border-radius: 12px; color: white; font-weight: 600;
            z-index: 4000; display: none; box-shadow: 0 20px 25px -5px rgba(0,0,0,0.3);
            transition: all 0.3s;
        }

        @keyframes fadeIn { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }

        .btn-icon { width: 36px; height: 36px; padding: 0; display: inline-flex; align-items: center; justify-content: center; border-radius: 8px; }
        
        #main-app { display: none; }

        /* CodeMirror Overrides */
        .CodeMirror {
            border-radius: 10px;
            border: 1px solid var(--border);
            font-family: Consolas, Monaco, 'Courier New', monospace;
            font-size: 14px;
            height: 300px; /* Cố định chiều cao để có scroll riêng */
            margin-top: 4px;
            position: relative;
        }
        .CodeMirror-scroll {
            height: 300px;
        }
        
        /* Fullscreen Mode for CodeMirror */
        .CodeMirror-fullscreen {
            position: fixed !important;
            top: 0; left: 0; right: 0; bottom: 0;
            height: auto !important;
            z-index: 9999;
            border-radius: 0;
        }
        .CodeMirror-fullscreen .CodeMirror-scroll {
            height: 100vh !important;
        }
        
        .editor-container {
            position: relative;
        }
        
        .expand-btn {
            position: absolute;
            top: 10px;
            right: 25px;
            z-index: 10;
            background: rgba(15, 23, 42, 0.8);
            border: 1px solid var(--border);
            color: var(--text-muted);
            padding: 4px 8px;
            border-radius: 4px;
            font-size: 0.7rem;
            cursor: pointer;
            transition: all 0.2s;
        }
        .expand-btn:hover {
            color: white;
            border-color: var(--primary);
            background: var(--primary);
        }

        /* List Items Styling */
        .list-item-card {
            background: rgba(30, 41, 59, 0.4);
            padding: 20px;
            border-radius: 12px;
            border: 1px solid var(--border);
            position: relative;
            transition: all 0.2s ease;
            margin-bottom: 8px;
        }
        .list-item-card:hover {
            border-color: var(--primary);
            background: rgba(30, 41, 59, 0.6);
            box-shadow: 0 4px 20px -5px rgba(0, 0, 0, 0.3);
        }
        .list-item-card .remove-btn {
            position: absolute;
            top: 12px;
            right: 12px;
            opacity: 0.5;
            transition: opacity 0.2s;
        }
        .list-item-card:hover .remove-btn {
            opacity: 1;
        }
        
        /* Make form-grid in list more compact */
        /* History & Action Icons */
        .btn-group { display: flex; gap: 4px; justify-content: flex-end; }
        .btn-action { 
            width: 32px; height: 32px; padding: 0; border-radius: 6px; 
            background: rgba(255,255,255,0.05); border: 1px solid var(--border);
            color: var(--text-muted);
        }
        .btn-action:hover { color: white; background: var(--primary); border-color: var(--primary); }
        .btn-action.run:hover { background: var(--success); border-color: var(--success); }
        .btn-action.history:hover { background: #f59e0b; border-color: #f59e0b; }
        .btn-action.danger:hover { background: var(--danger); border-color: var(--danger); }

        .status-badge {
            padding: 4px 10px; border-radius: 20px; font-size: 0.75rem; font-weight: 600;
            display: inline-flex; align-items: center; gap: 6px;
        }
        .status-running { background: rgba(59, 130, 246, 0.2); color: #60a5fa; }
        .status-success { background: rgba(16, 185, 129, 0.2); color: #34d399; }
        .status-failed { background: rgba(239, 68, 68, 0.2); color: #f87171; }
        
        .trigger-system { color: var(--text-muted); font-size: 0.8rem; font-weight: 500; }
        .trigger-manual { color: var(--primary); font-size: 0.8rem; font-weight: 600; }
        
        .log-error-detail { 
            background: #000; padding: 12px; border-radius: 8px; 
            font-family: monospace; font-size: 0.8rem; color: #f87171;
            overflow-x: auto; white-space: pre-wrap; margin-top: 8px;
            border: 1px solid #450a0a;
            max-height: 300px;
            scrollbar-color: #450a0a #000;
        }
        
        /* JSON display styling */
        pre {
            background: rgba(0,0,0,0.3);
            padding: 16px;
            border-radius: 10px;
            border: 1px solid var(--border);
            overflow: auto;
            max-height: 400px;
            font-family: 'Consolas', 'Monaco', monospace;
            font-size: 0.85rem;
            scrollbar-width: thin;
        }

        .pagination {
            display: flex; justify-content: center; align-items: center; gap: 16px; margin-top: 24px;
        }
        .page-info { font-size: 0.9rem; color: var(--text-muted); }
        /* Collapsible Section */
        .collapsible-trigger {
            display: flex;
            align-items: center;
            justify-content: space-between;
            cursor: pointer;
            padding: 12px 16px;
            background: rgba(15, 23, 42, 0.3);
            border: 1px solid var(--border);
            border-radius: 10px;
            margin-top: 16px;
            transition: all 0.2s;
            user-select: none;
        }
        .collapsible-trigger:hover {
            background: rgba(15, 23, 42, 0.5);
            border-color: var(--primary);
        }
        .collapsible-trigger svg {
            transition: transform 0.3s;
        }
        .collapsible-trigger.active {
            border-radius: 10px 10px 0 0;
            border-bottom: 1px dashed var(--border);
        }
        .collapsible-trigger.active svg {
            transform: rotate(180deg);
        }
        .collapsible-content {
            display: none;
            padding: 16px;
            border: 1px solid var(--border);
            border-top: none;
            border-radius: 0 0 10px 10px;
            background: rgba(15, 23, 42, 0.2);
            margin-bottom: 16px;
        }

        /* Contact Selector V2 */
        .contact-selector-v2 {
            border: 1px solid var(--border);
            border-radius: 12px;
            padding: 12px;
            background: rgba(0,0,0,0.2);
            text-align: left;
        }
        .contact-checkbox-list {
            max-height: 200px;
            overflow-y: auto;
            display: flex;
            flex-direction: column;
            gap: 4px;
            padding-right: 4px;
        }
        .contact-checkbox-list::-webkit-scrollbar { width: 6px; }
        .contact-checkbox-list::-webkit-scrollbar-thumb { background: var(--border); border-radius: 10px; }
        
        .contact-item {
            display: flex;
            align-items: center;
            gap: 12px;
            padding: 8px 12px;
            border-radius: 8px;
            cursor: pointer;
            transition: all 0.2s;
            text-align: left;
        }
        .contact-item:hover { background: rgba(255,255,255,0.05); }
        .contact-item input[type="checkbox"] {
            width: 18px;
            height: 18px;
            cursor: pointer;
            flex-shrink: 0;
            margin: 0;
        }
        .contact-info {
            display: flex;
            flex-direction: column;
            line-height: 1.2;
            text-align: left;
        }
        .contact-info .name {
            font-weight: 600;
            font-size: 0.9rem;
            color: var(--text-main);
        }
        .contact-info .email {
            font-size: 0.75rem;
            color: var(--text-muted);
        }


        /* Date Tag Styles */
        .date-tag-container {
            display: flex;
            flex-wrap: wrap;
            gap: 8px;
            min-height: 42px;
            padding: 8px;
            border: 1px solid var(--border);
            border-radius: 10px;
            background: rgba(15, 23, 42, 0.3);
        }
        .date-tag {
            display: flex;
            align-items: center;
            gap: 6px;
            background: var(--primary);
            color: white;
            padding: 4px 10px;
            border-radius: 6px;
            font-size: 0.85rem;
            font-weight: 500;
            animation: tagPop 0.2s ease-out;
        }
        .date-tag .remove {
            cursor: pointer;
            opacity: 0.7;
            font-size: 1.1rem;
            line-height: 1;
        }
        .date-tag .remove:hover { opacity: 1; }
        @keyframes tagPop { from { transform: scale(0.8); opacity: 0; } to { transform: scale(1); opacity: 1; } }

        /* Toasts */
        .toast {
            min-width: 320px;
            padding: 16px 20px;
            border-radius: 12px;
            background: var(--card-bg);
            border: 1px solid var(--border);
            color: white;
            box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.4);
            display: flex;
            align-items: center;
            justify-content: space-between;
            gap: 16px;
            animation: toastIn 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
            transition: all 0.3s;
            position: relative;
            overflow: hidden;
        }
        .toast::after {
            content: '';
            position: absolute; bottom: 0; left: 0; height: 3px; width: 100%;
            background: var(--primary);
            animation: toastProgress 5s linear forwards;
        }
        .toast-success::after { background: var(--success); }
        .toast-danger::after { background: var(--danger); }
        .toast-info::after { background: var(--primary); }

        .toast-icon {
            width: 32px; height: 32px; border-radius: 8px;
            display: flex; align-items: center; justify-content: center; flex-shrink: 0;
        }
        .toast-success .toast-icon { background: rgba(16, 185, 129, 0.15); color: var(--success); }
        .toast-danger .toast-icon { background: rgba(239, 68, 68, 0.15); color: var(--danger); }
        .toast-info .toast-icon { background: rgba(99, 102, 241, 0.15); color: var(--primary); }
        
        .toast-message { font-size: 0.95rem; font-weight: 500; flex-grow: 1; }

        @keyframes toastIn {
            from { transform: translateX(100%) scale(0.9); opacity: 0; }
            to { transform: translateX(0) scale(1); opacity: 1; }
        }
        @keyframes toastProgress { from { width: 100%; } to { width: 0%; } }
/* Fullscreen Split View Styles */
.CodeMirror-fullscreen.split-mode {
    display: flex !important;
    width: 100vw !important;
    height: 100vh !important;
}

.CodeMirror-fullscreen.split-mode .CodeMirror-scroll {
    width: 50vw !important;
}

.fullscreen-toolbar {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 10005;
    display: flex;
    gap: 12px;
    background: rgba(15, 23, 42, 0.6);
    backdrop-filter: blur(8px);
    padding: 8px 12px;
    border-radius: 12px;
    border: 1px solid rgba(255, 255, 255, 0.1);
    box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.4);
}

.fullscreen-toolbar .expand-btn {
    position: static !important; /* Override absolute position */
    width: 36px;
    height: 36px;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 8px;
    transition: all 0.2s;
}

.fullscreen-toolbar .expand-btn svg {
    margin: 0 !important;
}

.fullscreen-preview-pane {
    width: 50vw;
    height: 100vh;
    background: white;
    border-left: 2px solid var(--primary);
    overflow: auto;
    position: fixed;
    top: 0;
    right: 0;
    z-index: 9999;
    display: flex;
    flex-direction: column;
}

.fullscreen-preview-pane header {
    padding: 10px 20px;
    background: #f1f5f9;
    border-bottom: 1px solid #e2e8f0;
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-weight: 600;
    font-size: 0.75rem;
    color: #475569;
}

/* Handlebars Variable Highlighting in Editor (Simple approach via CSS if possible) */
.cm-handlebars {
    color: #fbbf24 !important;
    font-weight: bold;
    background: rgba(251, 191, 36, 0.1);
    border-radius: 2px;
}
