:root {
  --bg: #ffffff;
  --bg-soft: #f7f7f8;
  --card: #ffffff;
  --card-muted: #f9fafb;
  --text: #1f2933;
  --muted: #6b7280;
  --primary: #b91c1c;
  --primary-dark: #991b1b;
  --primary-soft: #fff1f1;
  --border: #e4e7eb;
  --success-bg: #eefaf2;
  --success-text: #166534;
  --error-bg: #fff1f1;
  --error-text: #991b1b;
  --shadow: 0 16px 42px rgba(31, 41, 51, 0.08);
  --shadow-soft: 0 8px 24px rgba(31, 41, 51, 0.06);

  /* Compact density system: change these tokens to tune the whole application. */
  --ui-density: compact;
  --font-body: 14px;
  --font-small: 12px;
  --font-control: 13px;
  --font-card-title: 17px;
  --font-page-title: clamp(22px, 2.4vw, 26px);
  --control-height: 36px;
  --control-height-small: 32px;
  --icon-size: 32px;
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-6: 24px;
  --radius-control: 10px;
  --radius-card: 16px;
  --table-cell-block: 9px;
  --table-cell-inline: 12px;
  --content-max-width: 1680px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background:
    radial-gradient(circle at 15% 0%, rgba(185, 28, 28, 0.08), transparent 28rem),
    linear-gradient(180deg, #ffffff 0%, #f8f8f9 100%);
  color: var(--text);
  font-family: Inter, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: var(--font-body);
  line-height: 1.45;
}

body.drawer-open { overflow: hidden; }

.app-shell { display: flex; min-height: 100vh; width: 100%; }
.app-sidebar {
  position: sticky;
  top: 0;
  z-index: 30;
  display: flex;
  flex: 0 0 300px;
  flex-direction: column;
  width: 300px;
  height: 100vh;
  min-height: 100vh;
  overflow-y: auto;
  background: var(--card);
  border-right: 1px solid var(--border);
  box-shadow: var(--shadow-soft);
}
.sidebar-header { padding: 24px 24px 20px; border-bottom: 1px solid var(--border); }
.sidebar-brand { display: block; padding: 2px 0; }
.sidebar-brand img { display: block; width: 100%; height: auto; max-height: 48px; object-fit: contain; object-position: left center; }
.sidebar-header p { margin: 13px 0 0; color: var(--muted); font-size: 12px; font-weight: 650; line-height: 1.45; }
.sidebar-nav { flex: 1 0 auto; padding: 18px 14px; }
.sidebar-group-label { padding: 0 12px 8px; color: var(--muted); font-size: 11px; font-weight: 900; letter-spacing: .08em; text-transform: uppercase; }
.sidebar-admin-label { margin-top: 22px; padding-top: 18px; border-top: 1px solid var(--border); }
.sidebar-link {
  position: relative;
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 46px;
  margin: 2px 0;
  padding: 10px 13px;
  border-radius: 13px;
  color: var(--muted);
  font-weight: 800;
  line-height: 1.3;
  text-decoration: none;
  transition: background .15s ease, color .15s ease, transform .15s ease;
}
.sidebar-link:hover { background: var(--primary-soft); color: var(--primary); transform: translateX(2px); }
.sidebar-link:focus-visible, .sidebar-toggle:focus-visible, .sidebar-backdrop:focus-visible { outline: 3px solid rgba(185, 28, 28, .2); outline-offset: 2px; }
.sidebar-marker { width: 4px; height: 18px; flex: 0 0 4px; border-radius: 999px; background: transparent; }
.sidebar-link.is-active { background: var(--primary-soft); color: var(--primary-dark); font-weight: 900; }
.sidebar-link.is-active .sidebar-marker { background: var(--primary); }
.sidebar-footer { flex: 0 0 auto; padding: 16px 14px 20px; border-top: 1px solid var(--border); background: var(--card-muted); }
.sidebar-tokens { margin: 0 8px 10px; color: var(--muted); font-size: 12px; line-height: 1.45; }
.sidebar-tokens strong { color: var(--text); }
.sidebar-logout { color: var(--text); }
.app-workspace { flex: 1; min-width: 0; min-height: 100vh; }
.workspace-content { width: 100%; max-width: 1600px; margin: 0 auto; padding: 34px 32px 56px; }
.mobile-appbar, .sidebar-backdrop { display: none; }
.public-container { max-width: 1180px; }

a { color: inherit; }

.topbar {
  min-height: 76px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 14px 32px;
  background: rgba(255, 255, 255, 0.94);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
  backdrop-filter: blur(12px);
}

.topbar-public { justify-content: flex-start; }

.brand {
  display: inline-flex;
  align-items: center;
  gap: 16px;
  min-width: 0;
  padding: 4px 0;
  text-decoration: none;
}

.brand-logo {
  display: block;
  width: auto;
  height: 42px;
  max-width: min(320px, 54vw);
  object-fit: contain;
  flex: 0 1 auto;
}

.brand-subtitle { color: var(--muted); font-size: 13px; font-weight: 650; min-width: 0; }

.topnav { display: flex; gap: 8px; color: var(--muted); font-weight: 750; }
.topnav a { padding: 10px 12px; border-radius: 999px; text-decoration: none; }
.topnav a:hover { background: var(--primary-soft); color: var(--primary); }

.container { max-width: 1180px; margin: 0 auto; padding: 34px 24px 56px; }

.auth-card, .card, .menu-card, .stat-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 22px;
  box-shadow: var(--shadow-soft);
}

.auth-layout { display: grid; grid-template-columns: minmax(0, 1fr) 440px; gap: 34px; align-items: center; min-height: calc(100vh - 180px); }
.auth-intro { padding: 28px 0; }
.auth-intro .eyebrow { display: block; margin-bottom: 14px; }
.auth-intro h1 { max-width: 680px; margin: 0; font-size: clamp(36px, 3.2vw, 42px); line-height: 1.14; font-weight: 700; }
.auth-description { max-width: 660px; margin: 22px 0 0; color: var(--muted); font-size: 17px; font-weight: 400; line-height: 1.55; }
.auth-card { padding: 32px; }

.page-header { margin-bottom: 24px; }
.page-header-accent { padding: 24px; border: 1px solid var(--border); border-radius: 24px; background: linear-gradient(135deg, #ffffff 0%, #fff5f5 100%); }

h1, h2 { margin: 0 0 12px; letter-spacing: -0.035em; }
h1 { font-size: clamp(30px, 4vw, 44px); line-height: 1.04; }
h2 { font-size: 22px; }

.eyebrow { display: inline-flex; margin-bottom: 10px; color: var(--primary); font-size: 12px; font-weight: 900; letter-spacing: .08em; text-transform: uppercase; }
.muted { color: var(--muted); line-height: 1.55; }
.small { font-size: 14px; }
.card-description { max-width: 900px; margin: -4px 0 20px; }

.form { display: grid; gap: 18px; }
.feed-upload-form { margin-top: 22px; }
.form-wide { grid-template-columns: minmax(320px, 1fr) 260px auto; align-items: end; }
label { display: grid; gap: 8px; font-weight: 800; }
input, select {
  width: 100%; min-height: 46px; padding: 10px 13px; border: 1px solid var(--border); border-radius: 13px;
  background: #ffffff; color: var(--text); font: inherit; transition: border-color .15s ease, box-shadow .15s ease;
}
input:focus, select:focus { outline: 3px solid rgba(185, 28, 28, 0.14); border-color: var(--primary); }

.button {
  display: inline-flex; align-items: center; justify-content: center; min-height: 46px; padding: 10px 18px;
  border: 1px solid var(--border); border-radius: 13px; background: #ffffff; color: var(--text); text-decoration: none;
  cursor: pointer; font-weight: 850; font: inherit; transition: transform .15s ease, background .15s ease, border-color .15s ease;
}
.button:hover { transform: translateY(-1px); border-color: #fecaca; color: var(--primary); }
.button:disabled { opacity: .72; cursor: wait; transform: none; }
.button-primary { background: var(--primary); border-color: var(--primary); color: #ffffff; box-shadow: 0 10px 22px rgba(185, 28, 28, .18); }
.button-primary:hover { background: var(--primary-dark); color: #ffffff; }
.button-secondary { background: var(--primary-soft); border-color: #fecaca; color: var(--primary); }

.card { padding: 24px; margin-bottom: 24px; }
.feed-card { border-top: 4px solid var(--primary); }

.menu-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 20px; }
.menu-card { display: block; min-height: 248px; padding: 24px; text-decoration: none; transition: transform .15s ease, box-shadow .15s ease, border-color .15s ease; }
.menu-card-primary { border-color: #fecaca; background: linear-gradient(180deg, #ffffff 0%, #fff7f7 100%); box-shadow: var(--shadow); }
.menu-card:hover { transform: translateY(-3px); box-shadow: var(--shadow); }
.menu-card-disabled { background: var(--card-muted); color: #7b8491; box-shadow: none; }
.menu-card-disabled:hover { transform: none; box-shadow: none; }
.menu-card p { color: var(--muted); line-height: 1.5; }
.card-topline, .section-title-row { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 16px; }
.module-icon { width: 40px; height: 40px; display: grid; place-items: center; border-radius: 13px; background: var(--primary-soft); color: var(--primary); font-weight: 900; }
.badge { display: inline-flex; align-items: center; min-height: 28px; padding: 5px 10px; border-radius: 999px; background: #eef0f3; color: #68707d; font-size: 12px; font-weight: 900; }
.badge-live { background: var(--primary-soft); color: var(--primary); }
.card-cta { display: inline-flex; margin-top: 14px; color: var(--primary); font-weight: 900; }

.actions { display: flex; align-items: end; }
.inline-form { display: flex; align-items: center; flex-wrap: wrap; gap: 14px; margin-top: 18px; padding-top: 18px; border-top: 1px solid var(--border); }

.stats-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 18px; margin-bottom: 24px; }
.stat-card { padding: 22px; background: linear-gradient(180deg, #ffffff 0%, #fafafa 100%); }
.stat-label { color: var(--muted); font-weight: 800; margin-bottom: 10px; }
.stat-value { font-size: 36px; line-height: 1; font-weight: 950; letter-spacing: -0.045em; }
.stat-date { font-size: 20px; line-height: 1.25; }
.status-success { color: var(--success-text); }
.status-failed { color: var(--error-text); }
.status-empty { color: var(--muted); }

.report-info-row { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 14px; padding: 14px 16px; margin-bottom: 16px; border: 1px solid #fecaca; border-radius: 16px; background: var(--primary-soft); }
.report-info-row .button { flex-shrink: 0; }

.empty-state { padding: 26px; border: 1px dashed #fca5a5; border-radius: 16px; background: #fffafa; color: var(--muted); text-align: center; font-weight: 750; }
.empty-state.compact { padding: 16px; }

.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: 16px; background: #ffffff; }
table { width: 100%; min-width: 680px; border-collapse: collapse; background: #ffffff; }
th, td { padding: 13px 15px; border-bottom: 1px solid var(--border); text-align: left; vertical-align: top; }
th { background: #f6f7f9; color: #4b5563; font-size: 12px; text-transform: uppercase; letter-spacing: 0.055em; }
tbody tr:hover { background: #fffafa; }
tr:last-child td { border-bottom: none; }
.number { text-align: right; font-weight: 900; color: var(--primary); }

.alert { padding: 14px 16px; border-radius: 15px; margin-bottom: 18px; font-weight: 800; }
.alert-success { background: var(--success-bg); color: var(--success-text); }
.alert-error, .error-card { background: var(--error-bg); color: var(--error-text); }

@media (max-width: 960px) {
  .app-shell { display: block; }
  .mobile-appbar {
    position: sticky; top: 0; z-index: 20;
    display: flex; align-items: center; justify-content: space-between; gap: 18px;
    min-height: 64px; padding: 10px 18px;
    background: rgba(255,255,255,.96); border-bottom: 1px solid var(--border); backdrop-filter: blur(12px);
  }
  .mobile-brand { display: block; min-width: 0; }
  .mobile-brand img { display: block; width: auto; height: 34px; max-width: min(270px, 68vw); object-fit: contain; }
  .sidebar-toggle { display: grid; flex: 0 0 44px; width: 44px; height: 44px; padding: 10px; place-content: center; gap: 5px; border: 1px solid var(--border); border-radius: 12px; background: var(--card); cursor: pointer; }
  .sidebar-toggle span { display: block; width: 20px; height: 2px; border-radius: 9px; background: var(--primary); }
  .app-sidebar { position: static; width: 100%; height: auto; min-height: 0; border-right: 0; }
  .sidebar-js .app-sidebar { position: fixed; left: 0; top: 0; width: min(320px, 86vw); height: 100vh; transform: translateX(-105%); transition: transform .22s ease; }
  .sidebar-js .sidebar-open .app-sidebar { transform: translateX(0); }
  .sidebar-js .sidebar-backdrop { position: fixed; inset: 0; z-index: 25; display: block; padding: 0; border: 0; background: rgba(31, 41, 51, .44); opacity: 0; pointer-events: none; transition: opacity .2s ease; }
  .sidebar-js .sidebar-open .sidebar-backdrop { opacity: 1; pointer-events: auto; }
  .workspace-content { max-width: none; padding: 24px 20px 40px; }
  .topbar { padding: 12px 18px; align-items: flex-start; flex-direction: column; }
  .topbar-public { align-items: flex-start; }
  .container { padding: 24px 16px 40px; }
  .auth-layout { grid-template-columns: 1fr; min-height: auto; }
  .auth-intro { padding: 20px 0; }
  .auth-intro h1 { font-size: clamp(30px, 4.5vw, 36px); }
  .form-wide { grid-template-columns: 1fr; }
  .menu-grid { grid-template-columns: 1fr; }
  .stats-grid { grid-template-columns: 1fr 1fr; }
}

@media (max-width: 560px) {
  .mobile-appbar { padding: 8px 12px; }
  .mobile-brand img { height: 29px; max-width: 68vw; }
  .workspace-content { padding: 20px 12px 36px; overflow-x: clip; }
  .topbar { gap: 12px; }
  .brand { gap: 10px; }
  .brand-logo { height: 30px; max-width: min(240px, 72vw); }
  .brand-subtitle { display: none; }
  .topnav { width: 100%; overflow-x: auto; padding-bottom: 2px; }
  .stats-grid { grid-template-columns: 1fr; }
  .auth-intro { padding: 12px 0 20px; }
  .auth-intro .eyebrow { margin-bottom: 12px; }
  .auth-intro h1 { font-size: 28px; line-height: 1.16; }
  .auth-description { margin-top: 18px; font-size: 16px; line-height: 1.55; }
  .section-title-row { align-items: flex-start; flex-direction: column; }
  .report-info-row { align-items: stretch; flex-direction: column; }
  .report-info-row .button, .inline-form .button { width: 100%; }
  .rubric-analyses-actions { align-items: stretch; }
  .rubric-analyses-actions form,
  .rubric-analyses-actions .button { width: 100%; }
  .auth-card, .card, .menu-card, .page-header-accent { border-radius: 18px; padding: 20px; }
}
textarea { width: 100%; padding: 12px 13px; border: 1px solid var(--border); border-radius: 13px; font: inherit; resize: vertical; }
textarea:focus { outline: 3px solid rgba(185, 28, 28, 0.14); border-color: var(--primary); }
.inline-actions, .row-actions { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.rubric-analyses-actions { gap: 14px; }
.rubric-analyses-actions .button { white-space: nowrap; }
.analysis-current-status { margin-top: 16px; }
.rubric-analyses-status-host:not(:empty) { margin-top: 14px; }
.rubric-analyses-status-host .task-status-card { margin-top: 0; }
.button-small { min-height: 34px; padding: 6px 10px; border-radius: 10px; font-size: 13px; }
.tree-root, .tree-node { display: grid; gap: 10px; }
.tree-root { margin-top: 18px; }
.tree-node { margin: 10px 0 0 24px; padding-left: 14px; border-left: 2px solid #fecaca; }
.tree-row { display: grid; grid-template-columns: minmax(220px, 1fr) 140px repeat(4, auto); gap: 8px; align-items: center; padding: 10px; background: #fffafa; border: 1px solid var(--border); border-radius: 14px; }
.json-box, .markdown-result { white-space: pre-wrap; overflow-x: auto; padding: 16px; border-radius: 14px; background: #f6f7f9; border: 1px solid var(--border); }
.markdown-result { line-height: 1.55; }

.rubric-title-link { color: var(--primary); text-decoration: none; cursor: pointer; }
.rubric-title-link:hover, .rubric-title-link:focus { text-decoration: underline; }
.export-actions { margin-top: 14px; }
@media (max-width: 760px) { .tree-row { grid-template-columns: 1fr; } .tree-node { margin-left: 8px; } }

/* Rubric editor grid: mirrors the public Komus-like category columns while keeping edit controls inline. */
.rubric-editor-form #rubric-editor { margin-top: 18px; }
.rubric-editor-form .tree-root { gap: 18px; margin-top: 0; }
.rubric-editor-form .tree-root > .tree-row {
  background: linear-gradient(180deg, #ffffff 0%, #fff7f7 100%);
  border-color: #fecaca;
}
.rubric-children-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 18px;
  align-items: start;
}
.rubric-grid-item {
  min-width: 0;
  margin: 0;
  padding: 14px;
  border: 1px solid var(--border);
  border-left: 4px solid #fecaca;
  border-radius: 18px;
  background: #ffffff;
  box-shadow: 0 10px 24px rgba(31, 41, 51, 0.05);
  transition: border-color .15s ease, box-shadow .15s ease, transform .15s ease, background .15s ease;
}
.rubric-grid-item:hover,
.rubric-grid-item:focus-within {
  border-color: #fca5a5;
  border-left-color: var(--primary);
  background: #fffafa;
  box-shadow: 0 14px 30px rgba(185, 28, 28, 0.09);
  transform: translateY(-1px);
}
.rubric-editor-form .tree-row {
  grid-template-columns: minmax(0, 1fr) 92px;
  gap: 8px;
  align-items: start;
  padding: 0;
  background: transparent;
  border: 0;
  border-radius: 0;
}
.rubric-editor-form .tree-row:focus-within .node-name { border-color: var(--primary); }
.rubric-editor-form .node-name,
.rubric-editor-form .node-count {
  min-width: 0;
  overflow-wrap: anywhere;
}
.rubric-editor-form .node-name { font-weight: 850; }
.rubric-editor-form .tree-actions {
  grid-column: 1 / -1;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.rubric-editor-form .tree-children {
  display: grid;
  gap: 10px;
  margin-top: 12px;
}
.rubric-editor-form .rubric-children-grid { display: grid; }
.rubric-editor-form .tree-node:not(.rubric-grid-item) {
  margin: 0;
  padding: 0 0 0 12px;
  border: 0;
  border-left: 2px solid #fee2e2;
}
.rubric-editor-form .tree-node:not(.rubric-grid-item) .tree-row {
  grid-template-columns: minmax(0, 1fr) 78px;
}
.rubric-editor-form .tree-node:not(.rubric-grid-item) .node-name {
  font-weight: 750;
}

@media (max-width: 960px) {
  .rubric-children-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 560px) {
  .rubric-children-grid { grid-template-columns: 1fr; }
  .rubric-grid-item { padding: 12px; border-radius: 16px; }
}

/* Compact professional rubric structure editor. */
.rubric-editor-form { padding: 18px; }
.rubric-editor-form > label { margin-bottom: 12px; }
.rubric-editor-toolbar {
  position: sticky; top: 10px; z-index: 5;
  display: flex; justify-content: space-between; gap: 10px; align-items: center;
  margin: 4px 0 14px; padding: 10px;
  border: 1px solid var(--border); border-radius: 14px;
  background: rgba(255,255,255,.94); backdrop-filter: blur(10px);
  box-shadow: 0 8px 24px rgba(31,41,55,.06);
}
.rubric-search { display: flex; gap: 10px; align-items: center; min-width: 260px; flex: 1; }
.rubric-search input { min-height: 34px; padding: 7px 10px; border-radius: 10px; }
#rubric-save-state { font-size: 12px; font-weight: 800; color: #64748b; white-space: nowrap; }
.rubric-toolbar-actions { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
.button-ghost { background: #fff; color: #475569; border-color: #e2e8f0; }
.button-icon { min-height: 28px; min-width: 28px; padding: 3px 7px; border-radius: 9px; font-size: 12px; color: #64748b; background: #fff; border-color: #e2e8f0; }
.rubric-editor-form .inline-form { margin-top: 14px; }
.rubric-editor-form .tree-root > .tree-row { display: none; }
.rubric-children-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; }
.rubric-grid-item { padding: 10px; border-radius: 14px; border-left: 3px solid var(--primary); box-shadow: none; }
.rubric-grid-item:hover, .rubric-grid-item:focus-within { transform: none; box-shadow: 0 8px 20px rgba(185,28,28,.07); }
.rubric-editor-form .tree-row { grid-template-columns: 62px minmax(0, 1fr) 70px auto; gap: 7px; align-items: center; }
.rubric-child-item .tree-row { grid-template-columns: minmax(0, 1fr) 62px auto; }
.node-main { display: flex; gap: 4px; align-items: flex-start; min-width: 0; }
.node-toggle, .node-toggle-spacer { width: 20px; height: 28px; flex: 0 0 20px; border: 0; background: transparent; color: #64748b; cursor: pointer; }
.rubric-editor-form .node-name { min-height: 30px; padding: 6px 8px; border-radius: 9px; font-size: 13px; line-height: 1.25; resize: none; overflow: hidden; font-weight: 800; }
.rubric-editor-form .node-count { min-height: 30px; padding: 6px 7px; border-radius: 9px; font-size: 12px; text-align: right; background: #f8fafc; }
.rubric-editor-form .tree-actions { grid-column: auto; display: flex; gap: 4px; opacity: .3; justify-content: flex-end; }
.rubric-editor-form .tree-row:hover .tree-actions, .rubric-editor-form .tree-row:focus-within .tree-actions { opacity: 1; }
.rubric-editor-form .tree-children { gap: 6px; margin-top: 8px; }
.rubric-editor-form .tree-node:not(.rubric-grid-item) { padding-left: 9px; border-left: 1px solid #fecaca; }
.rubric-editor-form .tree-node:not(.rubric-grid-item) .tree-row { grid-template-columns: minmax(0, 1fr) 58px auto; }
.rubric-match > .tree-row { background: #fff7ed; outline: 2px solid #fed7aa; border-radius: 12px; }
.rubric-empty { padding: 14px; color: #64748b; border: 1px dashed #cbd5e1; border-radius: 14px; background: #f8fafc; }
@media (max-width: 1280px) { .rubric-children-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
@media (max-width: 960px) { .rubric-children-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); } .rubric-editor-toolbar { align-items: stretch; flex-direction: column; } }
@media (max-width: 560px) { .rubric-children-grid { grid-template-columns: 1fr; } .rubric-editor-form .tree-row { grid-template-columns: 54px minmax(0, 1fr) 64px; } .rubric-editor-form .tree-actions { grid-column: 1 / -1; opacity: 1; } }

/* Regression fix: compact, readable rubric editor. Keep this block last to override older grid rules. */
.rubric-editor-form #rubric-editor,
.rubric-editor-form #rubric-editor * {
  box-sizing: border-box;
  word-break: normal;
}
.rubric-editor-form { padding: 18px; }
.rubric-editor-form #rubric-editor { margin-top: 16px; }
.rubric-editor-toolbar {
  position: sticky; top: 10px; z-index: 5;
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  margin: 4px 0 14px; padding: 10px;
  border: 1px solid var(--border); border-radius: 14px;
  background: rgba(255,255,255,.95); box-shadow: 0 8px 24px rgba(31,41,55,.06);
}
.rubric-search { display: flex; align-items: center; gap: 10px; flex: 1 1 320px; min-width: 0; }
.rubric-search input { min-height: 34px; padding: 7px 10px; border-radius: 10px; min-width: 0; }
.rubric-toolbar-actions { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
#rubric-save-state { color: #64748b; font-size: 12px; font-weight: 800; white-space: nowrap; }
.button-ghost { background: #fff; color: #475569; border-color: #e2e8f0; }
.button-icon { min-height: 28px; min-width: 28px; padding: 3px 7px; border-radius: 9px; font-size: 12px; color: #64748b; background: #fff; border-color: #e2e8f0; }
.rubric-editor-form .tree-root { margin-top: 0; gap: 0; }
.rubric-editor-form .tree-root > .tree-row { display: none; }
.rubric-editor-form {
  width: 100%;
  max-width: 100%;
  overflow-x: hidden;
}
.rubric-editor-form .rubric-children-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  column-gap: 12px;
  row-gap: 12px;
  align-items: start;
  width: 100%;
  max-width: 100%;
  min-width: 0;
}
@media (min-width: 1536px) {
  .container { width: 100%; max-width: min(1520px, 100vw); }
}
.rubric-grid-item {
  position: relative;
  min-width: 0; max-width: 100%; margin: 0; padding: 8px 12px 12px 18px;
  border: 1px solid var(--border);
  border-radius: 14px; background: #fff; box-shadow: none;
}
.rubric-grid-item::before {
  content: "";
  position: absolute;
  left: 8px;
  top: 8px;
  bottom: 8px;
  width: 3px;
  border-radius: 999px;
  background: var(--primary);
  pointer-events: none;
}
.rubric-grid-item:hover,
.rubric-grid-item:focus-within { transform: none; background: #fffafa; box-shadow: 0 8px 20px rgba(185,28,28,.07); }
.rubric-editor-form .tree-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(64px, 76px) minmax(0, auto);
  gap: 8px; align-items: center;
  min-width: 0; max-width: 100%; padding: 0; border: 0; border-radius: 0; background: transparent;
}
.rubric-child-item { min-width: 0; margin: 0; padding: 0; border: 0; }
.rubric-child-item .tree-row {
  grid-template-columns: minmax(0, 1fr) minmax(56px, 64px) minmax(0, auto);
  align-items: center;
  gap: 6px;
  padding: 6px 0;
  border-top: 1px solid #f1f5f9;
}
.node-main { display: flex; align-items: flex-start; gap: 4px; min-width: 0; }
.node-title-block { flex: 1 1 auto; min-width: 0; }
.node-meta { margin-top: 2px; color: #64748b; font-size: 11px; font-weight: 800; line-height: 1.2; }
.node-toggle,
.node-toggle-spacer { width: 20px; height: 30px; flex: 0 0 20px; border: 0; background: transparent; color: #64748b; cursor: pointer; }
.rubric-editor-form .node-name {
  flex: 1 1 auto; min-width: 0; width: 100%; min-height: 34px; max-height: 64px;
  padding: 7px 8px; border-radius: 9px; font-size: 16px; line-height: 1.25;
  resize: none; overflow: hidden; white-space: normal; overflow-wrap: anywhere; word-break: normal;
  font-weight: 700;
}
.rubric-child-item .node-name { min-height: 30px; max-height: 60px; font-size: 13px; font-weight: 700; }
.rubric-editor-form .node-count { width: 100%; min-width: 0; min-height: 32px; padding: 7px 8px; border-radius: 9px; font-size: 12px; text-align: right; background: #f8fafc; }
.rubric-editor-form .tree-actions { display: flex; gap: 3px; justify-content: flex-end; flex-wrap: wrap; opacity: .62; min-width: 0; }
.rubric-editor-form .tree-row:hover .tree-actions,
.rubric-editor-form .tree-row:focus-within .tree-actions { opacity: 1; }
.rubric-editor-form .tree-children { display: grid; gap: 0; margin-top: 8px; padding-bottom: 4px; }
.rubric-editor-form .rubric-children-grid { padding-bottom: 0; }
.rubric-match > .tree-row { background: #fff7ed; outline: 2px solid #fed7aa; border-radius: 12px; }
.rubric-empty { padding: 14px; color: #64748b; border: 1px dashed #cbd5e1; border-radius: 14px; background: #f8fafc; }
@media (max-width: 960px) {
  .rubric-editor-form .rubric-children-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .rubric-editor-toolbar { align-items: stretch; flex-direction: column; }
}
@media (max-width: 560px) {
  .rubric-editor-form .rubric-children-grid { grid-template-columns: 1fr; }
  .rubric-editor-form .tree-row { grid-template-columns: minmax(0, 1fr) minmax(56px, 64px); gap: 6px; }
  .rubric-child-item .tree-row { grid-template-columns: minmax(0, 1fr) minmax(56px, 64px); gap: 6px; }
  .rubric-editor-form .tree-actions { grid-column: 1 / -1; opacity: 1; justify-content: flex-end; }
}

/* Rubric action menu: keep category rows compact with a single reusable trigger. */
.rubric-editor-form .tree-row {
  grid-template-columns: minmax(0, 1fr) minmax(70px, 82px) 32px;
}
.rubric-child-item .tree-row,
.rubric-editor-form .tree-node:not(.rubric-grid-item) .tree-row {
  grid-template-columns: minmax(0, 1fr) minmax(58px, 68px) 32px;
}
.rubric-editor-form .tree-actions {
  flex-wrap: nowrap;
  opacity: 1;
  min-width: 32px;
}
.rubric-action-trigger {
  font-size: 18px;
  line-height: 1;
  font-weight: 800;
  letter-spacing: 1px;
}
.rubric-action-trigger[aria-expanded="true"],
.rubric-action-trigger:focus-visible {
  outline: 3px solid rgba(185, 28, 28, 0.16);
  border-color: var(--primary);
  color: var(--primary);
}
.rubric-action-menu {
  position: fixed;
  z-index: 1000;
  min-width: 190px;
  max-width: calc(100vw - 16px);
  padding: 6px;
  border: 1px solid #e2e8f0;
  border-radius: 12px;
  background: #fff;
  box-shadow: 0 18px 40px rgba(15, 23, 42, .16);
}
.rubric-action-menu-list {
  display: grid;
  gap: 2px;
}
.rubric-action-menu-item {
  width: 100%;
  min-height: 34px;
  padding: 8px 10px;
  border: 0;
  border-radius: 9px;
  background: transparent;
  color: #334155;
  font: inherit;
  font-size: 13px;
  font-weight: 700;
  text-align: left;
  cursor: pointer;
}
.rubric-action-menu-item:hover,
.rubric-action-menu-item:focus-visible {
  outline: 0;
  background: #fff1f2;
  color: var(--primary);
}
.rubric-action-menu-item:disabled {
  color: #cbd5e1;
  cursor: not-allowed;
  background: transparent;
}
.rubric-action-menu-item.is-danger {
  color: #b91c1c;
}
@media (max-width: 560px) {
  .rubric-editor-form .tree-row,
  .rubric-child-item .tree-row,
  .rubric-editor-form .tree-node:not(.rubric-grid-item) .tree-row {
    grid-template-columns: minmax(0, 1fr) minmax(56px, 64px) 32px;
  }
  .rubric-editor-form .tree-actions {
    grid-column: auto;
  }
}

.breadcrumbs {
  margin: 0 0 18px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 750;
}
.breadcrumbs-list {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px 0;
  min-width: 0;
  margin: 0;
  padding: 0;
  list-style: none;
}
.breadcrumbs-item {
  display: inline-flex;
  align-items: center;
  min-width: 0;
  max-width: min(100%, 34rem);
}
.breadcrumbs-item:not(:last-child)::after {
  content: "›";
  margin: 0 8px;
  color: #9ca3af;
  font-weight: 800;
}
.breadcrumbs-link,
.breadcrumbs-current {
  min-width: 0;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.breadcrumbs-link {
  color: var(--muted);
  text-decoration: none;
  transition: color .15s ease, background .15s ease;
}
.breadcrumbs-link:hover { color: var(--primary); }
.breadcrumbs-current { color: var(--text); font-weight: 900; }

@media (max-width: 560px) {
  .breadcrumbs { margin-bottom: 14px; font-size: 12px; }
  .breadcrumbs-item { max-width: 100%; }
  .breadcrumbs-link,
  .breadcrumbs-current {
    white-space: normal;
    overflow-wrap: anywhere;
  }
}

.task-status-card { margin: 0 0 18px; padding: 16px 18px; background: #fff; border: 1px solid #fecaca; border-left: 5px solid var(--primary); border-radius: 18px; box-shadow: var(--shadow-soft); }
.task-status-head { display: flex; justify-content: space-between; gap: 16px; align-items: flex-start; }
.task-status-head h3 { margin: 2px 0 0; font-size: 18px; }
.task-status-head strong { color: var(--primary); font-size: 18px; }
.task-progress { height: 10px; margin: 12px 0 8px; overflow: hidden; background: #fee2e2; border-radius: 999px; }
.task-progress span { display: block; height: 100%; width: 0; background: linear-gradient(90deg, var(--primary), #ef4444); border-radius: inherit; transition: width .35s ease; }
.task-status-card p { margin: 0; color: var(--muted); font-weight: 750; }
.task-status-card.is-success { border-color: #bbf7d0; border-left-color: #16a34a; background: #f0fdf4; }
.task-status-card.is-success .task-progress { background: #dcfce7; }
.task-status-card.is-success .task-progress span { background: #16a34a; }
.task-status-card.is-success strong { color: #166534; }
.task-status-card.is-error { border-color: #fecaca; border-left-color: var(--primary); background: #fff7f7; }
.task-error { margin-top: 10px; padding: 10px 12px; background: var(--error-bg); color: var(--error-text); border-radius: 12px; font-weight: 700; }
button:disabled, .button:disabled { opacity: .55; cursor: not-allowed; }
.filter-pills { display: flex; gap: 8px; flex-wrap: wrap; }
.badge.is-active, .status-done { background: #fee2e2; color: #991b1b; border-color: #fecaca; }
.status-error { background: #fef2f2; color: #b91c1c; border-color: #fecaca; }
.status-running, .status-pending { background: #fff7ed; color: #9a3412; border-color: #fed7aa; }
.stats-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; margin: 12px 0 20px; }
.stats-grid > div { background: #fff7f7; border: 1px solid #fecaca; border-radius: 16px; padding: 16px; }
.stats-grid strong { display: block; color: var(--primary); font-size: 28px; line-height: 1; }
.stats-grid span { color: #64748b; font-weight: 700; }
@media (max-width: 720px) { .stats-grid { grid-template-columns: 1fr; } }
.analysis-modes-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; align-items: stretch; }
.analysis-mode-card { border: 1px solid var(--border); border-radius: 18px; padding: 18px; background: linear-gradient(180deg,#fff 0%,#fffafa 100%); }
.analysis-mode-card h3 { margin: 0 0 8px; font-size: 18px; }
.mode-fields-grid { display: grid; grid-template-columns: 1fr; gap: 12px; margin-top: 14px; }
.mode-fields-grid label { font-size: 13px; }
@media (max-width: 1040px) { .analysis-modes-grid { grid-template-columns: 1fr; } }

/* Compact header for saved rubric analysis history. */
.rubric-analyses-hero {
  padding: 30px 32px;
  margin-bottom: 24px;
}
.rubric-analyses-heading .eyebrow { margin-bottom: 10px; }
.rubric-analyses-heading h1 { margin-bottom: 14px; }
.rubric-analyses-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 18px;
  margin: 0;
}
.rubric-analyses-meta span + span::before {
  content: "·";
  margin-right: 18px;
  color: #9ca3af;
}
.rubric-analyses-action-block {
  display: grid;
  gap: 10px;
  margin-top: 22px;
}
.rubric-analyses-mode { margin: 0; }
.rubric-analyses-actions {
  gap: 18px;
  align-items: center;
}
.rubric-analyses-actions form { margin: 0; }
.rubric-analyses-actions .button { white-space: nowrap; }
.analysis-current-status {
  display: inline-flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px 10px;
  max-width: 100%;
  margin-top: 18px;
  padding: 10px 14px;
  border: 1px solid #fecaca;
  border-radius: 14px;
  background: rgba(255, 255, 255, .78);
  color: var(--muted);
  line-height: 1.35;
}
.analysis-current-status strong { color: var(--text); }
.analysis-current-status .badge { flex: 0 0 auto; }
.analysis-current-status .muted { line-height: 1.35; }

@media (max-width: 560px) {
  .rubric-analyses-hero { padding: 22px; }
  .rubric-analyses-meta { display: grid; gap: 6px; }
  .rubric-analyses-meta span + span::before { content: none; margin: 0; }
  .rubric-analyses-actions { gap: 10px; }
  .analysis-current-status { display: flex; width: 100%; }
}

.status-pending { color: var(--muted); }
.status-processing { color: #b45309; }
.status-badge.status-success { background: var(--success-bg); color: var(--success-text); }
.status-badge.status-failed { background: var(--error-bg); color: var(--error-text); }
.status-badge.status-processing { background: #fffbeb; color: #b45309; }
.disabled-link { pointer-events: none; opacity: .55; }
.useful-feed-status-row > td { padding-top: 0; border-top: 0; }
.useful-feed-status { margin: 10px 0 14px; box-shadow: none; }
.task-progress span.is-indeterminate { width: 55%; animation: useful-feed-progress 1.25s ease-in-out infinite alternate; }
.task-error { margin-top: 10px; color: var(--error-text); font-weight: 800; }
.task-error details { margin-top: 8px; font-weight: 700; }
.task-error pre { white-space: pre-wrap; word-break: break-word; margin: 8px 0 0; font-weight: 600; }
@keyframes useful-feed-progress { from { transform: translateX(-22%); } to { transform: translateX(88%); } }

.feed-status-panel dl,.node-feed dl{display:grid;grid-template-columns:max-content minmax(0,1fr);gap:6px 12px;margin:12px 0 0}.feed-status-panel dt,.node-feed dt{color:#64748b;font-size:12px;font-weight:800}.feed-status-panel dd,.node-feed dd{margin:0;min-width:0;overflow-wrap:anywhere}.rubric-editor-form .rubric-children-grid{grid-template-columns:repeat(2,minmax(0,1fr));gap:16px}.rubric-editor-form .tree-row{grid-template-columns:minmax(0,1fr) 82px auto;align-items:start}.rubric-child-item .tree-row{grid-template-columns:minmax(0,1fr) 76px auto}.node-feed{grid-column:1/-1;margin-top:8px;padding:10px;border:1px solid #fee2e2;border-radius:12px;background:#fffafa}.node-feed strong{display:block;margin-bottom:6px;color:#991b1b}.feed-empty{color:#94a3b8;font-weight:750}.entity-tags{display:flex;gap:6px;flex-wrap:wrap}.entity-tag,.entity-more{display:inline-flex;padding:3px 8px;border-radius:999px;background:#fee2e2;color:#991b1b;font-size:12px;font-weight:800}@media(max-width:1100px){.rubric-editor-form .rubric-children-grid{grid-template-columns:1fr}}

.rubric-feed-refresh-action{align-items:center;gap:10px}.rubric-feed-refresh-action form{margin:0}.small-note{font-size:12px;font-weight:700}
.checkbox-label { display: inline-flex; grid-auto-flow: column; align-items: center; gap: 8px; min-height: 46px; }
.checkbox-label input { width: auto; min-height: auto; }

.status-warning { color: #92400e; }

.status-panel { margin-top: 16px; padding: 14px 16px; border: 1px solid var(--border); border-radius: 14px; background: #f8fafc; color: var(--muted); font-weight: 750; }
.status-panel strong { color: #334155; }
.status-panel.status-success { background: var(--success-bg); color: var(--success-text); border-color: #bbf7d0; }
.status-panel.status-error { background: var(--error-bg); color: var(--error-text); border-color: #fecaca; }
.status-panel.status-idle { background: #f8fafc; color: var(--muted); }

body.modal-open { overflow: hidden; }
.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 2000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: rgba(15, 23, 42, .48);
  backdrop-filter: blur(2px);
}
.modal-card {
  width: min(100%, 640px);
  max-height: calc(100vh - 48px);
  overflow-y: auto;
  padding: 24px;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 18px;
  box-shadow: 0 24px 80px rgba(15, 23, 42, .28);
}
.modal-card h3 { margin: 0 0 12px; }
.modal-card p { margin: 0 0 20px; line-height: 1.5; }
.modal-card .row-actions { justify-content: flex-end; }
.details-list { display: grid; grid-template-columns: minmax(180px, 1fr) 2fr; gap: 8px 16px; margin: 16px 0; }
.details-list dt { color: #64748b; }
.details-list dd { margin: 0; font-weight: 600; }

.task-status-actions { display: flex; align-items: center; gap: 10px; }
.task-status-card.is-warning { border-color: #f59e0b; background: #fffbeb; }

@media (max-width: 560px) {
  .modal-backdrop { padding: 16px; }
  .modal-card { max-height: calc(100vh - 32px); padding: 20px; }
  .modal-card .row-actions { flex-direction: column; align-items: stretch; }
  .modal-card .row-actions .button { width: 100%; }
}

/* Application-wide compact density overrides. Keep these centralized so pages do
   not need their own scale fixes and overlays retain their native positioning. */
.app-sidebar { flex-basis: 264px; width: 264px; }
.sidebar-header { padding: var(--space-4); }
.sidebar-header p { margin-top: var(--space-2); font-size: var(--font-small); }
.sidebar-nav { padding: var(--space-3) var(--space-2); }
.sidebar-group-label { padding: 0 var(--space-2) var(--space-1); }
.sidebar-admin-label { margin-top: var(--space-4); padding-top: var(--space-3); }
.sidebar-link {
  gap: var(--space-2); min-height: var(--control-height); margin: 1px 0;
  padding: var(--space-2) 10px; border-radius: var(--radius-control);
  font-size: var(--font-control);
}
.sidebar-footer { padding: var(--space-3) var(--space-2); }
.workspace-content {
  max-width: var(--content-max-width);
  padding: var(--space-6) var(--space-6) 40px;
}
.topbar { min-height: 64px; gap: var(--space-4); padding: 10px var(--space-6); }
.brand-logo { height: 36px; }
.topnav { gap: var(--space-1); font-size: var(--font-control); }
.topnav a { padding: 7px 10px; }
.container { max-width: 1280px; padding: var(--space-6) var(--space-4) 40px; }

.auth-card, .card, .menu-card, .stat-card { border-radius: var(--radius-card); }
.auth-card, .card, .menu-card { padding: var(--space-4); }
.card { margin-bottom: var(--space-4); }
.menu-grid { gap: var(--space-4); }
.menu-card { min-height: 210px; }
.page-header { margin-bottom: var(--space-4); }
.page-header-accent { padding: var(--space-4); border-radius: var(--radius-card); }
h1 { font-size: var(--font-page-title); line-height: 1.12; }
h2 { font-size: var(--font-card-title); }
h1, h2 { margin-bottom: var(--space-2); }
h3, .task-status-head h3, .analysis-mode-card h3 { font-size: 16px; }
.eyebrow { margin-bottom: var(--space-2); font-size: var(--font-small); }
.small { font-size: var(--font-small); }
.card-description { margin-bottom: var(--space-4); }

.form { gap: var(--space-3); }
.feed-upload-form { margin-top: var(--space-4); }
label { gap: 6px; }
input, select, textarea {
  min-height: var(--control-height); padding: 7px 10px;
  border-radius: var(--radius-control); font-size: var(--font-control);
}
.button {
  min-height: var(--control-height); padding: 7px var(--space-3);
  border-radius: var(--radius-control); font-size: var(--font-control);
}
.button-small, .button-icon { min-height: var(--control-height-small); }
.checkbox-label { min-height: var(--control-height); }
.inline-form { gap: var(--space-2); margin-top: var(--space-3); padding-top: var(--space-3); }
.inline-actions, .row-actions { gap: var(--space-2); }

.card-topline, .section-title-row { gap: var(--space-3); margin-bottom: var(--space-3); }
.module-icon { width: var(--icon-size); height: var(--icon-size); border-radius: var(--radius-control); }
.badge { min-height: 24px; padding: 3px var(--space-2); font-size: var(--font-small); }
.stats-grid { gap: var(--space-3); margin-bottom: var(--space-4); }
.stat-card, .stats-grid > div { padding: var(--space-3); }
.stat-value, .stats-grid strong { font-size: 28px; }
.stat-date { font-size: 17px; }
.analysis-modes-grid { gap: var(--space-3); }
.analysis-mode-card { padding: var(--space-3); border-radius: var(--radius-card); }
.mode-fields-grid { gap: var(--space-2); margin-top: var(--space-3); }

.table-wrap { border-radius: var(--radius-card); }
table { font-size: 13px; }
th, td { padding: var(--table-cell-block) var(--table-cell-inline); }
th { font-size: var(--font-small); }
.breadcrumbs { margin-bottom: var(--space-3); font-size: var(--font-small); }
.alert, .report-info-row, .status-panel { padding: 10px var(--space-3); margin-bottom: var(--space-3); border-radius: var(--radius-control); }
.task-status-card { margin-bottom: var(--space-3); padding: var(--space-3); border-radius: var(--radius-card); }
.task-status-head h3, .task-status-head strong { font-size: 16px; }
.task-progress { height: 8px; margin: var(--space-2) 0 6px; }
.rubric-analyses-hero { padding: var(--space-4); margin-bottom: var(--space-4); }
.rubric-analyses-action-block { gap: var(--space-2); margin-top: var(--space-4); }

.modal-backdrop { padding: var(--space-4); }
.modal-card {
  max-height: calc(100vh - 32px); padding: var(--space-4);
  border-radius: var(--radius-card); font-size: var(--font-body);
}
.modal-card p { margin-bottom: var(--space-4); }
.details-list { gap: var(--space-2) var(--space-3); margin: var(--space-3) 0; }

@media (max-width: 960px) {
  .workspace-content { padding: var(--space-4) var(--space-4) var(--space-6); }
  .mobile-appbar { min-height: 56px; padding: var(--space-2) var(--space-3); }
  .sidebar-toggle { width: 40px; height: 40px; flex-basis: 40px; }
}
@media (max-width: 560px) {
  .workspace-content { padding: var(--space-4) var(--space-3) var(--space-6); }
  .auth-card, .card, .menu-card, .page-header-accent { padding: var(--space-4); border-radius: var(--radius-card); }
  .modal-backdrop { padding: var(--space-2); }
  .modal-card { max-height: calc(100vh - 16px); padding: var(--space-3); }
}
