/* ===== ระบบบันทึกข้อความขออนุมัติไปราชการ — สไตล์เสริม Tailwind ===== */
:root {
  --navy: #001255; --ocean: #0095b7; --teal: #26A69A; --lime: #AED581; --amber: #FFCA28;
  --coral: #FF8A65; --rose: #EF5350; --plum: #4A2C6D; --crimson: #D32F2F; --tangerine: #F57C00;
  --sun: #FBC02D; --sky: #0288D1;
}
html { -webkit-tap-highlight-color: transparent; }
body { font-family: 'Sarabun', ui-sans-serif, system-ui, sans-serif; }
[x-cloak], .hidden-important { display: none !important; }

/* ---------- ฟอร์ม ---------- */
.input, .select, .textarea {
  width: 100%; border-radius: .9rem; border: 1px solid #e2e8f0; background: #fff;
  padding: .7rem 1rem; font-size: .95rem; color: #1e293b; transition: border-color .15s, box-shadow .15s;
}
.input:focus, .select:focus, .textarea:focus { outline: none; border-color: var(--ocean); box-shadow: 0 0 0 4px rgba(0,149,183,.14); }
.input[readonly], .input:disabled { background: #f8fafc; color: #475569; cursor: not-allowed; }
.input.is-invalid, .textarea.is-invalid, .select.is-invalid { border-color: var(--rose); box-shadow: 0 0 0 4px rgba(239,83,80,.12); }
.label { display: block; margin-bottom: .4rem; font-size: .875rem; font-weight: 600; color: #475569; }
.label .req { color: var(--rose); margin-left: 2px; }
.label .opt { color: #94a3b8; font-weight: 400; font-size: .75rem; margin-left: 4px; }

/* ---------- ปุ่ม ---------- */
.btn, .btn-primary, .btn-ocean, .btn-ghost, .btn-danger, .btn-success, .btn-light {
  display: inline-flex; align-items: center; justify-content: center; gap: .5rem; border-radius: .9rem;
  padding: .62rem 1.1rem; font-weight: 600; font-size: .925rem; transition: all .18s ease; white-space: nowrap; cursor: pointer;
}
.btn-primary { background: linear-gradient(135deg, var(--navy), #0a2a8a); color: #fff; box-shadow: 0 8px 20px -8px rgba(0,18,85,.55); }
.btn-primary:hover { transform: translateY(-1px); box-shadow: 0 12px 24px -10px rgba(0,18,85,.6); }
.btn-ocean { background: var(--ocean); color: #fff; box-shadow: 0 8px 20px -10px rgba(0,149,183,.7); }
.btn-ocean:hover { background: #007c99; }
.btn-success { background: var(--teal); color: #fff; }
.btn-success:hover { background: #1f8c81; }
.btn-danger { background: var(--rose); color: #fff; }
.btn-danger:hover { background: var(--crimson); }
.btn-ghost { background: #fff; color: #334155; border: 1px solid #e2e8f0; }
.btn-ghost:hover { border-color: var(--ocean); color: var(--ocean); }
.btn-light { background: #f1f5f9; color: #334155; }
.btn-light:hover { background: #e2e8f0; }
button:disabled { opacity: .6; cursor: not-allowed; transform: none !important; }

.icon-btn {
  display: inline-grid; place-items: center; width: 2.1rem; height: 2.1rem; border-radius: .7rem; font-size: 1.05rem;
  transition: all .15s; cursor: pointer;
}
.icon-btn:hover { transform: translateY(-1px); }
.icon-btn.view { background: #e6f7fb; color: var(--ocean); }
.icon-btn.edit { background: #fff8e1; color: var(--tangerine); }
.icon-btn.del { background: #fdecec; color: var(--crimson); }
.icon-btn.print { background: #eef1fb; color: var(--navy); }
.icon-btn.approve { background: #e0f2f1; color: #00897b; }

/* ---------- การ์ด / badge ---------- */
.card { background: #fff; border-radius: 1.4rem; border: 1px solid #eef2f7; box-shadow: 0 1px 2px rgba(0,18,85,.04), 0 8px 24px -14px rgba(0,18,85,.14); }
.badge { display: inline-flex; align-items: center; gap: .3rem; border-radius: 999px; padding: .2rem .65rem; font-size: .75rem; font-weight: 600; white-space: nowrap; }
.badge-pending { background: #fff8e1; color: #b26a00; }
.badge-approved { background: #e0f2f1; color: #00796b; }
.badge-rejected { background: #fdecec; color: var(--crimson); }
.badge-returned { background: #fff3e0; color: #e65100; }
.badge-deputy { background: #e3f2fd; color: #0277bd; }
.badge-personnel { background: #fce4ec; color: #ad1457; }
.badge-admin { background: #ede7f6; color: var(--plum); }
.badge-director { background: #e6f7fb; color: #006f88; }
.badge-teacher { background: #f1f8e9; color: #558b2f; }
.badge-soft { background: #f1f5f9; color: #475569; }

/* ---------- Skeleton ---------- */
.skeleton { position: relative; overflow: hidden; background: #edf1f7; border-radius: .6rem; }
.skeleton::after {
  content: ''; position: absolute; inset: 0; transform: translateX(-100%);
  background: linear-gradient(90deg, transparent, rgba(255,255,255,.75), transparent); animation: shimmer 1.3s infinite;
}
@keyframes shimmer { 100% { transform: translateX(100%); } }

/* ---------- Animations ---------- */
.fade-up { animation: fadeUp .45s cubic-bezier(.2,.7,.2,1) both; }
@keyframes fadeUp { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: none; } }

/* ---------- Loader ---------- */
#appLoader { position: fixed; inset: 0; z-index: 9999; display: none; place-items: center; background: rgba(0,18,85,.18); backdrop-filter: blur(3px); }
#appLoader.show { display: grid; }
.spinner { width: 54px; height: 54px; border-radius: 50%; border: 5px solid rgba(255,255,255,.35); border-top-color: var(--ocean); border-right-color: var(--navy); animation: spin .8s linear infinite; }
.spinner-sm { width: 18px; height: 18px; border-width: 2.5px; border-color: rgba(255,255,255,.4); border-top-color: #fff; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Sidebar ---------- */
.side-link { display: flex; align-items: center; gap: .85rem; padding: .72rem 1rem; border-radius: 1rem; color: rgba(255,255,255,.72); font-weight: 500; transition: all .18s; }
.side-link i { font-size: 1.3rem; }
.side-link:hover { background: rgba(255,255,255,.08); color: #fff; }
.side-link.active { background: linear-gradient(135deg, var(--ocean), #00b4d8); color: #fff; box-shadow: 0 10px 24px -10px rgba(0,149,183,.8); }
#sidebar { transition: transform .28s cubic-bezier(.2,.7,.2,1); }

/* ---------- Mobile bottom nav (ลอย มุมโค้งมน) ---------- */
.mnav { position: fixed; left: 12px; right: 12px; bottom: calc(12px + env(safe-area-inset-bottom)); z-index: 40;
  background: rgba(255,255,255,.92); backdrop-filter: blur(16px); border-radius: 1.6rem; border: 1px solid rgba(226,232,240,.8);
  box-shadow: 0 18px 40px -14px rgba(0,18,85,.35); }
.mnav a { display: flex; flex-direction: column; align-items: center; gap: 2px; padding: .55rem .25rem; font-size: .68rem; color: #64748b; border-radius: 1.1rem; flex: 1; transition: all .15s; }
.mnav a i { font-size: 1.45rem; }
.mnav a.active { color: var(--navy); font-weight: 700; }
.mnav a.active i { color: var(--ocean); transform: translateY(-1px); }
.mnav a.fab i { display: grid; place-items: center; width: 2.9rem; height: 2.9rem; margin-top: -1.6rem; border-radius: 1rem; color: #fff;
  background: linear-gradient(135deg, var(--navy), var(--ocean)); box-shadow: 0 10px 20px -6px rgba(0,149,183,.7); border: 4px solid #fff; }

/* ---------- iPhone-style shortcut icons ---------- */
.app-icon { display: flex; flex-direction: column; align-items: center; gap: .4rem; font-size: .72rem; color: #334155; text-align: center; line-height: 1.2; }
.app-icon .ico { display: grid; place-items: center; width: 3.6rem; height: 3.6rem; border-radius: 1.05rem; color: #fff; font-size: 1.75rem;
  box-shadow: 0 8px 16px -8px rgba(0,0,0,.35), inset 0 1px 0 rgba(255,255,255,.35); transition: transform .15s; }
.app-icon:active .ico { transform: scale(.92); }

/* ---------- Tables ---------- */
.tbl { width: 100%; border-collapse: separate; border-spacing: 0; font-size: .9rem; }
.tbl thead th { position: sticky; top: 0; background: #f8fafc; color: #475569; font-weight: 700; text-align: left; padding: .8rem 1rem; border-bottom: 1px solid #e2e8f0; white-space: nowrap; }
.tbl thead th:first-child { border-top-left-radius: 1rem; }
.tbl thead th:last-child { border-top-right-radius: 1rem; }
.tbl thead th.sortable { cursor: pointer; user-select: none; }
.tbl thead th.sortable:hover { color: var(--navy); }
.tbl tbody td { padding: .8rem 1rem; border-bottom: 1px solid #f1f5f9; vertical-align: middle; }
.tbl tbody tr { transition: background .12s; }
.tbl tbody tr:hover { background: #f8fbff; }
.table-wrap { overflow-x: auto; border-radius: 1rem; border: 1px solid #eef2f7; }
.table-wrap::-webkit-scrollbar { height: 8px; }
.table-wrap::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 99px; }

.view-toggle button { display: grid; place-items: center; width: 2.25rem; height: 2.25rem; border-radius: .7rem; color: #64748b; font-size: 1.15rem; }
.view-toggle button.on { background: #fff; color: var(--navy); box-shadow: 0 2px 8px -2px rgba(0,18,85,.2); }
.pager button { min-width: 2.2rem; height: 2.2rem; padding: 0 .55rem; border-radius: .7rem; font-size: .85rem; font-weight: 600; color: #475569; background: #fff; border: 1px solid #e2e8f0; }
.pager button.on { background: var(--navy); color: #fff; border-color: var(--navy); }
.pager button:hover:not(.on):not(:disabled) { border-color: var(--ocean); color: var(--ocean); }

/* ---------- Modal ---------- */
.modal { position: fixed; inset: 0; z-index: 60; display: none; align-items: flex-end; justify-content: center; background: rgba(0,18,85,.35); backdrop-filter: blur(4px); padding: 0; }
.modal.open { display: flex; animation: fadeIn .2s ease; }
.modal .modal-box { width: 100%; max-height: 92vh; overflow-y: auto; background: #fff; border-radius: 1.6rem 1.6rem 0 0; animation: slideUp .3s cubic-bezier(.2,.7,.2,1); }
@media (min-width: 640px) {
  .modal { align-items: center; padding: 1.5rem; }
  .modal .modal-box { border-radius: 1.6rem; }
}
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes slideUp { from { transform: translateY(30px); opacity: 0; } to { transform: none; opacity: 1; } }

/* ---------- Signature ---------- */
.sign-canvas { width: 100%; height: 190px; border: 2px dashed #cbd5e1; border-radius: 1rem; background: #fff; touch-action: none; cursor: crosshair; }
.seg { display: inline-flex; background: #f1f5f9; border-radius: .9rem; padding: .25rem; gap: .25rem; }
.seg label { cursor: pointer; }
.seg input { display: none; }
.seg span { display: inline-flex; align-items: center; gap: .4rem; padding: .45rem .9rem; border-radius: .7rem; font-size: .875rem; font-weight: 600; color: #64748b; transition: all .15s; }
.seg input:checked + span { background: #fff; color: var(--navy); box-shadow: 0 2px 8px -2px rgba(0,18,85,.22); }

.radio-card input { display: none !important; }
.check-card .on { display: none; }
.check-card input:checked + span .on { display: inline-block; }
.check-card input:checked + span .un { display: none; }
.radio-card span { display: flex; align-items: center; gap: .55rem; border: 1.5px solid #e2e8f0; border-radius: 1rem; padding: .7rem .9rem; font-weight: 500; cursor: pointer; transition: all .15s; background: #fff; }
.radio-card span i { font-size: 1.3rem; color: #94a3b8; }
.radio-card input:checked + span { border-color: var(--ocean); background: #e6f7fb; color: var(--navy); }
.radio-card input:checked + span i { color: var(--ocean); }

.upload-box { border: 2px dashed #cbd5e1; border-radius: 1.1rem; padding: 1rem; text-align: center; transition: all .15s; background: #fafcff; cursor: pointer; }
.upload-box:hover { border-color: var(--ocean); background: #f0fbfe; }

/* ---------- Switch ---------- */
.switch { position: relative; display: inline-block; width: 46px; height: 26px; cursor: pointer; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch span { position: absolute; inset: 0; background: #cbd5e1; border-radius: 99px; transition: .2s; }
.switch span::before { content: ''; position: absolute; width: 20px; height: 20px; left: 3px; top: 3px; background: #fff; border-radius: 50%; transition: .2s; box-shadow: 0 1px 3px rgba(0,0,0,.2); }
.switch input:checked + span { background: var(--teal); }
.switch input:checked + span::before { transform: translateX(20px); }

/* Swal font */
.swal2-popup { font-family: 'Sarabun', sans-serif !important; border-radius: 1.4rem !important; }
.swal2-styled.swal2-confirm { border-radius: .8rem !important; }
.swal2-styled.swal2-cancel { border-radius: .8rem !important; }

@media (max-width: 767px) {
  .has-mnav { padding-bottom: calc(96px + env(safe-area-inset-bottom)); }
}

/* มุมมองการ์ด: ไม่ให้เนื้อหายาว (ชื่อเรื่อง/ป้ายสถานะ) ดันการ์ดล้นจอมือถือ */
.dv-grid > * { min-width: 0; }
.dv-grid .card { min-width: 0; overflow-wrap: anywhere; word-break: break-word; }
.dv-grid .card .badge { max-width: 100%; white-space: normal; }
