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

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 15px;
  color: #111827;
  background: #f9fafb;
}

a {
  color: #2563eb;
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

/* Layout */
.container {
  max-width: 960px;
  margin: 0 auto;
  padding: 0 1rem;
}

/* Nav */
.topnav {
  background: #111827;
  padding: 0.75rem 0;
  margin-bottom: 2rem;
}

.topnav-brand {
  font-weight: 700;
  font-size: 1.1rem;
  color: #fff !important;
  text-decoration: none;
}

/* Page header row (title + action button) */
.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1.5rem;
  gap: 1rem;
}

.page-header .page-title {
  margin: 0;
}

.page-header .back-link {
  margin: 0;
  font-size: 0.9rem;
}

.page-title {
  font-size: 1.5rem;
  font-weight: 700;
  margin: 0 0 1.5rem;
}

.section-title {
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: #6b7280;
  margin: 0 0 0.75rem;
}

.incident-section {
  margin-bottom: 2.5rem;
}

/* Badges */
.badge {
  display: inline-block;
  padding: 0.2rem 0.55rem;
  border-radius: 4px;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  white-space: nowrap;
}

.sev0 {
  background: #111827;
  color: #fff;
}

.sev1 {
  background: #dc2626;
  color: #fff;
}

.sev2 {
  background: #ea580c;
  color: #fff;
}

.sev3 {
  background: #ca8a04;
  color: #fff;
}

.sev4 {
  background: #d1d5db;
  color: #374151;
}

.status-open {
  background: #fef2f2;
  color: #dc2626;
  border: 1px solid #fca5a5;
}

.status-resolved {
  background: #f0fdf4;
  color: #15803d;
  border: 1px solid #86efac;
}

/* Tables */
.table-wrap {
  overflow-x: auto;
}

.incident-table {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
  background: #fff;
  border-radius: 8px;
  overflow: hidden;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.07);
}

.incident-table .col-sev {
  width: 72px;
}

.incident-table .col-status {
  width: 100px;
}

.incident-table .col-date {
  width: 160px;
}

.incident-table .col-title {
  /* takes remaining width */
}

.incident-table th {
  text-align: left;
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: #6b7280;
  background: #f9fafb;
  padding: 0.65rem 1rem;
  border-bottom: 1px solid #e5e7eb;
}

.incident-table th a {
  color: inherit;
  text-decoration: none;
  white-space: nowrap;
}

.incident-table th a:hover {
  text-decoration: underline;
}

.incident-table th a.sort-active {
  color: #374151;
}

.incident-table td {
  padding: 0.75rem 1rem;
  border-bottom: 1px solid #f3f4f6;
  vertical-align: middle;
}

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

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

.ts {
  color: #6b7280;
  font-size: 0.85rem;
  white-space: nowrap;
  cursor: default;
}

.empty {
  color: #9ca3af;
  font-style: italic;
  margin: 0;
}

/* Incident card */
.incident-card {
  background: #fff;
  border-radius: 8px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.07);
  padding: 1.5rem;
  margin-bottom: 2rem;
}

.incident-card-header {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
  margin-bottom: 1.25rem;
}

.incident-title {
  font-size: 1.25rem;
  font-weight: 700;
  margin: 0;
  flex: 1 1 100%;
  margin-top: 0.5rem;
}

.incident-description {
  color: #4b5563;
  margin: -0.5rem 0 1.25rem;
  line-height: 1.6;
  font-size: 0.95rem;
}

/* Metadata grid */
.incident-meta {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem 2rem;
}

.meta-item {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
}

.meta-label {
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: #9ca3af;
}

.meta-value {
  font-size: 0.92rem;
  color: #111827;
}

.slack-channel {
  font-family: monospace;
  font-size: 0.85rem;
}

/* Timeline */
.timeline-section {
  margin-bottom: 2rem;
}

.timeline {
  border-left: 2px solid #e5e7eb;
  margin-left: 0.5rem;
}

.timeline-entry {
  position: relative;
  padding: 0 0 1.25rem 1.5rem;
}

.timeline-entry::before {
  content: "";
  position: absolute;
  left: -0.45rem;
  top: 0.35rem;
  width: 0.65rem;
  height: 0.65rem;
  border-radius: 50%;
  background: #d1d5db;
  border: 2px solid #fff;
}

.update-declared::before {
  background: #2563eb;
}

.update-resolved::before {
  background: #15803d;
}

.update-comment::before {
  background: #9ca3af;
}

.update-severity_changed::before {
  background: #7c3aed;
}

.update-title_changed::before {
  background: #0891b2;
}

.update-description_changed::before {
  background: #0891b2;
}

.update-unresolved::before {
  background: #dc2626;
}

.timeline-meta {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
  margin-bottom: 0.25rem;
}

.timeline-type {
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: #6b7280;
  background: #f3f4f6;
  padding: 0.1rem 0.4rem;
  border-radius: 3px;
}

.timeline-who {
  font-size: 0.85rem;
  font-weight: 600;
}

.timeline-entry .ts {
  margin-left: auto;
  font-size: 0.8rem;
}

.timeline-message {
  font-size: 0.92rem;
  color: #374151;
  line-height: 1.5;
}

/* Buttons */
.btn-primary {
  display: inline-block;
  padding: 0.45rem 1rem;
  background: #111827;
  color: #fff !important;
  border-radius: 6px;
  font-size: 0.85rem;
  font-weight: 600;
  text-decoration: none;
  border: none;
  cursor: pointer;
  white-space: nowrap;
}

.btn-primary:hover {
  background: #1f2937;
  text-decoration: none;
}

.btn-edit {
  display: inline-block;
  padding: 0.35rem 0.85rem;
  background: #fff;
  color: #374151 !important;
  border: 1px solid #d1d5db;
  border-radius: 6px;
  font-size: 0.85rem;
  font-weight: 500;
  text-decoration: none;
  white-space: nowrap;
}

.btn-edit:hover {
  background: #f9fafb;
  text-decoration: none;
}

.btn-cancel {
  font-size: 0.9rem;
  color: #6b7280 !important;
}

.btn-resolve {
  display: inline-block;
  padding: 0.45rem 1rem;
  background: #15803d;
  color: #fff;
  border: none;
  border-radius: 6px;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
}

.btn-resolve:hover {
  background: #166534;
}

.btn-unresolve {
  display: inline-block;
  padding: 0.45rem 1rem;
  background: #fff;
  color: #6b7280;
  border: 1px solid #d1d5db;
  border-radius: 6px;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
}

.btn-unresolve:hover {
  background: #f9fafb;
}

.page-header-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

/* Forms */
.back-link {
  margin-bottom: 1.5rem;
  font-size: 0.9rem;
}

.form-card {
  background: #fff;
  border-radius: 8px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.07);
  padding: 2rem;
  max-width: 560px;
  margin-top: 1.5rem;
}

.incident-form {
  display: flex;
  flex-direction: column;
  gap: 1.1rem;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}

.form-group label {
  font-size: 0.8rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: #6b7280;
}

.form-group input[type="text"],
.form-group select,
.form-group textarea {
  padding: 0.5rem 0.65rem;
  border: 1px solid #d1d5db;
  border-radius: 6px;
  font-size: 0.95rem;
  font-family: inherit;
  color: #111827;
  background: #fff;
  width: 100%;
}

.form-group input[type="text"]:focus,
.form-group select:focus,
.form-group textarea:focus {
  outline: none;
  border-color: #2563eb;
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

.form-group textarea {
  resize: vertical;
}

.form-actions {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding-top: 0.25rem;
}

.form-errors {
  background: #fef2f2;
  border: 1px solid #fca5a5;
  border-radius: 6px;
  padding: 0.75rem 1rem;
  font-size: 0.9rem;
  color: #dc2626;
}

/* Responsive */
@media (max-width: 600px) {
  .incident-meta {
    grid-template-columns: 1fr;
  }

  .timeline-entry .ts {
    margin-left: 0;
  }

  .form-card {
    padding: 1rem;
  }
}