/* ============ CSS Variables ============ */
:root {
    --primary: #6366f1;
    --primary-dark: #4f46e5;
    --secondary: #8b5cf6;
    --success: #10b981;
    --danger: #ef4444;
    --warning: #f59e0b;
    --bg-dark: #0f172a;
    --bg-card: rgba(30, 41, 59, 0.7);
    --bg-card-hover: rgba(30, 41, 59, 0.9);
    --text-primary: #f1f5f9;
    --text-secondary: #94a3b8;
    --border: rgba(148, 163, 184, 0.1);
    --shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.3);
}

/* ============ Global Styles ============ */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: linear-gradient(135deg, #0f172a 0%, #1e293b 100%);
    color: var(--text-primary);
    min-height: 100vh;
    overflow-x: hidden;
}

body::before {
    content: '';
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: radial-gradient(circle at 20% 50%, rgba(99, 102, 241, 0.1) 0%, transparent 50%),
        radial-gradient(circle at 80% 80%, rgba(139, 92, 246, 0.1) 0%, transparent 50%);
    pointer-events: none;
    z-index: 0;
}

/* ============ Login Page ============ */
.login-page {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
}

.login-container {
    position: relative;
    z-index: 1;
    padding: 1.5rem;
    /* Reduced padding for mobile */
    width: 100%;
    display: flex;
    justify-content: center;
}

.login-card {
    background: var(--bg-card);
    backdrop-filter: blur(20px);
    border: 1px solid var(--border);
    border-radius: 24px;
    padding: 2.5rem;
    width: 100%;
    max-width: 480px;
    box-shadow: var(--shadow);
    animation: fadeInUp 0.6s ease-out;
}

@media (max-width: 480px) {
    .login-card {
        padding: 1.5rem;
    }

    .login-header h1 {
        font-size: 1.5rem;
    }
}


.login-header h1 {
    font-size: 2rem;
    margin-bottom: 0.5rem;
    background: linear-gradient(135deg, var(--primary), var(--secondary));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.login-header p {
    color: var(--text-secondary);
    margin-bottom: 2rem;
}

.login-features {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    margin-bottom: 2rem;
}

.feature {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem;
    background: rgba(99, 102, 241, 0.1);
    border-radius: 12px;
    transition: all 0.3s ease;
}

.feature:hover {
    background: rgba(99, 102, 241, 0.2);
    transform: translateX(5px);
}

.feature-icon {
    font-size: 1.5rem;
}

.google-signin-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.75rem;
    width: 100%;
    padding: 1rem;
    background: white;
    color: #1f2937;
    border: none;
    border-radius: 12px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    text-decoration: none;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
}

.google-signin-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.2);
}

.login-footer {
    margin-top: 2rem;
    text-align: center;
}

.login-footer p {
    color: var(--text-secondary);
    font-size: 0.875rem;
}

/* ============ Main App Container ============ */
.app-container {
    position: relative;
    z-index: 1;
    max-width: 1400px;
    margin: 0 auto;
    padding: 2rem;
}

/* ============ Header ============ */
.app-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1.5rem 2rem;
    background: var(--bg-card);
    backdrop-filter: blur(20px);
    border: 1px solid var(--border);
    border-radius: 16px;
    margin-bottom: 2rem;
    box-shadow: var(--shadow);
}

.header-left h1 {
    font-size: 1.75rem;
    background: linear-gradient(135deg, var(--primary), var(--secondary));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.header-right {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.user-profile {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.5rem 1rem;
    background: rgba(99, 102, 241, 0.1);
    border-radius: 12px;
}

.user-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    border: 2px solid var(--primary);
}

.logout-btn {
    padding: 0.5rem 1.5rem;
    background: rgba(239, 68, 68, 0.1);
    color: var(--danger);
    border: 1px solid rgba(239, 68, 68, 0.3);
    border-radius: 8px;
    cursor: pointer;
    font-weight: 500;
    transition: all 0.3s ease;
}

.logout-btn:hover {
    background: var(--danger);
    color: white;
}

/* ============ Tab Navigation ============ */
.tab-nav {
    display: flex;
    gap: 1rem;
    margin-bottom: 2rem;
}

.tab-btn {
    flex: 1;
    padding: 1rem;
    background: var(--bg-card);
    backdrop-filter: blur(20px);
    border: 1px solid var(--border);
    border-radius: 12px;
    color: var(--text-secondary);
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
}

.tab-btn span {
    font-size: 1.25rem;
}

.tab-btn:hover {
    background: var(--bg-card-hover);
    border-color: var(--primary);
}

.tab-btn.active {
    background: linear-gradient(135deg, var(--primary), var(--secondary));
    color: white;
    border-color: transparent;
}

/* ============ Tab Content ============ */
.tab-pane {
    display: none;
    animation: fadeIn 0.4s ease-out;
}

.tab-pane.active {
    display: block;
}

/* ============ Metrics Grid ============ */
.metrics-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 1.5rem;
    margin-bottom: 2rem;
}

.metric-card {
    background: var(--bg-card);
    backdrop-filter: blur(20px);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 1.5rem;
    box-shadow: var(--shadow);
    transition: all 0.3s ease;
}

.metric-card:hover {
    transform: translateY(-5px);
    box-shadow: 0 25px 30px -5px rgba(0, 0, 0, 0.4);
}

.metric-label {
    color: var(--text-secondary);
    font-size: 0.875rem;
    margin-bottom: 0.5rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.metric-value {
    font-size: 2rem;
    font-weight: 700;
    margin-bottom: 0.25rem;
}

.metric-change {
    font-size: 0.875rem;
    font-weight: 600;
}

.metric-change.positive {
    color: var(--success);
}

.metric-change.negative {
    color: var(--danger);
}

/* ============ Controls Bar ============ */
.controls-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 2rem;
}

.time-filter {
    display: flex;
    gap: 0.5rem;
}

.filter-btn {
    padding: 0.5rem 1.25rem;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text-secondary);
    cursor: pointer;
    font-weight: 500;
    transition: all 0.3s ease;
}

.filter-btn:hover {
    border-color: var(--primary);
    color: var(--primary);
}

.filter-btn.active {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
}

.refresh-btn {
    padding: 0.5rem 1.5rem;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text-primary);
    cursor: pointer;
    font-weight: 500;
    transition: all 0.3s ease;
}

.refresh-btn:hover {
    background: var(--primary);
    border-color: var(--primary);
}

/* ============ Tables ============ */
.trades-container,
.scanner-header {
    margin-bottom: 1.5rem;
}

.trades-container h2,
.scanner-header h2 {
    font-size: 1.5rem;
    margin-bottom: 1rem;
}

.table-container {
    background: var(--bg-card);
    backdrop-filter: blur(20px);
    border: 1px solid var(--border);
    border-radius: 16px;
    overflow-y: auto;
    max-height: 600px;
    box-shadow: var(--shadow);
}

table {
    width: 100%;
    border-collapse: collapse;
}

thead {
    background: rgba(99, 102, 241, 0.1);
}

th {
    padding: 1rem;
    text-align: left;
    font-weight: 600;
    color: var(--text-primary);
    text-transform: uppercase;
    font-size: 0.75rem;
    letter-spacing: 0.05em;
    position: sticky;
    top: 0;
    background: rgba(99, 102, 241, 0.1);
    backdrop-filter: blur(20px);
    z-index: 10;
}

td {
    padding: 1rem;
    border-top: 1px solid var(--border);
    color: var(--text-secondary);
}

tbody tr {
    transition: all 0.2s ease;
}

tbody tr:hover {
    background: rgba(99, 102, 241, 0.05);
}

.loading-cell {
    text-align: center;
    padding: 3rem !important;
    color: var(--text-secondary);
}

.status-badge {
    padding: 0.25rem 0.75rem;
    border-radius: 6px;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
}

.status-badge.ongoing {
    background: rgba(16, 185, 129, 0.1);
    color: var(--success);
}

.status-badge.closed {
    background: rgba(148, 163, 184, 0.1);
    color: var(--text-secondary);
}

.pl-positive {
    color: var(--success);
    font-weight: 600;
}

.pl-negative {
    color: var(--danger);
    font-weight: 600;
}

/* ============ Market Scanner ============ */
.scanner-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.scanner-status {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    color: var(--text-secondary);
}

.status-indicator {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--success);
    animation: pulse 2s infinite;
}

.telegram-config {
    background: var(--bg-card);
    backdrop-filter: blur(20px);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 1.5rem;
    margin-bottom: 2rem;
}

.telegram-config h3 {
    margin-bottom: 1rem;
}

.config-row {
    display: flex;
    gap: 1rem;
}

.scanner-controls {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 2rem;
}

.scan-btn {
    padding: 0.75rem 2rem;
    background: linear-gradient(135deg, var(--primary), var(--secondary));
    border: none;
    border-radius: 12px;
    color: white;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
}

.scan-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 10px 20px -5px rgba(99, 102, 241, 0.5);
}

.scan-info {
    color: var(--text-secondary);
    font-size: 0.875rem;
}

/* ============ Settings ============ */
.settings-container {
    max-width: 800px;
}

.settings-container h2 {
    font-size: 1.75rem;
    margin-bottom: 2rem;
}

.settings-section {
    background: var(--bg-card);
    backdrop-filter: blur(20px);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 2rem;
    margin-bottom: 2rem;
}

.settings-section h3 {
    margin-bottom: 1.5rem;
    color: var(--primary);
}

.form-group {
    margin-bottom: 1.5rem;
}

.form-group label {
    display: block;
    margin-bottom: 0.5rem;
    color: var(--text-secondary);
    font-weight: 500;
}

.input-field {
    width: 100%;
    padding: 0.75rem 1rem;
    background: rgba(15, 23, 42, 0.5);
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text-primary);
    font-size: 1rem;
    transition: all 0.3s ease;
}

.input-field:focus {
    outline: none;
    border-color: var(--primary);
    background: rgba(15, 23, 42, 0.7);
}

.help-text {
    margin-top: 0.5rem;
    color: var(--text-secondary);
    font-size: 0.875rem;
}

.help-text code {
    background: rgba(99, 102, 241, 0.1);
    padding: 0.125rem 0.5rem;
    border-radius: 4px;
    font-family: 'Courier New', monospace;
}

.help-text a {
    color: var(--primary);
    text-decoration: none;
}

.help-text a:hover {
    text-decoration: underline;
}

.settings-actions {
    margin-top: 2rem;
}

.save-settings-btn,
.save-btn {
    padding: 0.75rem 2rem;
    background: linear-gradient(135deg, var(--primary), var(--secondary));
    border: none;
    border-radius: 12px;
    color: white;
    font-weight: 600;
    font-size: 1rem;
    cursor: pointer;
    transition: all 0.3s ease;
}

.save-settings-btn:hover,
.save-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 10px 20px -5px rgba(99, 102, 241, 0.5);
}

.settings-status {
    margin-top: 1rem;
    padding: 1rem;
    border-radius: 8px;
    display: none;
}

.settings-status.success {
    display: block;
    background: rgba(16, 185, 129, 0.1);
    color: var(--success);
    border: 1px solid rgba(16, 185, 129, 0.3);
}

.settings-status.error {
    display: block;
    background: rgba(239, 68, 68, 0.1);
    color: var(--danger);
    border: 1px solid rgba(239, 68, 68, 0.3);
}

/* ============ Animations ============ */
@keyframes fadeIn {
    from {
        opacity: 0;
    }

    to {
        opacity: 1;
    }
}

@keyframes fadeInUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes pulse {

    0%,
    100% {
        opacity: 1;
    }

    50% {
        opacity: 0.5;
    }
}

/* ============ Responsive Design ============ */
/* ============ Mobile Optimization (iPhone 16 & General Mobile) ============ */
@media (max-width: 768px) {
    :root {
        --header-height: 60px;
        --nav-height: 70px;
    }

    body {
        padding-top: var(--header-height);
        padding-bottom: calc(var(--nav-height) + env(safe-area-inset-bottom));
    }

    /* Keep app container from being too wide and add safe area padding */
    .app-container {
        padding: 1rem;
        max-width: 100vw;
        overflow-x: hidden;
    }

    /* Fixed Header for Mobile */
    .app-header {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        height: var(--header-height);
        margin-bottom: 0;
        border-radius: 0;
        border-left: none;
        border-right: none;
        border-top: none;
        padding: 0.5rem 1rem;
        z-index: 1001;
        display: flex;
        justify-content: space-between;
    }

    .header-left h1 {
        font-size: 1.25rem;
    }

    .header-right {
        gap: 0.5rem;
    }

    .user-profile {
        padding: 0.25rem 0.5rem;
    }

    .user-avatar {
        width: 24px;
        height: 24px;
    }

    #userName {
        display: none;
        /* Hide name on mobile to save space */
    }

    .logout-btn {
        padding: 0.25rem 0.75rem;
        font-size: 0.8rem;
    }

    /* Bottom Navigation Bar */
    .tab-nav {
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        height: calc(var(--nav-height) + env(safe-area-inset-bottom));
        padding: 0.5rem 1rem calc(0.5rem + env(safe-area-inset-bottom)) 1rem;
        margin-bottom: 0;
        background: var(--bg-card);
        backdrop-filter: blur(30px);
        border-top: 1px solid var(--border);
        border-radius: 0;
        flex-direction: row;
        justify-content: space-around;
        z-index: 1000;
        box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.4);
    }

    .tab-btn {
        flex: 1;
        flex-direction: column;
        gap: 0.25rem;
        padding: 0.5rem 0;
        background: transparent;
        border: none;
        font-size: 0.7rem;
        border-radius: 12px;
    }

    .tab-btn span {
        font-size: 1.5rem;
    }

    .tab-btn:hover {
        background: transparent;
        border-color: transparent;
    }

    .tab-btn.active {
        background: rgba(99, 102, 241, 0.1);
        color: var(--primary);
        border-color: transparent;
    }

    /* Metrics Grid - 2 columns on mobile */
    .metrics-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 0.75rem;
        margin-bottom: 1.5rem;
    }

    .metric-card {
        padding: 1rem;
    }

    .metric-value {
        font-size: 1.25rem;
    }

    .metric-label {
        font-size: 0.7rem;
    }

    /* Controls Bar */
    .controls-bar {
        flex-direction: row;
        flex-wrap: wrap;
        gap: 0.75rem;
        align-items: center;
        justify-content: space-between;
    }

    .time-filter {
        width: 100%;
        justify-content: space-between;
    }

    .filter-btn {
        flex: 1;
        padding: 0.5rem 0.25rem;
        font-size: 0.8rem;
        text-align: center;
    }

    /* Table to Card Transformation */
    .table-container {
        background: transparent;
        border: none;
        box-shadow: none;
        overflow: visible;
        max-height: none;
    }

    table,
    thead,
    tbody,
    th,
    td,
    tr {
        display: block;
    }

    thead tr {
        position: absolute;
        top: -9999px;
        left: -9999px;
    }

    tbody tr {
        background: var(--bg-card);
        border: 1px solid var(--border);
        border-radius: 16px;
        margin-bottom: 1rem;
        padding: 1rem;
        box-shadow: var(--shadow);
    }

    td {
        border: none;
        padding: 0.5rem 0;
        position: relative;
        padding-left: 50%;
        text-align: right;
        font-size: 0.9rem;
    }

    td::before {
        content: attr(data-label);
        position: absolute;
        left: 0;
        width: 45%;
        padding-right: 10px;
        white-space: nowrap;
        text-align: left;
        font-weight: 600;
        color: var(--text-secondary);
        font-size: 0.8rem;
        text-transform: uppercase;
    }

    /* Special styling for common table cells */
    td:first-child {
        padding-left: 0;
        text-align: left;
        border-bottom: 1px solid var(--border);
        margin-bottom: 0.5rem;
        padding-bottom: 0.75rem;
        font-size: 1.1rem;
    }

    td:first-child::before {
        display: none;
    }

    td:last-child {
        padding-bottom: 0;
    }

    /* History and Scanner specific table cell mapping via JS or CSS */
    /* We'll use JS to add data-label attributes shortly */

    /* Scanner Tab Adjustments */
    .scanner-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.5rem;
    }

    .config-row {
        flex-direction: column;
        gap: 0.75rem;
    }

    /* Settings Adjustments */
    .settings-section {
        padding: 1.5rem;
    }

    .save-settings-btn {
        width: 100%;
    }

    /* Header sizes */
    .trades-container h2,
    .scanner-header h2,
    .settings-container h2 {
        font-size: 1.25rem;
        margin-bottom: 0.75rem;
    }
}

@media (max-width: 400px) {
    .metrics-grid {
        grid-template-columns: 1fr;
    }
}


/* ============ Scrollbar ============ */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: rgba(15, 23, 42, 0.5);
}

::-webkit-scrollbar-thumb {
    background: var(--primary);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--primary-dark);
}