/* ===== Padlet Clone — สไตล์ ===== */
:root {
  --bar: rgba(255, 255, 255, .92);
  --txt: #1f2430;
  --muted: #6b7280;
  --line: rgba(0, 0, 0, .08);
  --shadow: 0 6px 18px rgba(0, 0, 0, .14);
  --radius: 14px;
  --brand: #6d5efc;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: "Segoe UI", system-ui, "Noto Sans Thai", sans-serif;
  color: var(--txt);
  overflow: hidden;
}

/* ---------- พื้นหลังธีม ---------- */
.bg-aurora   { background: linear-gradient(135deg, #a18cd1, #fbc2eb 60%, #8ec5fc); }
.bg-sunset   { background: linear-gradient(135deg, #ff9a9e, #fad0c4 50%, #fbc687); }
.bg-ocean    { background: linear-gradient(135deg, #2193b0, #6dd5ed); }
.bg-forest   { background: linear-gradient(135deg, #134e5e, #71b280); }
.bg-mono     { background: #f1f3f7; }
.bg-night    { background: linear-gradient(135deg, #0f2027, #203a43, #2c5364); }
.bg-dots     { background: #f6f7fb radial-gradient(circle, rgba(0,0,0,.12) 1.4px, transparent 1.6px) 0 0/22px 22px; }

/* ---------- แถบบน ---------- */
header {
  position: fixed; inset: 0 0 auto 0; height: 60px; z-index: 50;
  display: flex; align-items: center; gap: 12px; padding: 0 16px;
  background: var(--bar); backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line); box-shadow: 0 2px 8px rgba(0,0,0,.06);
}
header .brand { font-weight: 800; font-size: 18px; color: var(--brand); cursor: pointer; white-space: nowrap; }
header .brand span { color: var(--txt); }
header .title-wrap { flex: 1; min-width: 0; }
header .b-title { font-weight: 700; font-size: 17px; border: none; background: transparent; width: 100%; outline: none; }
header .b-desc  { font-size: 12px; color: var(--muted); border: none; background: transparent; width: 100%; outline: none; }
header .spacer { flex: 1; }

button, .btn {
  font: inherit; cursor: pointer; border: 1px solid var(--line);
  background: #fff; color: var(--txt); padding: 8px 14px; border-radius: 10px;
  display: inline-flex; align-items: center; gap: 6px; transition: .15s;
}
button:hover, .btn:hover { background: #f3f4f8; }
button.primary { background: var(--brand); color: #fff; border-color: transparent; }
button.primary:hover { filter: brightness(1.08); }
button.ghost { background: transparent; border-color: transparent; }
button.danger:hover { background: #fee2e2; color: #b91c1c; }

/* ---------- พื้นที่บอร์ด ---------- */
#stage { position: absolute; inset: 60px 0 0 0; overflow: auto; }
#canvas { position: relative; min-width: 100%; min-height: 100%; width: 3000px; height: 2200px; }

/* โหมด grid */
#canvas.grid {
  width: 100% !important; height: auto !important; min-height: calc(100vh - 60px);
  display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 16px; padding: 20px; align-content: start;
}
#canvas.grid .card { position: static !important; width: auto !important; }

/* ---------- การ์ด ---------- */
.card {
  position: absolute; width: 250px; background: #fffae6; border-radius: var(--radius);
  box-shadow: var(--shadow); border: 1px solid rgba(0,0,0,.06);
  display: flex; flex-direction: column; overflow: hidden; user-select: none;
}
.card.dragging { box-shadow: 0 16px 40px rgba(0,0,0,.28); transform: scale(1.02); }
.card .handle { height: 8px; cursor: grab; background: rgba(0,0,0,.06); }
.card .handle:active { cursor: grabbing; }
.card .body { padding: 12px 14px 6px; cursor: grab; }
.card h3 { margin: 0 0 6px; font-size: 16px; word-break: break-word; }
.card .text { font-size: 14px; line-height: 1.5; white-space: pre-wrap; word-break: break-word; }
.card img { width: 100%; display: block; border-radius: 8px; margin-top: 8px; cursor: zoom-in; }
.card a.link { display: inline-block; margin-top: 8px; font-size: 13px; color: #2563eb; word-break: break-all; }
.card .meta { display: flex; align-items: center; gap: 8px; padding: 6px 12px 10px; font-size: 12px; color: var(--muted); }
.card .meta .author { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.card .meta button { padding: 3px 8px; font-size: 12px; border-radius: 8px; }
.card .like.on { color: #e0245e; border-color: #f7b6c8; background: #fff0f4; }
.card .tools { position: absolute; top: 6px; right: 6px; display: none; gap: 4px; }
.card:hover .tools { display: flex; }
.card .tools button { padding: 2px 7px; font-size: 12px; background: rgba(255,255,255,.85); }

/* สีการ์ด */
.c-yellow { background: #fff7cc; } .c-green { background: #d8f5d0; }
.c-blue   { background: #d6ecff; } .c-pink  { background: #ffe0ee; }
.c-purple { background: #ece2ff; } .c-orange{ background: #ffe6c9; }
.c-red    { background: #ffd9d6; } .c-gray  { background: #eceef1; }
.c-white  { background: #ffffff; }

/* ---------- ปุ่มลอย ---------- */
.fab {
  position: fixed; right: 22px; bottom: 22px; z-index: 40;
  width: 58px; height: 58px; border-radius: 50%; font-size: 28px; color: #fff;
  background: var(--brand); border: none; box-shadow: var(--shadow);
}
.fab:hover { filter: brightness(1.1); }

/* ---------- Modal ---------- */
.overlay {
  position: fixed; inset: 0; z-index: 100; background: rgba(15,18,30,.5);
  display: none; align-items: center; justify-content: center; padding: 16px;
}
.overlay.show { display: flex; }
.modal {
  background: #fff; border-radius: 16px; width: 100%; max-width: 460px;
  box-shadow: 0 24px 60px rgba(0,0,0,.35); max-height: 90vh; overflow: auto;
}
.modal header { position: static; height: auto; background: none; border: none; box-shadow: none; padding: 18px 20px 6px; }
.modal h2 { margin: 0; font-size: 18px; }
.modal .content { padding: 8px 20px 4px; }
.modal .actions { padding: 12px 20px 20px; display: flex; gap: 10px; justify-content: flex-end; }
label { display: block; font-size: 13px; color: var(--muted); margin: 12px 0 4px; }
input[type=text], input[type=url], textarea, select {
  width: 100%; padding: 10px 12px; border: 1px solid #d1d5db; border-radius: 10px;
  font: inherit; outline: none;
}
input:focus, textarea:focus, select:focus { border-color: var(--brand); }
textarea { resize: vertical; min-height: 90px; }

.swatches { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 4px; }
.swatch { width: 30px; height: 30px; border-radius: 8px; cursor: pointer; border: 2px solid transparent; }
.swatch.sel { border-color: var(--txt); box-shadow: 0 0 0 2px #fff inset; }

.bg-pick { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 4px; }
.bg-pick .opt { width: 54px; height: 36px; border-radius: 8px; cursor: pointer; border: 2px solid transparent; }
.bg-pick .opt.sel { border-color: var(--brand); }

/* ---------- หน้ารวมบอร์ด ---------- */
#home { position: absolute; inset: 60px 0 0 0; overflow: auto; padding: 30px; }
.home-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 18px; max-width: 1100px; margin: 0 auto; }
.board-card {
  background: #fff; border-radius: 14px; box-shadow: var(--shadow); overflow: hidden;
  cursor: pointer; transition: .15s; position: relative;
}
.board-card:hover { transform: translateY(-3px); box-shadow: 0 12px 28px rgba(0,0,0,.2); }
.board-card .thumb { height: 90px; }
.board-card .info { padding: 12px 14px; }
.board-card .info h3 { margin: 0 0 4px; font-size: 16px; }
.board-card .info p { margin: 0; font-size: 13px; color: var(--muted); }
.board-card .info .count { margin-top: 8px; font-size: 12px; color: var(--brand); font-weight: 600; }
.board-card .del { position: absolute; top: 8px; right: 8px; opacity: 0; }
.board-card:hover .del { opacity: 1; }
.new-board {
  display: flex; align-items: center; justify-content: center; min-height: 192px;
  border: 2px dashed rgba(255,255,255,.7); color: #fff; border-radius: 14px; cursor: pointer;
  font-size: 16px; font-weight: 600; background: rgba(255,255,255,.12);
}
.new-board:hover { background: rgba(255,255,255,.22); }
.home-title { color: #fff; text-align: center; margin: 0 0 26px; text-shadow: 0 2px 8px rgba(0,0,0,.2); }
.home-title h1 { margin: 0; font-size: 30px; }
.home-title p { margin: 6px 0 0; opacity: .9; }

/* ---------- lightbox รูป ---------- */
#lightbox { position: fixed; inset: 0; z-index: 200; background: rgba(0,0,0,.85); display: none; align-items: center; justify-content: center; cursor: zoom-out; }
#lightbox.show { display: flex; }
#lightbox img { max-width: 92vw; max-height: 92vh; border-radius: 10px; }

.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%) translateY(20px);
  background: #1f2430; color: #fff; padding: 10px 18px; border-radius: 10px; z-index: 300;
  opacity: 0; transition: .25s; pointer-events: none;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* แสดงเฉพาะเมื่อเป็นครู */
.teacher-only { display: none !important; }
body.is-teacher .teacher-only { display: inline-flex !important; }
body.is-teacher .board-card .del { display: block; }

.attach-item { display: flex; align-items: center; gap: 8px; font-size: 13px; background: #f3f4f8; padding: 6px 10px; border-radius: 8px; }
.attach-item img { width: 40px; height: 40px; object-fit: cover; border-radius: 6px; }
.attach-item a { color: #2563eb; word-break: break-all; flex: 1; }
.file-chip { display: inline-flex; align-items: center; gap: 6px; margin-top: 8px; font-size: 13px; color: var(--brand); }

.empty-hint { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; color: rgba(255,255,255,.85); font-size: 16px; pointer-events: none; text-shadow: 0 1px 4px rgba(0,0,0,.2); }

@media (max-width: 640px) {
  header .brand span { display: none; }
  .card { width: 210px; }
}
