/* Reset and Base Styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background-color: #f8fafc;
    color: #334155;
    line-height: 1.6;
}

/* Loading Screen */
.loading-screen {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100vh;
    gap: 1rem;
}

/* Login Screen */
.login-screen {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100vh;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
}

.login-card {
    background: white;
    padding: 3rem;
    border-radius: 12px;
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.1);
    text-align: center;
    max-width: 400px;
    width: 100%;
    margin: 1rem;
}

.login-card h1 {
    color: #1e293b;
    margin-bottom: 1rem;
    font-size: 2rem;
}

/* (moved valid .modal-overlay rules to the Modal section below) */

.login-card p {
    color: #64748b;
    margin-bottom: 2rem;
}

/* Main App Layout */
.main-app {
    min-height: 100vh;
}

.app-header {
    background: white;
    border-bottom: 1px solid #e2e8f0;
    padding: 1rem 2rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

.app-header h1 {
    color: #1e293b;
    font-size: 1.5rem;
}

.user-info {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.app-nav {
    background: white;
    border-bottom: 1px solid #e2e8f0;
    padding: 0 2rem;
    display: flex;
    gap: 0;
}

.nav-btn {
    background: none;
    border: none;
    padding: 1rem 1.5rem;
    color: #64748b;
    font-weight: 500;
    cursor: pointer;
    border-bottom: 2px solid transparent;
    transition: all 0.2s;
}

.nav-btn:hover {
    color: #3b82f6;
}

.nav-btn.active {
    color: #3b82f6;
    border-bottom-color: #3b82f6;
}

/* Content Areas */
.dashboard,
.feeds,
.logs {
    padding: 2rem;
    max-width: 1200px;
    margin: 0 auto;
}

/* Cards */
.card {
    background: white;
    border-radius: 8px;
    padding: 1.5rem;
    margin-bottom: 1.5rem;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
    border: 1px solid #e2e8f0;
}

.card h3 {
    color: #1e293b;
    margin-bottom: 1rem;
    font-size: 1.25rem;
}

/* subtle count next to headings */
.muted-count {
    color: #64748b;
    font-weight: 500;
    margin-left: 0.25rem;
}


/* Connection Status */
.connection-status {
    display: flex;
    align-items: center;
    justify-content: flex-start;
    gap: 1rem;
    flex-wrap: wrap;
    /* allow next-line placement for disconnect */
}

/* Ensure Disconnect button sits on its own line below */
.disconnect-row {
    width: 100%;
    margin-top: 0.5rem;
}

/* Align the refresh button to the far right of the connection row */
.btn-refresh {
    margin-left: auto;
}

/* Default to desktop label; hide mobile variant */
.btn-refresh .label-desktop {
    display: inline;
}

.btn-refresh .label-mobile {
    display: none;
}

/* Utility for responsive line breaks */
.mobile-only {
    display: none;
}

.connection-status.connected {
    color: #059669;
}

.connection-status.disconnected {
    color: #dc2626;
}

/* Buttons */
.btn {
    background: #3b82f6;
    color: white;
    border: none;
    padding: 0.75rem 1.5rem;
    border-radius: 6px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
    text-decoration: none;
    display: inline-block;
    text-align: center;
}

.btn:hover:not(:disabled) {
    background: #2563eb;
    transform: translateY(-1px);
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
}

.btn-secondary {
    background: #6b7280;
}

.btn-secondary:hover:not(:disabled) {
    background: #4b5563;
}

.btn-danger {
    background: #dc2626;
}

.btn-danger:hover:not(:disabled) {
    background: #b91c1c;
}

.btn-small {
    padding: 0.5rem 1rem;
    font-size: 0.875rem;
}

.btn-primary {
    background: #3b82f6;
}

/* Feeds */
.feeds-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 2rem;
}

.feeds-header h2 {
    color: #1e293b;
}

.feeds-list {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.feed-item {
    background: white;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    padding: 1.5rem;
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
}

.feed-info h4 {
    color: #1e293b;
    margin-bottom: 0.5rem;
}

.feed-info p {
    color: #64748b;
    margin-bottom: 0.5rem;
    word-break: break-all;
}

.feed-meta {
    display: flex;
    gap: 1rem;
    font-size: 0.875rem;
    color: #64748b;
}

.status-active {
    color: #059669;
    font-weight: 500;
}

.status-inactive {
    color: #dc2626;
    font-weight: 500;
}

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

/* Modal */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    padding: 1rem;
}

/* Modal card */
.modal {
    background: white;
    border-radius: 8px;
    padding: 2rem;
    width: 100%;
    max-width: 500px;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.2);
}

.modal h3 {
    color: #1e293b;
    position: relative;
    margin-bottom: 1.5rem;

    /* Improve mobile select dropdown alignment inside modal */
}

/* Subtle differentiation for nested modals if future stacked usage */
.modal form .form-group:last-of-type {
    margin-bottom: 0.5rem;
}

/* Forms */
.form-group {
    margin-bottom: 1rem;
}

.form-group label {
    display: block;
    color: #374151;
    font-weight: 500;
    margin-bottom: 0.5rem;
}

.form-group input,
.form-group select,
.form-group textarea {
    width: 100%;
    padding: 0.75rem;
    border: 1px solid #d1d5db;
    border-radius: 6px;
    font-size: 1rem;
    transition: border-color 0.2s;
    display: block;
    /* ensure predictable width calculations */
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
    outline: none;
    border-color: #3b82f6;
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

.form-group input[type="checkbox"] {
    width: auto;
    margin-right: 0.5rem;
}

.form-actions {
    display: flex;
    gap: 1rem;
    justify-content: flex-end;
    margin-top: 2rem;
}

/* Logs */
.logs-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 2rem;
}

.logs-filters .filter-select.level-select {
    width: 140px;
}

.logs-filters {
    display: flex;
    gap: 1rem;
    align-items: center;
}

.logs-filters .filter-select.action-select {
    width: 160px;
}

.logs-filters select {
    padding: 0.4rem 0.5rem;
    border: 1px solid #d1d5db;
    border-radius: 6px;
    font-size: 0.95rem;
}

/* Tighter filter controls to fit on one row */
.logs-filters .filter-select.level-select {
    width: 140px;
}

.logs-filters .filter-select.action-select {
    width: 160px;
}

.logs-filters .btn {
    white-space: nowrap;
}

.logs-list {
    background: white;
    border-radius: 8px;
    border: 1px solid #e2e8f0;
    overflow: hidden;
}

.log-item {
    display: grid;
    grid-template-columns: 150px 80px 120px 1fr;
    gap: 1rem;
    padding: 1rem;
    border-bottom: 1px solid #f1f5f9;
    align-items: start;
}

.log-item:last-child {
    border-bottom: none;
}

.log-item.log-error {
    background: #fef2f2;
    border-left: 4px solid #dc2626;
}

.log-item.log-warn {
    background: #fffbeb;
    border-left: 4px solid #f59e0b;
}

.log-item.log-info {
    background: #f0f9ff;
    border-left: 4px solid #3b82f6;
}

.log-time {
    font-size: 0.875rem;
    color: #64748b;
}

.log-level {
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
}

.log-action {
    font-size: 0.875rem;
    color: #64748b;
}

.log-message {
    color: #1e293b;
}

.log-url {
    grid-column: 1 / -1;
    font-size: 0.875rem;
    color: #64748b;
    word-break: break-all;
    margin-top: 0.5rem;
}

.logs-pagination {
    text-align: center;
    margin-top: 2rem;
}

/* Empty States */
.empty-state {
    text-align: center;
    padding: 3rem 1rem;
    color: #64748b;
}

.disabled-section {
    opacity: 0.6;
    pointer-events: none;
}

/* Last Run Results */
.last-run {
    margin-top: 1rem;
    padding: 1rem;
    background: #f8fafc;
    border-radius: 6px;
    border: 1px solid #e2e8f0;
}

.last-run h4 {
    color: #1e293b;
    margin-bottom: 0.5rem;
}

.last-run p {
    margin: 0.25rem 0;
    color: #64748b;
}

/* Toast Messages */
.toast-container {
    position: fixed;
    top: 1rem;
    right: 1rem;
    z-index: 1100;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.toast {
    background: white;
    border: 1px solid #e2e8f0;
    border-radius: 6px;
    padding: 1rem;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.1);
    display: flex;
    align-items: center;
    justify-content: space-between;
    min-width: 300px;
    max-width: 500px;
}

.toast-success {
    border-left: 4px solid #10b981;
    background: #f0fdf4;
}

.toast-error {
    border-left: 4px solid #ef4444;
    background: #fef2f2;
}

.toast-info {
    border-left: 4px solid #3b82f6;
    background: #f0f9ff;
}

.toast-close {
    background: none;
    border: none;
    font-size: 1.25rem;
    color: #64748b;
    cursor: pointer;
    margin-left: 1rem;
}

.toast-enter {
    animation: slideInRight 0.3s ease-out;
}

.toast-leave {
    animation: slideOutRight 0.3s ease-out;
}

@keyframes slideInRight {
    from {
        transform: translateX(100%);
        opacity: 0;
    }

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

@keyframes slideOutRight {
    from {
        transform: translateX(0);
        opacity: 1;
    }

    to {
        transform: translateX(100%);
        opacity: 0;
    }
}

/* Responsive Design */
@media (max-width: 768px) {
    .app-header {
        padding: 1rem;
        flex-direction: column;
        gap: 1rem;
    }

    .app-nav {
        padding: 0 1rem;
    }

    .dashboard,
    .feeds,
    .logs {
        padding: 1rem;
    }

    .feed-item {
        flex-direction: column;
        gap: 1rem;
    }

    .feed-actions {
        align-self: stretch;
    }

    .log-item {
        grid-template-columns: 1fr;
        gap: 0.5rem;
    }

    .log-url {
        grid-column: 1;
        margin-top: 0.5rem;
    }

    .feeds-header {
        flex-direction: column;
        gap: 1rem;
        align-items: stretch;
    }

    .logs-header {
        flex-direction: column;
        gap: 1rem;
        align-items: stretch;
    }

    /* Keep three controls on one line on mobile by narrowing widths */
    .logs-filters {
        flex-wrap: nowrap;
        gap: 0.5rem;
    }

    .logs-filters .filter-select.level-select {
        flex: 0 0 auto;
        width: 110px;
        min-width: 0;
    }

    .logs-filters .filter-select.action-select {
        flex: 0 0 auto;
        width: 130px;
        min-width: 0;
    }

    .logs-filters .btn {
        flex: 0 0 auto;
        padding: 0.4rem 0.6rem;
        font-size: 0.9rem;
    }

    .modal {
        margin: 1rem;
        overflow: visible;
        /* allow native select dropdowns to render fully */
    }

    .toast-container {
        left: 1rem;
        right: 1rem;
    }

    .toast {
        min-width: auto;
    }

    /* Mobile layout: keep status + Refresh on first row; email and button label break to two lines */
    .connection-status {
        flex-direction: row;
        align-items: flex-start;
        /* top align */
        justify-content: space-between;
        gap: 0.5rem;
        flex-wrap: wrap;
        /* allows disconnect row to go below */
    }

    .connection-status p {
        flex: 1 1 auto;
        min-width: 0;
    }

    .email-inline-mobile-block {
        display: block;
    }

    .mobile-only {
        display: inline;
    }

    .btn-refresh {
        margin-left: 0;
        /* override desktop auto */
        white-space: normal;
        line-height: 1.1;
        padding-top: 0.5rem;
        padding-bottom: 0.5rem;
        align-self: flex-start;
        /* top align button */
    }

    .btn-refresh .label-desktop {
        display: none;
    }

    .btn-refresh .label-mobile {
        display: inline-block;
    }

    .disconnect-row {
        width: 100%;
        margin-top: 0.5rem;
    }
}