/* ========================================================================
   Link Audit — editorial workshop aesthetic
   Warm paper, deep ink, restrained color, deliberate typography
   ======================================================================== */

:root {
  /* Paper & ink */
  --paper:      #f5f1ea;
  --paper-2:    #ebe6dc;
  --paper-3:    #e0d9cc;
  --ink:        #1a1816;
  --ink-2:      #3d3933;
  --ink-3:      #6b6359;
  --ink-4:      #a39c8f;

  /* Accent: Cursor brand purple, used sparingly */
  --accent:     #443fde;
  --accent-2:   #5c58e8;
  --accent-3:   #ecebfc;

  /* Status signal */
  --good:       #1f7a4d;
  --good-soft:  #d8eadf;
  --amber:      #a86d20;
  --amber-soft: #f2e2c8;
  --bad:        #a13e25;
  --bad-soft:   #f0d9cf;

  /* Rule weights */
  --rule:       1px solid #d6cebd;
  --rule-soft:  1px solid #e3dccd;
  --rule-bold:  2px solid var(--ink);

  /* Type */
  --font-display: 'Fraunces', 'Times New Roman', serif;
  --font-sans:    'IBM Plex Sans', system-ui, sans-serif;
  --font-mono:    'IBM Plex Mono', 'Menlo', monospace;

  --container: 1280px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font-sans);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

.hidden { display: none !important; }

.container {
  max-width: var(--container);
  margin: 0 auto;
  padding: 0 32px;
}

/* ----- Masthead ----- */

.masthead {
  border-bottom: var(--rule-bold);
  background: var(--paper);
  position: sticky;
  top: 0;
  z-index: 10;
}
.masthead-inner {
  max-width: var(--container);
  margin: 0 auto;
  padding: 20px 32px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
}
.brand {
  display: flex;
  align-items: center;
  gap: 16px;
}
.brand-mark {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 22px;
  letter-spacing: -0.02em;
  background: var(--ink);
  color: var(--paper);
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  border-radius: 2px;
}
.brand-text h1 {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 22px;
  letter-spacing: -0.02em;
  margin: 0;
  line-height: 1;
}
.brand-meta {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--ink-3);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-top: 4px;
}
.masthead-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}

/* ----- Buttons ----- */

.btn {
  font-family: var(--font-sans);
  font-size: 13px;
  font-weight: 500;
  letter-spacing: 0.01em;
  padding: 10px 18px;
  border: 1px solid transparent;
  border-radius: 2px;
  cursor: pointer;
  transition: all 120ms ease;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: none;
  color: inherit;
  white-space: nowrap;
}
.btn:disabled { opacity: 0.4; cursor: not-allowed; }
.btn-sm { padding: 6px 12px; font-size: 12px; }

.btn-primary {
  background: var(--ink);
  color: var(--paper);
  border-color: var(--ink);
}
.btn-primary:hover:not(:disabled) { background: var(--accent); border-color: var(--accent); }

.btn-ghost {
  background: transparent;
  border-color: var(--ink-4);
  color: var(--ink);
}
.btn-ghost:hover { background: var(--paper-2); border-color: var(--ink-3); }

.btn-danger {
  background: transparent;
  border-color: var(--bad);
  color: var(--bad);
}
.btn-danger:hover { background: var(--bad-soft); }

.btn .btn-spinner {
  display: none;
  width: 12px; height: 12px;
  border: 2px solid currentColor;
  border-top-color: transparent;
  border-radius: 50%;
  animation: spin 600ms linear infinite;
}
.btn.loading .btn-spinner { display: inline-block; }
.btn.loading .btn-label { opacity: 0.6; }
@keyframes spin { to { transform: rotate(360deg); } }

.link-btn {
  background: none;
  border: none;
  color: var(--accent);
  font-family: var(--font-sans);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  padding: 0;
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 3px;
}
.link-btn:hover { color: var(--accent-2); }

/* ----- Empty state ----- */

.empty-state {
  min-height: 60vh;
  display: grid;
  place-items: center;
}
.empty-state-inner {
  text-align: center;
  max-width: 460px;
  padding: 48px 32px;
}
.empty-mark {
  font-family: var(--font-display);
  font-size: 120px;
  line-height: 0.6;
  color: var(--ink-4);
  margin-bottom: 16px;
}
.empty-state h2 {
  font-family: var(--font-display);
  font-weight: 500;
  font-size: 32px;
  letter-spacing: -0.02em;
  margin: 0 0 12px;
}
.empty-state p {
  color: var(--ink-3);
  margin: 0 0 24px;
  font-size: 14px;
  line-height: 1.6;
}

/* ----- Dashboard ----- */

.dashboard {
  padding: 40px 0 24px;
  border-bottom: var(--rule);
}
.run-meta {
  font-family: var(--font-mono);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--ink-3);
  margin-bottom: 20px;
  display: flex;
  align-items: center;
  gap: 12px;
}
.run-meta::before {
  content: "";
  width: 6px;
  height: 6px;
  background: var(--accent);
  border-radius: 50%;
  display: inline-block;
}

.headline-stats {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0;
  border-top: var(--rule);
  border-bottom: var(--rule);
  margin-bottom: 32px;
}
.headline-stat {
  padding: 24px 28px;
  border-right: var(--rule-soft);
}
.headline-stat:last-child { border-right: none; }
.headline-stat .stat-label {
  font-family: var(--font-mono);
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--ink-3);
  margin-bottom: 8px;
}
.headline-stat .stat-value {
  font-family: var(--font-display);
  font-weight: 500;
  font-size: 42px;
  line-height: 1;
  letter-spacing: -0.03em;
  color: var(--ink);
}
.headline-stat .stat-delta {
  font-family: var(--font-mono);
  font-size: 11px;
  margin-top: 8px;
  font-weight: 500;
}
.stat-delta.up   { color: var(--good); }
.stat-delta.down { color: var(--bad); }
.stat-delta.flat { color: var(--ink-4); }

.dashboard-grid {
  display: grid;
  grid-template-columns: 1.5fr 1fr;
  gap: 32px;
  margin-bottom: 32px;
}
@media (max-width: 900px) {
  .dashboard-grid, .headline-stats { grid-template-columns: 1fr 1fr; }
}

.panel {
  background: var(--paper);
  border: var(--rule);
  border-radius: 2px;
  overflow: hidden;
}
.panel-header {
  padding: 16px 20px;
  border-bottom: var(--rule-soft);
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
}
.panel-header h3 {
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--ink-2);
  margin: 0;
}
.panel-sub {
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--ink-3);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.cluster-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 0;
}
.cluster-card {
  padding: 18px 20px;
  border-right: var(--rule-soft);
  border-bottom: var(--rule-soft);
}
.cluster-card:last-child { border-right: none; }
.cluster-name {
  font-family: var(--font-mono);
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--ink-3);
  margin-bottom: 8px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.cluster-density {
  font-family: var(--font-display);
  font-weight: 500;
  font-size: 30px;
  line-height: 1;
  letter-spacing: -0.03em;
}
.cluster-density.good { color: var(--good); }
.cluster-density.amber { color: var(--amber); }
.cluster-density.bad { color: var(--bad); }
.cluster-density.muted { color: var(--ink-4); }
.cluster-meta {
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--ink-3);
  margin-top: 8px;
}
.empty-cluster-msg {
  padding: 20px;
  color: var(--ink-3);
  font-size: 13px;
}

.trend-chart {
  padding: 20px;
  min-height: 140px;
}
.trend-chart svg { width: 100%; height: 140px; display: block; }
.trend-empty {
  color: var(--ink-3);
  font-size: 12px;
  text-align: center;
  padding: 40px 12px;
  font-family: var(--font-mono);
}

.panel-actions { }
.action-list {
  list-style: none;
  margin: 0;
  padding: 0;
  counter-reset: actions;
}
.action-item {
  padding: 18px 20px 18px 56px;
  border-bottom: var(--rule-soft);
  position: relative;
  counter-increment: actions;
}
.action-item:last-child { border-bottom: none; }
.action-item::before {
  content: counter(actions, decimal-leading-zero);
  position: absolute;
  left: 20px;
  top: 18px;
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--ink-4);
  font-weight: 600;
}
.action-title {
  font-weight: 500;
  font-size: 14px;
  color: var(--ink);
  margin-bottom: 4px;
  line-height: 1.4;
}
.action-detail {
  font-size: 12px;
  color: var(--ink-3);
  font-family: var(--font-mono);
}
.action-detail .action-tag {
  background: var(--paper-3);
  padding: 1px 6px;
  border-radius: 2px;
  margin-right: 6px;
}

/* ----- Posts section ----- */

.posts-section {
  padding: 48px 0 96px;
}
.section-header {
  margin-bottom: 24px;
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
}
.section-header h2 {
  font-family: var(--font-display);
  font-weight: 500;
  font-size: 32px;
  letter-spacing: -0.02em;
  margin: 0;
}
.section-sub {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--ink-3);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.controls {
  display: flex;
  gap: 16px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}
.search-wrap {
  flex: 1;
  min-width: 240px;
  position: relative;
}
.search-icon {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--ink-3);
  pointer-events: none;
}
#search {
  width: 100%;
  padding: 10px 14px 10px 38px;
  border: 1px solid var(--ink-4);
  border-radius: 2px;
  background: var(--paper);
  font-family: var(--font-sans);
  font-size: 13px;
  color: var(--ink);
}
#search:focus {
  outline: none;
  border-color: var(--ink);
}
.filter-group {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}
.filter-btn {
  background: var(--paper);
  border: 1px solid var(--ink-4);
  padding: 8px 14px;
  border-radius: 2px;
  font-family: var(--font-sans);
  font-size: 12px;
  font-weight: 500;
  color: var(--ink-2);
  cursor: pointer;
  transition: all 120ms ease;
}
.filter-btn:hover { border-color: var(--ink); }
.filter-btn.active {
  background: var(--ink);
  color: var(--paper);
  border-color: var(--ink);
}

/* ----- Table ----- */

.table-wrap {
  border: var(--rule);
  background: var(--paper);
  border-radius: 2px;
  overflow: hidden;
}
.audit-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
.audit-table th {
  text-align: left;
  background: var(--paper-2);
  padding: 12px 16px;
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--ink-2);
  border-bottom: var(--rule);
  cursor: pointer;
  user-select: none;
  position: sticky;
  top: 0;
  white-space: nowrap;
}
.audit-table th:hover { color: var(--accent); }
.audit-table th.num { text-align: right; }
.audit-table td {
  padding: 12px 16px;
  border-bottom: var(--rule-soft);
  vertical-align: top;
}
.audit-table tr.row { cursor: pointer; transition: background 80ms ease; }
.audit-table tr.row:hover { background: var(--paper-2); }
.audit-table .num { text-align: right; font-variant-numeric: tabular-nums; }
.cell-title { font-weight: 500; max-width: 480px; }
.cell-url {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--ink-3);
  max-width: 380px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 2px;
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.04em;
}
.badge.orphan { background: var(--bad-soft); color: var(--bad); text-transform: uppercase; font-size: 10px; }
.badge.low { background: var(--paper-3); color: var(--ink-2); }
.badge.good { background: var(--good-soft); color: var(--good); }

.row-delta {
  font-family: var(--font-mono);
  font-size: 10px;
  margin-left: 6px;
  font-weight: 500;
}
.row-delta.up   { color: var(--good); }
.row-delta.down { color: var(--bad); }

.detail-row td {
  background: var(--paper-2);
  padding: 20px 32px;
}
.detail-section { margin-bottom: 18px; }
.detail-section:last-child { margin-bottom: 0; }
.detail-section h4 {
  font-family: var(--font-mono);
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--ink-3);
  margin: 0 0 10px;
  font-weight: 600;
}
.detail-list { list-style: none; padding: 0; margin: 0; }
.detail-list li {
  padding: 6px 0;
  font-size: 13px;
  border-bottom: var(--rule-soft);
}
.detail-list li:last-child { border-bottom: none; }
.detail-list a { color: var(--ink); text-decoration: none; font-weight: 500; }
.detail-list a:hover { color: var(--accent); }
.detail-list .detail-path {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--ink-3);
  margin-left: 8px;
}
.detail-empty {
  font-style: italic;
  color: var(--ink-3);
  font-size: 12px;
}
.detail-open-link {
  display: inline-block;
  margin-top: 8px;
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--accent);
  text-decoration: none;
}
.detail-open-link:hover { text-decoration: underline; }

.empty-table {
  padding: 60px 20px;
  text-align: center;
  color: var(--ink-3);
  font-family: var(--font-mono);
  font-size: 12px;
}

/* ----- Drawer ----- */

.drawer-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(26, 24, 22, 0.4);
  z-index: 20;
  animation: fadeIn 160ms ease;
}
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

.drawer {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: 480px;
  max-width: 92vw;
  background: var(--paper);
  border-left: var(--rule-bold);
  z-index: 21;
  display: flex;
  flex-direction: column;
  animation: slideIn 200ms cubic-bezier(0.2, 0.7, 0.2, 1);
}
@keyframes slideIn { from { transform: translateX(100%); } to { transform: translateX(0); } }

.drawer-header {
  padding: 24px 32px;
  border-bottom: var(--rule);
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.drawer-header h2 {
  font-family: var(--font-display);
  font-weight: 500;
  font-size: 26px;
  letter-spacing: -0.02em;
  margin: 0;
}
.drawer-close {
  background: none;
  border: none;
  font-size: 28px;
  color: var(--ink-3);
  cursor: pointer;
  padding: 0;
  width: 32px;
  height: 32px;
  line-height: 1;
  border-radius: 2px;
}
.drawer-close:hover { background: var(--paper-2); color: var(--ink); }

.drawer-body {
  flex: 1;
  overflow-y: auto;
  padding: 24px 32px;
}

.form-section {
  margin-bottom: 32px;
  padding-bottom: 32px;
  border-bottom: var(--rule-soft);
}
.form-section:last-child { border-bottom: none; padding-bottom: 0; }
.form-section h3 {
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--ink-2);
  margin: 0 0 16px;
}
.form-hint {
  font-size: 12px;
  color: var(--ink-3);
  margin: 0 0 12px;
  line-height: 1.5;
}

.field {
  display: block;
  margin-bottom: 16px;
}
.field-label {
  display: block;
  font-family: var(--font-mono);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--ink-2);
  margin-bottom: 6px;
  font-weight: 500;
}
.field input[type="text"], .field input[type="password"] {
  width: 100%;
  padding: 10px 14px;
  border: 1px solid var(--ink-4);
  border-radius: 2px;
  background: var(--paper);
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--ink);
}
.field input:focus {
  outline: none;
  border-color: var(--ink);
}
.field-hint {
  display: block;
  font-size: 11px;
  color: var(--ink-3);
  margin-top: 6px;
  font-family: var(--font-sans);
}

.source-toggle {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 4px;
}
.source-option {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 14px 16px;
  border: 1px solid var(--ink-4);
  border-radius: 2px;
  cursor: pointer;
  transition: all 120ms ease;
}
.source-option:has(input:checked) {
  border-color: var(--ink);
  background: var(--paper-2);
}
.source-option input { margin-top: 3px; accent-color: var(--accent); }
.source-option-title {
  font-weight: 500;
  font-size: 13px;
  color: var(--ink);
  margin-bottom: 2px;
}
.source-option-sub {
  font-size: 11px;
  color: var(--ink-3);
  line-height: 1.4;
}

.cluster-row {
  display: grid;
  grid-template-columns: 1fr 2fr auto;
  gap: 8px;
  margin-bottom: 8px;
  align-items: center;
}
.cluster-row input {
  padding: 8px 12px;
  border: 1px solid var(--ink-4);
  border-radius: 2px;
  background: var(--paper);
  font-family: var(--font-sans);
  font-size: 12px;
  color: var(--ink);
  min-width: 0;
}
.cluster-row input:focus { outline: none; border-color: var(--ink); }
.cluster-row .keywords { font-family: var(--font-mono); font-size: 11px; }
.cluster-remove {
  background: none;
  border: 1px solid var(--ink-4);
  color: var(--ink-3);
  width: 30px;
  height: 30px;
  border-radius: 2px;
  cursor: pointer;
  font-size: 16px;
  display: grid;
  place-items: center;
}
.cluster-remove:hover { border-color: var(--bad); color: var(--bad); }

.data-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 12px;
}

.drawer-footer {
  padding-top: 24px;
  border-top: var(--rule-soft);
  display: flex;
  justify-content: flex-end;
}

/* ----- Toast ----- */

.toast-container {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 50;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.toast {
  padding: 12px 20px;
  background: var(--ink);
  color: var(--paper);
  border-radius: 2px;
  font-family: var(--font-mono);
  font-size: 12px;
  letter-spacing: 0.02em;
  animation: toastIn 200ms ease;
  max-width: 460px;
  box-shadow: 0 4px 20px rgba(0,0,0,0.15);
}
.toast.error { background: var(--bad); }
.toast.success { background: var(--good); }
@keyframes toastIn {
  from { transform: translateY(20px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

/* ----- Responsive tweaks ----- */
@media (max-width: 700px) {
  .container, .masthead-inner { padding-left: 20px; padding-right: 20px; }
  .headline-stats { grid-template-columns: repeat(2, 1fr); }
  .headline-stat { padding: 18px 20px; }
  .headline-stat .stat-value { font-size: 32px; }
  .empty-state h2 { font-size: 24px; }
  .section-header h2 { font-size: 24px; }
}
