:root {
  --primary: #0b6efd;
  --bg: #f6f8fa;
  --bg-offset: #fff;
  --text: #111;
  --muted: #6b7280;
  --border: #e5e7eb;
  --focus-ring: #0b6efd80;
}
[data-theme="dark"] {
  --primary: #388bfd;
  --bg: #0d1117;
  --bg-offset: #161b22;
  --text: #c9d1d9;
  --muted: #8b949e;
  --border: #30363d;
  --focus-ring: #388bfd80;
}

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

body{background:var(--bg);color:var(--text); transition: background .2s, color .2s; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol";}
.container{max-width:1024px;margin:0 auto;padding:1rem}
.topbar{background:var(--bg-offset);border-bottom:1px solid var(--border); padding: 0 .75rem; position: sticky; top: 0; z-index: 50; box-shadow: 0 1px 2px rgba(0,0,0,.04);} 
.topbar-inner { display: flex; align-items: center; gap: .75rem; }
.brand-wrapper { flex: 1 1 auto; min-width: 0; }
.brand { font-size:1.1rem; font-weight:600; text-decoration:none; color:var(--text); display:inline-block; padding:.75rem .25rem; line-height:1.1; }
.brand:focus-visible { outline:2px solid var(--focus-ring); outline-offset:2px; border-radius:4px; }
.topbar-rhs { display: flex; align-items: center; gap: .75rem; }
.nav { display:flex; align-items:center; flex-wrap:wrap; }
/* Force nav visible when body.nav-open (extra safety if media query race) */
.nav-open .nav { display:flex; }
.nav a { white-space:nowrap; }
.navlink{margin:0 .25rem; color: var(--text); text-decoration: none; font-weight: 500; padding: 0.5rem 0.7rem; border-radius: 6px; line-height:1; transition: background-color 0.2s, color .2s; }
.navlink:hover { background-color: var(--border); text-decoration: none; }
.navlink.logout-btn { background-color: var(--border); }
.navlink.logout-btn:hover { background-color: #fee2e2; color: #991b1b; }
[data-theme="dark"] .navlink.logout-btn:hover { background-color: #4f2323; color: #fca5a5; }
/* Mobile nav toggle */
.nav-toggle { background:none; border:1px solid var(--border); padding:.55rem; border-radius:6px; display:none; flex-direction:column; gap:4px; cursor:pointer; }
.nav-toggle:focus-visible { outline:2px solid var(--focus-ring); }
.nav-toggle .bar { width:20px; height:2px; background:var(--text); border-radius:2px; transition:transform .3s, opacity .3s; }
.nav-open .nav-toggle .bar:nth-child(1){ transform:translateY(6px) rotate(45deg);} 
.nav-open .nav-toggle .bar:nth-child(2){ opacity:0;} 
.nav-open .nav-toggle .bar:nth-child(3){ transform:translateY(-6px) rotate(-45deg);} 

/* Responsive layout helpers */
.stack-sm { display:flex; gap:1rem; }
@media (max-width: 860px){
  .nav-toggle { display:flex; }
  .topbar-inner { flex-wrap: wrap; }
  .topbar-rhs { width:100%; order: 3; }
  .nav { flex-direction:column; align-items:stretch; width:100%; display:none; padding:.25rem 0 .75rem; }
  .nav a { padding:.9rem .85rem; margin:0; border-radius:0; border-top:1px solid var(--border); }
  .nav a:first-child { border-top:0; }
  .nav-open .nav { display:flex; animation: fadeIn .25s ease; }
  .topbar { padding:.25rem .75rem; }
}

/* NGO dashboard responsive tweaks */
@media (max-width: 920px){
  .row.ngo-dashboard { flex-direction: column; }
  .ngo-primary, .ngo-secondary { flex: 1 1 auto !important; }
  .ngo-secondary .map-embed { height:220px; }
}
@media (max-width:600px){
  .project-card-grid { grid-template-columns: 1fr; }
  .map-embed, .map-embed-lg { height:240px; }
  input,select,textarea,button { font-size: 1rem; }
}

/* Utility & a11y helpers */
.sr-only { position:absolute; width:1px; height:1px; padding:0; margin:-1px; overflow:hidden; clip:rect(0 0 0 0); white-space:nowrap; border:0; }
.gap-sm { gap:.5rem; }
.gap-md { gap:1rem; }
.flex { display:flex; }
.flex-col { flex-direction:column; }
.w-100 { width:100%; }

.card{
  background:var(--bg-offset);
  border:1px solid var(--border);
  border-radius:8px;
  padding:1rem;
  margin:1rem 0;
  transition: all 0.2s ease-in-out;
  box-shadow: 0 1px 3px 0 rgba(0,0,0,0.07), 0 1px 2px 0 rgba(0,0,0,0.05);
}
.card:hover {
  transform: translateY(-2px);
  box-shadow: 0 10px 15px -3px rgba(0,0,0,0.1), 0 4px 6px -2px rgba(0,0,0,0.05);
}

.row{display:flex;gap:1rem;flex-wrap:wrap}
.col{flex:1 1 280px}
input,select,textarea{width:100%;padding:.6rem;border:1px solid var(--border);border-radius:8px; background: var(--bg); color: var(--text);}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--focus-ring); }
label{font-size:.9rem;color:var(--muted); display: block; margin-bottom: .75rem;}
button{
  background:var(--primary);
  color:#fff;
  border:0;
  border-radius:6px;
  padding:.6rem .9rem;
  cursor:pointer;
  transition: all 0.2s ease-in-out;
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
}
button:hover:not(:disabled) {
  transform: translateY(-1px);
  box-shadow: 0 4px 6px -1px rgba(0,0,0,0.1), 0 2px 4px -1px rgba(0,0,0,0.06);
}
button:active:not(:disabled) {
  transform: translateY(0);
}
button:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}
button.secondary{background:var(--border);color:var(--text)}
.flash{padding:.6rem .9rem;border-radius:6px;margin:.5rem 0}
.flash.error{background:#fee2e2;color:#991b1b}
.flash.ok{background:#dcfce7;color:#14532d}
.footer{color:var(--muted);font-size:.85rem;text-align:center;padding:1rem}

/* Skeleton Loader */
.skeleton {
  opacity: .7;
  animation: skeleton-loading 1s linear infinite alternate;
}
.skeleton-text {
  width: 100%;
  height: 0.7rem;
  margin-bottom: 0.5rem;
  border-radius: 0.25rem;
}
.skeleton-text:last-child {
  margin-bottom: 0;
  width: 80%;
}
@keyframes skeleton-loading {
  0% { background-color: hsl(200, 20%, 80%); }
  100% { background-color: hsl(200, 20%, 95%); }
}
[data-theme="dark"] .skeleton-text {
  background-color: var(--muted);
}
[data-theme="dark"] .skeleton {
  animation-name: skeleton-loading-dark;
}
@keyframes skeleton-loading-dark {
  0% { background-color: var(--border); }
  100% { background-color: var(--muted); }
}

/* Admin Table */
.admin-table{
  width: 100%;
  border-collapse: collapse;
  margin-top: 1rem;
}
.admin-table th, .admin-table td {
  border: 1px solid var(--border);
  padding: 0.75rem;
  text-align: left;
}
.admin-table th {
  background-color: var(--bg-offset);
}
.admin-table tr:nth-child(even) {
  background-color: var(--bg);
}
.admin-table .actions {
  display: flex;
  gap: 0.5rem;
}
.admin-table .actions button {
  padding: 0.3rem 0.6rem;
  font-size: 0.8rem;
}

/* Status Badges */
.status-badge {
  padding: 0.2rem 0.5rem;
  border-radius: 12px;
  font-size: 0.8rem;
  font-weight: 600;
  text-transform: uppercase;
}
.status-pending { background-color: #fef3c7; color: #92400e; }
.status-approved { background-color: #dcfce7; color: #14532d; }
.status-rejected { background-color: #fee2e2; color: #991b1b; }

/* NGO Project Cards */
.project-card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 1rem;
}
.project-card {
  background: var(--bg-offset);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}
.project-card h3 {
  margin-top: 0;
  font-size: 1.1rem;
}
.project-card-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 1rem;
}

/* Timeline for Updates */
.timeline {
  position: relative;
  padding-left: 2rem;
}
.timeline::before {
  content: '';
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 2px;
  background-color: var(--border);
}
.timeline-item {
  position: relative;
  margin-bottom: 1.5rem;
}
.timeline-item::before {
  content: '';
  position: absolute;
  left: -2rem;
  top: 4px;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background-color: var(--primary);
  border: 2px solid var(--bg-offset);
  transform: translateX(-5px);
}
.timeline-item .card {
  margin: 0;
}
.timeline-item .card:hover {
  transform: none;
  box-shadow: none;
}
.timeline-item-header {
  font-size: 0.9rem;
  color: var(--muted);
  margin-bottom: 0.5rem;
}

/* Pagination */
.pagination {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 1rem;
  color: var(--muted);
}

/* Animations */
#view {
  animation: fadeIn 0.4s ease-in-out;
}
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

/* Auth Page Layout */
.auth-container {
  display: flex;
  justify-content: center;
  align-items: center;
  padding-top: 5vh;
}
.auth-card {
  width: 100%;
  max-width: 420px;
}

/* Icons */
.icon {
  width: 1.1em;
  height: 1.1em;
}

/* Empty States & Previews */
.empty-state {
  text-align: center;
  padding: 2rem;
  color: var(--muted);
  background-color: var(--bg);
  border-radius: 6px;
}
.image-preview {
  max-width: 100%;
  height: auto;
  margin-top: 1rem;
  border-radius: 6px;
  border: 1px solid var(--border);
}

.muted { color: var(--muted); }

/* Map containers */
.map-embed { height: 280px; border-radius: 8px; overflow: hidden; border: 1px solid var(--border); }
.map-embed-lg { height: 360px; }

/* Theme Toggle */
.theme-toggle {
  background: none;
  border: 1px solid var(--border);
  color: var(--text);
  cursor: pointer;
  border-radius: 6px;
  width: 32px;
  height: 32px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.loader {
  border: 4px solid var(--bg-offset);
  border-top: 4px solid var(--primary);
  border-radius: 50%;
  width: 40px;
  height: 40px;
  animation: spin 1s linear infinite;
  margin: 2rem auto;
}
/* Buyer purchases table scroll container (scoped) */
.table-scroll--buyer { width:100%; overflow-x:auto; -webkit-overflow-scrolling:touch; }
.table-scroll--buyer table { min-width:640px; }

/* Admin table mobile handling: allow soft wrapping / horizontal scroll only below small widths */
@media (max-width: 640px){
  .admin-table th, .admin-table td { white-space: nowrap; }
  .admin-table-wrapper { overflow-x:auto; -webkit-overflow-scrolling:touch; }
  .admin-table-wrapper table { min-width:520px; }
}

/* Buyer form responsive */
@media (max-width: 760px){
  .buyer-form-row { flex-direction: column; }
  .buyer-form-row .col { max-width:100% !important; width:100%; }
  .buyer-form-row button { width:100%; }
}

/* Theme toggle visibility adjustments */
@media (max-width: 860px){
  .theme-toggle-desktop { display:none !important; }
  .theme-toggle-mobile { display:inline-flex; margin-top:.25rem; }
}
@media (min-width: 861px){
  .theme-toggle-mobile { display:none !important; }
}
@keyframes spin {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}

/* Form Enhancements */
form {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

form label {
    font-weight: 600;
    font-size: 0.9rem;
}

form input, form select, form textarea {
    margin-top: 0.25rem;
}
