:root {
    --primary: #4f46e5;
    --primary-dark: #4338ca;
    --bg: #f4f6fb;
    --card: #ffffff;
    --text: #1e293b;
    --muted: #64748b;
    --border: #e2e8f0;
    --radius: 12px;
}
* { box-sizing: border-box; }
body { margin: 0; font-family: 'Segoe UI', system-ui, -apple-system, sans-serif; background: var(--bg); color: var(--text); line-height: 1.5; }
a { color: var(--primary); text-decoration: none; }
h1 { margin: 4px 0; font-size: 1.6rem; }
h3 { margin-top: 0; }
.muted { color: var(--muted); }
.center { text-align: center; }
small { font-size: .8rem; }

/* Navbar */
.navbar { background: #fff; border-bottom: 1px solid var(--border); display: flex; align-items: center; gap: 24px; padding: 0 28px; height: 64px; position: sticky; top: 0; z-index: 10; }
.brand { font-weight: 700; font-size: 1.15rem; color: var(--text); }
.nav-links { display: flex; gap: 6px; flex: 1; }
.nav-links a { color: var(--muted); padding: 8px 14px; border-radius: 8px; font-weight: 500; }
.nav-links a:hover { background: var(--bg); color: var(--text); }
.nav-user { display: flex; align-items: center; gap: 12px; }

.container { max-width: 1100px; margin: 0 auto; padding: 28px 20px 60px; }
.page-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; margin-bottom: 22px; }
.page-head p { margin: 0; }

/* Cards */
.card { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: 22px; box-shadow: 0 1px 3px rgba(15, 23, 42, .04); }
.card-head { display: flex; justify-content: space-between; margin-bottom: 14px; }
.form-card { max-width: 640px; }
.two-col .form-card { max-width: none; }
.two-col { display: grid; grid-template-columns: 1.6fr 1fr; gap: 20px; align-items: start; }
.row { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }

/* Forms */
label { display: block; font-weight: 600; font-size: .88rem; margin: 14px 0 6px; }
input[type=text], input[type=email], input[type=password], select, textarea {
    width: 100%; padding: 10px 12px; border: 1px solid var(--border); border-radius: 8px;
    font: inherit; background: #fff; color: var(--text);
}
input:focus, select:focus, textarea:focus { outline: 2px solid #c7d2fe; border-color: var(--primary); }
textarea { resize: vertical; }
form .btn { margin-top: 16px; }

/* Buttons */
.btn { display: inline-block; padding: 10px 18px; border: 0; border-radius: 8px; font: inherit; font-weight: 600; cursor: pointer; text-align: center; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-light { background: #eef2ff; color: var(--primary); }
.btn-light:hover { background: #e0e7ff; }
.btn-sm { padding: 6px 12px; font-size: .85rem; margin: 0; }
.btn-block { width: 100%; }

/* Alerts */
.alert { padding: 12px 16px; border-radius: 8px; margin-bottom: 18px; font-size: .92rem; }
.alert-success { background: #dcfce7; color: #166534; }
.alert-error { background: #fee2e2; color: #991b1b; }

/* Auth pages */
.auth-wrap { min-height: 100vh; display: flex; flex-direction: column; justify-content: center; align-items: center; padding: 20px;
    background: linear-gradient(135deg, #eef2ff, #f5f3ff); }
.auth-card { background: #fff; width: 100%; max-width: 400px; padding: 36px; border-radius: 16px; box-shadow: 0 10px 40px rgba(79, 70, 229, .12); }
.auth-card h1 { text-align: center; }
.auth-card > .muted { text-align: center; margin-top: 0; }
.auth-logo { font-size: 2.4rem; text-align: center; }

/* Stat cards */
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; margin-bottom: 22px; }
.stat { background: #fff; border: 1px solid var(--border); border-radius: var(--radius); padding: 18px 20px; color: var(--text); border-left: 4px solid var(--primary); transition: .15s; }
.stat:hover, .stat.active { box-shadow: 0 4px 14px rgba(15, 23, 42, .08); transform: translateY(-1px); }
.stat-num { display: block; font-size: 1.9rem; font-weight: 700; }
.stat-label { color: var(--muted); font-size: .88rem; }
.stat-open { border-left-color: #3b82f6; }
.stat-in_progress { border-left-color: #f59e0b; }
.stat-resolved { border-left-color: #10b981; }
.stat-closed { border-left-color: #94a3b8; }

/* Table */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th { text-align: left; font-size: .78rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); padding: 10px 12px; border-bottom: 1px solid var(--border); }
td { padding: 14px 12px; border-bottom: 1px solid var(--border); vertical-align: middle; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr[onclick] { cursor: pointer; }
tbody tr[onclick]:hover { background: #f8fafc; }
.empty { text-align: center; color: var(--muted); padding: 30px 0; }

/* Badges */
.badge { display: inline-block; padding: 3px 10px; border-radius: 999px; font-size: .78rem; font-weight: 600; white-space: nowrap; }
.badge-lg { font-size: .9rem; padding: 6px 16px; }
.st-open { background: #dbeafe; color: #1d4ed8; }
.st-in_progress { background: #fef3c7; color: #b45309; }
.st-resolved { background: #d1fae5; color: #047857; }
.st-closed { background: #e2e8f0; color: #475569; }
.prio-low { background: #f1f5f9; color: #475569; }
.prio-medium { background: #fef3c7; color: #b45309; }
.prio-high { background: #fee2e2; color: #b91c1c; }
.role { text-transform: capitalize; background: #eef2ff; color: var(--primary); padding: 1px 8px; border-radius: 999px; font-size: .7rem; font-weight: 600; }
.role-agent { background: #d1fae5; color: #047857; }
.role-admin { background: #fee2e2; color: #b91c1c; }

/* Ticket page */
.ticket-layout { display: grid; grid-template-columns: 1fr 300px; gap: 20px; align-items: start; }
.chat-card { padding: 0; overflow: hidden; }
.chat { height: 460px; overflow-y: auto; padding: 22px; background: #f8fafc; display: flex; flex-direction: column; gap: 16px; }
.msg { max-width: 78%; }
.msg.mine { align-self: flex-end; text-align: right; }
.msg-meta { font-size: .78rem; color: var(--muted); margin-bottom: 4px; }
.bubble { display: inline-block; padding: 10px 14px; border-radius: 14px; background: #fff; border: 1px solid var(--border); text-align: left; word-break: break-word; }
.msg.mine .bubble { background: var(--primary); color: #fff; border-color: var(--primary); }
.reply-form { display: flex; gap: 12px; padding: 16px; border-top: 1px solid var(--border); align-items: flex-end; }
.reply-form .btn { margin: 0; }
.side form { margin-top: 18px; padding-top: 4px; border-top: 1px solid var(--border); }
.side dl { margin: 0; }
.side dt { font-size: .78rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin-top: 14px; }
.side dd { margin: 2px 0 0; }

@media (max-width: 800px) {
    .stats { grid-template-columns: repeat(2, 1fr); }
    .ticket-layout, .two-col, .row { grid-template-columns: 1fr; }
    .navbar { padding: 0 14px; gap: 10px; }
    .nav-user > span { display: none; }
}

/* Locked chat, feedback, agent history */
.reply-form.locked textarea { background: #f1f5f9; cursor: not-allowed; }
.reply-form.locked .btn { opacity: .5; cursor: not-allowed; }
.feedback-box { border-top: 1px solid var(--border); padding: 20px; background: #fffbeb; }
.feedback-box textarea { margin-top: 10px; }
.feedback-box p { margin: 4px 0; }
.stars-view { color: #f59e0b; font-size: 1.5rem; letter-spacing: 2px; }
.star-input { display: inline-flex; flex-direction: row-reverse; gap: 4px; margin-top: 6px; }
.star-input input { display: none; }
.star-input label { margin: 0; font-size: 2rem; color: #cbd5e1; cursor: pointer; line-height: 1; }
.star-input input:checked ~ label, .star-input label:hover, .star-input label:hover ~ label { color: #f59e0b; }
.agent-history .hist-item { padding: 10px 0; border-bottom: 1px solid var(--border); }
.agent-history .hist-item:last-child { border-bottom: 0; }
.agent-history .hist-item.current strong::before { content: '\25CF '; color: #f59e0b; }
.side .agent-history { margin-top: 18px; padding-top: 4px; border-top: 1px solid var(--border); }

/* ---------- Status colours (used everywhere) ---------- */
.s-open        { --sc: #3b82f6; --sc-soft: #dbeafe; --sc-dark: #1d4ed8; }
.s-in_progress { --sc: #f59e0b; --sc-soft: #fef3c7; --sc-dark: #b45309; }
.s-resolved    { --sc: #10b981; --sc-soft: #d1fae5; --sc-dark: #047857; }
.s-closed      { --sc: #64748b; --sc-soft: #e2e8f0; --sc-dark: #475569; }

.btn-success { background: #10b981; color: #fff; }
.btn-success:hover { background: #059669; }
.side form + form { margin-top: 10px; padding-top: 0; border-top: 0; }
.stars-view.small { font-size: 1rem; letter-spacing: 0; }

/* Big banner at the top of a ticket */
.status-banner { display: flex; align-items: center; gap: 18px; padding: 18px 24px; margin-bottom: 20px; border-radius: 14px;
    background: var(--sc-soft); border: 1px solid var(--sc); border-left-width: 6px; color: var(--sc-dark); animation: slideIn .5s ease; }
.status-banner strong { font-size: 1.15rem; }
.status-banner p { margin: 2px 0 0; color: var(--text); opacity: .8; }
.sb-icon { width: 52px; height: 52px; border-radius: 50%; background: #fff; display: flex; align-items: center; justify-content: center; font-size: 1.7rem; flex-shrink: 0; }
.s-open .sb-icon { animation: pulse 1.8s ease-in-out infinite; }
.s-in_progress .sb-icon { animation: spin 3s linear infinite; }
.s-resolved .sb-icon { animation: pop .6s ease; }
.s-closed .sb-icon { animation: pop .6s ease; }

/* Ticket history timeline */
.history-card { margin-top: 20px; }
.timeline { position: relative; }
.timeline::before { content: ''; position: absolute; left: 15px; top: 6px; bottom: 6px; width: 2px; background: var(--border); }
.tl-item { display: flex; gap: 14px; padding: 8px 0; position: relative; animation: slideIn .4s ease; }
.tl-dot { width: 32px; height: 32px; border-radius: 50%; background: #fff; border: 2px solid var(--border); display: flex; align-items: center; justify-content: center; font-size: .9rem; flex-shrink: 0; z-index: 1; }
.tl-in_progress .tl-dot { border-color: #f59e0b; } .tl-resolved .tl-dot { border-color: #10b981; } .tl-closed .tl-dot { border-color: #64748b; }
.tl-created .tl-dot, .tl-open .tl-dot { border-color: #3b82f6; } .tl-reopened .tl-dot { border-color: #ef4444; } .tl-feedback .tl-dot { border-color: #f59e0b; }

/* Animations */
@keyframes pulse { 0%, 100% { transform: scale(1); } 50% { transform: scale(1.12); } }
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes pop { 0% { transform: scale(.3); opacity: 0; } 70% { transform: scale(1.2); } 100% { transform: scale(1); opacity: 1; } }
@keyframes slideIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
@keyframes ring { 0% { box-shadow: 0 0 0 0 var(--sc); } 100% { box-shadow: 0 0 0 10px transparent; } }
@keyframes fillLine { from { transform: scaleX(0); } to { transform: scaleX(1); } }
@keyframes stripes { to { background-position: 24px 0; } }
@keyframes blink { 50% { opacity: .45; } }
@media (prefers-reduced-motion: reduce) { * { animation: none !important; } }

/* =====================================================
   Ticket page: header card, chat layout
   ===================================================== */
.back-link { display: inline-block; margin-bottom: 10px; color: var(--muted); font-weight: 500; }
.back-link:hover { color: var(--primary); }
.ticket-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; background: #fff;
    border: 1px solid var(--border); border-radius: var(--radius); padding: 20px 24px; margin-bottom: 16px; }
.th-main { min-width: 0; }
.th-ref { font-size: .8rem; font-weight: 700; color: var(--primary); letter-spacing: .04em; }
.ticket-head h1 { font-size: 1.4rem; margin: 2px 0 10px; word-break: break-word; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { background: var(--bg); color: var(--muted); padding: 4px 12px; border-radius: 999px; font-size: .8rem; font-weight: 500; }
.chip.prio-low { background: #f1f5f9; color: #475569; }
.chip.prio-medium { background: #fef3c7; color: #b45309; }
.chip.prio-high { background: #fee2e2; color: #b91c1c; }

.status-banner { padding: 14px 20px; }
.sb-icon { width: 46px; height: 46px; font-size: 1.5rem; }

.main-col { min-width: 0; }
.chat-card { display: flex; flex-direction: column; padding: 0; overflow: hidden; }
.chat-head { display: flex; align-items: center; gap: 12px; padding: 14px 20px; border-bottom: 1px solid var(--border); background: #fff; }
.chat-head small { display: block; line-height: 1.2; }
.chat { height: clamp(340px, 58vh, 560px); padding: 20px; gap: 14px; background: #f8fafc; scroll-behavior: smooth; }
.chat-empty { margin: auto; color: var(--muted); }

.avatar { width: 38px; height: 38px; border-radius: 50%; display: flex; align-items: center; justify-content: center; flex-shrink: 0;
    font-weight: 700; color: #fff; background: var(--primary); }
.av-agent { background: #10b981; } .av-admin { background: #ef4444; } .av-user { background: #6366f1; }

.day-divider { text-align: center; position: relative; margin: 4px 0; }
.day-divider::before { content: ''; position: absolute; left: 0; right: 0; top: 50%; height: 1px; background: var(--border); }
.day-divider span { position: relative; background: #f8fafc; padding: 0 12px; font-size: .75rem; color: var(--muted); font-weight: 600; }

.msg { display: flex; gap: 10px; max-width: 80%; align-self: flex-start; text-align: left; animation: slideIn .25s ease; }
.msg.mine { flex-direction: row-reverse; align-self: flex-end; text-align: left; }
.msg-body { display: flex; flex-direction: column; min-width: 0; }
.msg.mine .msg-body { align-items: flex-end; }
.msg-meta { font-size: .78rem; margin-bottom: 4px; display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.msg-meta b { color: var(--text); }
.msg-meta time { color: var(--muted); }
.msg.mine .msg-meta { flex-direction: row-reverse; }
.bubble { display: block; width: fit-content; max-width: 100%; padding: 10px 14px; border-radius: 4px 16px 16px 16px; overflow-wrap: anywhere; }
.msg.mine .bubble { border-radius: 16px 4px 16px 16px; }
body.customer .bubble { border-radius: 4px 18px 18px 18px; }
body.customer .msg.mine .bubble { border-radius: 18px 4px 18px 18px; }

/* Message box */
.reply-form { display: flex; align-items: flex-end; gap: 10px; padding: 12px 16px; border-top: 1px solid var(--border); background: #fff; }
.reply-form textarea { flex: 1; resize: none; max-height: 140px; border-radius: 22px; background: var(--bg); border-color: transparent; padding: 11px 16px; line-height: 1.4; }
.reply-form textarea:focus { background: #fff; border-color: var(--primary); }
.send-btn { width: 44px; height: 44px; border-radius: 50%; border: 0; background: var(--primary); color: #fff; font-size: 1.1rem; cursor: pointer; flex-shrink: 0; transition: .15s; }
.send-btn:hover:not(:disabled) { background: var(--primary-dark); transform: scale(1.06); }
.send-btn:disabled { opacity: .45; cursor: not-allowed; }
.reply-form.locked { background: #f1f5f9; }

.ticket-layout { align-items: start; }
.side h3 { margin-bottom: 4px; }

/* =====================================================
   Mobile friendly
   ===================================================== */
@media (max-width: 800px) {
    .container { padding: 16px 14px 40px; }
    h1 { font-size: 1.35rem; }
    .page-head { flex-wrap: wrap; }

    /* navbar: brand + logout on top row, links on a scrolling second row */
    .navbar { flex-wrap: wrap; height: auto; padding: 10px 14px; gap: 6px 10px; }
    .brand { flex: 1; }
    .nav-user { order: 2; }
    .nav-links { order: 3; width: 100%; flex: none; overflow-x: auto; gap: 4px; padding-bottom: 2px; }
    .nav-links a { white-space: nowrap; padding: 6px 12px; }

    .ticket-head { flex-direction: column-reverse; padding: 16px; gap: 10px; }
    .ticket-head h1 { font-size: 1.2rem; }
    .status-banner { padding: 12px 14px; gap: 12px; }
    .status-banner strong { font-size: 1rem; }
    .sb-icon { width: 40px; height: 40px; font-size: 1.3rem; }
    .track-step, .tracker-card .track-step { font-size: .66rem; }

    .ticket-layout { grid-template-columns: 1fr; gap: 16px; }
    .chat { height: clamp(320px, 62vh, 520px); padding: 14px 12px; }
    .chat-head { padding: 12px 14px; }
    .msg { max-width: 94%; gap: 8px; }
    .avatar { width: 32px; height: 32px; font-size: .85rem; }
    .reply-form { padding: 10px 12px; }

    .ticket-cards { grid-template-columns: 1fr; }
    .hero { padding: 22px 18px; }
    .hero h1 { font-size: 1.5rem; }
    .hero-stats { width: 100%; }
    .hero-stats div { flex: 1; padding: 12px; }
    .tabs { flex-wrap: nowrap; overflow-x: auto; padding-bottom: 4px; }
    .tabs a { white-space: nowrap; }
    .card { padding: 16px; }
    .chat-card { padding: 0; }
    .tracker-card { padding: 16px 8px; }
    .form-card { max-width: none; }
    .auth-card { padding: 26px 20px; }
    .landing-hero { padding: 60px 16px 80px; }

    /* comfortable tap targets; 16px font stops phones zooming into inputs */
    input[type=text], input[type=email], input[type=password], select, textarea { font-size: 16px; }
    .btn { min-height: 44px; display: inline-flex; align-items: center; justify-content: center; }
    .btn-sm { min-height: 36px; }
}
@media (max-width: 480px) {
    .stats { gap: 10px; }
    .stat { padding: 14px; }
    .stat-num { font-size: 1.5rem; }
    .navbar .nav-user .btn { padding: 6px 12px; }
}

/* =====================================================
   Ticket page = one screen: merged header on top,
   chat window + details side by side, only the chat scrolls
   ===================================================== */
.container.fit { max-width: 1320px; height: calc(100vh - 64px); height: calc(100dvh - 64px);
    display: flex; flex-direction: column; padding-top: 14px; padding-bottom: 14px; overflow: hidden; }
.fit .alert { margin-bottom: 10px; padding: 8px 14px; flex-shrink: 0; }

/* merged header */
.ticket-head { display: block; padding: 0; overflow: hidden; border-left: 6px solid var(--sc); margin-bottom: 12px; flex-shrink: 0; }
.th-top { display: flex; align-items: center; gap: 14px; padding: 12px 18px 10px; }
.back-btn { width: 36px; height: 36px; border-radius: 50%; background: var(--bg); color: var(--text); display: flex;
    align-items: center; justify-content: center; font-size: 1.1rem; flex-shrink: 0; }
.back-btn:hover { background: #e0e7ff; color: var(--primary); }
.th-main { flex: 1; min-width: 0; }
.ticket-head h1 { font-size: 1.2rem; margin: 4px 0 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ticket-head .chips { gap: 6px; align-items: center; }
.ticket-head .chip { padding: 2px 10px; font-size: .76rem; }
.th-status { display: flex; align-items: center; gap: 12px; padding: 8px 18px; background: var(--sc-soft); color: var(--sc-dark); }
.th-status .sb-icon { width: 34px; height: 34px; font-size: 1.1rem; }
.th-text { flex: 1; min-width: 0; display: flex; flex-direction: column; line-height: 1.3; }
.th-text span { color: var(--text); opacity: .75; font-size: .85rem; }
.th-tracker { width: 360px; max-width: 45%; flex-shrink: 0; }
.th-tracker .track-step { font-size: .7rem; }
.th-tracker .track-step .dot { width: 18px; height: 18px; font-size: .6rem; background: #fff; border: 2px solid #cbd5e1; color: #fff; margin-bottom: 2px; }
.th-tracker .track-step::before { top: 8px; height: 3px; background: #cbd5e1; }
.th-tracker .track-step.done .dot { background: var(--sc); border-color: var(--sc); }
.th-tracker .track-step.done::before, .th-tracker .track-step.current::before { background: var(--sc); }
.th-tracker .track-step.current .dot { border-color: var(--sc); }
.track-step.current .dot::after { content: ''; width: 6px; height: 6px; border-radius: 50%; background: var(--sc); }

/* chat + side fill the rest of the screen */
.fit .ticket-layout { flex: 1; min-height: 0; display: grid; grid-template-columns: 1fr 330px; gap: 14px; align-items: stretch; }
.fit .chat-card { min-height: 0; height: 100%; }
.fit .chat { flex: 1; height: auto; min-height: 0; overflow-y: auto; }
.fit .reply-form, .fit .chat-head { flex-shrink: 0; }
.fit .feedback-box { flex-shrink: 0; max-height: 46%; overflow-y: auto; padding: 12px 18px; }
.fit .feedback-box textarea { margin-top: 8px; }
.fit .feedback-box form .btn { margin-top: 8px; padding: 8px 16px; }
.fit .star-input label { font-size: 1.7rem; }

/* side panel: compact, tabs */
.fit .side { min-height: 0; overflow-y: auto; padding: 16px; }
.fit .side h3 { margin: 0 0 2px; font-size: 1rem; }
.fit .side dt { margin-top: 10px; }
.fit .side form { margin-top: 10px; padding-top: 2px; }
.fit .side label { margin: 8px 0 4px; }
.fit .side select { padding: 8px 10px; }
.fit .side .btn { margin-top: 8px; padding: 8px 14px; }
.side-tabs { display: flex; gap: 4px; background: var(--bg); padding: 4px; border-radius: 10px; margin-bottom: 14px; }
.side-tabs button { flex: 1; border: 0; background: transparent; padding: 7px; border-radius: 8px; font: inherit; font-weight: 600; color: var(--muted); cursor: pointer; }
.side-tabs button.on { background: #fff; color: var(--primary); box-shadow: 0 1px 3px rgba(15, 23, 42, .1); }
.tab-pane[hidden] { display: none; }
.fit .timeline .tl-item { padding: 6px 0; }
.fit .tl-dot { width: 28px; height: 28px; font-size: .8rem; }
.fit .timeline::before { left: 13px; }

@media (max-width: 800px) {
    /* on phones the page scrolls normally: header, chat, then details */
    .container.fit { height: auto; display: block; overflow: visible; padding: 12px 12px 30px; }
    .th-top { padding: 10px 12px 8px; gap: 10px; }
    .th-status { flex-wrap: wrap; padding: 8px 12px; }
    .th-tracker { width: 100%; max-width: none; }
    .fit .ticket-layout { display: block; }
    .fit .chat-card { height: auto; }
    .fit .chat { flex: none; height: clamp(300px, 56vh, 480px); }
    .fit .feedback-box { max-height: none; }
    .fit .side { margin-top: 14px; overflow: visible; }
}

/* =====================================================
   New ticket page
   ===================================================== */
.new-ticket { display: grid; grid-template-columns: 1fr 340px; gap: 20px; align-items: start; }
.nt-form { padding: 26px 28px; }
.nt-form > form > label:first-child { margin-top: 0; }
.optional { font-weight: 400; color: var(--muted); }
.counter { text-align: right; font-size: .78rem; color: var(--muted); margin-top: 4px; }

/* category cards */
.cat-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 10px; }
label.cat { margin: 0; cursor: pointer; font-weight: 600; }
.cat input { position: absolute; opacity: 0; pointer-events: none; }
.cat span { display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 14px 8px; border: 2px solid var(--border);
    border-radius: 12px; background: #fff; font-size: .88rem; text-align: center; transition: .15s; }
.cat i { font-style: normal; font-size: 1.5rem; }
.cat span:hover { border-color: #c7d2fe; background: #f8faff; }
.cat input:checked + span { border-color: var(--primary); background: #eef2ff; color: var(--primary); box-shadow: 0 0 0 3px #e0e7ff; }
.cat input:focus-visible + span { outline: 2px solid var(--primary); }

/* duplicate warnings */
.dup-warning { display: flex; gap: 14px; background: #fffbeb; border: 1px solid #fcd34d; border-left: 5px solid #f59e0b; border-radius: 12px;
    padding: 16px 18px; margin-bottom: 20px; animation: slideIn .3s ease; }
.dup-warning p { margin: 4px 0 10px; }
.dup-warning .btn { margin: 0; }
.dup-icon { font-size: 1.6rem; }
.dup-live { margin-top: 8px; padding: 8px 12px; background: #fffbeb; border: 1px solid #fcd34d; border-radius: 8px; font-size: .88rem; color: #92400e; }
.dup-live[hidden] { display: none; }

/* info column */
.nt-info { display: flex; flex-direction: column; gap: 16px; }
.info-card h3 { margin: 0 0 12px; font-size: 1rem; }
.next-steps { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 14px; }
.next-steps li { display: flex; gap: 12px; }
.next-steps li > span { width: 28px; height: 28px; border-radius: 50%; background: var(--primary); color: #fff; font-weight: 700; font-size: .85rem;
    display: flex; align-items: center; justify-content: center; flex-shrink: 0; margin-top: 2px; }
.next-steps p { margin: 2px 0 0; color: var(--muted); font-size: .88rem; }
.tips { background: #f5f3ff; border-color: #ddd6fe; }
.tips ul { margin: 0; padding-left: 20px; color: var(--text); font-size: .9rem; }
.tips li { margin: 4px 0; }

@media (max-width: 800px) {
    .new-ticket { grid-template-columns: 1fr; }
    .nt-form { padding: 18px 16px; }
    .cat-grid { grid-template-columns: repeat(2, 1fr); }
    .nt-form .btn { width: 100%; margin-top: 10px; }
}

/* =====================================================
   Fit-to-screen pages (ticket page + new ticket page)
   The body fills the window; the page area takes whatever the navbar leaves.
   ===================================================== */
body.fitpage { height: 100vh; height: 100dvh; display: flex; flex-direction: column; overflow: hidden; }
body.fitpage .navbar { flex-shrink: 0; position: static; }
body.fitpage .container.fit { flex: 1; min-height: 0; height: auto; width: 100%; }
body.fitpage footer { display: none; }

/* ---------- New ticket page ---------- */
.container.fit-all { max-width: 1120px; margin: 0 auto; padding: 14px 20px; }
.nt-head { margin-bottom: 10px; align-items: center; flex-shrink: 0; }
.nt-head h1 { margin: 0; font-size: 1.35rem; }
.reply-chip { background: #eef2ff; color: var(--primary); font-weight: 600; font-size: .85rem; padding: 6px 14px; border-radius: 999px; }

.fit-all .new-ticket { flex: 1; min-height: 0; grid-template-columns: 1fr 320px; gap: 16px; align-items: stretch; }
.fit-all .nt-form { display: flex; flex-direction: column; min-height: 0; overflow-y: auto; padding: 16px 22px; }
.fit-all .nt-form form { display: flex; flex-direction: column; flex: 1; min-height: 0; }
.fit-all .nt-form label { margin: 10px 0 5px; }
.fit-all .nt-form form > label:first-child { margin-top: 0; }
.fit-all .nt-form input[type=text] { padding: 9px 12px; }
.fit-all .nt-form textarea { flex: 1; min-height: 80px; resize: none; }
.fit-all .alert, .fit-all .dup-warning { flex-shrink: 0; }
.fit-all .dup-warning { padding: 10px 14px; margin-bottom: 10px; }
.fit-all .dup-warning p { margin: 2px 0 6px; }

/* subject + reference share one row */
.nt-row { display: grid; grid-template-columns: 1.7fr 1fr; gap: 14px; }
.label-row { display: flex; justify-content: space-between; align-items: baseline; }
.label-row .counter { margin: 0; }
.nt-actions { display: flex; gap: 10px; margin-top: 12px; flex-shrink: 0; }
.nt-actions .btn { margin: 0; }

/* the 5 category boxes always stay in ONE row */
.fit-all .cat-grid { grid-template-columns: repeat(5, 1fr); gap: 8px; }
.fit-all .cat span { padding: 10px 4px; gap: 3px; font-size: .8rem; line-height: 1.15; min-height: 66px; justify-content: center; }
.fit-all .cat i { font-size: 1.3rem; }

/* info column: compact, never pushes the page down */
.fit-all .nt-info { min-height: 0; overflow-y: auto; gap: 12px; }
.fit-all .info-card { padding: 14px 16px; }
.fit-all .info-card h3 { margin-bottom: 10px; font-size: .95rem; }
.fit-all .next-steps { gap: 10px; }
.fit-all .next-steps p { font-size: .82rem; }
.fit-all .next-steps li > span { width: 24px; height: 24px; font-size: .78rem; }
.fit-all .tips ul { font-size: .85rem; }
.fit-all .tips li { margin: 2px 0; }

@media (max-width: 800px) {
    /* ticket page keeps scrolling normally on phones */
    body.fitpage:not(.fit-all) { height: auto; display: block; overflow: visible; }
    body.fitpage:not(.fit-all) .navbar { position: sticky; }

    /* new ticket page: still one screen on phones, form only */
    .container.fit-all { display: flex; flex-direction: column; overflow: hidden; padding: 10px 12px 12px; height: auto; }
    .nt-head h1 { font-size: 1.15rem; }
    .reply-chip { font-size: .75rem; padding: 4px 10px; }
    .fit-all .new-ticket { display: flex; flex-direction: column; }
    .fit-all .nt-form { flex: 1; padding: 12px; }
    .fit-all .nt-info { display: none; }
    .nt-row { grid-template-columns: 1fr; gap: 0; }
    .fit-all .nt-form label { margin: 8px 0 4px; font-size: .82rem; }
    .fit-all .cat-grid { gap: 5px; }
    .fit-all .cat span { padding: 8px 2px; font-size: .64rem; min-height: 58px; font-weight: 600; }
    .fit-all .cat i { font-size: 1.15rem; }
    .fit-all .nt-form textarea { min-height: 70px; }
    .nt-actions .btn { flex: 1; margin-top: 0; }
    .fit-all .nt-form .btn { width: auto; }
}

/* Feedback lives in the side panel under the agent name */
.side-feedback { margin-top: 14px; padding: 12px 14px; background: #fffbeb; border: 1px solid #fde68a; border-radius: 12px; animation: slideIn .4s ease; }
.side-feedback p { margin: 4px 0 0; font-size: .88rem; }
.side-feedback .stars-view { font-size: 1.35rem; letter-spacing: 2px; }
.side-feedback .star-input { margin: 2px 0 6px; }
.side-feedback .star-input label { font-size: 1.8rem; }
.side-feedback textarea { margin-top: 4px; font-size: .9rem; padding: 8px 10px; }
.side-feedback .btn { margin-top: 8px; }

/* tighter side panel so the solved / not-solved buttons always fit */
.fit .side #tab-details > h3 { display: none; }
.side-feedback { margin-top: 10px; padding: 10px 12px; }
.side-feedback textarea { height: 44px; min-height: 0; resize: none; }
.side-feedback .star-input label { font-size: 1.6rem; }
.side-feedback strong { font-size: .92rem; }
.fit .side dt { margin-top: 8px; }

/* =====================================================
   Notification bell, panel and toasts
   ===================================================== */
.notif { position: relative; }
.bell { position: relative; width: 40px; height: 40px; border-radius: 50%; border: 0; background: transparent; color: var(--muted);
    display: flex; align-items: center; justify-content: center; cursor: pointer; transition: background .15s; }
.bell:hover, .bell[aria-expanded="true"] { background: var(--bg); color: var(--text); }
.bell-count { position: absolute; top: 2px; right: 0; min-width: 18px; height: 18px; padding: 0 5px; border-radius: 999px; background: #ef4444; color: #fff;
    font-size: .68rem; font-weight: 700; display: flex; align-items: center; justify-content: center; border: 2px solid #fff; animation: pop .35s ease; }
.bell-count[hidden] { display: none; }

.notif-panel { position: absolute; right: -8px; top: 50px; width: 380px; max-width: calc(100vw - 16px); background: #fff; color: var(--text);
    border: 1px solid var(--border); border-radius: 14px; box-shadow: 0 16px 40px rgba(15, 23, 42, .18); z-index: 60; overflow: hidden; }
.notif-panel[hidden] { display: none; }
.np-head { display: flex; justify-content: space-between; align-items: center; padding: 14px 16px; border-bottom: 1px solid var(--border); }
.link-btn { border: 0; background: none; color: var(--primary); font: inherit; font-size: .84rem; font-weight: 600; cursor: pointer; padding: 0; }
.link-btn:hover { text-decoration: underline; }
.np-list { max-height: min(420px, 60vh); overflow-y: auto; }
.np-empty { margin: 0; padding: 30px 20px; text-align: center; color: var(--muted); font-size: .9rem; }
.np-item { display: flex; gap: 12px; align-items: flex-start; padding: 12px 16px; color: var(--text); border-bottom: 1px solid #f1f5f9; position: relative; }
.np-item:hover { background: #f8fafc; }
.np-item.unread { background: #f5f3ff; }
.np-item.unread:hover { background: #ede9fe; }
.np-icon { width: 36px; height: 36px; border-radius: 50%; background: var(--bg); display: flex; align-items: center; justify-content: center; font-size: 1.05rem; flex-shrink: 0; }
.np-item.unread .np-icon { background: #fff; }
.np-text { display: flex; flex-direction: column; min-width: 0; flex: 1; line-height: 1.35; }
.np-text strong { font-size: .88rem; }
.np-item:not(.unread) .np-text strong { font-weight: 600; }
.np-text small { color: var(--muted); font-size: .8rem; overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.np-text em { font-style: normal; color: var(--muted); font-size: .74rem; margin-top: 2px; }
.np-dot { width: 9px; height: 9px; border-radius: 50%; background: var(--primary); flex-shrink: 0; margin-top: 6px; }
.np-foot { padding: 12px 16px; background: #f8fafc; border-top: 1px solid var(--border); font-size: .82rem; color: var(--muted); }
.np-foot .ok { color: #047857; font-weight: 600; }
.np-enable { width: 100%; border: 0; border-radius: 8px; padding: 9px 12px; background: var(--primary); color: #fff; font: inherit; font-weight: 600; cursor: pointer; }
.np-enable:hover { background: var(--primary-dark); }

/* toast: pops up at the bottom right while the page is open */
.toasts { position: fixed; right: 18px; bottom: 18px; display: flex; flex-direction: column; gap: 10px; z-index: 80; pointer-events: none; }
.toast { pointer-events: auto; display: flex; gap: 12px; align-items: flex-start; width: 340px; max-width: calc(100vw - 36px); background: #fff; color: var(--text);
    border: 1px solid var(--border); border-left: 5px solid var(--primary); border-radius: 12px; padding: 12px 14px; box-shadow: 0 12px 32px rgba(15, 23, 42, .2);
    animation: slideIn .3s ease; transition: opacity .35s, transform .35s; }
.toast.out { opacity: 0; transform: translateY(10px); }

@media (max-width: 800px) {
    .notif { position: static; }
    .notif-panel { position: fixed; left: 8px; right: 8px; top: 60px; width: auto; max-width: none; }
    .toasts { left: 12px; right: 12px; bottom: 12px; }
    .toast { width: auto; max-width: none; }
}

/* Demo accounts box on the login page */
.demo-box { margin-top: 20px; padding: 14px; background: #f8fafc; border: 1px dashed #c7d2fe; border-radius: 12px; }
.demo-title { font-weight: 700; font-size: .88rem; margin-bottom: 10px; }
.demo-title small { font-weight: 500; color: var(--muted); margin-left: 6px; }
.demo-row { display: flex; align-items: center; gap: 10px; width: 100%; padding: 9px 10px; margin-top: 6px; background: #fff; border: 1px solid var(--border);
    border-radius: 10px; font: inherit; text-align: left; cursor: pointer; transition: border-color .15s, box-shadow .15s; }
.demo-row:hover { border-color: var(--primary); box-shadow: 0 0 0 3px #e0e7ff; }
.demo-row .role { min-width: 66px; text-align: center; font-size: .72rem; }
.role-user { background: #eef2ff; color: var(--primary); }
.demo-cred { display: flex; flex-direction: column; flex: 1; min-width: 0; line-height: 1.3; }
.demo-cred b { font-size: .85rem; overflow: hidden; text-overflow: ellipsis; }
.demo-cred small { color: var(--muted); font-size: .76rem; }
.demo-use { color: var(--primary); font-weight: 700; font-size: .8rem; }
.auth-card { max-width: 420px; }
