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

:root {
    --primary: #2563eb;
    --primary-dark: #1d4ed8;
    --success: #16a34a;
    --danger: #dc2626;
    --warning: #f59e0b;
    --info: #0ea5e9;
    --gray-50: #f9fafb;
    --gray-100: #f3f4f6;
    --gray-200: #e5e7eb;
    --gray-300: #d1d5db;
    --gray-400: #9ca3af;
    --gray-500: #6b7280;
    --gray-600: #4b5563;
    --gray-700: #374151;
    --gray-800: #1f2937;
    --gray-900: #111827;
    --radius: 8px;
    --shadow: 0 1px 3px rgba(0,0,0,0.1);
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--gray-50);
    color: var(--gray-800);
    line-height: 1.6;
}

.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 20px;
}

/* Navbar */
.navbar {
    background: var(--gray-900);
    color: white;
    padding: 0 20px;
    position: sticky;
    top: 0;
    z-index: 100;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.navbar .container {
    display: flex;
    align-items: center;
    height: 56px;
}

.navbar-brand {
    color: white;
    text-decoration: none;
    font-size: 1.125rem;
    font-weight: 700;
    margin-right: 32px;
}

.navbar-nav {
    display: flex;
    list-style: none;
    gap: 4px;
    flex: 1;
}

.navbar-nav a {
    color: var(--gray-300);
    text-decoration: none;
    padding: 8px 12px;
    border-radius: var(--radius);
    font-size: 0.875rem;
    transition: all 0.2s;
}

.navbar-nav a:hover {
    color: white;
    background: var(--gray-700);
}

.navbar-user {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.875rem;
    color: var(--gray-300);
}

.dropdown {
    position: relative;
}

.dropdown-menu {
    display: none;
    position: absolute;
    top: 100%;
    left: 0;
    background: white;
    min-width: 200px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
    border-radius: var(--radius);
    padding: 4px;
    z-index: 200;
}

.dropdown:hover .dropdown-menu {
    display: block;
}

.dropdown-menu a {
    display: block;
    color: var(--gray-700) !important;
    padding: 8px 12px;
}

.dropdown-menu a:hover {
    background: var(--gray-100) !important;
    color: var(--gray-900) !important;
}

/* Auth pages */
.auth-page {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    background: linear-gradient(135deg, var(--gray-900) 0%, var(--primary-dark) 100%);
}

.auth-container {
    width: 100%;
    max-width: 420px;
    padding: 20px;
}

.auth-box {
    background: white;
    border-radius: 12px;
    box-shadow: 0 20px 60px rgba(0,0,0,0.3);
    padding: 40px;
}

.auth-logo {
    text-align: center;
    font-size: 1.5rem;
    color: var(--gray-900);
    margin-bottom: 24px;
}

.auth-form {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.auth-links {
    text-align: center;
    margin-top: 8px;
}

.auth-links a {
    color: var(--primary);
    text-decoration: none;
    font-size: 0.875rem;
}

/* Cards */
.card {
    background: white;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    margin-bottom: 20px;
}

.card-header {
    padding: 16px 20px;
    border-bottom: 1px solid var(--gray-200);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.card-header h2 {
    font-size: 1rem;
    font-weight: 600;
}

.card-body {
    padding: 20px;
}

.card-danger {
    border-left: 4px solid var(--danger);
}

/* Stats grid */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 16px;
    margin-bottom: 24px;
}

.stat-card {
    background: white;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 20px;
    text-align: center;
}

.stat-value {
    display: block;
    font-size: 2rem;
    font-weight: 700;
    color: var(--primary);
}

.stat-label {
    display: block;
    font-size: 0.875rem;
    color: var(--gray-500);
    margin-top: 4px;
}

.stat-danger .stat-value { color: var(--danger); }
.stat-warning .stat-value { color: var(--warning); }

/* Page header */
.page-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 24px;
    margin-top: 24px;
}

.page-header h1 {
    font-size: 1.5rem;
    font-weight: 700;
}

/* Forms */
.form-group {
    margin-bottom: 16px;
}

.form-group label {
    display: block;
    font-size: 0.875rem;
    font-weight: 500;
    margin-bottom: 4px;
    color: var(--gray-700);
}

.form-control {
    width: 100%;
    padding: 8px 12px;
    border: 1px solid var(--gray-300);
    border-radius: var(--radius);
    font-size: 0.875rem;
    transition: border-color 0.2s;
}

.form-control:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

textarea.form-control {
    resize: vertical;
    min-height: 100px;
}

select.form-control {
    appearance: auto;
}

.form-check {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 12px;
}

.form-check-input {
    width: 16px;
    height: 16px;
}

/* Buttons */
.btn {
    display: inline-block;
    padding: 8px 16px;
    border: none;
    border-radius: var(--radius);
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    text-decoration: none;
    transition: all 0.2s;
}

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

.btn-primary:hover {
    background: var(--primary-dark);
}

.btn-secondary {
    background: var(--gray-200);
    color: var(--gray-700);
}

.btn-secondary:hover {
    background: var(--gray-300);
}

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

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

.btn-sm {
    padding: 4px 8px;
    font-size: 0.75rem;
}

.btn-block {
    width: 100%;
    text-align: center;
}

/* Tables */
.table {
    width: 100%;
    border-collapse: collapse;
}

.table th {
    text-align: left;
    padding: 10px 12px;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--gray-500);
    border-bottom: 2px solid var(--gray-200);
}

.table td {
    padding: 10px 12px;
    border-bottom: 1px solid var(--gray-100);
    font-size: 0.875rem;
}

.table tr:hover {
    background: var(--gray-50);
}

.table tr.table-danger {
    background: #fef2f2;
}

.table a {
    color: var(--primary);
    text-decoration: none;
}

.table a:hover {
    text-decoration: underline;
}

/* Badges */
.badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 12px;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: lowercase;
}

.badge-low { background: #dbeafe; color: #1e40af; }
.badge-medium { background: #fef3c7; color: #92400e; }
.badge-high { background: #fed7aa; color: #9a3412; }
.badge-critical { background: #fecaca; color: #991b1b; }
.badge-open { background: #dbeafe; color: #1e40af; }
.badge-in_progress { background: #fef3c7; color: #92400e; }
.badge-waiting_user { background: #f3e8ff; color: #6b21a8; }
.badge-resolved { background: #dcfce7; color: #166534; }
.badge-closed { background: var(--gray-200); color: var(--gray-600); }
.badge-admin { background: #fecaca; color: #991b1b; }
.badge-agent { background: #fef3c7; color: #92400e; }
.badge-user { background: #dbeafe; color: #1e40af; }
.badge-active { background: #dcfce7; color: #166534; }
.badge-inactive { background: var(--gray-200); color: var(--gray-500); }
.badge-internal { background: var(--gray-200); color: var(--gray-600); }

/* Alerts */
.alert {
    padding: 12px 16px;
    border-radius: var(--radius);
    margin-bottom: 16px;
    font-size: 0.875rem;
}

.alert-success {
    background: #dcfce7;
    color: #166534;
    border: 1px solid #bbf7d0;
}

.alert-danger {
    background: #fef2f2;
    color: #991b1b;
    border: 1px solid #fecaca;
}

/* Filters */
.filters {
    display: flex;
    gap: 12px;
    align-items: end;
    flex-wrap: wrap;
}

.filter-group {
    flex: 1;
    min-width: 150px;
}

/* Pagination */
.pagination {
    display: flex;
    gap: 4px;
    margin-top: 16px;
    justify-content: center;
}

.page-link {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    border-radius: var(--radius);
    background: white;
    border: 1px solid var(--gray-200);
    text-decoration: none;
    color: var(--gray-700);
    font-size: 0.875rem;
}

.page-link.active {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
}

/* Comments */
.comment {
    padding: 16px;
    margin-bottom: 12px;
    border: 1px solid var(--gray-200);
    border-radius: var(--radius);
}

.comment-internal {
    background: #faf5ff;
    border-color: #e9d5ff;
}

.comment-header {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 8px;
}

.comment-body {
    font-size: 0.875rem;
    line-height: 1.6;
}

.comment-form {
    margin-top: 20px;
    padding-top: 20px;
    border-top: 1px solid var(--gray-200);
}

/* Ticket detail */
.ticket-detail {
    max-width: 900px;
}

.ticket-meta {
    display: flex;
    gap: 8px;
}

.ticket-info {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 8px 24px;
    margin-bottom: 20px;
    padding-bottom: 16px;
    border-bottom: 1px solid var(--gray-200);
}

.info-row {
    font-size: 0.875rem;
}

.info-label {
    font-weight: 600;
    color: var(--gray-500);
    margin-right: 4px;
}

.ticket-description {
    margin-bottom: 20px;
}

.ticket-description h3 {
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--gray-500);
    margin-bottom: 8px;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.ticket-description p {
    font-size: 0.9375rem;
    line-height: 1.7;
    white-space: pre-wrap;
}

.ticket-attachments {
    margin-bottom: 20px;
}

.ticket-attachments h3 {
    font-size: 0.875rem;
    font-weight: 600;
    margin-bottom: 8px;
}

.ticket-attachments ul {
    list-style: none;
}

.ticket-attachments li {
    padding: 4px 0;
}

.action-buttons {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    align-items: center;
}

/* History */
.history-list {
    max-height: 300px;
    overflow-y: auto;
}

.history-item {
    padding: 8px 0;
    border-bottom: 1px solid var(--gray-100);
    font-size: 0.8125rem;
}

.history-header {
    display: flex;
    justify-content: space-between;
}

.history-action {
    color: var(--gray-500);
    margin-top: 2px;
}

.old-value {
    text-decoration: line-through;
    color: var(--danger);
}

.new-value {
    color: var(--success);
    font-weight: 500;
}

/* Ticket list */
.ticket-list {
    list-style: none;
}

.ticket-list li {
    padding: 8px 0;
    border-bottom: 1px solid var(--gray-100);
}

.ticket-list a {
    color: var(--gray-700);
    text-decoration: none;
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.875rem;
}

/* Modal */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.modal-content {
    background: white;
    border-radius: 12px;
    max-width: 500px;
    width: 90%;
    max-height: 80vh;
    overflow-y: auto;
}

.modal-header {
    padding: 20px;
    border-bottom: 1px solid var(--gray-200);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

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

.close {
    font-size: 1.5rem;
    cursor: pointer;
    color: var(--gray-400);
}

.close:hover {
    color: var(--gray-600);
}

.modal-body {
    padding: 20px;
}

/* Footer */
.footer {
    background: white;
    border-top: 1px solid var(--gray-200);
    padding: 16px 0;
    margin-top: 40px;
    text-align: center;
    font-size: 0.8125rem;
    color: var(--gray-500);
}

/* Error page */
.error-page {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    background: var(--gray-50);
}

.error-container {
    text-align: center;
}

.error-box {
    padding: 40px;
}

.error-code {
    font-size: 5rem;
    font-weight: 800;
    color: var(--primary);
    line-height: 1;
}

.error-title {
    font-size: 1.5rem;
    color: var(--gray-700);
    margin: 16px 0;
}

.error-message {
    color: var(--gray-500);
    margin-bottom: 24px;
}

/* Row / Col grid */
.row {
    display: flex;
    gap: 20px;
    flex-wrap: wrap;
}

.col-md-4 { flex: 1; min-width: 250px; }
.col-md-5 { flex: 0 0 calc(41.666% - 20px); min-width: 300px; }
.col-md-6 { flex: 0 0 calc(50% - 20px); min-width: 300px; }
.col-md-7 { flex: 0 0 calc(58.333% - 20px); min-width: 300px; }
.col-md-8 { flex: 0 0 calc(66.666% - 20px); min-width: 300px; }

/* Utilities */
.text-muted { color: var(--gray-500); }
.text-danger { color: var(--danger); }
.text-success { color: var(--success); }

/* Responsive */
@media (max-width: 768px) {
    .stats-grid {
        grid-template-columns: repeat(2, 1fr);
    }

    .filters {
        flex-direction: column;
    }

    .filter-group {
        min-width: 100%;
    }

    .row {
        flex-direction: column;
    }

    .col-md-4, .col-md-5, .col-md-6, .col-md-7, .col-md-8 {
        flex: 1;
        min-width: 100%;
    }

    .navbar-nav {
        display: none;
    }

    .page-header {
        flex-direction: column;
        gap: 12px;
        align-items: start;
    }
}
