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

:root {
  --bg: #0a0a0a;
  --bg-card: #161616;
  --bg-elevated: #1f1f1f;
  --text: #f5f5f5;
  --text-muted: #a3a3a3;
  --border: #2e2e2e;
  --red: #c8102e;
  --red-hover: #a50d26;
  --green: #22c55e;
  --danger: #ef4444;
}

html,
body {
  margin: 0;
  min-height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
}

a {
  color: var(--text);
}

.container {
  width: min(1100px, 100% - 2rem);
  margin-inline: auto;
}

.site-header {
  border-bottom: 1px solid var(--border);
  background: var(--bg-card);
}

.header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.75rem 0;
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  text-decoration: none;
  color: var(--text);
  font-weight: 600;
}

.brand-text {
  font-size: 0.95rem;
  letter-spacing: 0.02em;
}

.nav {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.nav a {
  text-decoration: none;
  font-size: 0.9rem;
  padding: 0.35rem 0.5rem;
}

.nav a:hover {
  color: #fff;
}

.main-content {
  padding: 2rem 0 3rem;
}

.site-footer {
  border-top: 1px solid var(--border);
  padding: 1.25rem 0 2rem;
  color: var(--text-muted);
  font-size: 0.85rem;
}

.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 1.5rem;
}

.card-narrow {
  max-width: 480px;
  margin-inline: auto;
}

h1 {
  margin: 0 0 0.75rem;
  font-size: 1.5rem;
  font-weight: 600;
}

.muted {
  color: var(--text-muted);
}

.form-group {
  margin-bottom: 1rem;
}

label {
  display: block;
  margin-bottom: 0.35rem;
  font-size: 0.9rem;
}

input[type='email'],
input[type='text'],
select {
  width: 100%;
  padding: 0.65rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg-elevated);
  color: var(--text);
  font-size: 1rem;
}

input:focus,
select:focus {
  outline: 2px solid var(--red);
  outline-offset: 1px;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.6rem 1rem;
  border-radius: 6px;
  border: 1px solid transparent;
  font-size: 0.95rem;
  font-weight: 500;
  cursor: pointer;
  text-decoration: none;
  background: transparent;
  color: var(--text);
}

.btn-primary {
  background: var(--red);
  color: #fff;
}

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

.btn-secondary {
  background: var(--bg-elevated);
  border-color: var(--border);
}

.btn-secondary:hover {
  border-color: #555;
}

.btn-danger {
  background: var(--danger);
  color: #fff;
}

.btn-ghost {
  border-color: var(--border);
}

.btn-sm {
  padding: 0.35rem 0.65rem;
  font-size: 0.82rem;
}

.alert {
  padding: 0.75rem 1rem;
  border-radius: 6px;
  margin-bottom: 1rem;
  font-size: 0.9rem;
}

.alert-error {
  background: rgba(239, 68, 68, 0.15);
  border: 1px solid rgba(239, 68, 68, 0.4);
}

.alert-success {
  background: rgba(34, 197, 94, 0.12);
  border: 1px solid rgba(34, 197, 94, 0.35);
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 1rem;
  margin: 1.5rem 0;
}

.stat-card {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 1rem;
  text-align: center;
}

.stat-value {
  display: block;
  font-size: 1.75rem;
  font-weight: 700;
}

.stat-label {
  color: var(--text-muted);
  font-size: 0.85rem;
}

.actions-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  margin-top: 1rem;
}

.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
  margin-bottom: 1rem;
}

.filter-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-bottom: 1rem;
}

.tab {
  padding: 0.4rem 0.75rem;
  border-radius: 999px;
  border: 1px solid var(--border);
  text-decoration: none;
  font-size: 0.85rem;
  color: var(--text-muted);
}

.tab.active,
.tab:hover {
  color: var(--text);
  border-color: #555;
}

.table-wrap {
  overflow-x: auto;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

.data-table th,
.data-table td {
  padding: 0.65rem 0.5rem;
  border-bottom: 1px solid var(--border);
  text-align: left;
  vertical-align: top;
}

.data-table th {
  color: var(--text-muted);
  font-weight: 500;
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.badge {
  display: inline-block;
  padding: 0.15rem 0.45rem;
  border-radius: 4px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  font-size: 0.78rem;
  text-transform: lowercase;
}

.badge-pending { border-color: #ca8a04; color: #facc15; }
.badge-approved { border-color: #16a34a; color: #86efac; }
.badge-rejected { border-color: #dc2626; color: #fca5a5; }
.badge-disabled { border-color: #6b7280; color: #d1d5db; }

.inline-form {
  display: inline;
}

.stack-form {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  margin-bottom: 0.35rem;
}

.select-sm {
  width: auto;
  min-width: 90px;
  padding: 0.35rem 0.5rem;
  font-size: 0.82rem;
}

.actions-cell {
  min-width: 180px;
}

textarea {
  width: 100%;
  padding: 0.65rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg-elevated);
  color: var(--text);
  font-size: 1rem;
  font-family: inherit;
  resize: vertical;
}

.form-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 1rem;
}

.section-heading {
  margin: 1.5rem 0 0.75rem;
  font-size: 1.1rem;
  font-weight: 600;
}

.field-hint {
  font-size: 0.82rem;
  color: var(--text-muted);
  margin-top: 0.35rem;
}

.checkbox-label {
  display: flex;
  align-items: flex-start;
  gap: 0.5rem;
  font-size: 0.9rem;
}

.alert-warning {
  background: rgba(202, 138, 4, 0.15);
  border: 1px solid rgba(202, 138, 4, 0.4);
  padding: 0.75rem 1rem;
  border-radius: 6px;
}

.error-list {
  margin: 0;
  padding-left: 1.25rem;
}

.detail-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.detail-item {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.75rem;
}

.detail-label {
  display: block;
  font-size: 0.75rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 0.25rem;
}

.detail-value {
  font-size: 0.95rem;
}

.detail-section {
  margin-top: 1.5rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--border);
}

.detail-section h2,
.detail-section h3 {
  margin-top: 0;
}

.pre-wrap {
  white-space: pre-wrap;
}

.attachment-list {
  list-style: none;
  padding: 0;
  margin: 0;
}

.attachment-list li {
  padding: 0.35rem 0;
}

.timeline {
  list-style: none;
  padding: 0;
  margin: 0;
}

.timeline li {
  padding: 0.5rem 0;
  border-bottom: 1px solid var(--border);
}

.timeline-type {
  text-transform: capitalize;
  margin-right: 0.5rem;
}

.queue-section {
  margin-top: 1.5rem;
}

.queue-section h2 {
  font-size: 1.1rem;
  margin-bottom: 0.75rem;
}

.badge-priority-rush { border-color: #dc2626; color: #fca5a5; }
.badge-priority-high { border-color: #ea580c; color: #fdba74; }
.badge-priority-normal { border-color: #6b7280; color: #d1d5db; }

.inline-assign {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
}

.inline-assign select {
  width: auto;
  min-width: 200px;
}

.admin-actions {
  margin-top: 1rem;
}

.badge-status.badge-unassigned { border-color: #ca8a04; color: #facc15; }
.badge-status.badge-assigned_pending_ack { border-color: #2563eb; color: #93c5fd; }
.badge-status.badge-in_progress { border-color: #0891b2; color: #67e8f9; }
.badge-status.badge-completed { border-color: #16a34a; color: #86efac; }
.badge-status.badge-accepted { border-color: #059669; color: #6ee7b7; }
.badge-status.badge-closed { border-color: #6b7280; color: #d1d5db; }

.ticket-number {
  word-break: break-all;
  font-size: 1.1rem;
}

.comment-thread { display: flex; flex-direction: column; gap: 0.75rem; margin-bottom: 1rem; }
.comment-card {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.75rem 1rem;
}
.comment-card.internal-note { border-color: #ca8a04; }
.internal-badge {
  display: inline-block;
  font-size: 0.7rem;
  font-weight: 700;
  color: #facc15;
  margin-right: 0.5rem;
}
.internal-section { border-left: 3px solid #ca8a04; padding-left: 1rem; }
.comment-meta { display: flex; flex-wrap: wrap; gap: 0.5rem; margin-bottom: 0.35rem; font-size: 0.85rem; }
.comment-form { margin-top: 1rem; }
.action-panel .stack-form { display: flex; flex-direction: column; gap: 0.5rem; margin-bottom: 0.75rem; max-width: 420px; }
.action-panel-primary { margin-bottom: 1rem; }
.action-panel-danger {
  margin-top: 1.25rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border);
}
.action-panel-danger h4 {
  margin: 0 0 0.5rem;
  font-size: 0.95rem;
  color: var(--text-muted);
}
.force-close-help {
  font-size: 0.85rem;
  max-width: 520px;
  margin-bottom: 0.75rem;
}
.timeline-msg { margin-right: 0.5rem; }
.attachment-group { margin-bottom: 0.75rem; }
.attachment-group h4 { margin: 0 0 0.35rem; font-size: 0.9rem; color: var(--text-muted); }

@media (max-width: 640px) {
  .header-inner {
    flex-direction: column;
    align-items: flex-start;
  }

  .page-header {
    flex-direction: column;
    align-items: flex-start;
  }

  .data-table {
    font-size: 0.82rem;
  }
}
