:root {
  --bg: #0b0f17;
  --bg-2: #111725;
  --panel: #151c2c;
  --panel-2: #1b2436;
  --border: #243049;
  --text: #e6ebf5;
  --muted: #8a97b1;
  --accent: #4f8cff;
  --accent-2: #6ee7b7;
  --danger: #f87171;
  --warn: #fbbf24;
  --ok: #34d399;
  --radius: 12px;
  --shadow: 0 8px 30px rgba(0,0,0,.35);
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  background: radial-gradient(1200px 600px at 80% -10%, #16203a 0%, var(--bg) 55%);
  color: var(--text);
  font-size: 14px;
}
code, .code-input, .mono { font-family: 'JetBrains Mono', ui-monospace, monospace; }

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

/* Sidebar */
.sidebar {
  width: 248px; flex-shrink: 0;
  background: linear-gradient(180deg, var(--bg-2), #0d1320);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
  padding: 20px 14px;
  position: sticky; top: 0; height: 100vh;
}
.brand { display: flex; align-items: center; gap: 12px; padding: 6px 8px 22px; }
.brand-mark {
  width: 40px; height: 40px; border-radius: 10px;
  background: linear-gradient(135deg, var(--accent), #7c5cff);
  display: grid; place-items: center; font-weight: 700; letter-spacing: .5px;
  box-shadow: 0 4px 14px rgba(79,140,255,.4);
}
.brand-text { display: flex; flex-direction: column; line-height: 1.2; }
.brand-text strong { font-size: 15px; }
.brand-text span { font-size: 11px; color: var(--muted); }

.nav { display: flex; flex-direction: column; gap: 4px; }
.nav-item {
  display: flex; align-items: center; gap: 12px;
  background: transparent; border: 0; color: var(--muted);
  padding: 11px 12px; border-radius: 9px; cursor: pointer;
  font-size: 14px; font-weight: 500; text-align: left; transition: .15s;
}
.nav-item .ico { width: 18px; text-align: center; opacity: .8; }
.nav-item:hover { background: var(--panel); color: var(--text); }
.nav-item.active { background: var(--panel-2); color: #fff; box-shadow: inset 3px 0 0 var(--accent); }

.sidebar-foot { margin-top: auto; display: flex; flex-direction: column; gap: 12px; padding: 12px 8px 4px; }
.link-out { color: var(--accent); text-decoration: none; font-size: 13px; font-weight: 500; }
.link-out:hover { text-decoration: underline; }
.status-dot { display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--muted); }
.status-dot .dot { width: 9px; height: 9px; border-radius: 50%; background: var(--muted); }
.status-dot.ok .dot { background: var(--ok); box-shadow: 0 0 8px var(--ok); }
.status-dot.down .dot { background: var(--danger); box-shadow: 0 0 8px var(--danger); }

/* Main */
.main { flex: 1; padding: 28px 34px; max-width: 1400px; }
.view { display: none; animation: fade .25s ease; }
.view.active { display: block; }
@keyframes fade { from { opacity: 0; transform: translateY(6px);} to {opacity:1; transform:none;} }

.view-head { display: flex; justify-content: space-between; align-items: flex-end; margin-bottom: 22px; gap: 16px; flex-wrap: wrap; }
.view-head h1 { margin: 0; font-size: 24px; font-weight: 700; }
.subtitle { margin: 4px 0 0; color: var(--muted); font-size: 13.5px; }
.head-actions { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }

/* Buttons */
.btn { border: 1px solid var(--border); background: var(--panel-2); color: var(--text);
  padding: 9px 16px; border-radius: 9px; cursor: pointer; font-weight: 600; font-size: 13.5px; transition: .15s; }
.btn:hover { border-color: var(--accent); }
.btn.primary { background: linear-gradient(135deg, var(--accent), #6a73ff); border: 0; box-shadow: 0 4px 14px rgba(79,140,255,.35); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.ghost { background: transparent; }
.btn.ghost.danger { color: var(--danger); border-color: transparent; }
.btn.ghost.danger:hover { border-color: var(--danger); }
.btn.sm { padding: 6px 11px; font-size: 12px; }

.toggle { display: inline-flex; align-items: center; gap: 8px; color: var(--muted); font-size: 13px; cursor: pointer; user-select: none; }
.toggle input { accent-color: var(--accent); width: 15px; height: 15px; }

/* Stat grid */
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(165px, 1fr)); gap: 14px; margin-bottom: 22px; }
.stat-card { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px 18px; }
.stat-card .label { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .6px; }
.stat-card .value { font-size: 28px; font-weight: 700; margin-top: 8px; }
.stat-card .value.small { font-size: 18px; }
.stat-card .sub { font-size: 12px; color: var(--muted); margin-top: 2px; }
.stat-card.accent .value { color: var(--accent-2); }

/* Panels */
.panel { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); margin-bottom: 18px; overflow: hidden; }
.panel-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 18px; border-bottom: 1px solid var(--border); }
.panel-head h3 { margin: 0; font-size: 14.5px; font-weight: 600; }
.panel-body { padding: 18px; }
.panel-body.no-pad { padding: 0; }
.panel-row { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
.split { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; align-items: start; }

@media (max-width: 980px) {
  .panel-row, .split { grid-template-columns: 1fr; }
  .sidebar { width: 70px; }
  .brand-text, .nav-item span:not(.ico), .sidebar-foot .link-out, #conn-text { display: none; }
}

/* Tables */
.data-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.data-table th { text-align: left; padding: 11px 16px; color: var(--muted); font-weight: 600; font-size: 11.5px; text-transform: uppercase; letter-spacing: .5px; border-bottom: 1px solid var(--border); position: sticky; top: 0; background: var(--panel); }
.data-table td { padding: 10px 16px; border-bottom: 1px solid rgba(36,48,73,.5); }
.data-table tbody tr:hover { background: var(--panel-2); }
.data-table .center { text-align: center; }
.tx-scroll { max-height: 62vh; overflow: auto; }

/* Pills / badges */
.pill { display: inline-block; padding: 3px 9px; border-radius: 20px; font-size: 11.5px; font-weight: 600; }
.pill.in { background: rgba(79,140,255,.15); color: #8db4ff; }
.pill.out { background: rgba(124,92,255,.18); color: #b8a4ff; }
.pill.ok { background: rgba(52,211,153,.15); color: var(--ok); }
.pill.fail { background: rgba(248,113,113,.15); color: var(--danger); }
.pill.explicit { background: rgba(110,231,183,.13); color: var(--accent-2); }
.pill.fallback { background: rgba(148,163,184,.15); color: var(--muted); }
.pill.x12 { background: rgba(251,191,36,.13); color: var(--warn); }
.pill.edifact { background: rgba(96,165,250,.14); color: #93c5fd; }

/* Inputs */
.code-input, input, select, textarea {
  width: 100%; background: var(--bg-2); border: 1px solid var(--border);
  color: var(--text); border-radius: 9px; padding: 10px 12px; font-size: 13px; outline: none; transition: .15s;
}
.code-input { resize: vertical; line-height: 1.5; font-size: 12.5px; }
input:focus, select:focus, textarea:focus { border-color: var(--accent); }
.search { width: auto; min-width: 200px; }
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; flex: 1; }
.field label { font-size: 12px; color: var(--muted); font-weight: 600; }
.field-row { display: flex; gap: 12px; }
.field.shrink { flex: 0 0 110px; }
.options { display: flex; gap: 18px; margin: 12px 0 16px; }

.segmented { display: inline-flex; background: var(--bg-2); border: 1px solid var(--border); border-radius: 9px; padding: 3px; }
.seg { background: transparent; border: 0; color: var(--muted); padding: 7px 14px; border-radius: 7px; cursor: pointer; font-size: 13px; font-weight: 600; }
.seg.active { background: var(--panel-2); color: #fff; }

/* Result blocks */
pre.out { background: var(--bg-2); border: 1px solid var(--border); border-radius: 9px; padding: 14px; overflow: auto; font-size: 12px; line-height: 1.55; max-height: 360px; white-space: pre-wrap; word-break: break-word; }
.result-meta { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 12px; }
.result-inline { margin-top: 12px; }
.kv { display: flex; gap: 8px; font-size: 13px; padding: 4px 0; }
.kv .k { color: var(--muted); min-width: 130px; }
.section-label { font-size: 11.5px; text-transform: uppercase; letter-spacing: .5px; color: var(--muted); margin: 16px 0 7px; font-weight: 600; }

.muted { color: var(--muted); }
.center { text-align: center; }
.bar { height: 7px; background: var(--bg-2); border-radius: 6px; overflow: hidden; margin-top: 5px; }
.bar > span { display: block; height: 100%; background: linear-gradient(90deg, var(--accent), var(--accent-2)); }
.type-row { display: flex; align-items: center; justify-content: space-between; padding: 7px 0; gap: 12px; }
.type-row .name { flex: 1; }
.type-row .cnt { color: var(--accent-2); font-weight: 700; }

/* Login overlay */
.login-overlay {
  position: fixed; inset: 0; z-index: 100;
  display: none; align-items: center; justify-content: center;
  background: radial-gradient(900px 500px at 50% 0%, #16203a 0%, #070a11 70%);
}
.login-overlay.show { display: flex; }
.app-root.blurred, .app.blurred { filter: blur(4px); pointer-events: none; }
.login-card {
  width: 380px; max-width: 92vw; background: var(--panel); border: 1px solid var(--border);
  border-radius: 16px; padding: 32px; box-shadow: var(--shadow);
}
.login-brand { text-align: center; margin-bottom: 22px; }
.login-brand h2 { margin: 14px 0 4px; font-size: 20px; }
.brand-mark.lg { width: 56px; height: 56px; border-radius: 14px; font-size: 18px; margin: 0 auto; }
.login-card .field { margin-bottom: 16px; }
.login-error { color: var(--danger); font-size: 13px; min-height: 18px; margin-bottom: 8px; }
.btn.full { width: 100%; justify-content: center; }

/* User chip in sidebar */
.user-chip { display: flex; align-items: center; gap: 10px; background: var(--panel); border: 1px solid var(--border); border-radius: 10px; padding: 8px 10px; }
.avatar { width: 32px; height: 32px; border-radius: 50%; background: linear-gradient(135deg, var(--accent), #7c5cff); display: grid; place-items: center; font-size: 10px; flex-shrink: 0; }
.user-meta { display: flex; flex-direction: column; line-height: 1.25; overflow: hidden; flex: 1; }
.user-meta strong { font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-meta span { font-size: 11px; text-transform: uppercase; letter-spacing: .4px; }
.icon-btn { background: transparent; border: 0; color: var(--muted); cursor: pointer; font-size: 16px; padding: 4px; border-radius: 6px; }
.icon-btn:hover { color: var(--danger); background: var(--panel-2); }
.row-actions { display: flex; gap: 6px; justify-content: flex-end; }
.mini-select { width: auto; min-width: 150px; padding: 5px 8px; font-size: 12.5px; }
.mini-input { width: auto; min-width: 150px; padding: 5px 8px; font-size: 12.5px; }
.fwd-edit { display: flex; gap: 6px; margin-top: 5px; flex-wrap: wrap; }
.fwd-edit .mini-input { min-width: 130px; }
.fwd-edit .mini-select { min-width: 90px; }

@media (max-width: 980px) {
  .user-meta, .user-chip .icon-btn { display: none; }
}

/* Toast */
.toast { position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%) translateY(20px);
  background: var(--panel-2); border: 1px solid var(--border); color: var(--text);
  padding: 12px 20px; border-radius: 10px; box-shadow: var(--shadow); opacity: 0; pointer-events: none; transition: .25s; font-size: 13.5px; z-index: 50; }
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.ok { border-color: var(--ok); }
.toast.err { border-color: var(--danger); }
