/* ==================== Admin Panel Styles ==================== */
:root {
  --admin-primary: #4338ca;
  --admin-primary-dark: #3730a3;
  --admin-bg: #f5f7fa;
  --admin-card-bg: #ffffff;
  --admin-text: #1a1a2e;
  --admin-text-secondary: #6b7280;
  --admin-border: #e5e7eb;
  --admin-success: #10b981;
  --admin-warning: #f59e0b;
  --admin-error: #ef4444;
  --admin-info: #3b82f6;
  --admin-radius: 8px;
  --admin-shadow: 0 1px 3px rgba(0, 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(--admin-bg);
  color: var(--admin-text);
  font-size: 14px;
  line-height: 1.5;
}

.hidden { display: none !important; }

/* ==================== Login ==================== */
.admin-login {
  height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, var(--admin-primary) 0%, var(--admin-primary-dark) 100%);
}

.login-card {
  background: white;
  padding: 40px;
  border-radius: 12px;
  width: 100%;
  max-width: 380px;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
  text-align: center;
}

.login-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 72px;
  height: 72px;
  border-radius: 16px;
  background: linear-gradient(135deg, var(--admin-primary) 0%, var(--admin-primary-dark) 100%);
  color: white;
  margin-bottom: 16px;
}

.login-card h1 {
  font-size: 24px;
  margin-bottom: 4px;
  color: var(--admin-primary-dark);
}

.login-card p {
  color: var(--admin-text-secondary);
  margin-bottom: 8px;
  font-size: 14px;
}

.login-badge {
  display: inline-block;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--admin-primary);
  background: #eef2ff;
  padding: 4px 12px;
  border-radius: 20px;
  margin-bottom: 24px;
}

.login-card form {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.login-card input {
  padding: 12px 16px;
  border: 1px solid var(--admin-border);
  border-radius: var(--admin-radius);
  font-size: 14px;
}

.login-card input:focus {
  outline: none;
  border-color: var(--admin-primary);
  box-shadow: 0 0 0 3px rgba(67, 56, 202, 0.1);
}

.error-msg {
  color: var(--admin-error);
  font-size: 13px;
  text-align: left;
  padding: 8px 12px;
  background: #fef2f2;
  border-radius: var(--admin-radius);
}

/* ==================== Buttons ==================== */
.btn-primary {
  background: var(--admin-primary);
  color: white;
  border: none;
  padding: 12px 20px;
  border-radius: var(--admin-radius);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s;
}

.btn-primary:hover { background: var(--admin-primary-dark); }

.btn-sm {
  padding: 6px 14px;
  font-size: 13px;
  border-radius: 6px;
  border: 1px solid var(--admin-border);
  background: white;
  cursor: pointer;
  transition: background 0.2s;
}

.btn-sm:hover { background: #f3f4f6; }

.btn-sm.btn-primary {
  border: none;
  color: white;
  background: var(--admin-primary);
}

.btn-sm.btn-primary:hover {
  background: var(--admin-primary-dark);
}

.btn-claim {
  background: var(--admin-info);
  color: white;
  border: none;
  font-weight: 600;
}

.btn-claim:hover { background: #2563eb; }

.action-buttons {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
}

.btn-close {
  background: none;
  border: none;
  font-size: 24px;
  cursor: pointer;
  color: var(--admin-text-secondary);
  padding: 4px 8px;
  line-height: 1;
}

.btn-close:hover { color: var(--admin-text); }

/* ==================== Header ==================== */
.admin-header {
  background: var(--admin-primary);
  color: white;
  padding: 12px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.admin-header h2 { font-size: 18px; }

.header-right {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 13px;
}

.header-right .btn-sm {
  color: white;
  border-color: rgba(255,255,255,0.3);
  background: transparent;
}

.header-right .btn-sm:hover {
  background: rgba(255,255,255,0.1);
}

/* ==================== Dashboard Stats ==================== */
.dashboard-stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 16px;
  padding: 20px 24px;
}

.stat-card {
  background: var(--admin-card-bg);
  padding: 20px;
  border-radius: var(--admin-radius);
  box-shadow: var(--admin-shadow);
  text-align: center;
  border-top: 3px solid var(--admin-border);
}

.stat-card.stat-open { border-top-color: var(--admin-info); }
.stat-card.stat-review { border-top-color: var(--admin-warning); }
.stat-card.stat-resolved { border-top-color: var(--admin-success); }
.stat-card.stat-closed { border-top-color: #6b7280; }
.stat-card.stat-today { border-top-color: var(--admin-primary); }

.stat-number {
  font-size: 32px;
  font-weight: 700;
  line-height: 1;
  margin-bottom: 4px;
}

.stat-label {
  font-size: 13px;
  color: var(--admin-text-secondary);
}

/* ==================== Filters ==================== */
.filters-bar {
  display: flex;
  gap: 10px;
  padding: 0 24px 16px;
  flex-wrap: wrap;
}

.filters-bar select {
  padding: 8px 12px;
  border: 1px solid var(--admin-border);
  border-radius: 6px;
  font-size: 13px;
  background: white;
  cursor: pointer;
}

.filters-bar select:focus {
  outline: none;
  border-color: var(--admin-primary);
}

/* ==================== Tickets Table ==================== */
.tickets-container {
  padding: 0 24px;
  overflow-x: auto;
}

.tickets-table {
  width: 100%;
  border-collapse: collapse;
  background: var(--admin-card-bg);
  border-radius: var(--admin-radius);
  overflow: hidden;
  box-shadow: var(--admin-shadow);
}

.tickets-table th {
  background: #f9fafb;
  padding: 10px 14px;
  text-align: left;
  font-weight: 600;
  font-size: 12px;
  text-transform: uppercase;
  color: var(--admin-text-secondary);
  border-bottom: 1px solid var(--admin-border);
}

.tickets-table td {
  padding: 12px 14px;
  border-bottom: 1px solid var(--admin-border);
  font-size: 13px;
}

.tickets-table tbody tr {
  cursor: pointer;
  transition: background 0.15s;
}

.tickets-table tbody tr:hover {
  background: #f9fafb;
}

.tickets-table tbody tr:last-child td {
  border-bottom: none;
}

/* Status badges */
.badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 12px;
  font-size: 12px;
  font-weight: 500;
}

.badge-open { background: #dbeafe; color: #1d4ed8; }
.badge-in_review { background: #fef3c7; color: #92400e; }
.badge-resolved { background: #d1fae5; color: #065f46; }
.badge-closed { background: #e5e7eb; color: #4b5563; }

.badge-low { background: #f3f4f6; color: #6b7280; }
.badge-normal { background: #dbeafe; color: #1d4ed8; }
.badge-high { background: #fef3c7; color: #92400e; }
.badge-urgent { background: #fee2e2; color: #991b1b; }

.empty-state, .loading-state {
  text-align: center;
  padding: 40px;
  color: var(--admin-text-secondary);
  font-size: 14px;
}

/* ==================== Pagination ==================== */
.pagination {
  display: flex;
  justify-content: center;
  gap: 6px;
  padding: 16px 24px;
}

.pagination button {
  padding: 6px 12px;
  border: 1px solid var(--admin-border);
  border-radius: 6px;
  background: white;
  cursor: pointer;
  font-size: 13px;
}

.pagination button.active {
  background: var(--admin-primary);
  color: white;
  border-color: var(--admin-primary);
}

.pagination button:hover:not(.active) {
  background: #f3f4f6;
}

/* ==================== Modal ==================== */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  z-index: 100;
  padding: 40px 16px;
  overflow-y: auto;
}

.modal-content {
  background: white;
  border-radius: 12px;
  width: 100%;
  max-width: 500px;
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.2);
}

.modal-lg {
  max-width: 700px;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--admin-border);
}

.modal-header h3 {
  font-size: 16px;
  font-weight: 600;
}

.modal-body {
  padding: 20px;
  max-height: 70vh;
  overflow-y: auto;
}

/* ==================== Ticket Detail ==================== */
.detail-section {
  margin-bottom: 24px;
}

.detail-section h4 {
  font-size: 14px;
  font-weight: 600;
  margin-bottom: 10px;
  color: var(--admin-primary);
  border-bottom: 1px solid var(--admin-border);
  padding-bottom: 6px;
}

.detail-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  font-size: 13px;
}

.detail-grid strong {
  color: var(--admin-text-secondary);
  font-weight: 500;
}

/* Reported message */
.reported-message {
  background: #fff3cd;
  border-left: 4px solid var(--admin-warning);
  padding: 12px 16px;
  border-radius: 0 var(--admin-radius) var(--admin-radius) 0;
  font-size: 13px;
  white-space: pre-wrap;
  word-wrap: break-word;
}

.tools-info {
  margin-top: 10px;
  font-size: 12px;
  color: var(--admin-text-secondary);
}

.tools-info .tool-tag {
  display: inline-block;
  background: #eef2ff;
  color: #4338ca;
  padding: 2px 8px;
  border-radius: 4px;
  margin: 2px;
  font-size: 11px;
  font-family: monospace;
}

/* Conversation snapshot */
.conversation-snapshot {
  max-height: 300px;
  overflow-y: auto;
  border: 1px solid var(--admin-border);
  border-radius: var(--admin-radius);
  padding: 12px;
}

.snapshot-msg {
  padding: 8px 12px;
  margin-bottom: 6px;
  border-radius: 8px;
  font-size: 13px;
  white-space: pre-wrap;
  word-wrap: break-word;
}

.snapshot-msg.user {
  background: #dcf8c6;
  margin-left: 20%;
  text-align: right;
}

.snapshot-msg.assistant {
  background: #f3f4f6;
  margin-right: 20%;
}

.snapshot-msg.reported {
  background: #fff3cd;
  border: 2px solid var(--admin-warning);
}

.snapshot-role {
  font-size: 11px;
  font-weight: 600;
  color: var(--admin-text-secondary);
  margin-bottom: 2px;
}

/* Actions */
.action-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin-bottom: 12px;
}

.action-group {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-bottom: 8px;
}

.action-group label {
  font-size: 12px;
  font-weight: 500;
  color: var(--admin-text-secondary);
}

.action-group select,
.action-group textarea {
  padding: 8px 10px;
  border: 1px solid var(--admin-border);
  border-radius: 6px;
  font-size: 13px;
  font-family: inherit;
  width: 100%;
}

.action-group select:focus,
.action-group textarea:focus {
  outline: none;
  border-color: var(--admin-primary);
}

.resolve-section {
  margin-top: 16px;
  padding-top: 16px;
  border-top: 1px solid var(--admin-border);
}

.resolve-section h4 {
  border-bottom: none;
  padding-bottom: 0;
}

/* Notes */
#detail-notes {
  margin-bottom: 10px;
}

.note-item {
  background: #fefce8;
  border-left: 3px solid var(--admin-warning);
  padding: 8px 12px;
  margin-bottom: 6px;
  border-radius: 0 6px 6px 0;
  font-size: 13px;
}

.note-meta {
  font-size: 11px;
  color: var(--admin-text-secondary);
  margin-bottom: 4px;
}

.add-note {
  display: flex;
  gap: 8px;
  align-items: flex-end;
}

.add-note textarea {
  flex: 1;
  padding: 8px 10px;
  border: 1px solid var(--admin-border);
  border-radius: 6px;
  font-size: 13px;
  font-family: inherit;
  resize: vertical;
}

.add-note textarea:focus {
  outline: none;
  border-color: var(--admin-primary);
}

/* ==================== Toast Notifications ==================== */
.admin-toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  padding: 12px 20px;
  border-radius: var(--admin-radius);
  color: white;
  font-size: 14px;
  font-weight: 500;
  z-index: 200;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  animation: toastIn 0.3s ease;
  max-width: 400px;
}

.admin-toast-success { background: var(--admin-success); }
.admin-toast-error { background: var(--admin-error); }
.admin-toast-info { background: var(--admin-info); }

.admin-toast-exit {
  animation: toastOut 0.3s ease forwards;
}

@keyframes toastIn {
  from { opacity: 0; transform: translateY(20px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes toastOut {
  from { opacity: 1; transform: translateY(0); }
  to { opacity: 0; transform: translateY(20px); }
}

/* ==================== Responsive ==================== */
@media (max-width: 768px) {
  .dashboard-stats {
    grid-template-columns: repeat(2, 1fr);
  }

  .action-grid {
    grid-template-columns: 1fr;
  }

  .detail-grid {
    grid-template-columns: 1fr;
  }

  .tickets-table th:nth-child(5),
  .tickets-table td:nth-child(5),
  .tickets-table th:nth-child(6),
  .tickets-table td:nth-child(6) {
    display: none;
  }
}
