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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: #f0f2f5;
    min-height: 100vh;
    display: flex;
    justify-content: center;
    padding: 20px;
}

.container {
    background: white;
    border-radius: 20px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.08);
    padding: 40px;
    max-width: 800px;
    width: 100%;
    text-align: center;
    display: flex;
    flex-direction: column;
}

/* --- Login Section --- */
#loginSection .logo {
    width: 80px;
    height: 80px;
    margin: 0 auto 20px;
    background: linear-gradient(135deg, #ff4500, #ff6b35);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-size: 32px;
    font-weight: bold;
    box-shadow: 0 10px 20px rgba(255, 69, 0, 0.3);
}

#loginSection h1 {
    color: #333;
    margin-bottom: 10px;
    font-size: 28px;
    font-weight: 600;
}

#loginSection .subtitle {
    color: #666;
    margin-bottom: 30px;
}

.login-btn {
    background: linear-gradient(135deg, #ff4500 0%, #ff6b35 100%);
    color: white;
    border: none;
    padding: 16px 32px;
    border-radius: 50px;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    text-decoration: none;
    display: inline-block;
    box-shadow: 0 8px 16px rgba(255, 69, 0, 0.3);
}

.login-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 12px 24px rgba(255, 69, 0, 0.4);
}


/* --- Status & Loading --- */
.status {
    margin-top: 20px;
    padding: 15px;
    border-radius: 10px;
    font-size: 14px;
    display: none;
}
.status.success { background: #d4edda; color: #155724; }
.status.error { background: #f8d7da; color: #721c24; }
.status.loading { background: #d1ecf1; color: #0c5460; }

.loading-spinner {
    display: inline-block;
    width: 1em;
    height: 1em;
    border: 3px solid #f3f3f3;
    border-top-color: #ff4500;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    vertical-align: middle;
    margin-right: 8px;
}

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

/* --- Unauthorized Message --- */
.unauthorized-container {
    margin-top: 20px;
    padding: 20px;
    background-color: #fffbe6; /* Light yellow */
    border: 1px solid #ffe58f; /* Yellow border */
    border-radius: 8px;
    color: #8a6d3b; /* Dark yellow text */
    text-align: center;
    line-height: 1.6;
}

.unauthorized-container a {
    color: #ff4500;
    font-weight: bold;
    text-decoration: none;
}

.unauthorized-container a:hover {
    text-decoration: underline;
}

/* --- Logged In View --- */
#loggedInView {
    display: none;
    flex-grow: 1;
    flex-direction: column;
}

.user-info {
    padding: 20px;
    background: #f8f9fa;
    border-radius: 15px;
    text-align: left;
    margin-bottom: 30px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-shrink: 0;
}

.user-details {
    display: flex;
    align-items: center;
    gap: 15px;
}

.user-avatar {
    width: 50px;
    height: 50px;
    background: linear-gradient(135deg, #ff4500, #ff6b35);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-size: 24px;
    font-weight: bold;
    flex-shrink: 0;
}

.user-data p { margin: 0; color: #666; }
.user-data strong { color: #333; }

.logout-btn {
    background: #6c757d;
    color: white;
    border: none;
    padding: 10px 20px;
    border-radius: 25px;
    font-size: 14px;
    cursor: pointer;
    transition: background 0.3s ease;
}
.logout-btn:hover { background: #5a6268; }


/* --- Search Section --- */
.search-container {
    margin-bottom: 30px;
    text-align: left;
}

.search-container h2 {
    margin-bottom: 15px;
    color: #333;
}

#searchForm {
    display: flex;
    flex-direction: column;
    gap: 15px;
}

.main-search {
    display: flex;
    gap: 10px;
}

.search-input {
    flex-grow: 1;
    padding: 12px 15px;
    border: 1px solid #ddd;
    border-radius: 8px;
    font-size: 16px;
    transition: border-color 0.3s, box-shadow 0.3s;
}

.search-input:focus {
    outline: none;
    border-color: #ff4500;
    box-shadow: 0 0 0 3px rgba(255, 69, 0, 0.1);
}

.search-btn {
    background: #ff4500;
    color: white;
    border: none;
    padding: 12px 25px;
    border-radius: 8px;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.3s;
}

.search-btn:hover {
    background: #e03e00;
}

.filter-container {
    display: flex;
    gap: 10px;
    align-items: center;
    flex-wrap: wrap;
}

.filter-input {
    padding: 8px 12px;
    border: 1px solid #ddd;
    border-radius: 6px;
    font-size: 14px;
    font-family: inherit;
    color: #333;
}

.filter-container label {
    font-size: 14px;
    color: #666;
}


/* --- Search Results --- */
.search-results-container {
    margin-top: 20px;
    text-align: left;
    overflow-y: auto;
    padding-right: 10px;
    flex-grow: 1; /* Allows this to fill available space */
    min-height: 200px; /* Ensures it has a minimum height */
}

.loading-spinner-container {
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 40px;
    color: #666;
    font-size: 16px;
}

.search-result-item {
    padding: 15px;
    border-bottom: 1px solid #eee;
}

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

.result-header {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    margin-bottom: 8px;
    flex-wrap: wrap;
    gap: 5px;
}

.result-sender {
    font-weight: bold;
    color: #333;
}

.result-timestamp {
    font-size: 0.85em;
    color: #999;
    white-space: nowrap;
}

.chat-link {
    text-decoration: none;
    margin-left: 8px;
    font-size: 1.1em;
    display: inline-block;
    transition: transform 0.2s ease;
}

.chat-link:hover {
    transform: scale(1.2);
}

.result-body {
    color: #555;
    line-height: 1.5;
    white-space: pre-wrap;
    word-break: break-word;
}

.error-message {
    color: #721c24;
    background-color: #f8d7da;
    border: 1px solid #f5c6cb;
    padding: 15px;
    border-radius: 8px;
}

/* --- App Footer --- */
.app-footer {
    margin-top: 30px;
    padding-top: 20px;
    border-top: 1px solid #eee;
    text-align: center;
    font-size: 14px;
    color: #888;
    flex-shrink: 0;
}

.app-footer a {
    color: #ff4500;
    text-decoration: none;
    font-weight: 500;
}

.app-footer a:hover {
    text-decoration: underline;
}

/* --- Pagination --- */
.pagination-controls {
    display: flex;
    justify-content: center;
    align-items: center;
    margin-top: 20px;
    gap: 10px;
    flex-shrink: 0;
}

.pagination-btn {
    background: #e4e6eb;
    color: #333;
    border: none;
    padding: 8px 16px;
    border-radius: 6px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.3s;
}

.pagination-btn:hover:not(:disabled) {
    background: #d8dbdf;
}

.pagination-btn:disabled {
    background: #f0f2f5;
    color: #bcc0c4;
    cursor: not-allowed;
}

.page-info {
    color: #666;
    font-size: 14px;
}

/* --- Responsive Design --- */
@media (max-width: 768px) {
    body {
        padding: 10px;
    }

    .container {
        padding: 20px;
        border-radius: 15px;
    }

    /* Stack user info and logout button on mobile */
    .user-info {
        flex-direction: column;
        align-items: flex-start;
        gap: 15px;
    }

    .logout-btn {
        align-self: flex-start;
    }
    
    .main-search {
        flex-direction: column;
    }
    
    .search-btn {
        width: 100%;
    }
    
    /* Make search filters stack vertically */
    .filter-container {
        flex-direction: column;
        align-items: stretch; /* Make inputs full width */
        gap: 12px;
    }

    .filter-container label {
        text-align: left; /* Align labels to the left when stacked */
    }
    
    .filter-input {
        width: 100%;
    }

    /* Adjust search results container height */
    .search-results-container {
        padding-right: 5px;
    }
}

@media (max-width: 480px) {
    body {
        padding: 0;
        min-height: -webkit-fill-available; /* iOS fix */
    }
    html {
        min-height: -webkit-fill-available; /* iOS fix */
    }

    .container {
        padding: 15px;
        border-radius: 0;
        min-height: 100vh;
        box-shadow: none;
    }

    #loginSection h1 {
        font-size: 24px;
    }

    .user-avatar {
        width: 45px;
        height: 45px;
        font-size: 20px;
    }

    .user-details {
        gap: 10px;
    }
}

