* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

:root {
  --sidebar-bg: #0f172a;
  --sidebar-text: #94a3b8;
  --sidebar-hover: #1e293b;
  --accent: #208d44;
  --accent-dark: #055934;
  --accent-soft: #86c242;
  --main-bg: #f1f5f9;
  --card-bg: #ffffff;
  --border: #e2e8f0;
  --text: #1e293b;
  --text-muted: #64748b;
  --topbar-h: 64px;
  --sidebar-w: 220px;
}

body {
  font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
  background: var(--main-bg);
  min-height: 100vh;
  color: var(--text);
}

.app {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: var(--sidebar-bg);
  color: #e2e8f0;
  display: flex;
  flex-direction: column;
  padding: 20px 0;
  border-right: 1px solid rgba(255, 255, 255, 0.06);
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 4px 20px 22px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  margin-bottom: 18px;
}

.sidebar-brand-mark {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 38px;
  height: 38px;
  padding: 0;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.05em;
  line-height: 1;
  background: var(--accent);
  color: #fff;
  border-radius: 10px;
  flex-shrink: 0;
}

.sidebar-brand-text {
  font-size: 17px;
  font-weight: 600;
  letter-spacing: -0.02em;
  line-height: 1.2;
  color: #f8fafc;
}

.sidebar-nav {
  display: flex;
  flex-direction: column;
  gap: 0;
  padding: 0 12px;
}

.sidebar-nav-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 18px;
}

.sidebar-nav-group:last-child {
  margin-bottom: 0;
}

.sidebar-nav-label {
  display: block;
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: #64748b;
  padding: 0 10px 2px;
}

.sidebar-link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  border-radius: 8px;
  border: 1px solid transparent;
  color: #cbd5e1;
  text-decoration: none;
  font-size: 14px;
  font-weight: 500;
  line-height: 1.35;
  transition:
    background 0.22s ease,
    color 0.22s ease,
    box-shadow 0.22s ease,
    transform 0.22s ease,
    border-color 0.22s ease;
}

.sidebar-link-icon {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 20px;
  height: 20px;
  opacity: 0.88;
  transition: transform 0.22s ease, opacity 0.22s ease, color 0.22s ease;
}

.sidebar-link-icon svg {
  display: block;
}

.sidebar-link-text {
  flex: 1;
  min-width: 0;
  white-space: normal;
}

.sidebar-link:hover:not(.is-active) {
  background: linear-gradient(105deg, rgba(51, 65, 85, 0.65) 0%, rgba(30, 41, 59, 0.95) 100%);
  border-color: rgba(148, 163, 184, 0.28);
  color: #f8fafc;
  transform: translateX(4px);
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.22);
}

.sidebar-link:hover:not(.is-active) .sidebar-link-icon {
  opacity: 1;
  transform: scale(1.06);
}

.sidebar-link.is-active {
  background: linear-gradient(
    105deg,
    rgba(32, 141, 68, 0.28) 0%,
    rgba(15, 23, 42, 0.55) 52%,
    rgba(15, 23, 42, 0.28) 100%
  );
  border-color: rgba(134, 194, 66, 0.4);
  color: #f0fdf4;
  font-weight: 600;
  box-shadow:
    inset 3px 0 0 var(--accent-soft),
    0 0 0 1px rgba(32, 141, 68, 0.2),
    0 4px 22px rgba(32, 141, 68, 0.18);
  transform: none;
}

.sidebar-link.is-active .sidebar-link-icon {
  opacity: 1;
  color: #bbf7d0;
}

.sidebar-link.is-active:hover {
  background: linear-gradient(
    105deg,
    rgba(32, 141, 68, 0.38) 0%,
    rgba(15, 23, 42, 0.65) 52%,
    rgba(15, 23, 42, 0.35) 100%
  );
  border-color: rgba(190, 242, 100, 0.55);
  color: #fff;
  box-shadow:
    inset 3px 0 0 #bef264,
    0 0 0 1px rgba(32, 141, 68, 0.28),
    0 6px 26px rgba(32, 141, 68, 0.22);
}

.sidebar-link.is-active:hover .sidebar-link-icon {
  color: #ecfccb;
}

.sidebar-link:focus-visible {
  outline: 2px solid var(--accent-soft);
  outline-offset: 2px;
}

@media (prefers-reduced-motion: reduce) {
  .sidebar-link {
    transition-duration: 0.01ms;
  }

  .sidebar-link:hover:not(.is-active) {
    transform: none;
  }

  .sidebar-link:hover:not(.is-active) .sidebar-link-icon {
    transform: none;
  }
}

.app-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.topbar {
  height: var(--topbar-h);
  flex-shrink: 0;
  display: flex;
  align-items: center;
  padding: 0 28px;
  background: var(--card-bg);
  border-bottom: 1px solid var(--border);
  box-shadow: 0 1px 0 rgba(15, 23, 42, 0.04);
}

.topbar-titles {
  min-width: 0;
}

.topbar-title {
  font-size: 1.25rem;
  font-weight: 600;
  color: var(--text);
  letter-spacing: -0.02em;
  line-height: 1.25;
}

.topbar-subtitle {
  font-size: 13px;
  color: var(--text-muted);
  margin-top: 4px;
  line-height: 1.4;
  max-width: 52ch;
}

.main {
  flex: 1;
  padding: 24px 28px 40px;
  overflow-x: hidden;
}

.app-footer {
  flex-shrink: 0;
  padding: 14px 28px 18px;
  text-align: center;
  font-size: 13px;
  color: var(--text-muted);
  background: var(--card-bg);
  border-top: 1px solid var(--border);
}

.app-footer p {
  margin: 0;
  line-height: 1.45;
}

.form-view[hidden] {
  display: none !important;
}

.home-view {
  max-width: 720px;
  margin: 0 auto;
}

.home-hero {
  margin-bottom: 28px;
}

.home-kicker {
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--accent-dark);
  margin-bottom: 8px;
}

.home-title {
  font-size: 1.75rem;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -0.02em;
  margin-bottom: 12px;
}

.home-lead {
  font-size: 15px;
  line-height: 1.6;
  color: var(--text-muted);
}

.home-cards {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.home-card {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 18px 20px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--card-bg);
  text-decoration: none;
  color: inherit;
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.04);
  transition: border-color 0.15s, box-shadow 0.15s, background 0.15s;
}

.home-card:hover {
  border-color: var(--accent);
  box-shadow: 0 4px 16px rgba(32, 141, 68, 0.12);
  background: #fafefd;
}

.home-card:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.home-card-icon {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 48px;
  height: 48px;
  border-radius: 10px;
  background: rgba(32, 141, 68, 0.12);
  color: var(--accent-dark);
}

.home-card-body {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.home-card-title {
  font-size: 1.05rem;
  font-weight: 600;
  color: var(--text);
}

.home-card-desc {
  font-size: 14px;
  color: var(--text-muted);
  line-height: 1.45;
}

.home-card-arrow {
  flex-shrink: 0;
  font-size: 1.25rem;
  color: var(--accent);
  font-weight: 600;
}

.home-footnote {
  margin-top: 24px;
  font-size: 13px;
  color: var(--text-muted);
  line-height: 1.45;
}

.form-view .about-form {
  margin-bottom: 20px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--card-bg);
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.04);
}

.form-view .about-form > summary {
  list-style: none;
  cursor: pointer;
  padding: 14px 18px;
  font-weight: 600;
  font-size: 15px;
  color: var(--accent-dark);
  display: flex;
  align-items: center;
  gap: 10px;
  user-select: none;
  border-radius: 10px;
}

.form-view .about-form > summary:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.form-view .about-form > summary::-webkit-details-marker {
  display: none;
}

.form-view .about-form > summary::before {
  content: "";
  display: inline-block;
  width: 0;
  height: 0;
  border-left: 5px solid transparent;
  border-right: 5px solid transparent;
  border-top: 6px solid var(--text-muted);
  transform: rotate(-90deg);
  transition: transform 0.15s ease;
  flex-shrink: 0;
}

.form-view .about-form[open] > summary::before {
  transform: rotate(0deg);
}

.form-view .about-form-body {
  padding: 0 18px 16px;
  border-top: 1px solid var(--border);
}

.form-view .about-form-body p {
  font-size: 14px;
  line-height: 1.55;
  color: var(--text);
  margin-top: 12px;
}

.form-view .about-form-body p:first-child {
  margin-top: 14px;
}

.form-view .about-form-note {
  font-size: 13px;
  color: var(--text-muted);
}

.form-view .card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 24px 28px;
  margin-bottom: 20px;
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.04);
}

.form-view .section {
  margin-bottom: 10px;
}

.form-view .section-title {
  font-size: 1rem;
  font-weight: 600;
  color: var(--accent-dark);
  margin-bottom: 18px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 10px;
}

.form-view .section-icon {
  width: 26px;
  height: 26px;
  background: var(--accent);
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-size: 13px;
  font-weight: 700;
}

.form-view .form-group {
  margin-bottom: 18px;
}

.form-view label {
  display: block;
  margin-bottom: 6px;
  font-weight: 400;
  color: var(--text);
  font-size: 14px;
}

.form-view label:has(.required) {
  font-weight: 600;
}

.form-view .required {
  color: #e74c3c;
  margin-left: 3px;
}

.form-view input[type="text"],
.form-view input[type="number"],
.form-view input[type="date"],
.form-view select,
.form-view textarea {
  width: 100%;
  padding: 11px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 14px;
  transition: border-color 0.15s, box-shadow 0.15s;
  font-family: inherit;
  background: #fff;
}

.form-view select {
  cursor: pointer;
  appearance: none;
  -webkit-appearance: none;
  -moz-appearance: none;
  padding-right: 2.5rem;
  background-color: #fff;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='20' height='20' viewBox='0 0 24 24' fill='none'%3E%3Cpath stroke='%2364748b' stroke-width='2' stroke-linecap='round' stroke-linejoin='round' d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  background-size: 18px;
}

.form-view select::-ms-expand {
  display: none;
}

.form-view input:focus,
.form-view select:focus,
.form-view textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(32, 141, 68, 0.12);
}

.form-view textarea {
  resize: vertical;
  min-height: 100px;
}

.form-view .grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px 20px;
}

.form-view .grid > .form-group {
  min-width: 0;
}

.form-view .full-width {
  grid-column: 1 / -1;
}

.form-view .grid-row-three {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px 20px;
  min-width: 0;
}

.form-view .grid-row-three > .form-group {
  min-width: 0;
}

.form-view .grid-row-four {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px 20px;
  min-width: 0;
}

.form-view .grid-row-four > .form-group {
  min-width: 0;
}

.form-view .form-group-split {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px 20px;
  min-width: 0;
}

.form-view .form-group-split .split-field {
  min-width: 0;
}

.form-view .improvement-item {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 12px;
  align-items: center;
}

.form-view .improvement-item .select-search {
  flex: 0 1 220px;
  min-width: 120px;
  max-width: 100%;
}

.form-view .improvement-item .so-marks-input {
  flex: 0 1 110px;
  min-width: 88px;
  max-width: 140px;
}

.form-view .improvement-item .so-pct-hint {
  flex: 1 1 140px;
  font-size: 13px;
  color: var(--text-muted);
  white-space: nowrap;
}

.form-view .improvement-item .so-remove {
  flex: 0 0 auto;
}

.form-view .so-alloc-summary {
  font-size: 13px;
  color: var(--text-muted);
  margin-bottom: 12px;
  line-height: 1.4;
}

.form-view .btn-secondary:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  filter: none;
}

.form-view .combo-field .combo,
.form-view .combo-field .tag-input {
  position: relative;
  max-width: 100%;
}

.form-view .tag-input {
  box-sizing: border-box;
  width: 100%;
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
  transition: border-color 0.15s, box-shadow 0.15s;
  cursor: text;
}

.form-view .tag-input.is-focused {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(32, 141, 68, 0.12);
}

.form-view .tag-input-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  min-height: 28px;
}

.form-view .tag-input-chips {
  display: contents;
}

.form-view .tag-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  max-width: 100%;
  padding: 4px 6px 4px 10px;
  border-radius: 999px;
  background: #f0fdf4;
  border: 1px solid rgba(32, 141, 68, 0.25);
  font-size: 13px;
  line-height: 1.3;
  color: var(--text);
}

.form-view .tag-chip-label {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.form-view .tag-chip-remove {
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 20px;
  height: 20px;
  padding: 0;
  margin: 0;
  border: none;
  border-radius: 50%;
  background: transparent;
  color: var(--text-muted);
  font-size: 16px;
  line-height: 1;
  cursor: pointer;
  font-family: inherit;
}

.form-view .tag-chip-remove:hover,
.form-view .tag-chip-remove:focus {
  background: rgba(32, 141, 68, 0.15);
  color: var(--text);
  outline: none;
}

.form-view .tag-input-field {
  flex: 1 1 120px;
  min-width: 120px;
  border: none;
  outline: none;
  padding: 5px 2px;
  font-size: 14px;
  font-family: inherit;
  background: transparent;
  color: var(--text);
}

.form-view .tag-input-field::placeholder {
  color: var(--text-muted);
}

.form-view .tag-input .combo-list {
  position: absolute;
  left: 0;
  right: 0;
  top: calc(100% + 4px);
}

/* Anchor combo dropdowns; SO rows live in .improvement-item, not .form-group */
.form-view .combo.select-search {
  position: relative;
  min-width: 0;
  max-width: 100%;
}

.form-view .combo.select-search > .select-search-input {
  width: 100%;
  box-sizing: border-box;
  padding: 11px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 14px;
  transition: border-color 0.15s, box-shadow 0.15s;
  font-family: inherit;
  background: #fff;
}

.form-view .combo.select-search > .select-search-input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(32, 141, 68, 0.12);
}

.form-view .combo.select-search > .select-search-input:disabled {
  opacity: 0.65;
  cursor: not-allowed;
  background: #f8fafc;
}

.form-view .select-search-native {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}

.form-view .combo-field .combo > input[type="text"] {
  width: 100%;
}

.form-view .combo-list {
  position: absolute;
  left: 0;
  right: 0;
  top: calc(100% + 4px);
  z-index: 40;
  max-height: 220px;
  overflow-y: auto;
  margin: 0;
  padding: 4px 0;
  list-style: none;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 8px 24px rgba(15, 23, 42, 0.12);
}

.form-view .combo-list li {
  padding: 8px 12px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 2px;
  border-bottom: 1px solid var(--border);
}

.form-view .combo-list li:last-child {
  border-bottom: none;
}

.form-view .combo-list li:hover,
.form-view .combo-list li.is-active {
  background: #f0fdf4;
}

.form-view .combo-option-name {
  font-weight: 600;
  font-size: 14px;
  color: var(--text);
}

.form-view .combo-option-meta {
  font-size: 12px;
  color: var(--text-muted);
}

.form-view .btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 18px;
  border: none;
  border-radius: 8px;
  font-size: 14px;
  cursor: pointer;
  transition: background 0.15s, transform 0.15s, box-shadow 0.15s;
  font-weight: 600;
  font-family: inherit;
}

.form-view .btn .btn-icon {
  display: inline-flex;
  flex-shrink: 0;
  line-height: 0;
}

.form-view .btn .btn-icon svg {
  display: block;
  width: 1.125em;
  height: 1.125em;
}

.form-view .btn-primary {
  background: linear-gradient(135deg, var(--accent) 0%, var(--accent-dark) 100%);
  color: white;
  width: 100%;
  max-width: 360px;
  padding: 14px 22px;
  font-size: 15px;
  box-shadow: 0 2px 8px rgba(32, 141, 68, 0.25);
}

.form-view .btn-primary:hover:not(:disabled) {
  transform: translateY(-1px);
  box-shadow: 0 4px 14px rgba(32, 141, 68, 0.3);
}

.form-view .btn-primary:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.form-view .btn-secondary {
  background: var(--accent-soft);
  color: #0f172a;
}

.form-view .btn-secondary:hover {
  filter: brightness(0.95);
}

.form-view .btn-danger {
  background: #e74c3c;
  color: white;
  padding: 10px 14px;
}

.form-view .btn-danger:hover {
  background: #c0392b;
}

.form-view .actions {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
  flex-wrap: wrap;
  gap: 12px;
}

.form-view .actions .section-title {
  margin: 0;
  border: none;
  padding: 0;
}

.form-view .submit-bar {
  margin-top: 8px;
  padding-top: 8px;
}

.form-view .success-message {
  background: #ecfdf5;
  border: 1px solid #86efac;
  color: #14532d;
  padding: 16px 20px;
  border-radius: 10px;
  margin-bottom: 20px;
  display: none;
}

.form-view .success-message h3 {
  margin-bottom: 6px;
  color: var(--accent-dark);
  font-size: 1rem;
}

.form-view .loading {
  display: none;
  text-align: center;
  padding: 24px;
  background: var(--card-bg);
  border: 1px dashed var(--border);
  border-radius: 10px;
  margin-bottom: 20px;
}

.form-view .spinner {
  border: 3px solid var(--border);
  border-top: 3px solid var(--accent);
  border-radius: 50%;
  width: 40px;
  height: 40px;
  animation: spin 0.9s linear infinite;
  margin: 0 auto 12px;
}

@keyframes spin {
  0% {
    transform: rotate(0deg);
  }
  100% {
    transform: rotate(360deg);
  }
}

.form-view .form-error {
  color: #c0392b;
  margin-bottom: 12px;
  font-size: 14px;
  font-weight: 600;
}

.banner-error {
  background: #fef2f2;
  border: 1px solid #fecaca;
  color: #991b1b;
  padding: 12px 16px;
  border-radius: 10px;
  margin-bottom: 20px;
  display: none;
  font-size: 14px;
}

@media (max-width: 900px) {
  .app {
    flex-direction: column;
  }

  .sidebar {
    width: 100%;
    flex-direction: row;
    align-items: center;
    flex-wrap: wrap;
    padding: 12px 16px;
    gap: 12px;
  }

  .sidebar-brand {
    padding: 0;
    margin: 0;
    border: none;
    flex: 1;
    min-width: 0;
  }

  .sidebar-nav {
    flex-direction: row;
    align-items: center;
    flex-wrap: wrap;
    padding: 0;
    width: 100%;
    gap: 8px;
  }

  .sidebar-nav-group {
    flex-direction: row;
    align-items: center;
    gap: 8px;
    margin-bottom: 0;
  }

  .sidebar-nav-label {
    display: none;
  }

  .sidebar-link {
    padding: 8px 12px;
  }

  .sidebar-link:hover:not(.is-active) {
    transform: none;
  }

  .sidebar-link:hover:not(.is-active) .sidebar-link-icon {
    transform: none;
  }

  .topbar {
    height: auto;
    min-height: 56px;
    padding: 14px 20px;
  }

  .main {
    padding: 16px 20px 32px;
  }

  .app-footer {
    padding: 12px 16px 16px;
  }

  .form-view .card {
    padding: 18px 16px;
  }
}

@media (max-width: 768px) {
  .form-view .grid {
    grid-template-columns: 1fr;
  }

  .form-view .grid-row-three {
    grid-template-columns: 1fr;
  }

  .form-view .grid-row-four {
    grid-template-columns: 1fr;
  }

  .form-view .form-group-split {
    grid-template-columns: 1fr;
  }

  .topbar-title {
    font-size: 1.1rem;
  }
}
