/* PANN Asset Management — mobile-first · ฟอนต์ระบบ · ปุ่มใหญ่กดจากมือถือ */
:root {
  --bg: #f5f6f8;
  --card: #ffffff;
  --text: #1d2330;
  --muted: #6b7280;
  --line: #e3e6eb;
  --primary: #1f6feb;
  --primary-dark: #1558c0;
  --ok: #1a7f37;
  --ok-bg: #e6f4ea;
  --warn: #9a6700;
  --warn-bg: #fff4d6;
  --danger: #c62828;
  --danger-bg: #fdecea;
  --info-bg: #e8f0fe;
  --grey-bg: #eef0f3;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: system-ui, -apple-system, "Segoe UI", "Noto Sans Thai", "Leelawadee UI", Tahoma, sans-serif;
  font-size: 16px;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
  -webkit-text-size-adjust: 100%;
}
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.35rem; margin: .2rem 0 .8rem; }
h2 { font-size: 1.12rem; margin: 1.2rem 0 .6rem; }
h3 { font-size: 1rem; margin: 1rem 0 .4rem; }
small, .muted { color: var(--muted); }
img { max-width: 100%; }

/* ---------- เมนูบน ---------- */
.topbar {
  position: sticky; top: 0; z-index: 50;
  background: #172033; color: #fff;
  box-shadow: 0 1px 4px rgba(0,0,0,.2);
}
.topbar-row { display: flex; align-items: center; gap: .5rem; padding: .5rem .75rem; flex-wrap: wrap; }
.brand { font-weight: 700; color: #fff; white-space: nowrap; }
.brand:hover { text-decoration: none; }
.topbar select {
  background: #24304a; color: #fff; border: 1px solid #3a4a6b; border-radius: 8px;
  padding: .35rem .5rem; font-size: .9rem; max-width: 46vw;
}
.topbar .spacer { flex: 1; }
.topbar .icon-btn { background: transparent; color: #fff; border: 0; font-size: 1.3rem; padding: .25rem .5rem; cursor: pointer; position: relative; }
.topbar .badge-dot { position: absolute; top: 0; right: 0; background: #e5484d; color: #fff; border-radius: 999px; font-size: .65rem; padding: 0 .3rem; }
.nav { display: none; flex-direction: column; background: #1c2740; }
.nav.open { display: flex; }
.nav a { color: #dfe6f3; padding: .75rem 1rem; border-top: 1px solid #26324d; }
.nav a.active { color: #fff; font-weight: 600; background: #24304a; }
.nav a:hover { text-decoration: none; background: #24304a; }
@media (min-width: 900px) {
  .nav { display: flex; flex-direction: row; flex-wrap: wrap; padding: 0 .5rem; }
  .nav a { border-top: 0; padding: .55rem .8rem; }
  #menuToggle { display: none; }
}

/* ---------- โครงหน้า ---------- */
main.container { max-width: 1100px; margin: 0 auto; padding: 1rem .75rem 5rem; }
.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 1rem; margin-bottom: 1rem; }
.card h2:first-child, .card h3:first-child { margin-top: 0; }
.grid { display: grid; gap: .75rem; grid-template-columns: 1fr; }
@media (min-width: 640px) { .grid.cols-2 { grid-template-columns: 1fr 1fr; } .grid.cols-3 { grid-template-columns: repeat(3, 1fr); } }
@media (min-width: 900px) { .grid.cols-4 { grid-template-columns: repeat(4, 1fr); } }
.row { display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; }
.between { justify-content: space-between; }
.stack > * + * { margin-top: .6rem; }
.hidden { display: none !important; }
.spacer { flex: 1; }

/* ---------- ฟอร์ม ---------- */
label { display: block; font-size: .9rem; color: #394150; margin-bottom: .2rem; }
input, select, textarea {
  width: 100%; font: inherit; color: inherit;
  padding: .65rem .7rem; border: 1px solid #cfd5dd; border-radius: 10px; background: #fff;
}
input:focus, select:focus, textarea:focus { outline: 2px solid #b6d0fb; border-color: var(--primary); }
input[type=checkbox], input[type=radio] { width: auto; }
textarea { min-height: 5rem; }
.field { margin-bottom: .75rem; }
.field-inline { display: flex; align-items: center; gap: .5rem; }

/* ---------- ปุ่ม ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .4rem;
  font: inherit; font-weight: 600; cursor: pointer;
  border: 1px solid #cfd5dd; background: #fff; color: var(--text);
  padding: .6rem 1rem; border-radius: 10px; min-height: 44px;
}
.btn:hover { text-decoration: none; background: #f3f5f8; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-danger { color: var(--danger); border-color: #f1b7b3; }
.btn-danger:hover { background: var(--danger-bg); }
.btn-block { width: 100%; }
.btn-lg { min-height: 54px; font-size: 1.05rem; }
.btn-sm { min-height: 34px; padding: .3rem .65rem; font-size: .88rem; }
.btn-link { background: none; border: 0; color: var(--primary); padding: 0; min-height: 0; font-weight: 500; }
.fab { position: fixed; right: 1rem; bottom: 1rem; z-index: 40; border-radius: 999px; box-shadow: 0 4px 14px rgba(31,111,235,.35); }

/* ---------- ตาราง ---------- */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table { width: 100%; border-collapse: collapse; font-size: .93rem; }
th, td { text-align: left; padding: .55rem .5rem; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: .82rem; color: var(--muted); font-weight: 600; white-space: nowrap; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
tr.clickable { cursor: pointer; }
tr.clickable:hover td { background: #f7f9fc; }

/* ---------- ป้าย/แจ้งเตือน ---------- */
.tag { display: inline-block; font-size: .78rem; padding: .08rem .5rem; border-radius: 999px; background: var(--grey-bg); color: #394150; white-space: nowrap; }
.tag.ok { background: var(--ok-bg); color: var(--ok); }
.tag.warn { background: var(--warn-bg); color: var(--warn); }
.tag.danger { background: var(--danger-bg); color: var(--danger); }
.tag.info { background: var(--info-bg); color: var(--primary-dark); }
.alert { padding: .75rem .9rem; border-radius: 10px; margin-bottom: 1rem; background: var(--info-bg); }
.alert.error { background: var(--danger-bg); color: #8a1c1c; }
.alert.ok { background: var(--ok-bg); color: #145c29; }
.alert.warn { background: var(--warn-bg); color: #6b4a00; }
.empty { text-align: center; color: var(--muted); padding: 2rem 1rem; }

#toast {
  position: fixed; left: 50%; bottom: 1.2rem; transform: translateX(-50%);
  background: #172033; color: #fff; padding: .7rem 1rem; border-radius: 10px;
  z-index: 100; max-width: 92vw; box-shadow: 0 6px 20px rgba(0,0,0,.25); font-size: .95rem;
}
#toast.error { background: #a4161a; }

/* ---------- แท็บ ---------- */
.tabs { display: flex; gap: .25rem; overflow-x: auto; border-bottom: 1px solid var(--line); margin-bottom: 1rem; }
.tabs button { font: inherit; background: none; border: 0; padding: .6rem .8rem; cursor: pointer; color: var(--muted); border-bottom: 3px solid transparent; white-space: nowrap; }
.tabs button.active { color: var(--primary); border-bottom-color: var(--primary); font-weight: 600; }

/* ---------- dialog ---------- */
dialog { border: 0; border-radius: 14px; padding: 0; width: min(560px, 94vw); box-shadow: 0 20px 60px rgba(0,0,0,.3); }
dialog::backdrop { background: rgba(15, 23, 42, .45); }
dialog .dlg-body { padding: 1rem; max-height: 80vh; overflow-y: auto; }
dialog .dlg-foot { padding: .75rem 1rem; border-top: 1px solid var(--line); display: flex; gap: .5rem; justify-content: flex-end; }

.auth-wrap { max-width: 420px; margin: 8vh auto; padding: 0 1rem; }
.stat { font-size: 1.6rem; font-weight: 700; }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: .3rem .9rem; font-size: .95rem; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; }
.spinner { display: inline-block; width: 1em; height: 1em; border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: spin .7s linear infinite; vertical-align: -2px; }
@keyframes spin { to { transform: rotate(360deg); } }

@media print {
  .topbar, .nav, .fab, .no-print { display: none !important; }
  body { background: #fff; }
  .card { box-shadow: none; }
}

/* ---------- ผังชั้น-ห้อง ---------- */
.floorplan { display: flex; flex-direction: column; gap: .4rem; }
.floor-row { display: flex; gap: .4rem; align-items: stretch; }
.floor-label { flex: none; width: 4.5rem; font-size: .82rem; color: var(--muted); display: flex; align-items: center; }
.floor-units { display: flex; flex-wrap: wrap; gap: .35rem; flex: 1; }
.ucell {
  min-width: 3.6rem; padding: .35rem .45rem; border-radius: 8px; text-align: center; cursor: pointer;
  border: 1px solid transparent; font-weight: 600; font-size: .9rem; line-height: 1.2; color: var(--text);
}
.ucell small { display: block; font-weight: 400; font-size: .7rem; }
.ucell:hover { text-decoration: none; filter: brightness(.95); }
.st-vacant { background: #fff4d6; border-color: #f3d58a; }
.st-occupied { background: #e6f4ea; border-color: #a9d8b6; }
.st-reserved { background: #e8f0fe; border-color: #b6ccf5; }
.st-maintenance { background: #fdecea; border-color: #f1b7b3; }
.st-unavailable { background: #eef0f3; border-color: #d5d9df; color: var(--muted); }
.legend { display: flex; flex-wrap: wrap; gap: .5rem; font-size: .8rem; margin: .5rem 0 1rem; }
.legend span { padding: .05rem .5rem; border-radius: 6px; }
.photo-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: .5rem; }
.photo-grid figure { margin: 0; position: relative; }
.photo-grid img { width: 100%; aspect-ratio: 1; object-fit: cover; border-radius: 10px; cursor: zoom-in; background: var(--grey-bg); }
.photo-grid figcaption { font-size: .8rem; color: var(--muted); }
.photo-grid .del { position: absolute; top: .3rem; right: .3rem; }
.header-card { display: flex; gap: 1rem; flex-wrap: wrap; align-items: flex-start; }
.header-card .cover { width: 120px; height: 120px; border-radius: 12px; object-fit: cover; background: var(--grey-bg); display:flex; align-items:center; justify-content:center; font-size: 2.5rem; color:#9aa3af; }
.err-row td { background: var(--danger-bg); }

/* ---------- งานซ่อม ---------- */
.board { display: grid; gap: .75rem; grid-template-columns: 1fr; }
@media (min-width: 800px) { .board { grid-template-columns: repeat(4, 1fr); } }
.board-col { background: #eceff3; border-radius: 12px; padding: .5rem; min-height: 6rem; }
.board-col h3 { margin: .2rem .3rem .5rem; font-size: .95rem; }
.wo-card { display: flex; gap: .5rem; background: #fff; border-radius: 10px; padding: .55rem; margin-bottom: .5rem; color: var(--text); box-shadow: var(--shadow); }
.wo-card:hover { text-decoration: none; box-shadow: 0 2px 10px rgba(16,24,40,.15); }
.wo-card.urgent { border-left: 4px solid var(--danger); }
.wo-card img { width: 56px; height: 56px; object-fit: cover; border-radius: 8px; flex: none; }
.bars { display: flex; align-items: flex-end; gap: .3rem; height: 140px; padding: .5rem 0; }
.bar { flex: 1; display: flex; flex-direction: column; justify-content: flex-end; align-items: center; height: 100%; }
.bar-fill { width: 100%; background: var(--primary); border-radius: 4px 4px 0 0; min-height: 2px; }
.bar small { font-size: .68rem; color: var(--muted); }
.timeline-ev { border-left: 2px solid var(--line); padding: 0 0 .7rem .8rem; margin-left: .3rem; position: relative; }
.timeline-ev::before { content: ""; position: absolute; left: -6px; top: .35rem; width: 10px; height: 10px; border-radius: 50%; background: var(--primary); }
.stage-photos { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: .4rem; margin: .3rem 0 .8rem; }
.stage-photos img { width: 100%; aspect-ratio: 1; object-fit: cover; border-radius: 8px; cursor: zoom-in; }
.qr-label { display: inline-flex; flex-direction: column; align-items: center; border: 1px dashed #999; padding: .5rem; margin: .3rem; width: 190px; text-align: center; font-size: .8rem; break-inside: avoid; }

/* ---------- กระดิ่ง ---------- */
.bell-panel { position: absolute; right: .5rem; top: 100%; width: min(380px, 94vw); max-height: 70vh; overflow-y: auto;
  background: #fff; color: var(--text); border-radius: 12px; box-shadow: 0 12px 40px rgba(0,0,0,.25); z-index: 60; }
.bell-item { display: flex; gap: .5rem; padding: .6rem .8rem; border-bottom: 1px solid var(--line); align-items: flex-start; }
.bell-item a { color: var(--text); flex: 1; }
.bell-item a:hover { text-decoration: none; background: #f7f9fc; }
.topbar { position: sticky; }

/* ---------- ของในห้อง / แปลน (งาน 008) ---------- */
.floor-label { flex-direction: column; align-items: flex-start; justify-content: center; gap: .15rem; }
.floor-label .btn-link { font-size: .74rem; cursor: pointer; text-align: left; }
.inspect-row { display: flex; flex-wrap: wrap; gap: .4rem; align-items: center; padding: .5rem 0; border-bottom: 1px solid var(--line); }
dialog.plan-viewer { width: 100vw; max-width: 100vw; height: 100vh; height: 100dvh; max-height: 100dvh; margin: 0; border-radius: 0; background: #1f2937; }
dialog.plan-viewer[open] { display: flex; flex-direction: column; }
.plan-bar { flex: none; display: flex; gap: .4rem; align-items: center; padding: .5rem; background: #fff; }
.plan-title { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: .95rem; }
.plan-scroll { flex: 1; overflow: auto; -webkit-overflow-scrolling: touch; touch-action: pan-x pan-y pinch-zoom; }
.plan-stage { margin: 0 auto; }
.plan-stage .empty { color: #cbd5e1; }
.plan-page { display: block; width: 100%; height: auto; margin: 0 auto .5rem; background: #fff; }
.plan-frame { display: block; width: 100%; height: calc(100dvh - 60px); border: 0; background: #fff; }
.inv-item { display: flex; gap: .6rem; align-items: flex-start; padding: .65rem 0; border-bottom: 1px solid var(--line); cursor: pointer; }
.inv-item:hover { background: #f7f9fc; }
.inv-pic { flex: none; width: 52px; height: 52px; border-radius: 8px; background: var(--grey-bg); display: flex; align-items: center; justify-content: center; font-size: 1.4rem; overflow: hidden; }
.inv-pic img { width: 100%; height: 100%; object-fit: cover; }
.inv-main { flex: 1; min-width: 0; }
.inv-meta { display: flex; flex-wrap: wrap; gap: .15rem .9rem; font-size: .86rem; color: var(--muted); margin-top: .2rem; }
