/* -------------------------------------------------------------
 * Scrapi - CSS Design System & Stylesheet
 * Premium Dark Theme with Glassmorphism and Neon Accents
 * ------------------------------------------------------------- */

/* 全域 CSS 變數定義 (色調系統採用極具質感的深海藍與霓虹藍紫) */
:root {
    --bg-base: #080c14;
    --bg-panel: rgba(13, 20, 35, 0.65);
    --border-color: rgba(255, 255, 255, 0.08);
    --border-focus: rgba(0, 242, 254, 0.5);
    
    --text-primary: #f3f5f9;
    --text-secondary: #8e9bb4;
    --text-muted: #5b6880;

    /* 品牌色彩 - 採用漸層配色 */
    --primary-color: #00f2fe;
    --primary-grad: linear-gradient(135deg, #4facfe 0%, #00f2fe 100%);
    --accent-purple: #c471ed;
    --accent-grad: linear-gradient(135deg, #f7797d, #FBD786, #C6FFDD);
    
    /* 狀態色彩 */
    --status-success: #10b981;
    --status-warning: #f59e0b;
    --status-danger: #ef4444;
    --status-inactive: #6b7280;

    --font-sans: 'Outfit', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    --font-mono: 'JetBrains Mono', Consolas, Monaco, monospace;
}

/* 基礎重置與排版 */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    background-color: var(--bg-base);
    color: var(--text-primary);
    font-family: var(--font-sans);
    min-height: 100vh;
    overflow-x: hidden;
    position: relative;
}

/* 背景發光氣泡效果 */
.glass-bg-glow {
    position: absolute;
    top: -10%;
    left: 20%;
    width: 60vw;
    height: 60vw;
    background: radial-gradient(circle, rgba(79, 172, 254, 0.15) 0%, rgba(196, 113, 237, 0.05) 50%, transparent 100%);
    z-index: -1;
    pointer-events: none;
    filter: blur(80px);
    animation: slow-drift 20s ease-in-out infinite alternate;
}

@keyframes slow-drift {
    0% { transform: translateY(0) scale(1); }
    100% { transform: translateY(50px) scale(1.1); }
}

/* 主容器 */
.app-container {
    max-width: 1440px;
    margin: 0 auto;
    padding: 20px;
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

/* Header 導覽列 */
.app-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding-bottom: 20px;
    border-bottom: 1px solid var(--border-color);
    margin-bottom: 24px;
}

.logo {
    display: flex;
    align-items: center;
    gap: 12px;
}

.logo-icon {
    font-size: 26px;
    background: var(--primary-grad);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    filter: drop-shadow(0 2px 8px rgba(0, 242, 254, 0.3));
    animation: spider-float 4s ease-in-out infinite;
}

@keyframes spider-float {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-4px); }
}

.logo-text {
    font-size: 28px;
    font-weight: 900;
    letter-spacing: 1px;
    text-transform: lowercase;
}

.logo-text span {
    color: var(--primary-color);
}

.app-badge {
    display: flex;
    align-items: center;
    gap: 8px;
    background: rgba(16, 185, 129, 0.1);
    border: 1px solid rgba(16, 185, 129, 0.2);
    padding: 6px 14px;
    border-radius: 20px;
    font-size: 13px;
    font-weight: 500;
    color: var(--status-success);
}

.pulse-indicator {
    width: 8px;
    height: 8px;
    background-color: var(--status-success);
    border-radius: 50%;
    box-shadow: 0 0 0 0 rgba(16, 185, 129, 0.7);
    animation: pulse 1.6s infinite;
}

@keyframes pulse {
    0% {
        transform: scale(0.95);
        box-shadow: 0 0 0 0 rgba(16, 185, 129, 0.7);
    }
    70% {
        transform: scale(1);
        box-shadow: 0 0 0 8px rgba(16, 185, 129, 0);
    }
    100% {
        transform: scale(0.95);
        box-shadow: 0 0 0 0 rgba(16, 185, 129, 0);
    }
}

/* 雙欄主網格配置 */
.dashboard-grid {
    display: grid;
    grid-template-columns: 460px 1fr;
    gap: 24px;
    flex-grow: 1;
    align-items: stretch;
}

.sidebar-wrapper {
    display: flex;
    flex-direction: column;
    gap: 24px;
}


@media (max-width: 1024px) {
    .dashboard-grid {
        grid-template-columns: 1fr;
    }
}

/* 玻璃帷幕卡片卡板 */
.glass-card {
    background: var(--bg-panel);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border: 1px solid var(--border-color);
    border-radius: 16px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.25);
    padding: 24px;
    transition: transform 0.3s ease, border-color 0.3s ease;
}

.panel {
    display: flex;
    flex-direction: column;
}

.panel-title {
    font-size: 20px;
    font-weight: 600;
    margin-bottom: 20px;
    color: var(--text-primary);
    display: flex;
    align-items: center;
    gap: 10px;
    border-left: 3px solid var(--primary-color);
    padding-left: 10px;
}

/* 表單元件樣式 */
.form-group {
    margin-bottom: 18px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.form-row-2 {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
}

label {
    font-size: 14px;
    font-weight: 500;
    color: var(--text-secondary);
}

.required {
    color: var(--status-danger);
}

/* 輸入框 */
input[type="text"],
input[type="url"],
select,
textarea {
    width: 100%;
    background: rgba(8, 12, 20, 0.6);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 11px 14px;
    color: var(--text-primary);
    font-family: var(--font-sans);
    font-size: 14px;
    outline: none;
    transition: all 0.2s ease-in-out;
}

input[type="text"]:focus,
input[type="url"]:focus,
select:focus,
textarea:focus {
    border-color: var(--primary-color);
    box-shadow: 0 0 10px rgba(0, 242, 254, 0.15);
    background: rgba(8, 12, 20, 0.8);
}

/* 帶有圖示的輸入框 */
.input-with-icon {
    position: relative;
    display: flex;
    align-items: center;
}

.input-with-icon i {
    position: absolute;
    left: 14px;
    color: var(--text-muted);
    font-size: 15px;
    pointer-events: none;
}

.input-with-icon input {
    padding-left: 40px;
}

/* 靜態下拉選單樣式修正 */
select {
    cursor: pointer;
    appearance: none;
    background-image: url("data:image/svg+xml;utf8,<svg fill='%238e9bb4' height='24' viewBox='0 0 24 24' width='24' xmlns='http://www.w3.org/2000/svg'><path d='M7 10l5 5 5-5z'/><path d='M0 0h24v24H0z' fill='none'/></svg>");
    background-repeat: no-repeat;
    background-position: right 10px center;
    padding-right: 35px;
}

/* 展開型容器 */
.collapsible-section {
    max-height: 500px;
    opacity: 1;
    overflow: hidden;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    margin-bottom: 12px;
}

.collapsible-section.hidden {
    max-height: 0;
    opacity: 0;
    margin-bottom: 0;
    pointer-events: none;
}

.border-highlight {
    border: 1px dashed rgba(0, 242, 254, 0.3);
    padding: 12px;
    border-radius: 10px;
    background: rgba(0, 242, 254, 0.02);
}

/* 動態 Key-Value 區塊 */
.section-header-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 4px;
}

.dynamic-kv-container {
    display: flex;
    flex-direction: column;
    gap: 8px;
    max-height: 180px;
    overflow-y: auto;
    padding-right: 4px;
}

.kv-row {
    display: grid;
    grid-template-columns: 1fr 1fr 36px;
    gap: 8px;
    align-items: center;
    animation: fade-in-up 0.2s ease-out;
}

@keyframes fade-in-up {
    from { opacity: 0; transform: translateY(4px); }
    to { opacity: 1; transform: translateY(0); }
}

/* 按鈕樣式 */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    border: none;
    border-radius: 8px;
    font-family: var(--font-sans);
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    outline: none;
}

.btn-xs {
    padding: 4px 10px;
    font-size: 11px;
    border-radius: 6px;
}

.btn-secondary {
    background: rgba(255, 255, 255, 0.06);
    color: var(--text-secondary);
    border: 1px solid var(--border-color);
}

.btn-secondary:hover {
    background: rgba(255, 255, 255, 0.12);
    color: var(--text-primary);
    border-color: rgba(255, 255, 255, 0.2);
}

.btn-primary {
    background: var(--primary-grad);
    color: #040810;
    box-shadow: 0 4px 15px rgba(0, 242, 254, 0.25);
}

.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(0, 242, 254, 0.4);
}

.btn-primary:active {
    transform: translateY(0);
}

.btn-block {
    width: 100%;
    padding: 13px 20px;
    font-size: 16px;
    margin-top: 10px;
}

.btn-delete {
    background: rgba(239, 68, 68, 0.1);
    border: 1px solid rgba(239, 68, 68, 0.2);
    color: var(--status-danger);
    width: 36px;
    height: 36px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s ease;
}

.btn-delete:hover {
    background: var(--status-danger);
    color: #ffffff;
    border-color: var(--status-danger);
}

/* 隱藏與顯示輔助 */
.hidden {
    display: none !important;
}

/* 右側結果面板 */
.result-panel {
    display: flex;
    flex-direction: column;
}

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

.status-indicators {
    display: flex;
    align-items: center;
    gap: 10px;
}

.badge-status {
    padding: 5px 12px;
    border-radius: 6px;
    font-size: 12px;
    font-weight: 700;
    letter-spacing: 0.5px;
    border: 1px solid transparent;
}

.badge-inactive {
    background: rgba(107, 114, 128, 0.1);
    color: var(--text-muted);
    border-color: rgba(107, 114, 128, 0.2);
}

.badge-success {
    background: rgba(16, 185, 129, 0.12);
    color: #10b981;
    border-color: rgba(16, 185, 129, 0.3);
    box-shadow: 0 0 10px rgba(16, 185, 129, 0.15);
}

.badge-error {
    background: rgba(239, 68, 68, 0.12);
    color: #ef4444;
    border-color: rgba(239, 68, 68, 0.3);
    box-shadow: 0 0 10px rgba(239, 68, 68, 0.15);
}

.badge-meta {
    background: rgba(255, 255, 255, 0.04);
    color: var(--text-secondary);
    padding: 5px 10px;
    border-radius: 6px;
    font-size: 12px;
    font-weight: 500;
    display: flex;
    align-items: center;
    gap: 6px;
    border: 1px solid var(--border-color);
}

/* Tabs 切換按鈕 */
.tabs-container {
    display: flex;
    gap: 8px;
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 10px;
    margin-bottom: 16px;
}

.tab-btn {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    padding: 8px 16px;
    font-family: var(--font-sans);
    font-weight: 500;
    font-size: 14px;
    cursor: pointer;
    border-radius: 8px;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    gap: 8px;
}

.tab-btn:hover {
    color: var(--text-primary);
    background: rgba(255, 255, 255, 0.03);
}

.tab-btn.active {
    color: #040810;
    background: var(--primary-grad);
    font-weight: 600;
    box-shadow: 0 4px 12px rgba(0, 242, 254, 0.15);
}

/* Tab 顯示視窗群 */
.tab-viewports {
    flex-grow: 1;
    position: relative;
    display: flex;
    flex-direction: column;
}

.viewport {
    display: none;
    flex-grow: 1;
    height: 100%;
}

.viewport.active {
    display: flex;
    flex-direction: column;
}

/* 1. Live 預覽 iframe */
.iframe-container {
    width: 100%;
    flex-grow: 1;
    min-height: 480px;
    border-radius: 12px;
    border: 1px solid var(--border-color);
    background: #ffffff; /* Iframe 內容在白色背景中渲染更為真實 */
    overflow: hidden;
    position: relative;
}

iframe {
    width: 100%;
    height: 100%;
    border: none;
    background: transparent;
}

.iframe-placeholder {
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background: var(--bg-base);
    color: var(--text-muted);
    gap: 16px;
}

.iframe-placeholder i {
    font-size: 48px;
    color: var(--text-muted);
    opacity: 0.5;
}

.iframe-placeholder p {
    font-size: 14px;
}

/* 2. 原始程式碼 Code View */
.code-view-container {
    width: 100%;
    flex-grow: 1;
    border-radius: 12px;
    border: 1px solid var(--border-color);
    background: rgba(8, 12, 20, 0.9);
    position: relative;
    max-height: 520px;
    display: flex;
}

.code-view-container pre {
    width: 100%;
    padding: 20px;
    overflow: auto;
    margin: 0;
}

.code-view-container code {
    font-family: var(--font-mono);
    font-size: 13px;
    color: #e2e8f0;
    line-height: 1.6;
    white-space: pre-wrap;
    word-break: break-all;
}

.btn-copy {
    position: absolute;
    top: 12px;
    right: 12px;
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid var(--border-color);
    color: var(--text-secondary);
    padding: 6px 12px;
    border-radius: 6px;
    font-size: 12px;
    font-family: var(--font-sans);
    cursor: pointer;
    transition: all 0.2s ease;
    z-index: 10;
}

.btn-copy:hover {
    background: rgba(255, 255, 255, 0.16);
    color: var(--text-primary);
}

/* 3. Headers 表格 */
.table-container {
    width: 100%;
    max-height: 480px;
    overflow-y: auto;
    border-radius: 12px;
    border: 1px solid var(--border-color);
    background: rgba(8, 12, 20, 0.4);
}

.headers-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 14px;
}

.headers-table th {
    background: rgba(13, 20, 35, 0.8);
    color: var(--text-secondary);
    text-align: left;
    padding: 14px 18px;
    font-weight: 600;
    border-bottom: 1px solid var(--border-color);
    position: sticky;
    top: 0;
}

.headers-table td {
    padding: 12px 18px;
    color: var(--text-primary);
    border-bottom: 1px solid var(--border-color);
    font-family: var(--font-sans);
    word-break: break-all;
}

.headers-table tr:hover td {
    background: rgba(255, 255, 255, 0.02);
}

.headers-table td:first-child {
    font-family: var(--font-mono);
    color: var(--primary-color);
    font-size: 13px;
    width: 30%;
}

.table-placeholder {
    text-align: center !important;
    color: var(--text-muted) !important;
    padding: 40px !important;
}

/* 4. Terminal Console */
.terminal-box {
    display: flex;
    flex-direction: column;
    flex-grow: 1;
    border-radius: 12px;
    border: 1px solid var(--border-color);
    background: #05080f;
    min-height: 480px;
    box-shadow: inset 0 0 10px rgba(0, 0, 0, 0.8);
    overflow: hidden;
}

.terminal-header {
    background: #0d121f;
    padding: 10px 16px;
    display: flex;
    align-items: center;
    border-bottom: 1px solid var(--border-color);
}

.terminal-header .dot {
    width: 11px;
    height: 11px;
    border-radius: 50%;
    display: inline-block;
    margin-right: 6px;
}

.terminal-header .dot.red { background: #ef4444; }
.terminal-header .dot.yellow { background: #f59e0b; }
.terminal-header .dot.green { background: #10b981; }

.terminal-title {
    margin-left: 10px;
    font-family: var(--font-mono);
    font-size: 12px;
    color: var(--text-secondary);
    flex-grow: 1;
}

.btn-clear {
    background: transparent;
    border: none;
    color: var(--text-muted);
    font-size: 12px;
    cursor: pointer;
    font-family: var(--font-sans);
    display: flex;
    align-items: center;
    gap: 6px;
    transition: color 0.2s ease;
}

.btn-clear:hover {
    color: var(--text-primary);
}

.terminal-body {
    padding: 16px;
    overflow-y: auto;
    font-family: var(--font-mono);
    font-size: 13px;
    line-height: 1.6;
    flex-grow: 1;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.log-line {
    padding: 2px 0;
    word-break: break-all;
}

.system-log { color: #8a99ad; }
.info-log { color: #60a5fa; }
.success-log { color: #34d399; }
.warn-log { color: #fbbf24; }
.error-log { color: #f87171; }

/* Scrollbar 美化 */
::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.1);
    border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.25);
}

/* Footer 頁尾 */
.app-footer {
    text-align: center;
    padding: 20px 0;
    border-top: 1px solid var(--border-color);
    margin-top: auto;
    font-size: 13px;
    color: var(--text-muted);
}
