:root {
  --bg: #f3f5f8;
  --panel: #ffffff;
  --ink: #18212f;
  --muted: #667085;
  --line: #e4e7ec;
  --brand: #2563eb;
  --brand-soft: #eff4ff;
  --ok: #159947;
  --warn: #c47f0a;
  --crit: #d92d20;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.05);
  --radius: 12px;
  --topbar-h: auto;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

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

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 16px;
  font-weight: 700;
  letter-spacing: -0.2px;
}

h2 {
  font-size: 14px;
  font-weight: 700;
}

.token-gate {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(15, 23, 42, 0.55);
  backdrop-filter: blur(3px);
}

.token-card {
  width: min(420px, 100%);
  background: #fff;
  border-radius: 14px;
  border: 1px solid var(--line);
  box-shadow: 0 20px 50px rgba(15, 23, 42, 0.25);
  padding: 18px;
  display: grid;
  gap: 12px;
}

.token-card h2 {
  font-size: 18px;
}

.token-card p {
  font-size: 13px;
  color: var(--muted);
}

.token-error {
  color: var(--crit);
  font-size: 12px;
  font-weight: 600;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}

.app {
  height: 100vh;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  min-width: 0;
  padding: 10px 12px 12px;
  gap: 10px;
}

.topbar {
  display: grid;
  grid-template-columns: minmax(180px, 240px) 1fr auto;
  gap: 10px 14px;
  align-items: center;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 8px 12px;
  box-shadow: var(--shadow);
  flex-shrink: 0;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.brand-mark {
  width: 34px;
  height: 34px;
  border-radius: 9px;
  display: grid;
  place-items: center;
  background: #fff;
  border: 1px solid var(--line);
  flex-shrink: 0;
}

.brand-mark img {
  width: 20px;
  height: 22px;
  display: block;
}

.brand-text {
  min-width: 0;
}

.brand-text p {
  margin-top: 1px;
  font-size: 11px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.status-strip {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  min-width: 0;
}

.status-chip,
.meter-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 28px;
  padding: 0 8px;
  border-radius: 8px;
  background: #f8fafc;
  border: 1px solid var(--line);
  font-size: 11px;
  max-width: 100%;
}

.status-chip.wide strong {
  max-width: 160px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.status-label {
  color: var(--muted);
  font-weight: 600;
}

.status-chip strong,
.meter-chip strong {
  font-size: 11px;
  font-weight: 700;
  color: var(--ink);
}

.meter-chip {
  min-width: 92px;
}

.mini-bar {
  width: 36px;
  height: 5px;
  border-radius: 999px;
  background: #e8edf5;
  overflow: hidden;
}

.bar-fill {
  height: 100%;
  width: 0%;
  border-radius: 999px;
  background: var(--ok);
  transition: width 0.35s ease, background 0.25s;
}

.bar-fill.ok {
  background: var(--ok);
}

.bar-fill.warn {
  background: var(--warn);
}

.bar-fill.crit {
  background: var(--crit);
}

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

button {
  height: 32px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  padding: 0 12px;
  font-weight: 600;
  font-size: 12px;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}

button:hover {
  background: #f5f7fb;
}

button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

button.primary {
  background: var(--brand);
  border-color: var(--brand);
  color: #fff;
}

button.primary:hover {
  filter: brightness(1.05);
}

button.ghost {
  background: #fff;
}

button.danger {
  color: var(--crit);
  border-color: #f3c8c8;
}

button.danger:hover {
  background: #fdeaea;
}

.icon-btn {
  width: 32px;
  height: 32px;
  padding: 0;
  font-size: 20px;
  line-height: 1;
  color: var(--muted);
}

.switch {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 11px;
  color: var(--muted);
  cursor: pointer;
  user-select: none;
}

.conn-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 28px;
  padding: 0 10px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
  border: 1px solid var(--line);
}

.conn-badge .dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: currentColor;
}

.conn-badge.online {
  color: var(--ok);
  background: #eafaf0;
  border-color: #c5ecd3;
}

.conn-badge.offline {
  color: var(--crit);
  background: #fdeef0;
  border-color: #f3cdd3;
}

.workspace {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.pane {
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.pane-toolbar {
  flex-shrink: 0;
  padding: 10px 12px 8px;
  border-bottom: 1px solid var(--line);
  background: linear-gradient(180deg, #fff 0%, #fbfcfe 100%);
  position: sticky;
  top: 0;
  z-index: 2;
}

.pane-title {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
}

.log-copy-all {
  margin-left: auto;
  padding: 5px 9px;
  font-size: 11px;
}

.muted-chip {
  font-size: 11px;
  font-weight: 600;
  color: var(--muted);
  background: #f2f4f8;
  border-radius: 999px;
  padding: 2px 8px;
}

.pane-filters {
  display: grid;
  grid-template-columns: minmax(140px, 220px);
  gap: 8px;
  align-items: end;
}

.jobs-pane .pane-filters {
  grid-template-columns: repeat(2, minmax(140px, 220px));
}

.log-filters {
  grid-template-columns: repeat(4, minmax(100px, 1fr));
}

.pane-filters .grow {
  min-width: 0;
}

.firm-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  margin-top: 8px;
  max-height: 52px;
  overflow: auto;
}

.log-pagination {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 8px;
}

.log-pagination button {
  height: 28px;
  padding: 0 10px;
  font-size: 11px;
}

.log-pagination span {
  min-width: 58px;
  text-align: center;
  color: var(--muted);
  font-size: 11px;
  font-weight: 600;
}

.firm-chip {
  font-size: 10px;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 999px;
  border: 1px solid transparent;
  white-space: nowrap;
}

label {
  display: grid;
  gap: 4px;
  color: var(--muted);
  font-size: 11px;
}

input,
select,
textarea {
  height: 30px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fff;
  color: var(--ink);
  padding: 0 8px;
  font-size: 12px;
  width: 100%;
}

textarea {
  height: auto;
  min-height: 180px;
  padding: 9px;
  resize: vertical;
  font-family: Consolas, "Courier New", monospace;
  line-height: 1.45;
}

input:focus,
select:focus {
  outline: none;
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.12);
}

.check {
  grid-template-columns: auto 1fr;
  align-items: center;
  min-height: 30px;
  color: var(--ink);
  font-size: 12px;
}

.inline-check {
  min-height: 30px;
  align-content: end;
}

.check input {
  width: 14px;
  height: 14px;
}

.jobs-scroll,
.logs-scroll {
  flex: 1;
  min-height: 0;
  overflow: auto;
  overscroll-behavior: contain;
}

.jobs-scroll {
  padding: 8px;
  display: grid;
  gap: 6px;
  align-content: start;
}

.jobs-scroll.empty,
.logs-scroll.empty {
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  font-size: 13px;
  background: #fff;
}

.job-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px 10px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fcfdff;
  border-left-width: 3px;
  border-left-style: solid;
  transition: background 0.12s, border-color 0.12s;
}

.job-row:hover {
  background: #f7f9fc;
}

.job-main {
  min-width: 0;
}

.job-top {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.job-name {
  font-size: 13px;
  font-weight: 700;
  color: var(--ink);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 100%;
}

.job-code {
  font-size: 11px;
  color: var(--muted);
}

.job-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 10px;
  margin-top: 4px;
  font-size: 11px;
  color: var(--muted);
}

.job-meta b {
  color: #475467;
  font-weight: 600;
}

.job-side {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 6px;
}

.job-status {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.row-actions {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.row-actions button {
  height: 28px;
  padding: 0 8px;
  font-size: 11px;
}

.pill {
  display: inline-block;
  padding: 2px 7px;
  border-radius: 999px;
  font-size: 10px;
  font-weight: 700;
}

.pill.success {
  background: #eafaf0;
  color: var(--ok);
}

.pill.muted {
  background: #eef1f6;
  color: var(--muted);
}

.pill.danger {
  background: #fdeef0;
  color: var(--crit);
}

.pill.running {
  background: #e8f1ff;
  color: #1551f4;
}

.logs-scroll {
  background: #0f172a;
  font-family: Consolas, "Courier New", monospace;
  font-size: 12px;
  line-height: 1.45;
  color: #cbd5e1;
  padding: 6px 8px;
}

.logs-scroll.nowrap .log-line {
  white-space: nowrap;
}

.log-line {
  padding: 3px 6px;
  border-radius: 4px;
  overflow-wrap: anywhere;
  border-left: 3px solid transparent;
  display: flex;
  align-items: flex-start;
  gap: 8px;
  user-select: text;
}

.log-content {
  flex: 1;
  min-width: 0;
}

.log-copy {
  flex: 0 0 auto;
  padding: 2px 7px;
  border-color: rgba(148, 163, 184, 0.35);
  background: rgba(15, 23, 42, 0.72);
  color: #cbd5e1;
  font-family: inherit;
  font-size: 10px;
  user-select: none;
}

.log-copy:hover {
  background: rgba(51, 65, 85, 0.9);
}

.log-product-link {
  display: inline-block;
  margin-left: 6px;
  color: #7dd3fc;
  font-weight: 700;
  text-decoration: underline;
  text-underline-offset: 2px;
}

.log-product-link:hover {
  color: #bae6fd;
}

.log-line:hover {
  background: rgba(148, 163, 184, 0.12);
}

.log-time {
  color: #64748b;
}

.log-line strong {
  color: #94a3b8;
  text-transform: uppercase;
  margin: 0 6px;
  font-size: 11px;
}

.log-line.error {
  color: #fecaca;
}

.log-line.error strong {
  color: #f87171;
}

.log-line.warn {
  color: #fde68a;
}

.log-line.warn strong {
  color: #fbbf24;
}

.log-firm {
  display: inline-block;
  padding: 1px 6px;
  border-radius: 999px;
  font-size: 10px;
  font-weight: 700;
  margin-right: 6px;
}

.hidden {
  display: none !important;
}

.field-hint {
  color: var(--muted);
  font-size: 11px;
  line-height: 1.3;
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  padding: 16px;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(15, 23, 42, 0.45);
  backdrop-filter: blur(2px);
}

.modal-card {
  position: relative;
  width: min(720px, 100%);
  max-height: min(90vh, 900px);
  overflow: auto;
  background: #fff;
  border-radius: 14px;
  border: 1px solid var(--line);
  box-shadow: 0 20px 50px rgba(15, 23, 42, 0.2);
  padding: 16px 18px 18px;
}

.data-modal-card {
  width: min(720px, 100%);
}

.data-actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 14px;
}

.advanced-import-toggle {
  display: flex;
  align-items: center;
  gap: 10px;
  padding-top: 12px;
  border-top: 1px solid var(--line);
}

.advanced-import-toggle small {
  color: var(--muted);
  line-height: 1.4;
}

.advanced-import {
  display: grid;
  gap: 10px;
  margin-top: 14px;
  padding: 12px;
  border: 1px dashed var(--line);
  border-radius: 9px;
  background: #fafbfc;
}

.data-action-result {
  max-height: 180px;
  overflow: auto;
  margin: 14px 0 0;
  padding: 10px;
  border-radius: 8px;
  background: #0f172a;
  color: #dbeafe;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  font: 12px/1.45 Consolas, "Courier New", monospace;
}

.data-action-result.error {
  background: #450a0a;
  color: #fecaca;
}

.modal-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.modal-head p {
  margin-top: 4px;
  font-size: 12px;
  color: var(--muted);
}

.job-form {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  align-items: end;
}

.modal-actions {
  grid-column: 1 / -1;
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 4px;
}

body.modal-open {
  overflow: hidden;
}

@media (max-width: 1100px) {
  .topbar {
    grid-template-columns: 1fr;
  }

  .actions {
    justify-content: flex-start;
  }

  .status-strip {
    order: 3;
  }
}

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

  .app {
    height: auto;
    min-height: 100vh;
    min-height: 100dvh;
  }

  .workspace {
    grid-template-columns: 1fr;
    min-height: auto;
  }

  .pane {
    min-height: 55vh;
  }

  .jobs-scroll,
  .logs-scroll {
    max-height: 60vh;
  }

  .log-filters {
    grid-template-columns: 1fr 1fr;
  }

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

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

  .job-side {
    align-items: flex-start;
  }

  .row-actions,
  .job-status {
    justify-content: flex-start;
  }
}

@media (max-width: 560px) {
  .app {
    padding: 8px;
  }

  .log-filters {
    grid-template-columns: 1fr;
  }

  .jobs-pane .pane-filters {
    grid-template-columns: 1fr;
  }

  .data-actions {
    grid-template-columns: 1fr;
  }

  .advanced-import-toggle {
    align-items: stretch;
    flex-direction: column;
  }

  .status-chip.wide {
    display: none;
  }
}
