/* ==========================================================
   Titatree.com — Design System
   Modern, minimal, responsive
   ========================================================== */

:root {
  /* ---- โทนสีตาม Design System ที่กำหนด ---- */
  --color-bg: #F8FAFC;          /* พื้นหลังหลัก */
  --color-surface: #ffffff;
  --color-header-bg: #0F172A;   /* Header / Navbar — Navy */
  --color-header-text: #E2E8F0;
  --color-text: #1E293B;        /* ตัวอักษรหลัก — Slate */
  --color-text-muted: #64748B;  /* ตัวอักษรรอง — Gray */
  --color-primary: #7C3AED;     /* สีหลัก / ปุ่มสำคัญ — Purple */
  --color-primary-dark: #6D28D9;
  --color-accent: #06B6D4;      /* สีรอง — Cyan */
  --color-code-bg: #111827;     /* Code Block — Dark Navy */
  --color-success: #10B981;     /* สำเร็จ / ดาวน์โหลด — Green */
  --color-border: #E2E8F0;
  --color-success-bg: #ECFDF5;
  --color-success-text: #047857;
  --color-error-bg: #FEF2F2;
  --color-error-text: #991B1B;
  --radius-sm: 6px;
  --radius-md: 12px;
  --radius-lg: 20px;
  --shadow-sm: 0 1px 3px rgba(15,23,42,0.06);
  --shadow-md: 0 4px 16px rgba(15,23,42,0.10);
  --font-body: -apple-system, BlinkMacSystemFont, "Segoe UI", "Sarabun", "Noto Sans Thai", sans-serif;
  --max-width: 1120px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --color-bg: #0F172A;
    --color-surface: #1E293B;
    --color-text: #F1F5F9;
    --color-text-muted: #94A3B8;
    --color-border: #334155;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--font-body);
  background: var(--color-bg);
  color: var(--color-text);
  line-height: 1.7;
  -webkit-font-smoothing: antialiased;
}

.container { max-width: var(--max-width); margin: 0 auto; padding: 0 1.25rem; }
.section { padding: 3rem 1.25rem; }
img { max-width: 100%; display: block; }
a { color: inherit; text-decoration: none; }

h1, h2, h3 { line-height: 1.3; margin: 0 0 0.75rem; }
h1 { font-size: clamp(1.75rem, 4vw, 2.5rem); }
h2 { font-size: clamp(1.4rem, 3vw, 1.8rem); }

/* ---------- Header ---------- */
.site-header {
  background: var(--color-header-bg);
  border-bottom: 1px solid rgba(255,255,255,.08);
  position: sticky; top: 0; z-index: 50;
}
.header-inner { display: flex; align-items: center; justify-content: space-between; padding: 1rem 1.25rem; }
.logo { font-weight: 700; font-size: 1.2rem; color: #fff; }
.main-nav { display: flex; gap: 1.5rem; }
.main-nav a { color: var(--color-header-text); font-weight: 500; transition: color .15s; }
.main-nav a:hover { color: var(--color-accent); }
.nav-toggle { display: none; background: none; border: none; font-size: 1.5rem; cursor: pointer; color: #fff; }

@media (max-width: 720px) {
  .main-nav {
    position: absolute; top: 100%; left: 0; right: 0;
    background: var(--color-header-bg); flex-direction: column; gap: 0;
    border-bottom: 1px solid rgba(255,255,255,.08);
    display: none;
  }
  .main-nav.open { display: flex; }
  .main-nav a { padding: 0.9rem 1.25rem; border-top: 1px solid rgba(255,255,255,.08); }
  .nav-toggle { display: block; }
}

/* ---------- Hero ---------- */
.hero {
  background: linear-gradient(135deg, var(--color-header-bg) 0%, var(--color-primary) 100%);
  color: #fff; padding: 4.5rem 1.25rem; text-align: center;
}
.hero h1 { color: #fff; margin-bottom: .5rem; }
.hero-sub { opacity: .9; margin-bottom: 1.5rem; }
.hero-actions { display: flex; gap: 1rem; justify-content: center; flex-wrap: wrap; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-block; padding: 0.7rem 1.4rem; border-radius: var(--radius-sm);
  font-weight: 600; cursor: pointer; border: 2px solid transparent; transition: all .15s;
  font-size: .95rem;
}
.btn-primary { background: var(--color-primary); color: #fff; }
.btn-primary:hover { background: var(--color-primary-dark); }
.btn-success { background: var(--color-success); color: #fff; }
.btn-success:hover { filter: brightness(1.08); }
.btn-outline { border-color: var(--color-border); color: var(--color-text); }
.hero .btn-outline, .btn-outline.on-dark { border-color: rgba(255,255,255,.6); color: #fff; }
.btn-outline:hover { background: rgba(124,58,237,.06); }
.hero .btn-outline:hover, .btn-outline.on-dark:hover { background: rgba(255,255,255,.1); }
.btn-block { width: 100%; text-align: center; }

/* ---------- Sections & Cards ---------- */
.section-head { display: flex; align-items: baseline; justify-content: space-between; margin-bottom: 1.25rem; }
.link-more { color: var(--color-primary); font-weight: 600; }
.link-back { display: inline-block; margin-bottom: 1.5rem; color: var(--color-primary); font-weight: 600; }

.card-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 1.5rem;
}
.card {
  background: var(--color-surface); border: 1px solid var(--color-border); border-radius: var(--radius-md);
  overflow: hidden; box-shadow: var(--shadow-sm); transition: transform .15s, box-shadow .15s;
}
a.card:hover { transform: translateY(-3px); box-shadow: var(--shadow-md); }
.card-thumb { aspect-ratio: 16/9; background: var(--color-border); overflow: hidden; }
.card-thumb img { width: 100%; height: 100%; object-fit: cover; }
.thumb-placeholder { width: 100%; height: 100%; display: flex; align-items: center; justify-content: center; font-size: 2.5rem; }
.thumb-placeholder.large { font-size: 5rem; }
.card-body { padding: 1rem 1.1rem; }
.badge { display: inline-block; font-size: .75rem; font-weight: 600; color: var(--color-primary); background: rgba(124,58,237,.1); padding: .2rem .6rem; border-radius: 999px; margin-bottom: .5rem; }
.badge-green { color: var(--color-success-text); background: var(--color-success-bg); }
.badge-gray { color: var(--color-text-muted); background: var(--color-border); }
code { background: var(--color-code-bg); color: #E2E8F0; padding: .15rem .45rem; border-radius: 4px; font-size: .85em; }
.tech-stack { color: var(--color-text-muted); font-size: .85rem; margin: .25rem 0 0; }

.video-embed { position: relative; aspect-ratio: 16/9; background: #000; }
.video-embed iframe { width: 100%; height: 100%; border: 0; }

/* YouTube facade (โหลดแค่ thumbnail จนกว่าจะคลิก เพื่อความเร็วของหน้าเว็บ) */
.yt-facade {
  width: 100%; height: 100%; border: 0; cursor: pointer;
  background-size: cover; background-position: center; position: relative;
}
.yt-facade::after {
  content: ""; position: absolute; inset: 0; margin: auto; width: 60px; height: 42px;
  background: rgba(0,0,0,.65) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='white'%3E%3Cpath d='M8 5v14l11-7z'/%3E%3C/svg%3E") no-repeat center / 22px;
  border-radius: 10px; transition: background-color .15s;
}
.yt-facade:hover::after { background-color: rgba(220,38,38,.85); }

.empty-state { color: var(--color-text-muted); padding: 2rem 0; text-align: center; grid-column: 1 / -1; }

/* ---------- Filter bar ---------- */
.filter-bar { display: flex; gap: .75rem; margin: 1.5rem 0 2rem; flex-wrap: wrap; }
.filter-bar input, .filter-bar select {
  padding: .65rem .9rem; border: 1px solid var(--color-border); border-radius: var(--radius-sm);
  background: var(--color-surface); color: var(--color-text); font-size: .95rem;
}
.filter-bar input { flex: 1; min-width: 200px; }

/* ---------- Detail page ---------- */
.detail-layout { display: grid; grid-template-columns: 1fr 1.4fr; gap: 2rem; align-items: start; }
.detail-thumb img, .detail-thumb .thumb-placeholder { border-radius: var(--radius-md); }
.detail-actions { display: flex; gap: 1rem; margin-top: 1.5rem; flex-wrap: wrap; }
@media (max-width: 800px) { .detail-layout { grid-template-columns: 1fr; } }

/* ---------- Profile / About ---------- */
.profile-header { display: flex; gap: 1.5rem; align-items: center; margin-bottom: 2rem; flex-wrap: wrap; }
.profile-photo { width: 120px; height: 120px; border-radius: 50%; object-fit: cover; background: var(--color-border); }
.profile-photo-placeholder { display: flex; align-items: center; justify-content: center; font-size: 2.5rem; }
.profile-nickname { color: var(--color-text-muted); margin: 0; }
.prose { margin-bottom: 2rem; }
.contact-list { list-style: none; padding: 0; }
.contact-list li { margin-bottom: .5rem; }
.donation-box { background: var(--color-surface); border: 1px solid var(--color-border); border-radius: var(--radius-md); padding: 1.5rem; }

/* ---------- Alerts ---------- */
.alert { padding: .9rem 1.1rem; border-radius: var(--radius-sm); margin: 1rem 0; font-weight: 500; }
.alert-success { background: var(--color-success-bg); color: var(--color-success-text); }
.alert-error { background: var(--color-error-bg); color: var(--color-error-text); }

/* ---------- Footer ---------- */
.site-footer { border-top: 1px solid var(--color-border); padding: 2rem 1.25rem; text-align: center; color: var(--color-text-muted); margin-top: 3rem; }
.footer-sub { font-size: .85rem; }

/* ==========================================================
   Admin Panel
   ========================================================== */
.admin-body { background: var(--color-bg); }
.admin-shell { display: flex; min-height: 100vh; }
.admin-sidebar {
  width: 240px; background: var(--color-header-bg); border-right: 1px solid rgba(255,255,255,.08);
  padding: 1.5rem 1rem; display: flex; flex-direction: column; gap: 1.5rem; position: sticky; top: 0; height: 100vh;
}
.admin-logo { font-weight: 700; font-size: 1.1rem; color: #fff; }
.admin-nav { display: flex; flex-direction: column; gap: .25rem; flex: 1; }
.admin-nav a { padding: .6rem .75rem; border-radius: var(--radius-sm); color: var(--color-header-text); font-weight: 500; }
.admin-nav a:hover { background: rgba(255,255,255,.08); color: #fff; }
.logout-form { margin-top: auto; }
.btn-logout { width: 100%; padding: .6rem; border: 1px solid rgba(255,255,255,.15); background: none; border-radius: var(--radius-sm); cursor: pointer; color: var(--color-header-text); font-size: .85rem; }
.admin-main { flex: 1; padding: 2rem; max-width: 900px; }

@media (max-width: 800px) {
  .admin-shell { flex-direction: column; }
  .admin-sidebar { width: 100%; height: auto; position: static; flex-direction: row; overflow-x: auto; }
  .admin-nav { flex-direction: row; }
  .logout-form { margin-top: 0; }
}

.admin-toolbar { display: flex; justify-content: space-between; align-items: center; margin-bottom: 1.5rem; flex-wrap: wrap; gap: 1rem; }
.admin-table { width: 100%; border-collapse: collapse; background: var(--color-surface); border-radius: var(--radius-md); overflow: hidden; box-shadow: var(--shadow-sm); }
.admin-table th, .admin-table td { padding: .75rem 1rem; text-align: left; border-bottom: 1px solid var(--color-border); font-size: .9rem; }
.admin-table th { background: var(--color-bg); font-weight: 600; }
.table-actions a, .table-actions button { margin-right: .75rem; color: var(--color-primary); font-weight: 600; background: none; border: none; cursor: pointer; font-size: .9rem; padding: 0; }
.link-danger { color: #dc2626 !important; }

.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 1rem; margin-bottom: 2rem; }
.stat-card { background: var(--color-surface); border: 1px solid var(--color-border); border-radius: var(--radius-md); padding: 1.5rem; text-align: center; }
.stat-num { display: block; font-size: 2rem; font-weight: 700; color: var(--color-primary); }
.stat-label { color: var(--color-text-muted); font-size: .85rem; }
.quick-actions { display: flex; gap: 1rem; flex-wrap: wrap; }

.admin-form { display: flex; flex-direction: column; gap: 1.1rem; max-width: 640px; }
.admin-form label { display: flex; flex-direction: column; gap: .4rem; font-weight: 600; font-size: .9rem; }
.admin-form input[type=text], .admin-form input[type=url], .admin-form input[type=email],
.admin-form input[type=password], .admin-form textarea, .admin-form select {
  font-weight: 400; padding: .65rem .8rem; border: 1px solid var(--color-border); border-radius: var(--radius-sm);
  background: var(--color-surface); color: var(--color-text); font-size: .95rem; font-family: inherit;
}
.checkbox-label { flex-direction: row !important; align-items: center; gap: .5rem !important; }
.form-actions { display: flex; gap: 1rem; margin-top: .5rem; }

/* ---------- Login ---------- */
.login-body { display: flex; align-items: center; justify-content: center; min-height: 100vh; background: var(--color-bg); }
.login-box { background: var(--color-surface); border: 1px solid var(--color-border); border-radius: var(--radius-lg); padding: 2.5rem; width: 100%; max-width: 380px; box-shadow: var(--shadow-md); }
.login-box form { display: flex; flex-direction: column; gap: 1rem; margin-top: 1.25rem; }
.login-box label { display: flex; flex-direction: column; gap: .4rem; font-weight: 600; font-size: .9rem; }
.login-box input { padding: .7rem .9rem; border: 1px solid var(--color-border); border-radius: var(--radius-sm); font-size: .95rem; }
