/*
 * foundation_os — Mobile-first stylesheet
 */

/* ─── Tokens ─── */
:root {
  --cream:       #faf5eb;
  --brown:       #2d1810;
  --brown-light: #5c3d2e;
  --orange:      #f97316;
  --orange-dark: #c2410c;
  --border:      #e5d8c0;
  --text:        #1a0f0a;
  --text-muted:  #7c5c3e;
  --radius:      8px;
}

/* ─── Reset ─── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
img, video { max-width: 100%; display: block; }
a { color: inherit; }

/* ─── Base ─── */
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--cream);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.6;
  font-size: 16px;
}

/* ─── Layout ─── */
main {
  max-width: 1100px;
  margin: 0 auto;
  padding: 1.25rem 1rem;
}
@media (min-width: 640px) {
  main { padding: 2rem 1.5rem; }
}

/* ─── Nav ─── */
.pknf-nav {
  background: var(--brown);
  color: #fff;
  position: relative;
}

.nav-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 1rem;
  gap: 1rem;
}

.nav-brand a {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  color: #fff;
  text-decoration: none;
  font-weight: 700;
  font-size: 0.95rem;
  line-height: 1.2;
  white-space: nowrap;
}

/* Hamburger toggle — mobile only */
.nav-toggle {
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 5px;
  background: none;
  border: none;
  cursor: pointer;
  padding: 4px;
  flex-shrink: 0;
}
.nav-toggle span {
  display: block;
  width: 22px;
  height: 2px;
  background: #fff;
  border-radius: 2px;
  transition: all 0.2s;
}

/* Collapsible panel */
.nav-panel {
  display: none;
  flex-direction: column;
  gap: 0;
  background: #1e0e07;
  border-top: 1px solid rgba(255,255,255,0.1);
}
.nav-panel.open { display: flex; }

.nav-links-mobile {
  display: flex;
  flex-direction: column;
  padding: 0.5rem 0;
}
.nav-links-mobile a {
  padding: 0.65rem 1.25rem;
  color: rgba(255,255,255,0.85);
  text-decoration: none;
  font-size: 0.95rem;
}
.nav-links-mobile a:hover { color: #fff; background: rgba(255,255,255,0.05); }

.nav-auth-mobile {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
  padding: 0.75rem 1.25rem;
  border-top: 1px solid rgba(255,255,255,0.08);
}
.nav-username { color: rgba(255,255,255,0.85); font-size: 0.9rem; font-weight: 500; }
.nav-link { color: rgba(255,255,255,0.8); text-decoration: none; font-size: 0.9rem; }
.nav-link:hover { color: #fff; }
.nav-join {
  background: var(--orange);
  color: #fff !important;
  padding: 0.35rem 0.9rem;
  border-radius: 4px;
  font-weight: 500;
  font-size: 0.9rem;
  text-decoration: none;
  white-space: nowrap;
}
.nav-join:hover { background: var(--orange-dark); }
.nav-admin { color: #fbbf24 !important; font-size: 0.9rem; }

/* Desktop nav — hide hamburger, show inline */
@media (min-width: 768px) {
  .nav-toggle { display: none; }
  .nav-panel { display: none !important; } /* always hidden on desktop */

  .nav-inner {
    gap: 0;
  }
  .nav-desktop {
    display: flex;
    align-items: center;
    gap: 1rem;
    margin-left: 1.5rem;
    flex: 1;
  }
  .nav-desktop .nav-link {
    font-size: 0.9rem;
    color: rgba(255,255,255,0.85);
  }
  .nav-desktop .nav-link:hover { color: #fff; }
  .nav-auth-desktop {
    display: flex;
    align-items: center;
    gap: 1rem;
    margin-left: auto;
  }
}
@media (max-width: 767px) {
  .nav-desktop { display: none; }
  .nav-auth-desktop { display: none; }
}

/* ─── Flash ─── */
.flash {
  padding: 0.75rem 1.25rem;
  font-size: 0.9rem;
  border-bottom: 1px solid transparent;
}
.flash.notice { background: #dcfce7; color: #166534; border-color: #bbf7d0; }
.flash.alert  { background: #fee2e2; color: #991b1b; border-color: #fecaca; }

/* ─── Typography ─── */
h1 { font-size: 1.6rem; }
h2 { font-size: 1.3rem; }
h3 { font-size: 1.1rem; }

@media (min-width: 640px) {
  h1 { font-size: 2rem; }
  h2 { font-size: 1.5rem; }
}

/* ─── Buttons ─── */
.btn {
  display: inline-block;
  padding: 0.55rem 1.25rem;
  border-radius: 6px;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
  border: none;
  font-size: 0.95rem;
  transition: background 0.15s, color 0.15s;
  white-space: nowrap;
}
.btn-primary { background: var(--orange); color: #fff; }
.btn-primary:hover { background: var(--orange-dark); color: #fff; }
.btn-outline { background: transparent; color: var(--brown); border: 2px solid var(--brown); }
.btn-outline:hover { background: var(--brown); color: #fff; }
.btn-sm { padding: 0.3rem 0.75rem; font-size: 0.85rem; }
.btn-danger { background: #dc2626; color: #fff; }
.btn-danger:hover { background: #b91c1c; }

/* Hero aliases (used in home view) */
.btn-primary-lg {
  display: inline-block;
  background: var(--orange);
  color: #fff;
  padding: 0.75rem 1.75rem;
  border-radius: 6px;
  font-weight: 600;
  text-decoration: none;
  margin: 0.25rem;
}
.btn-secondary-lg {
  display: inline-block;
  border: 2px solid var(--brown);
  color: var(--brown);
  padding: 0.7rem 1.75rem;
  border-radius: 6px;
  font-weight: 600;
  text-decoration: none;
  margin: 0.25rem;
}
/* Keep old aliases too */
.btn-primary-hero { display: inline-block; background: var(--orange); color: #fff; padding: 0.75rem 1.75rem; border-radius: 6px; font-weight: 600; text-decoration: none; margin: 0.25rem; }
.btn-secondary { display: inline-block; border: 2px solid var(--brown); color: var(--brown); padding: 0.7rem 1.75rem; border-radius: 6px; font-weight: 600; text-decoration: none; margin: 0.25rem; }

/* ─── Cards ─── */
.card {
  background: white;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
}
@media (min-width: 640px) {
  .card { padding: 1.5rem; }
}

/* ─── Responsive grids ─── */
/* 2-col: stacks on mobile */
.grid-2 {
  display: grid;
  grid-template-columns: 1fr;
  gap: 1.25rem;
}
@media (min-width: 640px) {
  .grid-2 { grid-template-columns: 1fr 1fr; }
}

/* Main + sidebar: stacks on mobile */
.grid-main-sidebar {
  display: grid;
  grid-template-columns: 1fr;
  gap: 1.5rem;
}
@media (min-width: 768px) {
  .grid-main-sidebar { grid-template-columns: 1fr 220px; }
}

/* Auto-fill card grid */
.grid-cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 1rem;
}

/* ─── Page header ─── */
.page-header {
  padding: 1.25rem 0 1rem;
  border-bottom: 1px solid var(--border);
  margin-bottom: 1.5rem;
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.75rem;
}
.page-header h1 { font-size: 1.6rem; color: var(--brown); }
@media (min-width: 640px) {
  .page-header { padding: 2rem 0 1rem; }
  .page-header h1 { font-size: 2rem; }
}

/* ─── Hero ─── */
.home-hero {
  text-align: center;
  padding: 3rem 1rem;
}
.home-hero h1 {
  font-size: 2rem;
  font-weight: 700;
  color: var(--brown);
  margin-bottom: 0.75rem;
}
.home-hero p {
  font-size: 1.1rem;
  color: #78350f;
  margin-bottom: 2rem;
}
@media (min-width: 640px) {
  .home-hero { padding: 4rem 1rem; }
  .home-hero h1 { font-size: 2.75rem; }
  .home-hero p { font-size: 1.25rem; }
}

/* ─── Forms ─── */
input[type="text"],
input[type="email"],
input[type="password"],
input[type="search"],
input[type="url"],
select,
textarea {
  width: 100%;
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 0.95rem;
  font-family: inherit;
  background: white;
  color: var(--text);
}
input:focus, textarea:focus, select:focus {
  outline: 2px solid var(--orange);
  outline-offset: 1px;
  border-color: var(--orange);
}

.form-group { margin-bottom: 1.25rem; }
.form-group label { display: block; font-weight: 600; margin-bottom: 0.35rem; font-size: 0.9rem; color: var(--brown); }
.form-actions { display: flex; flex-wrap: wrap; gap: 0.75rem; margin-top: 1.5rem; }

/* ─── Badges ─── */
.badge { display: inline-block; padding: 0.2rem 0.6rem; border-radius: 20px; font-size: 0.75rem; font-weight: 600; }
.badge-green { background: #dcfce7; color: #166534; }
.badge-gray  { background: #f1f5f9; color: #475569; }
.badge-orange { background: #ffedd5; color: #9a3412; }

/* ─── Tags ─── */
.tag-pill {
  display: inline-block;
  padding: 0.15rem 0.6rem;
  border-radius: 20px;
  background: var(--border);
  color: var(--brown-light);
  font-size: 0.8rem;
  text-decoration: none;
  margin: 0.1rem;
}
.tag-pill:hover { background: var(--orange); color: #fff; }

/* ─── Misc ─── */
.vote-score { font-weight: 700; font-size: 1.1rem; color: var(--brown); }
.accepted-badge { background: #dcfce7; color: #166534; padding: 0.2rem 0.6rem; border-radius: 4px; font-size: 0.8rem; font-weight: 600; }
.member-gate { background: white; border: 1px solid var(--border); border-radius: var(--radius); padding: 2rem; text-align: center; }
.member-gate h2 { color: var(--brown); margin-bottom: 0.5rem; }
.member-gate p { color: var(--text-muted); }
.flash-notice { background: #dcfce7; border: 1px solid #bbf7d0; color: #166534; padding: 0.75rem 1rem; border-radius: 6px; margin-bottom: 1rem; }
.flash-alert  { background: #fef2f2; border: 1px solid #fecaca; color: #991b1b;  padding: 0.75rem 1rem; border-radius: 6px; margin-bottom: 1rem; }

/* Responsive table wrapper */
.table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 0.5rem 0.75rem; text-align: left; border-bottom: 1px solid var(--border); font-size: 0.9rem; }
th { font-weight: 600; color: var(--brown); background: var(--cream); }

/* Search row */
.search-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-bottom: 1rem;
  align-items: center;
}
.search-row input { flex: 1; min-width: 160px; }

/* ─── Auth pages ─── */
.auth-wrap {
  display: flex;
  justify-content: center;
  align-items: flex-start;
  padding: 2rem 1rem;
  min-height: 60vh;
}

.auth-card {
  background: white;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 2rem;
  width: 100%;
  max-width: 420px;
}

.auth-header {
  text-align: center;
  margin-bottom: 1.75rem;
}

.auth-header h1 {
  font-size: 1.5rem;
  color: var(--brown);
  margin: .5rem 0 .25rem;
}

.auth-header p {
  color: var(--text-muted);
  font-size: .9rem;
}

.auth-links {
  margin-top: 1.25rem;
  text-align: center;
  font-size: .9rem;
  color: var(--text-muted);
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: .5rem;
}

.auth-links a {
  color: var(--orange);
  text-decoration: none;
}

.auth-links a:hover { text-decoration: underline; }

/* Pagy pagination — nav.pagy.nav */
nav.pagy {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: .3rem;
  margin: 1.75rem 0 .5rem;
  flex-wrap: wrap;
}
nav.pagy a {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 2.25rem;
  height: 2.25rem;
  padding: 0 .6rem;
  border-radius: .4rem;
  font-size: .875rem;
  font-weight: 500;
  text-decoration: none;
  color: var(--brown);
  background: #fff;
  border: 1px solid #d4c4b0;
  transition: background .15s, color .15s, border-color .15s;
}
nav.pagy a:hover {
  background: var(--brown);
  color: #fff;
  border-color: var(--brown);
}
nav.pagy a.current {
  background: var(--orange);
  color: #fff;
  border-color: var(--orange);
  font-weight: 700;
  pointer-events: none;
}
nav.pagy a.gap {
  border: none;
  background: none;
  color: var(--text-muted);
  pointer-events: none;
  min-width: 1rem;
}
nav.pagy a[aria-disabled="true"] {
  opacity: .35;
  pointer-events: none;
  cursor: default;
}

/* ── Q&A Form ─────────────────────────────────────────────────── */
.qa-form-section {
  background: #fff;
  border: 1px solid #e5ddd3;
  border-radius: .625rem;
  padding: 1.25rem 1.4rem;
  margin-bottom: 1rem;
}
.qa-form-label {
  display: block;
  font-weight: 600;
  font-size: 1rem;
  color: var(--brown);
  margin-bottom: .6rem;
}
.qa-form-hint {
  display: block;
  font-weight: 400;
  font-size: .8rem;
  color: var(--text-muted);
  margin-top: .1rem;
}
.qa-form-input {
  width: 100%;
  padding: .65rem .85rem;
  border: 1px solid #d4c4b0;
  border-radius: .4rem;
  font-size: 1rem;
  color: var(--brown);
  background: #faf8f5;
  box-sizing: border-box;
  transition: border-color .15s, box-shadow .15s;
}
.qa-form-input:focus {
  outline: none;
  border-color: var(--orange);
  box-shadow: 0 0 0 3px rgba(249,115,22,.12);
  background: #fff;
}

/* ── Trix editor ───────────────────────────────────────────────── */
.trix-wrapper trix-editor {
  min-height: 160px;
  border: 1px solid #d4c4b0;
  border-top: none;
  border-radius: 0 0 .4rem .4rem;
  padding: .75rem 1rem;
  font-size: .95rem;
  line-height: 1.6;
  color: var(--brown);
  background: #faf8f5;
  outline: none;
}
.trix-wrapper trix-editor:focus {
  background: #fff;
  border-color: var(--orange);
  box-shadow: 0 0 0 3px rgba(249,115,22,.12);
}
.trix-wrapper trix-toolbar {
  border: 1px solid #d4c4b0;
  border-radius: .4rem .4rem 0 0;
  background: #f5f0ea;
  padding: .4rem .5rem;
  overflow-x: auto;
  display: flex;
  flex-wrap: wrap;
}
.trix-wrapper trix-toolbar .trix-button-group {
  border: 1px solid #d4c4b0;
  border-radius: .3rem;
  margin-right: .3rem;
  margin-bottom: .3rem;
}
.trix-wrapper trix-toolbar .trix-button {
  border: none;
  background: none;
  color: var(--brown);
  padding: .25rem .45rem;
  font-size: .8rem;
  cursor: pointer;
  border-radius: .2rem;
}
.trix-wrapper trix-toolbar .trix-button:hover {
  background: var(--brown);
  color: #fff;
}
.trix-wrapper trix-toolbar .trix-button.trix-active {
  background: var(--orange);
  color: #fff;
}
/* Hide file attachment button — not needed for Q&A */
.trix-wrapper trix-toolbar .trix-button-group--file-tools { display: none; }

/* ── Tag input ─────────────────────────────────────────────────── */
.tag-input-wrapper {
  position: relative;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: .35rem;
  min-height: 2.5rem;
  padding: .4rem .65rem;
  border: 1px solid #d4c4b0;
  border-radius: .4rem;
  background: #faf8f5;
  cursor: text;
  transition: border-color .15s, box-shadow .15s;
}
.tag-input-wrapper:focus-within {
  border-color: var(--orange);
  box-shadow: 0 0 0 3px rgba(249,115,22,.12);
  background: #fff;
}
.tag-chip-selected {
  display: inline-flex;
  align-items: center;
  gap: .3rem;
  background: var(--brown);
  color: #fff;
  border-radius: 999px;
  padding: .2rem .6rem .2rem .7rem;
  font-size: .82rem;
  font-weight: 500;
  white-space: nowrap;
}
.tag-chip-selected button {
  background: none;
  border: none;
  color: rgba(255,255,255,.7);
  cursor: pointer;
  font-size: 1rem;
  line-height: 1;
  padding: 0;
  transition: color .1s;
}
.tag-chip-selected button:hover { color: #fff; }
.tag-text-input {
  flex: 1;
  min-width: 120px;
  border: none;
  background: none;
  outline: none;
  font-size: .9rem;
  color: var(--brown);
  padding: .15rem 0;
}
.tag-text-input::placeholder { color: #b0a090; }
.tag-dropdown {
  position: absolute;
  top: calc(100% + 4px);
  left: 0; right: 0;
  background: #fff;
  border: 1px solid #d4c4b0;
  border-radius: .4rem;
  box-shadow: 0 4px 16px rgba(0,0,0,.1);
  z-index: 100;
  max-height: 220px;
  overflow-y: auto;
}
.tag-dropdown-item {
  padding: .55rem .85rem;
  font-size: .88rem;
  color: var(--brown);
  cursor: pointer;
  transition: background .1s;
}
.tag-dropdown-item:hover { background: #faf0e8; }
.tag-dropdown-create {
  color: var(--orange);
  font-weight: 600;
  border-top: 1px solid #ede8e0;
}
kbd {
  background: #f0ebe4;
  border: 1px solid #d4c4b0;
  border-radius: .25rem;
  padding: .05rem .35rem;
  font-size: .78rem;
  font-family: inherit;
}

/* ── Vote column ────────────────────────────────────────────────── */
.vote-col {
  display: flex;
  flex-direction: column;
  align-items: center;
  min-width: 44px;
}
.vote-btn {
  background: none;
  border: 1px solid var(--border);
  border-radius: .3rem;
  color: var(--text-muted);
  cursor: pointer;
  width: 36px;
  height: 28px;
  font-size: .85rem;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background .15s, color .15s;
}
.vote-btn:hover { background: var(--orange); color: #fff; border-color: var(--orange); }

/* ── Accepted answer card ───────────────────────────────────────── */
.answer-card { border-left: 3px solid transparent; }
.answer-accepted { border-left-color: #16a34a !important; }

/* ── Trix content (rendered rich text) ─────────────────────────── */
.trix-content { line-height: 1.65; color: var(--brown); }
.trix-content h1, .trix-content h2 { font-size: 1.1rem; margin: 1rem 0 .5rem; }
.trix-content ul, .trix-content ol { padding-left: 1.5rem; margin: .5rem 0; }
.trix-content blockquote {
  border-left: 3px solid var(--orange);
  margin: .75rem 0;
  padding: .25rem .75rem;
  color: var(--text-muted);
  font-style: italic;
}
.trix-content pre {
  background: #f5f0ea;
  border: 1px solid #e5ddd3;
  border-radius: .35rem;
  padding: .65rem .85rem;
  font-size: .85rem;
  overflow-x: auto;
}

/* ── Research record type badges ───────────────────────────────── */
.record-type-badge {
  display: inline-block;
  font-size: .72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .05em;
  padding: .15rem .55rem;
  border-radius: 999px;
  background: #f0ebe4;
  color: var(--brown);
}
.record-type-observation_record  { background: #dbeafe; color: #1e40af; }
.record-type-harvest_record      { background: #dcfce7; color: #15803d; }
.record-type-amendment_record    { background: #fef9c3; color: #854d0e; }
.record-type-sowing_record       { background: #f0fdf4; color: #166534; }
.record-type-water_record        { background: #e0f2fe; color: #0369a1; }
.record-type-maintenance_record  { background: #f3e8ff; color: #7e22ce; }
.record-type-weekly_report       { background: #fff7ed; color: #c2410c; }
