/* ── design tokens ── */
:root {
  --clr-nav: #1a2236;
  --clr-border: #e2e8f0;
  --clr-surface: #f8fafc;
  --clr-accent: #2563eb;
  --clr-accent-bg: #dbeafe;
  --clr-ok: #16a34a;
  --clr-warn: #d97706;
  --clr-danger: #dc2626;
  --clr-muted: #64748b;
}

/* ── base ── */
body {
  background: #f0f2f5;
  font-size: 0.875rem;
  color: #1e293b;
}

/* ── navbar ── */
.app-nav {
  background: var(--clr-nav) !important;
  padding-top: 0.3rem;
  padding-bottom: 0.3rem;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}

.app-brand {
  display: inline-flex;
  align-items: center;
  text-decoration: none;
}

.app-brand-logo {
  display: block;
  width: auto;
  height: 2rem;
  max-width: 13rem;
  object-fit: contain;
  border-radius: 0.2rem;
  background: #fff;
}

.nav-link-btn {
  display: inline-block;
  padding: 0.28rem 0.65rem;
  border-radius: 0.35rem;
  font-size: 0.8rem;
  color: rgba(255, 255, 255, 0.65);
  text-decoration: none;
  transition: background 0.12s, color 0.12s;
}

.nav-link-btn:hover,
.nav-link-btn.active {
  background: rgba(255, 255, 255, 0.13);
  color: #fff;
}

/* ── cards ── */
.card {
  border: 1px solid var(--clr-border);
  border-radius: 0.5rem;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.04);
  background: #fff;
}

.card-hd {
  padding: 0.5rem 0.875rem;
  background: var(--clr-surface);
  border-bottom: 1px solid var(--clr-border);
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--clr-muted);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.card-hd .hd-extra {
  font-weight: 400;
  text-transform: none;
  letter-spacing: 0;
  font-size: 0.72rem;
}

.card-bd {
  padding: 0.75rem 0.875rem;
}

/* ── dense tables ── */
.table-dense th,
.table-dense td {
  padding: 0.25rem 0.6rem;
  font-size: 0.8125rem;
  vertical-align: middle;
}

.table-dense thead th {
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--clr-muted);
  background: var(--clr-surface);
  border-bottom: 1px solid var(--clr-border);
}

/* ── status indicators ── */
.status-dot {
  display: inline-block;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  margin-right: 4px;
  vertical-align: middle;
  flex-shrink: 0;
}

.sd-online  { background: var(--clr-ok); }
.sd-offline { background: #cbd5e1; }
.sd-warn    { background: var(--clr-warn); }

.text-ok   { color: var(--clr-ok) !important; }
.text-warn { color: var(--clr-warn) !important; }

/* ── dashboard metrics ── */
.metric-val {
  font-size: 1.6rem;
  font-weight: 700;
  line-height: 1;
  color: #1e293b;
}

.metric-val-sm {
  font-size: 1.1rem;
  font-weight: 700;
  line-height: 1;
  color: #1e293b;
}

.metric-lbl {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--clr-muted);
  margin-top: 0.2rem;
}

/* ── global worker sleep switch ── */
.sleep-control {
  display: inline-flex;
  align-items: center;
  min-height: 2rem;
  padding: 0.22rem 0.55rem;
  border: 1px solid var(--clr-border);
  border-radius: 0.45rem;
  background: #fff;
}

.sleep-control .form-check-input {
  margin-top: 0;
  cursor: pointer;
}

.sleep-control-label {
  font-size: 0.78rem;
  font-weight: 700;
  color: #334155;
}

.sleep-control-state {
  min-width: 3.6rem;
  padding: 0.08rem 0.35rem;
  border-radius: 0.35rem;
  background: #e2e8f0;
  color: #475569;
  font-size: 0.68rem;
  font-weight: 800;
  text-align: center;
}

.sleep-control-active {
  border-color: #fca5a5;
  background: #fef2f2;
}

.sleep-control-active .sleep-control-state {
  background: var(--clr-danger);
  color: #fff;
}

/* ── worker config ── */
.worker-config-add {
  padding: 0.65rem;
  border: 1px solid var(--clr-border);
  border-radius: 0.45rem;
  background: #f8fafc;
}

.worker-config-list {
  display: grid;
  gap: 0.65rem;
}

.worker-config-row {
  padding-top: 0.65rem;
  border-top: 1px solid var(--clr-border);
}

.worker-config-row-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  margin-bottom: 0.45rem;
}

.worker-config-host {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 0.82rem;
  font-weight: 700;
}

.worker-config-badge {
  flex-shrink: 0;
  padding: 0.1rem 0.42rem;
  border: 1px solid var(--clr-border);
  border-radius: 0.35rem;
  background: #fff;
  color: var(--clr-muted);
  font-size: 0.7rem;
  font-weight: 700;
}

.worker-config-grid {
  display: grid;
  grid-template-columns: minmax(3.75rem, 0.55fr) minmax(4.5rem, 1fr) minmax(4.5rem, 1fr);
  gap: 0.45rem;
  align-items: end;
}

.worker-field {
  min-width: 0;
}

.worker-field-label {
  display: block;
  margin-bottom: 0.16rem;
  color: var(--clr-muted);
  font-size: 0.68rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.worker-field-notes,
.worker-field-host,
.worker-config-actions {
  grid-column: 1 / -1;
}

.worker-config-actions {
  display: flex;
  gap: 0.35rem;
}

.worker-config-actions .btn {
  min-width: 4.5rem;
}

.worker-delete-btn {
  min-width: 2rem !important;
}

.worker-config-empty {
  color: var(--clr-muted);
  font-size: 0.8rem;
}

@media (max-width: 575.98px) {
  .worker-config-grid {
    grid-template-columns: 1fr;
  }
}

/* ── job strip ── */
.job-strip {
  padding: 0.5rem 0.75rem;
  border-radius: 0.4rem;
  background: var(--clr-surface);
  border: 1px solid var(--clr-border);
}

.job-meta {
  font-size: 0.775rem;
  color: var(--clr-muted);
}

.job-config-table-wrap {
  max-height: calc(100vh - 145px);
  overflow: auto;
}

.job-config-table thead th {
  position: sticky;
  top: 0;
  z-index: 2;
}

/* ── patent browser ── */
.patent-browser-shell,
.patent-detail-shell {
  border-radius: 0.5rem;
  overflow: hidden;
}

.patent-toolbar {
  background: var(--clr-surface);
  border-bottom: 1px solid var(--clr-border);
  padding: 0.6rem 0.875rem;
}

.column-toggle {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.18rem 0.5rem;
  border: 1px solid var(--clr-border);
  border-radius: 0.3rem;
  background: #fff;
  font-size: 0.775rem;
  cursor: pointer;
  user-select: none;
  transition: background 0.1s;
}

.column-toggle:hover {
  background: #f1f5f9;
}

.patent-table-wrap {
  max-height: calc(100vh - 225px);
  overflow-y: auto;
}

.patent-table thead th {
  position: sticky;
  top: 0;
  z-index: 2;
  background: var(--clr-surface);
  box-shadow: inset 0 -1px 0 var(--clr-border);
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--clr-muted);
  padding: 0.35rem 0.6rem;
  white-space: nowrap;
}

.patent-table tbody td {
  padding: 0.28rem 0.6rem;
  font-size: 0.8125rem;
}

.patent-table tbody tr {
  cursor: pointer;
}

.patent-table tbody tr:hover {
  background: #f8fafc;
}

.patent-table tbody tr.active {
  background: var(--clr-accent-bg);
}

.patent-cell-title {
  max-width: 42rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.table-sort {
  border: 0;
  padding: 0;
  background: transparent;
  color: inherit;
  font: inherit;
  font-weight: 700;
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.table-sort[data-direction="asc"]::after  { content: " ↑"; }
.table-sort[data-direction="desc"]::after { content: " ↓"; }

.patent-footer {
  background: var(--clr-surface);
  border-top: 1px solid var(--clr-border);
  padding: 0.45rem 0.875rem;
}

.page-pill {
  min-width: 6rem;
  text-align: center;
  padding: 0.22rem 0.7rem;
  border: 1px solid var(--clr-border);
  border-radius: 0.35rem;
  background: #fff;
  font-size: 0.8rem;
}

.patent-jump-input {
  width: 4.5rem;
}

.patent-preview {
  white-space: pre-wrap;
  word-break: break-word;
  background: #0f172a;
  color: #94a3b8;
  padding: 0.75rem;
  border-radius: 0.4rem;
  font-size: 0.775rem;
  line-height: 1.55;
  max-height: calc(100vh - 340px);
  min-height: 180px;
  overflow: auto;
  margin: 0;
}

.detail-count {
  display: inline-block;
  padding: 0.15rem 0.55rem;
  background: var(--clr-surface);
  border: 1px solid var(--clr-border);
  border-radius: 0.35rem;
  font-size: 0.8rem;
  font-weight: 600;
}

/* ── search page ── */
.search-page {
  display: grid;
  gap: 0.85rem;
}

.search-head {
  display: flex;
  justify-content: space-between;
  align-items: end;
  gap: 1rem;
}

.search-question-card {
  overflow: hidden;
}

.search-label {
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--clr-muted);
}

.search-question-input {
  min-height: 7rem;
  resize: vertical;
  font-size: 0.9rem;
  line-height: 1.45;
}

.search-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-top: 0.65rem;
}

.search-state {
  margin-left: auto;
  font-size: 0.78rem;
}

.search-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 24rem;
  gap: 0.85rem;
  align-items: start;
}

.search-side {
  display: grid;
  gap: 0.85rem;
}

.search-answer-card {
  min-height: 30rem;
}

.search-answer,
.advisor-notes {
  white-space: pre-wrap;
  word-break: break-word;
  background: #f8fafc;
  color: #1e293b;
  padding: 0.8rem;
  border: 1px solid var(--clr-border);
  border-radius: 0.4rem;
  font-size: 0.84rem;
  line-height: 1.6;
  overflow: auto;
  margin: 0;
}

.search-answer {
  min-height: 25rem;
  max-height: calc(100vh - 330px);
}

.advisor-notes {
  max-height: 18rem;
  color: #334155;
}

.search-empty {
  color: var(--clr-muted);
  min-height: 25rem;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  border: 1px dashed var(--clr-border);
  border-radius: 0.4rem;
  background: #f8fafc;
}

.search-progress {
  display: grid;
  gap: 0.55rem;
}

.search-step {
  display: grid;
  grid-template-columns: 0.75rem minmax(0, 1fr);
  gap: 0.5rem;
}

.search-step-dot {
  width: 0.55rem;
  height: 0.55rem;
  margin-top: 0.32rem;
  border-radius: 50%;
  background: #cbd5e1;
}

.search-step-running .search-step-dot {
  background: var(--clr-accent);
  box-shadow: 0 0 0 0.22rem rgba(37, 99, 235, 0.12);
}

.search-step-done .search-step-dot {
  background: var(--clr-ok);
}

.search-step-body {
  min-width: 0;
}

.search-step-title {
  font-size: 0.78rem;
  font-weight: 700;
}

.search-step-message,
.search-step-extra {
  font-size: 0.76rem;
  color: var(--clr-muted);
}

.search-step-extra {
  margin-top: 0.25rem;
  padding: 0.35rem 0.45rem;
  border-radius: 0.35rem;
  background: #f8fafc;
  border: 1px solid var(--clr-border);
}

.search-patents-card {
  overflow: hidden;
}

.search-patent-table td {
  vertical-align: top;
}

.search-patent-title {
  max-width: 42rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.search-query-cell {
  max-width: 24rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

@media (max-width: 991.98px) {
  .search-layout {
    grid-template-columns: 1fr;
  }
}

/* ── login ── */
.login-wrap {
  min-height: calc(100vh - 48px);
  display: flex;
  align-items: center;
  justify-content: center;
}
