:root {
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;

  --bg: #f2f5f9;
  --bg-alt: #e4edf7;
  --card-bg: #ffffff;

  --primary: #2563eb;
  --primary-soft: rgba(37, 99, 235, 0.06);
  --primary-dark: #1d4ed8;

  --accent: #0f766e;
  --danger: #dc2626;
  --success: #16a34a;

  --border: #d2d7e3;
  --border-soft: #e3e7f2;

  --text: #111827;
  --text-muted: #6b7280;

  --chip-bg: #e0ecff;
  --radius-card: 16px;
}

/* GLOBAL RESET */

*,
*::before,
*::after {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: radial-gradient(circle at top, #dbeafe 0, #f2f5f9 48%, #f2f5f9 100%);
  color: var(--text);
}

/* HEADER */

.app-header {
  background: linear-gradient(135deg, #0f172a, #1d4ed8);
  color: #ffffff;
  padding: 12px 16px 10px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  box-shadow: 0 4px 16px rgba(15, 23, 42, 0.35);
  position: sticky;
  top: 0;
  z-index: 30;
}

.header-left h1 {
  margin: 0;
  font-size: 18px;
  font-weight: 650;
  letter-spacing: 0.02em;
}

.header-left p {
  margin: 3px 0 0 0;
  font-size: 12px;
  opacity: 0.9;
}

.header-right {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}

/* MAIN LAYOUT */

main {
  padding: 10px 10px 90px;
  max-width: 900px;
  margin: 0 auto;
}

/* BUTTONS */

button,
.btn {
  border: none;
  border-radius: 999px;
  padding: 7px 14px;
  font-size: 13px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
  outline: none;
  transition: transform 0.08s ease, box-shadow 0.1s ease, background 0.1s ease,
    border-color 0.1s ease;
}

button:active,
.btn:active {
  transform: scale(0.96);
}

.btn-primary {
  background: #f9fafb;
  color: #1d4ed8;
  border: 1px solid rgba(255, 255, 255, 0.9);
  box-shadow: 0 2px 10px rgba(15, 23, 42, 0.35);
}

.btn-primary:hover {
  background: #eef2ff;
}

.btn-outline {
  background: transparent;
  color: #e5ecff;
  border: 1px solid rgba(255, 255, 255, 0.7);
}

.btn-outline:hover {
  background: rgba(255, 255, 255, 0.12);
}

.btn-sm {
  font-size: 12px;
  padding: 5px 11px;
}

/* On small screens, make Add button float as FAB */

@media (max-width: 640px) {
  #openNewNeedBtn {
    position: fixed;
    right: 14px;
    bottom: 18px;
    z-index: 40;
    border-radius: 999px;
    padding-inline: 16px;
    box-shadow: 0 4px 16px rgba(15, 23, 42, 0.35);
    background: #1d4ed8;
    color: #fff;
    border-color: transparent;
  }
}

/* FILTERS */

.filters {
  background: rgba(255, 255, 255, 0.9);
  border-radius: 16px;
  padding: 12px 10px 10px;
  margin: 10px 0;
  border: 1px solid var(--border-soft);
  box-shadow: 0 4px 12px rgba(15, 23, 42, 0.05);
  backdrop-filter: blur(8px);
}

.filters h2 {
  margin: 0 0 8px;
  font-size: 14px;
  font-weight: 600;
}

.filters-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.filters-row > div {
  flex: 1 1 48%;
  min-width: 150px;
}

.filters-row label {
  font-size: 11px;
  display: block;
  margin-bottom: 3px;
  color: var(--text-muted);
}

.filters-row select,
.filters-row input {
  width: 100%;
  padding: 7px 9px;
  border-radius: 999px;
  border: 1px solid var(--border);
  font-size: 13px;
  background: #f9fafb;
  outline: none;
  transition: border-color 0.12s ease, background 0.12s ease, box-shadow 0.12s ease;
}

.filters-row select:focus,
.filters-row input:focus {
  border-color: var(--primary);
  background: #ffffff;
  box-shadow: 0 0 0 1px rgba(37, 99, 235, 0.15);
}

.filters-actions {
  margin-top: 10px;
  display: flex;
  gap: 6px;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
}

/* LOADERS */

.loader-container {
  display: none;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 6px;
  padding: 12px;
}

.loader-container.small {
  padding: 6px;
}

.spinner {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 3px solid rgba(37, 99, 235, 0.18);
  border-top-color: #1d4ed8;
  animation: spin 0.7s linear infinite;
}

.spinner.small {
  width: 20px;
  height: 20px;
}

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

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

/* NEEDS LIST */

.needs-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 6px;
}

.need-card {
  background: var(--card-bg);
  border-radius: var(--radius-card);
  padding: 10px;
  border: 1px solid var(--border-soft);
  box-shadow: 0 5px 16px rgba(15, 23, 42, 0.08);
  cursor: pointer;
  transition: transform 0.08s ease, box-shadow 0.08s ease, border-color 0.08s ease,
    background 0.08s ease;
}

.need-card:active {
  transform: scale(0.98);
  box-shadow: 0 3px 10px rgba(15, 23, 42, 0.08);
}

.need-card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 6px;
}

.need-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
}

.badge {
  display: inline-flex;
  align-items: center;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 500;
  color: #fff;
}

.badge-severity-high {
  background: linear-gradient(135deg, #dc2626, #f97316);
}

.badge-severity-med {
  background: linear-gradient(135deg, #facc15, #f97316);
  color: #111827;
}

.badge-severity-low {
  background: linear-gradient(135deg, #16a34a, #22c55e);
}

.badge-type {
  background: var(--chip-bg);
  color: #1e3a8a;
}

.need-meta {
  margin-top: 5px;
  font-size: 11px;
  color: var(--text-muted);
}

.need-people {
  font-size: 11px;
  margin-top: 2px;
  color: var(--text-muted);
}

.progress-bar-wrapper {
  margin-top: 6px;
  font-size: 11px;
  color: var(--text-muted);
}

.progress-track {
  width: 100%;
  height: 6px;
  border-radius: 999px;
  background: #e5edff;
  overflow: hidden;
  margin-top: 3px;
}

.progress-fill {
  height: 100%;
  background: linear-gradient(90deg, #16a34a, #22c55e);
  width: 0%;
}

/* EMPTY STATE */

.empty-state {
  text-align: center;
  font-size: 13px;
  color: var(--text-muted);
  padding: 20px 10px;
}

/* PANELS (DETAIL + NEW NEED) AS BOTTOM SHEETS */

.panel {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  max-height: 88vh;
  background: var(--card-bg);
  border-radius: 18px 18px 0 0;
  border-top: 1px solid var(--border-soft);
  transform: translateY(110%);
  opacity: 0;
  pointer-events: none;
  transition: transform 0.25s ease-out, opacity 0.2s ease-out, box-shadow 0.15s ease-out;
  z-index: 50;
  box-shadow: none; /* no shadow when hidden */
}

/* Visible state */

.panel.visible {
  transform: translateY(0);
  opacity: 1;
  pointer-events: auto;
  box-shadow: 0 -10px 24px rgba(15, 23, 42, 0.4);
}

.panel-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  padding: 10px 12px 6px;
  border-bottom: 1px solid #eef1f7;
}

.panel-title {
  font-size: 14px;
  font-weight: 600;
}

.panel-close {
  border-radius: 999px;
  border: none;
  background: #eef2ff;
  font-size: 20px;
  line-height: 1;
  width: 30px;
  height: 30px;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background 0.1s ease;
}

.panel-close:hover {
  background: #e0e7ff;
}

.panel-body {
  font-size: 13px;
  overflow-y: auto;
  max-height: calc(88vh - 44px);
  padding: 8px 12px 18px;
}

/* DETAIL STYLES */

#detailBadges {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 6px;
}

.detail-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px 12px;
  margin-bottom: 8px;
  font-size: 12px;
}

.detail-label {
  color: var(--text-muted);
  font-size: 11px;
}

.detail-value {
  font-weight: 500;
}

.detail-section-title {
  margin-top: 10px;
  font-size: 13px;
  font-weight: 600;
}

.detail-description {
  margin-top: 4px;
  font-size: 13px;
  white-space: pre-wrap;
  background: #f9fafb;
  border-radius: 8px;
  padding: 6px 8px;
}

/* COMMENTS */

.comment-list {
  margin-top: 8px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.comment-card {
  border-radius: 10px;
  border: 1px solid var(--border-soft);
  padding: 6px 8px;
  font-size: 12px;
  background: #f9fafb;
}

.comment-header {
  display: flex;
  justify-content: space-between;
  gap: 6px;
  margin-bottom: 2px;
}

.comment-name {
  font-weight: 600;
}

.comment-meta {
  font-size: 11px;
  color: var(--text-muted);
}

.comment-text {
  font-size: 12px;
  margin-top: 3px;
  white-space: pre-wrap;
}

/* FORMS (COMMENT + NEW NEED) */

.comment-form,
.new-need-form {
  margin-top: 10px;
  border-radius: 12px;
  border: 1px solid var(--border-soft);
  padding: 8px 8px 10px;
  background: #fdfdfd;
}

.comment-form h3,
.new-need-form h3 {
  margin: 0 0 6px;
  font-size: 13px;
  font-weight: 600;
}

.form-row {
  margin-bottom: 7px;
}

.form-row label {
  font-size: 12px;
  display: block;
  margin-bottom: 3px;
  color: var(--text-muted);
}

.form-row input,
.form-row textarea,
.form-row select {
  width: 100%;
  padding: 7px 9px;
  border-radius: 10px;
  border: 1px solid var(--border);
  font-size: 13px;
  background: #f9fafb;
  outline: none;
  transition: border-color 0.12s ease, background 0.12s ease, box-shadow 0.12s ease;
}

.form-row input:focus,
.form-row textarea:focus,
.form-row select:focus {
  border-color: var(--primary);
  background: #ffffff;
  box-shadow: 0 0 0 1px rgba(37, 99, 235, 0.15);
}

.form-row textarea {
  min-height: 60px;
  resize: vertical;
}

.form-error {
  color: var(--danger);
  font-size: 12px;
}

/* Sticky submit buttons inside forms (uses your existing .text-right) */

.comment-form .text-right,
.new-need-form .text-right {
  position: sticky;
  bottom: 6px; /* keeps it off the very bottom edge */
  padding-top: 8px;
  padding-bottom: 4px;
  text-align: right;
  background: linear-gradient(
    to bottom,
    rgba(253, 253, 253, 0) 0%,
    #fdfdfd 35%,
    #fdfdfd 100%
  );
  z-index: 1;
}

/* Slider row */

.fulfilment-row {
  display: flex;
  align-items: center;
  gap: 6px;
}

.fulfilment-row input[type="range"] {
  flex: 1;
}

/* RESPONSIVE: DESKTOP LAYOUT */

@media (min-width: 768px) {
  main {
    padding-bottom: 20px;
  }

  .app-header {
    border-radius: 0 0 14px 14px;
  }

  .panel.detail-panel {
    left: auto;
    right: 16px;
    bottom: 16px;
    width: 380px;
    max-height: 84vh;
    border-radius: 18px;
  }

  .panel.new-need-panel {
    left: 16px;
    right: auto;
    bottom: 16px;
    width: 380px;
    max-height: 84vh;
    border-radius: 18px;
  }
}

/* EXTRA: SMALL DEVICES TWEAK */

@media (max-width: 480px) {
  .filters-row > div {
    flex: 1 1 100%;
  }

  .need-card {
    padding: 9px;
  }

  .panel-body {
    padding-bottom: 22px;
  }
}
