/* ==========================================================================
   Cloud SQL Factory — Design System
   Dark mode, glassmorphism, modern aesthetics
   ========================================================================== */

/* --- CSS Variables --- */
:root {
    /* Colors */
    --bg-primary: #0a0e1a;
    --bg-secondary: #111827;
    --bg-tertiary: #1f2937;
    --surface: rgba(255, 255, 255, 0.04);
    --surface-hover: rgba(255, 255, 255, 0.08);
    --border: rgba(255, 255, 255, 0.08);
    --border-hover: rgba(255, 255, 255, 0.16);

    --text-primary: #f1f5f9;
    --text-secondary: #94a3b8;
    --text-muted: #64748b;

    --accent: #6366f1;
    --accent-light: #818cf8;
    --accent-dark: #4f46e5;
    --accent-glow: rgba(99, 102, 241, 0.25);

    --success: #22c55e;
    --success-bg: rgba(34, 197, 94, 0.12);
    --warning: #f59e0b;
    --warning-bg: rgba(245, 158, 11, 0.12);
    --danger: #ef4444;
    --danger-bg: rgba(239, 68, 68, 0.12);
    --info: #3b82f6;
    --info-bg: rgba(59, 130, 246, 0.12);

    /* Typography */
    --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    --radius: 12px;
    --radius-sm: 8px;
    --radius-lg: 16px;

    /* Transitions */
    --transition: 200ms cubic-bezier(0.4, 0, 0.2, 1);
    --transition-slow: 400ms cubic-bezier(0.4, 0, 0.2, 1);
}

/* --- Reset --- */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html {
    font-size: 16px;
    scroll-behavior: smooth;
}

body {
    font-family: var(--font);
    background: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.6;
    min-height: 100vh;
    overflow-x: hidden;

    /* Animated gradient background */
    background-image:
        radial-gradient(ellipse at 20% 50%, rgba(99, 102, 241, 0.08) 0%, transparent 50%),
        radial-gradient(ellipse at 80% 20%, rgba(139, 92, 246, 0.06) 0%, transparent 50%),
        radial-gradient(ellipse at 50% 100%, rgba(59, 130, 246, 0.05) 0%, transparent 50%);
    background-attachment: fixed;
}

/* --- Screens --- */
.screen {
    display: none;
}
.screen.active {
    display: block;
}

/* --- Glass effect --- */
.glass {
    background: rgba(255, 255, 255, 0.04);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border: 1px solid var(--border);
    border-radius: var(--radius);
}

.glass-dark {
    background: rgba(0, 0, 0, 0.3);
    backdrop-filter: blur(10px);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
}

/* ==========================================================================
   Login Screen
   ========================================================================== */
.login-container {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    padding: 2rem;
}

.login-card {
    max-width: 420px;
    width: 100%;
    padding: 3rem 2.5rem;
    text-align: center;
    animation: fadeInUp 0.6s ease-out;
}

.login-logo {
    margin-bottom: 1.5rem;
}

.logo-icon {
    font-size: 3.5rem;
    background: linear-gradient(135deg, var(--accent), var(--accent-light));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    filter: drop-shadow(0 0 20px var(--accent-glow));
}

.login-card h1 {
    font-size: 1.75rem;
    font-weight: 700;
    margin-bottom: 0.5rem;
    letter-spacing: -0.02em;
}

.login-subtitle {
    color: var(--text-secondary);
    margin-bottom: 2rem;
    font-size: 0.9rem;
}

.login-footer {
    color: var(--text-muted);
    font-size: 0.8rem;
    margin-top: 1.5rem;
}

/* ==========================================================================
   Buttons
   ========================================================================== */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.625rem 1.25rem;
    border: none;
    border-radius: var(--radius-sm);
    font-family: var(--font);
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    transition: all var(--transition);
    text-decoration: none;
    line-height: 1.4;
    white-space: nowrap;
}

.btn .material-icons-outlined {
    font-size: 1.125rem;
}

.btn-primary {
    background: linear-gradient(135deg, var(--accent), var(--accent-dark));
    color: white;
    box-shadow: 0 4px 15px var(--accent-glow);
}
.btn-primary:hover {
    transform: translateY(-1px);
    box-shadow: 0 6px 25px var(--accent-glow);
}

.btn-danger {
    background: var(--danger);
    color: white;
}
.btn-danger:hover {
    background: #dc2626;
    transform: translateY(-1px);
}

.btn-ghost {
    background: transparent;
    color: var(--text-secondary);
    border: 1px solid var(--border);
}
.btn-ghost:hover {
    background: var(--surface-hover);
    color: var(--text-primary);
    border-color: var(--border-hover);
}

.btn-sm {
    padding: 0.4rem 0.8rem;
    font-size: 0.8rem;
}

.btn-lg {
    padding: 0.875rem 2rem;
    font-size: 1rem;
    width: 100%;
    justify-content: center;
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none !important;
}

/* ==========================================================================
   Topbar
   ========================================================================== */
.topbar {
    position: sticky;
    top: 0;
    z-index: 100;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 2rem;
    height: 64px;
    border-radius: 0;
    border-top: none;
    border-left: none;
    border-right: none;
}

.topbar-left {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.topbar-logo {
    font-size: 1.5rem;
    color: var(--accent-light);
}

.topbar-title {
    font-weight: 600;
    font-size: 1rem;
    letter-spacing: -0.01em;
}

.topbar-right {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.user-email {
    color: var(--text-secondary);
    font-size: 0.8rem;
}

/* ==========================================================================
   Main Content
   ========================================================================== */
.main-content {
    max-width: 960px;
    margin: 0 auto;
    padding: 2rem;
}

.view {
    display: none;
}
.view.active {
    display: block;
    animation: fadeIn 0.3s ease-out;
}

.view-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1.5rem;
    gap: 1rem;
}

.view-header h2 {
    font-size: 1.5rem;
    font-weight: 600;
    letter-spacing: -0.02em;
}

.view-subtitle {
    color: var(--text-secondary);
    font-size: 0.85rem;
}

/* ==========================================================================
   Stats Row
   ========================================================================== */
.stats-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 1rem;
    margin-bottom: 2rem;
}

.stat-card {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 1.25rem;
    transition: all var(--transition);
}
.stat-card:hover {
    border-color: var(--border-hover);
}

.stat-icon {
    font-size: 2rem;
    padding: 0.5rem;
    border-radius: var(--radius-sm);
}
.stat-icon.running { color: var(--success); background: var(--success-bg); }
.stat-icon.pending  { color: var(--warning); background: var(--warning-bg); }
.stat-icon.deleted  { color: var(--danger);  background: var(--danger-bg); }

.stat-value {
    font-size: 1.5rem;
    font-weight: 700;
    display: block;
}

.stat-label {
    color: var(--text-secondary);
    font-size: 0.8rem;
}

/* ==========================================================================
   Instance List
   ========================================================================== */
.instance-list {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.instance-card {
    display: grid;
    grid-template-columns: 1fr auto auto;
    align-items: center;
    gap: 1.5rem;
    padding: 1.25rem 1.5rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    cursor: pointer;
    transition: all var(--transition);
}
.instance-card:hover {
    background: var(--surface-hover);
    border-color: var(--border-hover);
    transform: translateY(-1px);
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.2);
}

.instance-name {
    font-weight: 600;
    font-size: 0.95rem;
}

.instance-meta {
    color: var(--text-secondary);
    font-size: 0.8rem;
    margin-top: 0.25rem;
}

/* Status badges */
.status-badge {
    display: inline-flex;
    align-items: center;
    gap: 0.375rem;
    padding: 0.3rem 0.75rem;
    border-radius: 100px;
    font-size: 0.75rem;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.status-RUNNING     { color: var(--success); background: var(--success-bg); }
.status-PROVISIONING,
.status-PENDING     { color: var(--warning); background: var(--warning-bg); }
.status-STOPPING,
.status-DELETING    { color: var(--danger);  background: var(--danger-bg); }
.status-STOPPED,
.status-DELETED     { color: var(--text-muted); background: rgba(100,116,139,0.12); }
.status-ERROR       { color: var(--danger);  background: var(--danger-bg); }

/* Pulsing dot for active states */
.status-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: currentColor;
}
.status-RUNNING .status-dot,
.status-PROVISIONING .status-dot,
.status-PENDING .status-dot {
    animation: pulse 2s ease-in-out infinite;
}

.instance-arrow {
    color: var(--text-muted);
    font-size: 1.25rem;
}

/* Empty state */
.empty-state {
    text-align: center;
    padding: 4rem 2rem;
    color: var(--text-secondary);
}

.empty-icon {
    font-size: 4rem;
    color: var(--text-muted);
    margin-bottom: 1rem;
    display: block;
}

.empty-state p {
    margin-bottom: 1.5rem;
}

/* ==========================================================================
   Create Form
   ========================================================================== */
.create-form {
    padding: 2rem;
    max-width: 600px;
}

.form-group {
    margin-bottom: 1.5rem;
}

.form-group label {
    display: block;
    font-weight: 500;
    font-size: 0.875rem;
    margin-bottom: 0.5rem;
    color: var(--text-primary);
}

.form-group input,
.form-group select {
    width: 100%;
    padding: 0.7rem 1rem;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-family: var(--font);
    font-size: 0.9rem;
    transition: all var(--transition);
}

.form-group input:focus,
.form-group select:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-glow);
}

.form-group input::placeholder {
    color: var(--text-muted);
}

.form-hint {
    display: block;
    color: var(--text-muted);
    font-size: 0.75rem;
    margin-top: 0.375rem;
}

.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
}

.form-info {
    display: flex;
    align-items: flex-start;
    gap: 0.75rem;
    padding: 1rem 1.25rem;
    margin-bottom: 1.5rem;
    color: var(--text-secondary);
    font-size: 0.85rem;
}

.form-info .material-icons-outlined {
    color: var(--info);
    font-size: 1.25rem;
    margin-top: 0.1rem;
}

.form-info ul {
    margin-top: 0.375rem;
    padding-left: 1.25rem;
}

.form-info li {
    margin-bottom: 0.125rem;
}

.form-actions {
    display: flex;
    justify-content: flex-end;
    gap: 0.75rem;
    margin-top: 0.5rem;
}

/* ==========================================================================
   Detail View
   ========================================================================== */
.detail-content {
    max-width: 600px;
}

.detail-card {
    padding: 1.5rem;
    margin-bottom: 1rem;
}

.detail-field {
    display: flex;
    justify-content: space-between;
    padding: 0.75rem 0;
    border-bottom: 1px solid var(--border);
}
.detail-field:last-child {
    border-bottom: none;
}

.detail-label {
    color: var(--text-secondary);
    font-size: 0.85rem;
}

.detail-value {
    font-weight: 500;
    font-size: 0.9rem;
    text-align: right;
}

.detail-value code {
    background: var(--bg-tertiary);
    padding: 0.125rem 0.5rem;
    border-radius: 4px;
    font-size: 0.8rem;
    font-family: 'JetBrains Mono', 'Fira Code', monospace;
}

.detail-actions {
    margin-top: 1.5rem;
    display: flex;
    gap: 0.75rem;
}

/* ==========================================================================
   Toast Notifications
   ========================================================================== */
.toast-container {
    position: fixed;
    bottom: 2rem;
    right: 2rem;
    z-index: 9999;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.toast {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.875rem 1.25rem;
    border-radius: var(--radius-sm);
    font-size: 0.875rem;
    backdrop-filter: blur(20px);
    animation: slideInRight 0.3s ease-out;
    min-width: 300px;
    max-width: 450px;
    box-shadow: 0 8px 30px rgba(0, 0, 0, 0.4);
}

.toast-success {
    background: rgba(34, 197, 94, 0.15);
    border: 1px solid rgba(34, 197, 94, 0.3);
    color: var(--success);
}

.toast-error {
    background: rgba(239, 68, 68, 0.15);
    border: 1px solid rgba(239, 68, 68, 0.3);
    color: var(--danger);
}

.toast-info {
    background: rgba(59, 130, 246, 0.15);
    border: 1px solid rgba(59, 130, 246, 0.3);
    color: var(--info);
}

/* ==========================================================================
   Loading spinner
   ========================================================================== */
.spinner {
    display: inline-block;
    width: 16px;
    height: 16px;
    border: 2px solid rgba(255, 255, 255, 0.2);
    border-top-color: var(--accent-light);
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
}

/* ==========================================================================
   Animations
   ========================================================================== */
@keyframes fadeIn {
    from { opacity: 0; }
    to   { opacity: 1; }
}

@keyframes fadeInUp {
    from { opacity: 0; transform: translateY(20px); }
    to   { opacity: 1; transform: translateY(0); }
}

@keyframes slideInRight {
    from { opacity: 0; transform: translateX(60px); }
    to   { opacity: 1; transform: translateX(0); }
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50%      { opacity: 0.4; }
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* ==========================================================================
   Responsive
   ========================================================================== */
@media (max-width: 640px) {
    .main-content {
        padding: 1rem;
    }
    .topbar {
        padding: 0 1rem;
    }
    .view-header {
        flex-direction: column;
        align-items: flex-start;
    }
    .instance-card {
        grid-template-columns: 1fr auto;
    }
    .instance-arrow {
        display: none;
    }
    .form-row {
        grid-template-columns: 1fr;
    }
    .stats-row {
        grid-template-columns: 1fr;
    }
}
