:root {
  --bg: #0d0d0d;
  --panel: #161616;
  --panel-raised: #1e1e1e;
  --border: #2c2c2c;
  --text: #e8e8e6;
  --text-dim: #8a8a86;
  --text-faint: #55554f;
  --live: #e8e8e6;
  --error: #e8e8e6;
  --mono: 'IBM Plex Mono', 'SFMono-Regular', Consolas, monospace;
  --sans: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  --radius: 3px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 14px;
  line-height: 1.5;
}

.hidden { display: none !important; }

/* ---------- login ---------- */

.login-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
}

.login-card {
  width: 280px;
  padding: 32px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--panel);
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.login-mark {
  font-family: var(--mono);
  font-size: 12px;
  letter-spacing: 0.15em;
  color: var(--text-dim);
}

.login-card h1 {
  margin: 0 0 8px;
  font-size: 20px;
  font-weight: 600;
}

.login-card input {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  padding: 10px 12px;
  font-size: 14px;
}

.login-error { color: var(--text-dim); font-size: 12px; margin: 0; }

/* ---------- topbar ---------- */

.topbar {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 14px 24px;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  background: var(--bg);
  z-index: 10;
}

.brand { display: flex; align-items: center; gap: 8px; }
.brand-mark {
  font-family: var(--mono);
  font-size: 11px;
  border: 1px solid var(--text-dim);
  padding: 2px 6px;
  border-radius: var(--radius);
  color: var(--text-dim);
}
.brand-name { font-weight: 600; letter-spacing: -0.01em; }

.version-badge {
  font-family: var(--mono);
  font-size: 10px;
  color: var(--text-faint);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1px 5px;
}

/* ---------- footer ---------- */

.app-footer {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 14px 12px 20px;
  font-family: var(--mono);
  font-size: 11px;
  color: var(--text-faint);
}
.app-footer a {
  color: var(--text-faint);
  text-decoration: underline;
}
.app-footer a:hover { color: var(--text); }
.footer-sep { opacity: 0.5; }

.license-badge {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1px 6px;
}
.license-badge a {
  color: inherit;
  text-decoration: none;
}
.license-badge a:hover { text-decoration: underline; }
.license-badge--active {
  color: var(--text);
  border-color: var(--text-faint);
}

.topbar-status {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 6px;
  font-family: var(--mono);
  font-size: 11px;
  color: var(--text-faint);
}

.ws-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--text-faint);
  display: inline-block;
}
.ws-dot.connected { background: var(--text); }

.btn-primary {
  background: var(--text);
  color: var(--bg);
  border: none;
  border-radius: var(--radius);
  padding: 8px 14px;
  font-weight: 600;
  font-size: 13px;
  cursor: pointer;
}
.btn-primary:hover { opacity: 0.85; }

.btn-ghost {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-dim);
  border-radius: var(--radius);
  padding: 7px 12px;
  font-size: 13px;
  cursor: pointer;
}
.btn-ghost:hover { border-color: var(--text-dim); color: var(--text); }

/* ---------- library ---------- */

.library { max-width: 920px; margin: 0 auto; padding: 24px; }

/* ---------- overview ---------- */

.overview-panel {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--panel);
  margin-bottom: 16px;
  overflow: hidden;
}

.overview-header {
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.1em;
  color: var(--text-faint);
  padding: 8px 14px;
  border-bottom: 1px solid var(--border);
}

.overview-stats {
  display: flex;
  flex-wrap: wrap;
}

.overview-stat {
  flex: 1;
  min-width: 80px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 14px 8px;
  border-right: 1px solid var(--border);
}
.overview-stat:last-child { border-right: none; }

.overview-value {
  font-family: var(--mono);
  font-size: 20px;
  font-weight: 600;
}

.overview-label {
  font-family: var(--mono);
  font-size: 10px;
  color: var(--text-faint);
  letter-spacing: 0.05em;
}

.library-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
  gap: 12px;
}

.select-all-page-label {
  display: flex;
  align-items: center;
}

.select-all-library-row {
  margin-bottom: 12px;
  font-family: var(--mono);
  font-size: 11px;
}
.select-all-library-row a {
  color: var(--text-faint);
  text-decoration: none;
  border-bottom: 1px dashed var(--text-faint);
}
.select-all-library-row a:hover { color: var(--text-dim); border-color: var(--text-dim); }

.bulk-toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--panel-raised);
  margin-bottom: 12px;
  font-family: var(--mono);
  font-size: 12px;
}
.bulk-spacer { flex: 1; }
.bulk-progress { color: var(--text-faint); font-size: 11px; }

.entry-select {
  flex-shrink: 0;
}

#search-box {
  flex: 1;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  padding: 9px 12px;
  font-size: 13px;
}

.pager {
  display: flex;
  align-items: center;
  gap: 10px;
  font-family: var(--mono);
  font-size: 12px;
  color: var(--text-dim);
}

.library-list { display: flex; flex-direction: column; gap: 8px; }

.entry {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--panel);
  overflow: hidden;
}

.entry-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  cursor: pointer;
}

.entry-row:hover { background: var(--panel-raised); }

.entry-url {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 13px;
}

.entry-id {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--text-faint);
}

.badges { display: flex; gap: 6px; font-family: var(--mono); font-size: 11px; }

.badge {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 2px 6px;
  color: var(--text-dim);
}
.badge.live { color: var(--text); border-color: var(--text-dim); }
.badge.error { color: var(--text); border-color: var(--text); border-style: dashed; }
.badge.pending { color: var(--text-faint); }
.badge.failed { color: var(--text); background: var(--text-faint); }

.chevron {
  color: var(--text-faint);
  font-family: var(--mono);
  transition: transform 0.15s ease;
}
.entry.open .chevron { transform: rotate(90deg); }

.entry-detail {
  display: none;
  border-top: 1px solid var(--border);
  padding: 14px;
}
.entry.open .entry-detail { display: block; }

.provider-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
}
.provider-row:last-child { border-bottom: none; }

.provider-name { width: 110px; font-weight: 600; }
.provider-link { flex: 1; color: var(--text-dim); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-family: var(--mono); font-size: 12px; }
.provider-link a { color: inherit; }
.provider-status { font-family: var(--mono); font-size: 11px; width: 90px; }

.row-actions { display: flex; gap: 6px; }
.row-actions button {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-dim);
  border-radius: var(--radius);
  padding: 4px 8px;
  font-size: 11px;
  cursor: pointer;
  font-family: var(--mono);
}
.row-actions button:hover { color: var(--text); border-color: var(--text-dim); }
.row-actions button.danger { border-style: dashed; }
.row-actions button.danger:hover { border-color: var(--text); }

.detail-footer { display: flex; justify-content: flex-end; gap: 6px; margin-top: 10px; }
.detail-footer .btn-ghost.danger { border-style: dashed; }
.detail-footer .btn-ghost.danger:hover { border-color: var(--text); }

.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-faint);
  font-family: var(--mono);
  font-size: 13px;
}

/* ---------- log panel ---------- */

.log-panel {
  margin-top: 28px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: #0a0a0a;
  overflow: hidden;
}

.log-header {
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.1em;
  color: var(--text-faint);
  padding: 8px 14px;
  border-bottom: 1px solid var(--border);
}

.log-body {
  height: 220px;
  overflow-y: auto;
  padding: 10px 14px;
  font-family: var(--mono);
  font-size: 12px;
  line-height: 1.7;
  color: var(--text-dim);
}

.log-line { white-space: pre-wrap; word-break: break-all; }
.log-line .log-time { color: var(--text-faint); }
.log-line.log-alert { color: var(--text); }

/* ---------- modal ---------- */

.modal {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}

.modal-card {
  width: 380px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.modal-card h2 { margin: 0 0 6px; font-size: 16px; }
.modal-card label { font-size: 12px; color: var(--text-dim); margin-top: 6px; }
.modal-card input[type="url"] {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  padding: 9px 12px;
  font-size: 13px;
}

.provider-checkboxes {
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 180px;
  overflow-y: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 8px 10px;
}
.provider-checkboxes label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--text);
  margin: 0;
}
.provider-checkboxes .select-all-row {
  padding-bottom: 6px;
  margin-bottom: 4px;
  border-bottom: 1px solid var(--border);
  font-weight: 600;
}

.input-hint {
  font-size: 11px;
  color: var(--text-faint);
  margin: 2px 0 0;
}

.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 10px; }
.upload-result { font-family: var(--mono); font-size: 11px; color: var(--text-dim); white-space: pre-wrap; }

/* ---------- mobile ----------
   Keep everything in the same horizontal rows as desktop - just tighten
   padding/gaps/font-sizes so each row actually fits the narrower width,
   and truncate (ellipsis) instead of wrapping. Wrapping to new lines is
   what makes the page balloon vertically for no reason. */

@media (max-width: 640px) {
  .library { padding: 12px; }

  .topbar { padding: 10px 12px; gap: 8px; }
  .brand-name { font-size: 14px; }
  .topbar-status { font-size: 10px; gap: 4px; }
  .version-badge { display: none; } /* first thing to drop when space is tight */
  .btn-primary { padding: 7px 10px; font-size: 12px; white-space: nowrap; }

  /* overview: same 5-across strip, just denser */
  .overview-stat { padding: 10px 2px; }
  .overview-value { font-size: 16px; }
  .overview-label { font-size: 8px; letter-spacing: 0.02em; }

  /* toolbar: stays one row - search shrinks instead of the row wrapping */
  .library-toolbar { gap: 8px; }
  #search-box { min-width: 0; padding: 8px 8px; font-size: 12px; }
  .pager { gap: 6px; font-size: 11px; }
  .pager .btn-ghost { padding: 6px 8px; }
  #page-label { white-space: nowrap; }

  .bulk-toolbar { gap: 6px; padding: 8px; font-size: 11px; flex-wrap: wrap; }
  .bulk-toolbar .btn-ghost { padding: 5px 8px; font-size: 11px; }

  /* entry rows: same single-line layout, ellipsis still does the work */
  .entry-row { gap: 8px; padding: 10px 12px; }
  .entry-id { display: none; } /* redundant with the detail view; frees width for the URL */
  .badges { gap: 4px; }
  .badge { padding: 2px 5px; }

  /* provider rows: shrink the fixed-width columns instead of stacking them */
  .provider-row { gap: 6px; font-size: 12px; }
  .provider-name { width: 72px; font-size: 12px; }
  .provider-link { font-size: 11px; }
  .provider-status { width: 64px; font-size: 10px; }
  .row-actions button { padding: 4px 6px; font-size: 10px; }

  /* modal: use most of the viewport width instead of a fixed 380px card */
  .modal { padding: 16px; }
  .modal-card { width: 100%; max-width: 380px; padding: 18px; }
}
