/* Global Styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    line-height: 1.6;
    color: #333;
    background-color: #f5f5f5;
    overflow-x: hidden;
    max-width: 100vw;
}

/* Navigation */
.navbar {
    background: linear-gradient(135deg, #2c3e50 0%, #34495e 100%);
    color: white;
    padding: 0;
    box-shadow: 0 2px 8px rgba(0,0,0,0.15);
    position: sticky;
    top: 0;
    z-index: 100;
}

.nav-container {
    max-width: 1400px;
    margin: 0 auto;
    padding: 0 2rem;
    display: flex;
    justify-content: space-between;
    align-items: stretch;
    min-height: 64px;
}

.nav-logo {
    font-size: 1.5rem;
    font-weight: 700;
    letter-spacing: -0.5px;
    display: flex;
    align-items: center;
    padding: 0 1rem;
}

.nav-menu {
    display: flex;
    list-style: none;
    gap: 0;
    margin: 0;
    padding: 0;
}

.nav-menu li {
    display: flex;
    align-items: stretch;
}

.nav-link {
    color: rgba(255, 255, 255, 0.9);
    text-decoration: none;
    padding: 0 1.5rem;
    display: flex;
    align-items: center;
    font-weight: 500;
    font-size: 0.95rem;
    transition: all 0.2s ease;
    border-bottom: 3px solid transparent;
    position: relative;
}

.nav-link:hover {
    background-color: rgba(52, 152, 219, 0.15);
    border-bottom-color: #3498db;
    color: white;
}

.nav-link:active {
    background-color: rgba(52, 152, 219, 0.25);
}

.nav-right {
    margin-left: auto;
    display: flex;
    align-items: stretch;
}

.nav-right .nav-menu {
    border-left: 1px solid rgba(255, 255, 255, 0.1);
}

/* Hamburger Menu */
.nav-hamburger {
    display: none;
    flex-direction: column;
    gap: 4px;
    background: none;
    border: none;
    cursor: pointer;
    padding: 0.5rem;
    z-index: 101;
}

.nav-hamburger span {
    display: block;
    width: 25px;
    height: 3px;
    background-color: white;
    transition: all 0.3s ease;
    border-radius: 2px;
}

.nav-hamburger.active span:nth-child(1) {
    transform: rotate(45deg) translate(6px, 6px);
}

.nav-hamburger.active span:nth-child(2) {
    opacity: 0;
}

.nav-hamburger.active span:nth-child(3) {
    transform: rotate(-45deg) translate(6px, -6px);
}

.nav-menu-wrapper {
    display: flex;
    align-items: stretch;
    flex: 1;
}

/* Flash Messages */
.flash-messages {
    max-width: 1200px;
    margin: 1rem auto;
    padding: 0 2rem;
}

.flash-message {
    padding: 1rem 1.5rem;
    margin-bottom: 1rem;
    border-radius: 4px;
    font-weight: 500;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
    animation: slideDown 0.3s ease-out;
}

@keyframes slideDown {
    from {
        opacity: 0;
        transform: translateY(-10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.flash-success {
    background-color: #d4edda;
    border-left: 4px solid #28a745;
    color: #155724;
}

.flash-error {
    background-color: #f8d7da;
    border-left: 4px solid #dc3545;
    color: #721c24;
}

.flash-info {
    background-color: #d1ecf1;
    border-left: 4px solid #17a2b8;
    color: #0c5460;
}

.flash-warning {
    background-color: #fff3cd;
    border-left: 4px solid #ffc107;
    color: #856404;
}

/* Container */
.container {
    max-width: 1200px;
    margin: 2rem auto;
    padding: 0 2rem;
}

/* Cards */
.card {
    background: white;
    border-radius: 8px;
    padding: 2rem;
    margin-bottom: 2rem;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.card h2 {
    margin-bottom: 1rem;
    color: #2c3e50;
}

/* Dashboard */
.dashboard h1 {
    margin-bottom: 2rem;
}

.dashboard-grid {
    display: grid;
    gap: 2rem;
}

.agent-flow {
    display: flex;
    align-items: center;
    gap: 1rem;
    overflow-x: auto;
    padding: 1rem 0;
    -webkit-overflow-scrolling: touch;
}

.agent-box {
    background: #ecf0f1;
    padding: 1rem;
    border-radius: 8px;
    min-width: 150px;
    text-align: center;
}

.agent-box h3 {
    font-size: 1rem;
    margin-bottom: 0.5rem;
    color: #2c3e50;
}

.agent-box p {
    font-size: 0.85rem;
    color: #7f8c8d;
}

.arrow {
    font-size: 2rem;
    color: #3498db;
}

/* Buttons */
.button-group {
    display: flex;
    gap: 1rem;
    flex-wrap: wrap;
}

.btn {
    padding: 0.75rem 1.5rem;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 1rem;
    transition: all 0.3s;
}

.btn-primary {
    background-color: #3498db;
    color: white;
}

.btn-primary:hover {
    background-color: #2980b9;
}

.btn-secondary {
    background-color: #95a5a6;
    color: white;
}

.btn-secondary:hover {
    background-color: #7f8c8d;
}

.btn-success {
    background-color: #2ecc71;
    color: white;
}

.btn-success:hover {
    background-color: #27ae60;
}

.btn-danger {
    background-color: #e74c3c;
    color: white;
}

.btn-danger:hover {
    background-color: #c0392b;
}

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

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

.form-group label {
    display: block;
    margin-bottom: 0.5rem;
    font-weight: 600;
}

.form-group input[type="text"],
.form-group input[type="url"],
.form-group input[type="file"],
.form-group select {
    width: 100%;
    padding: 0.75rem;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 1rem;
}

.help-text {
    font-size: 0.875rem;
    color: #7f8c8d;
    margin-top: 0.5rem;
}

/* Sliders */
.slider-container {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.slider-container input[type="range"] {
    flex: 1;
}

.slider-container span {
    font-weight: bold;
    min-width: 50px;
}

/* Document List */
.document-list {
    list-style: none;
}

.document-list li {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem;
    border-bottom: 1px solid #ecf0f1;
}

.document-list li:last-child {
    border-bottom: none;
}

.doc-name {
    font-weight: 600;
}

.doc-date {
    color: #7f8c8d;
    font-size: 0.875rem;
}

/* Jobs Page */
.jobs-page {
    max-width: 1200px;
    margin: 2rem auto;
    padding: 0 2rem;
}

/* Jobs Grid */
.jobs-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 1.5rem;
    max-width: 100%;
}

.job-card {
    background: white;
    border-radius: 8px;
    padding: 1.5rem;
    cursor: pointer;
    transition: all 0.3s;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
    position: relative;
    overflow: hidden;
    word-wrap: break-word;
    overflow-wrap: break-word;
    max-width: 100%;
}

.job-card:hover {
    transform: translateY(-4px);
    box-shadow: 0 4px 8px rgba(0,0,0,0.15);
}

.job-card h3 {
    margin-bottom: 0.5rem;
    color: #2c3e50;
    word-wrap: break-word;
    overflow-wrap: break-word;
}

.job-card .company {
    color: #7f8c8d;
    font-size: 0.9rem;
    margin-bottom: 1rem;
    word-wrap: break-word;
    overflow-wrap: break-word;
}

.job-card .source {
    font-size: 0.85rem;
    color: #95a5a6;
    word-wrap: break-word;
    overflow-wrap: break-word;
}

.score {
    display: inline-block;
    padding: 0.5rem 1rem;
    border-radius: 4px;
    font-weight: bold;
    margin: 0.5rem 0;
}

.score-high {
    background-color: #2ecc71;
    color: white;
}

.score-medium {
    background-color: #f39c12;
    color: white;
}

.score-low {
    background-color: #e74c3c;
    color: white;
}

.status-badge {
    position: absolute;
    top: 1rem;
    right: 1rem;
    padding: 0.25rem 0.75rem;
    border-radius: 12px;
    font-size: 0.75rem;
    font-weight: bold;
    text-transform: uppercase;
}

.status-pending {
    background-color: #f39c12;
    color: white;
}

.status-approved {
    background-color: #2ecc71;
    color: white;
}

.status-rejected {
    background-color: #e74c3c;
    color: white;
}

.status-applied {
    background-color: #3498db;
    color: white;
}

/* Modal */
.modal {
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0,0,0,0.5);
    overflow: auto;
}

.modal-content {
    background-color: white;
    margin: 5% auto;
    padding: 2rem;
    border-radius: 8px;
    width: 90%;
    max-width: 800px;
    max-height: 80vh;
    overflow-y: auto;
    overflow-x: hidden;
    word-wrap: break-word;
}

.close {
    color: #aaa;
    float: right;
    font-size: 28px;
    font-weight: bold;
    cursor: pointer;
}

.close:hover {
    color: #000;
}

.document-preview {
    background: #f8f9fa;
    padding: 1.5rem;
    border-radius: 4px;
    white-space: pre-wrap;
    margin: 1rem 0;
    max-height: 400px;
    overflow-y: auto;
}

.research-notes {
    background: #ecf0f1;
    padding: 1rem;
    border-radius: 4px;
    white-space: pre-wrap;
}

.job-actions {
    display: flex;
    gap: 1rem;
    margin-top: 2rem;
}

/* Sites List */
.sites-list {
    list-style: none;
}

.site-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1.5rem;
    border: 1px solid #ecf0f1;
    border-radius: 8px;
    margin-bottom: 1rem;
}

.site-item.inactive {
    opacity: 0.6;
}

.site-info h3 {
    margin-bottom: 0.5rem;
}

.site-url {
    color: #3498db;
    font-size: 0.9rem;
    word-break: break-all;
}

.site-meta {
    font-size: 0.85rem;
    color: #7f8c8d;
    margin-top: 0.5rem;
}

.site-type {
    background: #ecf0f1;
    padding: 0.25rem 0.5rem;
    border-radius: 4px;
    margin-right: 1rem;
}

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

/* Logs */
.logs-container {
    max-height: calc(100vh - 280px);
    overflow-y: auto;
    overflow-x: hidden;
}

.log-entry {
    background: white;
    border-left: 4px solid #95a5a6;
    padding: 1rem;
    margin-bottom: 1rem;
    border-radius: 4px;
}

.log-entry.success {
    border-left-color: #2ecc71;
}

.log-entry.failure {
    border-left-color: #e74c3c;
}

.log-entry.pending {
    border-left-color: #f39c12;
}

.log-header {
    display: flex;
    gap: 1rem;
    align-items: center;
    margin-bottom: 0.5rem;
}

.log-agent {
    background: #3498db;
    color: white;
    padding: 0.25rem 0.75rem;
    border-radius: 4px;
    font-weight: bold;
    text-transform: uppercase;
    font-size: 0.75rem;
}

.log-action {
    font-weight: 600;
}

.log-status {
    padding: 0.25rem 0.75rem;
    border-radius: 4px;
    font-size: 0.75rem;
    font-weight: bold;
}

.log-time {
    margin-left: auto;
    color: #7f8c8d;
    font-size: 0.85rem;
}

.log-details {
    color: #555;
    font-size: 0.9rem;
    margin-top: 0.5rem;
}

.log-job {
    color: #7f8c8d;
    font-size: 0.85rem;
    margin-top: 0.5rem;
}

/* Filters */
.filters {
    background: white;
    padding: 1rem;
    border-radius: 8px;
    margin-bottom: 2rem;
    display: flex;
    gap: 2rem;
    flex-wrap: wrap;
}

.filters label {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    cursor: pointer;
}

/* New Unified Filter Styles */
.filters-container {
    background: white;
    padding: 1.5rem;
    border-radius: 8px;
    margin-bottom: 2rem;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.filters-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1.5rem;
    align-items: end;
}

.filter-group {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.filter-group label {
    font-weight: 600;
    font-size: 0.9rem;
    color: #2c3e50;
}

.filter-group select {
    width: 100%;
    padding: 0.625rem;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 0.95rem;
    background-color: white;
    cursor: pointer;
    transition: border-color 0.2s;
}

.filter-group select:hover {
    border-color: #3498db;
}

.filter-group select:focus {
    outline: none;
    border-color: #3498db;
    box-shadow: 0 0 0 2px rgba(52, 152, 219, 0.1);
}

.job-date {
    font-size: 0.85rem;
    color: #7f8c8d;
    margin-top: 0.25rem;
    margin-bottom: 0.5rem;
}

/* Utility Classes */
.no-items {
    color: #7f8c8d;
    font-style: italic;
    padding: 2rem;
    text-align: center;
}

.error {
    color: #e74c3c;
    padding: 1rem;
}

.rules-list {
    list-style: none;
    padding-left: 0;
}

.rules-list li {
    padding: 0.75rem 0;
    border-bottom: 1px solid #ecf0f1;
}

.rules-list li:last-child {
    border-bottom: none;
}

/* Responsive */
@media (max-width: 768px) {
    /* Prevent horizontal scrolling */
    body {
        overflow-x: hidden;
        max-width: 100vw;
    }

    .container,
    .jobs-page,
    .dashboard,
    .admin-page {
        max-width: 100vw;
        overflow-x: hidden;
    }

    /* Navigation */
    .nav-container {
        padding: 0 1rem;
        flex-wrap: nowrap;
        min-height: 56px;
    }

    .nav-logo {
        font-size: 1.2rem;
        padding: 0.75rem 0;
        flex: 1;
    }

    .nav-hamburger {
        display: flex;
    }

    .nav-menu-wrapper {
        position: fixed;
        top: 56px;
        left: 0;
        right: 0;
        background: linear-gradient(135deg, #2c3e50 0%, #34495e 100%);
        flex-direction: column;
        max-height: 0;
        overflow: hidden;
        transition: max-height 0.3s ease;
        box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
        z-index: 99;
    }

    .nav-menu-wrapper.active {
        max-height: 500px;
    }

    .nav-menu {
        flex-direction: column;
        width: 100%;
    }

    .nav-menu li {
        width: 100%;
    }

    .nav-link {
        padding: 0.875rem 1.5rem;
        border-bottom: none;
        border-left: 3px solid transparent;
        width: 100%;
    }

    .nav-link:hover {
        border-bottom: none;
        border-left-color: #3498db;
    }

    .nav-right {
        margin-left: 0;
        width: 100%;
    }

    .nav-right .nav-menu {
        border-left: none;
        border-top: 1px solid rgba(255, 255, 255, 0.1);
    }

    /* Container and spacing */
    .container {
        padding: 0 1rem;
        margin: 1rem auto;
    }

    .flash-messages {
        padding: 0 1rem;
        margin: 0.5rem auto;
    }

    .flash-message {
        padding: 0.75rem 1rem;
        font-size: 0.9rem;
    }

    /* Cards */
    .card {
        padding: 1.25rem;
        margin-bottom: 1rem;
        border-radius: 6px;
    }

    .card h2 {
        font-size: 1.25rem;
        margin-bottom: 0.75rem;
    }

    /* Typography */
    h1 {
        font-size: 1.75rem;
    }

    h3 {
        font-size: 1.1rem;
    }

    /* Buttons */
    .btn {
        padding: 0.625rem 1.25rem;
        font-size: 0.9rem;
    }

    .btn-sm {
        padding: 0.375rem 0.625rem;
        font-size: 0.813rem;
    }

    .button-group {
        gap: 0.5rem;
    }

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

    .form-group label {
        font-size: 0.9rem;
    }

    .form-group input[type="text"],
    .form-group input[type="url"],
    .form-group input[type="email"],
    .form-group input[type="password"],
    .form-group input[type="file"],
    .form-group select,
    .form-group textarea {
        font-size: 16px; /* Prevents zoom on iOS */
    }

    .form-row {
        flex-direction: column;
        gap: 0;
    }

    .form-row .form-group {
        width: 100%;
    }

    /* Tables - make scrollable */
    .whitelist-table-container,
    .users-table-container {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        margin: 1rem -1.25rem 0 -1.25rem;
        padding: 0 1.25rem;
    }

    .whitelist-table,
    .users-table {
        font-size: 0.75rem;
        min-width: 650px;
    }

    .whitelist-table th,
    .users-table th,
    .whitelist-table td,
    .users-table td {
        padding: 0.5rem 0.375rem;
        white-space: nowrap;
    }

    .whitelist-table .btn-small,
    .users-table .btn-small {
        padding: 0.25rem 0.5rem;
        font-size: 0.7rem;
    }

    /* Jobs Page */
    .jobs-page .info-box {
        padding: 0.75rem !important;
        margin-bottom: 1rem !important;
        max-width: 100%;
        overflow-x: hidden;
    }

    .jobs-page .info-box p {
        word-wrap: break-word;
        overflow-wrap: break-word;
    }

    .filters {
        padding: 0.75rem !important;
        flex-direction: column !important;
        align-items: flex-start !important;
        gap: 1rem !important;
        max-width: 100%;
    }

    .filters > div {
        width: 100%;
    }

    .filters select,
    .filters input {
        max-width: 100%;
    }

    /* New filters container mobile styles */
    .filters-container {
        padding: 1rem;
        margin-bottom: 1rem;
    }

    .filters-row {
        grid-template-columns: 1fr;
        gap: 1rem;
    }

    .filter-group label {
        font-size: 0.875rem;
    }

    .filter-group select {
        font-size: 16px; /* Prevents zoom on iOS */
        padding: 0.75rem;
    }

    .job-date {
        font-size: 0.8rem;
    }

    /* Jobs Grid */
    .jobs-grid {
        grid-template-columns: 1fr;
        gap: 1rem;
        max-width: 100%;
    }

    .job-card {
        padding: 1rem;
        max-width: 100%;
        overflow: hidden;
        word-wrap: break-word;
        overflow-wrap: break-word;
    }

    .job-card h3 {
        font-size: 1.1rem;
        margin-bottom: 0.375rem;
        word-wrap: break-word;
        overflow-wrap: break-word;
    }

    .job-card .company {
        font-size: 0.85rem;
        word-wrap: break-word;
        overflow-wrap: break-word;
    }

    .job-card .source {
        font-size: 0.813rem;
        word-wrap: break-word;
        overflow-wrap: break-word;
    }

    .job-actions {
        flex-direction: column;
        gap: 0.5rem;
    }

    .job-actions .btn {
        width: 100%;
    }

    /* Site Management */
    .site-item {
        flex-direction: column;
        align-items: flex-start;
        gap: 1rem;
        padding: 1rem;
    }

    .site-actions {
        width: 100%;
        flex-direction: column;
    }

    .site-actions .btn {
        width: 100%;
    }

    /* Document List */
    .document-list li {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.5rem;
        padding: 0.75rem;
    }

    /* Logs */
    .logs-container {
        max-height: calc(100vh - 260px);
    }

    .log-entry {
        padding: 0.75rem;
        font-size: 0.9rem;
    }

    .log-header {
        flex-wrap: wrap;
        gap: 0.5rem;
    }

    .log-agent {
        font-size: 0.7rem;
    }

    .log-time {
        width: 100%;
        margin-left: 0;
        margin-top: 0.25rem;
    }

    /* Dashboard */
    .agent-flow {
        flex-direction: column;
        align-items: stretch;
        overflow-x: visible;
        overflow-y: visible;
    }

    .agent-box {
        min-width: auto;
        width: 100%;
    }

    .arrow {
        transform: rotate(90deg);
        font-size: 1.5rem;
    }

    /* Modals - center in viewport on mobile */
    .modal {
        position: fixed;
        padding: 10px;
        overflow: hidden;
    }

    /* When modal is visible, use flex centering */
    .modal:not([style*="display: none"]) {
        display: flex;
        align-items: center;
        justify-content: center;
    }

    .modal-content {
        width: 95%;
        max-width: 95vw;
        margin: 0;
        padding: 0;
        max-height: 90vh;
        overflow-y: auto;
        position: relative;
    }

    .modal-header {
        padding: 1rem;
        position: sticky;
        top: 0;
        background: white;
        z-index: 10;
        border-radius: 8px 8px 0 0;
    }

    .modal-header h2 {
        font-size: 1.25rem;
    }

    .modal-body {
        padding: 1rem;
        max-width: 100%;
        overflow-x: hidden;
        word-wrap: break-word;
        overflow-wrap: break-word;
    }

    .modal-body h3,
    .modal-body p,
    .modal-body a {
        word-wrap: break-word;
        overflow-wrap: break-word;
        max-width: 100%;
    }

    .modal-footer {
        padding: 0.75rem 1rem;
        flex-wrap: wrap;
        position: sticky;
        bottom: 0;
        background: white;
        border-top: 1px solid #dee2e6;
        border-radius: 0 0 8px 8px;
    }

    .modal-footer .btn {
        flex: 1;
        min-width: 120px;
    }

    .profile-info .info-row {
        padding: 0.625rem 0;
        font-size: 0.9rem;
    }

    .profile-info .info-label {
        min-width: 100px;
        font-size: 0.875rem;
    }

    /* Document Preview */
    .document-preview {
        padding: 1rem;
        font-size: 0.85rem;
        max-height: 300px;
    }

    /* Admin page specific */
    .whitelist-form {
        padding: 1rem;
    }

    /* Status badges */
    .status-badge {
        font-size: 0.75rem;
        padding: 0.2rem 0.5rem;
    }

    /* Sliders */
    .slider-container {
        flex-direction: column;
        align-items: stretch;
        gap: 0.5rem;
    }

    .slider-container span {
        text-align: center;
    }
}
