/* Police Theme Variables */
:root {
    --police-blue: #51a6dd;
    --police-navy: #51a6dd;
    --police-light-blue: #51a6dd;
    --police-gold: #f59e0b;
    --text-light: #f8fafc;
    --border-color: #e2e8f0;
    --bg-light: #f1f5f9;
    --success-green: #10b981;
    --danger-red: #ef4444;
}

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

body {
    margin: 0;
    padding: 0;
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background-color: var(--bg-light);
    color: #334155;
    overflow-x: hidden;
}

/* Header Styles */
.police-header {
    background: linear-gradient(135deg, var(--police-navy) 0%, var(--police-blue) 100%);
    padding: 0.75rem 0;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
    position: sticky;
    top: 0;
    z-index: 1000;
}

/* Remove this - it's duplicated later in the file */

.police-header h1 {
    font-size: 1.75rem;
    margin: 0;
    line-height: 1.2;
}

.police-header p {
    font-size: 0.9rem;
    margin: 0;
    line-height: 1.2;
}

.police-logo {
    height: 60px;
    width: auto;
}

/* Flag Icons */
.flag-icon {
    display: inline-block;
    width: 32px;
    height: 24px;
    background-size: cover;
    background-position: center;
    border-radius: 3px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.2);
    margin-right: 0.75rem;
    vertical-align: middle;
}

/* Language Button Styling */
.language-button {
    background-color: rgba(255, 255, 255, 0.9) !important;
    border-color: rgba(255, 255, 255, 0.9) !important;
    color: var(--police-navy) !important;
    padding: 0.25rem 0.5rem;
}

.language-button:hover,
.language-button:focus,
.language-button.show {
    background-color: white !important;
    border-color: white !important;
    color: var(--police-navy) !important;
}

/* Custom flag icons using your uploaded SVG files */
.flag-us { background-image: url('assets/flag-us.svg'); }
.flag-es { background-image: url('assets/flag-es.svg'); }
.flag-de { background-image: url('assets/flag-de.svg'); }
.flag-it { background-image: url('assets/flag-it.svg'); }
.flag-fr { background-image: url('assets/flag-fr.svg'); }

/* Login Section */
.login-section {
    min-height: calc(100vh - 100px);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 2rem 0;
}

/* Password toggle button */
#togglePassword {
    border: 1px solid #ced4da;
    border-left: none;
    color: #6b7280;
    background: white;
    border-radius: 0 0.375rem 0.375rem 0;
}

#togglePassword:hover {
    color: var(--police-blue);
    background: #f8fafc;
    border-color: #ced4da;
}

#togglePassword:focus {
    box-shadow: none;
    border-color: #ced4da;
    background: white;
}

/* Ensure password input has no right border radius */
.input-group #password {
    border-radius: 0.375rem 0 0 0.375rem;
    border-right: none;
}

.input-group #password:focus {
    border-right: none;
    box-shadow: none;
}

.login-card {
    background: white;
    border-radius: 10px;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.1);
    padding: 2.5rem;
    border-top: 4px solid var(--police-blue);
}

.login-logo {
    height: 80px;
    width: auto;
}

.form-control:focus {
    border-color: var(--police-light-blue);
    box-shadow: 0 0 0 0.2rem rgba(59, 130, 246, 0.25);
}

/* Login Error Styling */
.alert-danger {
    font-size: 0.85rem;
    line-height: 1.4;
    padding: 0.7rem;
    margin-bottom: 1rem;
    border: 1px solid #f5c6cb;
    border-radius: 6px;
    background-color: #f8d7da;
    color: #721c24;
}

.alert-danger strong {
    font-size: 0.9rem;
    font-weight: 600;
    display: block;
    margin-bottom: 0.4rem;
}

.alert-danger span {
    font-size: 0.8rem;
    line-height: 1.3;
    color: #5a1a1a;
    display: block;
    margin-bottom: 0.2rem;
    padding-left: 0.25rem;
}

.btn-primary {
    background-color: var(--police-blue);
    border-color: var(--police-blue);
    padding: 0.75rem 1rem;
}

.btn-primary:hover {
    background-color: var(--police-navy);
    border-color: var(--police-navy);
}

/* Email Interface */
.email-section {
    min-height: calc(100vh - 100px);
}

.email-sidebar {
    background: white;
    border-right: 1px solid var(--border-color);
    padding: 0;
    min-height: calc(100vh - 100px);
}

.sidebar-header {
    padding: 1.5rem;
    border-bottom: 1px solid var(--border-color);
    background: var(--bg-light);
}

.email-folders li {
    border-bottom: 1px solid var(--border-color);
}

.email-folders a {
    display: block;
    padding: 0.75rem 1.5rem;
    color: #64748b;
    text-decoration: none;
    transition: all 0.2s;
    position: relative;
}

.email-folders a:hover,
.email-folders li.active a {
    background-color: var(--police-blue);
    color: white;
}

.email-folders .badge {
    float: right;
}

.user-info {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    padding: 1.5rem;
    border-top: 1px solid var(--border-color);
    background: var(--bg-light);
}

.avatar {
    width: 40px;
    height: 40px;
    background: var(--police-light-blue);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
}

/* Database Container */
.database-container {
    background: white;
    padding: 0;
    height: calc(100vh - 100px);
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.database-header {
    padding: 2rem;
    border-bottom: 1px solid var(--border-color);
    background: var(--bg-light);
    position: sticky;
    top: 0;
    z-index: 10;
}

.database-actions {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.user-info-compact {
    display: flex;
    align-items: center;
}

/* File List */
.file-list {
    background: white;
    padding: 0;
    flex: 1;
    overflow-y: auto;
}

.email-list-header {
    padding: 1.5rem;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: var(--bg-light);
    position: sticky;
    top: 0;
    z-index: 10;
}

.email-item {
    padding: 1.5rem 2rem;
    border-bottom: 1px solid var(--border-color);
    cursor: pointer;
    transition: all 0.2s;
    background: white;
}

.email-item:hover {
    background-color: #f8fafc;
    transform: translateY(-1px);
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}

.email-item.unread {
    font-weight: 600;
    background-color: #fefefe;
    border-left: 4px solid var(--police-blue);
}

.email-item {
    display: flex;
    align-items: flex-start;
    gap: 1rem;
}

.email-content-left {
    flex: 0 0 320px;
    min-width: 0;
    display: flex;
    flex-direction: column;
}

.email-content-middle {
    flex: 1;
    min-width: 0;
    padding: 0 1rem;
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100%;
}

.email-content-right {
    flex: 0 0 120px;
    text-align: right;
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 0.5rem;
}

.email-preview-middle {
    color: #6b7280;
    font-size: 0.85rem;
    line-height: 1.4;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    width: 100%;
    max-width: 300px;
    display: flex;
    align-items: center;
    min-height: 1.4em;
    font-family: inherit;
    font-weight: normal;
    letter-spacing: normal;
    word-spacing: normal;
}

.email-sender {
    font-weight: 600;
    color: var(--police-navy);
    margin-bottom: 0.25rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 100%;
}

.email-subject {
    color: #374151;
    margin-bottom: 0.25rem;
    font-size: 0.95rem;
    margin-top: 0.25rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 100%;
}

.email-datetime {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    text-align: right;
}

.email-time {
    font-size: 0.75rem;
    color: #9ca3af;
    margin-top: 0.1rem;
}

.email-preview {
    color: #6b7280;
    font-size: 0.85rem;
    line-height: 1.4;
    margin-top: 0.25rem;
    margin-bottom: 0.5rem;
    overflow: hidden;
    text-overflow: ellipsis;
    display: -webkit-box;
    -webkit-line-clamp: 1;
    -webkit-box-orient: vertical;
}

@media (max-width: 768px) {
    .email-preview {
        display: none;
    }
    
    .email-content-middle {
        display: none;
    }
    
    .email-item {
        justify-content: space-between;
        gap: 0.75rem;
        padding: 1rem 1.5rem;
    }
    
    .email-content-left {
        flex: 1;
        min-width: 0; /* Allows flex item to shrink below content size */
        max-width: calc(100vw - 140px); /* Reserve space for right content */
    }
    
    .email-content-left .d-flex {
        gap: 0.5rem;
    }
    
    .email-content-left .file-info {
        min-width: 0; /* Allows text to be truncated */
    }
    
    .email-sender {
        max-width: 100%;
        font-size: 0.9rem;
    }
    
    .email-subject {
        max-width: 100%;
        font-size: 0.85rem;
    }
    
    .email-content-right {
        flex: 0 0 auto;
        flex-direction: column;
        align-items: flex-end;
        gap: 0.5rem;
        min-width: 120px;
        max-width: 120px;
    }
    
    .email-datetime {
        align-items: flex-end;
        text-align: right;
    }
    
    .file-category {
        font-size: 0.75rem;
        max-width: 120px;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }
}

.email-date {
    font-size: 0.8rem;
    color: #9ca3af;
    float: right;
}

.attachment-icon {
    color: #6b7280;
    margin-left: 0.5rem;
}

/* Email Single View (Both Desktop and Mobile) */
.email-single-view {
    display: none;
    background: white;
    min-height: calc(100vh - 100px);
}

.email-back-header {
    background: var(--bg-light);
    padding: 0.5rem 1.5rem;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    gap: 0.75rem;
    position: sticky;
    top: 0;
    z-index: 100;
    min-height: 50px;
}

.back-button {
    background: none;
    border: none;
    color: var(--police-blue);
    font-size: 1.2rem;
    cursor: pointer;
    padding: 0.75rem;
    border-radius: 5px;
    transition: background-color 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
    min-width: 48px;
    height: 48px;
}

.back-button:hover {
    background-color: #e5e7eb;
}

.email-count-mobile {
    font-size: 1rem;
    color: #6b7280;
    font-weight: 500;
}

.email-viewer {
    height: 100%;
    overflow-y: auto;
}

.email-header {
    padding: 2rem;
    border-bottom: 1px solid var(--border-color);
    background: var(--bg-light);
}

.email-subject-line {
    font-size: 1.5rem;
    font-weight: 600;
    color: var(--police-navy);
    margin-bottom: 1rem;
}

.email-meta {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 1rem;
    font-size: 0.9rem;
    color: #6b7280;
    flex-wrap: wrap;
}

.email-meta-left {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    flex: 1;
}

.email-meta-right {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    text-align: right;
}

.email-body {
    padding: 2rem;
    line-height: 1.6;
    font-size: 1rem;
}

.email-body pre {
    background: #f8fafc;
    padding: 1rem;
    border-radius: 5px;
    border-left: 4px solid var(--police-blue);
    white-space: pre-wrap;
    font-family: 'Courier New', monospace;
}

.email-signature {
    margin-top: 2rem;
    padding-top: 1rem;
    color: #6b7280;
}

.attachment-section {
    padding: 1rem 2rem;
    background: #f8fafc;
    border-top: 1px solid var(--border-color);
}

.attachment {
    display: inline-flex;
    align-items: center;
    background: white;
    border: 1px solid var(--border-color);
    border-radius: 5px;
    padding: 0.5rem 1rem;
    margin-right: 1rem;
    margin-bottom: 0.5rem;
    text-decoration: none;
    color: var(--police-navy);
    transition: all 0.2s;
}

.attachment:hover {
    background: var(--bg-light);
    color: var(--police-blue);
    text-decoration: none;
}

.attachment-item {
    margin-bottom: 1rem;
}

.attachment-header {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
}

.attachment-preview {
    margin-top: 0.5rem;
    text-align: center;
}

.attachment-preview img {
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}

.attachment i {
    margin-right: 0.5rem;
    color: var(--police-gold);
}

/* Email Threading Styles */
.quoted-header {
    margin: 1rem 0 0.5rem 0;
    padding: 0.5rem;
    font-size: 0.9rem;
    color: #6b7280;
    background: #f8fafc;
    border-radius: 4px;
}

/* Header Layout */
.header-content {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.header-left {
    display: flex;
    align-items: center;
    flex: 1;
}

.header-right {
    flex: none;
}

.header-text {
    margin-left: 0.75rem;
}

/* Mobile Responsiveness */
@media (max-width: 768px) {
    .police-header {
        padding: 0.75rem 0;
    }
    
    .police-header .container-fluid {
        padding: 0 1rem;
    }
    
    .header-content {
        display: flex;
        align-items: center;
        justify-content: space-between;
    }
    
    .header-left {
        display: flex;
        align-items: center;
        flex: 1;
        min-width: 0;
    }
    
    .police-logo {
        height: 44px;
        margin-right: 0.75rem;
        flex-shrink: 0;
    }
    
    .header-text {
        margin-left: 0;
        min-width: 0;
        flex: 1;
    }
    
    .police-header h1 {
        font-size: 1.1rem;
        margin: 0;
        line-height: 1.2;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }
    
    .police-header p {
        font-size: 0.85rem;
        margin: 0;
        line-height: 1.1;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }
    
    .header-right {
        flex-shrink: 0;
        margin-left: 0.75rem;
    }
    
    .language-button {
        padding: 0.3rem !important;
        min-width: 40px;
        height: 36px;
        display: flex;
        align-items: center;
        justify-content: center;
    }
    
    .flag-icon {
        width: 28px;
        height: 21px;
    }
    
    .email-sidebar,
    .email-content {
        min-height: auto;
        max-height: none;
    }
    
    .email-section {
        min-height: calc(100dvh - 80px); /* Use dynamic viewport height for mobile */
        height: calc(100dvh - 80px);
        overflow: hidden;
    }
    
    .email-section .row {
        flex-direction: column;
        min-height: auto;
        height: 100%;
        flex: 1;
        display: flex;
    }
    
    .inbox-container {
        height: calc(100dvh - 80px); /* Full viewport minus header */
        min-height: calc(100dvh - 80px);
        overflow: hidden;
        display: flex;
        flex-direction: column;
    }
    
    .email-sidebar {
        order: 3;
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        z-index: 1000;
        min-height: auto;
        max-height: 200px;
        overflow-y: auto;
        background: white;
        border-top: 1px solid var(--border-color);
        box-shadow: 0 -2px 10px rgba(0,0,0,0.1);
    }
    
    .email-list {
        order: 1;
        flex: 1;
        overflow-y: scroll;
        max-height: none;
        min-height: 0; /* Allow flexbox to shrink */
        -webkit-overflow-scrolling: touch; /* Smooth scrolling on iOS */
        box-sizing: border-box;
    }
    
    /* Mobile adjustments for new design */
    .inbox-header {
        padding: 1rem;
        background: var(--bg-light);
        border-bottom: 1px solid var(--border-color);
        flex-shrink: 0; /* Don't let header shrink */
    }
    
    .inbox-actions {
        flex-direction: column;
        align-items: flex-end;
        gap: 0.5rem;
    }
    
    .user-info-compact {
        font-size: 0.9rem;
    }
    
    .email-item {
        padding: 1rem 1.5rem;
    }
    
    .email-back-header {
        padding: 0.5rem 1rem;
        min-height: 45px;
    }
    
    .user-info {
        position: static;
        padding: 1rem;
    }
    
    .login-card {
        margin: 1rem;
        padding: 2rem;
    }
    
    .login-section {
        min-height: calc(100vh - 120px);
        display: flex;
        align-items: center;
        justify-content: center;
        padding: 2rem 0;
    }
}

@media (max-width: 576px) {
    .police-header {
        padding: 0.6rem 0;
    }
    
    .police-header .container-fluid {
        padding: 0 0.75rem;
    }
    
    .police-logo {
        height: 40px;
        margin-right: 0.6rem;
    }
    
    .police-header h1 {
        font-size: 1rem;
    }
    
    .police-header p {
        font-size: 0.8rem;
    }
    
    .language-button {
        padding: 0.2rem !important;
        min-width: 36px;
        height: 32px;
        display: flex;
        align-items: center;
        justify-content: center;
    }
    
    .flag-icon {
        width: 26px;
        height: 19px;
    }
    
    .login-logo {
        height: 80px;
    }
    
    .attachment-section {
        padding: 0.75rem;
    }
    
    .attachment {
        padding: 0.5rem;
        font-size: 0.8rem;
    }
    
    .attachment i {
        font-size: 0.9rem;
        margin-right: 0.4rem;
    }
    
    .email-header {
        padding: 1rem;
    }
    
    .email-body {
        padding: 1rem;
    }
    
    .email-subject-line {
        font-size: 1.25rem;
    }
    
    .attachment-section {
        padding: 1rem;
        background: #f8fafc;
        border-top: 1px solid var(--border-color);
        margin-top: 1rem;
    }
    
    .attachment {
        display: flex;
        width: 100%;
        margin: 0 0 0.75rem 0;
        padding: 0.75rem;
        font-size: 0.85rem;
        border-radius: 8px;
        box-sizing: border-box;
        background: white;
        border: 1px solid var(--border-color);
        justify-content: flex-start;
        align-items: center;
        min-width: 0;
        flex-wrap: nowrap;
        overflow: hidden;
    }
    
    .attachment i {
        font-size: 1rem;
        margin-right: 0.5rem;
        flex-shrink: 0;
    }
    
    .attachment span {
        flex: 1;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
        min-width: 0;
    }
}

/* Custom Scrollbars */
.email-list::-webkit-scrollbar,
.email-content::-webkit-scrollbar {
    width: 6px;
}

.email-list::-webkit-scrollbar-track,
.email-content::-webkit-scrollbar-track {
    background: #f1f1f1;
}

.email-list::-webkit-scrollbar-thumb,
.email-content::-webkit-scrollbar-thumb {
    background: #c1c1c1;
    border-radius: 3px;
}

.email-list::-webkit-scrollbar-thumb:hover,
.email-content::-webkit-scrollbar-thumb:hover {
    background: #a1a1a1;
}

/* Show thin scrollbar on mobile */
@media (max-width: 768px) {
    .email-list::-webkit-scrollbar {
        width: 4px;
        display: block;
    }
    
    .email-list::-webkit-scrollbar-track {
        background: transparent;
    }
    
    .email-list::-webkit-scrollbar-thumb {
        background: rgba(0,0,0,0.3);
        border-radius: 2px;
    }
    
    .email-list {
        scrollbar-width: thin; /* Firefox */
    }
}

/* Loading States */
.loading {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 200px;
    color: #9ca3af;
}

.loading i {
    animation: spin 1s linear infinite;
}

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