:root {
  --bg: #f6f4ef;
  --surface: #ffffff;
  --surface-muted: #ebe7de;
  --text: #1f2328;
  --muted: #68707a;
  --line: #d8d3c9;
  --accent: #175c62;
  --accent-soft: #e5efec;
  --accent-strong: #0f4045;
  --danger: #b42318;
  --success: #287a3e;
  --radius: 8px;
  --shadow: 0 16px 40px rgba(31, 35, 40, 0.08);
  --font: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

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

a {
  color: inherit;
  text-decoration: none;
}

input,
select,
textarea,
button {
  font: inherit;
}

.shell {
  display: grid;
  grid-template-columns: 224px minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
  height: 100dvh;
  overflow-y: auto;
  padding: 24px 16px 16px;
  border-right: 1px solid var(--line);
  background: var(--surface);
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 12px;
  font-weight: 700;
}

.brand-mark {
  display: grid;
  width: 32px;
  height: 32px;
  flex-shrink: 0;
  place-items: center;
  border-radius: var(--radius);
  background: var(--text);
  color: white;
  font-size: 12px;
  text-transform: uppercase;
}

.sidebar-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding-left: 12px;
}

.sidebar-header .brand {
  padding: 0;
  font-size: 14px;
}

.sidebar-toggle {
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  flex-shrink: 0;
  margin-left: auto;
  padding: 6px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--muted);
  cursor: pointer;
}

.sidebar-toggle[hidden] { display: none; }
.sidebar-toggle:hover { color: var(--accent); background: var(--accent-soft); }
.sidebar-toggle svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.sidebar-collapsed .sidebar-toggle svg { transform: rotate(180deg); }

@media (min-width: 821px) {
  .sidebar-collapsed .shell { grid-template-columns: 76px minmax(0, 1fr); }
  .sidebar-collapsed .sidebar { padding-inline: 16px; }
  .sidebar-collapsed .sidebar-header { flex-direction: column; padding: 0; }
  .sidebar-collapsed .sidebar-toggle { margin: 0; }
  .sidebar-collapsed .nav a,
  .sidebar-collapsed .logout { justify-content: center; padding-inline: 0; }
  .sidebar-collapsed .brand-name,
  .sidebar-collapsed .nav a span,
  .sidebar-collapsed .logout span {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip-path: inset(50%);
    white-space: nowrap;
  }
}

.nav {
  display: grid;
  gap: 4px;
  margin-top: 32px;
  margin-bottom: 24px;
}

.nav a,
.logout,
.tabs a {
  border-radius: var(--radius);
  color: var(--muted);
  padding: 9px 10px;
}

.nav a:hover,
.logout:hover,
.tabs a:hover {
  background: var(--surface-muted);
  color: var(--text);
}

.nav a,
.logout {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 44px;
  padding: 10px 12px;
  font-size: 14px;
  font-weight: 500;
  white-space: nowrap;
  transition: background-color 150ms ease, color 150ms ease;
}

.nav svg,
.logout svg {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.7;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.nav a[aria-current="page"],
.tabs a[aria-current="page"] {
  background: var(--accent-soft);
  color: var(--accent-strong);
  font-weight: 650;
}

.sidebar a:focus-visible,
.sidebar-toggle:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.sidebar-footer {
  margin-top: auto;
  padding-top: 16px;
  border-top: 1px solid var(--line);
}

.main {
  width: 100%;
  max-width: 1120px;
  padding: 40px;
}

.auth-card,
.hub-card,
.panel,
.card,
.metric {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.auth-card {
  width: min(100%, 420px);
  max-width: 420px;
  margin: 12vh auto;
  padding: 32px;
}

.auth-page .shell {
  display: block;
}

.auth-page .main {
  display: grid;
  width: 100%;
  max-width: none;
  min-height: 100vh;
  place-items: center;
  padding: 24px;
}

.auth-page .auth-card {
  margin: 0;
}

.hub-card {
  max-width: 720px;
  padding: 32px;
}

.eyebrow {
  color: var(--accent);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0;
  margin: 0 0 8px;
  text-transform: uppercase;
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

h1 {
  font-size: 40px;
  line-height: 1.1;
  margin-bottom: 12px;
}

h2 {
  font-size: 22px;
}

.lead {
  color: var(--muted);
  font-size: 18px;
}

.muted {
  color: var(--muted);
}

.form {
  display: grid;
  gap: 16px;
}

.form label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 14px;
}

.form input,
.form select,
.form textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 11px 12px;
}

.form textarea {
  resize: vertical;
}

.form .checkbox-row {
  align-items: center;
  display: flex;
  flex-direction: row-reverse;
  gap: 10px;
  justify-content: flex-end;
}

.form .checkbox-row input {
  width: auto;
}

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  padding: 10px 14px;
}

.button.primary {
  border-color: var(--accent);
  background: var(--accent);
  color: white;
}

.button.primary:hover:not(:disabled) {
  background: var(--accent-strong);
}

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

.auth-card .button {
  width: 100%;
}

.quick-grid,
.card-grid,
.metric-grid {
  display: grid;
  gap: 16px;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  margin-top: 24px;
}

.quick-link,
.card,
.metric {
  padding: 18px;
}

.quick-link {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-muted);
}

.quick-link span,
.metric span {
  color: var(--muted);
  display: block;
  font-size: 13px;
}

.quick-link strong,
.metric strong {
  display: block;
  margin-top: 6px;
}

.page-header {
  margin-bottom: 24px;
}

.panel {
  margin-bottom: 18px;
  padding: 24px;
}

.stack {
  display: grid;
  gap: 14px;
}

.item {
  border-top: 1px solid var(--line);
  padding-top: 14px;
}

.tag-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.tag,
.badge {
  display: inline-flex;
  border-radius: 999px;
  background: var(--surface-muted);
  color: var(--muted);
  font-size: 12px;
  padding: 4px 9px;
}

.article {
  max-width: 760px;
}

.tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: -8px 0 22px;
}

.control-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 18px;
}

.control-form {
  gap: 18px;
}

#connection-guide li + li {
  margin-top: 10px;
}

#connection-guide code {
  overflow-wrap: anywhere;
}

#connection-guide a:not(.button) {
  color: var(--accent);
  text-decoration: underline;
  text-underline-offset: 3px;
}

#connection-guide a:not(.button):hover {
  color: var(--accent-strong);
}

.form-grid {
  display: grid;
  gap: 16px;
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.form-grid label:has(textarea) {
  grid-column: 1 / -1;
}

.inline-formset {
  border-top: 1px solid var(--line);
  display: grid;
  gap: 14px;
  padding-top: 18px;
}

.inline-formset h2 {
  margin-bottom: 0;
}

.inline-row {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  display: grid;
  gap: 12px;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  padding: 14px;
}

.inline-row label:has(textarea) {
  grid-column: 1 / -1;
}

.form-errors {
  color: var(--danger);
}

.table-actions {
  text-align: right;
  white-space: nowrap;
}

.table-scroll {
  max-width: 100%;
  overflow-x: auto;
}

.table-scroll table {
  min-width: 480px;
}

.table-actions a {
  color: var(--accent);
  font-weight: 600;
}

table {
  border-collapse: collapse;
  width: 100%;
}

th,
td {
  border-bottom: 1px solid var(--line);
  padding: 12px 10px;
  text-align: left;
}

th {
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
}

.row-link {
  align-items: center;
  border-bottom: 1px solid var(--line);
  display: flex;
  justify-content: space-between;
  padding: 12px 0;
}

.messages {
  margin-bottom: 18px;
}

.message {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  margin-bottom: 8px;
  padding: 10px 12px;
}

.message.error {
  border-color: var(--danger);
  color: var(--danger);
}

.message.success {
  border-color: var(--success);
  color: var(--success);
}

.status-row {
  align-items: center;
  display: flex;
  gap: 10px;
  margin-bottom: 16px;
}

.log-list pre {
  overflow: auto;
  border-radius: var(--radius);
  background: #111418;
  color: #edf0f3;
  padding: 12px;
}

@media (max-width: 820px) {
  .shell {
    display: block;
  }

  .sidebar {
    display: grid;
    grid-template-columns: 1fr auto;
    grid-template-areas: "brand exit" "nav nav";
    align-items: center;
    gap: 12px;
    position: static;
    height: auto;
    padding: 16px 24px;
    overflow: visible;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .sidebar-header {
    grid-area: brand;
    padding: 0;
  }

  .sidebar-toggle { margin-left: 0; }
  .sidebar-collapsed .sidebar { grid-template-areas: "brand exit"; }
  .sidebar-collapsed .nav { display: none; }

  .nav {
    grid-area: nav;
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin: 0;
  }

  .nav a {
    justify-content: flex-start;
    gap: 7px;
    padding: 10px 12px;
    font-size: 13px;
  }

  .sidebar-footer {
    grid-area: exit;
    margin: 0;
    padding: 0;
    border: 0;
  }

  .main {
    padding: 24px;
  }

  .quick-grid,
  .card-grid,
  .metric-grid,
  .form-grid,
  .inline-row {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 620px) {
  .sidebar {
    padding: 12px 16px;
    gap: 8px;
  }

  .nav a {
    gap: 6px;
    padding: 10px 12px;
  }

  .nav svg {
    width: 16px;
    height: 16px;
  }
}

@media (max-width: 420px) {
  .auth-page .main {
    align-items: start;
    padding: 28px 16px;
  }

  .auth-card {
    padding: 24px;
  }

  h1 {
    font-size: 34px;
  }
}

/* Project workspace uses the existing palette and components. */
.project-context { margin-bottom: 24px; border-bottom: 1px solid var(--line); padding-bottom: 16px; }
.project-heading { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 12px; }
.project-heading > div { min-width: 0; }
.project-heading p { margin: 4px 0 12px; overflow-wrap: anywhere; }
.project-tabs { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 12px; }
.project-tabs a { padding: 10px 12px; border-radius: var(--radius); min-height: 44px; }
.project-tabs a:hover, .project-tabs a[aria-current] { background: var(--accent-soft); color: var(--accent-strong); }
.project-tab-alert { display: inline-flex; align-items: center; justify-content: center; width: 20px; height: 20px; margin-left: 4px; border-radius: 50%; background: var(--danger); color: #fff; font-weight: 700; font-size: 13px; vertical-align: middle; }
.project-switcher { display: grid; gap: 8px; padding-bottom: 8px; min-width: 0; }
.project-switcher label { color: var(--muted); font-size: 14px; }
.project-switcher select { min-width: 0; width: 100%; }
.project-switcher a { justify-self: start; white-space: normal; }
.main { min-width: 0; }
.main h1, .main h2, .main h3, .main .row-link { overflow-wrap: anywhere; }
.row-link { gap: 12px; }
.main a.text-link { color: var(--accent-strong); text-decoration: underline; text-underline-offset: 3px; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }
@media (min-width: 821px) { .sidebar-collapsed .project-switcher { display: none; } }
@media (max-width: 820px) { .project-switcher { flex: 0 0 100%; grid-template-columns: minmax(0, 1fr) auto; align-items: stretch; column-gap: 12px; } .project-switcher label { grid-column: 1 / -1; } .project-switcher a { grid-column: 1 / -1; } }
@media (max-width: 420px) { .main { padding: 20px 16px; } .project-tabs { gap: 2px; } .project-tabs a { padding: 8px; font-size: 14px; } }

.project-switcher select {
  appearance: none;
  min-height: 46px;
  padding: 10px 40px 10px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background-color: var(--surface);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%2319343D' stroke-width='1.75' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  background-size: 16px;
  color: var(--text);
}
@media (forced-colors: active) { .project-switcher select { appearance: auto; background-image: none; } }
.table-scroll { max-width: 100%; overflow-x: auto; }

.seo-report-action { margin-top: 16px; }
.seo-metrics { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.seo-metrics .metric { display: flex; flex-direction: column; justify-content: space-between; background: var(--bg); box-shadow: none; }
.seo-metrics strong { font-size: 28px; }
@media (max-width: 620px) { .seo-metrics { grid-template-columns: 1fr; } }

.project-subtabs { border-top: 1px solid var(--line); padding-top: 10px; }
.project-subtabs a { font-size: 14px; }
.project-workspaces { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; margin-bottom: 24px; }
.workspace-link { display: block; margin: 0; }
.workspace-link:hover { border-color: var(--accent); background: var(--accent-soft); }
.workspace-link h2 { display: flex; justify-content: space-between; gap: 16px; font-size: 20px; }
.workspace-link p { margin-bottom: 0; }
.section-actions { margin-bottom: 24px; }
.seo-panel h3, .seo-panel p { overflow-wrap: anywhere; }
.seo-reports { display: grid; gap: 18px; }
.seo-overview .seo-metrics { margin-top: 12px; }
.seo-overview .seo-metrics .metric { padding: 12px 16px; }
.seo-overview .seo-metrics strong { font-size: 24px; }
@media (max-width: 620px) { .project-workspaces { grid-template-columns: 1fr; } }
