:root {
  --bg: #f4f6f8;
  --panel: #ffffff;
  --border: #dde3ea;
  --text: #1c2733;
  --muted: #64748b;
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --danger: #dc2626;
  --warn-bg: #fef9c3;
  --radius: 8px;
  --shadow: 0 1px 3px rgba(16, 24, 40, .08);
  font-size: 15px;
}
* { box-sizing: border-box; }
body { margin: 0; font-family: 'Segoe UI', system-ui, -apple-system, sans-serif; background: var(--bg); color: var(--text); }
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.4rem; margin: 0 0 16px; }
h2 { font-size: 1.1rem; margin: 0 0 12px; }

/* layout */
.layout { display: grid; grid-template-columns: 210px 1fr; min-height: 100vh; }
.sidebar { background: #10203a; color: #cbd5e1; padding: 16px 0; position: sticky; top: 0; height: 100vh; }
.sidebar .brand { font-weight: 700; color: #fff; font-size: 1.1rem; padding: 4px 20px 16px; }
.sidebar nav a { display: block; padding: 9px 20px; color: #cbd5e1; font-size: .95rem; }
.sidebar nav a:hover { background: #1a3050; text-decoration: none; }
.sidebar nav a.active { background: var(--primary); color: #fff; }
.sidebar .section-label { padding: 14px 20px 4px; font-size: .72rem; text-transform: uppercase; letter-spacing: .08em; color: #64748b; }
.main { display: flex; flex-direction: column; min-width: 0; }
.topbar { display: flex; align-items: center; gap: 16px; background: var(--panel); border-bottom: 1px solid var(--border); padding: 10px 24px; position: sticky; top: 0; z-index: 30; }
.topbar .spacer { flex: 1; }
.content { padding: 24px; max-width: 1200px; width: 100%; }

/* search */
.search-wrap { position: relative; width: 340px; }
.search-wrap input { width: 100%; }
.search-results { position: absolute; top: 110%; left: 0; right: 0; background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: 0 8px 24px rgba(16,24,40,.15); max-height: 420px; overflow-y: auto; z-index: 50; }
.search-results .group { padding: 6px 12px 2px; font-size: .72rem; text-transform: uppercase; color: var(--muted); }
.search-results a { display: block; padding: 7px 12px; color: var(--text); font-size: .9rem; }
.search-results a:hover { background: #eef2ff; text-decoration: none; }

/* bell */
.bell-wrap { position: relative; }
.bell-btn { background: none; border: none; cursor: pointer; font-size: 1.25rem; position: relative; padding: 4px 8px; }
.bell-badge { position: absolute; top: -2px; right: 0; background: var(--danger); color: #fff; font-size: .68rem; border-radius: 10px; padding: 1px 5px; font-weight: 700; }
.notif-panel { position: absolute; right: 0; top: 120%; width: 380px; background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: 0 8px 24px rgba(16,24,40,.15); z-index: 50; max-height: 480px; overflow-y: auto; }
.notif-panel .head { display: flex; justify-content: space-between; align-items: center; padding: 10px 14px; border-bottom: 1px solid var(--border); font-weight: 600; }
.notif-item { display: block; padding: 10px 14px; border-bottom: 1px solid #eef1f5; font-size: .88rem; color: var(--text); }
.notif-item.unread { background: #eff6ff; }
.notif-item:hover { background: #e0eaff; text-decoration: none; }
.notif-item .time { color: var(--muted); font-size: .75rem; }

/* cards & panels */
.panel { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px; margin-bottom: 18px; }
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 14px; margin-bottom: 18px; }
.card { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; }
.card .num { font-size: 1.9rem; font-weight: 700; }
.card .label { color: var(--muted); font-size: .85rem; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
@media (max-width: 900px) { .grid-2 { grid-template-columns: 1fr; } .layout { grid-template-columns: 1fr; } .sidebar { position: static; height: auto; } }

/* tables */
table { width: 100%; border-collapse: collapse; font-size: .9rem; }
th { text-align: left; color: var(--muted); font-weight: 600; font-size: .78rem; text-transform: uppercase; letter-spacing: .04em; padding: 8px 10px; border-bottom: 2px solid var(--border); }
td { padding: 9px 10px; border-bottom: 1px solid #eef1f5; vertical-align: top; }
tr.clickable { cursor: pointer; }
tr.clickable:hover { background: #f0f5ff; }

/* forms */
input, select, textarea { font: inherit; padding: 7px 10px; border: 1px solid var(--border); border-radius: 6px; background: #fff; color: var(--text); }
input:focus, select:focus, textarea:focus { outline: 2px solid #bfdbfe; border-color: var(--primary); }
textarea { width: 100%; resize: vertical; }
label { display: block; font-size: .82rem; font-weight: 600; color: var(--muted); margin: 10px 0 4px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 16px; }
.form-actions { margin-top: 16px; display: flex; gap: 10px; }
button, .btn { font: inherit; padding: 8px 16px; border-radius: 6px; border: 1px solid var(--border); background: #fff; cursor: pointer; color: var(--text); }
button:hover, .btn:hover { background: #f1f5f9; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; font-weight: 600; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-danger { color: var(--danger); border-color: #fca5a5; }
.btn-danger:hover { background: #fef2f2; }
.btn-sm { padding: 4px 10px; font-size: .82rem; }

/* badges */
.badge { display: inline-block; padding: 2px 9px; border-radius: 20px; font-size: .75rem; font-weight: 600; white-space: nowrap; }
.st-open { background: #dcfce7; color: #15803d; }
.st-pending { background: #fef3c7; color: #b45309; }
.st-resolved { background: #dbeafe; color: #1d4ed8; }
.st-closed { background: #e2e8f0; color: #475569; }
.pr-low { background: #f1f5f9; color: #64748b; }
.pr-medium { background: #dbeafe; color: #1d4ed8; }
.pr-high { background: #ffedd5; color: #c2410c; }
.pr-urgent { background: #fee2e2; color: #b91c1c; }
.tag { display: inline-block; background: #eef2ff; color: #4338ca; border-radius: 4px; padding: 1px 7px; font-size: .75rem; margin-right: 4px; }

/* filter bar */
.filterbar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 14px; }
.filterbar select, .filterbar input { font-size: .88rem; }
.viewtabs { display: flex; gap: 4px; margin-bottom: 14px; flex-wrap: wrap; }
.viewtabs button { border: none; background: none; padding: 7px 14px; border-radius: 6px; color: var(--muted); font-size: .9rem; }
.viewtabs button.active { background: #dbeafe; color: var(--primary-dark); font-weight: 600; }

/* ticket detail */
.ticket-layout { display: grid; grid-template-columns: 1fr 300px; gap: 18px; align-items: start; }
@media (max-width: 900px) { .ticket-layout { grid-template-columns: 1fr; } }
.comment { border: 1px solid var(--border); border-radius: var(--radius); margin-bottom: 12px; background: #fff; }
.comment.internal { background: var(--warn-bg); border-color: #fde047; }
.comment .meta { padding: 8px 14px; font-size: .8rem; color: var(--muted); border-bottom: 1px solid rgba(0,0,0,.06); display: flex; justify-content: space-between; }
.comment .body { padding: 12px 14px; white-space: pre-wrap; font-size: .92rem; }
.composer-tabs { display: flex; gap: 0; margin-bottom: -1px; }
.composer-tabs button { border-radius: 6px 6px 0 0; border-bottom: none; font-size: .85rem; }
.composer-tabs button.active-reply { background: #dbeafe; font-weight: 600; }
.composer-tabs button.active-internal { background: var(--warn-bg); font-weight: 600; }
.activity-item { font-size: .82rem; color: var(--muted); padding: 5px 0; border-bottom: 1px dashed #e5eaf0; }
.side-field { margin-bottom: 12px; }
.side-field .lbl { font-size: .75rem; text-transform: uppercase; color: var(--muted); font-weight: 600; margin-bottom: 3px; }
.side-field select, .side-field input { width: 100%; }

/* bars */
.bar-row { display: flex; align-items: center; gap: 10px; margin-bottom: 7px; font-size: .87rem; }
.bar-row .name { width: 130px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar-row .bar { height: 16px; background: var(--primary); border-radius: 3px; min-width: 2px; }
.bar-row .val { color: var(--muted); }
.chart14 { display: flex; align-items: flex-end; gap: 4px; height: 120px; margin-top: 10px; }
.chart14 .day { flex: 1; display: flex; flex-direction: column; justify-content: flex-end; gap: 2px; height: 100%; }
.chart14 .c { background: var(--primary); border-radius: 2px 2px 0 0; }
.chart14 .r { background: #22c55e; border-radius: 2px 2px 0 0; }
.legend { display: flex; gap: 16px; font-size: .78rem; color: var(--muted); margin-top: 6px; }
.legend .dot { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 5px; vertical-align: middle; }

/* auth screens */
.auth-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; }
.auth-box { background: var(--panel); border: 1px solid var(--border); border-radius: 12px; box-shadow: 0 10px 40px rgba(16,24,40,.1); padding: 34px; width: 400px; }
.auth-box h1 { text-align: center; }
.auth-box input { width: 100%; }
.auth-box button { width: 100%; margin-top: 18px; }
.auth-error { background: #fef2f2; color: var(--danger); border: 1px solid #fecaca; border-radius: 6px; padding: 9px 12px; font-size: .87rem; margin-top: 12px; }

/* modal */
.modal-backdrop { position: fixed; inset: 0; background: rgba(15,23,42,.45); display: flex; align-items: flex-start; justify-content: center; padding: 60px 20px; z-index: 100; overflow-y: auto; }
.modal { background: var(--panel); border-radius: 12px; width: 560px; max-width: 100%; padding: 24px; box-shadow: 0 20px 60px rgba(0,0,0,.25); }
.modal h2 { margin-top: 0; }

/* toast */
#toast-container { position: fixed; bottom: 20px; right: 20px; z-index: 200; display: flex; flex-direction: column; gap: 8px; }
.toast { background: #1c2733; color: #fff; padding: 10px 18px; border-radius: 8px; font-size: .9rem; box-shadow: 0 6px 20px rgba(0,0,0,.25); animation: fadein .2s; }
.toast.error { background: var(--danger); }
@keyframes fadein { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; } }

.muted { color: var(--muted); }
.small { font-size: .82rem; }
.mt0 { margin-top: 0; }
.empty { text-align: center; color: var(--muted); padding: 30px; }
.row-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 14px; }
.row-head h1 { margin: 0; }
