/* ===== Variables ===== */
:root {
  --sidebar-bg: #1e293b;
  --sidebar-text: #94a3b8;
  --sidebar-text-active: #f1f5f9;
  --sidebar-active-bg: #3b82f6;
  --sidebar-hover-bg: #334155;
  --sidebar-width: 220px;

  --bg: #f8fafc;
  --surface: #ffffff;
  --border: #e2e8f0;
  --text: #1e293b;
  --text-muted: #64748b;

  --primary: #3b82f6;
  --primary-hover: #2563eb;
  --success: #22c55e;
  --danger: #ef4444;
  --danger-hover: #dc2626;
  --warning: #f59e0b;

  --radius: 6px;
  --shadow: 0 1px 3px rgba(0,0,0,.1);
}

/* ===== Reset ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
body { font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif; font-size: 14px; color: var(--text); background: var(--bg); }
a { color: inherit; text-decoration: none; }
input, select, button, textarea { font: inherit; }

/* ===== Layout ===== */
.app-layout {
  display: flex;
  min-height: 100vh;
}

/* ===== Sidebar ===== */
.sidebar {
  width: var(--sidebar-width);
  background: var(--sidebar-bg);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  position: fixed;
  top: 0; left: 0; bottom: 0;
}

.sidebar-header {
  padding: 20px 16px 16px;
  border-bottom: 1px solid #334155;
}

.sidebar-logo {
  font-size: 16px;
  font-weight: 700;
  color: #f1f5f9;
  letter-spacing: .3px;
}

.sidebar-nav {
  flex: 1;
  padding: 12px 0;
  overflow-y: auto;
}

.nav-item {
  display: block;
  padding: 8px 16px;
  color: var(--sidebar-text);
  border-radius: 0;
  transition: background .15s, color .15s;
  cursor: pointer;
}

.nav-item:hover {
  background: var(--sidebar-hover-bg);
  color: var(--sidebar-text-active);
}

.nav-item.active {
  background: var(--sidebar-active-bg);
  color: #fff;
}

.nav-section-label {
  padding: 16px 16px 4px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .8px;
  color: #475569;
}

.sidebar-footer {
  padding: 12px 16px;
  border-top: 1px solid #334155;
  display: flex;
  align-items: center;
  gap: 8px;
}

.sidebar-user {
  flex: 1;
  font-size: 12px;
  color: #64748b;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ===== Main content ===== */
.main-content {
  margin-left: var(--sidebar-width);
  flex: 1;
  padding: 32px;
  min-width: 0;
}

#page-content {
  max-width: 1100px;
}

/* ===== Page header ===== */
.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 24px;
}

.page-header h1 {
  font-size: 22px;
  font-weight: 700;
  color: var(--text);
}

/* ===== Buttons ===== */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border: none;
  border-radius: var(--radius);
  cursor: pointer;
  font-weight: 500;
  transition: background .15s, opacity .15s;
  white-space: nowrap;
}

.btn:disabled { opacity: .55; cursor: not-allowed; }

.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--primary-hover); }

.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover:not(:disabled) { background: var(--danger-hover); }

.btn-success { background: var(--success); color: #fff; }

.btn-ghost { background: transparent; color: var(--text-muted); border: 1px solid var(--border); }
.btn-ghost:hover:not(:disabled) { background: var(--bg); color: var(--text); }

.btn-sm { padding: 4px 10px; font-size: 12px; }
.btn-full { width: 100%; justify-content: center; }

/* ===== Forms ===== */
.form-group {
  display: flex;
  flex-direction: column;
  gap: 5px;
  flex: 1;
}

.form-group label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: .4px;
}

.form-group input,
.form-group select {
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  transition: border-color .15s;
}

.form-group input:focus,
.form-group select:focus {
  outline: none;
  border-color: var(--primary);
}

.form-row {
  display: flex;
  gap: 16px;
  margin-bottom: 16px;
}

.form-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  margin-top: 16px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}

.inline-form {
  display: flex;
  gap: 8px;
  align-items: flex-end;
}

.inline-form input {
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  min-width: 200px;
}

.inline-form input:focus {
  outline: none;
  border-color: var(--primary);
}

/* ===== Tool controls ===== */
.tool-controls {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 24px;
}

.tool-controls .form-row {
  margin-bottom: 0;
}

/* ===== Tables ===== */
.data-table {
  width: 100%;
  border-collapse: collapse;
  background: var(--surface);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
}

.data-table th {
  padding: 10px 14px;
  text-align: left;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .5px;
  color: var(--text-muted);
  background: #f8fafc;
  border-bottom: 1px solid var(--border);
}

.data-table td {
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

.data-table tr:last-child td { border-bottom: none; }
.data-table tr:hover td { background: #f8fafc; }

/* ===== ALT table specifics ===== */
.thumb-cell { width: 80px; }

.thumb-preview {
  width: 64px;
  height: 48px;
  object-fit: cover;
  border-radius: 4px;
  display: block;
  background: #f1f5f9;
}

.path-cell {
  max-width: 180px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 12px;
  color: var(--text-muted);
}

.alt-cell { max-width: 200px; }

.suggested-cell { min-width: 200px; }

.alt-input {
  width: 100%;
  padding: 6px 8px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 13px;
}

.alt-input:focus {
  outline: none;
  border-color: var(--primary);
}

.actions-cell {
  white-space: nowrap;
  display: flex;
  gap: 6px;
  align-items: center;
}

.alt-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
  color: var(--text-muted);
  font-size: 13px;
}

/* ===== Word counter ===== */
.stats-header {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-bottom: 20px;
}

.stats-header h2 {
  font-size: 18px;
  font-weight: 600;
}

.stat-badge {
  background: var(--primary);
  color: #fff;
  padding: 4px 12px;
  border-radius: 20px;
  font-size: 13px;
  font-weight: 600;
}

.words-filter {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
}

.words-filter input {
  padding: 7px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  min-width: 200px;
}

.words-filter input:focus {
  outline: none;
  border-color: var(--primary);
}

.words-filter select {
  padding: 7px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  cursor: pointer;
}

.rank { color: var(--text-muted); font-size: 12px; width: 40px; }

.freq-bar {
  height: 8px;
  background: var(--primary);
  border-radius: 4px;
  min-width: 2px;
  opacity: .7;
}

/* ===== Stopwords ===== */
.stopwords-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.stopword-tag {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: #f1f5f9;
  border: 1px solid var(--border);
  padding: 4px 10px;
  border-radius: 20px;
  font-size: 13px;
}

.stopword-tag button {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-muted);
  font-size: 16px;
  line-height: 1;
  padding: 0;
  display: flex;
}

.stopword-tag button:hover { color: var(--danger); }

/* ===== Modal ===== */
.modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
}

.modal.hidden { display: none; }

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,.45);
}

.modal-content {
  position: relative;
  background: var(--surface);
  border-radius: 10px;
  padding: 28px;
  width: 520px;
  max-width: 95vw;
  box-shadow: 0 20px 60px rgba(0,0,0,.2);
}

.modal-content h2 {
  font-size: 18px;
  margin-bottom: 20px;
}

/* ===== Login page ===== */
.login-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  background: var(--sidebar-bg);
}

.login-container {
  background: var(--surface);
  border-radius: 12px;
  padding: 36px;
  width: 360px;
  box-shadow: 0 20px 60px rgba(0,0,0,.3);
}

.login-logo {
  font-size: 22px;
  font-weight: 800;
  color: var(--primary);
  text-align: center;
  margin-bottom: 28px;
  letter-spacing: -0.5px;
}

.login-container .form-group {
  margin-bottom: 16px;
}

/* ===== Alerts ===== */
.alert {
  padding: 10px 14px;
  border-radius: var(--radius);
  font-size: 13px;
  margin-bottom: 12px;
}

.alert-error { background: #fef2f2; color: #b91c1c; border: 1px solid #fecaca; }
.alert-success { background: #f0fdf4; color: #15803d; border: 1px solid #bbf7d0; }

/* ===== Utilities ===== */
.hidden { display: none !important; }

.empty-state {
  text-align: center;
  color: var(--text-muted);
  padding: 40px;
  background: var(--surface);
  border-radius: var(--radius);
  border: 1px dashed var(--border);
}

.loading-text {
  color: var(--text-muted);
  font-style: italic;
  font-size: 12px;
}

.placeholder-text { color: #cbd5e1; }

.error-badge {
  display: inline-block;
  background: #fef2f2;
  color: var(--danger);
  border: 1px solid #fecaca;
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 600;
}

.empty-alt { color: #cbd5e1; }

/* ===== Audit SEO ===== */
.audit-summary {
  display: flex;
  align-items: center;
  gap: 24px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  margin-bottom: 24px;
}

.score-circle {
  width: 100px;
  height: 100px;
  border-radius: 50%;
  border: 7px solid;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 32px;
  font-weight: 800;
  flex-shrink: 0;
}

.audit-site-name { font-size: 18px; font-weight: 700; margin-bottom: 6px; }
.audit-meta-info { font-size: 13px; color: var(--text-muted); }

.categories-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 12px;
  margin-bottom: 24px;
}

.cat-card {
  background: var(--surface);
  border: 2px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  cursor: pointer;
  transition: border-color .15s, box-shadow .15s;
  text-align: center;
}

.cat-card:hover { border-color: var(--primary); box-shadow: var(--shadow); }
.cat-card.active { border-color: var(--primary); }

.cat-score-num { font-size: 28px; font-weight: 800; margin-bottom: 4px; }
.cat-label { font-size: 12px; font-weight: 600; color: var(--text-muted); margin-bottom: 8px; text-transform: uppercase; letter-spacing: .3px; }

.cat-bar-wrap { height: 6px; background: #e2e8f0; border-radius: 3px; margin-bottom: 8px; overflow: hidden; }
.cat-bar-fill { height: 100%; border-radius: 3px; transition: width .4s; }

.cat-issues-count { font-size: 11px; font-weight: 600; }

.cat-detail {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 24px;
}

.cat-detail h2 { font-size: 16px; margin-bottom: 16px; }

.checks-list { display: flex; flex-direction: column; gap: 6px; }

.check-row {
  border-radius: var(--radius);
  overflow: hidden;
  border: 1px solid;
}

.check-ok      { border-color: #bbf7d0; background: #f0fdf4; }
.check-error   { border-color: #fecaca; background: #fef2f2; }
.check-warning { border-color: #fed7aa; background: #fff7ed; }

.check-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  cursor: pointer;
  user-select: none;
}

.check-header:hover { opacity: .85; }

.check-icon { font-size: 14px; flex-shrink: 0; }
.check-ok .check-icon    { color: #15803d; }
.check-error .check-icon { color: #b91c1c; }
.check-warning .check-icon { color: #92400e; }

.check-label-text { flex: 1; font-size: 13px; font-weight: 500; }
.check-stat { font-size: 12px; color: var(--text-muted); flex-shrink: 0; }
.check-toggle { font-size: 11px; color: var(--text-muted); flex-shrink: 0; }

.check-pages { border-top: 1px solid rgba(0,0,0,.06); }

/* ===== Dead links ===== */
.badge-ok   { display:inline-block; padding:2px 8px; border-radius:4px; background:#f0fdf4; color:#15803d; font-size:12px; font-weight:700; border:1px solid #bbf7d0; }
.badge-dead { display:inline-block; padding:2px 8px; border-radius:4px; background:#fef2f2; color:#b91c1c; font-size:12px; font-weight:700; border:1px solid #fecaca; }

.page-chip {
  display: inline-block;
  background: #f1f5f9;
  border: 1px solid #e2e8f0;
  padding: 1px 6px;
  border-radius: 10px;
  font-size: 11px;
  margin: 1px;
}

/* ===== Audit link expand ===== */
.link-expand summary {
  cursor: pointer; font-size: 12px; color: var(--primary);
  list-style: none; display: inline-flex; align-items: center; gap: 4px;
  user-select: none;
}
.link-expand summary::-webkit-details-marker { display: none; }
.link-expand summary::after { content: ' ▼'; font-size: 10px; }
.link-expand[open] summary::after { content: ' ▲'; }
.link-expand-list {
  margin: 6px 0 2px 0; padding: 0; list-style: none;
  display: flex; flex-direction: column; gap: 3px;
}
.link-expand-list li a {
  font-size: 11px; color: #64748b; word-break: break-all;
}
.link-expand-list li a:hover { color: var(--primary); }

/* ===== Audit dup headings ===== */
.dupes-expand { display: flex; flex-direction: column; gap: 6px; margin-top: 6px; }
.dupe-group { display: flex; flex-direction: column; gap: 3px; }
.dupe-group-label { font-size: 11px; color: #94a3b8; font-style: italic; margin-bottom: 2px; }
.dupe-sec-row { display: flex; align-items: center; gap: 6px; }
.dupe-level { flex-shrink: 0; font-size: 10px; font-weight: 700; color: #fff; background: #64748b; padding: 1px 5px; border-radius: 3px; }
.dupe-sec-val { display: flex; align-items: center; gap: 5px; flex: 1; min-width: 0; }
.dupe-sec-title { font-size: 12px; color: var(--text); word-break: break-word; }

/* ===== Audit inline edit ===== */
.av-cell { display: flex; align-items: center; gap: 6px; }
.av-text { font-size: 12px; color: var(--text); flex: 1; min-width: 0; word-break: break-word; }
.av-empty { color: #94a3b8; font-style: italic; }
.av-saving { font-size: 12px; color: #94a3b8; font-style: italic; }
.av-error  { font-size: 12px; color: #ef4444; }

.btn-av-edit {
  flex-shrink: 0;
  background: none; border: none; cursor: pointer;
  font-size: 13px; color: #94a3b8; padding: 2px 4px; border-radius: 3px;
  line-height: 1; opacity: 0;
  transition: opacity .15s, color .15s;
}
.av-cell:hover .btn-av-edit { opacity: 1; }
.btn-av-edit:hover { color: var(--primary); }

.av-input {
  flex: 1; min-width: 0;
  font-size: 12px; padding: 3px 6px;
  border: 1px solid var(--primary); border-radius: 4px;
  outline: none; background: #fff; color: var(--text);
}

.btn-av-save, .btn-av-cancel {
  flex-shrink: 0;
  border: none; cursor: pointer; font-size: 14px; font-weight: 700;
  padding: 2px 5px; border-radius: 3px; line-height: 1;
}
.btn-av-save   { background: #dcfce7; color: #166534; }
.btn-av-save:hover   { background: #bbf7d0; }
.btn-av-cancel { background: #fee2e2; color: #991b1b; }
.btn-av-cancel:hover { background: #fecaca; }

/* ===== Semantic ===== */
.sem-result-block { display: flex; flex-direction: column; gap: 20px; margin-top: 24px; }

.sem-meta { font-size: 14px; color: var(--text-muted); display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }

.sem-section { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px 20px; }
.sem-section h3 { font-size: 13px; font-weight: 700; color: var(--text); margin-bottom: 10px; display: flex; align-items: center; gap: 8px; }
.sem-section p { font-size: 13px; color: var(--text); line-height: 1.6; }

.sem-count { display: inline-block; padding: 1px 8px; border-radius: 10px; background: #dbeafe; color: #1d4ed8; font-size: 11px; font-weight: 600; }
.sem-count-missing { background: #fee2e2; color: #b91c1c; }

.sem-tags { display: flex; flex-wrap: wrap; gap: 6px; }
.sem-tag { display: inline-block; padding: 3px 10px; border-radius: 12px; font-size: 12px; font-weight: 500; }
.sem-found   { background: #dcfce7; color: #166534; border: 1px solid #bbf7d0; }
.sem-missing { background: #fef9c3; color: #854d0e; border: 1px solid #fef08a; }

.sem-recs { padding-left: 18px; display: flex; flex-direction: column; gap: 6px; }
.sem-recs li { font-size: 13px; color: var(--text); line-height: 1.5; }
