/* ===== ระบบหลังบ้าน ===== */
:root {
  --primary: #1e88e5; --primary-dark: #0d47a1; --accent: #e53935;
  --bg: #f3f7fc; --card: #fff; --text: #1f2d3d; --muted: #64748b; --line: #e2e8f0;
  --sky: #e3f2fd; --ok: #2e7d32; --warn: #f59e0b;
}
* { box-sizing: border-box; }
body { margin: 0; font-family: 'Prompt', sans-serif; font-size: 15px; color: var(--text); background: var(--bg); }
a { color: var(--primary); text-decoration: none; }
img { max-width: 100%; }
h1, h2, h3 { margin: 0 0 .6em; font-weight: 600; color: var(--primary-dark); }
.muted { color: var(--muted); }

/* layout */
.admin-wrap { display: flex; min-height: 100vh; }
.sidebar {
  width: 260px; flex: none; background: linear-gradient(180deg, var(--primary-dark), #0a3880); color: #cfe3ff;
  position: sticky; top: 0; height: 100vh; overflow-y: auto; transition: transform .3s;
}
.side-brand { display: flex; gap: 10px; align-items: center; padding: 20px 18px; border-bottom: 1px solid rgba(255,255,255,.1); }
.side-brand img { width: 42px; height: 42px; background: #fff; border-radius: 50%; padding: 3px; object-fit: contain; }
.side-brand b { color: #fff; display: block; font-weight: 500; line-height: 1.3; font-size: 15px; }
.side-brand small { font-size: 12px; opacity: .8; }
.side-nav { list-style: none; margin: 0; padding: 12px; }
.side-nav .label { font-size: 12px; text-transform: uppercase; letter-spacing: 1px; opacity: .55; padding: 14px 12px 6px; }
.side-nav a { display: flex; align-items: center; gap: 12px; padding: 10px 12px; border-radius: 10px; color: #cfe3ff; margin-bottom: 2px; transition: all .2s; }
.side-nav a i { font-size: 18px; width: 22px; text-align: center; }
.side-nav a:hover { background: rgba(255,255,255,.08); color: #fff; }
.side-nav a.active { background: #fff; color: var(--primary-dark); box-shadow: 0 6px 18px rgba(0,0,0,.15); }
.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topnav { background: #fff; height: 64px; display: flex; align-items: center; justify-content: space-between; padding: 0 24px; box-shadow: 0 1px 0 var(--line); position: sticky; top: 0; z-index: 50; }
.topnav .menu-btn { display: none; background: none; border: 0; font-size: 24px; cursor: pointer; color: var(--primary-dark); }
.topnav-right { display: flex; align-items: center; gap: 16px; }
.avatar { width: 36px; height: 36px; border-radius: 50%; background: var(--sky); color: var(--primary); display: grid; place-items: center; font-weight: 600; }
.content { padding: 28px; flex: 1; }
.page-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 22px; flex-wrap: wrap; }
.page-head h1 { margin: 0; font-size: 24px; }

/* cards */
.card { background: var(--card); border-radius: 16px; box-shadow: 0 4px 20px rgba(13,71,161,.06); padding: 22px; margin-bottom: 22px; }
.card h2 { font-size: 18px; }
.grid { display: grid; gap: 20px; }
.grid-2 { grid-template-columns: repeat(2, 1fr); }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
.grid-4 { grid-template-columns: repeat(4, 1fr); }
.grid-main { grid-template-columns: 1fr 320px; align-items: start; }
.stat-card { display: flex; align-items: center; gap: 16px; background: #fff; border-radius: 16px; padding: 20px; box-shadow: 0 4px 20px rgba(13,71,161,.06); color: var(--text); transition: transform .25s; }
.stat-card:hover { transform: translateY(-4px); }
.stat-card i { width: 56px; height: 56px; border-radius: 16px; display: grid; place-items: center; font-size: 26px; background: var(--sky); color: var(--primary); }
.stat-card b { font-size: 26px; display: block; line-height: 1.2; }
.stat-card span { color: var(--muted); font-size: 14px; }

/* buttons */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 9px 18px; border-radius: 10px; border: 0; cursor: pointer; font: inherit; font-weight: 500; background: var(--primary); color: #fff; transition: all .2s; white-space: nowrap; }
.btn:hover { background: var(--primary-dark); color: #fff; }
.btn-sm { padding: 5px 11px; font-size: 13px; border-radius: 8px; }
.btn-light { background: var(--sky); color: var(--primary-dark); }
.btn-light:hover { background: #cfe5fb; color: var(--primary-dark); }
.btn-danger { background: #fdecea; color: var(--accent); }
.btn-danger:hover { background: var(--accent); color: #fff; }
.btn-ok { background: var(--ok); }
.btn-block { width: 100%; }
.actions { display: flex; gap: 6px; flex-wrap: wrap; }

/* forms */
label { display: block; font-weight: 500; margin-bottom: 14px; font-size: 14px; }
input[type=text], input[type=password], input[type=email], input[type=url], input[type=number], input[type=date], input[type=datetime-local], input[type=search], select, textarea {
  display: block; width: 100%; margin-top: 6px; padding: 10px 13px; border: 1px solid var(--line); border-radius: 10px; font: inherit; font-weight: 400; background: #fff; color: var(--text); transition: border .2s, box-shadow .2s;
}
input:focus, select:focus, textarea:focus { outline: 0; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(30,136,229,.15); }
input[type=color] { width: 60px; height: 40px; border: 1px solid var(--line); border-radius: 10px; padding: 3px; margin-top: 6px; cursor: pointer; }
textarea { min-height: 100px; resize: vertical; }
.check { display: flex; align-items: center; gap: 8px; font-weight: 400; cursor: pointer; }
.check input { width: 18px; height: 18px; }
.hint { font-size: 13px; color: var(--muted); font-weight: 400; margin-top: 4px; }
.img-preview { width: 100%; max-height: 200px; object-fit: cover; border-radius: 10px; margin-top: 8px; background: var(--sky); }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }

/* table */
.table-wrap { overflow-x: auto; }
table.table { width: 100%; border-collapse: collapse; }
.table th { text-align: left; font-weight: 500; color: var(--muted); font-size: 13px; padding: 10px 12px; border-bottom: 2px solid var(--line); white-space: nowrap; }
.table td { padding: 12px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.table tr:hover td { background: #fafcff; }
.thumb { width: 72px; height: 48px; object-fit: cover; border-radius: 8px; background: var(--sky); }
.badge { display: inline-block; padding: 2px 10px; border-radius: 20px; font-size: 12px; background: var(--sky); color: var(--primary-dark); }
.badge-ok { background: #e8f5e9; color: var(--ok); }
.badge-warn { background: #fff7e6; color: #b26a00; }
.badge-red { background: #fdecea; color: var(--accent); }

/* alerts */
.alert { padding: 12px 16px; border-radius: 10px; margin-bottom: 18px; animation: slideIn .4s; }
.alert-success { background: #e8f5e9; color: var(--ok); }
.alert-error { background: #fdecea; color: #b71c1c; }
@keyframes slideIn { from { opacity: 0; transform: translateY(-8px); } }

/* menus manager */
.menu-tree, .menu-tree ul { list-style: none; margin: 0; padding: 0; }
.menu-tree ul { padding-left: 34px; min-height: 8px; }
.menu-tree li { margin: 6px 0; }
.mi { display: flex; align-items: center; gap: 10px; background: #fff; border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; transition: box-shadow .2s, border .2s; }
.mi:hover { border-color: #90caf9; box-shadow: 0 4px 14px rgba(13,71,161,.08); }
.mi .handle { cursor: grab; color: var(--muted); font-size: 18px; }
.mi .t { flex: 1; font-weight: 500; }
.mi .t small { display: block; font-weight: 400; color: var(--muted); font-size: 12px; word-break: break-all; }
.mi.hidden-item { opacity: .55; }
.menu-tree > li > .mi { background: var(--sky); border-color: #bbdefb; }
.sortable-ghost .mi { background: #fff8e1; border: 2px dashed var(--warn); }

/* gallery admin */
.photo-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; }
.photo-item { position: relative; border-radius: 12px; overflow: hidden; background: var(--sky); aspect-ratio: 1; }
.photo-item img { width: 100%; height: 100%; object-fit: cover; }
.photo-item .ops { position: absolute; top: 6px; right: 6px; display: flex; gap: 4px; }
.photo-item .ops button { border: 0; width: 30px; height: 30px; border-radius: 8px; cursor: pointer; background: rgba(255,255,255,.92); }
.photo-item .ops .del { color: var(--accent); }
.dropzone { border: 2px dashed #90caf9; border-radius: 14px; padding: 28px; text-align: center; background: #f8fbff; cursor: pointer; transition: all .2s; display: block; }
.dropzone:hover, .dropzone.drag { background: var(--sky); border-color: var(--primary); }
.dropzone i { font-size: 36px; color: var(--primary); }

/* modal */
.modal { position: fixed; inset: 0; background: rgba(15,23,42,.5); display: none; align-items: center; justify-content: center; z-index: 200; padding: 16px; }
.modal.open { display: flex; animation: fade .2s; }
.modal-box { background: #fff; border-radius: 18px; padding: 24px; width: 100%; max-width: 520px; max-height: 90vh; overflow-y: auto; animation: pop .25s; }
.modal-box h2 { display: flex; justify-content: space-between; align-items: center; }
.modal-close { background: none; border: 0; font-size: 22px; cursor: pointer; color: var(--muted); }
@keyframes fade { from { opacity: 0; } }
@keyframes pop { from { transform: scale(.95); opacity: 0; } }

/* login */
.login-page { min-height: 100vh; display: grid; place-items: center; padding: 20px; background: radial-gradient(circle at 80% 10%, #90caf9 0, transparent 40%), linear-gradient(135deg, var(--primary-dark), var(--primary)); }
.login-box { background: #fff; border-radius: 22px; padding: 36px 32px; width: 100%; max-width: 420px; box-shadow: 0 30px 60px rgba(0,0,0,.2); text-align: center; animation: pop .5s; }
.login-box form { text-align: left; margin-top: 18px; }
.login-logo { width: 84px; height: 84px; object-fit: contain; margin: 0 auto 12px; display: block; }
.login-box h1 { font-size: 22px; margin-bottom: 4px; }

.empty { text-align: center; color: var(--muted); padding: 30px; }
.tox-tinymce { border-radius: 12px !important; }

@media (max-width: 960px) {
  .sidebar { position: fixed; left: 0; top: 0; z-index: 100; transform: translateX(-100%); }
  .sidebar.open { transform: none; box-shadow: 10px 0 40px rgba(0,0,0,.25); }
  .topnav .menu-btn { display: block; }
  .grid-2, .grid-3, .grid-main { grid-template-columns: 1fr; }
  .grid-4 { grid-template-columns: 1fr 1fr; }
  .content { padding: 18px 14px; }
  .form-row { grid-template-columns: 1fr; }
  .topnav-right .uname { display: none; }
}
