:root {
  --bg: #eef3f9;
  --bg2: #f8fafc;
  --panel: #0f172a;
  --panel2: #111c33;
  --card: #ffffff;
  --muted: #64748b;
  --text: #0f172a;
  --line: #e2e8f0;
  --primary: #4f46e5;
  --primary-dark: #4338ca;
  --danger: #dc2626;
  --danger-bg: #fee2e2;
  --danger-text: #991b1b;
  --warning: #f97316;
  --success: #16a34a;
  --success-bg: #dcfce7;
  --success-text: #166534;
  --radius: 18px;
  --shadow: 0 20px 60px rgba(15, 23, 42, .14);
}

*, *::before, *::after { box-sizing: border-box; }
html, body {
  margin: 0;
  min-height: 100%;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: radial-gradient(circle at top right, #dbeafe 0, var(--bg) 360px, var(--bg2));
  color: var(--text);
}
button, input, textarea, select { font: inherit; }
p { margin: 0 0 8px; }
h3, h4 { margin: 0 0 12px; }
dl, dt, dd { margin: 0; }
.hidden { display: none !important; }

.loading-bar {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: 3px;
  background: linear-gradient(90deg, var(--primary), #06b6d4, #7c3aed, var(--primary));
  background-size: 220% 100%;
  animation: shimmer 1.1s infinite linear;
  z-index: 1000;
}
@keyframes shimmer { to { background-position: -220% 0; } }

.auth-screen {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 22px;
  background: radial-gradient(circle at 20% 20%, #4f46e5, #172554 40%, #020617 100%);
}
.auth-card {
  width: min(440px, calc(100vw - 32px));
  background: rgba(255,255,255,.97);
  border: 1px solid rgba(255,255,255,.38);
  box-shadow: var(--shadow);
  border-radius: 28px;
  padding: 34px;
  text-align: center;
}
.auth-card-wide { width: min(480px, calc(100vw - 32px)); }
.auth-card h1 { margin: 16px 0 8px; font-size: 32px; }
.auth-card p { line-height: 1.55; }
.auth-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  background: #eef2ff;
  padding: 6px;
  border-radius: 16px;
  margin: 22px 0 16px;
}
.auth-tab {
  border: 0;
  border-radius: 12px;
  padding: 10px 12px;
  cursor: pointer;
  color: #475569;
  background: transparent;
  font-weight: 800;
}
.auth-tab.active { background: white; color: var(--text); box-shadow: 0 2px 8px rgba(15,23,42,.08); }
.auth-form { display: grid; gap: 9px; text-align: left; }
.auth-form label { font-weight: 800; font-size: 14px; color: #334155; }
.auth-form input { width: 100%; }
.bottom-note { margin-top: 18px; }
.link-button {
  border: 0;
  background: transparent;
  color: var(--primary);
  font-weight: 800;
  cursor: pointer;
  padding: 8px 0 0;
}

.brand-mark {
  width: 64px; height: 64px;
  border-radius: 20px;
  background: linear-gradient(135deg, #2563eb, #7c3aed);
  color: white;
  display: grid; place-items: center;
  margin: 0 auto;
  font-weight: 900; font-size: 24px;
  box-shadow: 0 14px 34px rgba(37,99,235,.28);
  flex-shrink: 0;
}
.small-mark { width: 42px; height: 42px; border-radius: 14px; font-size: 16px; margin: 0; }

.app {
  display: grid;
  grid-template-columns: 280px 1fr;
  min-height: 100vh;
}
.sidebar {
  background: linear-gradient(180deg, var(--panel), #0b1120);
  color: white;
  padding: 22px;
  display: flex;
  flex-direction: column;
  gap: 22px;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
  border-right: 1px solid rgba(255,255,255,.08);
}
.logo-row {
  display: flex; align-items: center; gap: 12px;
  padding-bottom: 14px;
  border-bottom: 1px solid rgba(255,255,255,.1);
}
.logo-row strong { display: block; }
.role-badge {
  display: inline-block;
  margin-top: 4px;
  font-size: 11px;
  background: rgba(255,255,255,.12);
  border-radius: 7px;
  padding: 3px 8px;
  color: #cbd5e1;
}
nav { display: grid; gap: 7px; }
.nav-item {
  width: 100%; text-align: left;
  border: 0; background: transparent;
  color: #a8b4ca;
  padding: 12px 14px;
  border-radius: 14px;
  cursor: pointer;
  transition: .15s ease;
  font-weight: 750;
}
.nav-item:hover, .nav-item.active {
  background: rgba(255,255,255,.105);
  color: white;
}
.main { padding: 28px; overflow: auto; }
.topbar {
  display: flex; align-items: flex-start; justify-content: space-between;
  gap: 16px; margin-bottom: 24px;
}
.topbar h2 { font-size: 34px; margin: 0 0 4px; letter-spacing: -.03em; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.view { animation: fade .18s ease; }
@keyframes fade { from { opacity: .55; transform: translateY(5px); } to { opacity: 1; transform: none; } }

.btn {
  border: 0; border-radius: 13px;
  padding: 10px 14px;
  font-weight: 850;
  cursor: pointer;
  transition: .15s ease;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  white-space: nowrap;
}
.btn.primary { background: var(--primary); color: white; box-shadow: 0 8px 18px rgba(79,70,229,.22); }
.btn.primary:hover { background: var(--primary-dark); transform: translateY(-1px); }
.btn.secondary { background: white; color: var(--text); border: 1px solid var(--line); }
.btn.secondary:hover { background: #f8fafc; }
.btn.ghost { background: rgba(255,255,255,.09); color: white; }
.btn.ghost:hover { background: rgba(255,255,255,.16); }
.btn.danger { background: var(--danger-bg); color: var(--danger-text); }
.btn.success-btn { background: var(--success-bg); color: var(--success-text); }
.btn.full { width: 100%; margin-top: auto; }
.full-width { width: 100%; }
.btn:disabled { opacity: .55; cursor: not-allowed; transform: none; }

.grid { display: grid; gap: 18px; }
.stats { grid-template-columns: repeat(4, minmax(0, 1fr)); margin-bottom: 22px; }
.card {
  background: rgba(255,255,255,.94);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: 0 7px 24px rgba(15,23,42,.07);
  padding: 20px;
}
.stat-card { text-align: center; overflow: hidden; position: relative; }
.stat-card::before { content: ''; position: absolute; inset: 0 0 auto 0; height: 4px; background: #c7d2fe; }
.stat-value { font-size: 38px; font-weight: 950; margin: 6px 0; letter-spacing: -.04em; }
.stat-label { font-weight: 850; color: #475569; font-size: 14px; }
.stat-urgent::before { background: var(--danger); }
.stat-warn::before { background: var(--warning); }

.toolbar { display: flex; flex-wrap: wrap; gap: 10px; margin-bottom: 14px; }
.toolbar input { flex: 1; min-width: 180px; min-height: 42px; }
.toolbar select { min-height: 42px; min-width: 150px; }

.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.field { display: grid; gap: 6px; }
.field.full { grid-column: 1 / -1; }
.field label { font-weight: 800; font-size: 14px; color: #334155; }
.field input, .field textarea, .field select, input, textarea, select {
  border: 1px solid var(--line);
  border-radius: 13px;
  padding: 11px 13px;
  background: white;
  transition: border-color .15s, box-shadow .15s;
}
.field input:focus, .field textarea:focus, .field select:focus, input:focus, textarea:focus, select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(79,70,229,.11);
}
.field textarea { min-height: 140px; resize: vertical; }
.hint { font-size: 13px; color: #64748b; line-height: 1.45; margin-top: 4px; }
.danger-note, .info-note {
  border-radius: 16px;
  padding: 13px 15px;
  margin-bottom: 14px;
  font-weight: 700;
}
.danger-note { background: #fff7ed; border: 1px solid #fed7aa; color: #9a3412; }
.info-note { background: #eef2ff; border: 1px solid #c7d2fe; color: #3730a3; }
.ai-row { display: flex; gap: 10px; align-items: center; }
.ai-row input { flex: 1; }

.ticket-list { display: grid; gap: 14px; }
.ticket-card {
  background: white;
  border: 1px solid var(--line);
  border-left: 6px solid #94a3b8;
  border-radius: 18px;
  padding: 17px;
  box-shadow: 0 4px 16px rgba(15,23,42,.055);
}
.priority-low { border-left-color: #64748b; }
.priority-normal { border-left-color: #16a34a; }
.priority-high { border-left-color: #f97316; }
.priority-urgent { border-left-color: #dc2626; }
.ticket-head { display: flex; justify-content: space-between; gap: 14px; align-items: flex-start; }
.ticket-title { font-weight: 950; font-size: 17px; letter-spacing: -.02em; }
.ticket-meta { display: flex; flex-wrap: wrap; gap: 7px; margin: 12px 0; }
.pill {
  display: inline-flex; align-items: center; gap: 5px;
  border-radius: 999px;
  padding: 5px 9px;
  background: #f1f5f9;
  color: #334155;
  font-size: 12px;
  font-weight: 850;
}
.pill.low { background: #f1f5f9; color: #334155; }
.pill.normal { background: #dcfce7; color: #166534; }
.pill.high { background: #ffedd5; color: #9a3412; }
.pill.urgent { background: #fee2e2; color: #991b1b; }
.status-open { background: #dbeafe; color: #1e40af; }
.status-in_progress { background: #ede9fe; color: #5b21b6; }
.status-waiting { background: #fef3c7; color: #92400e; }
.status-done, .status-closed { background: #dcfce7; color: #166534; }
.ticket-preview, .ticket-full-desc { white-space: pre-wrap; line-height: 1.55; color: #334155; }
.details { border-top: 1px solid var(--line); margin-top: 14px; padding-top: 14px; }
.detail-controls { margin: 14px 0; }
.ticket-actions { display: flex; flex-wrap: wrap; gap: 10px; margin: 12px 0 18px; }
.comment { background: #f8fafc; border: 1px solid var(--line); border-radius: 14px; padding: 11px; margin: 8px 0; }
.comment.internal { background: #fff7ed; border-color: #fed7aa; }
.comment small { color: #64748b; font-weight: 750; }
.comment p { white-space: pre-wrap; line-height: 1.5; margin-top: 6px; }
.checkbox-label { display: flex; align-items: center; gap: 8px; font-weight: 750; color: #334155; margin-top: 9px; }
.empty { padding: 18px; border: 1px dashed #cbd5e1; border-radius: 16px; background: #f8fafc; color: #64748b; text-align: center; }

.table-wrap { overflow-x: auto; }
.user-table { width: 100%; border-collapse: collapse; min-width: 720px; }
.user-table th, .user-table td { padding: 12px 10px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: middle; }
.user-table th { color: #475569; font-size: 13px; }
.user-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.user-inactive { opacity: .62; }
.status-dot { display: inline-block; width: 9px; height: 9px; border-radius: 999px; margin-right: 6px; background: var(--success); }
.status-dot.inactive { background: var(--danger); }
.profile-dl { display: grid; grid-template-columns: 110px 1fr; gap: 10px 14px; }
.profile-dl dt { color: #64748b; font-weight: 800; }
.profile-dl dd { font-weight: 850; }

.toast {
  position: fixed;
  right: 24px;
  bottom: 24px;
  max-width: min(460px, calc(100vw - 40px));
  background: #0f172a;
  color: white;
  padding: 13px 15px;
  border-radius: 14px;
  box-shadow: var(--shadow);
  z-index: 1000;
  font-weight: 750;
}
.toast.error { background: #991b1b; }
.toast.success { background: #166534; }

@media (max-width: 900px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; border-right: 0; }
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .main { padding: 18px; }
  .topbar { align-items: stretch; flex-direction: column; }
}
@media (max-width: 620px) {
  .stats, .form-grid { grid-template-columns: 1fr; }
  .ticket-head { flex-direction: column; }
  .ai-row { flex-direction: column; align-items: stretch; }
  .auth-card { padding: 24px; }
}

.section-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 12px; }
.stat-info::before { background: #06b6d4; }
.stat-success::before { background: var(--success); }
.assign-pill { background: #eff6ff; color: #1d4ed8; }
.strong-danger { background: var(--danger-bg) !important; color: var(--danger-text) !important; border: 1px solid #fecaca; }
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, .55);
  display: grid;
  place-items: center;
  padding: 20px;
  z-index: 2000;
  backdrop-filter: blur(5px);
}
.modal-card {
  width: min(460px, calc(100vw - 34px));
  background: white;
  border: 1px solid var(--line);
  border-radius: 22px;
  box-shadow: var(--shadow);
  padding: 24px;
}
.modal-card h3 { font-size: 22px; margin-bottom: 8px; }
.modal-card p { color: #475569; line-height: 1.55; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 22px; }

@media (max-width: 620px) {
  .section-head { align-items: flex-start; flex-direction: column; }
  .modal-actions { flex-direction: column-reverse; }
  .modal-actions .btn { width: 100%; }
}

.ai-suggestion {
  margin-top: 8px;
  padding: 10px 12px;
  border-radius: 14px;
  border: 1px solid #bfdbfe;
  background: #eff6ff;
  color: #1e3a8a;
  font-size: 0.9rem;
}
