/* AStockEvent Admin — Unified Stylesheet
   Pico CSS v2 base + custom admin overrides */

:root { --pico-font-size: 93.75%; --sidebar-width: 220px; --sidebar-collapsed: 56px; }

/* ====== Layout ====== */
body { margin: 0; display: flex; min-height: 100vh; }

.sidebar {
  width: var(--sidebar-width); min-width: var(--sidebar-width);
  background: var(--pico-card-background-color);
  border-right: 1px solid var(--pico-muted-border-color);
  display: flex; flex-direction: column;
  position: fixed; top: 0; left: 0; bottom: 0; z-index: 100;
  transition: width 0.25s, min-width 0.25s; overflow-x: hidden; overflow-y: auto;
}
.sidebar.collapsed { width: var(--sidebar-collapsed); min-width: var(--sidebar-collapsed); }
.sidebar-brand {
  padding: 0.75rem 1rem; font-weight: 700; font-size: 1rem;
  display: flex; align-items: center; gap: 0.5rem; white-space: nowrap;
  border-bottom: 1px solid var(--pico-muted-border-color);
}

.sidebar nav { flex: 1; padding: 0.25rem 0; overflow-y: auto; }

.sidebar-group { margin-top: 0.25rem; }
.sidebar-group-header {
  display: flex; align-items: center; gap: 0.4rem;
  padding: 0.5rem 1rem 0.25rem;
  font-size: 0.7rem; font-weight: 700; text-transform: uppercase;
  color: var(--pico-muted-color); letter-spacing: 0.05em;
  white-space: nowrap; cursor: default;
}
.sidebar.collapsed .sidebar-group-header { display: none; }

.sidebar nav a {
  display: flex; align-items: center; gap: 0.6rem;
  padding: 0.45rem 1rem 0.45rem 1.6rem;
  font-size: 0.85rem; text-decoration: none; color: var(--pico-color);
  border-left: 3px solid transparent; white-space: nowrap;
  transition: background 0.15s, border-color 0.15s;
}
.sidebar nav a:hover { background: var(--pico-muted-border-color); }
.sidebar nav a.active {
  border-left-color: var(--pico-primary);
  background: rgba(1,123,220,0.08); font-weight: 600;
}
.sidebar nav a .nav-icon { font-size: 1.1rem; width: 1.3rem; text-align: center; flex-shrink: 0; }

.sidebar-footer {
  padding: 0.5rem 1rem; border-top: 1px solid var(--pico-muted-border-color);
  display: flex; align-items: center; gap: 0.5rem;
}
.sidebar-footer button {
  background: none; border: 1px solid var(--pico-muted-border-color);
  border-radius: 6px; padding: 0.3rem 0.5rem; cursor: pointer; font-size: 1rem; line-height: 1;
}

.sidebar.collapsed .nav-label, .sidebar.collapsed .brand-text,
.sidebar.collapsed .sidebar-footer span { display: none; }
.sidebar.collapsed nav a { justify-content: center; padding: 0.45rem 0; }
.sidebar.collapsed .sidebar-footer { justify-content: center; }

.content {
  margin-left: var(--sidebar-width); flex: 1; padding: 1rem 1.5rem;
  max-width: calc(100vw - var(--sidebar-width));
  transition: margin-left 0.25s, max-width 0.25s;
}
.sidebar.collapsed ~ .content { margin-left: var(--sidebar-collapsed); max-width: calc(100vw - var(--sidebar-collapsed)); }

.top-bar {
  display: none; align-items: center; gap: 0.5rem; padding-bottom: 0.5rem;
  margin-bottom: 0.5rem; border-bottom: 1px solid var(--pico-muted-border-color);
}
.top-bar h1 { font-size: 1rem; margin: 0; flex: 1; }
.sidebar-toggle { background: none; border: none; cursor: pointer; font-size: 1.2rem; padding: 0.2rem; color: var(--pico-muted-color); display: none; }

.section { display: none; }
.section.active { display: block; }

/* ====== Components ====== */
.stat-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 0.75rem; margin-bottom: 1.5rem; }
.stat-card { padding: 1rem; text-align: center; border: 1px solid var(--pico-muted-border-color); border-radius: 8px; background: var(--pico-card-background-color); }
.stat-card .num { font-size: 1.6rem; font-weight: 700; line-height: 1.2; }
.stat-card .label { font-size: 0.75rem; color: var(--pico-muted-color); margin-top: 0.2rem; }

.card { margin-bottom: 1rem; padding: 1rem; border: 1px solid var(--pico-muted-border-color); border-radius: 8px; background: var(--pico-card-background-color); }
.card h3 { margin-bottom: 0.5rem; font-size: 0.95rem; }
.card h3 small { font-weight: 400; color: var(--pico-muted-color); }
.card-section { margin-bottom: 1rem; }
.card-section h3 { margin-bottom: 0.5rem; font-size: 0.95rem; }

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }

table { font-size: 0.82rem; }
th { font-size: 0.75rem; }
td.num { text-align: right; font-variant-numeric: tabular-nums; }

/* Badges */
.badge { font-size: 0.7rem; padding: 0.1rem 0.5rem; border-radius: 3px; white-space: nowrap; font-weight: 600; }
.badge-ok, .badge-online { background: #d5f5e3; color: #1e8449; }
.badge-err, .badge-offline { background: #fadbd8; color: #922b21; }
.badge-warn { background: #fef9e7; color: #927608; }
.badge-impl, .badge-info { background: #eaecee; color: #7f8c8d; }
.badge-blocked { background: #fadbd8; color: #c0392b; }

.status-dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 5px; }
.dot-ok { background: #27ae60; }
.dot-warn { background: #d35400; }
.dot-err { background: #c0392b; }
.dot-gray { background: #bdc3c7; }

.bar-wrap { background: var(--pico-muted-border-color); border-radius: 4px; height: 18px; overflow: hidden; margin: 0.3rem 0; }
.bar-fill { height: 100%; border-radius: 4px; transition: width 0.5s; }

.crawler-row { display: grid; grid-template-columns: 1fr 1fr; gap: 0.75rem; }
.crawler-control { padding: 0.9rem 1rem; border: 1px solid var(--pico-muted-border-color); border-radius: 8px; display: flex; align-items: center; justify-content: space-between; gap: 0.5rem; flex-wrap: wrap; }
.crawler-control .info { font-size: 0.85rem; }
.crawler-control .info .state { font-weight: 600; }
.crawler-control .info .desc { font-size: 0.75rem; color: var(--pico-muted-color); }
.crawler-control .actions { display: flex; gap: 0.3rem; }
.crawler-control .actions button { font-size: 0.75rem; padding: 0.25rem 0.7rem; }
.state-running { color: #27ae60; }
.state-paused { color: #c0392b; }
.state-night { color: #7f8c8d; }

.toast { position: fixed; top: 1rem; right: 1rem; padding: 0.5rem 1rem; border-radius: 6px; color: #fff; font-size: 0.85rem; z-index: 999; opacity: 0; transition: opacity 0.3s; pointer-events: none; }
.toast.show { opacity: 1; }
.toast-ok { background: #27ae60; }
.toast-err { background: #c0392b; }

.modal-overlay { display: none; position: fixed; inset: 0; background: rgba(0,0,0,0.5); z-index: 200; align-items: center; justify-content: center; }
.modal-overlay.show { display: flex; }
.modal-box { background: var(--pico-card-background-color); padding: 2rem; border-radius: 10px; max-width: 340px; width: 90%; text-align: center; }
.modal-box h3 { margin-bottom: 1rem; }
.modal-box form { display: flex; flex-direction: column; gap: 0.5rem; }

.loading { text-align: center; color: var(--pico-muted-color); padding: 2rem; }
.error-msg { text-align: center; padding: 2rem 1rem; color: #c0392b; }
.empty-msg { text-align: center; padding: 2rem; color: var(--pico-muted-color); }
.no-data { text-align: center; padding: 2rem; color: var(--pico-muted-color); border: 1px dashed var(--pico-muted-border-color); border-radius: 8px; }

.source-row-detail { background: var(--pico-card-background-color); }
.source-row-detail td { padding: 0.5rem 1rem; }
.expand-btn { cursor: pointer; background: none; border: none; font-size: 1rem; padding: 0 0.3rem; }

/* Topology */
.topo { display: flex; flex-direction: column; align-items: center; gap: 1.2rem; padding: 1rem 0; font-family: monospace; font-size: 0.85rem; }
.topo-master { border: 2px solid #27ae60; border-radius: 12px; padding: 0.8rem 1.2rem; background: var(--pico-card-background-color); min-width: 240px; text-align: center; }
.topo-master .topo-label { font-size: 0.95rem; font-weight: 700; color: #27ae60; margin-bottom: 0.3rem; }
.topo-master .topo-host { font-size: 0.75rem; color: var(--pico-muted-color); margin-bottom: 0.5rem; }
.topo-svcs { display: flex; flex-wrap: wrap; gap: 0.3rem; justify-content: center; }
.topo-svc { font-size: 0.65rem; padding: 0.15rem 0.4rem; border-radius: 4px; white-space: nowrap; }
.topo-svc-ok { background: #d5f5e3; color: #1e8449; }
.topo-svc-err { background: #fadbd8; color: #c0392b; }
.topo-svc-warn { background: #fef9e7; color: #927608; }
.topo-svc-off { background: #eaecee; color: #7f8c8d; }
.topo-pipe { width: 2px; height: 16px; background: var(--pico-muted-border-color); }
.topo-branch { display: flex; gap: 1.5rem; align-items: flex-start; flex-wrap: wrap; justify-content: center; }
.topo-worker { border: 1.5px solid var(--pico-muted-border-color); border-radius: 10px; padding: 0.5rem 0.9rem; background: var(--pico-card-background-color); min-width: 180px; text-align: center; }
.topo-worker.online { border-color: #27ae60; }
.topo-worker.offline { border-color: #c0392b; opacity: 0.6; }
.topo-worker .topo-label { font-size: 0.85rem; font-weight: 600; margin-bottom: 0.15rem; }
.topo-worker .topo-host { font-size: 0.7rem; color: var(--pico-muted-color); margin-bottom: 0.4rem; }

/* Workers */
.worker-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 0.8rem; margin-bottom: 1.2rem; }
.worker-card { padding: 1rem; border: 1px solid var(--pico-muted-border-color); border-radius: 8px; background: var(--pico-card-background-color); }
.worker-card .wh { display: flex; align-items: center; justify-content: space-between; margin-bottom: 0.5rem; }
.worker-card .wid { font-weight: 600; font-size: 0.85rem; word-break: break-all; }
.worker-card .wstats { display: grid; grid-template-columns: 1fr 1fr; gap: 0.3rem 0.5rem; font-size: 0.8rem; }
.worker-card .wstats .v { font-weight: 600; }
.worker-card .wstats .l { color: var(--pico-muted-color); font-size: 0.7rem; }
.worker-card .werr { font-size: 0.7rem; color: #c0392b; margin-top: 0.5rem; padding: 0.3rem 0.5rem; background: #fdedec; border-radius: 4px; word-break: break-all; }
.worker-card .worker-stats { margin-top: 0.6rem; padding-top: 0.5rem; border-top: 1px solid var(--pico-muted-border-color); }

/* ── Worker download stats bar charts ── */
.stat-charts { display: flex; flex-direction: column; gap: 0.5rem; }
.stat-chart { }
.stat-chart h4 { font-size: 0.7rem; font-weight: 600; color: var(--pico-muted-color); margin: 0 0 0.25rem 0; }
.stat-bars { display: flex; flex-direction: column; gap: 1px; max-height: 160px; overflow-y: auto; }
.stat-bar-row { display: flex; align-items: center; gap: 0.3rem; font-size: 0.65rem; }
.stat-bar-row .bar-label {
  width: 42px; text-align: right; flex-shrink: 0;
  color: var(--pico-muted-color); font-variant-numeric: tabular-nums;
}
.stat-bar-row .bar-track {
  flex: 1; height: 10px; background: var(--pico-muted-border-color);
  border-radius: 3px; overflow: hidden; min-width: 30px;
}
.stat-bar-row .bar-fill {
  height: 100%; background: linear-gradient(90deg, #3498db, #2980b9);
  border-radius: 3px; transition: width 0.3s;
}
.stat-bar-row .bar-val {
  width: 28px; text-align: right; flex-shrink: 0;
  font-weight: 600; color: var(--pico-color); font-variant-numeric: tabular-nums;
}
.master-card { padding: 1rem 1.2rem; border: 1px solid var(--pico-muted-border-color); border-radius: 10px; margin-bottom: 1.2rem; display: flex; align-items: center; gap: 1.5rem; flex-wrap: wrap; }
.master-card .title { font-weight: 600; font-size: 0.95rem; }

/* Reviews */
.filter-bar { display: flex; flex-wrap: wrap; gap: 0.3rem; margin-bottom: 0.8rem; align-items: center; }
.filter-bar > span { font-size: 0.75rem; color: var(--pico-muted-color); }
.filter-bar button { font-size: 0.75rem; padding: 0.2rem 0.6rem; }
.filter-bar .filter-active { background: var(--pico-primary); color: #fff; }

.conflict-card { margin-bottom: 0.8rem; padding: 1rem; border: 1px solid var(--pico-muted-border-color); border-radius: 8px; }
.conflict-card.resolved { opacity: 0.4; pointer-events: none; }
.conflict-header { display: flex; flex-wrap: wrap; align-items: center; gap: 0.4rem; margin-bottom: 0.8rem; }
.conflict-header .stock-info { font-weight: bold; margin-right: 0.5rem; }

.comparison { display: grid; grid-template-columns: 1fr auto 1fr; gap: 0.5rem; align-items: start; margin-bottom: 0.8rem; }
.comparison .side { padding: 0.5rem; border-radius: 6px; }
.comparison .regex-side { background: #fef9e7; }
.comparison .llm-side { background: #eaf2f8; }
.comparison .side-label { font-size: 0.7rem; color: var(--pico-muted-color); margin-bottom: 0.2rem; }
.comparison .side-value { font-family: monospace; word-break: break-all; }
.comparison .vs { font-size: 0.8rem; font-weight: bold; color: var(--pico-muted-color); align-self: center; }

.review-actions { display: flex; flex-wrap: wrap; gap: 0.4rem; margin-top: 0.8rem; align-items: center; }
.review-actions button { font-size: 0.75rem; padding: 0.3rem 0.8rem; }

.source-text-box { background: var(--pico-card-background-color); border: 1px solid var(--pico-muted-border-color); border-radius: 6px; padding: 0.6rem; font-size: 0.8rem; max-height: 150px; overflow-y: auto; white-space: pre-wrap; word-break: break-all; line-height: 1.5; }
.source-text-box mark { background: #f9e79f; padding: 0.1rem 0.2rem; border-radius: 2px; }

/* DB Browser */
.db-browse-controls { display: flex; flex-wrap: wrap; gap: 0.5rem; align-items: flex-end; margin-bottom: 1rem; }
.db-browse-controls label { font-size: 0.8rem; display: flex; flex-direction: column; gap: 0.2rem; }
.db-browse-controls select, .db-browse-controls input { font-size: 0.8rem; padding: 0.3rem 0.5rem; }
.db-browse-table { overflow-x: auto; max-height: 60vh; overflow-y: auto; }
.db-browse-table table { font-size: 0.78rem; white-space: nowrap; }

/* API Keys */
.key-value { font-family: 'SF Mono', 'Fira Code', 'Consolas', monospace; background: #fef9e7; padding: 0.5rem 0.8rem; border-radius: 6px; border: 2px dashed #d35400; font-size: 0.9rem; word-break: break-all; user-select: all; margin: 0.5rem 0; }

/* System banner */
.sys-banner { padding: 0.8rem 1rem; border-radius: 8px; margin-bottom: 1.2rem; font-weight: 600; font-size: 0.9rem; }
.sys-banner.green { background: #d5f5e3; border-left: 4px solid #27ae60; color: #1e8449; }
.sys-banner.yellow { background: #fef9e7; border-left: 4px solid #d35400; color: #927608; }
.sys-banner.red { background: #fadbd8; border-left: 4px solid #c0392b; color: #922b21; }

/* Nav badge */
.nav-badge { font-size: 0.6rem; padding: 0.1rem 0.35rem; border-radius: 8px; margin-left: auto; font-weight: 600; }

/* Forms */
.form-inline { display: flex; flex-wrap: wrap; gap: 0.5rem; align-items: flex-end; margin-bottom: 1rem; }
.form-inline label { font-size: 0.8rem; display: flex; flex-direction: column; gap: 0.2rem; }

footer { text-align: center; padding: 2rem 0; font-size: 0.75rem; color: var(--pico-muted-color); }

/* ====== Responsive ====== */
@media (max-width: 768px) {
  .sidebar { width: var(--sidebar-collapsed); min-width: var(--sidebar-collapsed); }
  .sidebar .nav-label, .sidebar .brand-text, .sidebar-footer span { display: none; }
  .sidebar .sidebar-group-header { display: none; }
  .sidebar nav a { justify-content: center; padding: 0.45rem 0; }
  .sidebar-footer { justify-content: center; }
  .sidebar.open { width: var(--sidebar-width); min-width: var(--sidebar-width); }
  .sidebar.open .nav-label, .sidebar.open .brand-text, .sidebar.open .sidebar-footer span { display: inline; }
  .sidebar.open .sidebar-group-header { display: flex; }
  .sidebar.open nav a { justify-content: flex-start; padding: 0.45rem 1rem 0.45rem 1.6rem; }
  .sidebar.open .sidebar-footer { justify-content: flex-start; }
  .content { margin-left: var(--sidebar-collapsed); max-width: calc(100vw - var(--sidebar-collapsed)); }
  .sidebar.open ~ .content { margin-left: var(--sidebar-width); }
  .top-bar { display: flex; }
  .sidebar-toggle { display: block; }
  .crawler-row { grid-template-columns: 1fr; }
  .grid-2 { grid-template-columns: 1fr; }
  .comparison { grid-template-columns: 1fr; }
  .comparison .vs { display: none; }
}
