:root {
  --primary: #fdca58;
  --primary-dark: #f0b82e;
  --primary-faint: #fff8e6;
  --dark: #111827;
  --body: #374151;
  --muted: #6b7280;
  --border: #e5e7eb;
  --bg: #f3f4f6;
  --card: #ffffff;
  --radius: 10px;
  --radius-sm: 6px;
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.07), 0 1px 2px rgba(0,0,0,0.04);
  --shadow: 0 4px 16px rgba(0,0,0,0.08);
  --shadow-lg: 0 12px 40px rgba(0,0,0,0.12);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: "Space Grotesk", system-ui, sans-serif;
  background: var(--bg);
  color: var(--body);
  font-size: 15px;
  line-height: 1.5;
}

/* ── Topbar ─────────────────────────────────── */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  height: 56px;
  background: var(--card);
  border-bottom: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
  position: sticky;
  top: 0;
  z-index: 100;
}
.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
  font-size: 16px;
  color: var(--dark);
  text-decoration: none;
}
.brand img { height: 28px; }
nav { display: flex; align-items: center; gap: 2px; }
nav a {
  padding: 6px 12px;
  border-radius: var(--radius-sm);
  text-decoration: none;
  color: var(--muted);
  font-weight: 500;
  font-size: 14px;
  transition: background 0.15s, color 0.15s;
  white-space: nowrap;
}
nav a:hover { background: var(--bg); color: var(--dark); }
nav a.active { background: var(--primary-faint); color: var(--dark); font-weight: 600; }
nav a.nav-logout:hover { background: #fef2f2; color: #dc2626; }

/* ── Layout ──────────────────────────────────── */
.container {
  max-width: 1160px;
  margin: 0 auto;
  padding: 28px 20px;
}

/* ── Cards ───────────────────────────────────── */
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px 24px;
  margin-bottom: 16px;
  box-shadow: var(--shadow-sm);
}
.card h2 { margin: 0 0 16px; font-size: 18px; font-weight: 700; color: var(--dark); }
.card h3 { margin: 0 0 12px; font-size: 15px; font-weight: 600; color: var(--dark); }

/* ── Page header ─────────────────────────────── */
.page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 20px;
  gap: 12px;
  flex-wrap: wrap;
}
.page-header h1 { margin: 0; font-size: 22px; font-weight: 700; color: var(--dark); }
.page-header .page-sub { margin: 3px 0 0; color: var(--muted); font-size: 13px; }
.page-header-actions { display: flex; gap: 8px; align-items: center; flex-shrink: 0; }

/* ── Section divider ─────────────────────────── */
.section-title {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  margin: 0 0 12px;
}

/* ── Grid ────────────────────────────────────── */
.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 16px; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; }

/* ── Buttons ─────────────────────────────────── */
.button {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--primary);
  color: var(--dark);
  padding: 8px 16px;
  border-radius: var(--radius-sm);
  border: none;
  cursor: pointer;
  font-weight: 600;
  font-size: 14px;
  font-family: inherit;
  text-decoration: none;
  transition: background 0.15s, box-shadow 0.15s;
  white-space: nowrap;
  line-height: 1.4;
}
.button:hover { background: var(--primary-dark); box-shadow: 0 2px 6px rgba(240,184,46,0.35); }
.button.secondary {
  background: var(--card);
  color: var(--dark);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
}
.button.secondary:hover { background: var(--bg); }
.button.danger { background: #fee2e2; color: #dc2626; border: 1px solid #fca5a5; }
.button.danger:hover { background: #fecaca; }
.button.sm { padding: 5px 10px; font-size: 13px; }

/* ── Forms ───────────────────────────────────── */
label {
  display: block;
  font-weight: 600;
  font-size: 13px;
  color: var(--dark);
  margin: 12px 0 4px;
}
label:first-child { margin-top: 0; }
.input, select, textarea {
  width: 100%;
  padding: 9px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--card);
  font-family: inherit;
  font-size: 14px;
  color: var(--dark);
  transition: border-color 0.15s, box-shadow 0.15s;
  appearance: auto;
}
.input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(253,202,88,0.22);
}
.form-group { margin-bottom: 14px; }
.form-hint { font-size: 12px; color: var(--muted); margin-top: 3px; }
.form-actions { display: flex; gap: 8px; margin-top: 16px; align-items: center; }
.checkbox-label { display: flex; align-items: center; gap: 8px; font-weight: 500; cursor: pointer; margin: 8px 0; }
.checkbox-label input { width: auto; }

/* ── Flash ───────────────────────────────────── */
.flash {
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  margin-bottom: 16px;
  font-size: 14px;
  font-weight: 500;
  border: 1px solid transparent;
}
.flash.success { background: #f0fdf4; color: #15803d; border-color: #bbf7d0; }
.flash.error   { background: #fef2f2; color: #dc2626; border-color: #fecaca; }

/* ── Tables ──────────────────────────────────── */
.table { width: 100%; border-collapse: collapse; font-size: 14px; }
.table th {
  text-align: left;
  padding: 9px 12px;
  font-size: 11px;
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  border-bottom: 1px solid var(--border);
  background: #fafafa;
  white-space: nowrap;
}
.table td { padding: 11px 12px; border-bottom: 1px solid #f3f4f6; vertical-align: middle; }
.table tbody tr:last-child td { border-bottom: none; }
.table tbody tr:hover td { background: #fafafa; }
.table td a { color: #2563eb; text-decoration: none; font-weight: 500; }
.table td a:hover { text-decoration: underline; }

/* ── Badges ──────────────────────────────────── */
.badge {
  display: inline-block;
  padding: 2px 9px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
  background: var(--bg);
  color: var(--muted);
  white-space: nowrap;
  letter-spacing: 0.01em;
}
.badge-NEW               { background: #eff6ff; color: #2563eb; }
.badge-ASSIGNED          { background: #f5f3ff; color: #7c3aed; }
.badge-ON_SITE_SCHEDULED { background: #fffbeb; color: #b45309; }
.badge-DELAYED           { background: #fff7ed; color: #c2410c; }
.badge-CLOSED            { background: #f0fdf4; color: #16a34a; }
.badge-LOW               { background: #f9fafb; color: #6b7280; border: 1px solid var(--border); }
.badge-NORMAL            { background: #eff6ff; color: #2563eb; }
.badge-BUSINESS_DEGRADED { background: #fffbeb; color: #b45309; }
.badge-BUSINESS_HALTED   { background: #fef2f2; color: #dc2626; }
.badge-HARDWARE          { background: #f5f3ff; color: #7c3aed; }
.badge-SOFTWARE          { background: #eff6ff; color: #2563eb; }
.badge-NETWORK           { background: #ecfdf5; color: #059669; }
.badge-EMAIL             { background: #fff7ed; color: #c2410c; }
.badge-ACCESS            { background: #fdf4ff; color: #9333ea; }
.badge-public            { background: #f0fdf4; color: #16a34a; }
.badge-internal          { background: #f5f3ff; color: #7c3aed; }
.badge-active            { background: #f0fdf4; color: #16a34a; }
.badge-inactive          { background: #fef2f2; color: #dc2626; }

/* ── Chat ────────────────────────────────────── */
.chat { display: flex; flex-direction: column; gap: 16px; }
.msg {
  padding: 12px 16px;
  border-radius: 12px;
  max-width: 74%;
  font-size: 14px;
  line-height: 1.55;
}
.msg-header { display: flex; align-items: baseline; gap: 8px; margin-bottom: 6px; }
.msg-author { font-weight: 700; font-size: 13px; color: var(--dark); }
.msg-time   { font-size: 11px; color: var(--muted); }
.msg.agent    { background: #fff8e6; border: 1px solid #fde68a; align-self: flex-start; }
.msg.user     { background: #eff6ff; border: 1px solid #bfdbfe; align-self: flex-end; }
.msg.internal { background: #f5f3ff; border: 1px dashed #c4b5fd; align-self: flex-start; max-width: 88%; }
.ai-intake-chat { max-height: 360px; overflow: auto; padding-right: 4px; margin-bottom: 12px; }
.ai-intake-actions { display: flex; gap: 10px; flex-wrap: wrap; }
.typing-dots { display: inline-flex; gap: 4px; align-items: center; height: 10px; }
.typing-dots span { width: 6px; height: 6px; border-radius: 50%; background: #9d8743; opacity: 0.35; animation: typingPulse 1s infinite ease-in-out; }
.typing-dots span:nth-child(2) { animation-delay: 0.15s; }
.typing-dots span:nth-child(3) { animation-delay: 0.3s; }
@keyframes typingPulse {
  0%,80%,100% { transform: translateY(0); opacity: 0.35; }
  40%          { transform: translateY(-2px); opacity: 1; }
}

/* ── Ticket meta ─────────────────────────────── */
.ticket-meta { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.ticket-header-card { border-left: 4px solid var(--primary); }

/* ── Asset tag ───────────────────────────────── */
.asset-tag { width: 180px; border: 1px solid var(--border); border-radius: 10px; overflow: hidden; box-shadow: var(--shadow-sm); }
.asset-tag .top { background: var(--primary); text-align: center; font-size: 10px; padding: 5px 4px; font-weight: 700; letter-spacing: 0.08em; }
.asset-tag .bottom { text-align: center; font-size: 18px; padding: 12px; font-weight: 800; font-family: monospace; color: var(--dark); background: #fff; }

/* ── Nav card grid (admin dashboard) ─────────── */
.nav-card-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(196px, 1fr)); gap: 12px; }
.nav-card {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 18px 20px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  text-decoration: none;
  color: var(--dark);
  transition: border-color 0.15s, box-shadow 0.15s, background 0.15s;
  box-shadow: var(--shadow-sm);
}
.nav-card:hover { border-color: var(--primary); box-shadow: 0 4px 14px rgba(253,202,88,0.25); background: var(--primary-faint); }
.nav-card-icon  { font-size: 24px; line-height: 1; margin-bottom: 6px; }
.nav-card-label { font-weight: 700; font-size: 14px; color: var(--dark); }
.nav-card-desc  { font-size: 12px; color: var(--muted); }

/* ── Stat cards ──────────────────────────────── */
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin-bottom: 16px; }
.stat-card { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px 20px; box-shadow: var(--shadow-sm); }
.stat-label { font-size: 11px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: 0.05em; margin-bottom: 8px; }
.stat-value { font-size: 28px; font-weight: 800; color: var(--dark); line-height: 1; }
.stat-unit  { font-size: 14px; color: var(--muted); font-weight: 400; }

/* ── Login ───────────────────────────────────── */
.login-wrap { min-height: calc(100vh - 57px); display: grid; place-items: center; padding: 32px 16px; }
.login-panel {
  width: min(520px, 100%);
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 32px;
  box-shadow: var(--shadow-lg);
}
.login-eyebrow { margin: 0 0 6px; font-size: 11px; letter-spacing: 0.12em; text-transform: uppercase; color: var(--muted); font-weight: 700; }
.login-panel h1 { margin: 0; font-size: 26px; line-height: 1.15; color: var(--dark); }
.login-subtitle { margin: 8px 0 20px; color: var(--muted); font-size: 14px; }
.login-form label { margin-top: 0; margin-bottom: 4px; }
.login-form .form-group { margin-bottom: 14px; }
.login-button { width: 100%; padding: 11px 14px; font-size: 15px; justify-content: center; }
.login-help { margin: 14px 0 0; color: var(--muted); font-size: 13px; }
.login-divider { margin: 20px 0; text-align: center; position: relative; }
.login-divider::before { content: ''; position: absolute; left: 0; right: 0; top: 50%; height: 1px; background: var(--border); }
.login-divider span { position: relative; padding: 0 12px; background: var(--card); color: var(--muted); font-size: 12px; font-weight: 600; letter-spacing: 0.06em; }
.login-hint { margin: 2px 0 10px; color: var(--muted); font-size: 12px; }
.login-asset-sample { margin: 4px 0 14px; }
.login-bottom-link { margin: 20px 0 0; font-size: 13px; text-align: center; }
.login-bottom-link a { color: var(--muted); text-decoration: none; }
.login-bottom-link a:hover { text-decoration: underline; color: var(--dark); }

/* ── Code ────────────────────────────────────── */
.code-reveal {
  display: flex;
  align-items: center;
  gap: 10px;
  background: #1e1e2e;
  color: #cdd6f4;
  border-radius: var(--radius-sm);
  padding: 14px 16px;
  font-family: 'JetBrains Mono', 'Fira Mono', monospace;
  font-size: 14px;
  overflow: auto;
  line-height: 1.5;
}
pre {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 16px;
  font-size: 13px;
  overflow: auto;
  line-height: 1.6;
  margin: 8px 0;
}

/* ── Empty state ─────────────────────────────── */
.empty-state { text-align: center; padding: 48px 20px; color: var(--muted); }
.empty-icon  { font-size: 36px; margin-bottom: 10px; }
.empty-state p { margin: 4px 0 0; font-size: 14px; }

/* ── Recovery codes ──────────────────────────── */
.code-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 8px; margin: 14px 0; padding: 0; }
.code-list li { list-style: none; background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 8px 12px; font-family: monospace; font-size: 14px; text-align: center; }

/* ── CSAT Stars ──────────────────────────────── */
.star-rating { display: flex; gap: 6px; flex-direction: row-reverse; justify-content: flex-end; margin: 8px 0 16px; }
.star-rating input { display: none; }
.star-rating label { font-size: 36px; cursor: pointer; color: #d1d5db; transition: color 0.12s; }
.star-rating label:hover,
.star-rating label:hover ~ label,
.star-rating input:checked ~ label { color: var(--primary); }

/* ── Key-value meta ──────────────────────────── */
.kv-list { display: grid; grid-template-columns: auto 1fr; gap: 6px 16px; font-size: 14px; margin: 10px 0; }
.kv-label { font-weight: 600; color: var(--muted); white-space: nowrap; }

/* ── Inline filter form ──────────────────────── */
.filter-bar { display: flex; gap: 10px; flex-wrap: wrap; align-items: flex-end; }
.filter-bar .input, .filter-bar select { width: auto; min-width: 140px; }

/* ── Footer note ─────────────────────────────── */
.footer-note { color: var(--muted); font-size: 12px; }

/* ── Responsive ──────────────────────────────── */
@media (max-width: 720px) {
  .topbar { padding: 0 14px; }
  nav a { padding: 5px 8px; font-size: 13px; }
  .container { padding: 16px 12px; }
  .card { padding: 16px; }
  .grid-2, .grid-3 { grid-template-columns: 1fr; }
  .login-panel h1 { font-size: 22px; }
  .login-panel { padding: 24px 18px; }
  .stat-grid { grid-template-columns: repeat(2, 1fr); }
  .nav-card-grid { grid-template-columns: repeat(2, 1fr); }
  .filter-bar .input, .filter-bar select { width: 100%; }
  .msg { max-width: 90%; }
}
