/* =====================================================================
   Message Gateway — interface system
   Machine data is monospace. Human writing is not.
   ===================================================================== */

@import url('https://fonts.googleapis.com/css2?family=Space+Grotesk:wght@500;600;700&family=IBM+Plex+Sans:wght@400;500;600;700&family=IBM+Plex+Mono:wght@400;500;600&display=swap');

:root {
  --canvas:    #F5F7FA;
  --surface:   #FFFFFF;
  --sunken:    #EDF1F5;
  --veil:      rgba(255, 255, 255, .72);

  --ink:       #0F1720;
  --ink-2:     #46545F;
  --ink-3:     #7C8B97;
  --ink-4:     #A6B2BD;

  --line:      #E3E9EF;
  --line-2:    #CFD9E2;

  --pine:      #0E7C6B;
  --pine-700:  #0A5D50;
  --mint:      #17C39A;
  --pine-50:   #E8F6F2;

  --good:      #10906B;
  --good-50:   #E6F5EF;
  --warn:      #B26E0F;
  --warn-50:   #FDF3E3;
  --fault:     #C0392B;
  --fault-50:  #FCECEA;
  --info:      #2A6FB0;
  --info-50:   #E9F2FA;

  --display: 'Space Grotesk', ui-sans-serif, system-ui, sans-serif;
  --body:    'IBM Plex Sans', ui-sans-serif, system-ui, sans-serif;
  --mono:    'IBM Plex Mono', ui-monospace, 'SFMono-Regular', monospace;

  --r-sm: 8px;
  --r:    12px;
  --r-lg: 16px;

  --e1: 0 1px 2px rgba(15, 23, 32, .05), 0 1px 3px rgba(15, 23, 32, .04);
  --e2: 0 2px 4px rgba(15, 23, 32, .04), 0 8px 20px -6px rgba(15, 23, 32, .10);
  --ring: 0 0 0 4px rgba(14, 124, 107, .13);
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--canvas);
  color: var(--ink);
  font-family: var(--body);
  font-size: 15px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

h1, h2, h3, h4 {
  font-family: var(--display);
  font-weight: 600;
  letter-spacing: -.02em;
  margin: 0;
  color: var(--ink);
}

a { color: var(--pine); text-decoration: none; }
a:hover { color: var(--pine-700); }

:focus-visible { outline: 2px solid var(--pine); outline-offset: 2px; border-radius: 4px; }

.mono, code, kbd, .data {
  font-family: var(--mono);
  font-size: .87em;
  font-variant-ligatures: none;
  letter-spacing: -.01em;
}

/* ================================ Shell ============================= */

.shell { display: flex; min-height: 100vh; }

.sidebar {
  width: 250px;
  flex: 0 0 250px;
  background:
    radial-gradient(620px 340px at 12% -6%, rgba(23, 195, 154, .16), transparent 62%),
    linear-gradient(168deg, #0D1A20 0%, #0B211E 46%, #072B26 100%);
  color: #C2D0D9;
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
  border-right: 1px solid rgba(255, 255, 255, .06);
}

.brand { padding: 24px 22px 20px; display: flex; align-items: center; gap: 11px; }
.brand-glyph {
  width: 34px; height: 34px; flex: none;
  border-radius: 10px;
  background: linear-gradient(145deg, var(--mint), var(--pine));
  display: grid; place-items: center;
  box-shadow: 0 4px 14px -3px rgba(23, 195, 154, .5);
}
.brand-glyph svg { width: 18px; height: 18px; color: #05231E; }
.brand-mark {
  font-family: var(--display);
  font-size: 15.5px; font-weight: 700; color: #fff;
  letter-spacing: -.025em; display: block; line-height: 1.2;
}
.brand-sub {
  font-family: var(--mono);
  font-size: 9.5px; text-transform: uppercase; letter-spacing: .16em;
  color: #6C7F8C; display: block; margin-top: 1px;
}

.nav { padding: 8px 12px 14px; flex: 1; overflow-y: auto; }

.nav-label {
  font-family: var(--mono);
  font-size: 9.5px; text-transform: uppercase; letter-spacing: .17em;
  color: #5D7080; padding: 16px 10px 7px;
}

.nav-item {
  position: relative;
  display: flex; align-items: center; gap: 11px;
  padding: 9px 12px;
  border-radius: var(--r-sm);
  color: #BCCAD4;
  font-size: 14px; font-weight: 500;
  margin-bottom: 2px;
  transition: background .16s ease, color .16s ease, transform .16s ease;
}
.nav-item:hover { background: rgba(255, 255, 255, .07); color: #fff; transform: translateX(2px); }
.nav-item.is-active {
  background: linear-gradient(90deg, rgba(23, 195, 154, .20), rgba(23, 195, 154, .05));
  color: #fff; font-weight: 600;
}
.nav-item.is-active::before {
  content: '';
  position: absolute; left: -12px; top: 50%;
  transform: translateY(-50%);
  width: 3px; height: 20px;
  border-radius: 0 3px 3px 0;
  background: var(--mint);
  box-shadow: 0 0 12px rgba(23, 195, 154, .8);
}
.nav-item svg { width: 17px; height: 17px; flex: none; opacity: .85; }
.nav-item.is-active svg { opacity: 1; color: var(--mint); }

.sidebar-foot { padding: 14px; border-top: 1px solid rgba(255, 255, 255, .07); }
.whoami {
  display: flex; align-items: center; gap: 11px;
  padding: 8px; border-radius: var(--r-sm);
  background: rgba(255, 255, 255, .05);
  margin-bottom: 10px;
}
.avatar {
  width: 32px; height: 32px; flex: none;
  border-radius: 9px;
  background: linear-gradient(145deg, #1B3A38, #0E5147);
  color: var(--mint);
  font-family: var(--mono); font-size: 12px; font-weight: 600;
  display: grid; place-items: center;
  border: 1px solid rgba(23, 195, 154, .22);
}
.whoami-name {
  font-size: 13px; font-weight: 600; color: #E6EDF2; line-height: 1.3;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 140px;
}
.whoami-role {
  font-family: var(--mono); font-size: 9.5px;
  text-transform: uppercase; letter-spacing: .12em; color: #6C7F8C;
}

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }

.topbar {
  background: var(--veil);
  backdrop-filter: saturate(180%) blur(14px);
  -webkit-backdrop-filter: saturate(180%) blur(14px);
  border-bottom: 1px solid var(--line);
  padding: 0 32px;
  min-height: 72px;
  display: flex; align-items: center; justify-content: space-between;
  gap: 18px;
  position: sticky; top: 0; z-index: 20;
}
.topbar h1 { font-size: 22px; letter-spacing: -.03em; }
.topbar-sub { font-size: 13.5px; color: var(--ink-3); margin-top: 2px; }

.content { padding: 28px 32px 64px; flex: 1; }
.content-narrow { max-width: 760px; }

.content > * { animation: rise .45s cubic-bezier(.2, .7, .3, 1) backwards; }
.content > *:nth-child(2) { animation-delay: .04s; }
.content > *:nth-child(3) { animation-delay: .08s; }
.content > *:nth-child(4) { animation-delay: .12s; }

@keyframes rise {
  from { opacity: 0; transform: translateY(10px); }
  to   { opacity: 1; transform: none; }
}

/* ============================= Stat tiles =========================== */

.tiles {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(215px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}

.tile {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  padding: 18px 20px;
  box-shadow: var(--e1);
  overflow: hidden;
  transition: transform .18s ease, box-shadow .18s ease;
}
.tile:hover { transform: translateY(-2px); box-shadow: var(--e2); }
.tile::after {
  content: '';
  position: absolute; inset: 0 0 auto 0; height: 3px;
  background: linear-gradient(90deg, var(--mint), var(--pine));
  opacity: .9;
}
.tile.is-fault::after { background: linear-gradient(90deg, #E0685A, var(--fault)); }
.tile.is-warn::after  { background: linear-gradient(90deg, #E8A947, var(--warn)); }
.tile.is-idle::after  { background: linear-gradient(90deg, var(--line-2), var(--ink-4)); }

.tile-top { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.tile-label {
  font-family: var(--mono); font-size: 10px;
  text-transform: uppercase; letter-spacing: .13em; color: var(--ink-3);
}
.tile-chip {
  width: 32px; height: 32px; border-radius: 9px;
  display: grid; place-items: center;
  background: var(--pine-50); color: var(--pine);
}
.tile-chip svg { width: 16px; height: 16px; }
.tile.is-fault .tile-chip { background: var(--fault-50); color: var(--fault); }
.tile.is-warn  .tile-chip { background: var(--warn-50);  color: var(--warn); }
.tile.is-idle  .tile-chip { background: var(--sunken);   color: var(--ink-3); }

.tile-value {
  font-family: var(--display);
  font-size: 30px; font-weight: 600;
  letter-spacing: -.035em; line-height: 1.1;
  font-variant-numeric: tabular-nums;
}
.tile-note { font-size: 12.5px; color: var(--ink-3); margin-top: 4px; }
.tile-note strong { color: var(--ink-2); font-weight: 600; }

/* =============================== Cards ============================== */

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  box-shadow: var(--e1);
  overflow: hidden;
}
.card + .card { margin-top: 20px; }

.card-head {
  padding: 18px 22px;
  border-bottom: 1px solid var(--line);
  display: flex; align-items: center; justify-content: space-between;
  gap: 16px; flex-wrap: wrap;
  background: linear-gradient(180deg, #FCFDFE, var(--surface));
}
.card-head h2 { font-size: 16px; font-weight: 600; }
.card-head p { margin: 3px 0 0; font-size: 13px; color: var(--ink-3); max-width: 62ch; }
.card-body { padding: 22px; }
.card-foot {
  padding: 16px 22px;
  border-top: 1px solid var(--line);
  background: #FAFCFD;
  display: flex; gap: 10px; align-items: center;
}

.rail { border-left: 3px solid var(--line-2); }
.rail-good  { border-left-color: var(--good); }
.rail-warn  { border-left-color: var(--warn); }
.rail-fault { border-left-color: var(--fault); }
.rail-idle  { border-left-color: var(--line-2); }

/* ============================== Tables ============================== */

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

table.grid { width: 100%; border-collapse: collapse; font-size: 14px; }

table.grid th {
  text-align: left;
  font-family: var(--mono);
  font-size: 10px; font-weight: 600;
  text-transform: uppercase; letter-spacing: .13em;
  color: var(--ink-3);
  padding: 12px 18px;
  background: #FAFCFD;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}
table.grid td { padding: 14px 18px; border-bottom: 1px solid var(--line); vertical-align: middle; }
table.grid tbody tr { transition: background .13s ease; }
table.grid tbody tr:last-child td { border-bottom: 0; }
table.grid tbody tr:hover { background: #F8FBFC; }

table.grid td:first-child { border-left: 3px solid transparent; transition: border-color .13s ease; }
table.grid tr.rail-good  td:first-child { border-left-color: var(--good); }
table.grid tr.rail-fault td:first-child { border-left-color: var(--fault); }
table.grid tr.rail-warn  td:first-child { border-left-color: var(--warn); }
table.grid tr.rail-idle  td:first-child { border-left-color: var(--line-2); }

.cell-title { font-weight: 600; color: var(--ink); }
a.cell-title:hover { color: var(--pine); }
.cell-sub { font-size: 12.5px; color: var(--ink-3); }
.cell-actions { text-align: right; white-space: nowrap; }

.empty { padding: 64px 24px; text-align: center; color: var(--ink-3); }
.empty-glyph {
  width: 52px; height: 52px; margin: 0 auto 16px;
  border-radius: 15px; background: var(--sunken); color: var(--ink-4);
  display: grid; place-items: center;
}
.empty-glyph svg { width: 24px; height: 24px; }
.empty strong {
  display: block; color: var(--ink);
  font-family: var(--display); font-size: 16px; margin-bottom: 5px;
}

/* ============================== Badges ============================== */

.badge {
  display: inline-flex; align-items: center; gap: 6px;
  font-family: var(--mono);
  font-size: 10px; font-weight: 600;
  text-transform: uppercase; letter-spacing: .09em;
  padding: 4px 9px;
  border-radius: 999px;
  border: 1px solid transparent;
  white-space: nowrap;
}
.badge::before { content: ''; width: 5px; height: 5px; border-radius: 50%; background: currentColor; }
.badge-good  { color: var(--good);  background: var(--good-50);  border-color: #BEE4D4; }
.badge-good::before { box-shadow: 0 0 0 3px rgba(16, 144, 107, .16); }
.badge-fault { color: var(--fault); background: var(--fault-50); border-color: #F2C9C4; }
.badge-warn  { color: var(--warn);  background: var(--warn-50);  border-color: #EDD6AE; }
.badge-idle  { color: var(--ink-3); background: var(--sunken);   border-color: var(--line-2); }
.badge-info  { color: var(--pine);  background: var(--pine-50);  border-color: #B8DED6; }

/* ============================= Buttons ============================== */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  font-family: var(--body);
  font-size: 14px; font-weight: 500; line-height: 1;
  padding: 10px 16px;
  border-radius: var(--r-sm);
  border: 1px solid var(--line-2);
  background: var(--surface);
  color: var(--ink);
  cursor: pointer;
  text-decoration: none;
  box-shadow: var(--e1);
  transition: background .15s ease, border-color .15s ease, box-shadow .15s ease, transform .1s ease;
}
.btn:hover { background: #F7FAFB; border-color: var(--ink-4); box-shadow: var(--e2); color: var(--ink); }
.btn:active { transform: translateY(1px); box-shadow: var(--e1); }

.btn-primary {
  background: linear-gradient(160deg, var(--pine), var(--pine-700));
  border-color: var(--pine-700);
  color: #fff;
  box-shadow: 0 1px 2px rgba(7, 47, 42, .2), 0 6px 16px -6px rgba(14, 124, 107, .5);
}
.btn-primary:hover {
  background: linear-gradient(160deg, #108975, var(--pine-700));
  color: #fff;
  box-shadow: 0 2px 4px rgba(7, 47, 42, .22), 0 10px 24px -8px rgba(14, 124, 107, .6);
}

.btn-danger { color: var(--fault); border-color: #EBC2BC; }
.btn-danger:hover { background: var(--fault-50); border-color: var(--fault); color: var(--fault); }

.btn-sm { padding: 7px 12px; font-size: 13px; }
.btn-block { width: 100%; }
.btn[disabled] { opacity: .5; cursor: not-allowed; }
.btn svg { width: 15px; height: 15px; }

.inline-form { display: inline; }

/* ============================== Forms =============================== */

.field { margin-bottom: 19px; }
.field:last-child { margin-bottom: 0; }

.field label { display: block; font-size: 13px; font-weight: 600; color: var(--ink-2); margin-bottom: 7px; }
.field .hint { font-size: 12.5px; color: var(--ink-3); margin: 6px 0 0; }
.field .req { color: var(--fault); }

.input, .select, .textarea {
  width: 100%;
  font-family: var(--body);
  font-size: 14.5px;
  color: var(--ink);
  padding: 11px 13px;
  border: 1px solid var(--line-2);
  border-radius: var(--r-sm);
  background: var(--surface);
  transition: border-color .15s ease, box-shadow .15s ease, background .15s ease;
}
.input::placeholder { color: var(--ink-4); }
.input:hover, .select:hover, .textarea:hover { border-color: var(--ink-4); }
.input:focus, .select:focus, .textarea:focus { outline: none; border-color: var(--pine); box-shadow: var(--ring); }
.input.mono { font-family: var(--mono); font-size: 13.5px; }
.textarea { min-height: 96px; resize: vertical; }

.select {
  appearance: none;
  background-image: url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8' fill='none'%3E%3Cpath d='M1 1.5L6 6.5L11 1.5' stroke='%237C8B97' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 13px center;
  padding-right: 36px;
  cursor: pointer;
}

.field.has-error .input,
.field.has-error .select { border-color: var(--fault); background: #FFFCFC; }
.field.has-error .input:focus { box-shadow: 0 0 0 4px rgba(192, 57, 43, .12); }
.field-error { font-size: 12.5px; color: var(--fault); margin: 6px 0 0; font-weight: 500; }

.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }

.check { display: flex; align-items: flex-start; gap: 10px; font-size: 14px; }
.check input { margin-top: 3px; accent-color: var(--pine); width: 16px; height: 16px; }

/* ============================== Flash =============================== */

.flash {
  display: flex; align-items: flex-start; gap: 11px;
  padding: 14px 18px;
  border-radius: var(--r);
  border: 1px solid;
  border-left-width: 3px;
  font-size: 14px;
  margin-bottom: 20px;
  box-shadow: var(--e1);
}
.flash-success { background: var(--good-50);  border-color: #BEE4D4; border-left-color: var(--good);  color: #0C4C38; }
.flash-error   { background: var(--fault-50); border-color: #F2C9C4; border-left-color: var(--fault); color: #7C241A; }
.flash-info    { background: var(--info-50);  border-color: #C4DCF0; border-left-color: var(--info);  color: #1B4C7A; }

/* ============================== Login =============================== */

.auth-page { min-height: 100vh; display: grid; grid-template-columns: 1.05fr 1fr; }

.auth-aside {
  background:
    radial-gradient(760px 460px at 76% 14%, rgba(23, 195, 154, .22), transparent 64%),
    radial-gradient(560px 420px at 8% 92%, rgba(20, 110, 160, .16), transparent 60%),
    linear-gradient(168deg, #0C171D 0%, #0A2320 52%, #062E28 100%);
  color: #fff;
  padding: 52px;
  display: flex; flex-direction: column; justify-content: space-between;
  position: relative; overflow: hidden;
}
.auth-aside::before {
  content: '';
  position: absolute; inset: 0;
  background-image:
    linear-gradient(rgba(255,255,255,.028) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255,255,255,.028) 1px, transparent 1px);
  background-size: 46px 46px;
  mask-image: radial-gradient(70% 60% at 50% 40%, #000 40%, transparent 100%);
  -webkit-mask-image: radial-gradient(70% 60% at 50% 40%, #000 40%, transparent 100%);
  pointer-events: none;
}
.auth-aside > * { position: relative; z-index: 1; }

.auth-brand { display: flex; align-items: center; gap: 11px; }
.auth-brand-text { font-family: var(--display); font-size: 16px; font-weight: 700; letter-spacing: -.025em; }

.auth-headline {
  font-family: var(--display);
  font-size: clamp(30px, 3.4vw, 42px);
  font-weight: 600; line-height: 1.12; letter-spacing: -.035em;
  margin: 0 0 16px; max-width: 14ch;
}
.auth-headline em {
  font-style: normal;
  background: linear-gradient(96deg, var(--mint), #7BE3C8);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.auth-copy { color: #94A6B2; font-size: 15.5px; max-width: 40ch; margin: 0; line-height: 1.65; }

.routemap {
  margin: 38px 0 0;
  font-family: var(--mono);
  font-size: 12px;
  border: 1px solid rgba(255,255,255,.09);
  border-radius: var(--r);
  padding: 16px 18px;
  background: rgba(255,255,255,.03);
  backdrop-filter: blur(6px);
  max-width: 340px;
}
.routemap-row { display: flex; align-items: center; gap: 10px; padding: 6px 0; color: #8496A3; }
.routemap-pipe { color: #35474F; letter-spacing: .08em; }
.routemap-row.hit  { color: #7BE3C8; }
.routemap-row.miss { color: #D89189; }
.routemap-dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; flex: none; }
.routemap-row.hit .routemap-dot { animation: pulse 2.6s ease-in-out infinite; }
.routemap-tail { margin-left: auto; opacity: .72; font-size: 11px; }

@keyframes pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(123, 227, 200, .55); }
  55%      { box-shadow: 0 0 0 6px rgba(123, 227, 200, 0); }
}

.auth-foot {
  font-family: var(--mono); font-size: 10.5px;
  color: #566A76; letter-spacing: .1em; text-transform: uppercase;
}

.auth-main { display: grid; place-items: center; padding: 44px 36px; background: var(--canvas); }
.auth-box { width: 100%; max-width: 384px; animation: rise .5s cubic-bezier(.2,.7,.3,1) backwards; }
.auth-box h1 { font-size: 28px; margin-bottom: 6px; letter-spacing: -.035em; }
.auth-box .lede { color: var(--ink-3); font-size: 14.5px; margin: 0 0 28px; }

/* ============================= Toolbar ============================== */

.toolbar { display: flex; gap: 11px; align-items: center; flex-wrap: wrap; margin-bottom: 20px; }
.toolbar .spacer { flex: 1; }

.search { position: relative; min-width: 260px; flex: 1; max-width: 420px; }
.search .input { padding-left: 38px; }
.search svg {
  position: absolute; left: 13px; top: 50%;
  transform: translateY(-50%);
  width: 16px; height: 16px;
  color: var(--ink-4);
  pointer-events: none;
}

.you-tag {
  font-family: var(--mono);
  font-size: 9px; text-transform: uppercase; letter-spacing: .12em;
  color: var(--pine); background: var(--pine-50);
  border: 1px solid #B8DED6; border-radius: 999px;
  padding: 2px 7px; margin-left: 8px; vertical-align: 1px;
}

.stack { display: flex; flex-direction: column; gap: 3px; }
hr.rule { border: 0; border-top: 1px solid var(--line); margin: 24px 0; }

.keyline {
  display: flex; align-items: center; gap: 10px;
  font-family: var(--mono); font-size: 13px;
  background: var(--sunken);
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  padding: 10px 13px;
  word-break: break-all;
}

/* =========================== Responsive ============================= */

@media (max-width: 1000px) {
  .auth-page { grid-template-columns: 1fr; }
  .auth-aside { display: none; }
}

@media (max-width: 860px) {
  .shell { flex-direction: column; }
  .sidebar {
    width: 100%; flex: none; height: auto; position: static;
    flex-direction: row; align-items: center; justify-content: space-between;
    padding-right: 12px;
  }
  .brand { padding: 14px 16px; }
  .brand-text { display: none; }
  .nav { display: flex; gap: 4px; padding: 0 8px; overflow-x: auto; }
  .nav-label { display: none; }
  .nav-item { white-space: nowrap; }
  .nav-item.is-active::before { display: none; }
  .sidebar-foot { border-top: 0; padding: 10px 12px; }
  .whoami { margin-bottom: 0; padding: 4px; background: none; }
  .whoami-name, .whoami-role { display: none; }
  .sidebar-foot form { display: none; }
  .topbar { padding: 0 16px; min-height: 64px; }
  .topbar h1 { font-size: 19px; }
  .content { padding: 18px 14px 48px; }
  .field-row { grid-template-columns: 1fr; }
  .tiles { grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; }
  .tile-value { font-size: 25px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .001ms !important;
  }
}
