:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #f1f3f6;
  --border: #e5e8ee;
  --border-strong: #cfd4dd;
  --text: #0f172a;
  --text-2: #475569;
  --muted: #6b7280;
  --accent: #0f766e;
  --accent-soft: #ccfbf1;
  --accent-ink: #134e4a;
  --danger: #b91c1c;
  --danger-soft: #fee2e2;
  --warn: #b45309;
  --warn-soft: #fef3c7;
  --ok: #15803d;
  --ok-soft: #dcfce7;
  --info: #1d4ed8;
  --info-soft: #dbeafe;
  --shadow: 0 1px 2px rgba(15, 23, 42, 0.04), 0 8px 24px rgba(15, 23, 42, 0.06);
  --radius: 12px;
}

* {
  box-sizing: border-box;
}

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

body {
  font-family: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}

.hidden {
  display: none !important;
}

.muted {
  color: var(--muted);
  font-size: 12.5px;
}

.eyebrow {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--accent);
}

code {
  font-family: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
  background: var(--surface-2);
  padding: 1px 6px;
  border-radius: 4px;
  font-size: 12px;
}

button {
  font-family: inherit;
  cursor: pointer;
  border: 0;
  background: transparent;
  color: inherit;
}

input,
select {
  font-family: inherit;
  font-size: 14px;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}

input:focus,
select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.primary {
  background: var(--accent);
  color: white;
  font-weight: 600;
  padding: 10px 16px;
  border-radius: 8px;
  transition: background 0.15s, transform 0.05s;
}

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

.primary:active {
  transform: translateY(1px);
}

.ghost {
  background: var(--surface);
  border: 1px solid var(--border);
  padding: 7px 12px;
  border-radius: 8px;
  color: var(--text-2);
  font-weight: 500;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
}

.ghost:hover {
  background: var(--surface-2);
  color: var(--text);
  border-color: var(--border-strong);
}

.ghost.small {
  padding: 4px 10px;
  font-size: 12px;
}

.link {
  color: var(--accent);
  font-weight: 500;
  background: transparent;
}

.link:hover {
  text-decoration: underline;
}

.icon-btn {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--text-2);
}

.icon-btn:hover {
  background: var(--surface-2);
  color: var(--text);
}

.error {
  background: var(--danger-soft);
  color: var(--danger);
  padding: 8px 12px;
  border-radius: 8px;
  font-size: 13px;
}

/* LOGIN */
.login-view {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: radial-gradient(1200px 600px at 80% -10%, #ccfbf1 0%, transparent 60%),
    radial-gradient(900px 500px at -10% 110%, #e0e7ff 0%, transparent 60%), var(--bg);
  padding: 24px;
}

.login-card {
  background: var(--surface);
  border-radius: 20px;
  border: 1px solid var(--border);
  padding: 36px 32px;
  width: 100%;
  max-width: 420px;
  box-shadow: var(--shadow);
}

.login-card h1 {
  margin: 12px 0 6px;
  font-size: 22px;
}

.login-card p {
  margin: 0 0 24px;
}

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

.brand-mark {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  background: linear-gradient(135deg, #0f766e, #14b8a6);
  color: white;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  letter-spacing: -0.02em;
  box-shadow: inset 0 -2px 0 rgba(0, 0, 0, 0.15);
}

.brand-title {
  font-weight: 600;
}

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

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

.login-form label {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.login-form label span {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-2);
}

.login-footer {
  margin-top: 20px;
  padding-top: 16px;
  border-top: 1px dashed var(--border);
}

/* APP LAYOUT */
.app-view {
  display: grid;
  grid-template-columns: 240px 1fr;
  min-height: 100vh;
}

.sidebar {
  background: #0b1220;
  color: #cbd5e1;
  padding: 20px 16px;
  display: flex;
  flex-direction: column;
  gap: 28px;
  border-right: 1px solid #0a0f1a;
}

.sidebar .logo {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 4px 6px 4px 4px;
}

.logo-title {
  font-weight: 700;
  letter-spacing: 0.02em;
  color: white;
}

.logo-sub {
  font-size: 11px;
  color: #94a3b8;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

.nav {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 8px;
  color: #94a3b8;
  font-weight: 500;
  font-size: 13.5px;
  transition: background 0.15s, color 0.15s;
  text-align: left;
}

.nav-item:hover {
  color: white;
  background: rgba(255, 255, 255, 0.04);
}

.nav-item.active {
  color: white;
  background: linear-gradient(90deg, rgba(20, 184, 166, 0.18), rgba(20, 184, 166, 0.05));
  box-shadow: inset 2px 0 0 #14b8a6;
}

.sidebar-footer {
  margin-top: auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.user-chip {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.04);
}

.avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: #14b8a6;
  color: #052e2b;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
}

.user-name {
  font-size: 13px;
  font-weight: 600;
  color: white;
}

.sidebar-footer .ghost {
  background: transparent;
  border-color: rgba(255, 255, 255, 0.08);
  color: #cbd5e1;
}

.sidebar-footer .ghost:hover {
  background: rgba(255, 255, 255, 0.06);
  border-color: rgba(255, 255, 255, 0.18);
  color: white;
}

.main {
  padding: 28px 32px 40px;
  overflow-x: hidden;
}

.page-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  margin-bottom: 24px;
  gap: 16px;
  flex-wrap: wrap;
}

.page-header h2 {
  margin: 4px 0 6px;
  font-size: 22px;
  letter-spacing: -0.01em;
}

.page-header p {
  margin: 0;
}

/* CARDS */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px;
  margin-bottom: 18px;
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.03);
}

.card.no-padding {
  padding: 0;
}

.card-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 14px;
}

.card-head h3 {
  margin: 0;
  font-size: 14.5px;
  letter-spacing: -0.005em;
}

/* STATS */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 14px;
  margin-bottom: 18px;
}

.stat {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  position: relative;
  overflow: hidden;
}

.stat::before {
  content: "";
  position: absolute;
  inset: 0 0 auto 0;
  height: 3px;
  background: var(--accent);
  opacity: 0.8;
}

.stat.ok::before { background: var(--ok); }
.stat.warn::before { background: var(--warn); }
.stat.danger::before { background: var(--danger); }
.stat.info::before { background: var(--info); }

.stat-label {
  font-size: 11.5px;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.07em;
}

.stat-value {
  font-size: 28px;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.stat-foot {
  font-size: 12px;
  color: var(--text-2);
}

/* TYPE BARS */
.type-bars {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.type-bar {
  display: grid;
  grid-template-columns: 70px 1fr 50px;
  align-items: center;
  gap: 12px;
}

.type-bar-label {
  font-weight: 600;
  font-size: 12.5px;
  font-family: "JetBrains Mono", monospace;
}

.type-bar-track {
  height: 8px;
  background: var(--surface-2);
  border-radius: 999px;
  overflow: hidden;
}

.type-bar-fill {
  height: 100%;
  background: linear-gradient(90deg, #14b8a6, #0f766e);
  border-radius: 999px;
}

.type-bar-count {
  text-align: right;
  font-size: 12.5px;
  color: var(--text-2);
  font-variant-numeric: tabular-nums;
}

/* ACTIVITY */
.activity-list {
  display: flex;
  flex-direction: column;
  divide-y: 1px solid var(--border);
}

.activity-item {
  display: grid;
  grid-template-columns: 90px 60px 1fr auto;
  align-items: center;
  gap: 12px;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  transition: background 0.1s;
}

.activity-item:last-child {
  border-bottom: 0;
}

.activity-item:hover {
  background: var(--surface-2);
}

.activity-time {
  font-size: 12px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

/* FILTERS */
.filters {
  display: flex;
  gap: 10px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}

.filters input[type="search"] {
  flex: 1;
  min-width: 240px;
}

/* TABLE */
.events-table {
  width: 100%;
  border-collapse: collapse;
}

.events-table thead th {
  text-align: left;
  font-size: 11.5px;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--surface-2);
}

.events-table tbody td {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
  font-variant-numeric: tabular-nums;
}

.events-table tbody tr {
  cursor: pointer;
  transition: background 0.1s;
}

.events-table tbody tr:hover {
  background: var(--surface-2);
}

.events-table tbody tr:last-child td {
  border-bottom: 0;
}

.empty {
  padding: 36px;
  text-align: center;
  color: var(--muted);
}

.table-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 16px;
  border-top: 1px solid var(--border);
  background: var(--surface);
}

.pager {
  display: flex;
  gap: 8px;
}

/* STATUS PILLS */
.pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 11.5px;
  font-weight: 600;
  letter-spacing: 0.02em;
}

.pill::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
}

.pill-SENT { background: var(--ok-soft); color: var(--ok); }
.pill-PROVIDER_ERROR { background: var(--danger-soft); color: var(--danger); }
.pill-VALIDATION_FAILED { background: var(--warn-soft); color: var(--warn); }
.pill-INTERNAL_ERROR { background: var(--danger-soft); color: var(--danger); }
.pill-PROCESSING { background: var(--info-soft); color: var(--info); }
.pill-RECEIVED { background: var(--surface-2); color: var(--text-2); }

.type-chip {
  display: inline-block;
  padding: 2px 8px;
  background: var(--surface-2);
  color: var(--text);
  border-radius: 6px;
  font-family: "JetBrains Mono", monospace;
  font-size: 11.5px;
  font-weight: 600;
}

/* DRAWER */
.drawer-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.35);
  backdrop-filter: blur(2px);
  z-index: 20;
  animation: fadeIn 0.15s ease-out;
}

.drawer {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: min(980px, 100vw);
  background: var(--surface);
  border-left: 1px solid var(--border);
  z-index: 21;
  display: flex;
  flex-direction: column;
  box-shadow: -10px 0 40px rgba(15, 23, 42, 0.12);
  animation: slideIn 0.2s ease-out;
}

@keyframes fadeIn { from { opacity: 0 } to { opacity: 1 } }
@keyframes slideIn { from { transform: translateX(20px); opacity: 0 } to { transform: none; opacity: 1 } }

.drawer-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  padding: 20px 22px 12px;
  border-bottom: 1px solid var(--border);
}

.drawer-head h3 {
  margin: 6px 0 4px;
  font-size: 18px;
}

.drawer-meta {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 6px 16px;
  padding: 14px 22px;
  border-bottom: 1px solid var(--border);
  background: var(--surface-2);
}

.meta-item {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.meta-label {
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  font-weight: 600;
}

.meta-value {
  font-size: 13px;
  font-variant-numeric: tabular-nums;
  word-break: break-all;
}

.tabs {
  display: flex;
  gap: 2px;
  padding: 0 22px;
  border-bottom: 1px solid var(--border);
}

.tab {
  padding: 12px 14px;
  font-size: 13px;
  font-weight: 500;
  color: var(--muted);
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  transition: color 0.15s, border-color 0.15s;
}

.tab:hover {
  color: var(--text);
}

.tab.active {
  color: var(--accent);
  border-color: var(--accent);
}

.tab-panels {
  flex: 1;
  overflow: auto;
  padding: 16px 22px 24px;
}

.tab-panel {
  display: none;
}

.tab-panel.active {
  display: block;
}

.panel-actions {
  display: flex;
  justify-content: flex-end;
  margin-bottom: 8px;
}

.code {
  background: #0b1220;
  color: #e2e8f0;
  font-family: "JetBrains Mono", monospace;
  font-size: 12px;
  line-height: 1.55;
  padding: 14px 16px;
  border-radius: 10px;
  overflow: auto;
  white-space: pre;
  margin: 0;
  max-height: 60vh;
}

.error-panel {
  background: var(--danger-soft);
  border: 1px solid #fecaca;
  color: var(--danger);
  border-radius: 10px;
  padding: 16px 18px;
  font-size: 13px;
}

.error-panel.empty {
  background: var(--surface-2);
  border-color: var(--border);
  color: var(--muted);
}

.error-panel h4 {
  margin: 0 0 8px;
  font-size: 13px;
  color: var(--danger);
}

.error-panel ul {
  margin: 4px 0 0 18px;
  padding: 0;
}

.toast {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  background: #0b1220;
  color: white;
  padding: 8px 14px;
  border-radius: 8px;
  font-size: 12.5px;
  box-shadow: var(--shadow);
  z-index: 40;
  animation: fadeIn 0.15s ease-out;
}

@media (max-width: 800px) {
  .app-view { grid-template-columns: 1fr }
  .sidebar { display: none }
  .main { padding: 20px }
}

/* STATUS / ACK / DESTINATION (Riayati flow) */
.pill-HELD { background: var(--info-soft); color: var(--info); }
.pill-PROVIDER_REJECTED { background: var(--warn-soft); color: var(--warn); }
.pill-SKIPPED_NON_DUBAI { background: var(--surface-2); color: var(--muted); }
.pill-ack-ok { background: var(--ok-soft); color: var(--ok); }
.pill-ack-warn { background: var(--warn-soft); color: var(--warn); }
.pill-ack-danger { background: var(--danger-soft); color: var(--danger); }
.pill-ack-info { background: var(--info-soft); color: var(--info); }

.dest-chip {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 6px;
  font-size: 11.5px;
  font-weight: 600;
  white-space: nowrap;
}
.dest-nabidh { background: var(--surface-2); color: var(--text-2); }
.dest-riayati { background: var(--accent-soft); color: var(--accent-ink); }

.live-toggle {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: var(--text-2);
  cursor: pointer;
  user-select: none;
}

@keyframes rowFlash { from { background: var(--accent-soft); } to { background: transparent; } }
.events-table tr.row-new td { animation: rowFlash 2.5s ease-out; }

/* HL7 STRUCTURED VIEW */
.hl7-actions {
  align-items: center;
  gap: 12px;
}
.hl7-actions .live-toggle { margin-right: auto; }
.segmented {
  display: inline-flex;
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  overflow: hidden;
}
.segmented button {
  border: 0;
  background: var(--surface);
  color: var(--text-2);
  padding: 5px 12px;
  font-size: 12.5px;
  cursor: pointer;
}
.segmented button + button { border-left: 1px solid var(--border-strong); }
.segmented button.active { background: var(--accent); color: #fff; }

.hl7-view { display: flex; flex-direction: column; gap: 8px; }
.hl7-seg {
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  overflow: hidden;
}
.hl7-seg > summary {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  background: var(--surface-2);
  cursor: pointer;
  list-style: none;
}
.hl7-seg > summary::-webkit-details-marker { display: none; }
.hl7-seg-name {
  font-family: "JetBrains Mono", monospace;
  font-weight: 700;
  font-size: 13px;
  color: var(--accent-ink);
  min-width: 34px;
}
.hl7-seg-title { font-weight: 600; font-size: 13px; color: var(--text); }
.hl7-seg-count { margin-left: auto; font-size: 12px; }

.hl7-table { width: 100%; border-collapse: collapse; font-size: 12.5px; }
.hl7-table td { padding: 6px 12px; border-top: 1px solid var(--border); vertical-align: top; }
.hl7-fnum {
  width: 64px;
  font-family: "JetBrains Mono", monospace;
  color: var(--text-2);
  white-space: nowrap;
}
.hl7-fname { width: 34%; color: var(--text-2); }
.hl7-fval { font-family: "JetBrains Mono", monospace; word-break: break-word; }
.hl7-empty td { opacity: 0.55; }
.hl7-rep + .hl7-rep { margin-top: 4px; padding-top: 4px; border-top: 1px dashed var(--border); }
.hl7-comp {
  display: inline-flex;
  align-items: baseline;
  gap: 4px;
  margin: 0 8px 3px 0;
}
.hl7-comp-n {
  font-size: 10px;
  color: var(--muted);
  background: var(--surface-2);
  border-radius: 4px;
  padding: 0 4px;
}
.hl7-sub { color: var(--warn); padding: 0 2px; }
.hl7-blob {
  font-family: "Inter", system-ui, sans-serif;
  font-size: 12px;
  color: var(--info);
  background: var(--info-soft);
  border-radius: 6px;
  padding: 1px 8px;
}

/* Riayati pre-send issue levels in the Errors tab */
.issue-list { list-style: none; margin: 6px 0 0 !important; padding: 0; }
.issue-list li { display: flex; gap: 8px; align-items: baseline; margin-bottom: 6px; color: var(--text); }
.issue-level {
  flex: none;
  font-size: 10.5px;
  font-weight: 700;
  text-transform: uppercase;
  border-radius: 5px;
  padding: 1px 6px;
  min-width: 48px;
  text-align: center;
}
.issue-reject { background: var(--danger-soft); color: var(--danger); }
.issue-hold { background: var(--info-soft); color: var(--info); }
.issue-warn { background: var(--warn-soft); color: var(--warn); }
.issue-riayati { background: var(--surface-2); color: var(--text-2); }
