:root {
  --bg: #05060a;
  --bg-alt: #0b0d16;
  --panel: #111320;
  --panel-alt: #151829;
  --accent: #ff3b4e;
  --accent-soft: rgba(255, 59, 78, 0.22);
  --accent-alt: #ffb347;
  --text: #f5f7ff;
  --muted: #8b90b0;
  --border-subtle: #20253a;
  --threat-low: #3fbf6b;
  --threat-medium: #f7b733;
  --threat-critical: #ff3b4e;
  --status-open: #ff3b4e;
  --status-investigating: #f7b733;
  --status-contained: #3fbf6b;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  height: 100%;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
  background: radial-gradient(circle at 0 0, #201022 0, #05060a 55%);
  color: var(--text);
}

body {
  display: flex;
  flex-direction: column;
}

.shell {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.top-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 1.5rem;
  background: linear-gradient(to right, #05060a, #151829 45%, #05060a);
  border-bottom: 1px solid #272b3f;
  box-shadow: 0 0 20px rgba(0, 0, 0, 0.7);
}

.top-left {
  display: flex;
  align-items: baseline;
  gap: 0.75rem;
}

.brand {
  font-weight: 600;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  font-size: 0.78rem;
  color: #f5657b;
}

.subtitle {
  font-size: 0.7rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.16em;
}

.status-pill {
  font-size: 0.7rem;
  padding: 0.2rem 0.55rem;
  border-radius: 999px;
  border: 1px solid rgba(99, 179, 237, 0.7);
  color: #a0d8ff;
  text-transform: uppercase;
  letter-spacing: 0.16em;
  background: radial-gradient(circle at 0 0, #1b2a40 0, #0b1020 55%);
  box-shadow: 0 0 0 1px rgba(10, 45, 80, 0.6);
}

.clock {
  font-family: "SF Mono", ui-monospace, Menlo, Monaco, "Cascadia Code",
    monospace;
  font-size: 0.8rem;
  color: var(--muted);
}

.layout {
  flex: 1;
  display: grid;
  grid-template-columns: minmax(0, 2.2fr) minmax(0, 2.8fr) minmax(260px, 1.8fr);
  gap: 0.75rem;
  padding: 0.75rem 0.9rem 0.9rem;
  min-height: 0;
}

.panel {
  background: radial-gradient(circle at 0 0, #1d1d30 0, #101222 50%);
  border-radius: 0.75rem;
  border: 1px solid var(--border-subtle);
  box-shadow: 0 10px 35px rgba(0, 0, 0, 0.75);
  padding: 0.75rem;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.panel-header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 0.5rem;
}

.panel-title {
  font-size: 0.82rem;
  text-transform: uppercase;
  letter-spacing: 0.18em;
  color: #cbd5ff;
}

.panel-subtitle {
  font-size: 0.7rem;
  color: var(--muted);
}

.divider {
  height: 1px;
  margin: 0.4rem 0 0.45rem;
  background: linear-gradient(to right,
      rgba(255, 255, 255, 0.06),
      rgba(255, 255, 255, 0.02));
}

.filters {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-bottom: 0.4rem;
}

.chip {
  padding: 0.18rem 0.55rem;
  border-radius: 999px;
  font-size: 0.68rem;
  border: 1px solid rgba(148, 163, 184, 0.45);
  color: var(--muted);
  background: rgba(15, 23, 42, 0.75);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 0.2rem;
}

.chip.active {
  border-color: var(--accent);
  color: #fed7e2;
  background: radial-gradient(circle at 0 0, #3d121a 0, #1b0a0f 60%);
  box-shadow: 0 0 18px rgba(255, 59, 78, 0.55);
}

.chip-dot {
  width: 6px;
  height: 6px;
  border-radius: 999px;
  background: currentColor;
}

.table-header,
.incident-row {
  display: grid;
  grid-template-columns: minmax(0, 1.9fr) 0.9fr 0.9fr 1.3fr 0.9fr;
  gap: 0.5rem;
  align-items: center;
  font-size: 0.72rem;
}

.table-header {
  text-transform: uppercase;
  letter-spacing: 0.14em;
  color: #7c86b0;
  padding: 0.3rem 0.3rem 0.25rem;
}

.incident-list {
  overflow: auto;
  padding-right: 0.25rem;
  margin-right: -0.25rem;
}

.incident-row {
  padding: 0.35rem 0.4rem;
  border-radius: 0.45rem;
  margin-bottom: 0.18rem;
  background: rgba(15, 23, 42, 0.55);
  border: 1px solid transparent;
  cursor: pointer;
  position: relative;
}

.incident-row.active {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px rgba(255, 59, 78, 0.4),
    0 0 24px rgba(255, 59, 78, 0.35);
}

.incident-row:hover:not(.active) {
  background: rgba(15, 23, 42, 0.9);
  border-color: rgba(148, 163, 184, 0.35);
}

.incident-title {
  font-size: 0.8rem;
  font-weight: 500;
}

.pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.12rem 0.45rem;
  border-radius: 999px;
  font-size: 0.7rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  border: 1px solid transparent;
  white-space: nowrap;
}

.pill.threat-low {
  border-color: rgba(63, 191, 107, 0.7);
  color: #b9f6ca;
  background: rgba(22, 101, 52, 0.45);
}

.pill.threat-medium {
  border-color: rgba(247, 183, 51, 0.8);
  color: #fef9c3;
  background: rgba(180, 83, 9, 0.5);
}

.pill.threat-critical {
  border-color: rgba(255, 59, 78, 0.9);
  color: #fee2e2;
  background: rgba(185, 28, 28, 0.6);
  box-shadow: 0 0 16px rgba(239, 68, 68, 0.7);
}

.pill.status-open {
  border-color: rgba(248, 113, 113, 0.8);
  color: #fecaca;
  background: rgba(153, 27, 27, 0.6);
}

.pill.status-investigating {
  border-color: rgba(250, 204, 21, 0.85);
  color: #fef3c7;
  background: rgba(133, 77, 14, 0.6);
}

.pill.status-contained {
  border-color: rgba(34, 197, 94, 0.9);
  color: #dcfce7;
  background: rgba(22, 101, 52, 0.6);
}

.timestamp {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas,
    "Liberation Mono", "Courier New", monospace;
  font-size: 0.7rem;
  color: var(--muted);
}

.threat-indicator {
  display: inline-flex;
  align-items: center;
  gap: 0.2rem;
}

.threat-dot {
  width: 7px;
  height: 14px;
  border-radius: 999px;
  background: linear-gradient(to bottom, #fecaca, #ef4444);
  box-shadow: 0 0 12px rgba(239, 68, 68, 0.9);
}

.details-body {
  flex: 1;
  display: grid;
  grid-template-rows: auto auto 1fr auto;
  gap: 0.5rem;
  min-height: 0;
}

.classification-bar {
  display: flex;
  justify-content: space-between;
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.18em;
  color: #fecaca;
  background: repeating-linear-gradient(-45deg,
      rgba(127, 29, 29, 0.6),
      rgba(127, 29, 29, 0.6) 8px,
      rgba(127, 29, 29, 0.2) 8px,
      rgba(127, 29, 29, 0.2) 16px),
    radial-gradient(circle at 0 0, #3f1515 0, #1b0b0b 65%);
  border-radius: 0.5rem;
  padding: 0.35rem 0.6rem;
  border: 1px solid rgba(248, 113, 113, 0.85);
  box-shadow: 0 0 26px rgba(220, 38, 38, 0.8);
}

.detail-meta {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.4rem;
  font-size: 0.72rem;
}

.meta-block {
  background: rgba(15, 23, 42, 0.8);
  border-radius: 0.45rem;
  padding: 0.38rem 0.45rem;
  border: 1px dashed rgba(148, 163, 184, 0.55);
}

.meta-label {
  font-size: 0.64rem;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  color: #9ca3c5;
  margin-bottom: 0.18rem;
}

.meta-value {
  font-size: 0.78rem;
}

.detail-scroll {
  background: rgba(15, 23, 42, 0.75);
  border-radius: 0.5rem;
  border: 1px solid rgba(51, 65, 85, 0.8);
  padding: 0.45rem 0.55rem;
  overflow: auto;
  font-size: 0.78rem;
  line-height: 1.4;
}

.tags {
  display: flex;
  flex-wrap: wrap;
  gap: 0.28rem;
  margin-top: 0.3rem;
}

.tag {
  padding: 0.12rem 0.4rem;
  border-radius: 999px;
  border: 1px solid rgba(148, 163, 184, 0.5);
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: #a5b4fc;
  background: rgba(30, 64, 175, 0.35);
}

.recommended-action {
  margin-top: 0.45rem;
  font-size: 0.76rem;
  color: #e5e7eb;
  padding-top: 0.3rem;
  border-top: 1px dashed rgba(55, 65, 81, 0.85);
}

.action-label {
  text-transform: uppercase;
  letter-spacing: 0.16em;
  font-size: 0.65rem;
  color: #9ca3c5;
  margin-bottom: 0.18rem;
  display: block;
}

.detail-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.7rem;
  color: var(--muted);
}

.threat-meter {
  background: radial-gradient(circle at 0 0, #1f2937 0, #020617 90%);
  border-radius: 0.75rem;
  padding: 0.65rem 0.65rem 0.6rem;
  border: 1px solid rgba(55, 65, 81, 0.95);
  box-shadow: 0 0 26px rgba(15, 23, 42, 0.9);
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.threat-header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
}

.threat-label {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.18em;
  color: #e5e7eb;
}

.threat-value {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas,
    "Liberation Mono", "Courier New", monospace;
  font-size: 0.88rem;
  color: #fee2e2;
}

.meter-track {
  position: relative;
  height: 0.65rem;
  border-radius: 999px;
  background: linear-gradient(to right,
      rgba(22, 163, 74, 0.3),
      rgba(250, 204, 21, 0.25),
      rgba(239, 68, 68, 0.4));
  overflow: hidden;
}

.meter-fill {
  position: absolute;
  inset: 0;
  width: 40%;
  background: linear-gradient(to right,
      rgba(74, 222, 128, 0.4),
      rgba(250, 204, 21, 0.6),
      rgba(239, 68, 68, 0.95));
  box-shadow: 0 0 22px rgba(248, 113, 113, 0.9);
  transition: width 1.2s cubic-bezier(0.22, 1, 0.36, 1);
}

.meter-marker {
  position: absolute;
  top: -0.18rem;
  width: 2px;
  height: 1rem;
  border-radius: 999px;
  background: #fef3c7;
  box-shadow: 0 0 12px rgba(250, 250, 210, 0.8);
  transform: translateX(-50%);
  transition: left 1.2s cubic-bezier(0.22, 1, 0.36, 1);
}

.threat-scale {
  display: flex;
  justify-content: space-between;
  font-size: 0.65rem;
  text-transform: uppercase;
  letter-spacing: 0.15em;
  color: #9ca3c5;
}

.breach-warning {
  margin-top: 0.25rem;
  font-size: 0.74rem;
  color: #fee2e2;
  background: rgba(127, 29, 29, 0.6);
  border-radius: 0.45rem;
  border: 1px solid rgba(220, 38, 38, 0.9);
  padding: 0.35rem 0.45rem;
  display: flex;
  align-items: center;
  gap: 0.4rem;
  box-shadow: 0 0 20px rgba(220, 38, 38, 0.85);
}

.breach-indicator {
  width: 10px;
  height: 18px;
  border-radius: 999px;
  background: repeating-linear-gradient(-45deg,
      #fecaca,
      #fecaca 4px,
      #991b1b 4px,
      #991b1b 8px);
  box-shadow: 0 0 14px rgba(248, 113, 113, 1);
}

.hotkeys {
  background: rgba(15, 23, 42, 0.9);
  border-radius: 0.6rem;
  border: 1px dashed rgba(71, 85, 105, 0.9);
  padding: 0.45rem 0.55rem;
  font-size: 0.7rem;
}

.hotkey-row {
  display: flex;
  justify-content: space-between;
  margin-bottom: 0.24rem;
}

.kbd {
  border-radius: 0.25rem;
  border: 1px solid rgba(148, 163, 184, 0.7);
  background: rgba(15, 23, 42, 0.9);
  padding: 0.09rem 0.35rem;
  font-size: 0.7rem;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas,
    "Liberation Mono", "Courier New", monospace;
}

.form {
  display: grid;
  gap: 0.4rem;
  font-size: 0.76rem;
}

.form-row {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.4rem;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 0.16rem;
}

.label {
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  color: #9ca3c5;
}

input,
select,
textarea {
  font: inherit;
  color: inherit;
  background: rgba(15, 23, 42, 0.9);
  border-radius: 0.35rem;
  border: 1px solid rgba(55, 65, 81, 0.9);
  padding: 0.3rem 0.4rem;
  outline: none;
  transition: border 120ms ease, box-shadow 120ms ease, background 120ms ease;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px rgba(248, 113, 113, 0.7);
  background: rgba(15, 23, 42, 0.95);
}

textarea {
  min-height: 82px;
  resize: vertical;
}

.submit-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 0.2rem;
}

.btn-primary {
  border-radius: 999px;
  padding: 0.32rem 0.9rem;
  font-size: 0.78rem;
  border: 1px solid rgba(248, 113, 113, 0.9);
  text-transform: uppercase;
  letter-spacing: 0.14em;
  background: radial-gradient(circle at 0 0, #7f1d1d 0, #1b0a0f 70%);
  color: #fee2e2;
  cursor: pointer;
  box-shadow: 0 0 10px rgba(248, 113, 113, 0.9);
}

.btn-primary:hover {
  box-shadow: 0 0 18px rgba(248, 113, 113, 1);
  transform: translateY(-0.5px);
}

.confirmation {
  font-size: 0.7rem;
  color: #bbf7d0;
  opacity: 0;
  transform: translateY(2px);
  transition: opacity 180ms ease, transform 180ms ease;
}

.confirmation.visible {
  opacity: 1;
  transform: translateY(0);
}

.footer {
  padding: 0.35rem 1rem 0.55rem;
  font-size: 0.68rem;
  color: var(--muted);
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-top: 1px solid rgba(30, 64, 175, 0.45);
  background: radial-gradient(circle at 100% 100%, #161927 0, #020617 70%);
}

.mode-indicator {
  display: inline-flex;
  align-items: center;
  gap: 0.28rem;
}

.mode-dot {
  width: 9px;
  height: 9px;
  border-radius: 999px;
  background: radial-gradient(circle at 30% 30%, #facc15, #b91c1c);
  box-shadow: 0 0 14px rgba(248, 113, 113, 0.9);
}

/* Upside Down Mode */
body.upside-down {
  background: radial-gradient(circle at 0 100%, #020617 0, #000 55%);
  color: #e5e7eb;
  filter: contrast(1.02) saturate(1.1);
}

body.upside-down .panel {
  background: radial-gradient(circle at 0 0, #070711 0, #020617 70%);
  border-color: #1f2937;
  box-shadow: 0 0 40px rgba(15, 23, 42, 0.95);
}

body.upside-down .incident-row {
  background: rgba(15, 23, 42, 0.95);
  border-color: rgba(148, 163, 184, 0.4);
}

body.upside-down .incident-row:hover:not(.active) {
  background: rgba(15, 23, 42, 1);
  border-color: rgba(148, 163, 184, 0.7);
}

body.upside-down .classification-bar {
  filter: hue-rotate(-25deg) saturate(1.2);
}

body.upside-down .threat-meter {
  background: radial-gradient(circle at 0 0, #020617 0, #0f172a 75%);
}

body.upside-down .meter-fill {
  animation: pulse 1.4s ease-in-out infinite alternate;
}

body.upside-down .incident-row[data-threat="Critical"] {
  box-shadow: 0 0 30px rgba(248, 113, 113, 0.9);
  transform: translateY(-0.5px);
}

@keyframes pulse {
  from {
    box-shadow: 0 0 16px rgba(248, 113, 113, 0.7);
  }

  to {
    box-shadow: 0 0 30px rgba(248, 113, 113, 1);
  }
}

@media (max-width: 1120px) {
  .layout {
    grid-template-columns: minmax(0, 2.2fr) minmax(0, 2.6fr);
    grid-template-rows: minmax(260px, 1.4fr) minmax(0, 2.2fr);
    grid-template-areas:
      "list threat"
      "details details";
  }

  .panel.list {
    grid-area: list;
  }

  .panel.details {
    grid-area: details;
  }

  .panel.sidebar {
    grid-area: threat;
  }
}

@media (max-width: 768px) {

  html,
  body {
    height: auto;
    min-height: 100%;
    overflow-y: auto;
    /* Allow natural page scrolling */
  }

  .shell {
    height: auto;
    overflow: visible;
  }

  .top-bar {
    flex-direction: column;
    align-items: flex-start;
    gap: 0.35rem;
    position: sticky;
    top: 0;
    z-index: 50;
  }

  .layout {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    padding: 1rem;
    height: auto;
    overflow: visible;
  }

  /* Reset any grid properties from desktop */
  .panel {
    min-height: 0;
    /* reset */
    height: auto;
  }

  .panel.sidebar {
    order: 1;
    /* Threat meter first */
  }

  .panel.list {
    order: 2;
    /* Incident list second */
    min-height: 400px;
    max-height: 80vh;
    /* Allow list to be tall but not infinite */
  }

  .panel.details {
    order: 3;
    /* Details last */
  }

  /* Adjust table for small screens */
  .table-header,
  .incident-row {
    grid-template-columns: 1fr 0.5fr 0.6fr;
    /* Title, Threat, Status */
    gap: 0.3rem;
  }

  .table-header span:nth-child(4),
  .table-header span:nth-child(5),
  .incident-row div:nth-child(4),
  .incident-row div:nth-child(5) {
    display: none;
    /* Hide Location and Logged columns */
  }

  .form-row {
    grid-template-columns: 1fr;
  }

  .threat-meter {
    margin-bottom: 0;
  }
}