* { box-sizing: border-box; }
:root {
  --bg: #f5f7fa;
  --card: #ffffff;
  --border: #e5e9f0;
  --text: #1f2937;
  --muted: #6b7280;
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --danger: #dc2626;
}
html, body { height: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}
header {
  background: var(--card);
  border-bottom: 1px solid var(--border);
  padding: 12px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand h1 { font-size: 18px; margin: 0; }
.logo { font-size: 24px; }
.user-bar #user-info { display: flex; align-items: center; gap: 10px; }
.user-bar #user-info a#logout {
  color: var(--text); text-decoration: none;
  border: 1px solid var(--border); padding: 8px 14px;
  border-radius: 6px; font-size: 14px; font-weight: 500;
}
.user-bar #user-info a#logout:hover { background: #f9fafb; }
.badge {
  background: #eff6ff;
  color: var(--primary);
  padding: 2px 8px;
  border-radius: 12px;
  font-size: 12px;
  font-weight: 500;
}
.badge.super { background: #fef3c7; color: #92400e; }
button {
  cursor: pointer;
  border: 1px solid var(--border);
  background: white;
  padding: 8px 14px;
  border-radius: 6px;
  font-size: 14px;
  font-weight: 500;
  color: var(--text);
  font-family: inherit;
}
button:hover { background: #f9fafb; }
button.primary {
  background: var(--primary);
  color: white;
  border-color: var(--primary);
}
button.primary:hover { background: var(--primary-hover); }
button.block { width: 100%; }
button.danger { color: var(--danger); border-color: #fecaca; }
button.danger:hover { background: #fef2f2; }
input, select, textarea {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 14px;
  font-family: inherit;
  background: white;
  color: var(--text);
}
textarea { resize: vertical; }
label {
  display: block;
  margin-bottom: 12px;
  font-size: 13px;
  font-weight: 500;
  color: var(--muted);
}
label input, label select, label textarea { margin-top: 4px; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.card { background: var(--card); border: 1px solid var(--border); border-radius: 8px; padding: 24px; }

main { padding: 24px; flex: 1; }

.site-footer {
  text-align: center;
  padding: 16px 24px;
  color: var(--muted);
  font-size: 12px;
  border-top: 1px solid var(--border);
  background: var(--card);
}

/* ---------- Auth screens (loading + unauthorized) ---------- */

.auth-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: calc(100vh - 130px);
  padding: 20px;
  background:
    radial-gradient(circle at 20% 0%, #dbeafe 0%, transparent 50%),
    radial-gradient(circle at 80% 100%, #e0e7ff 0%, transparent 50%),
    var(--bg);
  margin: -24px;
  padding: 24px;
}
.auth-screen.hidden { display: none !important; }

.auth-card {
  background: white;
  border-radius: 16px;
  padding: 48px 40px;
  width: 100%;
  max-width: 420px;
  text-align: center;
  box-shadow:
    0 20px 60px -15px rgba(15, 23, 42, 0.15),
    0 4px 12px -2px rgba(15, 23, 42, 0.05);
  border: 1px solid rgba(15, 23, 42, 0.04);
}
.auth-logo {
  width: 72px;
  height: 72px;
  border-radius: 18px;
  background: linear-gradient(135deg, var(--primary), #4f46e5);
  color: white;
  font-size: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 20px;
  box-shadow: 0 8px 24px -8px rgba(37, 99, 235, 0.5);
}
.auth-title {
  margin: 0 0 8px;
  font-size: 24px;
  font-weight: 700;
  letter-spacing: -0.01em;
  color: var(--text);
}
.auth-subtitle {
  margin: 0 0 28px;
  font-size: 14px;
  color: var(--muted);
  line-height: 1.5;
}
.auth-btn {
  display: inline-block;
  width: 100%;
  padding: 12px 24px;
  font-size: 15px;
  font-weight: 600;
  border-radius: 8px;
  text-decoration: none;
  text-align: center;
  cursor: pointer;
  transition: transform 0.05s ease, box-shadow 0.15s ease;
  box-shadow: 0 4px 12px -3px rgba(37, 99, 235, 0.4);
}
.auth-btn:hover { transform: translateY(-1px); box-shadow: 0 8px 18px -4px rgba(37, 99, 235, 0.5); }
.auth-btn:active { transform: translateY(0); }
.auth-note {
  margin: 16px 0 0;
  font-size: 12px;
  color: var(--muted);
}
.auth-help {
  margin-top: 28px;
  padding-top: 20px;
  border-top: 1px solid var(--border);
  font-size: 12px;
  color: var(--muted);
}
.auth-spinner {
  width: 28px;
  height: 28px;
  border: 3px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  margin: 8px auto 4px;
  animation: auth-spin 0.7s linear infinite;
}
@keyframes auth-spin { to { transform: rotate(360deg); } }

/* ---------- Main app ---------- */

#app-screen {
  display: grid;
  grid-template-columns: 240px 1fr;
  gap: 24px;
  align-items: start;
}
.sidebar {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 16px;
  position: sticky;
  top: 24px;
}
.stats { display: flex; gap: 8px; margin-bottom: 16px; }
.stat { flex: 1; background: #f9fafb; border-radius: 6px; padding: 12px; text-align: center; }
.stat-value { display: block; font-size: 22px; font-weight: 600; }
.stat-label { display: block; font-size: 11px; color: var(--muted); margin-top: 2px; text-transform: uppercase; }
nav { display: flex; flex-direction: column; gap: 2px; margin-bottom: 12px; }
.nav-btn {
  text-align: left;
  background: transparent;
  border: none;
  padding: 8px 10px;
  border-radius: 6px;
  width: 100%;
}
.nav-btn:hover { background: #f3f4f6; }
.nav-btn.active { background: #eff6ff; color: var(--primary); }
#new-ticket-btn { margin-top: 8px; }

.content { min-width: 0; }
.toolbar { display: flex; gap: 8px; margin-bottom: 16px; }
.toolbar input { flex: 1; }
.toolbar select { width: 200px; }

#ticket-list { display: flex; flex-direction: column; gap: 8px; }
.ticket-row {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 14px 16px;
  cursor: pointer;
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 12px;
  align-items: center;
}
.ticket-row:hover { border-color: var(--primary); }
.ticket-id { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; color: var(--muted); font-size: 12px; }
.ticket-main h3 { margin: 0 0 6px; font-size: 15px; font-weight: 600; }
.ticket-main .meta { font-size: 12px; color: var(--muted); display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.priority-pill, .status-pill {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 12px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.02em;
}
.priority-low { background: #f3f4f6; color: #4b5563; }
.priority-medium { background: #dbeafe; color: #1e40af; }
.priority-high { background: #fed7aa; color: #9a3412; }
.priority-urgent { background: #fecaca; color: #991b1b; }
.status-open { background: #fef3c7; color: #92400e; }
.status-in_progress { background: #dbeafe; color: #1e40af; }
.status-waiting { background: #e0e7ff; color: #3730a3; }
.status-resolved { background: #d1fae5; color: #065f46; }
.status-closed { background: #f3f4f6; color: #4b5563; }
.empty {
  text-align: center;
  padding: 60px 20px;
  color: var(--muted);
  background: var(--card);
  border-radius: 8px;
  border: 1px dashed var(--border);
}

.modal {
  position: fixed; inset: 0; background: rgba(15, 23, 42, 0.5);
  display: flex; align-items: center; justify-content: center;
  padding: 20px; z-index: 50;
}
.modal-card {
  background: white; border-radius: 8px; padding: 24px;
  width: 100%; max-width: 560px; max-height: 90vh; overflow-y: auto;
  box-shadow: 0 20px 50px rgba(15, 23, 42, 0.25);
}
.modal-card.detail { max-width: 720px; }
.modal-card header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 16px; padding: 0; background: none; border: none;
}
.modal-card header h2 { margin: 0; font-size: 18px; }
.close-modal {
  background: transparent; border: none; font-size: 24px;
  padding: 0 8px; line-height: 1; color: var(--muted);
}
.modal-card footer {
  display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px;
}
.detail-meta {
  display: grid; grid-template-columns: repeat(2, 1fr); gap: 14px;
  background: #f9fafb; padding: 16px; border-radius: 6px; margin-bottom: 16px;
}
.detail-meta > div { font-size: 13px; }
.detail-meta strong {
  display: block; color: var(--muted); font-size: 11px;
  text-transform: uppercase; margin-bottom: 4px; font-weight: 600;
  letter-spacing: 0.04em;
}
.detail-meta select { padding: 5px 8px; }
.description-block { margin-bottom: 20px; }
.description-block h3, .comments-block h3 {
  font-size: 12px; text-transform: uppercase; color: var(--muted);
  margin: 0 0 8px; letter-spacing: 0.04em;
}
.description-block p { white-space: pre-wrap; margin: 0; line-height: 1.5; }
#td-activity { display: flex; flex-direction: column; gap: 10px; margin-bottom: 12px; }
.activity-item {
  padding: 10px 12px;
  border-left: 3px solid var(--border);
  background: #f9fafb;
  border-radius: 0 6px 6px 0;
}
.activity-item.history {
  border-color: #cbd5e1; font-style: italic; color: var(--muted); font-size: 13px;
}
.activity-item .author { font-weight: 600; font-size: 13px; }
.activity-item .when { font-size: 11px; color: var(--muted); margin-left: 6px; }
.activity-item p { margin: 4px 0 0; white-space: pre-wrap; line-height: 1.5; }
.add-comment { display: flex; flex-direction: column; gap: 8px; }
.add-comment button { align-self: flex-end; }

#agents-list { display: flex; flex-direction: column; gap: 6px; margin-bottom: 16px; }
.agent-row {
  display: flex; justify-content: space-between; align-items: center;
  padding: 8px 12px; background: #f9fafb; border-radius: 6px;
}
.agent-row .agent-info { display: flex; flex-direction: column; }
.agent-row .agent-name { font-weight: 500; }
.agent-row .agent-email { font-size: 12px; color: var(--muted); }
.add-agent { display: grid; grid-template-columns: 1fr 1fr auto; gap: 8px; align-items: end; }

@media (max-width: 768px) {
  #app-screen { grid-template-columns: 1fr; }
  .sidebar { position: static; }
  .detail-meta { grid-template-columns: 1fr; }
  .toolbar { flex-direction: column; }
  .toolbar select { width: 100%; }
  .add-agent { grid-template-columns: 1fr; }
}
