:root {
    --primary-color: #2997ff; /* More vibrant Apple Blue */
    --primary-hover: #0077ed;
    --bg-main: #f5f5f7; 
    --card-bg: rgba(255, 255, 255, 0.9);
    --card-border: rgba(0, 0, 0, 0.08);
    --text-main: #1d1d1f; 
    --text-muted: #6e6e73; /* Slightly darker for better visibility */
    --success: #28cd41;
    --warning: #ff9f0a;
    --danger: #ff3b30;
    --info: #0071e3;
    --nav-bg: rgba(255, 255, 255, 0.7);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    -webkit-font-smoothing: antialiased;
}

@keyframes meshGradient {
    0% { background-position: 0% 50%; }
    50% { background-position: 100% 50%; }
    100% { background-position: 0% 50%; }
}

body {
    background: #f5f5f7;
    color: var(--text-main);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    line-height: 1.5;
    position: relative;
    overflow-x: hidden;
}

/* Premium Animated Background */
body::before {
    content: "";
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: 
        radial-gradient(circle at 0% 0%, rgba(41, 151, 255, 0.08) 0%, transparent 50%),
        radial-gradient(circle at 100% 100%, rgba(40, 205, 65, 0.05) 0%, transparent 50%),
        radial-gradient(circle at 50% 50%, rgba(255, 159, 10, 0.03) 0%, transparent 50%);
    z-index: -2;
}

.bg-blobs {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: -1;
    filter: blur(80px);
    opacity: 0.6;
    pointer-events: none;
}

.blob {
    position: absolute;
    width: 500px;
    height: 500px;
    border-radius: 50%;
    background: var(--primary-color);
    animation: move 25s infinite alternate;
}

.blob-2 {
    background: #5856d6;
    width: 400px;
    height: 400px;
    right: -100px;
    top: -100px;
    animation-delay: -5s;
    animation-duration: 30s;
}

.blob-3 {
    background: #ff2d55;
    width: 300px;
    height: 300px;
    left: 10%;
    bottom: -50px;
    animation-delay: -10s;
    animation-duration: 35s;
}

@keyframes move {
    0% { transform: translate(0, 0) scale(1); }
    33% { transform: translate(100px, 200px) scale(1.2); }
    66% { transform: translate(-100px, 50px) scale(0.8); }
    100% { transform: translate(0, 0) scale(1); }
}

.glass-card {
    background: var(--card-bg);
    backdrop-filter: saturate(180%) blur(20px);
    -webkit-backdrop-filter: saturate(180%) blur(20px);
    border: 1px solid var(--card-border);
    border-radius: 20px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.03);
}

.btn {
    padding: 10px 22px;
    border-radius: 980px; /* Pillow shape for Apple-style buttons */
    border: none;
    cursor: pointer;
    font-weight: 500;
    font-size: 0.95rem;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

.btn-primary {
    background: var(--primary-color);
    color: white;
}

.btn-primary:hover {
    background: var(--primary-hover);
    transform: scale(1.02);
}

/* Animations */
@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

.animate-fade-in {
    animation: fadeIn 0.8s cubic-bezier(0.4, 0, 0.2, 1) forwards;
}

/* Auth Pages */
.auth-container {
    max-width: 440px;
    width: 90%;
    margin: auto;
    padding: 40px 0;
}

.form-group {
    margin-bottom: 24px;
}

.form-group label {
    display: block;
    margin-bottom: 10px;
    color: var(--text-main);
    font-weight: 600;
    font-size: 0.85rem;
}

.form-control {
    width: 100%;
    padding: 14px 16px;
    background: #ffffff;
    border: 1px solid #d2d2d7;
    border-radius: 12px;
    color: var(--text-main);
    outline: none;
    font-size: 1.05rem;
    transition: all 0.2s ease;
}

select.form-control {
    appearance: none;
    -webkit-appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='24' height='24' viewBox='0 0 24 24' fill='none' stroke='%2386868b' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 14px center;
    background-size: 16px;
    padding-right: 40px;
}

.form-control:focus {
    border-color: var(--primary-color);
    box-shadow: 0 0 0 4px rgba(0, 113, 227, 0.1);
}

/* Dashboard Layout */
.navbar {
    padding: 12px 40px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: var(--nav-bg);
    backdrop-filter: saturate(180%) blur(20px);
    -webkit-backdrop-filter: saturate(180%) blur(20px);
    position: sticky;
    top: 0;
    z-index: 100;
    border-bottom: 1px solid var(--card-border);
}

.container {
    max-width: 1200px;
    width: 100%;
    margin: 0 auto;
    padding: 40px 20px;
    flex: 1;
}

.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 24px;
    margin-bottom: 48px;
}

.stat-card {
    padding: 32px;
    text-align: left;
}

.stat-card h3 {
    font-size: 2.4rem;
    font-weight: 700;
    margin-bottom: 4px;
    letter-spacing: -0.02em;
}

.stat-card p {
    color: var(--text-muted);
    font-weight: 500;
}

.ticket-table {
    width: 100%;
    border-collapse: collapse;
}

.ticket-table th {
    text-align: left;
    padding: 12px 14px;
    color: var(--text-muted);
    font-weight: 600;
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.ticket-table td {
    padding: 14px;
    border-top: 1px solid var(--card-border);
    font-size: 0.88rem;
}

.status-badge {
    padding: 4px 12px;
    border-radius: 980px;
    font-size: 0.7rem;
    font-weight: 700;
    text-transform: capitalize;
    white-space: nowrap;
    display: inline-block;
}

.status-pending { background: #fff1e6; color: #ff9500; border: 1px solid rgba(255,149,0,0.2); }
.status-responded { background: #eef7ff; color: #007aff; border: 1px solid rgba(0,122,255,0.2); }
.status-resolved { background: #f0fff4; color: #28cd41; border: 1px solid rgba(40,205,65,0.2); }
.status-closed { background: #f2f2f7; color: #6e6e73; border: 1px solid rgba(110,110,115,0.2); }
.status-in-progress { background: #f5f2ff; color: #5856d6; border: 1px solid rgba(88,86,214,0.2); }
.status-on-hold { background: #fff9e6; color: #ffcc00; border: 1px solid rgba(255,204,0,0.2); }

/* Ticket Detail */
.chat-container {
    display: flex;
    flex-direction: column;
    gap: 24px;
    margin-bottom: 32px;
}

.message {
    padding: 24px;
    border-radius: 20px;
    max-width: 90%;
    position: relative;
    transition: transform 0.2s ease;
}

.message.sent {
    align-self: flex-end;
    background: var(--primary-color);
    color: white;
    border-bottom-right-radius: 4px;
}

.message.received {
    align-self: flex-start;
    background: white;
    border: 1px solid var(--card-border);
    color: var(--text-main);
    border-bottom-left-radius: 4px;
}

.message:hover {
    transform: scale(1.005);
}

.info-row {
    margin-bottom: 20px;
}

.info-row small {
    color: var(--text-muted);
    font-weight: 600;
    font-size: 0.75rem;
    text-transform: uppercase;
    margin-bottom: 6px;
    display: block;
}

.info-row span {
    font-size: 1rem;
    font-weight: 500;
}

/* Attachment Area */
.attachment-box {
    margin-top: 16px;
    padding: 16px;
    background: #fdfdfd;
    border: 1px solid var(--card-border);
    border-radius: 14px;
}

.drop-zone {
    width: 100%;
    min-height: 140px;
    padding: 24px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    border: 2px dashed #d2d2d7;
    border-radius: 12px;
    cursor: pointer;
    transition: all 0.2s ease-in-out;
    background: #fbfbfd;
    position: relative;
    overflow: hidden;
}

.drop-zone:hover, .drop-zone--over {
    border-color: var(--primary-color);
    background: #f5faff;
}

.drop-zone i {
    font-size: 2.5rem;
    color: #a1a1a6;
    margin-bottom: 12px;
    transition: color 0.2s;
}

.drop-zone:hover i {
    color: var(--primary-color);
}

.drop-zone p.upload-title {
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--text-main);
    margin-bottom: 4px;
}

.drop-zone p.upload-subtitle {
    font-size: 0.9rem;
    color: var(--text-muted);
}

.drop-zone__input {
    display: none;
}

.drop-zone__thumb {
    font-size: 0.9rem;
    color: var(--primary-color);
    font-weight: 700;
    background: white;
    padding: 10px 20px;
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.05);
}

/* Modal for Image Preview */
.img-modal {
    display: none;
    position: fixed;
    z-index: 9999;
    padding-top: 60px;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    overflow: auto;
    background-color: rgba(0,0,0,0.9);
    backdrop-filter: blur(8px);
}

.img-modal-content {
    margin: auto;
    display: block;
    max-width: 90%;
    max-height: 85vh;
    border-radius: 12px;
    box-shadow: 0 0 50px rgba(0,0,0,0.5);
    animation: modalZoom 0.3s;
}

@keyframes modalZoom {
    from { transform: scale(0.9); opacity: 0; }
    to { transform: scale(1); opacity: 1; }
}

.close-modal {
    position: absolute;
    top: 20px;
    right: 35px;
    color: #f1f1f1;
    font-size: 40px;
    font-weight: bold;
    cursor: pointer;
    transition: 0.3s;
}

.close-modal:hover {
    color: #bbb;
}

/* Scrollbar */
::-webkit-scrollbar {
    width: 10px;
}
::-webkit-scrollbar-track {
    background: var(--bg-main);
}
::-webkit-scrollbar-thumb {
    background: #d2d2d7;
    border-radius: 10px;
}
::-webkit-scrollbar-thumb:hover {
    background: #86868b;
}

.table-header-controls {
    padding: 20px;
    display: flex;
    justify-content: flex-end;
}

.table-filter-input {
    padding: 8px 16px;
    border-radius: 12px;
    border: 1px solid var(--card-border);
    background: white;
    width: 280px;
    font-size: 0.85rem;
    outline: none;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 0 2px 4px rgba(0,0,0,0.02);
}

.table-filter-input:focus {
    width: 340px;
    border-color: var(--primary-color);
    box-shadow: 0 4px 12px rgba(41, 151, 255, 0.12);
}

.sortable {
    cursor: pointer;
    user-select: none;
    transition: background 0.2s;
}

.sortable:hover {
    background: rgba(0,0,0,0.02);
}

.sort-icon {
    font-size: 0.7rem;
    margin-left: 5px;
    color: #cbd5e1;
}

.active-sort {
    background: rgba(41, 151, 255, 0.04) !important;
    color: var(--primary-color) !important;
}

.sort-icon.active {
    color: var(--primary-color) !important;
    opacity: 1;
}

.pagination-controls {
    padding: 20px 24px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-top: 1px solid var(--card-border);
    background: #fbfbfd;
    border-bottom-left-radius: 20px;
    border-bottom-right-radius: 20px;
}

.pagination-controls .btn:hover:not(:disabled) {
    background: white !important;
    border-color: var(--primary-color) !important;
    color: var(--primary-color) !important;
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(41, 151, 255, 0.1);
}

.ticket-table.loading {
    opacity: 0.5;
    pointer-events: none;
    transition: opacity 0.2s;
}

/* --- RESPONSIVE ADAPTATIONS --- */

@media (max-width: 1024px) {
    .container {
        padding: 20px;
    }
    
    .view-ticket-grid {
        grid-template-columns: 1fr !important; /* Stack sidebar on ticket view */
    }
    
    .sidebar-sticky {
        position: static !important;
    }
}

@media (max-width: 768px) {
    .navbar {
        padding: 15px 20px;
        flex-direction: column;
        gap: 15px;
    }

    .nav-links {
        width: 100%;
        display: flex;
        flex-wrap: wrap;
        justify-content: center;
        gap: 10px;
        margin-top: 10px;
    }

    .nav-links span {
        width: 100%;
        text-align: center;
        margin-right: 0 !important;
    }

    .stats-grid {
        grid-template-columns: 1fr 1fr;
    }

    .stat-card {
        padding: 20px;
    }

    .stat-card h3 {
        font-size: 1.8rem;
    }

    /* Table Responsiveness: Horizontal Scroll */
    .ticket-table {
        display: block;
        width: 100%;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    .glass-card {
        border-radius: 12px;
    }

    /* Force Grid Stacking for ANY 2-column grid inside container */
    .container > div[style*="grid"] {
        grid-template-columns: 1fr !important;
        gap: 20px !important;
    }
    
    .view-ticket-grid {
        grid-template-columns: 1fr !important;
    }

    .message {
        max-width: 100%;
        padding: 15px;
    }

    /* ... */

    .form-row-mobile {
        grid-template-columns: 1fr !important;
    }

    .table-filter-input {
        width: 100% !important;
        margin-top: 15px;
    }
    
    .glass-card div[style*="justify-content: space-between"] {
        flex-direction: column;
        align-items: flex-start !important;
    }
}

@media (max-width: 480px) {
    .stats-grid {
        grid-template-columns: 1fr;
    }

    .btn {
        width: 100%;
        padding: 12px;
    }

    .auth-container {
        padding: 20px 0;
    }

    .glass-card {
        padding: 20px !important;
    }
    
    h1 {
        font-size: 1.6rem !important;
    }
}

