/* ============================================================
   TUS CRM — Үндсэн загвар
   ============================================================ */

@import url('https://fonts.googleapis.com/css2?family=IBM+Plex+Mono:wght@400;500;600&family=IBM+Plex+Sans:wght@300;400;500;600;700&display=swap');

:root {
  --bg:          #0f1117;
  --bg2:         #161b27;
  --bg3:         #1e2535;
  --border:      #2a3248;
  --border2:     #3a4560;
  --text:        #e8ecf4;
  --text2:       #8b97b5;
  --text3:       #5a6882;
  --accent:      #2dbdb6;       /* teal — TUS brand */
  --accent2:     #3dd6cf;
  --accent-dim:  rgba(45,189,182,0.12);
  --red:         #ef4444;
  --red-dim:     rgba(239,68,68,0.12);
  --green:       #22c55e;
  --green-dim:   rgba(34,197,94,0.12);
  --yellow:      #eab308;
  --yellow-dim:  rgba(234,179,8,0.12);
  --blue:        #3b82f6;
  --blue-dim:    rgba(59,130,246,0.12);
  --purple:      #a855f7;
  --purple-dim:  rgba(168,85,247,0.12);
  --sidebar-w:   240px;
  --topbar-h:    56px;
  --radius:      8px;
  --radius-sm:   4px;
  --shadow:      0 4px 24px rgba(0,0,0,0.4);
  --font:        'IBM Plex Sans', sans-serif;
  --mono:        'IBM Plex Mono', monospace;
  --transition:  0.15s ease;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.6;
}

a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent2); }

/* ── Layout ─────────────────────────────────────────────────── */
.app-shell { display: flex; height: 100vh; overflow: hidden; }

.sidebar {
  width: var(--sidebar-w);
  background: var(--bg2);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  z-index: 100;
}

.sidebar-logo {
  padding: 0 20px;
  height: var(--topbar-h);
  display: flex;
  align-items: center;
  gap: 10px;
  border-bottom: 1px solid var(--border);
  font-weight: 700;
  font-size: 15px;
  letter-spacing: -0.3px;
}

.sidebar-logo .logo-icon {
  width: 28px; height: 28px;
  background: var(--accent);
  border-radius: var(--radius-sm);
  display: grid;
  place-items: center;
  font-size: 14px;
  color: white;
  font-weight: 700;
}

.sidebar-logo .logo-text { color: var(--text); }
.sidebar-logo .logo-version {
  font-size: 10px;
  color: var(--text3);
  font-family: var(--mono);
  margin-left: auto;
}

.sidebar-nav {
  flex: 1;
  padding: 12px 0;
  overflow-y: auto;
}

.nav-section {
  padding: 4px 12px 2px;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 1px;
  text-transform: uppercase;
  color: var(--text3);
  margin-top: 12px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 16px;
  color: var(--text2);
  font-size: 13.5px;
  cursor: pointer;
  border-left: 2px solid transparent;
  transition: all var(--transition);
  position: relative;
}

.nav-item:hover { color: var(--text); background: var(--bg3); }
.nav-item.active { color: var(--accent); border-left-color: var(--accent); background: var(--accent-dim); }
.nav-item .nav-icon { width: 16px; text-align: center; flex-shrink: 0; }

.nav-badge {
  margin-left: auto;
  background: var(--accent);
  color: white;
  font-size: 10px;
  font-weight: 700;
  font-family: var(--mono);
  padding: 1px 6px;
  border-radius: 10px;
  min-width: 18px;
  text-align: center;
}

.sidebar-footer {
  padding: 12px;
  border-top: 1px solid var(--border);
}

.user-card {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px;
  border-radius: var(--radius);
  cursor: pointer;
  transition: background var(--transition);
}
.user-card:hover { background: var(--bg3); }
.user-avatar {
  width: 32px; height: 32px;
  border-radius: 50%;
  background: var(--accent-dim);
  border: 1px solid var(--accent);
  display: grid;
  place-items: center;
  font-size: 12px;
  font-weight: 700;
  color: var(--accent);
  flex-shrink: 0;
}
.user-info { flex: 1; min-width: 0; }
.user-name { font-size: 12.5px; font-weight: 600; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-role { font-size: 11px; color: var(--text3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ── Main ───────────────────────────────────────────────────── */
.main-area { flex: 1; display: flex; flex-direction: column; min-width: 0; overflow: hidden; }

.topbar {
  height: var(--topbar-h);
  background: var(--bg2);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 24px;
  gap: 16px;
  flex-shrink: 0;
}

.topbar-title { font-size: 15px; font-weight: 600; color: var(--text); }
.topbar-sub { font-size: 12px; color: var(--text3); font-family: var(--mono); }
.topbar-spacer { flex: 1; }

.page-content { flex: 1; overflow-y: auto; padding: 24px; }

/* ── Cards ──────────────────────────────────────────────────── */
.card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.card-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 12px;
}
.card-title { font-size: 14px; font-weight: 600; }
.card-body { padding: 20px; }

/* ── Stats ──────────────────────────────────────────────────── */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 12px;
  margin-bottom: 24px;
}

.stat-card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  position: relative;
  overflow: hidden;
}
.stat-card::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 2px;
  background: var(--c, var(--accent));
}
.stat-value { font-size: 28px; font-weight: 700; font-family: var(--mono); color: var(--text); line-height: 1; }
.stat-label { font-size: 11px; color: var(--text3); margin-top: 4px; text-transform: uppercase; letter-spacing: 0.5px; }
.stat-card.urgent  { --c: var(--red); }
.stat-card.high    { --c: var(--yellow); }
.stat-card.green   { --c: var(--green); }
.stat-card.blue    { --c: var(--blue); }
.stat-card.accent  { --c: var(--accent); }

/* ── Ticket Table ───────────────────────────────────────────── */
.ticket-table { width: 100%; border-collapse: collapse; }
.ticket-table thead tr { border-bottom: 1px solid var(--border2); }
.ticket-table th {
  text-align: left;
  padding: 8px 16px;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: var(--text3);
  font-weight: 600;
}
.ticket-table tbody tr {
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  transition: background var(--transition);
}
.ticket-table tbody tr:hover { background: var(--bg3); }
.ticket-table td { padding: 12px 16px; font-size: 13px; }

.ticket-num { font-family: var(--mono); font-size: 12px; color: var(--text2); }
.ticket-title { color: var(--text); font-weight: 500; }
.ticket-customer { color: var(--text2); font-size: 12px; }

/* ── Badges ─────────────────────────────────────────────────── */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: var(--radius-sm);
  font-size: 11px;
  font-weight: 600;
  font-family: var(--mono);
  letter-spacing: 0.3px;
}
.badge-urgent    { background: var(--red-dim);    color: var(--red);    border: 1px solid rgba(239,68,68,0.3); }
.badge-high      { background: var(--yellow-dim); color: var(--yellow); border: 1px solid rgba(234,179,8,0.3); }
.badge-normal    { background: var(--blue-dim);   color: var(--blue);   border: 1px solid rgba(59,130,246,0.3); }
.badge-low       { background: var(--bg3);        color: var(--text3);  border: 1px solid var(--border); }
.badge-new       { background: var(--purple-dim); color: var(--purple); border: 1px solid rgba(168,85,247,0.3); }
.badge-open      { background: var(--accent-dim); color: var(--accent); border: 1px solid rgba(249,115,22,0.3); }
.badge-inprogress{ background: var(--blue-dim);   color: var(--blue);   border: 1px solid rgba(59,130,246,0.3); }
.badge-pending   { background: var(--yellow-dim); color: var(--yellow); border: 1px solid rgba(234,179,8,0.3); }
.badge-escalated { background: var(--red-dim);    color: var(--red);    border: 1px solid rgba(239,68,68,0.3); }
.badge-resolved  { background: var(--green-dim);  color: var(--green);  border: 1px solid rgba(34,197,94,0.3); }
.badge-closed    { background: var(--bg3);        color: var(--text3);  border: 1px solid var(--border); }

/* ── Buttons ────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 14px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  border: 1px solid transparent;
  transition: all var(--transition);
  font-family: var(--font);
  white-space: nowrap;
}
.btn-primary { background: var(--accent); color: white; border-color: var(--accent); }
.btn-primary:hover { background: var(--accent2); }
.btn-secondary { background: var(--bg3); color: var(--text); border-color: var(--border); }
.btn-secondary:hover { border-color: var(--border2); background: var(--border); }
.btn-danger { background: var(--red-dim); color: var(--red); border-color: rgba(239,68,68,0.3); }
.btn-danger:hover { background: var(--red); color: white; }
.btn-ghost { background: transparent; color: var(--text2); border-color: transparent; }
.btn-ghost:hover { color: var(--text); background: var(--bg3); }
.btn-sm { padding: 4px 10px; font-size: 12px; }
.btn-icon { padding: 6px; width: 32px; height: 32px; justify-content: center; }

/* ── Forms ──────────────────────────────────────────────────── */
.form-group { margin-bottom: 16px; }
.form-label { display: block; font-size: 12px; font-weight: 600; color: var(--text2); margin-bottom: 6px; text-transform: uppercase; letter-spacing: 0.5px; }
.form-control {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 8px 12px;
  color: var(--text);
  font-size: 13.5px;
  font-family: var(--font);
  transition: border-color var(--transition);
  outline: none;
}
.form-control:focus { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-dim); }
.form-control::placeholder { color: var(--text3); }
textarea.form-control { resize: vertical; min-height: 80px; }

/* ── Ticket Detail ──────────────────────────────────────────── */
.detail-layout { display: grid; grid-template-columns: 1fr 300px; gap: 20px; align-items: start; }
@media (max-width: 900px) { .detail-layout { grid-template-columns: 1fr; } }

.workflow-steps { display: flex; flex-direction: column; gap: 0; }
.step-item {
  display: flex;
  gap: 12px;
  padding-bottom: 16px;
  position: relative;
}
.step-item:not(:last-child)::before {
  content: '';
  position: absolute;
  left: 15px;
  top: 30px;
  bottom: 0;
  width: 2px;
  background: var(--border);
}
.step-dot {
  width: 30px; height: 30px;
  border-radius: 50%;
  border: 2px solid var(--border);
  background: var(--bg);
  display: grid;
  place-items: center;
  font-size: 12px;
  flex-shrink: 0;
  position: relative;
  z-index: 1;
}
.step-item.completed .step-dot { background: var(--green-dim); border-color: var(--green); color: var(--green); }
.step-item.active .step-dot    { background: var(--accent-dim); border-color: var(--accent); color: var(--accent); animation: pulse 2s infinite; }
.step-item.pending .step-dot   { background: var(--bg2); color: var(--text3); }

@keyframes pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(249,115,22,0.4); }
  50%       { box-shadow: 0 0 0 6px rgba(249,115,22,0); }
}

.step-info { flex: 1; padding-top: 4px; }
.step-role { font-size: 13px; font-weight: 600; }
.step-meta { font-size: 11px; color: var(--text3); margin-top: 2px; }
.step-notes { font-size: 12px; color: var(--text2); margin-top: 4px; padding: 6px 8px; background: var(--bg3); border-radius: var(--radius-sm); border-left: 2px solid var(--border); }

/* ── Comments ───────────────────────────────────────────────── */
.comment-thread { display: flex; flex-direction: column; gap: 12px; }
.comment {
  display: flex;
  gap: 10px;
}
.comment-avatar { width: 28px; height: 28px; border-radius: 50%; background: var(--bg3); border: 1px solid var(--border); display: grid; place-items: center; font-size: 11px; font-weight: 700; color: var(--text2); flex-shrink: 0; }
.comment-bubble { flex: 1; }
.comment-meta { display: flex; align-items: center; gap: 8px; margin-bottom: 4px; }
.comment-author { font-size: 12.5px; font-weight: 600; }
.comment-time { font-size: 11px; color: var(--text3); font-family: var(--mono); }
.comment-type-badge { font-size: 9px; padding: 1px 5px; background: var(--bg3); border: 1px solid var(--border); border-radius: 3px; color: var(--text3); font-family: var(--mono); }
.comment-body { font-size: 13px; line-height: 1.7; color: var(--text2); background: var(--bg3); padding: 10px 14px; border-radius: var(--radius); border: 1px solid var(--border); }
.comment-body.system { background: var(--yellow-dim); border-color: rgba(234,179,8,0.2); color: var(--yellow); font-style: italic; }

/* ── Filters ────────────────────────────────────────────────── */
.filter-bar {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
  margin-bottom: 16px;
}
.filter-select {
  background: var(--bg2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 6px 10px;
  border-radius: var(--radius-sm);
  font-size: 12.5px;
  font-family: var(--font);
  cursor: pointer;
}
.search-input {
  background: var(--bg2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 6px 12px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-family: var(--font);
  width: 220px;
}
.search-input:focus { outline: none; border-color: var(--accent); }

/* ── Notifications ──────────────────────────────────────────── */
.notif-dot {
  width: 8px; height: 8px;
  background: var(--red);
  border-radius: 50%;
  position: absolute;
  top: 8px; right: 8px;
  animation: pulse 2s infinite;
}

/* ── Toast ──────────────────────────────────────────────────── */
#toast-container {
  position: fixed;
  bottom: 24px; right: 24px;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.toast {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 16px;
  font-size: 13px;
  box-shadow: var(--shadow);
  animation: slideIn 0.2s ease;
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 280px;
}
.toast.success { border-left: 3px solid var(--green); }
.toast.error   { border-left: 3px solid var(--red); }
.toast.info    { border-left: 3px solid var(--blue); }

@keyframes slideIn { from { transform: translateX(20px); opacity: 0; } to { transform: none; opacity: 1; } }

/* ── Modal ──────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.7);
  z-index: 500;
  display: none;
  place-items: center;
}
.modal-overlay.open { display: grid; }
.modal {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  width: min(520px, 90vw);
  box-shadow: var(--shadow);
  animation: modalIn 0.15s ease;
}
.modal-header { padding: 16px 20px; border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; }
.modal-body { padding: 20px; }
.modal-footer { padding: 16px 20px; border-top: 1px solid var(--border); display: flex; gap: 8px; justify-content: flex-end; }
@keyframes modalIn { from { transform: scale(0.95); opacity: 0; } to { transform: none; opacity: 1; } }

/* ── Login ──────────────────────────────────────────────────── */
.login-page { min-height: 100vh; display: grid; place-items: center; background: var(--bg); }
.login-card { width: min(400px, 90vw); }
.login-logo { text-align: center; margin-bottom: 32px; }
.login-logo-icon {
  width: 56px; height: 56px;
  background: var(--accent);
  border-radius: var(--radius);
  display: inline-grid;
  place-items: center;
  font-size: 24px;
  font-weight: 900;
  color: white;
  margin-bottom: 12px;
}
.login-title { font-size: 22px; font-weight: 700; }
.login-sub { color: var(--text3); font-size: 13px; margin-top: 4px; }
.login-error { background: var(--red-dim); border: 1px solid rgba(239,68,68,0.3); color: var(--red); padding: 10px 14px; border-radius: var(--radius-sm); font-size: 13px; margin-bottom: 16px; }

/* ── Utilities ──────────────────────────────────────────────── */
.text-muted   { color: var(--text3); }
.text-sm      { font-size: 12px; }
.mono         { font-family: var(--mono); }
.flex         { display: flex; }
.flex-center  { display: flex; align-items: center; }
.gap-8        { gap: 8px; }
.gap-12       { gap: 12px; }
.ml-auto      { margin-left: auto; }
.mt-8         { margin-top: 8px; }
.mt-16        { margin-top: 16px; }
.mt-24        { margin-top: 24px; }
.mb-16        { margin-bottom: 16px; }
.p-0          { padding: 0 !important; }
.w-full       { width: 100%; }
.truncate     { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.divider      { border: none; border-top: 1px solid var(--border); margin: 16px 0; }
.overdue-row  { border-left: 2px solid var(--red) !important; }
.category-dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 6px; }
.sla-bar { height: 3px; border-radius: 2px; background: var(--border); overflow: hidden; margin-top: 4px; }
.sla-fill { height: 100%; border-radius: 2px; transition: width 0.3s; }
