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

:root {
    --bg-dark: #0f1117;
    --bg-card: #1a1d27;
    --bg-sidebar: #14161e;
    --bg-input: #1e2130;
    --border: #2a2d3a;
    --text-primary: #e8eaed;
    --text-secondary: #9aa0a6;
    --text-muted: #5f6368;
    --accent: #6c63ff;
    --accent-hover: #7c74ff;
    --green: #34a853;
    --red: #ea4335;
    --yellow: #fbbc04;
    --blue: #4285f4;
    --radius: 12px;
    --radius-sm: 8px;
}

body {
    font-family: 'Inter', -apple-system, sans-serif;
    background: var(--bg-dark);
    color: var(--text-primary);
    min-height: 100vh;
}

/* ─── Layout ─────────────────────────────────────────────────────────────── */
.app {
    display: flex;
    min-height: 100vh;
}

.sidebar {
    width: 240px;
    background: var(--bg-sidebar);
    border-right: 1px solid var(--border);
    padding: 24px 16px;
    display: flex;
    flex-direction: column;
    gap: 32px;
    position: fixed;
    height: 100vh;
}

.sidebar-header {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 0 8px;
}

.logo {
    font-size: 28px;
}

.sidebar-header h1 {
    font-size: 1.2rem;
    font-weight: 700;
    letter-spacing: -0.5px;
}

.badge {
    background: var(--accent);
    color: white;
    font-size: 0.65rem;
    padding: 2px 8px;
    border-radius: 20px;
    font-weight: 600;
    text-transform: uppercase;
}

nav {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.nav-btn {
    background: none;
    border: none;
    color: var(--text-secondary);
    font-size: 0.9rem;
    font-family: inherit;
    padding: 10px 12px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    text-align: left;
    display: flex;
    align-items: center;
    gap: 10px;
    transition: all 0.15s;
}

.nav-btn:hover {
    background: rgba(108, 99, 255, 0.1);
    color: var(--text-primary);
}

.nav-btn.active {
    background: rgba(108, 99, 255, 0.15);
    color: var(--accent);
    font-weight: 600;
}

.nav-icon {
    font-size: 1.1rem;
}

/* ─── Main ───────────────────────────────────────────────────────────────── */
.main {
    flex: 1;
    margin-left: 240px;
    padding: 32px 40px;
    max-width: 1000px;
}

.view {
    display: none;
}

.view.active {
    display: block;
}

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

.view-header h2 {
    font-size: 1.5rem;
    font-weight: 700;
}

/* ─── Buttons ────────────────────────────────────────────────────────────── */
.btn {
    background: var(--bg-input);
    color: var(--text-primary);
    border: 1px solid var(--border);
    padding: 8px 16px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-family: inherit;
    font-size: 0.85rem;
    font-weight: 500;
    transition: all 0.15s;
}

.btn:hover {
    border-color: var(--accent);
}

.btn-sm {
    padding: 6px 12px;
    font-size: 0.8rem;
}

.btn-primary {
    background: var(--accent);
    border-color: var(--accent);
    color: white;
}

.btn-primary:hover {
    background: var(--accent-hover);
}

.btn-lg {
    padding: 12px 32px;
    font-size: 1rem;
}

.btn-danger {
    background: rgba(234, 67, 53, 0.1);
    border-color: var(--red);
    color: var(--red);
}

.btn-danger:hover {
    background: rgba(234, 67, 53, 0.2);
}

/* ─── Clients Grid ───────────────────────────────────────────────────────── */
.clients-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
    gap: 16px;
}

.client-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px;
    transition: border-color 0.15s;
}

.client-card:hover {
    border-color: var(--accent);
}

.client-card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 16px;
}

.client-card-header h3 {
    font-size: 1rem;
    font-weight: 600;
}

.client-id {
    color: var(--text-muted);
    font-size: 0.8rem;
    font-family: monospace;
}

.client-meta {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    margin-bottom: 16px;
}

.meta-item {
    font-size: 0.8rem;
}

.meta-label {
    color: var(--text-muted);
    margin-bottom: 2px;
}

.meta-value {
    font-family: monospace;
    font-weight: 500;
}

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

.status-dot.active {
    background: var(--green);
}

.status-dot.inactive {
    background: var(--red);
}

.client-actions {
    display: flex;
    gap: 8px;
    margin-top: 12px;
    padding-top: 12px;
    border-top: 1px solid var(--border);
}

/* ─── Modal ────────────────────────────────────────────────────────────────── */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    opacity: 1;
    transition: opacity 0.3s ease;
}

.modal-overlay.hidden {
    display: none;
    opacity: 0;
}

.modal {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 32px;
    width: 400px;
    max-width: 90vw;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
    transform: translateY(0);
    animation: modalSlideIn 0.3s ease forwards;
}

@keyframes modalSlideIn {
    from {
        opacity: 0;
        transform: translateY(20px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.modal h3 {
    margin-top: 0;
    margin-bottom: 12px;
    color: var(--text-primary);
    font-size: 1.2rem;
}

.modal p {
    color: var(--text-secondary);
    margin-bottom: 24px;
    font-size: 0.95rem;
    line-height: 1.5;
}

.modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 12px;
}

/* ─── Form ───────────────────────────────────────────────────────────────── */
.setup-form {
    display: flex;
    flex-direction: column;
    gap: 32px;
    position: relative;
    overflow: hidden;
}

@keyframes spinner {
    to {
        transform: rotate(360deg);
    }
}

.spin {
    animation: spinner 1s linear infinite;
}

/* ─── Stepper Navigation ─────────────────────────────────────────────────── */
.stepper-nav {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 32px;
    padding: 0 16px;
    position: relative;
}

.step-indicator {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    position: relative;
    z-index: 2;
    transition: all 0.3s ease;
}

.step-num {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: var(--bg-card);
    border: 2px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    color: var(--text-muted);
    transition: all 0.3s ease;
}

.step-label {
    font-size: 0.75rem;
    color: var(--text-muted);
    font-weight: 500;
    white-space: nowrap;
    transition: all 0.3s ease;
}

.step-connector {
    flex: 1;
    height: 2px;
    background: var(--border);
    margin: -20px 8px 0;
    z-index: 1;
    transition: all 0.3s ease;
}

/* Active and Completed Steps */
.step-indicator.active .step-num {
    border-color: var(--accent);
    background: rgba(108, 99, 255, 0.1);
    color: var(--accent);
    box-shadow: 0 0 0 4px rgba(108, 99, 255, 0.1);
}

.step-indicator.active .step-label {
    color: var(--accent);
}

.step-indicator.completed .step-num {
    background: var(--accent);
    border-color: var(--accent);
    color: white;
}

.step-indicator.completed .step-label {
    color: var(--text-primary);
}

.step-connector.completed {
    background: var(--accent);
}

/* ─── Step Content Visibility ────────────────────────────────────────────── */
.step-content {
    display: none;
    animation: fadeIn 0.4s ease forwards;
}

.step-content.active {
    display: block;
}

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

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.form-section {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 24px;
}

.form-section h3 {
    font-size: 1rem;
    font-weight: 600;
    margin-bottom: 16px;
    display: flex;
    align-items: center;
    gap: 8px;
}

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

.form-group {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.form-group.full-width {
    grid-column: 1 / -1;
}

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

input,
textarea,
select {
    background: var(--bg-input);
    border: 1px solid var(--border);
    color: var(--text-primary);
    padding: 10px 12px;
    border-radius: var(--radius-sm);
    font-family: inherit;
    font-size: 0.9rem;
    transition: border-color 0.15s;
}

input:focus,
textarea:focus {
    outline: none;
    border-color: var(--accent);
}

small {
    color: var(--text-muted);
    font-size: 0.75rem;
}

.checkbox-label {
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    font-size: 0.9rem;
    color: var(--text-secondary);
}

.form-actions {
    display: flex;
    justify-content: flex-end;
}

.split-actions {
    justify-content: space-between;
}

.btn-back {
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text-primary);
}

.btn-back:hover {
    background: rgba(255, 255, 255, 0.05);
}

/* ─── API Key Verification Inputs ────────────────────────────────────────── */
.input-with-btn {
    display: flex;
    gap: 8px;
    align-items: stretch;
}

.input-with-btn input {
    flex: 1;
}

.multi-input {
    display: grid;
    grid-template-columns: 1fr 1fr auto;
}

.btn-test {
    background: var(--bg-input);
    color: var(--accent);
    border: 1px solid var(--accent);
    padding: 0 16px;
    border-radius: var(--radius-sm);
    font-weight: 600;
    white-space: nowrap;
}

.btn-test:hover {
    background: rgba(108, 99, 255, 0.1);
}

.btn-test:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

.test-status {
    margin-top: 4px;
    display: block;
    min-height: 18px;
}

.test-status.success {
    color: var(--green);
}

.test-status.error {
    color: var(--red);
}

.test-status.loading {
    color: var(--text-secondary);
}

.step-hint {
    color: var(--text-secondary);
    font-size: 0.85rem;
    background: rgba(255, 255, 255, 0.03);
    padding: 10px 16px;
    border-radius: var(--radius-sm);
    border-left: 3px solid var(--accent);
}

.mb-4 {
    margin-bottom: 16px;
}

.mt-4 {
    margin-top: 16px;
}

.mt-3 {
    margin-top: 12px;
}

.mt-2 {
    margin-top: 8px;
}

.mb-2 {
    margin-bottom: 8px;
}

.p-3 {
    padding: 16px;
}

.port-hint {
    font-size: 0.75rem;
    font-weight: 400;
    color: var(--text-muted);
}

/* ─── Terminal Output ────────────────────────────────────────────────────── */
.output-section {
    margin-top: 24px;
}

.output-section h3 {
    margin-bottom: 12px;
    font-size: 1rem;
}

.terminal {
    background: #0d1117;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px;
    font-family: 'JetBrains Mono', 'Fira Code', monospace;
    font-size: 0.8rem;
    line-height: 1.6;
    max-height: 500px;
    overflow-y: auto;
    white-space: pre-wrap;
    word-break: break-all;
}

.terminal .line-stdout {
    color: #c9d1d9;
}

.terminal .line-stderr {
    color: #f85149;
}

.terminal .line-success {
    color: #3fb950;
}

.hidden {
    display: none;
}

.loading {
    color: var(--text-muted);
    padding: 20px;
    text-align: center;
}

/* ─── Responsive ─────────────────────────────────────────────────────────── */
@media (max-width: 768px) {
    .sidebar {
        width: 60px;
        padding: 16px 8px;
    }

    .sidebar-header h1,
    .badge {
        display: none;
    }

    .nav-btn span:not(.nav-icon) {
        display: none;
    }

    .main {
        margin-left: 60px;
        padding: 20px;
    }

    .form-grid {
        grid-template-columns: 1fr;
    }

    .clients-grid {
        grid-template-columns: 1fr;
    }
}