/* ========== Reset & Base ========== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
    --primary: #072c93;
    --primary-light: #072c93;
    --primary-dark: #072c93;
    --accent: #072c93;
    --accent-light: #5d9dcc;
    --success: #16a34a;
    --warning: #d97706;
    --danger: #dc2626;
    --info: #4f7fa8;
    --chart-blue-1: #072c93;
    --chart-blue-2: #072c93;
    --chart-blue-3: #072c93;
    --chart-blue-4: #5d9dcc;
    --chart-blue-5: #8bbfe0;
    --chart-blue-6: #c7dff0;
    --chart-neutral: #64748b;
    --bg: #f1f5f9;
    --surface: #ffffff;
    --text: #1e293b;
    --text-muted: #64748b;
    --border: #e2e8f0;
    --sidebar-width: 250px;
    --topbar-height: 52px;
    --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); }

/* ========== Top Bar ========== */
.topbar {
    position: fixed; top: 0; left: 0; right: 0; z-index: 200;
    height: var(--topbar-height);
    background: #072c93; color: #fff;
    display: flex; align-items: center; justify-content: space-between;
    padding: 0 20px;
    box-shadow: 0 1px 4px rgba(0,0,0,.15);
}
.topbar-left { display: flex; align-items: center; gap: 12px; }
.topbar-right { display: flex; align-items: center; gap: 16px; }
.topbar-brand { display: flex; align-items: center; gap: 10px; text-decoration: none; color: #fff; }
.topbar-logo { width: 30px; height: 30px; border-radius: 6px; }
.topbar-title { font-size: 1.05rem; font-weight: 700; letter-spacing: .3px; }
.sidebar-toggle {
    background: none; border: none; color: #fff; font-size: 1.25rem;
    cursor: pointer; padding: 4px 6px; border-radius: 4px; transition: background .15s;
    display: flex; align-items: center; justify-content: center;
    width: 34px; height: 34px;
}
.sidebar-toggle:hover { background: rgba(255,255,255,.15); }
.toggle-icon { line-height: 1; }

.topbar-user { display: flex; align-items: center; gap: 10px; }
.topbar-user-avatar {
    width: 32px; height: 32px; border-radius: 50%;
    background: rgba(255,255,255,.2); color: #fff;
    display: flex; align-items: center; justify-content: center;
    font-size: .72rem; font-weight: 700; letter-spacing: .5px;
    flex-shrink: 0;
}
.topbar-user-info { display: flex; flex-direction: column; line-height: 1.2; }
.topbar-user-info strong { font-size: .82rem; }
.topbar-user-info small { font-size: .68rem; opacity: .65; }
.topbar-action {
    color: rgba(255,255,255,.7); text-decoration: none; font-size: 1.1rem;
    padding: 4px; border-radius: 4px; transition: all .15s;
    filter: grayscale(1); display: flex; align-items: center;
}
.topbar-action:hover { color: #fff; background: rgba(255,255,255,.12); }

/* ========== Sidebar ========== */
.sidebar {
    position: fixed; top: var(--topbar-height); bottom: 0; left: 0; z-index: 100;
    width: var(--sidebar-width);
    background: #072c93; color: #fff;
    display: flex; flex-direction: column;
    transition: width .25s cubic-bezier(.4,0,.2,1), transform .25s cubic-bezier(.4,0,.2,1);
    overflow: hidden;
}
.sidebar.collapsed { width: 0; transform: translateX(calc(-1 * var(--sidebar-width))); }
.sidebar.expanded { width: var(--sidebar-width); transform: translateX(0); }

.sidebar-nav {
    list-style: none; padding: 8px 0; flex: 1; overflow-y: auto;
    scrollbar-width: thin; scrollbar-color: rgba(255,255,255,.15) transparent;
}
.sidebar-nav::-webkit-scrollbar { width: 4px; }
.sidebar-nav::-webkit-scrollbar-track { background: transparent; }
.sidebar-nav::-webkit-scrollbar-thumb { background: rgba(255,255,255,.15); border-radius: 4px; }

/* Nav group toggle (section headers) */
.nav-group { border-bottom: 1px solid rgba(255,255,255,.06); }
.nav-group-toggle {
    display: flex; align-items: center; justify-content: space-between;
    width: 100%; padding: 10px 18px; border: none; background: none; color: rgba(255,255,255,.5);
    font-size: .7rem; font-weight: 700; text-transform: uppercase; letter-spacing: 1.1px;
    cursor: pointer; transition: all .15s; user-select: none;
}
.nav-group-toggle:hover { color: rgba(255,255,255,.8); background: rgba(255,255,255,.04); }
.chevron { font-size: .6rem; transition: transform .2s ease; }
.chevron.open { transform: rotate(180deg); }

/* Nav group items */
.nav-group-items { list-style: none; padding: 0 0 4px; }
.nav-group-items li a {
    display: flex; align-items: center; gap: 10px; padding: 8px 18px 8px 24px;
    color: rgba(255,255,255,.75); text-decoration: none; font-size: .84rem; transition: all .15s;
    border-left: 3px solid transparent;
}
.nav-group-items li a:hover { background: rgba(255,255,255,.08); color: #fff; }
.nav-group-items li a.active {
    background: rgba(255,255,255,.12); color: #fff; font-weight: 600;
    border-left-color: var(--accent);
}
.nav-icon { font-size: .9rem; width: 18px; text-align: center; filter: grayscale(1); opacity: .6; flex-shrink: 0; }
.nav-label { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.sidebar-footer {
    padding: 12px 18px; border-top: 1px solid rgba(255,255,255,.1);
    color: rgba(255,255,255,.35); font-size: .72rem; text-align: center;
}

/* ========== Main Content ========== */
.main-content {
    margin-top: var(--topbar-height); flex: 1; display: flex; flex-direction: column;
    transition: margin-left .25s cubic-bezier(.4,0,.2,1);
    min-height: calc(100vh - var(--topbar-height));
}
.main-content.sidebar-is-expanded { margin-left: var(--sidebar-width); }
.main-content.sidebar-is-collapsed { margin-left: 0; }

.content-area { padding: 24px 32px; flex: 1; }

/* Overlay (mobile only) */
.sidebar-overlay {
    position: fixed; inset: 0; top: var(--topbar-height);
    background: rgba(0,0,0,.4); z-index: 90;
    display: none;
}

/* ========== 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: #072c93; }
.badge-inprogress { background: #fef3c7; color: #92400e; }
.badge-awaiting { background: #e0e7ff; color: #072c93; }
.badge-resolved { background: #dcfce7; color: #166534; }
.badge-closed { background: #f1f5f9; color: #475569; }

.badge-low { background: #f1f5f9; color: #475569; }
.badge-medium { background: #dbeafe; color: #072c93; }
.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;
}

/* ========== Messenger Chat UI ========== */
.chat-window {
    display: flex;
    flex-direction: column;
    gap: 14px;
    max-height: 560px;
    overflow-y: auto;
    padding: 8px 4px 4px;
}
.chat-row {
    display: flex;
    align-items: flex-end;
    gap: 10px;
}
.chat-row.agent {
    flex-direction: row-reverse;
}
.chat-avatar {
    width: 34px;
    height: 34px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    font-weight: 700;
    flex-shrink: 0;
    color: #fff;
    letter-spacing: .5px;
}
.chat-avatar.customer { background: var(--accent, #072c93); }
.chat-avatar.agent    { background: var(--primary, #072c93); }
.chat-bubble-wrap {
    display: flex;
    flex-direction: column;
    max-width: 65%;
}
.chat-row.agent .chat-bubble-wrap { align-items: flex-end; }
.chat-bubble {
    padding: 10px 14px;
    border-radius: 18px;
    font-size: .9rem;
    line-height: 1.55;
    word-break: break-word;
    box-shadow: 0 1px 3px rgba(0,0,0,.08);
}
.chat-bubble.customer {
    background: var(--bg, #f8fafc);
    border: 1px solid var(--border, #e2e8f0);
    border-bottom-left-radius: 4px;
    color: var(--text-primary);
}
.chat-bubble.agent {
    background: var(--primary, #072c93);
    color: #fff;
    border-bottom-right-radius: 4px;
}
.chat-body { white-space: pre-wrap; }
.chat-meta {
    font-size: .72rem;
    color: var(--text-muted);
    margin-top: 4px;
    padding: 0 4px;
}
.chat-attachments {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 8px;
    padding-top: 8px;
    border-top: 1px solid rgba(255,255,255,.15);
}
.chat-bubble.customer .chat-attachments {
    border-top-color: var(--border, #e2e8f0);
}
.chat-attachment-chip {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 3px 10px;
    border-radius: 12px;
    font-size: .78rem;
    text-decoration: none;
    background: rgba(255,255,255,.15);
    color: inherit;
    border: 1px solid rgba(255,255,255,.3);
    transition: background .15s;
}
.chat-attachment-chip:hover { background: rgba(255,255,255,.25); }
.chat-bubble.customer .chat-attachment-chip {
    background: var(--bg);
    border-color: var(--border);
    color: var(--text-primary);
}
.chat-bubble.customer .chat-attachment-chip:hover { background: var(--border); }

.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 & Skeleton System ========== */

/* Spinner */
.spinner {
    display: inline-block; width: 24px; height: 24px;
    border: 3px solid var(--border); border-top-color: var(--accent);
    border-radius: 50%; animation: spin .7s linear infinite;
    margin-right: 8px; vertical-align: middle;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Full-area loading state */
.loading {
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    gap: 16px; padding: 64px 24px; color: var(--text-muted);
    animation: fadeIn .3s ease;
}
.loading .spinner { width: 36px; height: 36px; border-width: 3.5px; margin: 0; }
.loading-text { font-size: .95rem; font-weight: 500; letter-spacing: .01em; }
.loading-subtext { font-size: .8rem; color: var(--text-muted); opacity: .7; margin-top: -8px; }

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

/* Skeleton shimmer base */
.skeleton {
    background: linear-gradient(90deg, var(--border) 25%, #e8edf2 37%, var(--border) 63%);
    background-size: 400% 100%;
    animation: shimmer 1.4s ease infinite;
    border-radius: var(--radius);
}
@keyframes shimmer { 0% { background-position: 100% 50%; } 100% { background-position: 0 50%; } }

/* Skeleton card grid (e.g. dashboard stats) */
.skeleton-cards {
    display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 16px; margin-bottom: 24px; animation: fadeIn .3s ease;
}
.skeleton-card {
    background: var(--surface); border-radius: var(--radius); padding: 24px;
    box-shadow: var(--shadow); display: flex; flex-direction: column; align-items: center; gap: 12px;
}
.skeleton-card .skeleton-number { width: 60px; height: 36px; }
.skeleton-card .skeleton-label { width: 90px; height: 14px; }

/* Skeleton table */
.skeleton-table { animation: fadeIn .3s ease; }
.skeleton-table-header {
    display: grid; grid-template-columns: 2fr 1fr 1fr 1fr 1fr; gap: 16px;
    padding: 14px 20px; border-bottom: 2px solid var(--border);
}
.skeleton-table-header .skeleton { height: 14px; border-radius: 4px; }
.skeleton-table-row {
    display: grid; grid-template-columns: 2fr 1fr 1fr 1fr 1fr; gap: 16px;
    padding: 16px 20px; border-bottom: 1px solid var(--border);
}
.skeleton-table-row .skeleton { height: 16px; border-radius: 4px; }
.skeleton-table-row:nth-child(odd) .skeleton { opacity: .85; }

/* Skeleton content block */
.skeleton-block { animation: fadeIn .3s ease; }
.skeleton-line { height: 14px; margin-bottom: 12px; border-radius: 4px; }
.skeleton-line.w-full { width: 100%; }
.skeleton-line.w-3\/4 { width: 75%; }
.skeleton-line.w-1\/2 { width: 50%; }
.skeleton-line.w-1\/3 { width: 33%; }
.skeleton-line.w-1\/4 { width: 25%; }
.skeleton-line.h-lg { height: 24px; margin-bottom: 16px; }
.skeleton-line.h-xl { height: 32px; margin-bottom: 20px; }

/* Skeleton section with card wrapper */
.skeleton-section {
    background: var(--surface); border-radius: var(--radius);
    padding: 24px; box-shadow: var(--shadow); margin-bottom: 24px;
    animation: fadeIn .3s ease;
}

/* Pulse variant for inline action indicators */
.skeleton-pulse { animation: pulse 1.5s ease-in-out infinite; }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: .4; } }

/* Inline loading badge */
.loading-badge {
    display: inline-flex; align-items: center; gap: 6px;
    padding: 4px 12px; border-radius: 16px;
    background: rgba(14, 165, 233, .08); color: var(--accent);
    font-size: .8rem; font-weight: 500;
}
.loading-badge .spinner { width: 14px; height: 14px; border-width: 2px; margin: 0; }

/* ========== Confirmation button ========== */
.btn-success { background: var(--success); color: #fff; border: none; }
.btn-success:hover { opacity: .85; }

/* ========== Responsive ========== */
@media (max-width: 768px) {
    .topbar-user-info { display: none; }
    .topbar-title { font-size: .9rem; }

    .sidebar.collapsed { transform: translateX(calc(-1 * var(--sidebar-width))); width: var(--sidebar-width); }
    .sidebar.expanded { transform: translateX(0); width: var(--sidebar-width); }
    .sidebar-overlay.mobile-only { display: block; }

    .main-content.sidebar-is-expanded,
    .main-content.sidebar-is-collapsed { margin-left: 0; }

    .content-area { padding: 16px; }
    .stats-grid { grid-template-columns: repeat(2, 1fr); }
    .filters-bar { flex-direction: column; }
    .filters-bar .form-group { min-width: 100%; }
}
