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

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background-color: #f5f5f5;
    color: #333;
}

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

.login-box {
    background: white;
    padding: 40px;
    border-radius: 12px;
    box-shadow: 0 10px 40px rgba(0,0,0,0.2);
    width: 100%;
    max-width: 420px;
}

.login-box h1 {
    text-align: center;
    color: #667eea;
    margin-bottom: 8px;
    font-size: 22px;
}

.subtitle { text-align: center; color: #666; margin-bottom: 24px; }

.role-selection {
    display: flex;
    gap: 12px;
    margin-bottom: 20px;
    justify-content: center;
    flex-wrap: wrap;
}

.role-option {
    display: flex;
    align-items: center;
    gap: 6px;
    cursor: pointer;
    padding: 8px 14px;
    border: 2px solid #ddd;
    border-radius: 8px;
    transition: border-color 0.2s;
}

.role-option:has(input:checked) { border-color: #667eea; background: #f0f2ff; }
.role-option input[type="radio"] { cursor: pointer; }
.role-label { cursor: pointer; font-weight: 500; }

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

.form-group input, .form-group textarea, .form-group select {
    width: 100%;
    padding: 12px;
    border: 1px solid #ddd;
    border-radius: 6px;
    font-size: 14px;
    font-family: inherit;
    transition: border-color 0.2s;
}

.form-group input:focus, .form-group textarea:focus, .form-group select:focus {
    outline: none;
    border-color: #667eea;
    box-shadow: 0 0 0 3px rgba(102,126,234,0.1);
}

.form-group label {
    display: block;
    margin-bottom: 6px;
    font-weight: 600;
    color: #444;
    font-size: 14px;
}

.form-group small { display: block; margin-top: 5px; color: #888; font-size: 12px; }
.required { color: #e74c3c; }
.optional { color: #aaa; font-weight: normal; font-size: 12px; }

.btn-login {
    width: 100%;
    padding: 13px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border: none;
    border-radius: 6px;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    transition: opacity 0.2s, transform 0.2s;
}

.btn-login:hover { opacity: 0.92; transform: translateY(-1px); }

.error-message {
    color: #e74c3c;
    background: #fadbd8;
    padding: 10px;
    border-radius: 5px;
    margin-top: 15px;
    text-align: center;
    font-size: 14px;
}

/* ===== Navbar ===== */
.navbar {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    padding: 15px 30px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    box-shadow: 0 2px 5px rgba(0,0,0,0.1);
    position: sticky;
    top: 0;
    z-index: 100;
}

.navbar-brand { font-size: 18px; font-weight: 600; }

.navbar-user { display: flex; gap: 16px; align-items: center; font-size: 14px; }

.btn-logout {
    background: rgba(255,255,255,0.2);
    color: white;
    padding: 7px 14px;
    border: none;
    border-radius: 5px;
    cursor: pointer;
    text-decoration: none;
    font-size: 13px;
    transition: background 0.2s;
}

.btn-logout:hover { background: rgba(255,255,255,0.35); }

/* ===== Layout ===== */
.container { display: flex; min-height: calc(100vh - 56px); }

.sidebar {
    width: 230px;
    background: white;
    box-shadow: 2px 0 5px rgba(0,0,0,0.08);
    padding: 20px 14px;
    flex-shrink: 0;
}

.menu { display: flex; flex-direction: column; gap: 8px; }

.menu-item {
    background: white;
    border: 2px solid #ddd;
    padding: 12px 14px;
    border-radius: 7px;
    cursor: pointer;
    text-align: left;
    font-size: 14px;
    font-weight: 500;
    transition: all 0.2s;
    color: #444;
}

.menu-item:hover { border-color: #667eea; background: #f9f9ff; }

.menu-item.active {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border-color: #667eea;
}

.menu-action {
    background: #f5f5f5;
    border: 2px dashed #ccc;
    padding: 11px 14px;
    border-radius: 7px;
    cursor: pointer;
    text-align: left;
    font-size: 14px;
    font-weight: 500;
    transition: all 0.2s;
    color: #555;
    margin-top: 4px;
}

.menu-action:hover { border-color: #667eea; background: #f0f2ff; color: #667eea; }

.main-content {
    flex: 1;
    padding: 28px;
    background: #f5f5f5;
    overflow-y: auto;
}

/* ===== Filter ===== */
.filter-section {
    background: white;
    padding: 14px 18px;
    border-radius: 8px;
    margin-bottom: 18px;
    box-shadow: 0 2px 5px rgba(0,0,0,0.07);
    display: flex;
    align-items: center;
    gap: 14px;
    flex-wrap: wrap;
}

.filter-section label { font-weight: 600; color: #444; font-size: 13px; }
.filter-section select {
    padding: 7px 11px;
    border: 1px solid #ddd;
    border-radius: 5px;
    font-size: 13px;
    background: white;
    cursor: pointer;
    min-width: 160px;
}

.filter-section select:focus { outline: none; border-color: #667eea; }

/* ===== View Sections ===== */
.view-section { display: none; }
.view-section.active { display: block; }
.view-section h2 { color: #333; margin-bottom: 18px; font-size: 22px; }

/* ===== Ticket Cards ===== */
.tickets-list { display: grid; gap: 14px; }

.ticket-card {
    background: white;
    padding: 18px 20px;
    border-radius: 10px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.07);
    cursor: pointer;
    transition: all 0.25s;
    border-left: 4px solid transparent;
}

.ticket-card:hover {
    box-shadow: 0 6px 18px rgba(0,0,0,0.13);
    transform: translateY(-2px);
    border-left-color: #667eea;
}

.ticket-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 10px;
}

.ticket-id { font-weight: 700; color: #667eea; font-size: 15px; }
.ticket-raised { font-size: 13px; color: #555; margin-top: 3px; }
.ticket-client { font-size: 12px; color: #888; margin-top: 4px; }
.ticket-problem { color: #555; line-height: 1.5; font-size: 14px; margin: 8px 0; }
.ticket-date { font-size: 12px; color: #aaa; }

.ticket-priority {
    display: inline-block;
    padding: 3px 10px;
    border-radius: 12px;
    font-size: 12px;
    font-weight: 600;
}

.priority-high { background: #fde8e8; color: #c0392b; }
.priority-medium { background: #fef9e7; color: #d68910; }
.priority-low { background: #eafaf1; color: #1e8449; }

.ticket-status {
    display: inline-block;
    padding: 4px 12px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 600;
}

.status-pending { background: #fff3cd; color: #856404; }
.status-resolved { background: #d4edda; color: #155724; }

.ticket-actions { display: flex; gap: 8px; margin-top: 12px; flex-wrap: wrap; }

/* ===== Buttons ===== */
.btn-primary {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    padding: 11px 28px;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 600;
    transition: opacity 0.2s, transform 0.2s;
}

.btn-primary:hover { opacity: 0.9; transform: translateY(-1px); }

.btn-solution {
    background: #27ae60;
    color: white;
    padding: 8px 14px;
    border: none;
    border-radius: 5px;
    cursor: pointer;
    font-size: 13px;
    transition: background 0.2s;
}

.btn-solution:hover { background: #229954; }

.btn-seen {
    background: #27ae60;
    color: white;
    padding: 8px 14px;
    border: none;
    border-radius: 5px;
    cursor: pointer;
    font-size: 13px;
    transition: background 0.2s;
}

.btn-seen:hover { background: #1e8449; }

.btn-reraise {
    background: #e67e22;
    color: white;
    padding: 8px 14px;
    border: none;
    border-radius: 5px;
    cursor: pointer;
    font-size: 13px;
    transition: background 0.2s;
}

.btn-reraise:hover { background: #ca6f1e; }

.btn-view-detail {
    background: #3498db;
    color: white;
    padding: 8px 14px;
    border: none;
    border-radius: 5px;
    cursor: pointer;
    font-size: 13px;
    transition: background 0.2s;
}

.btn-view-detail:hover { background: #2980b9; }

/* ===== Ticket Form ===== */
.ticket-form {
    background: white;
    padding: 24px;
    border-radius: 10px;
    max-width: 620px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.08);
}

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

.modal.show {
    display: flex;
    justify-content: center;
    align-items: center;
}

.modal-content {
    background: white;
    padding: 28px;
    border-radius: 10px;
    width: 90%;
    max-width: 540px;
    max-height: 85vh;
    overflow-y: auto;
    box-shadow: 0 10px 40px rgba(0,0,0,0.25);
}

.modal-large { max-width: 700px; }

.close {
    color: #aaa;
    float: right;
    font-size: 26px;
    font-weight: bold;
    cursor: pointer;
    line-height: 1;
    transition: color 0.2s;
}

.close:hover { color: #333; }

.modal-content h2 { margin-bottom: 18px; color: #333; clear: both; }

/* ===== Ticket Details ===== */
.ticket-details { padding: 5px 0; }

.detail-row {
    display: flex;
    padding: 10px 0;
    border-bottom: 1px solid #f0f0f0;
    gap: 12px;
}

.detail-label {
    font-weight: 600;
    min-width: 130px;
    color: #667eea;
    font-size: 13px;
}

.detail-value { flex: 1; color: #444; line-height: 1.6; font-size: 14px; }

.solution-box {
    background: #edf7ee;
    border-left: 3px solid #27ae60;
    padding: 12px 15px;
    border-radius: 6px;
    line-height: 1.6;
    font-size: 14px;
}

.solution-preview {
    background: #f9fff9;
    border: 1px solid #c3e6cb;
    border-radius: 8px;
    padding: 12px;
    margin-top: 10px;
    font-size: 13px;
}

/* ===== Attachments ===== */
.attachment-link {
    display: inline-block;
    color: #667eea;
    text-decoration: none;
    font-size: 13px;
    padding: 3px 8px;
    border-radius: 4px;
    background: #f0f2ff;
    margin: 2px 0;
    transition: background 0.2s;
}

.attachment-link:hover { background: #dde0ff; }

/* ===== Messages ===== */
.message { padding: 12px; border-radius: 6px; margin-top: 12px; font-size: 14px; }
.message.success { background: #d4edda; color: #155724; border: 1px solid #c3e6cb; }
.message.error { background: #f8d7da; color: #721c24; border: 1px solid #f5c6cb; }

.loading { text-align: center; color: #aaa; padding: 30px; }

/* ===== Chat ===== */
.chat-modal-fullscreen {
    display: none;
    position: fixed;
    z-index: 9999;
    left: 0; top: 0;
    width: 100%; height: 100%;
    background: rgba(0,0,0,0.5);
}

.chat-modal-fullscreen.show {
    display: flex;
    align-items: center;
    justify-content: center;
}

.chat-wrapper { width: 90%; max-width: 800px; height: 85vh; }

.chat-container {
    background: white;
    width: 100%;
    height: 100%;
    border-radius: 12px;
    display: flex;
    flex-direction: column;
    box-shadow: 0 10px 40px rgba(0,0,0,0.25);
    overflow: hidden;
}

.chat-header {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    padding: 18px 22px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.chat-header h2 { margin: 0; font-size: 20px; }
.chat-header .close { color: white; font-size: 24px; }
.chat-header .close:hover { color: #eee; }

.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 18px;
    background: #f9f9f9;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.chat-line {
    padding: 10px 14px;
    border-radius: 10px;
    max-width: 80%;
    font-size: 14px;
    line-height: 1.5;
    word-wrap: break-word;
}

.chat-line.user { align-self: flex-end; background: #667eea; color: white; border-bottom-right-radius: 2px; }
.chat-line.assistant { align-self: flex-start; background: #e8e8e8; color: #333; border-bottom-left-radius: 2px; }

.chat-form {
    display: flex;
    gap: 10px;
    padding: 14px;
    background: white;
    border-top: 1px solid #eee;
}

.chat-form input {
    flex: 1;
    padding: 11px 14px;
    border: 1px solid #ddd;
    border-radius: 6px;
    font-size: 14px;
    font-family: inherit;
}

.chat-form input:focus { outline: none; border-color: #667eea; box-shadow: 0 0 0 3px rgba(102,126,234,0.1); }
.chat-form .btn-primary { padding: 11px 24px; }

/* ===== Toast ===== */
.toast {
    position: fixed;
    bottom: 24px;
    right: 24px;
    padding: 14px 22px;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 500;
    z-index: 9999;
    box-shadow: 0 4px 20px rgba(0,0,0,0.15);
    display: none;
    animation: slideIn 0.3s ease;
}

.toast-success { background: #27ae60; color: white; }
.toast-error { background: #e74c3c; color: white; }

@keyframes slideIn {
    from { transform: translateY(20px); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
}

/* ===== Responsive ===== */
@media (max-width: 768px) {
    .container { flex-direction: column; }
    .sidebar { width: 100%; padding: 10px; }
    .menu { flex-direction: row; overflow-x: auto; }
    .menu-item, .menu-action { white-space: nowrap; flex-shrink: 0; }
    .main-content { padding: 15px; }
    .navbar { flex-direction: column; gap: 10px; text-align: center; }
    .filter-section { flex-direction: column; align-items: flex-start; }
}

/* ===== Navbar Logo ===== */
.navbar-logo {
    height: 36px;
    width: auto;
    max-width: 120px;
    object-fit: contain;
    border-radius: 4px;
    margin-right: 10px;
    vertical-align: middle;
    background: white;
    padding: 2px 4px;
}

/* ===== Remove User Button ===== */
.btn-remove {
    background: #e74c3c;
    color: white;
    padding: 6px 12px;
    border: none;
    border-radius: 5px;
    cursor: pointer;
    font-size: 12px;
    transition: background 0.2s;
}
.btn-remove:hover { background: #c0392b; }

/* ===== Monthly Report ===== */
.report-stats {
    display: flex;
    gap: 20px;
    flex-wrap: wrap;
    margin-bottom: 20px;
}

.stat-card {
    background: white;
    border-radius: 10px;
    padding: 20px 30px;
    text-align: center;
    box-shadow: 0 2px 8px rgba(0,0,0,0.08);
    flex: 1;
    min-width: 120px;
    border-top: 4px solid #667eea;
}

.stat-card.stat-resolved { border-top-color: #27ae60; }
.stat-card.stat-pending { border-top-color: #e67e22; }

.stat-num {
    font-size: 36px;
    font-weight: 700;
    color: #333;
}

.stat-label {
    font-size: 13px;
    color: #888;
    margin-top: 4px;
}

.report-table {
    width: 100%;
    border-collapse: collapse;
    background: white;
    border-radius: 8px;
    overflow: hidden;
    box-shadow: 0 2px 8px rgba(0,0,0,0.07);
    font-size: 13px;
}

.report-table th {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    padding: 12px 10px;
    text-align: left;
    font-weight: 600;
    white-space: nowrap;
}

.report-table td {
    padding: 10px;
    border-bottom: 1px solid #f0f0f0;
    color: #444;
    vertical-align: middle;
}

.report-table tr:hover td { background: #f9f9ff; }
.report-table tr:last-child td { border-bottom: none; }

/* ===== Print styles for report ===== */
@media print {
    .sidebar, .navbar, .filter-section, #btnGenerateReport, #btnPrintReport { display: none !important; }
    .main-content { padding: 0; }
    .report-table { font-size: 11px; }
    .stat-card { box-shadow: none; border: 1px solid #ddd; }
}

/* ===== Company Overview Cards ===== */
.companies-grid { display: grid; gap: 18px; grid-template-columns: repeat(auto-fill, minmax(340px, 1fr)); }

.company-card {
    background: white;
    border-radius: 12px;
    padding: 20px;
    box-shadow: 0 2px 10px rgba(0,0,0,0.08);
    border-top: 4px solid #667eea;
    transition: transform 0.2s, box-shadow 0.2s;
}
.company-card:hover { transform: translateY(-3px); box-shadow: 0 8px 24px rgba(0,0,0,0.12); }

.company-card-header { display: flex; gap: 14px; align-items: flex-start; margin-bottom: 16px; }
.company-logo-sm { width: 56px; height: 56px; object-fit: contain; border-radius: 8px; border: 1px solid #eee; background: #f9f9f9; padding: 4px; flex-shrink: 0; }
.company-logo-placeholder { width: 56px; height: 56px; display: flex; align-items: center; justify-content: center; font-size: 28px; background: #f0f2ff; border-radius: 8px; flex-shrink: 0; }
.company-card-name { font-size: 17px; font-weight: 700; color: #333; }
.company-card-user { font-size: 12px; color: #888; margin-top: 3px; }
.company-card-user code { background: #f0f0f0; padding: 1px 5px; border-radius: 3px; font-size: 12px; }
.company-card-branches { font-size: 12px; color: #667eea; margin-top: 4px; }

.company-stats { display: flex; gap: 10px; margin-bottom: 16px; }
.cstat { flex: 1; text-align: center; padding: 10px 6px; background: #f5f5f5; border-radius: 8px; }
.cstat-num { font-size: 24px; font-weight: 700; color: #333; }
.cstat-label { font-size: 11px; color: #888; margin-top: 2px; }
.cstat-green .cstat-num { color: #27ae60; }
.cstat-orange .cstat-num { color: #e67e22; }

.company-card-actions { display: flex; gap: 8px; flex-wrap: wrap; }

.btn-detail { background: #667eea; color: white; padding: 7px 12px; border: none; border-radius: 6px; cursor: pointer; font-size: 13px; transition: background 0.2s; }
.btn-detail:hover { background: #5a6fd6; }

.btn-edit-co { background: #f39c12; color: white; padding: 7px 12px; border: none; border-radius: 6px; cursor: pointer; font-size: 13px; transition: background 0.2s; }
.btn-edit-co:hover { background: #d68910; }

.btn-reset-pw { background: #e74c3c; color: white; padding: 7px 12px; border: none; border-radius: 6px; cursor: pointer; font-size: 13px; transition: background 0.2s; }
.btn-reset-pw:hover { background: #c0392b; }

.btn-edit-user { background: #3498db; color: white; padding: 6px 12px; border: none; border-radius: 5px; cursor: pointer; font-size: 12px; transition: background 0.2s; }
.btn-edit-user:hover { background: #2980b9; }

.btn-back { background: #667eea; color: white; padding: 8px 16px; border: none; border-radius: 6px; cursor: pointer; font-size: 14px; font-weight: 600; }
.btn-back:hover { background: #5a6fd6; }

.btn-secondary { background: #6c757d; color: white; padding: 11px 20px; border: none; border-radius: 6px; cursor: pointer; font-size: 14px; font-weight: 600; }
.btn-secondary:hover { background: #5a6268; }

.branch-tag { display: inline-block; background: #f0f2ff; color: #667eea; padding: 3px 10px; border-radius: 12px; font-size: 12px; margin: 2px 4px 2px 0; }
