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

:root {
  --pri:    #4f46e5;
  --pri-dk: #3730a3;
  --acc:    #f59e0b;
  --bg:     #f1f5f9;
  --surf:   #ffffff;
  --bdr:    #e2e8f0;
  --txt:    #1e293b;
  --muted:  #64748b;
  --r:      12px;
  --sh:     0 1px 3px rgba(0,0,0,.07), 0 4px 16px rgba(0,0,0,.06);
  --sh-lg:  0 8px 32px rgba(0,0,0,.12);
}

body { font-family: 'Segoe UI','Noto Sans Thai',sans-serif; background: var(--bg); color: var(--txt); min-height: 100vh; }
a    { text-decoration: none; color: inherit; }
img  { display: block; }

/* ── NAVBAR ─────────────────────────────────────── */
.navbar {
  height: 60px; padding: 0 24px;
  display: flex; align-items: center; gap: 12px;
  background: var(--surf); border-bottom: 1px solid var(--bdr);
  position: sticky; top: 0; z-index: 100;
  box-shadow: 0 1px 4px rgba(0,0,0,.06);
}
.brand { font-size: 1.2rem; font-weight: 700; color: var(--pri); flex: 1; }
.nav-right { display: flex; align-items: center; gap: 10px; }

/* ── VIEW TOGGLE ─────────────────────────────────── */
.view-toggle {
  display: flex; overflow: hidden;
  border: 1.5px solid var(--bdr); border-radius: 8px;
}
.view-toggle button {
  padding: 7px 12px; border: none; background: transparent;
  cursor: pointer; font-size: 1rem; color: var(--muted); transition: .15s;
}
.view-toggle button.active { background: var(--pri); color: #fff; }

/* ── BUTTONS ─────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 8px 16px; border-radius: 8px; border: none;
  cursor: pointer; font-size: .875rem; font-weight: 500;
  transition: .15s; white-space: nowrap; font-family: inherit;
}
.btn-primary { background: var(--pri); color: #fff; }
.btn-primary:hover { background: var(--pri-dk); }
.btn-outline  { background: transparent; color: var(--pri); border: 1.5px solid var(--pri); }
.btn-outline:hover { background: var(--pri); color: #fff; }
.btn-ghost    { background: transparent; color: var(--muted); border: 1.5px solid var(--bdr); }
.btn-ghost:hover { background: var(--bg); color: var(--txt); }
.btn-danger   { background: #ef4444; color: #fff; }
.btn-danger:hover { background: #dc2626; }
.btn-sm { padding: 5px 10px; font-size: .8rem; }
.full { width: 100%; justify-content: center; }

/* ── CONTAINER ───────────────────────────────────── */
.container { max-width: 1200px; margin: 0 auto; padding: 32px 24px; }

/* ── TOOLBAR ─────────────────────────────────────── */
.toolbar {
  display: flex; align-items: center; justify-content: space-between;
  flex-wrap: wrap; gap: 12px; margin-bottom: 24px;
}
.toolbar-left { display: flex; align-items: center; gap: 10px; }
.toolbar-left h2 { font-size: 1.25rem; font-weight: 700; }

.badge {
  background: #e0e7ff; color: var(--pri);
  font-size: .75rem; font-weight: 700;
  padding: 3px 10px; border-radius: 20px;
}

.filter-tabs { display: flex; gap: 8px; }
.tab {
  padding: 6px 16px; border-radius: 20px;
  border: 1.5px solid var(--bdr); background: var(--surf);
  color: var(--muted); cursor: pointer; font-size: .85rem; font-weight: 500;
  transition: .15s; font-family: inherit;
}
.tab.active { background: var(--pri); color: #fff; border-color: var(--pri); }

/* ── GRID VIEW ───────────────────────────────────── */
.grid-view {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
  gap: 20px;
}

.card {
  background: var(--surf); border-radius: var(--r);
  box-shadow: var(--sh); overflow: hidden;
  transition: transform .2s, box-shadow .2s;
  position: relative;
}
.card:hover { transform: translateY(-4px); box-shadow: var(--sh-lg); }

.card-img {
  width: 100%; aspect-ratio: 16/9; object-fit: cover;
}
.card-img-ph {
  width: 100%; aspect-ratio: 16/9;
  background: linear-gradient(135deg,#e0e7ff,#c7d2fe);
  display: flex; align-items: center; justify-content: center;
  font-size: 3rem; color: var(--pri);
}
.card-body { padding: 16px; }
.card-title    { font-size: 1rem; font-weight: 600; margin-bottom: 4px; }
.card-subtitle { font-size: .85rem; color: var(--muted); line-height: 1.4; }

/* ── LIST VIEW ───────────────────────────────────── */
.list-view { display: flex; flex-direction: column; gap: 12px; }

.list-item {
  background: var(--surf); border-radius: var(--r);
  box-shadow: var(--sh);
  display: flex; align-items: center; gap: 16px;
  padding: 14px 16px;
  transition: transform .2s, box-shadow .2s;
  position: relative;
}
.list-item:hover { transform: translateX(4px); box-shadow: var(--sh-lg); }

.li-img {
  width: 80px; height: 58px; border-radius: 8px;
  object-fit: cover; flex-shrink: 0;
}
.li-img-ph {
  width: 80px; height: 58px; border-radius: 8px; flex-shrink: 0;
  background: linear-gradient(135deg,#e0e7ff,#c7d2fe);
  display: flex; align-items: center; justify-content: center;
  font-size: 1.5rem; color: var(--pri);
}
.li-body     { flex: 1; min-width: 0; }
.li-title    { font-size: 1rem; font-weight: 600; }
.li-subtitle { font-size: .85rem; color: var(--muted); margin-top: 2px; }
.li-date     { font-size: .75rem; color: var(--muted); margin-top: 4px; }

/* ── FAV BUTTON ──────────────────────────────────── */
.fav-btn {
  width: 32px; height: 32px; border-radius: 50%;
  border: none; cursor: pointer;
  background: rgba(255,255,255,.88); backdrop-filter: blur(4px);
  display: flex; align-items: center; justify-content: center;
  transition: transform .15s, color .15s; box-shadow: 0 1px 6px rgba(0,0,0,.12);
  color: #94a3b8; flex-shrink: 0;
}
.fav-btn:hover { transform: scale(1.15); color: #f59e0b; }
.fav-btn[title="ลบออกจาก Favorites"] { color: #f59e0b; }

/* absolute positioning for grid cards */
.card .fav-btn { position: absolute; top: 10px; right: 10px; }

/* ── EMPTY STATE ─────────────────────────────────── */
.empty-state {
  text-align: center; padding: 80px 24px; color: var(--muted);
}
.empty-state .ico { font-size: 4rem; margin-bottom: 16px; }
.empty-state h3   { font-size: 1.2rem; color: var(--txt); margin-bottom: 8px; }

/* ── TOAST ───────────────────────────────────────── */
.toast-box { position: fixed; bottom: 24px; right: 24px; z-index: 2000; display: flex; flex-direction: column; gap: 10px; }
.toast {
  background: #1e293b; color: #fff;
  padding: 12px 20px; border-radius: 10px; font-size: .875rem;
  box-shadow: var(--sh-lg);
  transform: translateX(120%); transition: transform .3s ease;
}
.toast.show { transform: translateX(0); }
.toast.ok  { background: #166534; }
.toast.err { background: #991b1b; }

/* ── AUTH ────────────────────────────────────────── */
.auth-bg { background: linear-gradient(135deg,#e0e7ff 0%,var(--bg) 60%); }
.auth-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; }
.auth-card {
  background: var(--surf); border-radius: 16px; padding: 40px;
  width: 100%; max-width: 400px; box-shadow: var(--sh-lg);
}
.auth-card h1 { font-size: 1.5rem; font-weight: 700; color: var(--pri); margin-bottom: 6px; }
.auth-card .sub { color: var(--muted); font-size: .9rem; margin-bottom: 28px; }
.auth-card label { display: block; font-size: .875rem; font-weight: 500; margin-bottom: 6px; margin-top: 16px; }
.auth-card .inp:first-of-type { margin-top: 0; }
.auth-card button { margin-top: 24px; }
.back { text-align: center; margin-top: 20px; font-size: .85rem; }
.back a { color: var(--pri); }

/* ── INPUTS ──────────────────────────────────────── */
.inp {
  width: 100%; padding: 10px 14px;
  border: 1.5px solid var(--bdr); border-radius: 8px;
  font-size: .9rem; font-family: inherit;
  background: var(--surf); transition: border-color .15s;
}
.inp:focus { outline: none; border-color: var(--pri); }

/* ── ALERT ───────────────────────────────────────── */
.alert { padding: 12px 16px; border-radius: 8px; font-size: .9rem; font-weight: 500; margin-bottom: 20px; }
.alert.ok  { background: #dcfce7; color: #166534; border: 1px solid #86efac; }
.alert.err { background: #fef2f2; color: #991b1b; border: 1px solid #fca5a5; }

/* ── ADMIN LAYOUT ────────────────────────────────── */
.admin-layout { display: grid; grid-template-columns: 240px 1fr; min-height: 100vh; }

.sidebar {
  background: #0f172a; color: #fff; padding: 0;
  display: flex; flex-direction: column;
}
.sidebar-brand {
  padding: 20px 20px 16px; font-size: 1.1rem; font-weight: 700;
  border-bottom: 1px solid rgba(255,255,255,.1); margin-bottom: 8px;
}
.nav-link {
  display: flex; align-items: center; gap: 8px;
  padding: 11px 20px; color: rgba(255,255,255,.65);
  font-size: .9rem; transition: .15s;
}
.nav-link:hover, .nav-link.active { background: rgba(255,255,255,.1); color: #fff; }
.nav-link.danger { color: #f87171; margin-top: auto; }

.admin-main { padding: 32px; background: var(--bg); }
.page-header { margin-bottom: 28px; }
.page-header h1 { font-size: 1.4rem; font-weight: 700; }
.page-header p  { color: var(--muted); font-size: .9rem; margin-top: 4px; }

/* form card */
.card-plain {
  background: var(--surf); border-radius: var(--r);
  box-shadow: var(--sh); padding: 28px; margin-bottom: 28px;
}
.card-plain h3 { font-size: 1rem; font-weight: 700; margin-bottom: 20px; }

.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.form-group { margin-bottom: 18px; }
.form-group label { display: block; font-size: .875rem; font-weight: 500; margin-bottom: 6px; }
.req { color: #ef4444; }
.form-actions { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 4px; }

/* drop zone */
.drop-zone {
  border: 2px dashed var(--bdr); border-radius: 10px;
  padding: 24px; text-align: center; cursor: pointer;
  transition: border-color .15s, background .15s;
  display: flex; flex-direction: column; align-items: center; gap: 6px;
}
.drop-zone:hover { border-color: var(--pri); background: #eef2ff; }
.drop-zone input[type=file] { display: none; }
.drop-icon { font-size: 2rem; }
.drop-text { font-weight: 500; font-size: .9rem; }
.drop-zone small { color: var(--muted); font-size: .8rem; }
#img-preview { max-width: 180px; max-height: 130px; border-radius: 8px; object-fit: cover; margin-top: 8px; }

/* table */
.tbl-wrap { background: var(--surf); border-radius: var(--r); box-shadow: var(--sh); overflow: hidden; }
table { width: 100%; border-collapse: collapse; }
th {
  background: var(--bg); padding: 12px 16px; text-align: left;
  font-size: .78rem; font-weight: 700; color: var(--muted);
  text-transform: uppercase; letter-spacing: .05em;
  border-bottom: 1px solid var(--bdr);
}
td { padding: 13px 16px; border-bottom: 1px solid var(--bdr); font-size: .9rem; vertical-align: middle; }
tr:last-child td { border-bottom: none; }
tr:hover td { background: var(--bg); }
.tbl-img    { width: 60px; height: 42px; border-radius: 6px; object-fit: cover; }
.tbl-img-ph {
  width: 60px; height: 42px; border-radius: 6px;
  background: #e0e7ff; display: flex; align-items: center;
  justify-content: center; font-size: 1.2rem; color: var(--pri);
}
.fw    { font-weight: 600; }
.muted { color: var(--muted); }
.sm    { font-size: .82rem; }
.empty-row { text-align: center; color: var(--muted); padding: 40px !important; }

/* link column */
.tbl-link { color: var(--pri); text-decoration: none; font-size: .82rem; }
.tbl-link:hover { text-decoration: underline; }
.no-link  { color: var(--muted); }
.card-link { text-decoration: none; color: inherit; cursor: pointer; }
.card-link:hover { box-shadow: 0 6px 24px rgba(99,102,241,.18); transform: translateY(-2px); }

/* drag-and-drop reorder */
.drag-col  { width: 32px; padding: 0 8px !important; }
.drag-handle {
  width: 32px; cursor: grab; text-align: center;
  font-size: 1.1rem; color: var(--muted); user-select: none;
  padding: 0 8px !important;
}
.drag-handle:active { cursor: grabbing; }
.row-ghost td { background: #eef2ff !important; opacity: .7; }
.sort-toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%) translateY(20px);
  background: #1e293b; color: #fff; padding: 10px 20px; border-radius: 8px;
  font-size: .88rem; opacity: 0; transition: opacity .25s, transform .25s; pointer-events: none; z-index: 999;
}
.sort-toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.sort-toast.ok   { background: var(--ok, #16a34a); }
.sort-toast.err  { background: var(--err, #dc2626); }

/* ── RESPONSIVE ──────────────────────────────────── */
@media (max-width: 768px) {
  .admin-layout { grid-template-columns: 1fr; }
  .sidebar { display: none; }
  .grid-view { grid-template-columns: repeat(auto-fill, minmax(160px,1fr)); gap: 12px; }
  .container { padding: 16px; }
  .form-row  { grid-template-columns: 1fr; }
  .toolbar   { flex-direction: column; align-items: flex-start; }
}
