/* ============================================================
   Email Ticket Support System — Main Stylesheet
   ============================================================ */

:root {
  --brand:        #4f46e5;
  --brand-hover:  #4338ca;
  --brand-light:  #ede9fe;
  --sidebar-bg:   #1e1b4b;
  --sidebar-text: #c7d2fe;
  --sidebar-hover:#312e81;
  --sidebar-active:#4f46e5;
  --bg:           #f8fafc;
  --surface:      #ffffff;
  --border:       #e2e8f0;
  --text:         #1e293b;
  --text-muted:   #64748b;
  --danger:       #ef4444;
  --success:      #22c55e;
  --warning:      #f59e0b;
  --info:         #3b82f6;
  --radius:       8px;
  --shadow:       0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.06);
  --shadow-md:    0 4px 6px -1px rgba(0,0,0,.1), 0 2px 4px -2px rgba(0,0,0,.1);
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
}

a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ── Layout ──────────────────────────────────────────────── */
.layout { display: flex; min-height: 100vh; }

.sidebar {
  width: 240px;
  flex-shrink: 0;
  background: var(--sidebar-bg);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  z-index: 100;
  overflow-y: auto;
}

.sidebar-logo {
  padding: 20px 20px 12px;
  border-bottom: 1px solid rgba(255,255,255,.08);
}
.sidebar-logo h1 {
  font-size: 16px;
  font-weight: 700;
  color: #fff;
  letter-spacing: -.3px;
}
.sidebar-logo span { color: var(--sidebar-text); font-size: 12px; }

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

.nav-section { padding: 4px 12px; margin-top: 8px; }
.nav-section-label {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: rgba(199,210,254,.4);
  margin-bottom: 4px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  border-radius: 6px;
  color: var(--sidebar-text);
  font-weight: 500;
  font-size: 13.5px;
  transition: background .15s, color .15s;
  cursor: pointer;
}
.nav-item:hover { background: var(--sidebar-hover); color: #fff; text-decoration: none; }
.nav-item.active { background: var(--sidebar-active); color: #fff; }
.nav-item svg { width: 16px; height: 16px; opacity: .8; flex-shrink: 0; }
.nav-item .badge {
  margin-left: auto;
  background: rgba(255,255,255,.15);
  color: #fff;
  font-size: 11px;
  font-weight: 600;
  padding: 1px 7px;
  border-radius: 99px;
}

.sidebar-footer {
  padding: 12px 16px;
  border-top: 1px solid rgba(255,255,255,.08);
}
.sidebar-user {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--sidebar-text);
  font-size: 13px;
}
.sidebar-avatar {
  width: 32px; height: 32px;
  border-radius: 50%;
  background: var(--sidebar-active);
  display: flex; align-items: center; justify-content: center;
  color: #fff; font-weight: 700; font-size: 13px;
  flex-shrink: 0;
}
.sidebar-user-info { min-width: 0; }
.sidebar-user-name { color: #fff; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sidebar-user-role { font-size: 11px; text-transform: capitalize; }

.main {
  margin-left: 240px;
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 12px 24px;
  display: flex;
  align-items: center;
  gap: 16px;
  position: sticky; top: 0;
  z-index: 50;
}
.topbar-title { font-size: 18px; font-weight: 700; flex: 1; }
.topbar-actions { display: flex; align-items: center; gap: 10px; }

.content { padding: 24px; flex: 1; }

/* ── Cards ───────────────────────────────────────────────── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.card-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 12px;
}
.card-header h2 { font-size: 15px; font-weight: 600; flex: 1; }
.card-body { padding: 20px; }

/* ── Stat Cards ──────────────────────────────────────────── */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}
.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
}
.stat-card .label { font-size: 12px; color: var(--text-muted); font-weight: 500; text-transform: uppercase; letter-spacing: .05em; }
.stat-card .value { font-size: 32px; font-weight: 800; margin-top: 4px; line-height: 1; }
.stat-card .sub   { font-size: 12px; color: var(--text-muted); margin-top: 4px; }
.stat-open        { border-top: 3px solid var(--info); }
.stat-inprogress  { border-top: 3px solid var(--warning); }
.stat-resolved    { border-top: 3px solid var(--success); }
.stat-urgent      { border-top: 3px solid var(--danger); }

/* ── Tables ──────────────────────────────────────────────── */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
thead th {
  text-align: left;
  padding: 10px 16px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--text-muted);
  background: #f8fafc;
  border-bottom: 1px solid var(--border);
}
tbody td {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: #f8fafc; }

.ticket-row { cursor: pointer; }
.ticket-subject { font-weight: 600; color: var(--text); display: block; }
.ticket-preview { font-size: 12px; color: var(--text-muted); margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 380px; }
.ticket-meta    { font-size: 12px; color: var(--text-muted); }

/* ── Badges ──────────────────────────────────────────────── */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 10px;
  border-radius: 99px;
  font-size: 11px;
  font-weight: 600;
  text-transform: capitalize;
  white-space: nowrap;
}
.badge-open       { background: #dbeafe; color: #1d4ed8; }
.badge-inprogress { background: #fef3c7; color: #92400e; }
.badge-pending    { background: #f3f4f6; color: #374151; }
.badge-resolved   { background: #dcfce7; color: #15803d; }
.badge-closed     { background: #f3f4f6; color: #6b7280; }
.badge-urgent     { background: #fee2e2; color: #dc2626; }
.badge-high       { background: #ffedd5; color: #c2410c; }
.badge-medium     { background: #fef3c7; color: #92400e; }
.badge-low        { background: #f0fdf4; color: #166534; }

/* ── Buttons ─────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border-radius: var(--radius);
  font-size: 13.5px;
  font-weight: 600;
  cursor: pointer;
  border: 1px solid transparent;
  transition: background .15s, border-color .15s, opacity .15s;
  text-decoration: none !important;
  line-height: 1.4;
}
.btn:disabled { opacity: .6; cursor: not-allowed; }
.btn-primary  { background: var(--brand); color: #fff; border-color: var(--brand); }
.btn-primary:hover { background: var(--brand-hover); }
.btn-secondary { background: var(--surface); color: var(--text); border-color: var(--border); }
.btn-secondary:hover { background: var(--bg); }
.btn-danger   { background: var(--danger); color: #fff; }
.btn-danger:hover { opacity: .9; }
.btn-sm       { padding: 5px 12px; font-size: 12px; }
.btn-ghost    { background: transparent; border-color: transparent; color: var(--text-muted); }
.btn-ghost:hover { background: var(--bg); color: var(--text); }

/* ── Forms ───────────────────────────────────────────────── */
.form-group   { margin-bottom: 16px; }
.form-label   { display: block; font-weight: 600; font-size: 13px; margin-bottom: 6px; }
.form-control {
  width: 100%;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 14px;
  color: var(--text);
  background: var(--surface);
  transition: border-color .15s, box-shadow .15s;
}
.form-control:focus {
  outline: none;
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(79,70,229,.1);
}
.form-control::placeholder { color: var(--text-muted); }
select.form-control { cursor: pointer; }
textarea.form-control { resize: vertical; min-height: 120px; }
.form-hint { font-size: 12px; color: var(--text-muted); margin-top: 4px; }

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

/* ── Alert / Flash ───────────────────────────────────────── */
.alert {
  padding: 12px 16px;
  border-radius: var(--radius);
  margin-bottom: 16px;
  font-size: 13.5px;
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 10px;
}
.alert-success { background: #dcfce7; color: #15803d; border: 1px solid #86efac; }
.alert-error   { background: #fee2e2; color: #dc2626; border: 1px solid #fca5a5; }
.alert-info    { background: #dbeafe; color: #1d4ed8; border: 1px solid #93c5fd; }

/* ── Ticket thread ───────────────────────────────────────── */
.thread { display: flex; flex-direction: column; gap: 12px; }

.message-bubble {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--surface);
  box-shadow: var(--shadow);
}
.message-bubble.outbound { border-left: 3px solid var(--brand); }
.message-bubble.note     { border-left: 3px solid var(--warning); background: #fffbeb; }

.message-header {
  padding: 10px 16px;
  background: #f8fafc;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}
.message-header.outbound { background: var(--brand-light); }
.message-header.note     { background: #fef3c7; }

.msg-avatar {
  width: 28px; height: 28px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 11px; font-weight: 700; color: #fff;
  flex-shrink: 0;
}
.msg-avatar.customer  { background: #94a3b8; }
.msg-avatar.agent     { background: var(--brand); }
.msg-avatar.note-av   { background: var(--warning); }

.msg-sender       { font-weight: 600; font-size: 13px; }
.msg-email        { font-size: 12px; color: var(--text-muted); }
.msg-time         { margin-left: auto; font-size: 12px; color: var(--text-muted); }
.msg-type-label   { font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; padding: 2px 8px; border-radius: 99px; }
.type-outbound    { background: var(--brand); color: #fff; }
.type-note        { background: var(--warning); color: #fff; }
.type-inbound     { background: #94a3b8; color: #fff; }

.message-body { padding: 16px; font-size: 14px; line-height: 1.7; }
.message-body p { margin-bottom: 8px; }
.message-body p:last-child { margin-bottom: 0; }

/* ── Reply composer ──────────────────────────────────────── */
.composer {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
}
.composer-tabs {
  display: flex;
  border-bottom: 1px solid var(--border);
  background: #f8fafc;
}
.composer-tab {
  padding: 10px 20px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  color: var(--text-muted);
  transition: color .15s, border-color .15s;
  background: none; border-top: none; border-left: none; border-right: none;
}
.composer-tab.active { color: var(--brand); border-bottom-color: var(--brand); }
.composer-body { padding: 16px; }

/* ── Sidebar ticket detail panel ─────────────────────────── */
.ticket-layout { display: flex; gap: 24px; align-items: flex-start; }
.ticket-main   { flex: 1; min-width: 0; }
.ticket-sidebar {
  width: 280px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.info-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
}
.info-card h3 { font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; color: var(--text-muted); margin-bottom: 12px; }
.info-row { display: flex; flex-direction: column; gap: 2px; margin-bottom: 12px; }
.info-row:last-child { margin-bottom: 0; }
.info-label { font-size: 11px; color: var(--text-muted); font-weight: 600; }
.info-value { font-size: 13.5px; font-weight: 500; }

/* ── Activity log ────────────────────────────────────────── */
.activity-list { display: flex; flex-direction: column; gap: 8px; }
.activity-item {
  display: flex;
  gap: 8px;
  font-size: 12px;
  color: var(--text-muted);
  align-items: flex-start;
}
.activity-dot {
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--text-muted);
  flex-shrink: 0;
  margin-top: 5px;
}

/* ── Login page ──────────────────────────────────────────── */
.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
}
.login-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: var(--shadow-md);
  padding: 40px;
  width: 100%;
  max-width: 420px;
}
.login-logo {
  text-align: center;
  margin-bottom: 28px;
}
.login-logo h1 { font-size: 24px; font-weight: 800; color: var(--brand); }
.login-logo p  { color: var(--text-muted); font-size: 13px; margin-top: 4px; }

/* ── Filter bar ──────────────────────────────────────────── */
.filter-bar {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  align-items: center;
  padding: 12px 16px;
  background: #f8fafc;
  border-bottom: 1px solid var(--border);
}
.filter-bar select,
.filter-bar input { font-size: 13px; padding: 6px 10px; }

/* ── Pagination ──────────────────────────────────────────── */
.pagination { display: flex; gap: 4px; justify-content: center; margin-top: 20px; }
.page-btn {
  padding: 6px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 13px;
  cursor: pointer;
  background: var(--surface);
}
.page-btn.active { background: var(--brand); color: #fff; border-color: var(--brand); }

/* ── Empty state ─────────────────────────────────────────── */
.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-muted);
}
.empty-state svg { width: 48px; height: 48px; margin-bottom: 12px; opacity: .3; }
.empty-state h3  { font-size: 16px; color: var(--text); margin-bottom: 6px; }

/* ── Utilities ───────────────────────────────────────────── */
.flex        { display: flex; }
.items-center{ align-items: center; }
.gap-8       { gap: 8px; }
.gap-12      { gap: 12px; }
.gap-16      { gap: 16px; }
.mb-16       { margin-bottom: 16px; }
.mb-24       { margin-bottom: 24px; }
.mt-auto     { margin-top: auto; }
.text-muted  { color: var(--text-muted); }
.text-sm     { font-size: 12px; }
.font-bold   { font-weight: 700; }
.truncate    { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ── Charts wrapper ──────────────────────────────────────── */
.chart-container { position: relative; height: 240px; }

@media (max-width: 900px) {
  .ticket-layout { flex-direction: column; }
  .ticket-sidebar { width: 100%; }
  .form-row { grid-template-columns: 1fr; }
}
