:root {
  --bg: #eef1f5;
  --bg-subtle: #e4e9ef;
  --surface: #ffffff;
  --primary: #1a3a5c;
  --primary-dark: #0f2438;
  --primary-light: #2d5a87;
  --accent: #b8922a;
  --accent-muted: #4a6fa5;
  --border: #c5ced8;
  --border-strong: #8fa3b8;
  --ink: #1a2836;
  --ink-muted: #5a6b7d;
  --success: #2d6a4f;
  --warn: #9a7b2e;
  --error: #a63d3d;
  --shadow: 0 1px 3px rgba(15, 36, 56, 0.08), 0 4px 12px rgba(15, 36, 56, 0.06);
  --shadow-hover: 0 4px 16px rgba(15, 36, 56, 0.12);
  --radius: 4px;
  --radius-sm: 3px;
}

html {
  width: 100%;
  max-width: 100%;
}

body {
  width: 100%;
  max-width: 100%;
  margin: 0;
  background-color: var(--bg);
  background-image:
    linear-gradient(180deg, rgba(26, 58, 92, 0.03) 0%, transparent 120px);
  color: var(--ink);
  font-family: 'Source Sans 3', 'Segoe UI', system-ui, sans-serif;
  min-height: 100vh;
  font-size: 1rem;
  line-height: 1.5;
}

.app-wrap {
  width: 100%;
  max-width: 1140px;
  margin-left: auto;
  margin-right: auto;
  padding-left: 1rem;
  padding-right: 1rem;
}

/* Neutralize neobrutalism utility classes still in markup */
.border-dark {
  border-color: var(--border) !important;
}

.border-3 {
  border-width: 1px !important;
}

.shadow,
.shadow-sm {
  box-shadow: var(--shadow) !important;
}

.card,
.table,
.form-control,
.form-select,
.btn,
.alert,
.badge,
.pagination .page-link {
  border-radius: var(--radius) !important;
}

.card {
  background: var(--surface);
  border-color: var(--border) !important;
}

.btn-dark {
  background-color: var(--primary) !important;
  border-color: var(--primary) !important;
  color: #fff !important;
  font-weight: 600;
  letter-spacing: 0.02em;
}

.btn-dark:hover,
.btn-dark:focus,
.btn-dark:active {
  background-color: var(--primary-dark) !important;
  border-color: var(--primary-dark) !important;
  color: #fff !important;
}

.btn-outline-dark {
  color: var(--primary) !important;
  border-color: var(--border-strong) !important;
  background-color: var(--surface) !important;
  font-weight: 600;
}

.btn-outline-dark:hover,
.btn-outline-dark:focus,
.btn-outline-dark:active {
  color: #fff !important;
  background-color: var(--primary) !important;
  border-color: var(--primary) !important;
}

.btn-warning {
  background-color: var(--accent) !important;
  border-color: #9a7b22 !important;
  color: var(--primary-dark) !important;
  font-weight: 600;
}

.form-control,
.form-select {
  border-color: var(--border) !important;
  background: var(--surface);
}

.form-control:focus,
.form-select:focus {
  border-color: var(--primary-light) !important;
  box-shadow: 0 0 0 3px rgba(26, 58, 92, 0.15) !important;
}

.navbar-usrd {
  position: sticky;
  top: 0;
  z-index: 1030;
  background: var(--primary-dark) !important;
  border-bottom: 3px solid var(--accent) !important;
  padding-top: 0.65rem;
  padding-bottom: 0.65rem;
}

.navbar-usrd > .app-wrap {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  width: 100%;
}

.navbar-usrd .navbar-brand {
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  font-size: 1.05rem;
  color: #fff !important;
}

.navbar-usrd .navbar-brand:hover {
  color: var(--accent) !important;
}

.navbar-usrd .navbar-toggler {
  border: 1px solid rgba(255, 255, 255, 0.35) !important;
  border-radius: var(--radius-sm) !important;
  padding: 0.4rem 0.55rem;
  box-shadow: none !important;
}

.navbar-usrd .navbar-toggler:focus {
  box-shadow: 0 0 0 3px rgba(184, 146, 42, 0.35) !important;
}

.navbar-usrd .navbar-toggler-icon {
  filter: invert(1);
}

.site-nav-links .nav-link {
  font-weight: 600;
  font-size: 0.875rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: rgba(255, 255, 255, 0.85) !important;
  border: 1px solid transparent !important;
  border-radius: var(--radius-sm) !important;
  padding: 0.45rem 0.85rem !important;
  margin: 0 0.15rem;
}

.site-nav-links .nav-link:hover {
  color: #fff !important;
  background: rgba(255, 255, 255, 0.08) !important;
}

.site-nav-links .nav-link.active {
  background: rgba(184, 146, 42, 0.2) !important;
  color: #fff !important;
  border-color: var(--accent) !important;
}

@media (min-width: 992px) {
  .site-nav-links {
    flex-direction: row;
    align-items: center;
    gap: 0.25rem;
  }

  .site-nav-links .nav-item {
    margin: 0;
  }
}

@media (max-width: 991.98px) {
  .app-wrap {
    max-width: 100%;
  }

  .navbar-usrd > .app-wrap {
    flex-wrap: wrap;
  }

  .navbar-usrd .navbar-collapse {
    flex-basis: 100%;
    margin-top: 0.75rem;
    padding-top: 0.75rem;
    border-top: 1px solid rgba(255, 255, 255, 0.15) !important;
  }

  .site-nav-links {
    width: 100%;
    gap: 0.35rem;
    padding-bottom: 0.25rem;
  }

  .site-nav-links .nav-item {
    width: 100%;
  }

  .site-nav-links .nav-link {
    width: 100%;
    text-align: center;
    margin: 0 !important;
  }

  .page-header h1 {
    font-size: clamp(1.5rem, 6vw, 2rem);
  }

  .input-group {
    flex-wrap: wrap;
  }

  .input-group > .form-control {
    width: 100%;
    min-width: 0;
  }

  .input-group > .btn {
    width: 100%;
    margin-top: 0.5rem;
  }

  .match-score {
    font-size: 2rem;
  }
}

.stat-card {
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  background: var(--surface);
  padding: 1.25rem 1.35rem;
  border-top: 3px solid var(--primary);
}

.stat-card .stat-value {
  font-size: 2rem;
  font-weight: 700;
  line-height: 1;
  color: var(--primary);
}

.stat-card .stat-label {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-weight: 600;
  color: var(--ink-muted);
  margin-top: 0.35rem;
}

.grant-card {
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  background: var(--surface);
  transition: box-shadow 0.2s ease, border-color 0.2s ease;
}

.grant-card:hover {
  transform: none;
  box-shadow: var(--shadow-hover);
  border-color: var(--border-strong);
}

.dashboard-excerpt-list {
  display: flex;
  flex-direction: column;
  gap: 0;
}

.dashboard-excerpt-item {
  padding: 0.85rem 0;
  border-bottom: 1px solid var(--border);
}

.dashboard-excerpt-item:last-child {
  border-bottom: none;
  padding-bottom: 0;
}

.dashboard-excerpt-item:first-child {
  padding-top: 0;
}

.dashboard-excerpt-title {
  display: block;
  font-weight: 700;
  color: var(--ink);
  text-decoration: none;
  line-height: 1.3;
}

.dashboard-excerpt-title:hover {
  color: var(--primary);
}

.dashboard-excerpt-meta {
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--ink-muted);
  margin-top: 0.2rem;
}

.dashboard-excerpt-text {
  font-size: 0.88rem;
  color: var(--ink-muted);
  margin-top: 0.35rem;
}

.dashboard-excerpt-tags {
  margin-top: 0.45rem;
}

.dashboard-excerpt-tags .tag-chip {
  margin-left: 0;
  margin-right: 0.25rem;
}

.tag-chip {
  display: inline-block;
  border: 1px solid var(--border);
  padding: 0.2rem 0.55rem;
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  margin: 0.15rem;
  background: var(--bg-subtle);
  color: var(--primary);
  border-radius: var(--radius-sm);
}

.tag-chip.defense {
  background: #e8edf2;
  border-color: var(--primary-light);
  color: var(--primary-dark);
}

.tag-chip.cyber {
  background: #e8ecf4;
  border-color: #5a6fa5;
  color: #2a3d66;
}

.tag-chip.energy {
  background: #e8f0ec;
  border-color: #4a7c62;
  color: #1e4a32;
}

.deliverable-preview {
  font-family: 'IBM Plex Mono', 'Courier New', monospace;
  background: var(--surface);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  padding: 1.5rem;
  white-space: pre-wrap;
  font-size: 0.875rem;
  max-height: 500px;
  overflow-y: auto;
}

.deliverable-preview-html {
  background: var(--surface);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  padding: 1.5rem 1.75rem;
  max-height: 70vh;
  overflow-y: auto;
  line-height: 1.65;
}

.deliverable-preview-html h1,
.deliverable-preview-html h2,
.deliverable-preview-html h3 {
  font-weight: 700;
  color: var(--primary);
  margin-top: 1.25rem;
  margin-bottom: 0.75rem;
}

.deliverable-preview-html h1:first-child,
.deliverable-preview-html h2:first-child,
.deliverable-preview-html h3:first-child {
  margin-top: 0;
}

.deliverable-preview-html p,
.deliverable-preview-html li {
  margin-bottom: 0.65rem;
}

.deliverable-preview-html ul,
.deliverable-preview-html ol {
  padding-left: 1.25rem;
}

.deliverable-preview-html code {
  font-family: 'IBM Plex Mono', 'Courier New', monospace;
  background: var(--bg-subtle);
  padding: 0.1rem 0.35rem;
  border-radius: 2px;
  font-size: 0.9em;
}

.deliverable-preview-html pre {
  background: var(--bg-subtle);
  padding: 1rem;
  overflow-x: auto;
  border-radius: var(--radius-sm);
}

.deliverable-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
}

.deliverable-tab {
  border: 1px solid var(--border);
  background: var(--surface);
  padding: 0.4rem 0.75rem;
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.03em;
  cursor: pointer;
  border-radius: var(--radius-sm);
  color: var(--ink-muted);
}

.deliverable-tab.active {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}

.deliverable-list-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 0.5rem 0;
  border-bottom: 1px solid var(--border);
}

.deliverable-list-item:last-child {
  border-bottom: 0;
}

.deliverable-list-item.active .deliverable-list-btn {
  color: var(--primary);
}

.deliverable-list-btn,
.deliverable-list-link {
  border: 0;
  background: transparent;
  padding: 0;
  font-weight: 600;
  text-align: left;
  flex: 1;
  cursor: pointer;
  color: var(--ink);
  text-decoration: none;
  display: block;
}

.deliverable-list-link:hover {
  color: var(--primary);
}

.deliverable-list-item.active .deliverable-list-link {
  color: var(--primary);
}

.deliverable-fullview-body {
  max-height: none;
  overflow: visible;
}

.deliverable-view-sidebar .deliverable-list {
  max-height: calc(100vh - 22rem);
  overflow-y: auto;
}

.deliverable-list-actions {
  display: flex;
  gap: 0.65rem;
  flex-shrink: 0;
}

.deliverable-list-actions a {
  color: var(--primary-light);
  text-decoration: none;
  font-size: 0.85rem;
  font-weight: 600;
}

.deliverable-list-actions a:hover {
  text-decoration: underline;
  color: var(--primary);
}

.folder-tab {
  display: inline-block;
  border: 1px solid var(--border);
  border-bottom: none;
  padding: 0.5rem 1.1rem;
  font-weight: 600;
  background: var(--bg-subtle);
  margin-right: -1px;
  text-transform: uppercase;
  font-size: 0.75rem;
  letter-spacing: 0.05em;
  color: var(--primary);
  border-radius: var(--radius-sm) var(--radius-sm) 0 0;
}

.upload-zone {
  border: 2px dashed var(--border-strong);
  background: var(--surface);
  padding: 2rem;
  text-align: center;
  cursor: pointer;
  border-radius: var(--radius);
  color: var(--ink-muted);
}

.upload-zone:hover {
  background: var(--bg);
  border-color: var(--primary-light);
  color: var(--primary);
}

.document-link-form {
  border-top: 1px solid var(--border);
  padding-top: 1rem;
}

.document-link {
  color: var(--primary);
  text-decoration: none;
}

.document-link:hover {
  text-decoration: underline;
}

.deliverable-editor {
  font-family: 'IBM Plex Mono', 'Courier New', monospace;
  font-size: 0.875rem;
  line-height: 1.55;
  min-height: 12rem;
  resize: vertical;
}

.deliverable-editor-wrap-compact .deliverable-editor {
  max-height: min(52vh, 560px);
}

.deliverable-editor-preview {
  max-height: none;
  overflow: visible;
}

.deliverable-editor-wrap-compact .deliverable-editor-preview {
  max-height: min(52vh, 560px);
  overflow-y: auto;
}

.ai-edit-trigger {
  position: fixed;
  z-index: 1080;
  border: 1px solid var(--primary);
  background: var(--primary);
  color: #fff;
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  padding: 0.35rem 0.65rem;
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-hover);
  cursor: pointer;
}

.ai-edit-trigger:disabled {
  opacity: 0.65;
  cursor: not-allowed;
}

.ai-edit-popover {
  position: fixed;
  z-index: 1081;
  width: min(340px, calc(100vw - 1.5rem));
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  box-shadow: var(--shadow-hover);
  padding: 0.75rem;
}

.ai-edit-selection-preview {
  background: var(--bg-subtle);
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  border-radius: var(--radius-sm);
  padding: 0.45rem 0.55rem;
  color: var(--ink-muted);
  max-height: 4.5rem;
  overflow-y: auto;
  white-space: pre-wrap;
  word-break: break-word;
}

textarea.ai-edit-highlight {
  box-shadow: inset 0 0 0 2px rgba(184, 146, 42, 0.45);
}

.ai-editable-wrap {
  position: relative;
  display: block;
}

.ai-edit-backdrop {
  display: none;
  position: absolute;
  inset: 0;
  overflow: hidden;
  pointer-events: none;
  z-index: 3;
  border-radius: inherit;
}

.ai-editable-wrap.is-highlighting .ai-edit-backdrop {
  display: block;
}

.ai-editable-wrap.is-highlighting textarea.ai-editable {
  position: relative;
  z-index: 2;
}

.ai-edit-backdrop-inner {
  position: relative;
  min-height: 100%;
  pointer-events: none;
}

.ai-edit-highlight-box {
  position: absolute;
  background: rgba(255, 193, 7, 0.55);
  border-radius: 2px;
  pointer-events: none;
}

.ai-editable-wrap.is-highlighting textarea.ai-editable::selection {
  background: transparent;
  color: inherit;
}

textarea.ai-edit-highlight::selection {
  background: rgba(255, 193, 7, 0.45);
  color: inherit;
}

.ai-editable::selection {
  background: rgba(26, 58, 92, 0.18);
}

.match-score {
  font-size: 2.25rem;
  font-weight: 700;
  line-height: 1;
  color: var(--primary);
}

.match-explainer li {
  margin-bottom: 0.35rem;
  color: var(--ink-muted);
}

.match-progress {
  border: 1px solid var(--border);
  background: var(--surface);
  padding: 1rem 1.15rem;
  box-shadow: var(--shadow);
  border-left: 3px solid var(--primary);
  border-radius: var(--radius);
}

.match-progress-title {
  font-weight: 700;
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 0.75rem;
  color: var(--primary);
}

.match-step {
  display: flex;
  gap: 0.65rem;
  align-items: flex-start;
  padding: 0.45rem 0;
  border-bottom: 1px solid var(--border);
  font-size: 0.9rem;
}

.match-step:last-child {
  border-bottom: 0;
  padding-bottom: 0;
}

.match-step-icon {
  flex-shrink: 0;
  width: 1.25rem;
  font-weight: 700;
  line-height: 1.35;
  color: var(--ink-muted);
}

.match-step-body {
  flex: 1;
  min-width: 0;
}

.match-step-label {
  font-weight: 600;
}

.match-step-detail {
  font-size: 0.8rem;
  color: var(--ink-muted);
  margin-top: 0.15rem;
  line-height: 1.4;
}

.match-step.is-active .match-step-label {
  color: var(--primary);
}

.match-step.is-active .match-step-icon {
  color: var(--accent);
}

.match-step.is-done .match-step-label {
  color: var(--success);
}

.match-step.is-error .match-step-label {
  color: var(--error);
}

.match-tag-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem;
  margin-top: 0.35rem;
}

.match-tag-row .tag-chip {
  margin: 0;
  font-size: 0.65rem;
  padding: 0.1rem 0.4rem;
}

.match-session-list {
  margin-bottom: 0;
}

.match-session-item {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.4rem 0;
  border-bottom: 1px solid var(--border);
}

.match-session-item:last-child {
  border-bottom: 0;
}

.match-session-delete {
  margin-left: auto;
  flex-shrink: 0;
  line-height: 1;
  padding: 0.1rem 0.45rem;
  font-size: 1.1rem;
}

.document-list-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
}

.document-delete {
  flex-shrink: 0;
  line-height: 1;
  padding: 0.1rem 0.45rem;
  font-size: 1.1rem;
}

.gap-chip {
  border: 1px solid #d4b84a;
  background: #faf6e8;
  color: #6b5a1e;
  padding: 0.2rem 0.6rem;
  font-size: 0.78rem;
  font-weight: 600;
  display: inline-block;
  margin: 0.2rem;
  border-radius: var(--radius-sm);
}

.wizard-step {
  border: 1px solid var(--border);
  padding: 0.65rem 1rem;
  font-weight: 600;
  font-size: 0.85rem;
  letter-spacing: 0.03em;
  background: var(--surface);
  color: var(--ink-muted);
  border-radius: var(--radius-sm);
}

.wizard-step.active {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}

.wizard-step.done {
  background: #e8f0e8;
  color: var(--success);
  border-color: #a8c9a8;
}

.application-questions-card {
  padding: 1.5rem !important;
}

.application-question {
  margin-bottom: 2rem;
  padding-bottom: 2rem;
  border-bottom: 1px solid var(--border);
}

.application-question:last-of-type {
  border-bottom: 0;
  margin-bottom: 1.5rem;
  padding-bottom: 0;
}

.application-question-label {
  display: block;
  margin-bottom: 0.85rem;
  line-height: 1.5;
}

.application-answer {
  min-height: 8rem;
  line-height: 1.55;
  resize: vertical;
}

.application-sidebar {
  position: sticky;
  top: 5.5rem;
  align-self: flex-start;
  max-height: calc(100vh - 6.5rem);
  overflow-y: auto;
}

.application-deliverables-card .deliverable-list {
  max-height: 11rem;
  overflow-y: auto;
}

#deliverables {
  scroll-margin-top: 5.5rem;
}

.application-preview-panel {
  border-top: 1px solid var(--border);
  padding-top: 1rem;
  margin-top: 0.25rem;
}

.application-preview-body {
  max-height: min(52vh, 560px);
}

.letter-spacing-wide {
  letter-spacing: 0.08em;
}

.application-actions-card .btn {
  width: 100%;
}

.application-actions-card .btn + .btn {
  margin-top: 0.75rem;
}

@media (max-width: 1199.98px) {
  .application-sidebar {
    position: static;
    max-height: none;
    overflow: visible;
  }

  .application-preview-body {
    max-height: min(65vh, 640px);
  }
}

.sync-status-ok { color: var(--success); font-weight: 600; }
.sync-status-warn { color: var(--warn); font-weight: 600; }
.sync-status-error { color: var(--error); font-weight: 600; }

.page-header {
  border-bottom: 1px solid var(--border);
  padding-bottom: 1rem;
  margin-bottom: 1.5rem;
}

.page-header h1 {
  font-weight: 700;
  margin: 0;
  color: var(--primary-dark);
  letter-spacing: -0.01em;
}

.page-header p {
  color: var(--ink-muted);
}

.grant-summary,
.grant-prose {
  line-height: 1.65;
  max-width: 100%;
  overflow-wrap: break-word;
  word-wrap: break-word;
  word-break: break-word;
  hyphens: auto;
}

.grant-summary p {
  margin-bottom: 1rem;
}

.grant-summary p:last-child {
  margin-bottom: 0;
}

a.text-dark {
  color: var(--primary-dark) !important;
}

a.text-dark:hover {
  color: var(--primary-light) !important;
}

.accordion-item {
  border-color: var(--border) !important;
}

.accordion-button {
  font-weight: 600;
  color: var(--primary-dark);
}

.accordion-button:not(.collapsed) {
  background: var(--bg-subtle);
  color: var(--primary);
}

.alert-warning {
  background: #faf6e8 !important;
  border-color: #d4b84a !important;
  color: #5c4d1a !important;
}

.table-bordered {
  border-color: var(--border) !important;
}

.table-bordered td,
.table-bordered th {
  border-color: var(--border) !important;
}

.badge.bg-danger {
  background-color: #8b3a3a !important;
}

.badge.bg-warning {
  background-color: var(--accent) !important;
  color: var(--primary-dark) !important;
}

.client-application-card .client-answer-preview {
  border-left: 3px solid var(--primary-light);
  padding-left: 0.85rem;
}

.client-deliverable-links a {
  font-weight: 600;
  color: var(--primary-light);
}

.client-deliverable-links a:hover {
  color: var(--primary);
}
