/* Layout, nav, footer, app shell, grids */

/* ===== Public Nav ===== */
.site-header {
  position: sticky; top: 0; z-index: 100;
  min-height: var(--nav-h);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.nav {
  min-height: var(--nav-h);
  display: flex; align-items: center; justify-content: space-between;
  gap: 0.75rem;
  padding: 0.35rem 0;
}
.nav-brand {
  display: flex; align-items: center; gap: 0.5rem;
  flex-shrink: 0;
}
.nav-brand-text {
  font-family: var(--font);
  font-weight: 700;
  font-size: 1.05rem;
  line-height: 1.1;
}
.nav-brand-text .sisa { color: var(--green); }
.nav-brand-text .farm { color: var(--blue); }

/* Logo size system */
.brand-wordmark,
.brand-mark,
.brand-full {
  display: block;
  width: auto;
  height: auto;
  background: transparent;
  border-radius: 0;
  object-fit: contain;
}

/* Text logo, public header */
.brand-wordmark {
  height: 34px;
  max-width: 190px;
  object-position: left center;
}

/* Text logo, sidebar / footer */
.brand-wordmark-sm,
.app-sidebar .brand-wordmark,
.footer-top .brand-wordmark {
  height: 28px;
  max-width: 148px;
}

/* Icon mark, compact square uses */
.brand-mark {
  width: 32px;
  height: 32px;
  object-fit: contain;
}

/* Full logo (icon + text + tagline) */
.brand-full {
  height: clamp(96px, 18vw, 140px);
  max-width: min(280px, 70vw);
  margin-inline: auto;
}

@media (max-width: 560px) {
  .brand-wordmark {
    height: 30px;
    max-width: 150px;
  }
  .brand-wordmark-sm,
  .app-sidebar .brand-wordmark,
  .footer-top .brand-wordmark {
    height: 26px;
    max-width: 136px;
  }
}

.nav-links {
  display: flex; align-items: center; gap: 0.15rem;
}
.nav-links a {
  padding: 0.45rem 0.7rem;
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  font-weight: 600;
  font-size: 0.88rem;
  min-height: 40px;
  display: inline-flex; align-items: center;
}
.nav-links a:hover,
.nav-links a.active {
  color: var(--green-deep);
  background: var(--green-soft);
}
.nav-actions {
  display: flex; align-items: center; gap: 0.45rem;
}
.nav-toggle {
  display: none;
  width: var(--control-h); height: var(--control-h);
  border-radius: var(--radius-sm);
  align-items: center; justify-content: center;
  color: var(--text);
  background: var(--bg-alt);
}
.nav-toggle svg { width: 22px; height: 22px; }

@media (max-width: 900px) {
  .nav-toggle { display: flex; }
  .nav {
    flex-wrap: wrap;
  }
  .nav-links,
  .nav-actions {
    display: none;
    width: 100%;
    flex-direction: column;
    align-items: stretch;
    gap: 0.3rem;
    padding: 0.35rem 0 0.5rem;
  }
  .nav.is-open .nav-links,
  .nav.is-open .nav-actions {
    display: flex;
  }
  .nav.is-open .nav-actions {
    flex-direction: row;
    flex-wrap: wrap;
  }
  .nav.is-open .nav-actions .btn { flex: 1; min-width: 120px; }
}

/* ===== Footer ===== */
.site-footer {
  background: var(--surface);
  border-top: 1px solid var(--border);
  color: var(--text-muted);
  padding: 1.5rem 0 1.25rem;
  margin-top: 3rem;
}
.footer-inner { display: flex; flex-direction: column; gap: 1rem; }
.footer-top {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem 1.25rem;
}
.footer-name {
  font-weight: 600;
  font-size: 0.95rem;
  color: var(--text);
}
.footer-name .sisa { color: var(--green); }
.footer-name .farm { color: var(--blue); }
.footer-name:hover { color: var(--text); }
.footer-top .nav-brand { margin: 0; }
.footer-links {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem 1rem;
}
.footer-links a {
  color: var(--text-muted);
  font-size: 0.85rem;
  font-weight: 500;
}
.footer-links a:hover { color: var(--green-dark); }
.footer-bottom {
  border-top: 1px solid var(--border);
  padding-top: 0.85rem;
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 0.5rem;
  font-size: 0.8rem;
  color: var(--text-light);
}

/* ===== App Shell (dashboards) ===== */
.app-shell {
  display: grid;
  grid-template-columns: 220px 1fr;
  min-height: 100vh;
}
.app-sidebar {
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 0.85rem 0.65rem;
  display: flex; flex-direction: column;
  position: sticky; top: 0; height: 100vh;
  overflow-x: hidden;
  overflow-y: auto;
  min-width: 0;
}
.app-sidebar .nav-brand { margin-bottom: 0.85rem; padding: 0 0.35rem; }
.sidebar-role {
  position: relative;
  display: flex;
  align-items: flex-start;
  gap: 0.65rem;
  margin: 0 0.35rem 0.95rem;
  padding: 0.75rem 0.75rem 0.75rem 0.85rem;
  border-radius: 14px;
  background: linear-gradient(145deg, #f7faf8 0%, #eef4f0 100%);
  border: 1px solid var(--border);
  box-shadow: 0 1px 0 rgba(255,255,255,0.8) inset, 0 4px 14px rgba(28, 36, 40, 0.04);
  overflow: hidden;
  max-width: 100%;
  min-width: 0;
  box-sizing: border-box;
}
.sidebar-role::before {
  content: "";
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 4px;
  background: var(--green);
}
.sidebar-role:has(.role-farmer)::before {
  background: var(--blue);
}
.sidebar-role:has(.role-admin)::before {
  background: #8b6fbf;
}
.sidebar-role:has(.role-farmer) {
  background: linear-gradient(145deg, #f7fafc 0%, #eef4fa 100%);
}
.sidebar-role:has(.role-producer) {
  background: linear-gradient(145deg, #f5faf7 0%, #e8f4ec 100%);
}
.sidebar-role:has(.role-admin) {
  background: linear-gradient(145deg, #faf8fc 0%, #f3eef8 100%);
}
.sidebar-role-avatar {
  flex: 0 0 auto;
  width: 40px;
  height: 40px;
  margin-top: 0.1rem;
  border-radius: 11px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: 0.78rem;
  letter-spacing: 0.02em;
  color: #fff;
  background: linear-gradient(135deg, var(--green), var(--green-dark));
  box-shadow: 0 4px 12px rgba(86, 183, 120, 0.35);
}
.sidebar-role:has(.role-farmer) .sidebar-role-avatar {
  background: linear-gradient(135deg, var(--blue), var(--blue-dark));
  box-shadow: 0 4px 12px rgba(60, 150, 224, 0.35);
}
.sidebar-role:has(.role-admin) .sidebar-role-avatar {
  background: linear-gradient(135deg, #9b7fd1, #6b5099);
  box-shadow: 0 4px 12px rgba(107, 80, 153, 0.3);
}
.sidebar-role-meta {
  min-width: 0;
  flex: 1 1 auto;
  overflow: hidden;
}
.sidebar-role .role-chip {
  margin: 0;
  max-width: 100%;
}
.sidebar-role strong {
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  line-clamp: 2;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-top: 0.28rem;
  font-size: 0.86rem;
  font-weight: 700;
  color: var(--text);
  line-height: 1.3;
  letter-spacing: -0.01em;
  word-break: break-word;
  overflow-wrap: anywhere;
  hyphens: auto;
  max-width: 100%;
  cursor: default;
}
.sidebar-role span:not(.role-chip):not(.sidebar-role-avatar) {
  font-size: 0.72rem;
  color: var(--text-muted);
}

.sidebar-nav { display: flex; flex-direction: column; gap: 0.1rem; flex: 1; }
.sidebar-nav a {
  display: flex; align-items: center; gap: 0.5rem;
  padding: 0.7rem 0.75rem;
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  font-weight: 500;
  font-size: 0.9rem;
  min-height: 48px;
}
.sidebar-nav a:hover { background: var(--bg-alt); color: var(--text); }
.sidebar-nav a.active {
  background: var(--green-soft);
  color: var(--green-deep);
  font-weight: 600;
}
.sidebar-footer {
  padding-top: 1rem;
  border-top: 1px solid var(--border);
  margin-top: 1rem;
}
.sidebar-footer a {
  display: flex; align-items: center; gap: 0.6rem;
  padding: 0.65rem 0.85rem;
  color: var(--text-muted);
  font-weight: 600;
  font-size: 0.9rem;
  border-radius: var(--radius-sm);
}
.sidebar-footer a:hover { color: var(--danger); background: #FFEBEE; }

.app-main { min-width: 0; display: flex; flex-direction: column; }
.app-topbar {
  min-height: 52px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0.5rem 1rem;
  gap: 0.75rem;
  position: sticky; top: 0; z-index: 50;
}
.app-topbar h1 {
  font-size: 1rem;
  font-weight: 600;
}
.topbar-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-shrink: 0;
  margin-left: auto;
}
.app-content {
  padding: 1rem;
  flex: 1;
}
.sidebar-toggle {
  display: none;
  width: var(--control-h); height: var(--control-h);
  border-radius: var(--radius-sm);
  align-items: center; justify-content: center;
  background: var(--bg-alt);
  font-size: 1.1rem;
  border: 1px solid var(--border);
}


@media (max-width: 960px) {
  .app-shell { grid-template-columns: 1fr; }
  .app-sidebar {
    position: fixed; left: 0; top: 0; bottom: 0;
    z-index: 200; width: min(300px, 86vw);
    transform: translateX(-100%);
    transition: transform 0.3s var(--ease);
    box-shadow: var(--shadow);
  }
  .app-sidebar.is-open { transform: translateX(0); }
  .sidebar-toggle { display: flex; }
  .sidebar-overlay {
    display: none;
    position: fixed; inset: 0;
    background: rgba(31,42,46,0.4);
    z-index: 150;
  }
  .sidebar-overlay.is-open { display: block; }
  .app-content { padding: 0.85rem; }
  .app-topbar { padding: 0.5rem 0.85rem; }
}

/* ===== Section helpers ===== */
.section { padding: 3.5rem 0; }
.section-sm { padding: 2.25rem 0; }
.section-header {
  text-align: center;
  max-width: 640px;
  margin: 0 auto 2.5rem;
}
.section-header p { margin-top: 0.5rem; font-size: 0.92rem; max-width: 520px; margin-inline: auto; }

.page-header {
  display: flex; flex-wrap: wrap;
  align-items: flex-start; justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1.5rem;
}
.page-header p { margin-top: 0.35rem; }

.grid-2 { display: grid; grid-template-columns: repeat(2, 1fr); gap: 1.25rem; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1.25rem; }
.grid-4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 1.25rem; }
@media (max-width: 900px) {
  .grid-4 { grid-template-columns: repeat(2, 1fr); }
  .grid-3 { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 600px) {
  .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; }
}

.stack { display: flex; flex-direction: column; gap: 1rem; }
.stack-sm { display: flex; flex-direction: column; gap: 0.6rem; }
.row { display: flex; align-items: center; gap: 0.75rem; flex-wrap: wrap; }
.row-between { display: flex; align-items: center; justify-content: space-between; gap: 1rem; flex-wrap: wrap; }
.mt-1 { margin-top: 0.5rem; }
.mt-2 { margin-top: 1rem; }
.mt-3 { margin-top: 1.5rem; }
.mb-2 { margin-bottom: 1rem; }
.gap-1 { gap: 0.5rem; }
.text-center { text-align: center; }
.text-muted { color: var(--text-muted); }
.text-sm { font-size: 0.875rem; }
.text-xs { font-size: 0.75rem; }
.fw-700 { font-weight: 700; }
.w-full { width: 100%; }
