/* ===== Base / Reset ===== */
:root {
  --brand: #3c50e0;
  --brand-dark: #2a3ab0;
  --bg: #f1f5f9;
  --surface: #ffffff;
  --text: #1f2937;
  --muted: #64748b;
  --border: #e2e8f0;
  --green: #10b981;
  --green-bg: #d1fae5;
  --red: #ef4444;
  --red-bg: #fee2e2;
  --amber: #f59e0b;
  --amber-bg: #fef3c7;
  --blue-bg: #dbeafe;
  --sidebar-w: 264px;
  --radius: 10px;
  --shadow: 0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.04);
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Inter, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--brand); text-decoration: none; }
button { cursor: pointer; font-family: inherit; }

/* ===== Layout ===== */
#app { display: flex; min-height: 100vh; }
.sidebar {
  width: var(--sidebar-w);
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; bottom: 0; left: 0;
  z-index: 40;
  transition: transform .2s ease;
}
.brand {
  display: flex; align-items: center; gap: 10px;
  padding: 20px;
  border-bottom: 1px solid var(--border);
}
.brand-logo {
  width: 36px; height: 36px; border-radius: 8px;
  background: var(--brand); color: #fff;
  display: grid; place-items: center; font-weight: 700; font-size: 14px;
}
.brand-name { font-weight: 700; font-size: 16px; }
.nav { padding: 14px 12px; overflow-y: auto; flex: 1; }
.nav-group-label {
  font-size: 11px; text-transform: uppercase; letter-spacing: .06em;
  color: var(--muted); padding: 12px 10px 6px;
}
.nav-item {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 12px; border-radius: 8px;
  color: var(--text); font-weight: 500;
  margin-bottom: 2px;
  transition: background .1s;
  width: 100%; border: none; background: transparent; text-align: left;
}
.nav-item:hover { background: #f1f5f9; }
.nav-item.active { background: var(--blue-bg); color: var(--brand); }
.nav-item .ico { width: 20px; text-align: center; }
.nav-item .chev { margin-left: auto; font-size: 10px; color: var(--muted); }
.nav-sub { margin-left: 34px; }
.nav-sub .nav-item { padding: 7px 12px; font-size: 13px; }

.main { flex: 1; margin-left: var(--sidebar-w); display: flex; flex-direction: column; }
.topbar {
  display: flex; align-items: center; gap: 16px;
  height: 64px; padding: 0 24px;
  background: var(--surface); border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 30;
}
.topbar-title { font-weight: 700; font-size: 18px; }
.topbar-user { margin-left: auto; display: flex; align-items: center; gap: 10px; }
.avatar {
  width: 34px; height: 34px; border-radius: 50%;
  background: var(--brand); color: #fff; display: grid; place-items: center; font-weight: 600;
}
.username { font-weight: 500; }
.icon-btn {
  background: none; border: 1px solid var(--border); border-radius: 8px;
  width: 38px; height: 38px; font-size: 16px; color: var(--text);
  display: none;
}
.content { padding: 24px; flex: 1; }

/* ===== Components ===== */
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow);
}
.card-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 20px; border-bottom: 1px solid var(--border);
}
.card-title { font-weight: 600; font-size: 16px; }
.card-body { padding: 20px; }

.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 16px; border-radius: 8px;
  border: 1px solid transparent; font-weight: 500; font-size: 13px;
  transition: opacity .1s;
}
.btn-primary { background: var(--brand); color: #fff; }
.btn-primary:hover { background: var(--brand-dark); }
.btn-outline { background: #fff; border-color: var(--border); color: var(--text); }
.btn-outline:hover { background: #f1f5f9; }
.btn-danger { background: var(--red); color: #fff; }
.btn-success { background: var(--green); color: #fff; }
.btn-sm { padding: 5px 10px; font-size: 12px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

.btn-group { display: flex; gap: 8px; flex-wrap: wrap; }

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 20px; }
.tab {
  padding: 10px 16px; border: none; background: none; font-weight: 500;
  color: var(--muted); border-bottom: 2px solid transparent;
}
.tab.active { color: var(--brand); border-bottom-color: var(--brand); }

.stat-grid {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 16px;
}
.stat {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow);
}
.stat .label { color: var(--muted); font-size: 13px; }
.stat .value { font-size: 30px; font-weight: 700; margin-top: 6px; }
.stat .trend { font-size: 12px; margin-top: 4px; }
.trend.up { color: var(--green); }

.table { width: 100%; border-collapse: collapse; }
.table th, .table td { text-align: left; padding: 12px 16px; border-bottom: 1px solid var(--border); }
.table th { font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
.table tr:last-child td { border-bottom: none; }
.table tr:hover td { background: #f8fafc; }

.badge {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 10px; border-radius: 999px; font-size: 12px; font-weight: 600;
}
.badge-green { background: var(--green-bg); color: #047857; }
.badge-red { background: var(--red-bg); color: #b91c1c; }
.badge-amber { background: var(--amber-bg); color: #b45309; }
.badge-blue { background: var(--blue-bg); color: #1d4ed8; }
.dot { width: 7px; height: 7px; border-radius: 50%; display: inline-block; }
.dot-green { background: var(--green); }
.dot-red { background: var(--red); }

.input, .select, .textarea {
  width: 100%; padding: 9px 12px; border: 1px solid var(--border);
  border-radius: 8px; font-family: inherit; font-size: 14px; background: #fff;
}
.input:focus, .select:focus, .textarea:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px rgba(60,80,224,.12); }
.field { margin-bottom: 16px; }
.field label { display: block; font-weight: 500; margin-bottom: 6px; font-size: 13px; }

.empty { text-align: center; color: var(--muted); padding: 40px; }

/* ===== Search bar ===== */
.search-bar { display: flex; gap: 10px; align-items: center; }
.search-bar .input { max-width: 320px; }

/* ===== Inbox / Chat ===== */
.inbox-wrap { display: flex; gap: 20px; height: calc(100vh - 180px); }
.ticket-list {
  width: 360px; flex-shrink: 0; display: flex; flex-direction: column;
  border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden;
  background: var(--surface);
}
.ticket-list .list-head { padding: 14px; border-bottom: 1px solid var(--border); font-weight: 600; }
.ticket-list .list-body { overflow-y: auto; flex: 1; }
.ticket-item {
  display: flex; flex-direction: column; gap: 4px; padding: 14px 16px;
  border-bottom: 1px solid var(--border); cursor: pointer;
}
.ticket-item:hover { background: #f8fafc; }
.ticket-item.active { background: var(--blue-bg); }
.ticket-item .row { display: flex; justify-content: space-between; align-items: center; }
.ticket-item .name { font-weight: 600; }
.ticket-item .ticket { font-size: 12px; color: var(--muted); }
.ticket-item .muted { font-size: 12px; color: var(--muted); }

.chat-window {
  flex: 1; display: flex; flex-direction: column;
  border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden;
  background: var(--surface);
}
.chat-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 18px; border-bottom: 1px solid var(--border);
}
.chat-head .name { font-weight: 700; font-size: 16px; }
.chat-head .sub { font-size: 12px; color: var(--muted); }
.chat-body { flex: 1; overflow-y: auto; padding: 20px; background: #f8fafc; }
.msg { display: flex; margin-bottom: 12px; }
.msg .bubble {
  max-width: 70%; padding: 10px 14px; border-radius: 12px;
  font-size: 14px; line-height: 1.5;
}
.msg.me { justify-content: flex-end; }
.msg.me .bubble { background: var(--brand); color: #fff; border-bottom-right-radius: 4px; }
.msg.them { justify-content: flex-start; }
.msg.them .bubble { background: #fff; border: 1px solid var(--border); border-bottom-left-radius: 4px; }
.msg .time { font-size: 11px; color: var(--muted); margin-top: 4px; text-align: right; }
.chat-input { display: flex; gap: 10px; padding: 14px; border-top: 1px solid var(--border); }

.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  background: #1f2937; color: #fff; padding: 12px 20px; border-radius: 8px;
  box-shadow: 0 8px 20px rgba(0,0,0,.2); z-index: 200; font-size: 14px;
  animation: toast-in .2s ease;
}
@keyframes toast-in { from { opacity: 0; transform: translate(-50%, 8px); } to { opacity: 1; transform: translate(-50%, 0); } }

/* ===== Login ===== */
.login-wrap {
  min-height: 100vh; display: grid; place-items: center;
  background: linear-gradient(135deg, var(--brand), var(--brand-dark));
  padding: 20px;
}
.login-card {
  width: 400px; max-width: 100%; background: #fff; border-radius: 14px;
  box-shadow: 0 20px 40px rgba(0,0,0,.2); padding: 32px;
}
.login-title { font-size: 20px; font-weight: 700; margin-bottom: 20px; }
.login-err { color: var(--red); font-size: 13px; margin-bottom: 12px; min-height: 18px; }
.login-wrap .brand .brand-logo { width: 44px; height: 44px; font-size: 18px; }
.login-wrap .brand .brand-name { font-size: 20px; }

/* ===== Modal ===== */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,.4);
  display: grid; place-items: center; z-index: 100;
}
.modal {
  background: #fff; border-radius: 12px; width: 520px; max-width: 92vw;
  max-height: 90vh; overflow-y: auto; box-shadow: 0 20px 40px rgba(0,0,0,.2);
}
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 18px 22px; border-bottom: 1px solid var(--border); }
.modal-title { font-weight: 700; font-size: 16px; }
.modal-close { background: none; border: none; font-size: 20px; color: var(--muted); }
.modal-body { padding: 22px; }
.modal-foot { padding: 16px 22px; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: 10px; }

/* ===== Detail agent panel ===== */
.agent-detail { display: grid; grid-template-columns: 240px 1fr; gap: 24px; }
.agent-nav { display: flex; flex-direction: column; gap: 4px; }
.agent-nav .nav-item { border-radius: 8px; }
.agent-panel { min-height: 400px; }

/* ===== Responsive ===== */
@media (max-width: 900px) {
  .sidebar { transform: translateX(-100%); }
  .sidebar.open { transform: translateX(0); }
  .main { margin-left: 0; }
  .icon-btn { display: grid; place-items: center; }
  .inbox-wrap { flex-direction: column; height: auto; }
  .ticket-list { width: 100%; max-height: 320px; }
  .agent-detail { grid-template-columns: 1fr; }
}
