/* =====================================================================
   IT Helpdesk - Main Stylesheet
   Modern, responsive, Thai-first
   ===================================================================== */

/* ---- Design tokens ---- */
:root {
    /* Brand palette */
    --c-primary:        #2563eb;
    --c-primary-dark:   #1d4ed8;
    --c-primary-light:  #dbeafe;
    --c-primary-50:     #eff6ff;
    --c-accent:         #0ea5e9;

    --c-success:        #16a34a;
    --c-success-light:  #dcfce7;
    --c-warning:        #d97706;
    --c-warning-light:  #fef3c7;
    --c-danger:         #dc2626;
    --c-danger-light:   #fee2e2;
    --c-info:           #0891b2;

    /* Neutrals (slate-based) */
    --c-bg:             #f1f5f9;
    --c-surface:        #ffffff;
    --c-sidebar:        #0f172a;
    --c-sidebar-2:      #1e293b;
    --c-border:         #e2e8f0;
    --c-text:           #1e293b;
    --c-text-muted:     #64748b;
    --c-text-light:     #94a3b8;

    /* Spacing & radius */
    --r-sm: 6px;
    --r-md: 10px;
    --r-lg: 16px;
    --r-pill: 9999px;
    --sh-sm: 0 1px 2px rgba(15,23,42,.06);
    --sh-md: 0 4px 12px rgba(15,23,42,.08);
    --sh-lg: 0 10px 30px rgba(15,23,42,.12);

    --sidebar-w: 250px;
    --header-h: 62px;
    --font: 'Sarabun', 'Segoe UI', system-ui, -apple-system, sans-serif;
}

/* ---- Reset ---- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { -webkit-text-size-adjust: 100%; }
body {
    font-family: var(--font);
    font-size: 15px;
    line-height: 1.55;
    color: var(--c-text);
    background: var(--c-bg);
    -webkit-font-smoothing: antialiased;
}
a { color: var(--c-primary); text-decoration: none; }
a:hover { color: var(--c-primary-dark); text-decoration: underline; }
img { max-width: 100%; }
button, input, select, textarea { font-family: inherit; font-size: inherit; }

/* ---- Typography ---- */
h1,h2,h3,h4 { font-weight: 700; line-height: 1.3; color: var(--c-text); }
h1 { font-size: 1.6rem; }
h2 { font-size: 1.3rem; }
h3 { font-size: 1.1rem; }
.text-muted { color: var(--c-text-muted); }
.text-danger { color: var(--c-danger); }
.text-success { color: var(--c-success); }
.text-center { text-align: center; }
.small { font-size: .85rem; }

/* =====================================================================
   Layout
   ===================================================================== */
.app-wrap { display: flex; min-height: 100vh; }

/* ---- Sidebar ---- */
.sidebar {
    width: var(--sidebar-w);
    background: var(--c-sidebar);
    color: #cbd5e1;
    position: fixed;
    inset: 0 auto 0 0;
    z-index: 50;
    display: flex;
    flex-direction: column;
    transition: transform .25s ease;
}
.sidebar-brand {
    padding: 18px 20px;
    display: flex;
    align-items: center;
    gap: 12px;
    color: #fff;
    border-bottom: 1px solid rgba(255,255,255,.07);
}
.sidebar-brand .logo {
    width: 38px; height: 38px;
    background: linear-gradient(135deg, var(--c-primary), var(--c-accent));
    border-radius: var(--r-md);
    display: grid; place-items: center;
    color: #fff; font-weight: 700; font-size: 1.1rem;
    box-shadow: 0 4px 12px rgba(37,99,235,.4);
    flex-shrink: 0;
}
.sidebar-brand .brand-text { font-weight: 700; font-size: 1.05rem; line-height: 1.1; }
.sidebar-brand .brand-text small { display: block; font-weight: 400; font-size: .72rem; color: var(--c-text-light); }

.sidebar-nav {
    flex: 1; overflow-y: auto; padding: 12px 10px;
}
.sidebar-nav::-webkit-scrollbar { width: 5px; }
.sidebar-nav::-webkit-scrollbar-thumb { background: #334155; border-radius: 5px; }
.nav-section {
    font-size: .7rem;
    text-transform: uppercase;
    letter-spacing: .08em;
    color: #64748b;
    padding: 14px 12px 6px;
    font-weight: 600;
}
.nav-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 12px;
    border-radius: var(--r-md);
    color: #cbd5e1;
    text-decoration: none;
    font-size: .93rem;
    margin-bottom: 2px;
    transition: background .15s, color .15s;
}
.nav-item i { width: 18px; text-align: center; font-size: .95rem; }
.nav-item:hover { background: rgba(255,255,255,.06); color: #fff; text-decoration: none; }
.nav-item.active {
    background: linear-gradient(90deg, rgba(37,99,235,.25), rgba(14,165,233,.1));
    color: #fff;
    box-shadow: inset 3px 0 0 var(--c-primary);
}
.nav-item .nav-badge {
    margin-left: auto;
    background: var(--c-danger);
    color: #fff;
    font-size: .7rem;
    padding: 1px 7px;
    border-radius: var(--r-pill);
    font-weight: 600;
}

/* ---- Main content ---- */
.main {
    flex: 1;
    margin-left: var(--sidebar-w);
    display: flex;
    flex-direction: column;
    min-width: 0;
}

/* ---- Top header ---- */
.topbar {
    height: var(--header-h);
    background: var(--c-surface);
    border-bottom: 1px solid var(--c-border);
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 0 20px;
    position: sticky; top: 0; z-index: 30;
}
.topbar .menu-toggle { display: none; }
.topbar .page-title { font-size: 1.15rem; font-weight: 700; margin-right: auto; }
.topbar-search {
    position: relative;
    width: 280px; max-width: 35vw;
}
.topbar-search input {
    width: 100%; padding: 8px 36px 8px 12px;
    border: 1px solid var(--c-border);
    border-radius: var(--r-pill);
    background: var(--c-bg);
    transition: .15s;
}
.topbar-search input:focus {
    outline: none; border-color: var(--c-primary);
    background: #fff; box-shadow: 0 0 0 3px var(--c-primary-light);
}
.topbar-search i {
    position: absolute; right: 13px; top: 50%; transform: translateY(-50%);
    color: var(--c-text-light);
    pointer-events: none;
}
.topbar-actions { display: flex; align-items: center; gap: 8px; }
.icon-btn {
    width: 40px; height: 40px;
    display: grid; place-items: center;
    border: none; background: transparent;
    color: var(--c-text-muted);
    border-radius: var(--r-md);
    position: relative;
    cursor: pointer;
    transition: .15s;
}
.icon-btn:hover { background: var(--c-bg); color: var(--c-text); }
.icon-btn .dot {
    position: absolute; top: 8px; right: 9px;
    width: 8px; height: 8px; background: var(--c-danger);
    border: 2px solid var(--c-surface);
    border-radius: 50%;
}

/* user dropdown */
.user-menu { position: relative; }
.user-avatar-btn {
    display: flex; align-items: center; gap: 10px;
    padding: 4px 8px 4px 4px; border-radius: var(--r-pill);
    cursor: pointer; border: none; background: transparent;
    transition: .15s;
}
.user-avatar-btn:hover { background: var(--c-bg); }
.avatar {
    width: 36px; height: 36px; border-radius: 50%;
    background: linear-gradient(135deg, var(--c-primary), var(--c-accent));
    color: #fff; display: grid; place-items: center;
    font-weight: 700; font-size: .9rem; flex-shrink: 0;
    overflow: hidden;
}
.avatar img { width: 100%; height: 100%; object-fit: cover; }
.user-menu .uname { font-size: .88rem; font-weight: 600; }
.user-menu .urole { font-size: .72rem; color: var(--c-text-muted); }
.dropdown-menu {
    position: absolute; right: 0; top: calc(100% + 8px);
    min-width: 220px;
    background: var(--c-surface);
    border: 1px solid var(--c-border);
    border-radius: var(--r-md);
    box-shadow: var(--sh-lg);
    padding: 6px;
    display: none;
    z-index: 60;
}
.dropdown-menu.show { display: block; }
.dropdown-menu a, .dropdown-menu button {
    display: flex; align-items: center; gap: 10px;
    width: 100%; text-align: left;
    padding: 9px 12px; border: none; background: transparent;
    color: var(--c-text); border-radius: var(--r-sm);
    font-size: .9rem; cursor: pointer; text-decoration: none;
}
.dropdown-menu a:hover, .dropdown-menu button:hover {
    background: var(--c-bg); color: var(--c-text); text-decoration: none;
}
.dropdown-menu .divider { height: 1px; background: var(--c-border); margin: 4px 0; }
.dropdown-menu .text-danger { color: var(--c-danger); }

/* ---- Page content ---- */
.page { padding: 24px; flex: 1; }
.page-head {
    display: flex; align-items: center; gap: 16px; flex-wrap: wrap;
    margin-bottom: 22px;
}
.page-head h1 { margin: 0; }
.page-head .subtitle { color: var(--c-text-muted); font-size: .9rem; margin-top: 2px; }
.page-head .actions { margin-left: auto; display: flex; gap: 8px; flex-wrap: wrap; }

/* =====================================================================
   Cards & containers
   ===================================================================== */
.card {
    background: var(--c-surface);
    border: 1px solid var(--c-border);
    border-radius: var(--r-lg);
    box-shadow: var(--sh-sm);
    margin-bottom: 20px;
}
.card-header {
    padding: 16px 20px;
    border-bottom: 1px solid var(--c-border);
    display: flex; align-items: center; gap: 12px;
}
.card-header h2, .card-header h3 { margin: 0; font-size: 1.05rem; }
.card-header .actions { margin-left: auto; }
.card-body { padding: 20px; }
.card-body.no-pad { padding: 0; }
.card-footer { padding: 14px 20px; border-top: 1px solid var(--c-border); background: #fafbfc; border-radius: 0 0 var(--r-lg) var(--r-lg); }

/* ---- Stat cards ---- */
.stat-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 16px;
    margin-bottom: 24px;
}
.stat-card {
    background: var(--c-surface);
    border: 1px solid var(--c-border);
    border-radius: var(--r-lg);
    padding: 18px 20px;
    box-shadow: var(--sh-sm);
    display: flex; align-items: center; gap: 16px;
    transition: transform .15s, box-shadow .15s;
}
.stat-card:hover { transform: translateY(-2px); box-shadow: var(--sh-md); }
.stat-card .stat-ic {
    width: 52px; height: 52px; border-radius: var(--r-md);
    display: grid; place-items: center;
    font-size: 1.3rem; color: #fff; flex-shrink: 0;
}
.stat-card .stat-ic.blue   { background: linear-gradient(135deg,#3b82f6,#2563eb); }
.stat-card .stat-ic.amber  { background: linear-gradient(135deg,#f59e0b,#d97706); }
.stat-card .stat-ic.green  { background: linear-gradient(135deg,#22c55e,#16a34a); }
.stat-card .stat-ic.red    { background: linear-gradient(135deg,#ef4444,#dc2626); }
.stat-card .stat-ic.purple { background: linear-gradient(135deg,#a855f7,#7c3aed); }
.stat-card .stat-ic.cyan   { background: linear-gradient(135deg,#06b6d4,#0891b2); }
.stat-card .stat-val { font-size: 1.7rem; font-weight: 700; line-height: 1; }
.stat-card .stat-lbl { color: var(--c-text-muted); font-size: .85rem; margin-top: 4px; }

/* =====================================================================
   Buttons
   ===================================================================== */
.btn {
    display: inline-flex; align-items: center; gap: 8px;
    padding: 9px 16px;
    border: 1px solid transparent;
    border-radius: var(--r-md);
    background: var(--c-primary);
    color: #fff;
    font-size: .9rem; font-weight: 600;
    cursor: pointer;
    transition: .15s;
    text-decoration: none;
    line-height: 1.3;
    white-space: nowrap;
}
.btn:hover { background: var(--c-primary-dark); color: #fff; text-decoration: none; transform: translateY(-1px); }
.btn:active { transform: translateY(0); }
.btn i { font-size: .9rem; }
.btn-secondary { background: var(--c-surface); color: var(--c-text); border-color: var(--c-border); }
.btn-secondary:hover { background: var(--c-bg); color: var(--c-text); border-color: #cbd5e1; }
.btn-success { background: var(--c-success); }
.btn-success:hover { background: #15803d; }
.btn-danger  { background: var(--c-danger); }
.btn-danger:hover  { background: #b91c1c; }
.btn-warning { background: var(--c-warning); }
.btn-warning:hover { background: #b45309; }
.btn-outline {
    background: transparent; color: var(--c-primary); border-color: var(--c-primary);
}
.btn-outline:hover { background: var(--c-primary); color: #fff; }
.btn-ghost { background: transparent; color: var(--c-text-muted); border-color: transparent; }
.btn-ghost:hover { background: var(--c-bg); color: var(--c-text); }
.btn-sm { padding: 6px 11px; font-size: .82rem; }
.btn-lg { padding: 12px 22px; font-size: 1rem; }
.btn-block { width: 100%; justify-content: center; }
.btn-icon { padding: 9px 11px; }

/* =====================================================================
   Forms
   ===================================================================== */
.form-group { margin-bottom: 18px; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
label, .form-label {
    display: block; margin-bottom: 6px;
    font-weight: 600; font-size: .88rem; color: var(--c-text);
}
.form-label .req { color: var(--c-danger); }
.form-control, input[type=text], input[type=email], input[type=password],
input[type=tel], input[type=date], input[type=datetime-local], input[type=number],
input[type=search], select, textarea {
    width: 100%;
    padding: 10px 13px;
    border: 1px solid var(--c-border);
    border-radius: var(--r-md);
    background: var(--c-surface);
    color: var(--c-text);
    transition: .15s;
}
.form-control:focus, input:focus, select:focus, textarea:focus {
    outline: none; border-color: var(--c-primary);
    box-shadow: 0 0 0 3px var(--c-primary-light);
}
textarea { resize: vertical; min-height: 100px; }
select { appearance: none; background-image: url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 12' width='12'%3E%3Cpath fill='%2364748b' d='M6 8L1 3h10z'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 12px center; padding-right: 32px; }
.form-hint { font-size: .8rem; color: var(--c-text-muted); margin-top: 5px; }
.form-error { font-size: .82rem; color: var(--c-danger); margin-top: 5px; }
.has-error input, .has-error select, .has-error textarea { border-color: var(--c-danger); }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 16px; }
.input-group { display: flex; }
.input-group .form-control { border-radius: 0; }
.input-group .form-control:first-child { border-top-left-radius: var(--r-md); border-bottom-left-radius: var(--r-md); }
.input-group-prepend {
    padding: 0 14px; display: grid; place-items: center;
    background: var(--c-bg); border: 1px solid var(--c-border);
    border-radius: var(--r-md) 0 0 var(--r-md); color: var(--c-text-muted);
}
.input-group .input-group-prepend + .form-control { border-radius: 0 var(--r-md) var(--r-md) 0; }
.checkbox-row { display: flex; align-items: center; gap: 8px; }
.checkbox-row input[type=checkbox] { width: 18px; height: 18px; cursor: pointer; }

/* =====================================================================
   Tables
   ===================================================================== */
.table-wrap { overflow-x: auto; }
table.data-table {
    width: 100%; border-collapse: collapse; font-size: .9rem;
}
.data-table th, .data-table td {
    padding: 12px 16px; text-align: left;
    border-bottom: 1px solid var(--c-border);
}
.data-table th {
    background: #f8fafc; font-weight: 600; font-size: .82rem;
    color: var(--c-text-muted); text-transform: uppercase;
    letter-spacing: .03em; white-space: nowrap;
}
.data-table tbody tr:hover { background: #f8fafc; }
.data-table tbody tr:last-child td { border-bottom: none; }
.data-table .td-link { font-weight: 600; color: var(--c-text); }
.data-table .td-link:hover { color: var(--c-primary); }

/* =====================================================================
   Badges & pills
   ===================================================================== */
.badge {
    display: inline-flex; align-items: center; gap: 5px;
    padding: 3px 10px; border-radius: var(--r-pill);
    font-size: .76rem; font-weight: 600;
    background: var(--c-bg); color: var(--c-text-muted);
}
.badge i { font-size: .72rem; }
.badge-open        { background: #dbeafe; color: #1e40af; }
.badge-progress    { background: #fef3c7; color: #92400e; }
.badge-waiting     { background: #fce7f3; color: #9d174d; }
.badge-resolved    { background: #dcfce7; color: #166534; }
.badge-closed      { background: #e0e7ff; color: #3730a3; }
.badge-cancelled   { background: #fee2e2; color: #991b1b; }
.badge-default     { background: #f1f5f9; color: #475569; }

.prio-low     { background: #e0f2fe; color: #075985; }
.prio-medium  { background: #fef3c7; color: #92400e; }
.prio-high    { background: #ffedd5; color: #9a3412; }
.prio-urgent  { background: #fee2e2; color: #991b1b; }

.dot-prio { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }
.dot-prio.low { background: #38bdf8; }
.dot-prio.medium { background: #f59e0b; }
.dot-prio.high { background: #f97316; }
.dot-prio.urgent { background: #ef4444; }

/* =====================================================================
   Ticket list styles
   ===================================================================== */
.ticket-list { display: flex; flex-direction: column; }
.ticket-row {
    display: flex; align-items: center; gap: 14px;
    padding: 14px 20px;
    border-bottom: 1px solid var(--c-border);
    transition: background .15s;
    text-decoration: none; color: inherit;
}
.ticket-row:last-child { border-bottom: none; }
.ticket-row:hover { background: #f8fafc; text-decoration: none; color: inherit; }
.ticket-row .t-icon {
    width: 40px; height: 40px; border-radius: var(--r-md);
    background: var(--c-primary-50); color: var(--c-primary);
    display: grid; place-items: center; flex-shrink: 0;
}
.ticket-row .t-main { flex: 1; min-width: 0; }
.ticket-row .t-title {
    font-weight: 600; font-size: .95rem; color: var(--c-text);
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.ticket-row .t-meta { font-size: .8rem; color: var(--c-text-muted); margin-top: 2px; display: flex; gap: 12px; flex-wrap: wrap; }
.ticket-row .t-no { font-family: monospace; font-size: .8rem; }
.ticket-row .t-end { text-align: right; flex-shrink: 0; }
.ticket-row .t-assignee { display: flex; align-items: center; gap: 6px; font-size: .82rem; color: var(--c-text-muted); }

/* =====================================================================
   Ticket detail
   ===================================================================== */
.ticket-head {
    display: flex; gap: 16px; align-items: flex-start;
    margin-bottom: 24px; flex-wrap: wrap;
}
.ticket-head .ticket-no { font-family: monospace; color: var(--c-text-muted); font-size: .9rem; }
.ticket-head h1 { margin: 4px 0; }
.ticket-head .head-actions { margin-left: auto; display: flex; gap: 8px; flex-wrap: wrap; }

.ticket-grid { display: grid; grid-template-columns: 1fr 320px; gap: 20px; align-items: start; }

.detail-section { margin-bottom: 0; }
.meta-list { list-style: none; }
.meta-list li {
    display: flex; justify-content: space-between; gap: 12px;
    padding: 10px 0; border-bottom: 1px solid var(--c-border);
    font-size: .9rem;
}
.meta-list li:last-child { border-bottom: none; }
.meta-list .ml-label { color: var(--c-text-muted); font-size: .82rem; }
.meta-list .ml-val { font-weight: 600; text-align: right; }

/* timeline / comments */
.timeline { position: relative; padding-left: 28px; }
.timeline::before {
    content: ''; position: absolute; left: 13px; top: 6px; bottom: 6px;
    width: 2px; background: var(--c-border);
}
.timeline-item { position: relative; margin-bottom: 24px; }
.timeline-item::before {
    content: ''; position: absolute; left: -22px; top: 4px;
    width: 14px; height: 14px; border-radius: 50%;
    background: var(--c-surface); border: 3px solid var(--c-primary);
}
.timeline-item.system::before { border-color: var(--c-text-light); }
.timeline-item .ti-head { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; flex-wrap: wrap; }
.timeline-item .ti-author { font-weight: 600; }
.timeline-item .ti-time { color: var(--c-text-muted); font-size: .8rem; }
.timeline-item .ti-body {
    background: var(--c-bg); border-radius: var(--r-md);
    padding: 12px 14px; font-size: .9rem; line-height: 1.55;
    white-space: pre-wrap; word-wrap: break-word;
}
.timeline-item.internal .ti-body { background: #fffbeb; border-left: 3px solid var(--c-warning); }
.timeline-item .ti-attachments { margin-top: 10px; display: flex; flex-wrap: wrap; gap: 8px; }

.attach-chip {
    display: inline-flex; align-items: center; gap: 8px;
    padding: 6px 11px; background: var(--c-surface);
    border: 1px solid var(--c-border); border-radius: var(--r-pill);
    font-size: .82rem; text-decoration: none; color: var(--c-text);
}
.attach-chip:hover { background: var(--c-bg); text-decoration: none; color: var(--c-primary); border-color: var(--c-primary); }
.attach-chip i { color: var(--c-text-muted); }
.attach-thumb {
    display: inline-block; border-radius: var(--r-md); overflow: hidden;
    border: 1px solid var(--c-border); cursor: pointer;
    transition: .15s;
}
.attach-thumb:hover { border-color: var(--c-primary); box-shadow: var(--sh-md); }
.attach-thumb img { width: 110px; height: 110px; object-fit: cover; display: block; }

/* =====================================================================
   Alerts / flash messages
   ===================================================================== */
.alert {
    padding: 13px 16px; border-radius: var(--r-md);
    margin-bottom: 18px; display: flex; align-items: flex-start; gap: 12px;
    font-size: .9rem; border: 1px solid transparent;
}
.alert i { margin-top: 2px; }
.alert-success { background: var(--c-success-light); color: #14532d; border-color: #bbf7d0; }
.alert-danger  { background: var(--c-danger-light);  color: #7f1d1d; border-color: #fecaca; }
.alert-warning { background: var(--c-warning-light); color: #78350f; border-color: #fde68a; }
.alert-info    { background: #dbeafe; color: #1e3a8a; border-color: #bfdbfe; }

/* =====================================================================
   Filters bar
   ===================================================================== */
.filter-bar {
    display: flex; gap: 10px; flex-wrap: wrap; align-items: flex-end;
    margin-bottom: 18px;
}
.filter-bar .fg { display: flex; flex-direction: column; gap: 4px; }
.filter-bar .fg label { font-size: .76rem; color: var(--c-text-muted); margin: 0; font-weight: 600; }
.filter-bar select, .filter-bar input { min-width: 140px; padding: 8px 11px; font-size: .85rem; }

/* tabs */
.tabs {
    display: flex; gap: 4px; border-bottom: 2px solid var(--c-border);
    margin-bottom: 20px; overflow-x: auto;
}
.tab {
    padding: 10px 18px; cursor: pointer;
    border: none; background: transparent;
    color: var(--c-text-muted); font-weight: 600; font-size: .9rem;
    border-bottom: 2px solid transparent; margin-bottom: -2px;
    white-space: nowrap;
    transition: .15s;
}
.tab:hover { color: var(--c-text); }
.tab.active { color: var(--c-primary); border-bottom-color: var(--c-primary); }
.tab .count { background: var(--c-bg); padding: 1px 7px; border-radius: var(--r-pill); font-size: .72rem; margin-left: 6px; }
.tab.active .count { background: var(--c-primary-light); color: var(--c-primary-dark); }

/* pagination */
.pagination { display: flex; gap: 4px; justify-content: center; margin-top: 20px; flex-wrap: wrap; }
.pagination a, .pagination span {
    padding: 7px 13px; border: 1px solid var(--c-border);
    border-radius: var(--r-sm); font-size: .88rem;
    background: var(--c-surface); color: var(--c-text);
    text-decoration: none;
}
.pagination a:hover { background: var(--c-bg); text-decoration: none; }
.pagination .active { background: var(--c-primary); color: #fff; border-color: var(--c-primary); }
.pagination .disabled { color: var(--c-text-light); background: var(--c-bg); }

/* =====================================================================
   Empty state
   ===================================================================== */
.empty-state {
    text-align: center; padding: 50px 20px; color: var(--c-text-muted);
}
.empty-state i { font-size: 3rem; color: var(--c-text-light); margin-bottom: 12px; }
.empty-state h3 { color: var(--c-text); margin-bottom: 6px; }

/* =====================================================================
   Login page
   ===================================================================== */
.auth-wrap {
    min-height: 100vh; display: grid;
    grid-template-columns: 1fr 1fr;
}
.auth-aside {
    background: linear-gradient(135deg, #0f172a 0%, #1e3a8a 60%, #2563eb 100%);
    color: #fff; padding: 50px;
    display: flex; flex-direction: column; justify-content: center;
    position: relative; overflow: hidden;
}
.auth-aside::after {
    content: ''; position: absolute;
    width: 400px; height: 400px; border-radius: 50%;
    background: radial-gradient(circle, rgba(14,165,233,.35), transparent 70%);
    top: -100px; right: -100px;
}
.auth-aside::before {
    content: ''; position: absolute;
    width: 300px; height: 300px; border-radius: 50%;
    background: radial-gradient(circle, rgba(168,85,247,.25), transparent 70%);
    bottom: -80px; left: -80px;
}
.auth-aside .inner { position: relative; z-index: 2; max-width: 480px; }
.auth-aside h2 { color: #fff; font-size: 2rem; margin: 24px 0 14px; line-height: 1.25; }
.auth-aside p { color: rgba(255,255,255,.85); font-size: 1rem; line-height: 1.7; }
.auth-aside .feature-list { list-style: none; margin-top: 28px; }
.auth-aside .feature-list li { display: flex; align-items: center; gap: 12px; padding: 8px 0; color: rgba(255,255,255,.92); }
.auth-aside .feature-list i { color: #7dd3fc; font-size: 1.1rem; }

.auth-main {
    display: grid; place-items: center; padding: 30px;
    background: var(--c-bg);
}
.auth-card { width: 100%; max-width: 410px; }
.auth-card .auth-logo {
    width: 56px; height: 56px; border-radius: var(--r-lg);
    background: linear-gradient(135deg, var(--c-primary), var(--c-accent));
    display: grid; place-items: center; color: #fff;
    font-size: 1.5rem; font-weight: 700;
    box-shadow: 0 8px 20px rgba(37,99,235,.4);
    margin-bottom: 20px;
}
.auth-card h1 { font-size: 1.6rem; margin-bottom: 6px; }
.auth-card .auth-sub { color: var(--c-text-muted); margin-bottom: 28px; }

/* camera modal */
.camera-modal {
    position: fixed; inset: 0; z-index: 100;
    background: rgba(15,23,42,.85);
    display: none; flex-direction: column;
}
.camera-modal.show { display: flex; }
.camera-modal video { flex: 1; width: 100%; object-fit: cover; background: #000; }
.camera-modal canvas { display: none; }
.camera-modal .cam-bar {
    display: flex; justify-content: center; gap: 16px;
    padding: 20px; background: #0f172a;
}
.camera-modal .cam-btn {
    width: 64px; height: 64px; border-radius: 50%;
    border: 4px solid #fff; background: rgba(255,255,255,.15);
    color: #fff; font-size: 1.4rem; cursor: pointer;
    display: grid; place-items: center;
    transition: .15s;
}
.camera-modal .cam-btn:hover { background: rgba(255,255,255,.3); }
.camera-modal .cam-btn.close { background: var(--c-danger); border-color: var(--c-danger); }
.camera-modal .preview { flex: 1; display: none; background: #000; }
.camera-modal .preview img { width: 100%; height: 100%; object-fit: contain; }
.camera-modal.has-preview video { display: none; }
.camera-modal.has-preview .preview { display: block; }
.camera-modal.has-preview canvas { display: block; }

/* dropzone */
.dropzone {
    border: 2px dashed var(--c-border);
    border-radius: var(--r-md);
    padding: 24px; text-align: center;
    color: var(--c-text-muted); cursor: pointer;
    transition: .15s; background: #fafbfc;
}
.dropzone:hover, .dropzone.dragover { border-color: var(--c-primary); background: var(--c-primary-50); color: var(--c-primary); }
.dropzone i { font-size: 2rem; margin-bottom: 8px; }
.dropzone .dz-hint { font-size: .82rem; margin-top: 4px; }
.file-preview-list { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.file-preview {
    position: relative; width: 90px; height: 90px;
    border-radius: var(--r-md); overflow: hidden;
    border: 1px solid var(--c-border);
}
.file-preview img { width: 100%; height: 100%; object-fit: cover; }
.file-preview .fp-doc { width: 100%; height: 100%; display: grid; place-items: center; background: var(--c-bg); color: var(--c-text-muted); font-size: 1.5rem; }
.file-preview .fp-remove {
    position: absolute; top: 3px; right: 3px;
    width: 22px; height: 22px; border-radius: 50%;
    background: rgba(0,0,0,.65); color: #fff;
    border: none; cursor: pointer; font-size: .7rem;
    display: grid; place-items: center;
}

/* progress / resolution bar */
.progress-bar { height: 8px; background: var(--c-bg); border-radius: var(--r-pill); overflow: hidden; }
.progress-bar .fill { height: 100%; background: linear-gradient(90deg, var(--c-primary), var(--c-accent)); }

/* rating stars */
.stars { display: inline-flex; gap: 2px; }
.stars .star { color: #cbd5e1; font-size: 1.1rem; cursor: pointer; }
.stars .star.active { color: #f59e0b; }
.stars.readonly .star { cursor: default; }

/* utilities */
.flex { display: flex; }
.flex-1 { flex: 1; }
.gap-2 { gap: 8px; }
.gap-3 { gap: 12px; }
.gap-4 { gap: 16px; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.flex-wrap { flex-wrap: wrap; }
.mt-1 { margin-top: 4px;} .mt-2 { margin-top: 8px;} .mt-3 { margin-top: 12px;} .mt-4 { margin-top: 16px;} .mt-6 { margin-top: 24px;}
.mb-0 { margin-bottom: 0; } .mb-2 { margin-bottom: 8px;} .mb-3 { margin-bottom: 12px;}
.ml-auto { margin-left: auto; }
.text-right { text-align: right; }
.text-sm { font-size: .85rem; }
.hidden { display: none !important; }
.mono { font-family: 'Fira Code', monospace; }
.rounded { border-radius: var(--r-md); }
.cursor-pointer { cursor: pointer; }
.divider { height: 1px; background: var(--c-border); margin: 16px 0; }
.kpi-trend { font-size: .78rem; display: inline-flex; align-items: center; gap: 3px; }
.kpi-trend.up { color: var(--c-success); }
.kpi-trend.down { color: var(--c-danger); }

/* loading spinner */
.spinner {
    width: 18px; height: 18px;
    border: 2px solid rgba(255,255,255,.35);
    border-top-color: #fff;
    border-radius: 50%;
    animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* =====================================================================
   Responsive
   ===================================================================== */
@media (max-width: 1100px) {
    .ticket-grid { grid-template-columns: 1fr; }
}
@media (max-width: 900px) {
    :root { --sidebar-w: 240px; }
    .sidebar { transform: translateX(-100%); }
    .sidebar.open { transform: translateX(0); box-shadow: 0 0 50px rgba(0,0,0,.4); }
    .main { margin-left: 0; }
    .topbar .menu-toggle {
        display: grid; place-items: center;
        width: 40px; height: 40px; border: none;
        background: transparent; cursor: pointer; font-size: 1.1rem;
        color: var(--c-text);
    }
    .sidebar-backdrop {
        position: fixed; inset: 0; background: rgba(15,23,42,.5);
        z-index: 40; display: none;
    }
    .sidebar-backdrop.show { display: block; }
    .form-row, .form-grid { grid-template-columns: 1fr; }
    .auth-wrap { grid-template-columns: 1fr; }
    .auth-aside { display: none; }
}
@media (max-width: 640px) {
    .page { padding: 16px; }
    .topbar { padding: 0 14px; gap: 8px; }
    .topbar-search { display: none; }
    .page-head { flex-direction: column; align-items: stretch; }
    .page-head .actions { margin-left: 0; }
    .ticket-head .head-actions { margin-left: 0; }
    .ticket-row { flex-wrap: wrap; }
    .ticket-row .t-end { width: 100%; text-align: left; }
    .stat-grid { grid-template-columns: 1fr 1fr; }
    h1 { font-size: 1.35rem; }
}

/* print */
@media print {
    .sidebar, .topbar, .head-actions, .actions { display: none !important; }
    .main { margin: 0; }
    .card { box-shadow: none; border: 1px solid #ccc; }
}

/* =====================================================================
   KB Article body (เนื้อหาบทความจาก WYSIWYG)
   ===================================================================== */
.kb-body { overflow-wrap: break-word; word-wrap: break-word; }
.kb-body > *:first-child { margin-top: 0; }
.kb-body > *:last-child { margin-bottom: 0; }
.kb-body p { margin: 0 0 1.1em; }
.kb-body h1 { font-size: 1.7rem; margin: 1.4em 0 .7em; }
.kb-body h2 { font-size: 1.4rem; margin: 1.3em 0 .6em; padding-bottom: .3em; border-bottom: 1px solid var(--c-border); }
.kb-body h3 { font-size: 1.2rem; margin: 1.2em 0 .5em; }
.kb-body h4 { font-size: 1.05rem; margin: 1em 0 .4em; }
.kb-body ul, .kb-body ol { margin: 0 0 1.1em; padding-left: 1.6em; }
.kb-body li { margin-bottom: .35em; }
.kb-body img {
    max-width: 100%; height: auto; border-radius: var(--r-md);
    margin: 1.1em 0; box-shadow: var(--sh-sm);
}
.kb-body a { color: var(--c-primary); text-decoration: underline; text-underline-offset: 2px; }
.kb-body a:hover { color: var(--c-primary-dark); }
.kb-body blockquote {
    border-left: 4px solid var(--c-primary);
    padding: 8px 18px; margin: 1.2em 0;
    background: var(--c-primary-50); color: var(--c-text-muted);
    border-radius: 0 var(--r-md) var(--r-md) 0;
    font-style: italic;
}
.kb-body code {
    background: var(--c-bg); padding: 2px 7px; border-radius: var(--r-sm);
    font-family: 'Fira Code', 'Consolas', monospace; font-size: .9em; color: #be123c;
}
.kb-body pre {
    background: #0f172a; color: #e2e8f0; padding: 16px 20px;
    border-radius: var(--r-md); overflow-x: auto;
    margin: 1.2em 0; font-size: .88rem; line-height: 1.6;
}
.kb-body pre code { background: transparent; color: inherit; padding: 0; }
.kb-body table {
    border-collapse: collapse; width: 100%; margin: 1.2em 0;
    border: 1px solid var(--c-border); border-radius: var(--r-md); overflow: hidden;
}
.kb-body th, .kb-body td { border: 1px solid var(--c-border); padding: 10px 14px; text-align: left; }
.kb-body th { background: #f8fafc; font-weight: 600; }
.kb-body tbody tr:nth-child(even) { background: #fafbfc; }
.kb-body hr { border: none; border-top: 1px solid var(--c-border); margin: 1.6em 0; }
.kb-body figure { margin: 1.2em 0; text-align: center; }
.kb-body figcaption { font-size: .85rem; color: var(--c-text-muted); margin-top: 6px; }
