/* ===== RESET & BASE ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --blue: #1a6cff;
  --blue-dk: #0d4fcc;
  --blue-lt: rgba(26,108,255,.08);
  --navy: #0a0f2e;
  --text: #0f172a;
  --text2: #64748b;
  --text3: #94a3b8;
  --border: #e2e8f0;
  --border2: #cbd5e1;
  --bg: #f8fafc;
  --card: #ffffff;
  --radius: 10px;
  --radius-lg: 14px;
  --shadow: 0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.04);
  --shadow-md: 0 4px 16px rgba(0,0,0,.10);
}

html { scroll-behavior: smooth; }
body { font-family: 'Segoe UI', 'Noto Sans Thai', sans-serif; background: var(--bg); color: var(--text); line-height: 1.6; font-size: 15px; }
a { text-decoration: none; color: inherit; }
img { display: block; max-width: 100%; }
button { cursor: pointer; font-family: inherit; }

/* ===== NAVBAR ===== */
#navbar {
  position: sticky; top: 0; z-index: 100;
  background: rgba(10,15,46,.96);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid rgba(255,255,255,.08);
}
.nav-inner {
  max-width: 1140px; margin: 0 auto;
  display: flex; align-items: center; gap: 2rem;
  padding: 0 2rem; height: 64px;
}
.logo { font-size: 20px; font-weight: 600; color: #fff; letter-spacing: -.5px; }
.logo span { color: var(--blue); }
.nav-links { display: flex; gap: 1.75rem; margin-right: auto; }
.nav-links a { color: rgba(255,255,255,.65); font-size: 14px; transition: color .2s; }
.nav-links a:hover { color: #fff; }
.nav-btn {
  background: var(--blue); color: #fff; border: none;
  padding: 8px 20px; border-radius: var(--radius); font-size: 13px; font-weight: 500;
  transition: background .2s;
}
.nav-btn:hover { background: var(--blue-dk); }
.nav-hamburger { display: none; background: none; border: none; color: #fff; font-size: 22px; padding: 4px 8px; }

/* ===== HERO ===== */
.hero {
  background: linear-gradient(135deg, #0a0f2e 0%, #0f1a4a 55%, #091833 100%);
  padding: 90px 2rem 70px;
  position: relative; overflow: hidden;
}
.hero::before {
  content: '';
  position: absolute; inset: 0;
  background: radial-gradient(ellipse at 50% -10%, rgba(26,108,255,.18) 0%, transparent 65%);
  pointer-events: none;
}
.hero-inner { max-width: 680px; margin: 0 auto; text-align: center; position: relative; }
.hero-badge {
  display: inline-flex; align-items: center; gap: 7px;
  background: rgba(26,108,255,.14); border: 1px solid rgba(26,108,255,.3);
  color: #7aabff; padding: 6px 16px; border-radius: 20px;
  font-size: 12px; font-weight: 500; margin-bottom: 22px;
}
.hero h1 { font-size: clamp(30px,5vw,52px); font-weight: 600; color: #fff; line-height: 1.15; margin-bottom: 18px; }
.hero h1 span { color: var(--blue); }
.hero > .hero-inner > p { font-size: 15px; color: rgba(255,255,255,.58); max-width: 480px; margin: 0 auto 32px; line-height: 1.75; }
.hero-btns { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }
.btn-primary { background: var(--blue); color: #fff; border: none; padding: 11px 26px; border-radius: var(--radius); font-size: 14px; font-weight: 500; transition: background .2s; }
.btn-primary:hover { background: var(--blue-dk); }
.btn-outline { background: transparent; color: #fff; border: 1px solid rgba(255,255,255,.28); padding: 11px 26px; border-radius: var(--radius); font-size: 14px; transition: border-color .2s; }
.btn-outline:hover { border-color: rgba(255,255,255,.7); }
.stats-bar { display: flex; margin-top: 52px; border-top: 1px solid rgba(255,255,255,.07); padding-top: 36px; justify-content: center; }
.stat { padding: 0 36px; border-right: 1px solid rgba(255,255,255,.07); text-align: center; }
.stat:last-child { border-right: none; }
.stat-num { display: block; font-size: 26px; font-weight: 600; color: #fff; }
.stat-label { display: block; font-size: 11px; color: rgba(255,255,255,.4); margin-top: 3px; }

/* ===== SECTIONS ===== */
.section { padding: 72px 2rem; }
.section-alt { background: #f0f4ff; }
.container { max-width: 1140px; margin: 0 auto; }
.section-header { text-align: center; margin-bottom: 44px; }
.section-tag { font-size: 11px; font-weight: 600; color: var(--blue); letter-spacing: 1.6px; text-transform: uppercase; margin-bottom: 10px; }
.section-header h2 { font-size: clamp(22px,3vw,32px); font-weight: 600; }
.section-sub { font-size: 15px; color: var(--text2); margin-top: 8px; }

/* ===== SERVICES ===== */
.services-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px,1fr)); gap: 16px; }
.svc-card { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 1.5rem; transition: border-color .2s, box-shadow .2s; }
.svc-card:hover { border-color: var(--blue); box-shadow: var(--shadow-md); }
.svc-icon { width: 42px; height: 42px; background: var(--blue-lt); border-radius: 10px; display: flex; align-items: center; justify-content: center; margin-bottom: 14px; color: var(--blue); }
.svc-card h3 { font-size: 15px; font-weight: 600; margin-bottom: 6px; }
.svc-card p { font-size: 13px; color: var(--text2); line-height: 1.65; }

/* ===== DB STATUS ===== */
.db-status {
  padding: 10px 16px; border-radius: var(--radius); margin-bottom: 20px;
  font-size: 13px; display: none; align-items: center; gap: 8px;
}
.db-status.ok { background: #ecfdf5; border: 1px solid #6ee7b7; color: #065f46; display: flex; }
.db-status.err { background: #fef2f2; border: 1px solid #fca5a5; color: #991b1b; display: flex; }

/* ===== PORTFOLIO CONTROLS ===== */
.portfolio-controls { display: flex; justify-content: space-between; align-items: center; margin-bottom: 28px; gap: 12px; flex-wrap: wrap; }
.filter-btns { display: flex; gap: 8px; flex-wrap: wrap; }
.filter-btn {
  background: transparent; border: 1px solid var(--border2); color: var(--text2);
  padding: 7px 16px; border-radius: var(--radius); font-size: 13px; font-family: inherit;
  transition: all .2s;
}
.filter-btn:hover, .filter-btn.active { border-color: var(--blue); color: var(--blue); background: var(--blue-lt); }
.btn-add {
  display: flex; align-items: center; gap: 6px;
  background: var(--blue); color: #fff; border: none;
  padding: 9px 18px; border-radius: var(--radius); font-size: 13px; font-weight: 500;
  transition: background .2s;
}
.btn-add:hover { background: var(--blue-dk); }

/* ===== PORTFOLIO GRID ===== */
.portfolio-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(290px,1fr)); gap: 20px; }
.grid-loading { grid-column: 1/-1; text-align: center; padding: 60px 20px; color: var(--text3); }
.spinner { width: 32px; height: 32px; border: 3px solid var(--border); border-top-color: var(--blue); border-radius: 50%; animation: spin .7s linear infinite; margin: 0 auto 12px; }
@keyframes spin { to { transform: rotate(360deg); } }

.p-card { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius-lg); overflow: hidden; transition: transform .2s, box-shadow .2s; }
.p-card:hover { transform: translateY(-4px); box-shadow: var(--shadow-md); }
.p-card-img { width: 100%; aspect-ratio: 16/9; object-fit: cover; }
.p-card-placeholder { width: 100%; aspect-ratio: 16/9; display: flex; align-items: center; justify-content: center; }
.p-card-placeholder svg { opacity: .25; }
.p-card-body { padding: 1rem 1.2rem 1.25rem; }
.p-card-tags { display: flex; gap: 5px; flex-wrap: wrap; margin-bottom: 8px; }
.tag { font-size: 11px; padding: 3px 9px; border-radius: 20px; background: var(--blue-lt); color: var(--blue); }
.tag-cat { background: #f1f5f9; color: var(--text2); }
.p-card-title { font-size: 15px; font-weight: 600; margin-bottom: 4px; }
.p-card-desc { font-size: 13px; color: var(--text2); line-height: 1.55; }
.p-card-actions { display: flex; gap: 8px; margin-top: 12px; padding-top: 12px; border-top: 1px solid var(--border); }
.card-btn {
  display: flex; align-items: center; gap: 5px;
  background: transparent; border: 1px solid var(--border); color: var(--text2);
  padding: 5px 13px; border-radius: 7px; font-size: 12px; font-family: inherit;
  transition: all .2s;
}
.card-btn:hover { border-color: var(--border2); color: var(--text); }
.card-btn.danger:hover { border-color: #ef4444; color: #ef4444; }

.empty-state { grid-column: 1/-1; text-align: center; padding: 60px 20px; color: var(--text3); }
.empty-state p { margin-top: 8px; font-size: 13px; }

/* ===== CONTACT ===== */
.contact-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px,1fr)); gap: 16px; max-width: 720px; margin: 0 auto; }
.contact-card { text-align: center; }
.contact-card h3 { font-size: 15px; font-weight: 600; margin-bottom: 4px; }
.contact-card p { font-size: 13px; color: var(--text2); }

/* ===== FOOTER ===== */
footer { background: var(--navy); color: rgba(255,255,255,.35); text-align: center; padding: 28px 2rem; font-size: 13px; border-top: 1px solid rgba(255,255,255,.05); }

/* ===== MODAL ===== */
.modal-overlay {
  display: none; position: fixed; inset: 0;
  background: rgba(0,0,0,.55); z-index: 200;
  align-items: center; justify-content: center; padding: 20px;
}
.modal-overlay.open { display: flex; }
.modal { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius-lg); width: 100%; max-width: 540px; max-height: 90vh; overflow-y: auto; }
.modal-header { padding: 1.25rem 1.5rem; border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; }
.modal-header h3 { font-size: 16px; font-weight: 600; }
.modal-close { background: none; border: none; color: var(--text2); display: flex; align-items: center; padding: 4px; border-radius: 6px; transition: color .2s; }
.modal-close:hover { color: var(--text); }
.modal-body { padding: 1.5rem; }
.form-group { margin-bottom: 16px; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.form-label { display: block; font-size: 13px; font-weight: 500; color: var(--text2); margin-bottom: 6px; }
.required { color: #ef4444; }
.form-input, .form-select, .form-textarea {
  width: 100%; padding: 9px 12px; border: 1px solid var(--border); border-radius: var(--radius);
  font-size: 14px; font-family: inherit; background: #fff; color: var(--text); outline: none;
  transition: border-color .2s;
}
.form-input:focus, .form-select:focus, .form-textarea:focus { border-color: var(--blue); }
.form-textarea { resize: vertical; min-height: 82px; line-height: 1.55; }

.upload-area {
  display: block; border: 1.5px dashed var(--border2); border-radius: 10px;
  padding: 22px; text-align: center; cursor: pointer; position: relative; overflow: hidden;
  transition: border-color .2s;
}
.upload-area:hover { border-color: var(--blue); }
.upload-area input[type="file"] { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.upload-placeholder { pointer-events: none; }
.upload-placeholder svg { margin: 0 auto 8px; color: var(--text3); }
.upload-placeholder p { font-size: 13px; color: var(--text3); }
.img-preview { display: none; width: 100%; aspect-ratio: 16/9; object-fit: cover; border-radius: 8px; margin-top: 12px; }
.current-img-note { font-size: 12px; color: var(--text3); margin-top: 6px; }

.modal-footer { padding: 1rem 1.5rem; border-top: 1px solid var(--border); display: flex; gap: 10px; justify-content: flex-end; }
.btn-cancel { background: transparent; border: 1px solid var(--border); color: var(--text2); padding: 9px 20px; border-radius: var(--radius); font-size: 14px; font-family: inherit; transition: border-color .2s; }
.btn-cancel:hover { border-color: var(--border2); }
.btn-save { display: flex; align-items: center; gap: 8px; background: var(--blue); color: #fff; border: none; padding: 9px 22px; border-radius: var(--radius); font-size: 14px; font-weight: 500; font-family: inherit; transition: background .2s; }
.btn-save:hover { background: var(--blue-dk); }
.btn-save:disabled { opacity: .6; cursor: not-allowed; }
.btn-spinner { width: 14px; height: 14px; border: 2px solid rgba(255,255,255,.4); border-top-color: #fff; border-radius: 50%; animation: spin .6s linear infinite; }

/* ===== TOAST ===== */
.toast {
  position: fixed; bottom: 24px; right: 24px; z-index: 999;
  padding: 12px 20px; border-radius: var(--radius); font-size: 14px;
  transform: translateY(80px); opacity: 0; transition: all .3s; pointer-events: none;
}
.toast.show { transform: translateY(0); opacity: 1; }
.toast.success { background: #1a3a1a; border: 1px solid #4ade80; color: #86efac; }
.toast.error { background: #3a1a1a; border: 1px solid #f87171; color: #fca5a5; }

/* ===== RESPONSIVE ===== */
@media (max-width: 640px) {
  .nav-links { display: none; }
  .nav-hamburger { display: block; }
  .stats-bar { flex-wrap: wrap; gap: 16px; }
  .stat { border-right: none; }
  .form-row { grid-template-columns: 1fr; }
}
