/* =====================================================================
   ASM งานระบบ — คลังไฟล์
   สีแบรนด์เก็บจากโลโก้จริง (public/img/asm-logo.png):
   น้ำเงิน #2860A8 · น้ำเงินเข้ม #004098 (แถบ "งานระบบ") · ส้ม #F86808
   ===================================================================== */

:root {
  --blue: #2860a8;
  --blue-dark: #004098;
  --blue-deep: #0a2c66;
  --blue-50: #eef4fc;
  --blue-100: #d9e6f7;
  --orange: #f86808;
  --orange-dark: #d85600;
  --orange-50: #fff3ea;
  --ink: #1b2536;
  --muted: #64748b;
  --line: #e3e8f0;
  --surface: #ffffff;
  --bg: #f3f5f9;
  --danger: #c62828;
  --ok: #15803d;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.05), 0 8px 24px rgba(16, 38, 80, 0.07);
  --font-head: 'Prompt', 'Noto Sans Thai', 'Segoe UI', sans-serif;
  --font-body: 'Sarabun', 'Noto Sans Thai', 'Segoe UI', sans-serif;
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  font-family: var(--font-body);
  font-size: 15.5px;
  line-height: 1.55;
  color: var(--ink);
  background:
    radial-gradient(circle at 0% 0%, rgba(40, 96, 168, 0.10), transparent 42%),
    radial-gradient(circle at 100% 100%, rgba(248, 104, 8, 0.09), transparent 45%),
    var(--bg);
  background-attachment: fixed;
}

/* โลโก้ ASM เป็นลายน้ำพื้นหลังทั้งเว็บ — จางพอให้ตัวหนังสืออ่านง่าย */
body::before {
  content: '';
  position: fixed;
  inset: 0;
  background: url('/img/asm-logo.png') no-repeat center 58% / min(78vmin, 760px);
  opacity: 0.07;
  pointer-events: none;
  z-index: -1;
}

a { color: var(--blue-dark); }
a:hover { color: var(--orange-dark); }

h1, h2, h3 { font-family: var(--font-head); color: var(--ink); line-height: 1.25; }
h1 { font-size: 26px; font-weight: 700; margin: 0 0 6px; }
h1::after {
  content: '';
  display: block;
  width: 54px;
  height: 4px;
  margin-top: 10px;
  border-radius: 4px;
  background: linear-gradient(90deg, var(--orange), #ffa15c);
}

.icon { flex: none; vertical-align: middle; }

/* ---------------------------------------------------------------------
   แถบด้านบน
   --------------------------------------------------------------------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 50;
  background: linear-gradient(100deg, var(--blue-deep) 0%, var(--blue-dark) 55%, var(--blue) 100%);
  box-shadow: 0 4px 18px rgba(0, 28, 80, 0.25);
}
.topbar::after {
  content: '';
  display: block;
  height: 4px;
  background: linear-gradient(90deg, var(--orange), #ffb067 50%, var(--orange));
}
.topbar-inner {
  max-width: 1160px;
  margin: 0 auto;
  padding: 10px 20px;
  display: flex;
  align-items: center;
  gap: 18px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 11px;
  color: #fff;
  text-decoration: none;
  flex: none;
}
.brand:hover { color: #fff; }
.brand img {
  width: 46px;
  height: 46px;
  border-radius: 50%;
  box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.45), 0 4px 10px rgba(0, 0, 0, 0.25);
  transition: transform 0.2s;
}
.brand:hover img { transform: rotate(-8deg) scale(1.04); }
.brand-text strong {
  display: block;
  font-family: var(--font-head);
  font-size: 19px;
  font-weight: 700;
  letter-spacing: 0.2px;
  line-height: 1.15;
}
.brand-text small { display: block; font-size: 12.5px; color: #c7d7f3; }

.main-nav {
  display: flex;
  align-items: center;
  gap: 6px;
  flex: 1;
  margin-left: 6px;
}
.main-nav.guest { justify-content: flex-end; }
.main-nav a {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 8px 15px;
  border-radius: 999px;
  color: #dce7f9;
  text-decoration: none;
  font-family: var(--font-head);
  font-size: 14.5px;
  font-weight: 500;
  white-space: nowrap;
  transition: background 0.15s, color 0.15s, box-shadow 0.15s;
}
.main-nav a:hover { background: rgba(255, 255, 255, 0.13); color: #fff; }
.main-nav a.active {
  background: #fff;
  color: var(--blue-dark);
  box-shadow: 0 3px 10px rgba(0, 0, 0, 0.18);
}
.main-nav a.active .icon { color: var(--orange); }
.main-nav a.nav-cta { background: var(--orange); color: #fff; box-shadow: 0 3px 10px rgba(248, 104, 8, 0.35); }
.main-nav a.nav-cta:hover { background: var(--orange-dark); }

.user-box { display: flex; align-items: center; gap: 10px; flex: none; }
.avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: linear-gradient(135deg, #ff8a3d, var(--orange-dark));
  color: #fff;
  font-family: var(--font-head);
  font-weight: 700;
  box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.5);
}
.who { display: flex; align-items: center; gap: 6px; color: #fff; font-size: 14px; }
.btn-ghost {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin: 0;
  padding: 7px 14px;
  border: 1px solid rgba(255, 255, 255, 0.45);
  border-radius: 999px;
  background: transparent;
  color: #fff;
  font-family: var(--font-head);
  font-size: 13.5px;
  cursor: pointer;
  box-shadow: none;
  transition: background 0.15s;
}
.btn-ghost:hover { background: rgba(255, 255, 255, 0.14); box-shadow: none; }

/* ---------------------------------------------------------------------
   โครงหน้า
   --------------------------------------------------------------------- */
.container {
  width: 100%;
  max-width: 1160px;
  margin: 30px auto 0;
  padding: 0 20px;
  flex: 1;
}

.page-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 20px;
}
.page-head h1 { margin-bottom: 0; }
.page-head .btn-link { margin-top: 0; }
.page-sub { margin: 10px 0 0; color: var(--muted); font-size: 14.5px; }

.card,
.form-card,
.file-meta,
.stat,
.empty-state {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.site-footer {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  width: 100%;
  max-width: 1160px;
  margin: 44px auto 0;
  padding: 18px 20px 26px;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 13px;
  text-align: center;
}
.site-footer img { border-radius: 50%; flex: none; }

/* ---------------------------------------------------------------------
   ข้อความแจ้ง / ป้าย
   --------------------------------------------------------------------- */
.msg {
  padding: 12px 16px;
  margin: 0 0 16px;
  border-radius: 10px;
  border: 1px solid var(--line);
  border-left: 5px solid var(--blue);
  background: var(--blue-50);
  text-align: left;
}
.msg.warn { background: #fdecea; border-color: #f5c2bd; border-left-color: var(--danger); color: #7a1f16; }
.msg.ok { background: #e8f6ee; border-color: #bfe3cc; border-left-color: var(--ok); color: #14532d; }
.msg a { font-weight: 600; }

.hint { font-size: 12.5px; color: var(--muted); margin: 2px 0 0; }

.badge {
  display: inline-block;
  padding: 1px 9px;
  border-radius: 999px;
  font-family: var(--font-head);
  font-size: 12px;
  font-weight: 500;
  background: #e5e7eb;
  color: #374151;
  vertical-align: middle;
  white-space: nowrap;
}
.badge.admin { background: #ffe6cf; color: #9a3a00; }
.badge.on { background: #dcfce7; color: #166534; }
.badge.off { background: #fee2e2; color: #991b1b; }
.badge.pending { background: var(--orange); color: #fff; }

/* ---------------------------------------------------------------------
   ปุ่ม
   --------------------------------------------------------------------- */
button,
.btn-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin-top: 16px;
  padding: 10px 20px;
  border: none;
  border-radius: 10px;
  background: linear-gradient(180deg, #3673c2, var(--blue-dark));
  color: #fff;
  font-family: var(--font-head);
  font-size: 15px;
  font-weight: 500;
  text-decoration: none;
  text-align: center;
  cursor: pointer;
  box-shadow: 0 3px 10px rgba(0, 64, 152, 0.22);
  transition: transform 0.12s, box-shadow 0.15s, filter 0.15s;
}
button:hover,
.btn-link:hover { color: #fff; filter: brightness(1.08); box-shadow: 0 5px 14px rgba(0, 64, 152, 0.3); }
button:active,
.btn-link:active { transform: translateY(1px); }

button.accent,
.btn-link.accent { background: linear-gradient(180deg, #ff8126, var(--orange-dark)); box-shadow: 0 3px 10px rgba(248, 104, 8, 0.3); }
.btn-link.secondary { background: linear-gradient(180deg, #5b6b82, #3f4d63); box-shadow: 0 3px 10px rgba(30, 41, 59, 0.2); }
button.danger { background: linear-gradient(180deg, #e04a3f, var(--danger)); box-shadow: 0 3px 10px rgba(198, 40, 40, 0.25); }
.btn-block { width: 100%; }

.link-button {
  display: inline;
  margin: 0;
  padding: 0;
  border: none;
  background: none;
  box-shadow: none;
  color: var(--blue-dark);
  font-family: var(--font-body);
  font-size: 14px;
  font-weight: 500;
  text-decoration: underline;
  text-underline-offset: 2px;
  cursor: pointer;
}
.link-button:hover { color: var(--orange-dark); filter: none; box-shadow: none; }
.link-button.danger { color: var(--danger); }

.inline-form { display: inline; margin: 0; }

/* ---------------------------------------------------------------------
   ฟอร์ม
   --------------------------------------------------------------------- */
.form-card {
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-width: 460px;
  padding: 24px 26px;
}
.form-card.wide { max-width: 680px; }
.form-card button { align-self: flex-start; }

.form-card label,
.form-stack label {
  margin-top: 10px;
  font-family: var(--font-head);
  font-size: 13.5px;
  font-weight: 500;
  color: #334155;
}

.form-card input,
.form-card textarea,
.form-card select,
.form-stack input,
.search-bar input,
.search-bar select {
  width: 100%;
  padding: 11px 13px;
  border: 1px solid #cfd8e6;
  border-radius: 10px;
  background: #fff;
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 15px;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.form-card input:focus,
.form-card textarea:focus,
.form-card select:focus,
.form-stack input:focus,
.search-bar input:focus,
.search-bar select:focus {
  outline: none;
  border-color: var(--blue);
  box-shadow: 0 0 0 4px rgba(40, 96, 168, 0.15);
}
.form-card input[type='file'] {
  padding: 18px 14px;
  border: 2px dashed #b9c8de;
  background: var(--blue-50);
  cursor: pointer;
}
.form-card input[type='file']:hover { border-color: var(--orange); background: var(--orange-50); }
.form-card input[type='file']::file-selector-button {
  margin-right: 12px;
  padding: 8px 14px;
  border: none;
  border-radius: 8px;
  background: var(--blue-dark);
  color: #fff;
  font-family: var(--font-head);
  cursor: pointer;
}
.form-card .check {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 12px;
  font-family: var(--font-body);
  font-size: 14.5px;
  color: var(--ink);
}
.form-card .check input { width: 18px; height: 18px; accent-color: var(--orange); }
.form-intro { max-width: 460px; color: #374151; font-size: 14px; }

.form-stack { display: flex; flex-direction: column; gap: 6px; text-align: left; }
.form-stack button { margin-top: 18px; }
.form-stack .code-input {
  font-family: var(--font-head);
  font-size: 20px;
  letter-spacing: 0.4em;
  text-align: center;
}

/* ปุ่มกดค้างดูรหัสผ่าน (public/js/password-reveal.js) */
.password-wrap { position: relative; display: flex; }
.password-wrap input { flex: 1; width: 100%; padding-right: 46px; }
.password-reveal {
  position: absolute;
  top: 50%;
  right: 5px;
  transform: translateY(-50%);
  margin: 0;
  padding: 7px 9px;
  line-height: 0;
  border-radius: 8px;
  background: none;
  box-shadow: none;
  color: #7a8699;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}
/* กฎของปุ่มในฟอร์ม (.form-stack button / .form-card button) เจาะจงกว่า .password-reveal
   เคยดันปุ่มรูปตาลงไปขอบล่างของช่อง — ใช้ .password-wrap นำหน้าให้ชนะเสมอ */
.password-wrap .password-reveal { margin: 0; align-self: auto; }
.password-reveal:hover { background: var(--blue-50); color: var(--blue-dark); filter: none; box-shadow: none; }
.password-reveal:active { transform: translateY(-50%); }
.password-reveal.active { background: var(--orange-50); color: var(--orange-dark); }

/* ---------------------------------------------------------------------
   หน้าเข้าสู่ระบบ / สมัคร / ลืมรหัสผ่าน
   --------------------------------------------------------------------- */
body.auth::before { opacity: 0.05; }
.auth-wrap { display: flex; justify-content: center; padding: 12px 0 0; }
.auth-card {
  position: relative;
  width: 100%;
  max-width: 450px;
  padding: 26px 32px 24px;
  border-radius: 22px;
  border: 1px solid var(--line);
  border-top: 5px solid var(--orange);
  background: rgba(255, 255, 255, 0.97);
  box-shadow: 0 18px 48px rgba(10, 44, 102, 0.16);
  text-align: center;
}
.auth-logo {
  display: block;
  width: 124px;
  height: 124px;
  margin: 0 auto 8px;
  filter: drop-shadow(0 8px 16px rgba(0, 64, 152, 0.22));
}
.auth-card h1 { font-size: 25px; }
.auth-card h1::after { margin: 10px auto 0; }
.auth-sub { margin: 12px 0 18px; color: var(--muted); font-size: 14px; }
.auth-links { margin: 18px 0 0; color: var(--muted); font-size: 14px; }
.auth-links .dot { margin: 0 6px; color: #b6c0cf; }

/* ---------------------------------------------------------------------
   รายการไฟล์
   --------------------------------------------------------------------- */
.search-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 18px;
  padding: 12px;
}
.search-input { position: relative; flex: 1; min-width: 220px; }
.search-input .icon { position: absolute; top: 50%; left: 13px; transform: translateY(-50%); color: #8a96a8; }
.search-input input { padding-left: 40px; }
.search-bar select { width: auto; min-width: 170px; }
.search-bar button { margin-top: 0; }

.table-wrap { overflow-x: auto; border-radius: var(--radius); box-shadow: var(--shadow); }
.file-table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
}
.file-table th,
.file-table td {
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
  font-size: 14.5px;
  text-align: left;
  vertical-align: middle;
}
.file-table th {
  background: linear-gradient(180deg, #f4f8fe, var(--blue-50));
  border-bottom: 2px solid var(--blue-100);
  color: var(--blue-dark);
  font-family: var(--font-head);
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
}
.file-table tbody tr { transition: background 0.12s; }
.file-table tbody tr:hover td { background: #f8fbff; }
.file-table tbody tr:last-child td { border-bottom: none; }
.desc { font-family: var(--font-body); font-size: 12.5px; font-weight: 400; color: var(--muted); }
.file-table .desc { margin-top: 2px; }
.file-table .num { text-align: right; }
.file-table .nowrap { white-space: nowrap; }
.file-table.compact th,
.file-table.compact td { padding: 8px 12px; font-size: 13.5px; }
.file-table .row-warn td { background: #fff7ed; }
/* ตารางในแผงควบคุม: ไม่ตัดวันที่/ขนาดกลางบรรทัด ให้เลื่อนดูในกรอบแทน (.table-wrap) */
#users .file-table td,
#activity .file-table td:first-child { white-space: nowrap; }
section > .file-table { box-shadow: var(--shadow); }

.file-cell { display: flex; align-items: center; gap: 10px; min-width: 220px; }
.file-link { color: var(--ink); text-decoration: none; }
.file-link:hover { color: var(--blue-dark); text-decoration: underline; }

.ext-chip {
  display: inline-block;
  flex: none;
  min-width: 46px;
  padding: 3px 7px;
  border-radius: 7px;
  background: #64748b;
  color: #fff;
  font-family: var(--font-head);
  font-size: 11px;
  font-weight: 600;
  line-height: 1.5;
  text-align: center;
  text-transform: uppercase;
  letter-spacing: 0.3px;
}
.ext-cad { background: var(--blue-dark); }
.ext-sheet { background: #15803d; }
.ext-pdf { background: #c62828; }
.ext-image { background: #7c3aed; }
.ext-doc { background: #0284c7; }
.ext-archive { background: #78716c; }

.cat-chip {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 999px;
  background: var(--orange-50);
  color: #9a3a00;
  font-size: 13px;
  white-space: nowrap;
}
.tags .tag {
  display: inline-block;
  margin: 2px 4px 2px 0;
  padding: 1px 8px;
  border-radius: 6px;
  background: var(--blue-50);
  color: var(--blue-dark);
  font-size: 12.5px;
  white-space: nowrap;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.row-actions { white-space: nowrap; text-align: right; }
.row-actions .act {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  width: 34px;
  height: 34px;
  margin: 2px 0 2px 4px;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  box-shadow: none;
  color: var(--blue-dark);
  font-family: var(--font-body);
  font-size: 13px;
  font-weight: 500;
  text-decoration: none;
}
.row-actions .act:hover { border-color: var(--blue-100); background: var(--blue-50); filter: none; box-shadow: none; }
.row-actions .act.danger { color: var(--danger); }
.row-actions .act.danger:hover { border-color: #f5c2bd; background: #fdecea; }
.row-actions .link-button { margin-left: 8px; }

.empty-state { padding: 38px 20px; text-align: center; color: #94a3b8; }
.empty-state .msg-plain { margin: 10px 0 4px; color: var(--muted); font-size: 16px; }

/* ---------------------------------------------------------------------
   หน้ารายละเอียดไฟล์
   --------------------------------------------------------------------- */
.file-title { word-break: break-word; }
.file-title .ext-chip { position: relative; top: -3px; margin-right: 10px; font-size: 13px; padding: 4px 10px; vertical-align: middle; }
.file-meta {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(170px, 1fr));
  gap: 14px;
  margin: 18px 0 16px;
  padding: 18px;
}
.file-meta dt { font-size: 12.5px; color: var(--muted); }
.file-meta dd { margin: 3px 0 0; font-size: 15px; font-weight: 500; word-break: break-word; }
.file-desc { white-space: pre-wrap; }
.actions-bar { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 22px; }
.actions-bar .btn-link,
.actions-bar button { margin-top: 0; }
.preview img {
  display: block;
  max-width: 100%;
  height: auto;
  margin: 0 auto;
  border-radius: var(--radius);
  background: #fff;
  box-shadow: var(--shadow);
}
.preview iframe {
  width: 100%;
  height: 80vh;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
  box-shadow: var(--shadow);
}

/* ---------------------------------------------------------------------
   แผงควบคุมแอดมิน
   --------------------------------------------------------------------- */
.admin-tabs { display: flex; flex-wrap: wrap; gap: 8px; margin: 14px 0 22px; }
.admin-tabs a {
  padding: 7px 16px;
  border: 1px solid var(--blue-100);
  border-radius: 999px;
  background: #fff;
  color: var(--blue-dark);
  font-family: var(--font-head);
  font-size: 14px;
  text-decoration: none;
  transition: background 0.15s, color 0.15s;
}
.admin-tabs a:hover { background: var(--blue-dark); border-color: var(--blue-dark); color: #fff; }

section { margin-bottom: 36px; scroll-margin-top: 90px; }
section h2 { display: flex; align-items: center; gap: 10px; margin: 0 0 14px; font-size: 20px; font-weight: 600; }
section h2::before {
  content: '';
  flex: none;
  width: 12px;
  height: 12px;
  border-radius: 4px;
  background: linear-gradient(135deg, var(--orange), #ffa15c);
  box-shadow: 0 0 0 4px var(--orange-50);
}

.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 14px;
  margin-bottom: 16px;
}
.stat {
  display: flex;
  flex-direction: column;
  padding: 16px 18px;
  border-left: 5px solid var(--blue);
}
.stat:nth-child(2) { border-left-color: var(--orange); }
.stat:nth-child(3) { border-left-color: var(--blue-dark); }
.stat:nth-child(4) { border-left-color: #15803d; }
.stat-label { font-size: 13px; color: var(--muted); }
.stat-value { margin-top: 4px; font-family: var(--font-head); font-size: 28px; font-weight: 700; color: var(--blue-dark); }
.stat-sub { margin-top: 2px; font-size: 12.5px; color: var(--muted); }

/* ---------------------------------------------------------------------
   จอเล็ก
   --------------------------------------------------------------------- */
@media (max-width: 900px) {
  .topbar-inner { flex-wrap: wrap; gap: 10px 14px; padding: 10px 16px; }
  .main-nav { order: 3; flex-basis: 100%; margin-left: 0; overflow-x: auto; padding-bottom: 2px; scrollbar-width: none; }
  .main-nav::-webkit-scrollbar { display: none; } /* เลื่อนเมนูด้วยนิ้วได้ แต่ไม่โชว์แถบเลื่อนเทา */
  .main-nav.guest { justify-content: flex-start; }
  .user-box { margin-left: auto; }
  .who-name,
  .btn-ghost-text { display: none; }
  .btn-ghost { padding: 8px; }
  section { scroll-margin-top: 150px; } /* แถบด้านบนสูงขึ้นเป็นสองแถว — ไม่ให้บังหัวข้อตอนกดลิงก์ #users */
}

@media (max-width: 600px) {
  body { font-size: 15px; }
  .container { margin-top: 20px; padding: 0 14px; }
  h1 { font-size: 22px; }
  .brand img { width: 40px; height: 40px; }
  .brand-text strong { font-size: 17px; }
  .auth-card { padding: 22px 18px 20px; border-radius: 18px; }
  .auth-logo { width: 100px; height: 100px; }
  .form-card { padding: 18px 16px; }
  .search-bar select,
  .search-bar button { flex: 1; }
  .page-head .btn-link { width: 100%; }
}
