/* Custom styles for TradingView IBKR Dashboard */

:root {
    --primary: #3b82f6;
    --primary-dark: #2563eb;
    --success: #10b981;
    --warning: #f59e0b;
    --danger: #ef4444;
    --gray-50: #f9fafb;
    --gray-100: #f3f4f6;
    --gray-200: #e5e7eb;
    --gray-300: #d1d5db;
    --gray-400: #9ca3af;
    --gray-500: #6b7280;
    --gray-600: #4b5563;
    --gray-700: #374151;
    --gray-800: #1f2937;
    --gray-900: #111827;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

/* Hide browser-native password reveal icons */
input[type="password"]::-ms-reveal,
input[type="password"]::-ms-clear {
    display: none;
}
input[type="password"]::-webkit-credentials-auto-fill-button,
input[type="password"]::-webkit-textfield-decoration-container {
    display: none;
}

/* Sidebar */
.sidebar {
    min-height: 100vh;
    background: linear-gradient(180deg, var(--gray-900) 0%, var(--gray-800) 100%);
}

.sidebar-link {
    display: flex;
    align-items: center;
    padding: 0.75rem 1rem;
    color: var(--gray-300);
    text-decoration: none;
    border-radius: 0.5rem;
    margin: 0.25rem 0;
    transition: all 0.2s;
}

.sidebar-link:hover {
    background-color: var(--gray-700);
    color: white;
}

.sidebar-link.active {
    background-color: var(--primary);
    color: white;
}

.sidebar-link svg {
    width: 1.25rem;
    height: 1.25rem;
    margin-right: 0.75rem;
}

/* Cards */
.stat-card {
    background: white;
    border-radius: 0.75rem;
    padding: 1.5rem;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
    transition: transform 0.2s, box-shadow 0.2s;
}

.stat-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
}

.stat-card .icon {
    width: 3rem;
    height: 3rem;
    border-radius: 0.5rem;
    display: flex;
    align-items: center;
    justify-content: center;
}

.stat-card .value {
    font-size: 1.875rem;
    font-weight: 700;
    color: var(--gray-900);
}

.stat-card .label {
    font-size: 0.875rem;
    color: var(--gray-500);
}

/* Status indicators */
.status-dot {
    width: 0.75rem;
    height: 0.75rem;
    border-radius: 50%;
    display: inline-block;
}

.status-dot.connected {
    background-color: var(--success);
    box-shadow: 0 0 0 3px rgba(16, 185, 129, 0.2);
}

.status-dot.disconnected {
    background-color: var(--danger);
    box-shadow: 0 0 0 3px rgba(239, 68, 68, 0.2);
}

.status-dot.pending {
    background-color: var(--warning);
    box-shadow: 0 0 0 3px rgba(245, 158, 11, 0.2);
}

.status-dot.disabled {
    background-color: var(--gray-400);
    box-shadow: 0 0 0 3px rgba(156, 163, 175, 0.2);
}

/* Tables */
.data-table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
}

.data-table th {
    background-color: var(--gray-50);
    padding: 0.75rem 1rem;
    text-align: left;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    color: var(--gray-500);
    border-bottom: 1px solid var(--gray-200);
}

.data-table td {
    padding: 0.75rem 1rem;
    border-bottom: 1px solid var(--gray-100);
    font-size: 0.875rem;
}

.data-table tr:hover {
    background-color: var(--gray-50);
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0.5rem 1rem;
    font-size: 0.875rem;
    font-weight: 500;
    border-radius: 0.5rem;
    transition: all 0.2s;
    cursor: pointer;
    border: none;
}

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

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

.btn-success {
    background-color: var(--success);
    color: white;
}

.btn-danger {
    background-color: var(--danger);
    color: white;
}

.btn-outline {
    background-color: transparent;
    border: 1px solid var(--gray-300);
    color: var(--gray-700);
}

.btn-outline:hover {
    background-color: var(--gray-50);
}

/* Form inputs */
.form-input {
    width: 100%;
    padding: 0.625rem 0.875rem;
    font-size: 0.875rem;
    border: 1px solid var(--gray-300);
    border-radius: 0.5rem;
    transition: border-color 0.2s, box-shadow 0.2s;
}

.form-input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

/* Code blocks */
.code-block {
    background-color: var(--gray-900);
    color: var(--gray-100);
    padding: 1rem;
    border-radius: 0.5rem;
    font-family: 'Monaco', 'Consolas', monospace;
    font-size: 0.8125rem;
    overflow-x: auto;
    position: relative;
}

.code-block .copy-btn {
    position: absolute;
    top: 0.5rem;
    right: 0.5rem;
    padding: 0.25rem 0.5rem;
    font-size: 0.75rem;
    background-color: var(--gray-700);
    color: var(--gray-300);
    border: none;
    border-radius: 0.25rem;
    cursor: pointer;
}

.code-block .copy-btn:hover {
    background-color: var(--gray-600);
}

/* Alerts */
.alert {
    padding: 1rem;
    border-radius: 0.5rem;
    margin-bottom: 1rem;
}

.alert-success {
    background-color: rgba(16, 185, 129, 0.1);
    border: 1px solid rgba(16, 185, 129, 0.2);
    color: #065f46;
}

.alert-error {
    background-color: rgba(239, 68, 68, 0.1);
    border: 1px solid rgba(239, 68, 68, 0.2);
    color: #991b1b;
}

.alert-warning {
    background-color: rgba(245, 158, 11, 0.1);
    border: 1px solid rgba(245, 158, 11, 0.2);
    color: #92400e;
}


/* Loading spinner */
.spinner {
    width: 1.25rem;
    height: 1.25rem;
    border: 2px solid var(--gray-200);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

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

/* Mobile Header */
.mobile-header {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: 56px;
    background: var(--gray-900);
    color: white;
    align-items: center;
    padding: 0 1rem;
    z-index: 1000;
    gap: 0.75rem;
}

.mobile-menu-btn {
    background: none;
    border: none;
    color: white;
    cursor: pointer;
    padding: 0.5rem;
    border-radius: 0.375rem;
}

.mobile-menu-btn:hover {
    background: var(--gray-700);
}

.mobile-header-title {
    font-weight: 600;
    font-size: 1rem;
}

.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 1001;
}

.sidebar-overlay.active {
    display: block;
}

/* Responsive */
@media (max-width: 768px) {
    .mobile-header {
        display: flex;
    }

    .sidebar {
        position: fixed;
        top: 0;
        left: 0;
        width: 260px;
        height: 100vh;
        z-index: 1002;
        transform: translateX(-100%);
        transition: transform 0.3s ease;
    }

    .sidebar.open {
        transform: translateX(0);
    }

    main.ml-64,
    .ml-64 {
        margin-left: 0 !important;
        padding: 1rem !important;
        padding-top: 72px !important;
    }

    .stat-card {
        max-width: 100% !important;
    }

    .account-card-header {
        padding: 0.75rem 1rem;
    }

    .account-card-body {
        padding: 1rem;
    }

    .account-card-footer {
        flex-direction: column;
        gap: 0.75rem;
        align-items: flex-start;
        padding: 0.75rem 1rem;
    }

    .account-fields-row,
    .account-fields-row-3 {
        grid-template-columns: 1fr;
    }

    .code-block {
        font-size: 0.75rem;
    }

    .data-table th,
    .data-table td {
        padding: 0.5rem 0.625rem;
        font-size: 0.75rem;
    }

    h2.text-xl, h2.text-2xl {
        font-size: 1.25rem;
    }
}

/* Account card */
.account-card {
    background: white;
    border: 1px solid var(--gray-200);
    border-radius: 0.75rem;
    margin-bottom: 1.25rem;
    overflow: hidden;
    transition: box-shadow 0.2s, border-color 0.2s;
}

.account-card:hover {
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
    border-color: var(--gray-300);
}

.account-card.disabled {
    opacity: 0.55;
    background: var(--gray-50);
}

.account-card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem 1.5rem;
    border-bottom: 1px solid var(--gray-100);
    background: var(--gray-50);
}

.account-card-title {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.account-card-icon {
    width: 2.25rem;
    height: 2.25rem;
    border-radius: 0.5rem;
    background: var(--primary);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 0.875rem;
}

.account-card.disabled .account-card-icon {
    background: var(--gray-400);
}

.account-card-name {
    font-size: 0.9375rem;
    font-weight: 600;
    color: var(--gray-900);
    margin: 0;
}

.account-card-status {
    font-size: 0.75rem;
    color: var(--gray-500);
}

.account-card-toggle {
    display: flex;
    align-items: center;
}

.account-card-body {
    padding: 1.25rem 1.5rem;
}

.account-section {
    margin-bottom: 1rem;
}

.account-section:last-child {
    margin-bottom: 0;
}

.account-section-label {
    font-size: 0.6875rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--gray-400);
    margin-bottom: 0.5rem;
}

.account-fields-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.75rem;
}

.account-fields-row-3 {
    grid-template-columns: 1fr 1fr 1fr;
}

.account-field label {
    display: block;
    font-size: 0.75rem;
    font-weight: 500;
    color: var(--gray-600);
    margin-bottom: 0.25rem;
}

.account-field .form-input {
    font-size: 0.8125rem;
    padding: 0.5rem 0.75rem;
}

.account-card-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.75rem 1.5rem;
    border-top: 1px solid var(--gray-100);
    background: var(--gray-50);
}

.gateway-info {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.gateway-label {
    font-size: 0.6875rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--gray-400);
}

.gateway-state {
    font-size: 0.8125rem;
}

.account-actions {
    display: flex;
    gap: 0.5rem;
}

.btn-action {
    display: inline-flex;
    align-items: center;
    gap: 0.375rem;
    padding: 0.375rem 0.75rem;
    font-size: 0.75rem;
    font-weight: 500;
    border-radius: 0.375rem;
    border: 1px solid var(--gray-200);
    background: white;
    color: var(--gray-600);
    cursor: pointer;
    transition: all 0.15s;
}

.btn-action:hover {
    background: var(--gray-50);
    border-color: var(--gray-300);
    color: var(--gray-800);
}

.btn-action-restart:hover {
    border-color: var(--warning);
    color: #b45309;
    background: rgba(245, 158, 11, 0.05);
}

.btn-action-sync:hover {
    border-color: var(--primary);
    color: var(--primary-dark);
    background: rgba(59, 130, 246, 0.05);
}

.btn-action-save:hover {
    border-color: #10b981;
    color: #059669;
    background: rgba(16, 185, 129, 0.05);
}

.btn-action-connect {
    color: #10b981;
    border-color: #10b981;
}

.btn-action-connect:hover {
    border-color: #059669;
    color: #047857;
    background: rgba(16, 185, 129, 0.1);
}

.btn-action-disconnect {
    color: #ef4444;
    border-color: #ef4444;
}

.btn-action-disconnect:hover {
    border-color: #dc2626;
    color: #b91c1c;
    background: rgba(239, 68, 68, 0.1);
}

.btn-action-stop {
    color: #f59e0b;
    border-color: #f59e0b;
}

.btn-action-stop:hover {
    border-color: #d97706;
    color: #b45309;
    background: rgba(245, 158, 11, 0.1);
}

.btn-action-start {
    color: #10b981;
    border-color: #10b981;
}

.btn-action-start:hover {
    border-color: #059669;
    color: #047857;
    background: rgba(16, 185, 129, 0.1);
}

/* Toggle switch */
.toggle {
    position: relative;
    width: 3rem;
    height: 1.5rem;
    background-color: var(--gray-300);
    border-radius: 1rem;
    cursor: pointer;
    transition: background-color 0.2s;
}

.toggle.active {
    background-color: var(--success);
}

.toggle.active.toggle-manual {
    background-color: #f59e0b;
}

.toggle::after {
    content: '';
    position: absolute;
    top: 0.125rem;
    left: 0.125rem;
    width: 1.25rem;
    height: 1.25rem;
    background-color: white;
    border-radius: 50%;
    transition: transform 0.2s;
}

.toggle.active::after {
    transform: translateX(1.5rem);
}

/* Toggle switch (checkbox-based) */
.toggle-switch {
    position: relative;
    display: inline-block;
    width: 44px;
    height: 24px;
    flex-shrink: 0;
}

.toggle-switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.toggle-slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: var(--gray-300);
    transition: 0.3s;
    border-radius: 24px;
}

.toggle-slider:before {
    position: absolute;
    content: "";
    height: 18px;
    width: 18px;
    left: 3px;
    bottom: 3px;
    background-color: white;
    transition: 0.3s;
    border-radius: 50%;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
}

.toggle-switch input:checked + .toggle-slider {
    background-color: var(--success);
}

.toggle-switch input:checked + .toggle-slider:before {
    transform: translateX(20px);
}

.toggle-switch input:disabled + .toggle-slider {
    opacity: 0.5;
    cursor: not-allowed;
}

/* Password field */
.password-field {
    position: relative;
}

.password-field .toggle-visibility {
    position: absolute;
    right: 0.5rem;
    top: 50%;
    transform: translateY(-50%);
    background: none;
    border: none;
    color: var(--gray-400);
    cursor: pointer;
}

/* Trade log colors */
.trade-buy {
    color: var(--success);
    font-weight: 600;
}

.trade-sell {
    color: var(--danger);
    font-weight: 600;
}

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

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

.trade-status-pending {
    color: var(--warning);
}
