/* =========================================================
   assets/css/app.css — บ้านเจริญมาศ Community Portal
   ========================================================= */

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

/* ─── CSS Variables ─────────────────────────────────────── */
:root {
  --green-dark:   #0a4a2e;
  --green-mid:    #1a7a4a;
  --green-light:  #2ea865;
  --green-pale:   #d4f0e0;
  --gold:         #c9a84c;
  --gold-light:   #f0d080;
  --cream:        #faf7f0;
  --text:         #1a1a1a;
  --text-mid:     #4a4a4a;
  --text-soft:    #888;
  --border:       rgba(0,0,0,0.08);
  --white:        #ffffff;
  --red-soft:     #fee2e2;
  --red:          #dc2626;
  --blue-soft:    #dbeafe;
  --blue:         #2563eb;
  --amber-soft:   #fef3c7;
  --amber:        #d97706;
  --r:            12px;
  --r-lg:         20px;
}

/* ─── Base ───────────────────────────────────────────────── */
html { font-size: 18px; }
body {
  font-family: 'Sarabun', sans-serif;
  background: var(--cream);
  color: var(--text);
  min-height: 100vh;
  overflow-x: hidden;
}

/* ─── Mobile Wrapper ─────────────────────────────────────── */
.app {
  max-width: 430px;
  margin: 0 auto;
  background: var(--cream);
  min-height: 100vh;
  position: relative;
}

/* ─── Status Bar ─────────────────────────────────────────── */
.statusbar {
  background: var(--green-dark);
  padding: 8px 20px 6px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.statusbar span {
  font-size: 11px;
  color: rgba(255,255,255,0.8);
  font-weight: 500;
  letter-spacing: .3px;
}

/* ─── Header ─────────────────────────────────────────────── */
.header {
  background: var(--green-dark);
  padding: 0 16px 20px;
  position: relative;
  overflow: hidden;
}
.header::before {
  content: '';
  position: absolute;
  top: -60px; right: -60px;
  width: 200px; height: 200px;
  border-radius: 50%;
  background: rgba(255,255,255,0.04);
}
.header::after {
  content: '';
  position: absolute;
  bottom: -40px; left: -30px;
  width: 140px; height: 140px;
  border-radius: 50%;
  background: rgba(46,168,101,0.15);
}
.header-top {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 0 14px;
  position: relative;
  z-index: 1;
}
.village-logo {
  width: 40px; height: 40px;
  border-radius: 10px;
  background: var(--gold);
  display: flex; align-items: center; justify-content: center;
  font-family: 'Noto Serif Thai', serif;
  font-size: 18px; font-weight: 700;
  color: var(--green-dark);
  flex-shrink: 0;
  letter-spacing: -1px;
}
.village-name { flex: 1; }
.village-name h1 {
  font-family: 'Noto Serif Thai', serif;
  font-size: 16px; font-weight: 700;
  color: #fff; line-height: 1.2;
}
.village-name p {
  font-size: 11px;
  color: rgba(255,255,255,0.6);
  margin-top: 1px;
}
.header-actions { display: flex; gap: 8px; align-items: center; }

/* Notification button */
.notif-btn {
  width: 34px; height: 34px;
  border-radius: 50%;
  background: rgba(255,255,255,0.12);
  border: none; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  position: relative;
  transition: background .2s;
  text-decoration: none;
}
.notif-btn:active { background: rgba(255,255,255,0.2); }
.notif-btn svg {
  width: 18px; height: 18px;
  fill: none; stroke: rgba(255,255,255,0.9); stroke-width: 1.8;
}
.notif-badge {
  position: absolute; top: 4px; right: 4px;
  min-width: 16px; height: 16px;
  border-radius: 8px;
  background: var(--gold);
  border: 1.5px solid var(--green-dark);
  font-size: 9px; font-weight: 700;
  color: var(--green-dark);
  display: flex; align-items: center; justify-content: center;
  padding: 0 3px;
}

/* Avatar button */
.avatar-btn {
  width: 34px; height: 34px;
  border-radius: 50%;
  background: var(--green-light);
  border: 2px solid rgba(255,255,255,0.3);
  display: flex; align-items: center; justify-content: center;
  font-size: 13px; font-weight: 600;
  color: #fff; cursor: pointer;
  transition: border-color .2s;
  text-decoration: none;
  overflow: hidden;
}
.avatar-btn img { width: 100%; height: 100%; object-fit: cover; }
.avatar-btn:active { border-color: var(--gold); }

/* Login link (logged out) */
.login-link {
  font-size: 13px; font-weight: 600;
  color: var(--gold);
  text-decoration: none;
  padding: 6px 14px;
  border: 1px solid rgba(201,168,76,0.5);
  border-radius: 20px;
  transition: background .2s;
}
.login-link:hover { background: rgba(201,168,76,0.1); }

/* Greeting */
.greeting {
  position: relative; z-index: 1;
  margin-bottom: 14px;
}
.greeting p {
  font-size: 12px;
  color: rgba(255,255,255,0.6);
  margin-bottom: 2px;
}
.greeting h2 {
  font-size: 18px; font-weight: 600;
  color: #fff; line-height: 1.3;
}

/* Status Card */
.status-card {
  position: relative; z-index: 1;
  background: rgba(255,255,255,0.1);
  border: 1px solid rgba(255,255,255,0.15);
  border-radius: var(--r);
  padding: 14px;
  backdrop-filter: blur(4px);
}
.status-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-bottom: 12px;
}
.status-item { text-align: center; }
.status-val {
  font-size: 22px; font-weight: 600;
  color: var(--gold-light);
  font-family: 'Noto Serif Thai', serif;
  line-height: 1;
}
.status-lbl {
  font-size: 10px;
  color: rgba(255,255,255,0.6);
  margin-top: 3px;
}
.status-divider {
  height: 1px;
  background: rgba(255,255,255,0.12);
  margin-bottom: 10px;
}
.status-alert { display: flex; align-items: center; gap: 8px; }
.alert-dot {
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--gold);
  flex-shrink: 0;
  animation: pulse 2s ease-in-out infinite;
}
@keyframes pulse {
  0%,100% { opacity: 1; transform: scale(1); }
  50% { opacity: .5; transform: scale(.7); }
}
.alert-txt { font-size: 11px; color: rgba(255,255,255,0.85); }

/* ─── Main Content ───────────────────────────────────────── */
.main { padding: 16px; }

/* Section header */
.sec-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 12px;
}
.sec-title {
  font-size: 13px; font-weight: 600;
  color: var(--text-mid);
  letter-spacing: .2px;
  text-transform: uppercase;
}
.sec-link {
  font-size: 12px; color: var(--green-mid);
  text-decoration: none; font-weight: 500;
}

/* ─── App Launcher ───────────────────────────────────────── */
.app-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin-bottom: 20px;
}
.app-item {
  background: var(--white);
  border-radius: var(--r);
  border: 1px solid var(--border);
  padding: 12px 8px 10px;
  text-align: center;
  cursor: pointer;
  transition: transform .15s, box-shadow .15s;
  text-decoration: none;
  display: block;
}
.app-item:active { transform: scale(0.94); }
.app-item:hover  { box-shadow: 0 4px 12px rgba(0,0,0,0.08); }
.app-icon-wrap {
  width: 56px; height: 56px;
  border-radius: 16px;
  margin: 0 auto 10px;
  display: flex; align-items: center; justify-content: center;
}
.app-icon-wrap svg {
  width: 28px; height: 28px;
  fill: none; stroke-width: 1.8;
  stroke-linecap: round; stroke-linejoin: round;
}
.app-name {
  font-size: 13px; font-weight: 600;
  color: var(--text); line-height: 1.3;
}
.app-count {
  font-size: 11px; color: var(--text-soft); margin-top: 2px;
}

/* App icon colors */
.ic-teal   { background: #d4f0e0; }
.ic-teal   svg { stroke: #0a7a45; }
.ic-amber  { background: var(--amber-soft); }
.ic-amber  svg { stroke: var(--amber); }
.ic-red    { background: var(--red-soft); }
.ic-red    svg { stroke: var(--red); }
.ic-blue   { background: var(--blue-soft); }
.ic-blue   svg { stroke: var(--blue); }
.ic-purple { background: #ede9fe; }
.ic-purple svg { stroke: #7c3aed; }
.ic-gray   { background: #f3f4f6; }
.ic-gray   svg { stroke: #4b5563; }

/* ─── Public Info Bar ────────────────────────────────────── */
.public-bar {
  background: var(--green-pale);
  border-radius: var(--r);
  padding: 10px 14px;
  margin-bottom: 20px;
  display: flex; align-items: center; gap: 10px;
  border: 1px solid rgba(10,74,46,0.1);
}
.public-bar svg {
  width: 16px; height: 16px;
  fill: none; stroke: var(--green-mid);
  stroke-width: 2; flex-shrink: 0;
}
.public-bar p {
  font-size: 12px; color: var(--green-dark);
  flex: 1; line-height: 1.4;
}
.public-bar a {
  font-size: 11px; color: var(--green-mid);
  font-weight: 600; white-space: nowrap;
  text-decoration: none;
}

/* ─── News Feed ──────────────────────────────────────────── */
.feed-section { margin-bottom: 20px; }

.news-card {
  background: var(--white);
  border-radius: var(--r-lg);
  border: 1px solid var(--border);
  margin-bottom: 10px;
  overflow: hidden;
  transition: transform .15s;
}
.news-card:active { transform: scale(0.98); }

/* Public strip */
.pub-strip {
  background: #f0fdf4;
  border-bottom: 1px solid rgba(10,74,46,0.08);
  padding: 6px 16px;
  display: flex; align-items: center; gap: 6px;
}
.pub-strip span { font-size: 12px; color: var(--green-mid); font-weight: 600; }
.pub-strip svg  { width: 13px; height: 13px; fill: none; stroke: var(--green-mid); stroke-width: 2; }

/* Card head */
.card-head {
  padding: 12px 14px 0;
  display: flex; align-items: center; gap: 8px;
}
.card-avatar {
  width: 32px; height: 32px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 11px; font-weight: 700;
  flex-shrink: 0;
}
.av-green { background: var(--green-pale); color: var(--green-dark); }
.av-amber { background: var(--amber-soft); color: #92400e; }
.av-blue  { background: var(--blue-soft);  color: #1e3a8a; }

.card-meta { flex: 1; }
.card-author { font-size: 15px; font-weight: 600; color: var(--text); }
.card-time   { font-size: 12px; color: var(--text-soft); margin-top: 1px; }

/* Badges */
.card-badge {
  font-size: 12px; font-weight: 600;
  padding: 4px 10px; border-radius: 20px;
}
.badge-announce { background: var(--green-pale); color: var(--green-dark); }
.badge-waste    { background: var(--amber-soft); color: #92400e; }
.badge-fund     { background: var(--blue-soft);  color: #1e3a8a; }
.badge-health   { background: var(--red-soft);   color: #991b1b; }
.badge-market   { background: #ede9fe;            color: #5b21b6; }
.badge-general  { background: #f3f4f6;            color: #374151; }

/* Card body */
.card-body { padding: 12px 16px 14px; }
.card-title {
  font-size: 17px; font-weight: 700;
  color: var(--text); line-height: 1.4;
  margin-bottom: 6px;
}
.card-excerpt { font-size: 15px; color: var(--text-mid); line-height: 1.65; }
.card-img {
  width: 100%; aspect-ratio: 16/9;
  background: linear-gradient(135deg, #d4f0e0 0%, #b7e0cd 100%);
  display: flex; align-items: center; justify-content: center;
  margin: 8px 0; border-radius: 8px;
  overflow: hidden; position: relative;
}
.card-img img { width: 100%; height: 100%; object-fit: cover; }

/* Card video preview (index feed) */
.card-video-wrap {
  width: 100%; aspect-ratio: 16/9;
  margin: 8px 0; border-radius: 8px;
  overflow: hidden; position: relative; background: #0f172a;
  display: block; cursor: pointer; text-decoration: none;
}
.card-video-wrap video {
  width: 100%; height: 100%; object-fit: cover; display: block;
}
.card-video-play {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
}
.card-video-play svg {
  width: 44px; height: 44px;
  filter: drop-shadow(0 2px 6px rgba(0,0,0,.5));
  transition: transform .15s;
}
.card-video-wrap:active .card-video-play svg { transform: scale(.9); }

/* Card footer */
.card-footer {
  padding: 10px 16px 14px;
  display: flex; align-items: center; gap: 18px;
  border-top: 1px solid var(--border);
}
.card-action {
  display: flex; align-items: center; gap: 6px;
  font-size: 14px; color: var(--text-soft);
  cursor: pointer; background: none; border: none;
  font-family: inherit;
  transition: color .15s;
  text-decoration: none;
}
.card-action:active { color: var(--green-mid); }
.card-action svg   { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; }
.card-action.liked { color: var(--red); }

/* ─── Flash Message ──────────────────────────────────────── */
.flash {
  padding: 12px 16px;
  font-size: 14px; font-weight: 500;
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px;
}
.flash-success { background: var(--green-pale); color: var(--green-dark); }
.flash-error   { background: var(--red-soft);   color: #991b1b; }
.flash-close {
  background: none; border: none; cursor: pointer;
  font-size: 18px; line-height: 1;
  color: inherit; opacity: .6;
}
.flash-close:hover { opacity: 1; }

/* ─── Login Banner (logged-out state) ────────────────────── */
.login-banner {
  background: var(--green-dark);
  border-radius: var(--r);
  padding: 16px; margin-bottom: 20px;
  display: flex; align-items: center; gap: 12px;
}
.login-banner-text { flex: 1; }
.login-banner-text h3 { font-size: 14px; font-weight: 600; color: #fff; margin-bottom: 3px; }
.login-banner-text p  { font-size: 11px; color: rgba(255,255,255,0.6); line-height: 1.4; }
.login-btn {
  background: var(--gold); color: var(--green-dark);
  border: none; cursor: pointer;
  padding: 9px 16px; border-radius: 8px;
  font-size: 12px; font-weight: 700;
  font-family: inherit; white-space: nowrap;
  transition: background .2s;
  text-decoration: none;
}
.login-btn:hover { background: var(--gold-light); }

/* ─── Bottom Nav ─────────────────────────────────────────── */
.bottom-nav {
  position: sticky; bottom: 0;
  background: var(--white);
  border-top: 1px solid var(--border);
  display: flex;
  padding: 8px 0 max(10px, env(safe-area-inset-bottom));
  z-index: 100;
}
.nav-item {
  flex: 1; text-align: center;
  cursor: pointer; padding: 4px 0;
  display: flex; flex-direction: column;
  align-items: center; gap: 4px;
  transition: transform .1s;
  text-decoration: none;
}
.nav-item:active { transform: scale(0.9); }
.nav-icon { width: 30px; height: 30px; position: relative; }
.nav-icon svg {
  width: 28px; height: 28px; fill: none;
  stroke: var(--text-soft); stroke-width: 1.8;
  stroke-linecap: round; stroke-linejoin: round;
}
.nav-item.active .nav-icon svg { stroke: var(--green-mid); }
.nav-lbl { font-size: 12px; color: var(--text-soft); font-weight: 500; }
.nav-item.active .nav-lbl { color: var(--green-mid); font-weight: 700; }
.nav-dot {
  width: 5px; height: 5px; border-radius: 50%;
  background: var(--green-mid);
  position: absolute; top: -2px; right: -2px;
}

/* ─── Page Load Animations ───────────────────────────────── */
.anim-in {
  opacity: 0; transform: translateY(14px);
  animation: fadeUp .4s ease forwards;
}
@keyframes fadeUp {
  to { opacity: 1; transform: translateY(0); }
}
.anim-in:nth-child(1) { animation-delay: .05s; }
.anim-in:nth-child(2) { animation-delay: .10s; }
.anim-in:nth-child(3) { animation-delay: .15s; }
.anim-in:nth-child(4) { animation-delay: .20s; }
.anim-in:nth-child(5) { animation-delay: .25s; }

.header { animation: fadeDown .35s ease forwards; }
@keyframes fadeDown {
  from { opacity: 0; transform: translateY(-8px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ─── Mobile Topbar (หน้า admin/module บนมือถือ) ────────── */
.mobile-topbar {
  background: var(--green-dark);
  display: flex; align-items: center;
  padding: 10px 16px; gap: 10px;
  position: sticky; top: 0; z-index: 200;
}
.mobile-topbar-logo {
  display: flex; align-items: center; gap: 10px;
  text-decoration: none; flex: 1;
}
@media (min-width: 768px) {
  .mobile-topbar { display: none; }
}


.topbar {
  background: var(--green-dark);
  position: sticky; top: 0; z-index: 200;
}
.topbar-inner {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 16px; gap: 10px;
}
.logo-wrap { display: flex; align-items: center; gap: 10px; text-decoration: none; }

/* ─── Page Content Wrapper ───────────────────────────────── */
.page-content { min-height: calc(100vh - 60px); }

/* ─── Desktop greeting inline (ซ่อนบน mobile) ─────────────── */
.header-greeting-inline { display: none; }

/* ─── Desktop Sidebar ────────────────────────────────────── */
.desktop-sidebar { display: none; }

@media (min-width: 768px) {
  html { font-size: 15px; }
  body { background: #e8ede8; }

  /* ── .app เต็มพื้นที่ขวา sidebar ─────────────────────── */
  .app {
    max-width: 100%;
    width: 100%;
    min-height: 100vh;
    background: #f5f5f0;
    border-radius: 0;
    box-shadow: none;
    margin: 0;
    overflow-x: hidden;
  }

  /* Sidebar fixed ซ้าย */
  .desktop-sidebar {
    display: flex; flex-direction: column;
    background: #0a4a2e;
    position: fixed; top: 0; left: 0;
    width: 240px; height: 100vh;
    overflow-y: auto; padding: 20px 0;
    z-index: 300;
  }
  .desktop-sidebar::-webkit-scrollbar { display: none; }

  /* .app เลื่อนขวาพ้น sidebar */
  body.has-sidebar .app { margin-left: 240px; }

  /* ── Sidebar styles ────────────────────────────────────── */
  .sb-logo {
    display: flex; align-items: center; gap: 12px;
    padding: 0 20px 20px;
    border-bottom: 1px solid rgba(255,255,255,0.08);
    margin-bottom: 16px;
  }
  .sb-logo-badge {
    width: 44px; height: 44px; border-radius: 10px;
    background: var(--gold);
    display: flex; align-items: center; justify-content: center;
    font-family: 'Noto Serif Thai', serif;
    font-size: 18px; font-weight: 700; color: #0a4a2e; flex-shrink: 0;
  }
  .sb-logo-text h2 { font-family: 'Noto Serif Thai', serif; font-size: 14px; font-weight: 700; color: #fff; line-height: 1.3; }
  .sb-logo-text p  { font-size: 10px; color: rgba(255,255,255,0.45); margin-top: 2px; }
  .sb-user {
    display: flex; align-items: center; gap: 10px;
    padding: 0 20px 16px;
    border-bottom: 1px solid rgba(255,255,255,0.08);
    margin-bottom: 8px;
  }
  .sb-avatar {
    width: 36px; height: 36px; border-radius: 50%;
    background: var(--green-light);
    display: flex; align-items: center; justify-content: center;
    font-size: 13px; font-weight: 700; color: #fff; flex-shrink: 0;
  }
  .sb-user strong { font-size: 13px; color: #fff; display: block; font-weight: 600; }
  .sb-user span   { font-size: 11px; color: rgba(255,255,255,0.45); }
  a.sb-user:hover { background: rgba(255,255,255,0.06); }
  .sb-section {
    font-size: 9px; letter-spacing: 1px; text-transform: uppercase;
    color: rgba(255,255,255,0.3); font-weight: 700;
    padding: 12px 20px 6px;
  }
  .sb-link {
    display: flex; align-items: center; gap: 10px;
    padding: 10px 20px; cursor: pointer;
    transition: background .15s;
    border-left: 3px solid transparent;
    text-decoration: none;
  }
  .sb-link:hover      { background: rgba(255,255,255,0.06); }
  .sb-link.active     { background: rgba(255,255,255,0.1); border-left-color: var(--gold); }
  .sb-link svg        { width: 16px; height: 16px; fill: none; stroke: rgba(255,255,255,0.45); stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex-shrink: 0; }
  .sb-link.active svg { stroke: rgba(255,255,255,0.9); }
  .sb-link span       { font-size: 13px; color: rgba(255,255,255,0.5); font-weight: 500; }
  .sb-link.active span{ color: #fff; font-weight: 600; }
  .sb-badge { margin-left: auto; font-size: 9px; font-weight: 700; padding: 1px 7px; border-radius: 10px; background: var(--gold); color: #0a4a2e; }

  /* ── Header ──────────────────────────────────────────── */
  .header {
    padding: 20px 40px 24px;
    border-radius: 0;
  }
  /* ทำให้ content ใน header กว้างเท่า .main */
  .header-top,
  .greeting,
  .status-card {
    max-width: calc(80% - 80px);
    box-sizing: border-box;
  }
  .header-top { padding: 0 0 14px; }

  /* ── Status card ใหญ่ขึ้น ─────────────────────────────── */
  .status-card  { padding: 20px 24px; margin-top: 0; }
  .status-grid  { gap: 60px; margin-bottom: 0; }
  .status-val   { font-size: 72px; }
  .status-lbl   { font-size: 24px; margin-top: 12px; }
  .greeting h2  { font-size: 42px; margin-bottom: 14px; }
  .greeting p   { font-size: 22px; }

  /* ── Main ────────────────────────────────────────────── */
  .main {
    padding: 24px 40px;
    max-width: 77%;
    overflow-x: hidden;
    box-sizing: border-box;
  }

  /* ── App Grid: 3 คอลัมน์ มี margin ขอบ ──────────────── */
  .app-grid {
    grid-template-columns: repeat(3, 1fr);
    gap: 16px;
    width: 100%;
    box-sizing: border-box;
  }
  .app-item      { padding: 20px 12px 16px; }
  .app-icon-wrap { width: 68px; height: 68px; border-radius: 18px; margin-bottom: 12px; }
  .app-icon-wrap svg { width: 34px; height: 34px; }
  .app-name      { font-size: 20px; }

  /* ── Public bar เต็มความกว้าง ───────────────────────── */
  .public-bar { border-radius: 12px; padding: 14px 20px; }

  /* ── Feed: กว้างเท่า app grid (100% ของ .main) ───────── */
  .feed-section  { display: block; max-width: 100%; width: 100%; }
  .sec-header    { margin-bottom: 14px; }
  .news-card     { margin-bottom: 16px; box-sizing: border-box; }

  /* ตัวหนังสือ card ───────────────────────────────────── */
  .card-author   { font-size: 26px; }
  .card-time     { font-size: 22px; }
  .card-title    { font-size: 28px; line-height: 1.4; }
  .card-excerpt  { font-size: 28px; line-height: 1.75; }
  .card-action   { font-size: 26px; }
  .card-avatar   { width: 44px; height: 44px; font-size: 16px; }
  .card-badge    { font-size: 17px; padding: 6px 14px; }

  /* ── ซ่อน mobile-only ────────────────────────────────── */
  .statusbar  { display: none; }
  .bottom-nav { display: none; }
}