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

:root {
    --bg: #fafafa;
    --bg2: #ffffff;
    --bg3: #f4f4f5;
    --border: #e4e4e7;
    --text: #09090b;
    --text2: #71717a;
    --accent: #18181b;
    --accent2: #09090b;
    --green: #16a34a;
    --red: #ef4444;
    --orange: #f59e0b;
    --input-bg: #fafafa;
    --input-focus-bg: #ffffff;
    --ring: rgba(9,9,11,0.12);
    --shadow-sm: 0 1px 2px rgba(0,0,0,0.05);
    --shadow-md: 0 2px 8px rgba(0,0,0,0.08);
    --shadow-lg: 0 8px 24px rgba(0,0,0,0.1);
    --radius-sm: 6px;
    --radius-md: 8px;
    --fast: 150ms cubic-bezier(0.2, 0, 0, 1);
    --font-mono: 'SF Mono', 'Cascadia Code', 'Fira Code', monospace;
}
[data-theme="dark"] {
    --bg: #000000;
    --bg2: #0a0a0a;
    --bg3: #18181b;
    --border: #27272a;
    --text: #fafafa;
    --text2: #a1a1aa;
    --accent: #fafafa;
    --accent2: #e4e4e7;
    --green: #22c55e;
    --red: #ef4444;
    --orange: #f59e0b;
    --input-bg: #09090b;
    --input-focus-bg: #18181b;
    --ring: rgba(250,250,250,0.12);
    --shadow-sm: 0 1px 2px rgba(0,0,0,0.4);
    --shadow-md: 0 2px 8px rgba(0,0,0,0.5);
    --shadow-lg: 0 8px 24px rgba(0,0,0,0.6);
}

body {
    font-family: -apple-system, 'Inter', 'Segoe UI', system-ui, sans-serif;
    background: var(--bg);
    color: var(--text);
    height: 100vh;
    overflow: hidden;
    -webkit-font-smoothing: antialiased;
}

/* ─── Login ─────────────────────────────────────────── */
#login-screen {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100vh;
    background: #09090b;
}
.login-box {
    background: rgba(255,255,255,0.95);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-radius: 14px;
    padding: 44px 36px;
    width: 380px;
    text-align: center;
    box-shadow: 0 24px 80px rgba(0,0,0,0.15);
    animation: slideUp 0.4s var(--fast);
}
[data-theme="dark"] .login-box { background: rgba(10,10,10,0.95); border: 1px solid var(--border); }
[data-theme="dark"] .login-box h1 { color: var(--text); }
[data-theme="dark"] .login-box p { color: var(--text2); }
[data-theme="dark"] .login-box input { background: var(--bg3); border-color: var(--border); color: var(--text); }
[data-theme="dark"] .login-box input:focus { background: var(--bg2); }
@keyframes slideUp {
    from { transform: translateY(24px); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
}
.login-box h1 { font-size: 22px; font-weight: 700; letter-spacing: -0.02em; margin-bottom: 4px; color: var(--text); }
.login-box p { color: var(--text2); font-size: 13px; margin-bottom: 28px; line-height: 1.5; }
.login-box input {
    width: 100%; padding: 11px 14px; background: var(--input-bg); border: 1px solid var(--border);
    border-radius: var(--radius-sm); color: var(--text); font-size: 14px; margin-bottom: 14px; outline: none;
    transition: border-color 150ms, box-shadow 150ms;
}
.login-box input:focus { border-color: var(--text2); box-shadow: 0 0 0 2px var(--ring); background: var(--input-focus-bg); }
.login-box button {
    width: 100%; padding: 11px; background: var(--text); border: none;
    border-radius: var(--radius-sm); color: var(--bg); font-size: 14px; font-weight: 600; cursor: pointer;
    transition: opacity var(--fast);
}
.login-box button:hover { opacity: 0.85; }
.login-box button:active { opacity: 0.75; }
#login-error { color: var(--red); font-size: 13px; margin-top: 14px; display: none; font-weight: 500; animation: shake 0.4s ease; }
@keyframes shake { 25% { transform: translateX(-6px); } 75% { transform: translateX(6px); } }

/* ─── App Layout ────────────────────────────────────── */
#app {
    display: none;
    height: 100vh;
    grid-template-columns: auto 1fr;
}

/* ─── Sidebar ───────────────────────────────────────── */
.sidebar {
    width: 220px;
    min-width: 0;
    background: var(--bg2);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transition: width 200ms var(--fast), opacity 150ms;
}
.sidebar.collapsed { width: 0; border-right: none; }
.sidebar-header {
    padding: 16px 16px 12px;
    border-bottom: 1px solid var(--border);
}
.sidebar-brand {
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 1.5px;
    color: var(--text2);
    font-weight: 700;
}
#pod-list {
    flex: 1;
    overflow-y: auto;
    padding: 8px;
}
.pod-item {
    padding: 10px 12px;
    cursor: pointer;
    font-size: 13px;
    font-weight: 500;
    border-radius: var(--radius-sm);
    transition: all var(--fast);
    margin-bottom: 2px;
}
.pod-item:hover { background: var(--bg3); }
.pod-item.active { background: var(--bg3); color: var(--text); font-weight: 600; }
[data-theme="dark"] .pod-item.active { background: var(--bg3); }
.pod-item .pod-type { font-size: 11px; color: var(--text2); margin-top: 1px; }
.pod-item.active .pod-type { color: var(--text2); }
.pod-item .pod-stats { font-size: 10px; color: var(--text2); margin-top: 1px; opacity: 0.6; }

/* ─── App Main ──────────────────────────────────────── */
.app-main {
    display: flex;
    flex-direction: column;
    overflow: hidden;
    min-width: 0;
}

/* ─── Top Bar ───────────────────────────────────────── */
.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 20px;
    height: 48px;
    min-height: 48px;
    background: var(--bg2);
    border-bottom: 1px solid var(--border);
}
.topbar-left {
    display: flex;
    align-items: center;
    gap: 12px;
    min-width: 0;
}
.topbar-title {
    font-size: 15px;
    font-weight: 600;
    letter-spacing: -0.01em;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.topbar-right {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
}
.topbar-btn {
    background: var(--bg3);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text2);
    font-size: 13px;
    padding: 4px 10px;
    cursor: pointer;
    transition: all var(--fast);
    font-weight: 600;
    line-height: 1.4;
}
.topbar-btn:hover { background: var(--accent); color: #fff; border-color: var(--text); }
.logout-btn { font-size: 11px; }
.logout-btn:hover { background: var(--red); border-color: var(--red); }

/* ─── Empty State ───────────────────────────────────── */
.empty-state {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
}
.empty-state-inner { text-align: center; color: var(--text2); }
.empty-icon { font-size: 40px; margin-bottom: 12px; opacity: 0.3; }
.empty-state p { font-size: 14px; }

/* ─── Pod Editor ────────────────────────────────────── */
#pod-editor {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    animation: fadeIn 200ms ease;
}
@keyframes fadeIn {
    from { opacity: 0; transform: translateY(4px); }
    to { opacity: 1; transform: translateY(0); }
}
.app-main.loading #pod-editor {
    opacity: 0.4;
    filter: blur(1px);
    pointer-events: none;
    transition: opacity 150ms, filter 150ms;
}

/* ─── Tabs ──────────────────────────────────────────── */
.tab-bar {
    display: flex;
    gap: 0;
    background: var(--bg2);
    border-bottom: 1px solid var(--border);
    padding: 0 20px;
    flex-shrink: 0;
}
.tab {
    padding: 10px 16px;
    font-size: 13px;
    font-weight: 500;
    color: var(--text2);
    background: none;
    border: none;
    border-bottom: 2px solid transparent;
    cursor: pointer;
    transition: color var(--fast), border-color var(--fast);
    display: flex;
    align-items: center;
    gap: 6px;
    white-space: nowrap;
}
.tab:hover { color: var(--text); }
.tab.active {
    color: var(--text);
    border-bottom-color: var(--text);
    font-weight: 600;
}
.tab-badge {
    background: var(--bg3);
    color: var(--text2);
    font-size: 10px;
    font-weight: 600;
    padding: 1px 6px;
    border-radius: 8px;
    min-width: 18px;
    text-align: center;
}
.tab.active .tab-badge {
    background: var(--accent);
    color: var(--bg);
}

/* ─── Tab Content ───────────────────────────────────── */
.tab-content {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
}
.tab-pane { display: none; }
.tab-pane.active { display: block; animation: fadeIn 150ms ease; }

/* ─── Form Fields ───────────────────────────────────── */
.field-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 14px;
    margin-bottom: 14px;
}
.field-group { display: flex; flex-direction: column; }
.field-group label {
    font-size: 11px; color: var(--text2); text-transform: uppercase;
    letter-spacing: 0.5px; margin-bottom: 5px; font-weight: 500;
}
.field-group input, .field-group select {
    padding: 9px 12px; background: var(--bg); border: 1px solid var(--border);
    border-radius: var(--radius-sm); color: var(--text); font-size: 13px; outline: none;
    transition: border-color 150ms, box-shadow 150ms;
}
.field-group input:hover, .field-group select:hover { border-color: var(--text2); }
.field-group input:focus, .field-group select:focus {
    border-color: var(--text); box-shadow: 0 0 0 2px var(--ring); background: var(--input-focus-bg);
}
.field-hint { font-size: 11px; color: var(--text2); font-style: italic; }

/* ─── Tables ────────────────────────────────────────── */
.table-scroll { overflow-x: auto; margin: 0 -4px; padding: 0 4px; }
.wallet-table, .route-wallets-table {
    width: 100%; border-collapse: separate; border-spacing: 0; font-size: 12px;
}
.wallet-table th, .route-wallets-table th {
    text-align: left; padding: 8px 8px; border-bottom: 2px solid var(--border);
    color: var(--text2); font-size: 10px; text-transform: uppercase; letter-spacing: 0.8px;
    font-weight: 600; white-space: nowrap; position: sticky; top: 0; background: var(--bg2); z-index: 1;
}
.wallet-table td, .route-wallets-table td {
    padding: 5px 8px; border-bottom: 1px solid rgba(0,0,0,0.04); vertical-align: middle;
}
[data-theme="dark"] .wallet-table td, [data-theme="dark"] .route-wallets-table td { border-bottom-color: rgba(255,255,255,0.04); }
.wallet-table tbody tr, .route-wallets-table tbody tr { transition: background 100ms; }
.wallet-table tbody tr:hover, .route-wallets-table tbody tr:hover { background: var(--bg3); }
.wallet-table input, .route-wallets-table input {
    width: 100%; padding: 5px 8px; background: transparent; border: 1px solid transparent;
    border-radius: var(--radius-sm); color: var(--text); font-size: 12px; outline: none; min-width: 55px;
    transition: border-color 100ms, background 100ms;
}
.wallet-table input:hover, .route-wallets-table input:hover { border-color: var(--border); }
.wallet-table input:focus, .route-wallets-table input:focus {
    border-color: var(--text); background: var(--bg); box-shadow: 0 0 0 2px var(--ring);
}
.wallet-table input.key-input { min-width: 90px; }
.wallet-table input.url-input { min-width: 160px; }
.wallet-table .optional-field { opacity: 0.5; transition: opacity 150ms; }
.wallet-table .optional-field:focus { opacity: 1; }

/* ─── Toggle ────────────────────────────────────────── */
.toggle { position: relative; width: 34px; height: 18px; display: inline-block; }
.toggle input { opacity: 0; width: 0; height: 0; }
.toggle-slider {
    position: absolute; inset: 0; background: var(--border); border-radius: 9px;
    cursor: pointer; transition: background var(--fast);
}
.toggle-slider::before {
    content: ''; position: absolute; width: 14px; height: 14px; left: 2px; top: 2px;
    background: #fff; border-radius: 50%; transition: transform var(--fast);
    box-shadow: 0 1px 2px rgba(0,0,0,0.15);
}
.toggle input:checked + .toggle-slider { background: var(--green); }
.toggle input:checked + .toggle-slider::before { transform: translateX(16px); }

/* ─── Buttons ───────────────────────────────────────── */
.btn {
    padding: 7px 14px; border: none; border-radius: var(--radius-sm); font-size: 12px;
    font-weight: 600; cursor: pointer; transition: all var(--fast); position: relative;
}
.btn:active { transform: scale(0.97); }
.btn-primary { background: var(--accent); color: var(--bg); box-shadow: var(--shadow-sm); }
.btn-primary:hover { background: var(--accent2); color: var(--bg); box-shadow: var(--shadow-md); transform: translateY(-1px); }
.btn-success { background: var(--green); color: #fff; box-shadow: var(--shadow-sm); }
.btn-success:hover { filter: brightness(0.9); box-shadow: var(--shadow-md); transform: translateY(-1px); }
.btn-danger { background: var(--red); color: #fff; box-shadow: var(--shadow-sm); }
.btn-danger:hover { filter: brightness(0.9); box-shadow: var(--shadow-md); transform: translateY(-1px); }
.btn-outline { background: var(--bg2); border: 1px solid var(--border); color: var(--text); }
.btn-outline:hover { background: var(--bg3); box-shadow: var(--shadow-sm); }
.btn-sm { padding: 5px 10px; font-size: 11px; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; transform: none !important; }
.btn.saving { opacity: 0.7; pointer-events: none; }
.btn.saving::after {
    content: ''; display: inline-block; width: 11px; height: 11px;
    border: 2px solid rgba(128,128,128,0.3); border-top-color: currentColor; border-radius: 50%;
    margin-left: 6px; vertical-align: middle; animation: spin 0.6s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.btn-row { display: flex; gap: 8px; margin-top: 14px; }

/* ─── Route Groups ──────────────────────────────────── */
.route-group {
    border-radius: var(--radius-sm); margin-bottom: 12px; overflow: hidden;
    box-shadow: var(--shadow-sm); transition: box-shadow 200ms;
}
.route-group:hover { box-shadow: var(--shadow-md); }
.route-group-header {
    display: flex; align-items: center; justify-content: space-between;
    padding: 8px 12px; background: var(--bg3); border-bottom: 1px solid var(--border); gap: 8px;
}
.route-num {
    width: 22px; height: 22px; border-radius: 50%; background: var(--bg); border: 1px solid var(--border);
    display: flex; align-items: center; justify-content: center; font-size: 11px; font-weight: 700;
    color: var(--text2); flex-shrink: 0;
}
.route-group-header .route-match-type {
    flex: 1; padding: 5px 8px; background: var(--bg2); border: 1px solid var(--border);
    border-radius: var(--radius-sm); color: var(--text); font-size: 13px; font-weight: 600;
    outline: none; transition: border-color 150ms;
}
.route-group-header .route-match-type:focus { border-color: var(--text); }
.route-wallets-table input[placeholder="opt"] { opacity: 0.5; transition: opacity 150ms; }
.route-wallets-table input[placeholder="opt"]:focus { opacity: 1; }
.route-group-actions { padding: 6px 12px; border-top: 1px solid var(--border); background: var(--bg3); }

/* ─── Pipeline Drawer ───────────────────────────────── */
.pipeline-drawer {
    border-top: 1px solid var(--border);
    background: var(--bg2);
    flex-shrink: 0;
}
.pipeline-trigger {
    display: flex;
    align-items: center;
    padding: 8px 20px;
    cursor: pointer;
    gap: 12px;
    user-select: none;
    transition: background var(--fast);
}
.pipeline-trigger:hover { background: var(--bg3); }
.pipeline-trigger-label {
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: var(--text2);
}
.pipeline-steps-inline {
    display: flex;
    gap: 4px;
    flex: 1;
}
.step-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--bg3);
    border: 1.5px solid var(--border);
    transition: all 200ms;
}
.step-dot.done { background: var(--green); border-color: var(--green); }
.step-dot.error { background: var(--red); border-color: var(--red); }
.step-dot.in-progress { border-color: var(--text); animation: dotPulse 1.5s infinite; }
@keyframes dotPulse {
    0%, 100% { box-shadow: 0 0 0 0 var(--ring); }
    50% { box-shadow: 0 0 0 4px transparent; }
}
.pipeline-chevron {
    font-size: 10px;
    color: var(--text2);
    transition: transform 200ms;
}
.pipeline-drawer.open .pipeline-chevron { transform: rotate(180deg); }

.pipeline-body {
    max-height: 0;
    overflow: hidden;
    transition: max-height 200ms cubic-bezier(0.2, 0, 0, 1), padding 200ms;
    padding: 0 20px;
}
.pipeline-drawer.open .pipeline-body {
    max-height: 300px;
    padding: 12px 20px 16px;
}
.pipeline-actions {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-bottom: 10px;
    flex-wrap: wrap;
}
.pipeline-deploy-group {
    display: flex;
    gap: 4px;
    align-items: center;
}
.deploy-select {
    padding: 5px 8px; background: var(--bg); border: 1px solid var(--border);
    border-radius: var(--radius-sm); color: var(--text); font-size: 11px; outline: none;
}
.deploy-select:focus { border-color: var(--text); }
.pipeline-output {
    background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius-sm);
    padding: 8px 12px; font-family: var(--font-mono); font-size: 11px; color: var(--text2);
    white-space: pre-wrap; max-height: 120px; overflow-y: auto; margin: 0;
}

/* ─── Toast ─────────────────────────────────────────── */
#toast-container {
    position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
    z-index: 9999; display: flex; flex-direction: column; gap: 8px;
    pointer-events: none; max-width: 400px; width: 100%;
}
.toast {
    display: flex; align-items: center; gap: 10px; padding: 12px 16px;
    border-radius: var(--radius-md); font-size: 13px; font-weight: 500;
    pointer-events: auto; background: var(--bg2); color: var(--text);
    box-shadow: 0 4px 24px rgba(0,0,0,0.12), 0 0 0 1px rgba(0,0,0,0.04);
    opacity: 0; transform: translateY(8px) scale(0.96); will-change: transform, opacity;
}
.toast-visible { animation: toastIn 200ms cubic-bezier(0.2, 0, 0, 1) forwards; }
.toast-hiding { animation: toastOut 150ms ease forwards; }
.toast-icon { display: flex; flex-shrink: 0; }
.toast.success .toast-icon { color: var(--green); }
.toast.error .toast-icon { color: var(--red); }
.toast-msg { flex: 1; line-height: 1.4; }
.toast-close {
    background: none; border: none; color: var(--text2); font-size: 16px;
    cursor: pointer; padding: 0 2px; opacity: 0.4; transition: opacity 100ms; line-height: 1;
}
.toast-close:hover { opacity: 1; }
@keyframes toastIn {
    from { opacity: 0; transform: translateY(8px) scale(0.96); }
    to { opacity: 1; transform: translateY(0) scale(1); }
}
@keyframes toastOut {
    from { opacity: 1; transform: translateY(0) scale(1); }
    to { opacity: 0; transform: translateY(8px) scale(0.96); }
}

/* ─── Modal ─────────────────────────────────────────── */
.modal-overlay {
    position: fixed; inset: 0; z-index: 10000; display: flex; align-items: center; justify-content: center;
    background: rgba(0,0,0,0.4); backdrop-filter: blur(4px); -webkit-backdrop-filter: blur(4px);
    opacity: 0; transition: opacity 150ms ease; will-change: opacity;
}
.modal-overlay.modal-visible { opacity: 1; }
.modal-card {
    background: var(--bg2); border-radius: 12px; padding: 28px; width: 400px; max-width: 90vw;
    box-shadow: 0 20px 60px rgba(0,0,0,0.2); transform: scale(0.96);
    transition: transform 150ms cubic-bezier(0.2, 0, 0, 1); will-change: transform;
}
.modal-overlay.modal-visible .modal-card { transform: scale(1); }
.modal-title { font-size: 16px; font-weight: 600; margin-bottom: 8px; }
.modal-desc { font-size: 13px; color: var(--text2); line-height: 1.5; margin-bottom: 24px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; }

/* ─── Theme Toggle ──────────────────────────────────── */
.theme-toggle {
    background: none; border: 1px solid var(--border); border-radius: var(--radius-sm);
    width: 32px; height: 32px; cursor: pointer; display: flex; align-items: center;
    justify-content: center; color: var(--text2); transition: all var(--fast); padding: 0;
}
.theme-toggle:hover { background: var(--bg3); color: var(--text); }
.theme-toggle .icon-sun { display: block; }
.theme-toggle .icon-moon { display: none; }
[data-theme="dark"] .theme-toggle .icon-sun { display: none; }
[data-theme="dark"] .theme-toggle .icon-moon { display: block; }

/* ─── Scrollbar ─────────────────────────────────────── */
::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(0,0,0,0.12); border-radius: 5px; }
::-webkit-scrollbar-thumb:hover { background: rgba(0,0,0,0.2); }
[data-theme="dark"] ::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.1); }
[data-theme="dark"] ::-webkit-scrollbar-thumb:hover { background: rgba(255,255,255,0.18); }
