/* ═══════════════════════════════════════════════════════════
   FaaS Dashboard – Styles
   ═══════════════════════════════════════════════════════════ */

/* === Reset & Base === */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
    --primary: #5B5FC7;
    --primary-light: #7C7FDB;
    --success: #10B981;
    --danger: #EF4444;
    --warning: #F59E0B;
    --bg: #F1F5F9;
    --surface: #FFFFFF;
    --text: #1E293B;
    --text-secondary: #64748B;
    --border: #E2E8F0;
    --radius: 12px;
    --radius-sm: 8px;
    --shadow: 0 1px 3px rgba(0,0,0,0.08), 0 1px 2px rgba(0,0,0,0.04);
    --shadow-lg: 0 4px 12px rgba(0,0,0,0.1);
    --font: 'Inter', -apple-system, system-ui, sans-serif;
    --mono: 'JetBrains Mono', 'Fira Code', monospace;
}

html, body { height: 100%; }
body {
    font-family: var(--font);
    background: var(--bg);
    color: var(--text);
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

.screen { display: flex; flex-direction: column; min-height: 100vh; }
.hidden { display: none !important; }

/* === Login === */
#login-screen {
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
}

.login-card {
    background: var(--surface);
    padding: 48px 40px;
    border-radius: 20px;
    box-shadow: 0 20px 60px rgba(0,0,0,0.2);
    text-align: center;
    width: 100%;
    max-width: 400px;
}
.login-logo { font-size: 52px; margin-bottom: 8px; }
.login-card h1 { font-size: 24px; font-weight: 700; margin-bottom: 4px; }
.login-card p { color: var(--text-secondary); font-size: 14px; margin-bottom: 24px; }
.login-card input {
    width: 100%;
    padding: 12px 16px;
    border: 2px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 16px;
    font-family: var(--font);
    outline: none;
    transition: border-color 0.2s;
    margin-bottom: 16px;
}
.login-card input:focus { border-color: var(--primary); }
.error-msg { color: var(--danger); font-size: 14px; margin-top: 12px; }

/* === Buttons === */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 10px 20px;
    border: none;
    border-radius: var(--radius-sm);
    font-family: var(--font);
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.15s;
}
.btn:hover { opacity: 0.9; transform: translateY(-1px); }
.btn:active { transform: translateY(0); }
.btn-primary { background: var(--primary); color: #fff; }
.btn-success { background: var(--success); color: #fff; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-ghost { background: transparent; color: var(--text-secondary); }
.btn-ghost:hover { background: rgba(0,0,0,0.05); }
.btn-block { width: 100%; }
.btn-sm {
    padding: 6px 12px;
    font-size: 12px;
    border-radius: 6px;
    background: var(--surface);
    border: 1px solid var(--border);
    color: var(--text);
    font-family: var(--font);
    font-weight: 600;
    cursor: pointer;
    transition: all 0.15s;
}
.btn-sm:hover { background: var(--bg); }

/* === Topbar === */
.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 32px;
    height: 60px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    box-shadow: var(--shadow);
    position: sticky;
    top: 0;
    z-index: 100;
}
.topbar-left { display: flex; align-items: center; gap: 12px; }
.topbar-logo { font-size: 28px; }
.topbar h1 { font-size: 18px; font-weight: 700; }

/* === Content === */
#content { padding: 32px; max-width: 1200px; margin: 0 auto; width: 100%; }

/* === Stats === */
.dashboard-stats { display: flex; gap: 16px; margin-bottom: 32px; }
.stat {
    flex: 1;
    background: var(--surface);
    border-radius: var(--radius);
    padding: 20px 24px;
    box-shadow: var(--shadow);
    display: flex;
    flex-direction: column;
}
.stat-num { font-size: 32px; font-weight: 700; color: var(--primary); line-height: 1; }
.stat-label { font-size: 13px; color: var(--text-secondary); margin-top: 4px; }

/* === Function Grid === */
.fn-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(340px, 1fr));
    gap: 20px;
}

.fn-card {
    background: var(--surface);
    border-radius: var(--radius);
    padding: 24px;
    box-shadow: var(--shadow);
    cursor: pointer;
    transition: all 0.2s;
    border: 2px solid transparent;
}
.fn-card:hover {
    box-shadow: var(--shadow-lg);
    border-color: var(--primary);
    transform: translateY(-2px);
}
.fn-card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 12px;
}

.lang-badge {
    display: inline-flex;
    align-items: center;
    padding: 3px 10px;
    border-radius: 20px;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}
.lang-badge.python { background: #EFF6FF; color: #3B82F6; }
.lang-badge.javascript { background: #FEF9C3; color: #CA8A04; }

.status-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    flex-shrink: 0;
}
.status-dot.active {
    background: var(--success);
    box-shadow: 0 0 6px var(--success);
}
.status-dot.inactive { background: #CBD5E1; }

.status-badge {
    display: inline-flex;
    align-items: center;
    padding: 3px 10px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 600;
}
.status-badge.active { background: #ECFDF5; color: #059669; }
.status-badge.inactive { background: #F1F5F9; color: #64748B; }

.fn-card-title { font-size: 16px; font-weight: 700; margin-bottom: 6px; }
.fn-card-desc {
    font-size: 13px;
    color: var(--text-secondary);
    margin-bottom: 12px;
    line-height: 1.4;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}
.fn-card-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    font-size: 12px;
    color: var(--text-secondary);
}
.fn-card-footer {
    margin-top: 12px;
    padding-top: 12px;
    border-top: 1px solid var(--border);
}
.fn-card-date { font-size: 12px; color: var(--text-secondary); }

/* === Detail View === */
.detail-top {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 20px;
}
.back-btn {
    background: none;
    border: none;
    font-family: var(--font);
    font-size: 14px;
    font-weight: 600;
    color: var(--primary);
    cursor: pointer;
    padding: 6px 0;
}
.back-btn:hover { text-decoration: underline; }

.detail-header {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 8px;
    flex-wrap: wrap;
}
.detail-header h2 { font-size: 24px; font-weight: 700; }
.detail-desc { color: var(--text-secondary); margin-bottom: 16px; }

.detail-info { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 24px; }
.info-chip {
    background: var(--surface);
    border: 1px solid var(--border);
    padding: 6px 14px;
    border-radius: 20px;
    font-size: 13px;
    color: var(--text-secondary);
    font-family: var(--mono);
    word-break: break-all;
}

/* === Tabs === */
.tabs {
    display: flex;
    gap: 4px;
    border-bottom: 2px solid var(--border);
    margin-bottom: 0;
}
.tab {
    padding: 10px 20px;
    border: none;
    background: none;
    font-family: var(--font);
    font-size: 14px;
    font-weight: 600;
    color: var(--text-secondary);
    cursor: pointer;
    border-bottom: 2px solid transparent;
    margin-bottom: -2px;
    transition: all 0.15s;
}
.tab:hover { color: var(--text); }
.tab.active { color: var(--primary); border-bottom-color: var(--primary); }

.tab-panel {
    background: var(--surface);
    border-radius: 0 0 var(--radius) var(--radius);
    box-shadow: var(--shadow);
}

/* === Flow Visualization === */
.flow-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    border-bottom: 1px solid var(--border);
}
.zoom-controls { display: flex; gap: 4px; }

.flow-viewport {
    overflow: auto;
    background:
        radial-gradient(circle, #E2E8F0 1px, transparent 1px);
    background-size: 20px 20px;
    min-height: 400px;
    max-height: 70vh;
    position: relative;
}

.flow-container {
    position: relative;
    transform-origin: top left;
    transition: transform 0.15s;
    min-height: 300px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.flow-canvas {
    position: relative;
    min-width: 100%;
    min-height: 300px;
}

.flow-edges {
    position: absolute;
    top: 0;
    left: 0;
    pointer-events: none;
}

.flow-node {
    position: absolute;
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    border-radius: 12px;
    border: 2px solid;
    box-shadow: 0 2px 8px rgba(0,0,0,0.08);
    cursor: default;
    transition: box-shadow 0.15s;
    z-index: 1;
}
.flow-node:hover {
    box-shadow: 0 4px 16px rgba(0,0,0,0.15);
    z-index: 2;
}

.flow-node-icon {
    width: 36px;
    height: 36px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    flex-shrink: 0;
    color: white;
}

.flow-node-body { flex: 1; min-width: 0; }
.flow-node-label {
    font-size: 13px;
    font-weight: 700;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.flow-node-desc {
    font-size: 11px;
    color: var(--text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.flow-empty, .flow-error {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 60px;
    color: var(--text-secondary);
    text-align: center;
}
.flow-error span { font-size: 40px; margin-bottom: 12px; }
.flow-error p { font-weight: 600; font-size: 16px; }
.flow-error small { font-size: 12px; margin-top: 8px; }

/* === Code === */
.code-block {
    margin: 0 !important;
    padding: 24px !important;
    border-radius: 0 0 var(--radius) var(--radius) !important;
    font-size: 13px !important;
    line-height: 1.6 !important;
    font-family: var(--mono) !important;
    overflow-x: auto;
    max-height: 70vh;
}

/* === Loading === */
.loading {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 16px;
    padding: 60px;
    color: var(--text-secondary);
    font-size: 14px;
}

.spinner {
    width: 32px;
    height: 32px;
    border: 3px solid var(--border);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* === Error === */
.error-box {
    background: #FEF2F2;
    border: 1px solid #FECACA;
    color: #DC2626;
    padding: 16px 20px;
    border-radius: var(--radius-sm);
    font-size: 14px;
}

/* === Empty State === */
.empty-state {
    text-align: center;
    padding: 80px 40px;
    color: var(--text-secondary);
}
.empty-icon { font-size: 60px; margin-bottom: 16px; }
.empty-state h3 { font-size: 20px; color: var(--text); margin-bottom: 8px; }

/* === Responsive === */
@media (max-width: 768px) {
    #content { padding: 20px; }
    .fn-grid { grid-template-columns: 1fr; }
    .dashboard-stats { flex-wrap: wrap; }
    .stat { min-width: 100px; }
    .topbar { padding: 0 16px; }
    .login-card { margin: 16px; padding: 32px 24px; }
    .detail-header { flex-direction: column; align-items: flex-start; }
}
