/* ========== Reset & Base ========== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
    --primary: #1e3a5f;
    --primary-light: #2a5a8f;
    --primary-dark: #0f2744;
    --accent: #0ea5e9;
    --accent-light: #38bdf8;
    --success: #22c55e;
    --warning: #f59e0b;
    --danger: #ef4444;
    --info: #6366f1;
    --bg: #f1f5f9;
    --surface: #ffffff;
    --text: #1e293b;
    --text-muted: #64748b;
    --border: #e2e8f0;
    --sidebar-width: 250px;
    --radius: 8px;
    --shadow: 0 1px 3px rgba(0,0,0,.1), 0 1px 2px rgba(0,0,0,.06);
    --shadow-md: 0 4px 6px rgba(0,0,0,.07), 0 2px 4px rgba(0,0,0,.06);
}

html, body { height: 100%; font-family: 'Segoe UI', system-ui, -apple-system, sans-serif; background: var(--bg); color: var(--text); }

/* ========== Layout ========== */
.app-layout { display: flex; min-height: 100vh; }

.sidebar {
    width: var(--sidebar-width); background: var(--primary); color: #fff;
    display: flex; flex-direction: column; position: fixed; top: 0; bottom: 0; left: 0; z-index: 100;
}

.sidebar-header { padding: 24px 20px 16px; border-bottom: 1px solid rgba(255,255,255,.15); }
.sidebar-header h2 { font-size: 1.25rem; font-weight: 700; letter-spacing: .5px; }
.sidebar-subtitle { font-size: .75rem; color: rgba(255,255,255,.6); text-transform: uppercase; letter-spacing: 1px; }

.sidebar-nav { list-style: none; padding: 12px 0; flex: 1; overflow-y: auto; scrollbar-width: thin; scrollbar-color: rgba(255,255,255,.2) transparent; }
.sidebar-nav::-webkit-scrollbar { width: 4px; }
.sidebar-nav::-webkit-scrollbar-track { background: transparent; }
.sidebar-nav::-webkit-scrollbar-thumb { background: rgba(255,255,255,.2); border-radius: 4px; }
.nav-group-label {
    padding: 16px 20px 4px;
    font-size: .68rem;
    font-weight: 700;
    letter-spacing: 1.2px;
    text-transform: uppercase;
    color: rgba(255,255,255,.35);
    pointer-events: none;
    user-select: none;
}
.nav-group-label:not(:first-child) { margin-top: 4px; border-top: 1px solid rgba(255,255,255,.08); }

.sidebar-nav li a {
    display: flex; align-items: center; gap: 10px; padding: 12px 20px;
    color: rgba(255,255,255,.8); text-decoration: none; font-size: .9rem; transition: all .15s;
}
.sidebar-nav li a:hover { background: rgba(255,255,255,.1); color: #fff; }
.sidebar-nav li a.active { background: rgba(255,255,255,.15); color: #fff; font-weight: 600; border-left: 3px solid var(--accent); }
.nav-icon { font-size: 1rem; width: 20px; text-align: center; }

.sidebar-footer { padding: 16px 20px; border-top: 1px solid rgba(255,255,255,.15); color: rgba(255,255,255,.5); }

.main-content { margin-left: var(--sidebar-width); flex: 1; display: flex; flex-direction: column; }

.top-bar {
    background: var(--surface); border-bottom: 1px solid var(--border); padding: 16px 32px;
    box-shadow: var(--shadow);
}
.page-title { font-size: 1.25rem; font-weight: 600; }

.content-area { padding: 24px 32px; flex: 1; }

/* ========== Cards ========== */
.card { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); padding: 20px; }
.card-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 16px; }
.card-title { font-size: 1rem; font-weight: 600; }

/* ========== Stats Grid ========== */
.stats-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 16px; margin-bottom: 24px; }
.stat-card {
    background: var(--surface); border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow);
    display: flex; flex-direction: column; gap: 4px;
}
.stat-card.clickable { cursor: pointer; transition: all .15s; }
.stat-card.clickable:hover { transform: translateY(-2px); box-shadow: var(--shadow-md); }
.stat-value { font-size: 2rem; font-weight: 700; }
.stat-label { font-size: .85rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: .5px; }
.stat-card.open { border-left: 4px solid var(--accent); }
.stat-card.in-progress { border-left: 4px solid var(--warning); }
.stat-card.awaiting { border-left: 4px solid var(--info); }
.stat-card.resolved { border-left: 4px solid var(--success); }
.stat-card.closed { border-left: 4px solid var(--text-muted); }
.stat-card.total { border-left: 4px solid var(--primary); }
.stat-card.today { border-left: 4px solid var(--danger); }
.stat-card.users { border-left: 4px solid var(--success); }

/* ========== Table ========== */
.table-container { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: .9rem; }
thead th {
    text-align: left; padding: 12px 16px; background: var(--bg); font-weight: 600;
    color: var(--text-muted); text-transform: uppercase; font-size: .75rem; letter-spacing: .5px;
    border-bottom: 2px solid var(--border);
}
tbody td { padding: 12px 16px; border-bottom: 1px solid var(--border); vertical-align: middle; }
tbody tr { cursor: pointer; transition: background .1s; }
tbody tr:hover { background: #f8fafc; }

/* ========== Badges ========== */
.badge {
    display: inline-block; padding: 3px 10px; border-radius: 999px; font-size: .75rem; font-weight: 600;
    text-transform: uppercase; letter-spacing: .3px;
}
.badge-open { background: #dbeafe; color: #1e40af; }
.badge-inprogress { background: #fef3c7; color: #92400e; }
.badge-awaiting { background: #e0e7ff; color: #3730a3; }
.badge-resolved { background: #dcfce7; color: #166534; }
.badge-closed { background: #f1f5f9; color: #475569; }

.badge-low { background: #f1f5f9; color: #475569; }
.badge-medium { background: #dbeafe; color: #1e40af; }
.badge-high { background: #fef3c7; color: #92400e; }
.badge-critical { background: #fecaca; color: #991b1b; }
.badge-warning { background: #ffedd5; color: #c2410c; }  /* Orange - SLA due soon (15-30 min) */
.badge-soon { background: #fef9c3; color: #854d0e; }    /* Yellow - SLA approaching (30-120 min) */

/* ========== Buttons ========== */
.btn {
    display: inline-flex; align-items: center; gap: 6px; padding: 8px 16px;
    border: none; border-radius: var(--radius); font-size: .85rem; font-weight: 500;
    cursor: pointer; transition: all .15s; text-decoration: none;
}
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-light); }
.btn-accent { background: var(--accent); color: #fff; }
.btn-accent:hover { background: var(--accent-light); }
.btn-outline { background: transparent; border: 1px solid var(--border); color: var(--text); }
.btn-outline:hover { background: var(--bg); }
.btn-sm { padding: 4px 10px; font-size: .8rem; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-success { background: var(--success); color: #fff; }

/* ========== Forms ========== */
.form-group { display: flex; flex-direction: column; gap: 4px; }
.form-label { font-size: .85rem; font-weight: 500; color: var(--text-muted); }
.form-control {
    padding: 8px 12px; border: 1px solid var(--border); border-radius: var(--radius);
    font-size: .9rem; outline: none; transition: border .15s;
}
.form-control:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(14,165,233,.15); }
select.form-control { appearance: auto; }

.filters-bar { display: flex; gap: 12px; align-items: end; flex-wrap: wrap; margin-bottom: 20px; }
.filters-bar .form-group { min-width: 180px; }
.search-input { min-width: 280px; }

/* ========== Pagination ========== */
.pagination { display: flex; gap: 4px; justify-content: center; align-items: center; margin-top: 20px; }
.pagination button { min-width: 36px; height: 36px; border: 1px solid var(--border); background: var(--surface); border-radius: var(--radius); cursor: pointer; font-size: .85rem; }
.pagination button:hover:not(:disabled) { background: var(--bg); }
.pagination button:disabled { opacity: .4; cursor: default; }
.pagination .page-info { font-size: .85rem; color: var(--text-muted); padding: 0 8px; }

/* ========== Ticket Detail ========== */
.ticket-header { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; flex-wrap: wrap; }
.ticket-meta { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 12px; margin: 16px 0; }
.meta-item { display: flex; flex-direction: column; gap: 2px; }
.meta-label { font-size: .75rem; text-transform: uppercase; letter-spacing: .5px; color: var(--text-muted); font-weight: 600; }
.meta-value { font-size: .9rem; }

.ticket-description { background: var(--bg); border-radius: var(--radius); padding: 16px; margin: 16px 0; white-space: pre-wrap; font-size: .9rem; line-height: 1.6; }

.comments-section { margin-top: 24px; }
.comment { border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; margin-bottom: 12px; }
.comment-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.comment-author { font-weight: 600; font-size: .9rem; }
.comment-date { font-size: .8rem; color: var(--text-muted); }
.comment-body { white-space: pre-wrap; font-size: .9rem; line-height: 1.5; }

.attachments-list { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }
.attachment-chip {
    display: inline-flex; align-items: center; gap: 4px; padding: 4px 10px;
    background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius); font-size: .8rem;
}

.back-link { display: inline-flex; align-items: center; gap: 4px; color: var(--accent); text-decoration: none; font-size: .9rem; margin-bottom: 16px; }
.back-link:hover { text-decoration: underline; }

/* ========== Loading ========== */
.loading { text-align: center; padding: 48px; color: var(--text-muted); }
.spinner { display: inline-block; width: 24px; height: 24px; border: 3px solid var(--border); border-top-color: var(--accent); border-radius: 50%; animation: spin .6s linear infinite; margin-right: 8px; vertical-align: middle; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ========== Mobile Header & Hamburger ========== */
.mobile-header { display: none; }

.sidebar-overlay {
    display: none;
    position: fixed; inset: 0;
    background: rgba(0,0,0,.4);
    z-index: 90;
}

/* ========== Confirmation button ========== */
.btn-success { background: var(--success); color: #fff; border: none; }
.btn-success:hover { opacity: .85; }

/* ========== Responsive ========== */
@media (max-width: 768px) {
    .mobile-header {
        display: flex; align-items: center; gap: 12px;
        background: var(--primary); color: #fff;
        padding: 10px 16px; position: sticky; top: 0; z-index: 80;
    }
    .hamburger-btn {
        background: none; border: none; color: #fff;
        font-size: 1.5rem; cursor: pointer; padding: 0; line-height: 1;
    }
    .mobile-title { font-size: 1.1rem; font-weight: 600; }

    .sidebar { display: none; position: fixed; z-index: 100; top: 0; left: 0; bottom: 0; width: 260px; }
    .sidebar.sidebar-open { display: flex; flex-direction: column; }
    .sidebar-overlay { display: block; }

    .main-content { margin-left: 0; }
    .top-bar { display: none; }
    .content-area { padding: 16px; }
    .stats-grid { grid-template-columns: repeat(2, 1fr); }
    .filters-bar { flex-direction: column; }
    .filters-bar .form-group { min-width: 100%; }
}
