:root {
  --bg: #f5f7f6;
  --panel: #ffffff;
  --ink: #17211d;
  --muted: #65726d;
  --line: #dbe2df;
  --accent: #0f766e;
  --accent-strong: #0b5d56;
  --warning: #b45309;
  --danger: #b42318;
  --ok: #15803d;
  --shadow: 0 18px 45px rgba(20, 35, 30, 0.1);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
}

body {
  background: var(--bg);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

body.ticket-portal {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 18px;
}

button,
input,
select,
textarea {
  font: inherit;
}

button,
.primary-button {
  min-height: 36px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  color: var(--ink);
  cursor: pointer;
  padding: 7px 11px;
}

.primary-button {
  border-color: var(--accent);
  background: var(--accent);
  color: #ffffff;
  font-weight: 800;
}

.primary-button:hover {
  background: var(--accent-strong);
}

input,
select,
textarea {
  width: 100%;
  min-height: 36px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #ffffff;
  color: var(--ink);
  padding: 7px 9px;
}

label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.eyebrow {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
}

.brand h1,
.brand p {
  margin: 0;
}

.brand h1 {
  font-size: 18px;
}

.brand p {
  color: var(--muted);
  font-size: 12px;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  overflow: hidden;
}

.brand-mark img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.ticket-shell {
  display: grid;
  grid-template-columns: minmax(0, 0.9fr) minmax(420px, 1fr);
  gap: 18px;
  width: min(1040px, 100%);
  align-items: stretch;
}

.ticket-hero {
  display: flex;
  flex-direction: column;
  justify-content: center;
  min-height: 520px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #10241f;
  color: #ffffff;
  padding: 24px;
}

.ticket-hero .eyebrow,
.ticket-hero p {
  color: #dbe7e3;
}

.ticket-hero h2 {
  max-width: 520px;
  margin: 12px 0;
  font-size: 42px;
  line-height: 1.04;
}

.ticket-hero > p:last-child {
  max-width: 560px;
  font-size: 16px;
  line-height: 1.6;
}

.ticket-brand {
  margin-bottom: auto;
}

.ticket-brand .brand-mark {
  background: #ffffff;
}

.ticket-brand h1 {
  color: #ffffff;
}

.ticket-panel {
  align-self: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
  padding: 18px;
}

.ticket-form {
  margin-top: 14px;
  box-shadow: none;
  padding: 0;
}

.ticket-lookup {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: end;
}

.ticket-device-card {
  display: grid;
  gap: 4px;
  margin-top: 12px;
  border: 1px solid #bbf7d0;
  border-radius: 8px;
  background: #f0fdf4;
  padding: 12px;
}

.ticket-device-card span {
  color: var(--ok);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

.ticket-device-card strong {
  font-size: 20px;
}

.ticket-device-card p {
  margin: 0;
  color: var(--muted);
}

.section-header,
.dialog-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.dialog-form {
  display: grid;
  gap: 14px;
  min-width: min(620px, calc(100vw - 32px));
  padding: 16px;
}

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

.form-grid .wide {
  grid-column: 1 / -1;
}

.icon-button {
  width: 36px;
  min-height: 36px;
  padding: 0;
}

menu {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin: 0;
  padding: 0;
}

.msp-page {
  display: grid;
  grid-template-columns: 280px minmax(0, 1fr);
  min-height: 100vh;
  background: var(--bg);
}

.login-page {
  display: grid;
  place-items: center;
  min-height: 100vh;
  background: #f5f7f6;
  color: #17211d;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  padding: 18px;
}

.login-panel {
  display: grid;
  gap: 14px;
  width: min(420px, 100%);
  border: 1px solid #dbe2df;
  border-radius: 8px;
  background: #ffffff;
  padding: 20px;
  box-shadow: 0 18px 45px rgba(20, 35, 30, 0.1);
}

.login-panel h1,
.login-panel p {
  margin: 0;
}

.login-panel label {
  display: grid;
  gap: 6px;
  color: #65726d;
  font-size: 13px;
  font-weight: 700;
}

.login-panel input {
  min-height: 38px;
  border: 1px solid #dbe2df;
  border-radius: 6px;
  padding: 7px 9px;
}

.login-error {
  min-height: 18px;
  color: #b42318;
  font-size: 13px;
}

.form-message {
  min-height: 18px;
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.msp-sidebar {
  border-right: 1px solid var(--line);
  background: var(--panel);
  padding: 14px;
}

.msp-workspace {
  min-width: 0;
  min-height: 100vh;
}

.msp-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 18px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.78);
}

.msp-topbar h2,
.msp-topbar p,
.msp-panel h3,
.msp-card p,
.metric-tile p {
  margin: 0;
}

.msp-actions,
.msp-nav {
  display: flex;
  gap: 8px;
}

.msp-actions {
  align-items: center;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.msp-nav {
  flex-direction: column;
  margin-top: 14px;
}

.msp-nav button {
  justify-content: flex-start;
  text-align: left;
}

.msp-nav button.is-active {
  border-color: var(--accent);
  background: #e7f5f2;
  color: var(--accent-strong);
  font-weight: 800;
}

.msp-summary {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin-top: 12px;
}

.metric-tile {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfb;
  padding: 10px;
}

.metric-tile strong {
  display: block;
  font-size: 24px;
  line-height: 1;
  margin-bottom: 6px;
}

.metric-tile p {
  color: var(--muted);
  font-size: 12px;
}

.msp-section {
  display: none;
  padding: 18px;
}

.msp-section.is-active {
  display: block;
}

.msp-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}

.msp-panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  padding: 14px;
}

.msp-list {
  display: grid;
  gap: 10px;
}

.filter-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 12px;
}

.filter-bar button {
  min-height: 32px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.filter-bar button.is-active {
  border-color: var(--accent);
  background: #ecfdf5;
  color: var(--accent-strong);
}

.msp-card {
  display: grid;
  gap: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfb;
  padding: 12px;
}

.msp-card-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.msp-card strong {
  font-size: 15px;
}

.msp-card p,
.device-row span,
.status-pill {
  color: var(--muted);
  font-size: 12px;
}

.card-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.alert-card.is-resolved {
  opacity: 0.75;
}

.alert-pills {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 6px;
}

.alert-meta {
  color: var(--muted);
  font-size: 12px;
}

.comment-list {
  display: grid;
  gap: 6px;
  border-left: 3px solid var(--line);
  padding-left: 10px;
}

.comment-list p {
  margin: 0;
}

.danger-button {
  border-color: #fecaca;
  background: #fff7f7;
  color: var(--danger);
  font-weight: 800;
}

.danger-button:hover {
  background: #fee2e2;
}

.danger-button.is-compact {
  min-height: 28px;
  padding: 3px 7px;
  font-size: 12px;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  border-radius: 999px;
  padding: 2px 8px;
  border: 1px solid var(--line);
  background: white;
  font-weight: 800;
}

.status-pill.online {
  border-color: #bbf7d0;
  background: #f0fdf4;
  color: var(--ok);
}

.status-pill.offline,
.status-pill.critical {
  border-color: #fecaca;
  background: #fef2f2;
  color: var(--danger);
}

.status-pill.warning {
  border-color: #fed7aa;
  background: #fff7ed;
  color: var(--warning);
}

.status-pill.info {
  border-color: #bfdbfe;
  background: #eff6ff;
  color: #1d4ed8;
}

.status-pill.open {
  border-color: #bfdbfe;
  background: #eff6ff;
  color: #1d4ed8;
}

.status-pill.acknowledged {
  border-color: #fde68a;
  background: #fffbeb;
  color: #92400e;
}

.status-pill.resolved {
  border-color: #bbf7d0;
  background: #f0fdf4;
  color: var(--ok);
}

.status-pill.p1 {
  border-color: #fecaca;
  background: #fef2f2;
  color: var(--danger);
}

.status-pill.p2 {
  border-color: #fed7aa;
  background: #fff7ed;
  color: var(--warning);
}

.status-pill.p3 {
  border-color: #bfdbfe;
  background: #eff6ff;
  color: #1d4ed8;
}

.status-pill.p4,
.status-pill.closed {
  border-color: #d9e2df;
  background: #f8faf9;
  color: var(--muted);
}

.status-pill.new,
.status-pill.triage,
.status-pill.in_progress {
  border-color: #bfdbfe;
  background: #eff6ff;
  color: #1d4ed8;
}

.status-pill.waiting_customer {
  border-color: #fde68a;
  background: #fffbeb;
  color: #92400e;
}

.status-pill.inventory {
  border-color: #d9e2df;
  background: #f8faf9;
  color: var(--muted);
}

.device-table {
  display: grid;
  gap: 8px;
}

.device-row {
  display: grid;
  grid-template-columns: 1.4fr 1fr 82px 82px 82px 96px;
  gap: 10px;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfb;
  padding: 10px;
}

.device-row:not(.is-head) {
  cursor: pointer;
}

.device-row:not(.is-head):hover {
  border-color: var(--accent);
}

.device-row.is-head {
  background: transparent;
  border-color: transparent;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  padding-top: 0;
}

.device-main {
  display: grid;
  gap: 3px;
}

.device-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 6px;
}

.token-output {
  display: none;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fafc;
  color: var(--ink);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  overflow-wrap: anywhere;
  padding: 10px;
}

.token-output.has-token {
  display: block;
}

#testDeviceButton {
  margin-right: auto;
}

.device-detail {
  width: min(920px, calc(100vw - 32px));
}

.detail-toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.detail-grid,
.metric-strip {
  display: grid;
  gap: 10px;
}

.detail-grid {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.metric-strip {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.detail-item {
  display: grid;
  gap: 5px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfb;
  padding: 10px;
}

.detail-item span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.detail-item strong {
  overflow-wrap: anywhere;
  font-size: 14px;
}

.detail-panel {
  padding: 12px;
}

.mini-table {
  display: grid;
  gap: 8px;
}

.mini-table article {
  display: grid;
  grid-template-columns: 1.1fr 1fr 1fr 0.8fr;
  gap: 8px;
  align-items: start;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfb;
  padding: 9px;
}

.mini-table span {
  color: var(--muted);
  font-size: 12px;
  overflow-wrap: anywhere;
}

.tool-status {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 8px;
}

.tool-status span {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfb;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  padding: 6px 8px;
}

.event-list article {
  grid-template-columns: 0.7fr 1.1fr 1fr 2fr;
}

.metric-history {
  display: grid;
  gap: 10px;
}

.history-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
}

.history-card {
  display: grid;
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfb;
  padding: 10px;
}

.history-card div {
  display: grid;
  gap: 3px;
}

.history-card span,
.history-caption {
  color: var(--muted);
  font-size: 12px;
}

.history-card svg {
  width: 100%;
  height: 72px;
  overflow: visible;
}

.history-card polyline {
  fill: none;
  stroke: var(--accent);
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2;
}

.history-card.is-warning polyline {
  stroke: var(--danger);
}

@media (max-width: 900px) {
  body {
    height: auto;
    overflow: auto;
  }

  .msp-page {
    grid-template-columns: 1fr;
  }

  .ticket-shell {
    grid-template-columns: 1fr;
  }

  .ticket-hero {
    min-height: auto;
  }

  .ticket-hero h2 {
    font-size: 34px;
  }

  .ticket-lookup {
    grid-template-columns: 1fr;
  }

  .msp-sidebar {
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

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

  .device-row,
  .device-row.is-head {
    grid-template-columns: 1fr 1fr;
  }

  .device-row.is-head {
    display: none;
  }

  .detail-grid,
  .metric-strip,
  .history-grid,
  .mini-table article,
  .event-list article {
    grid-template-columns: 1fr;
  }
}
