/* POOMWIWAT V7 dashboard — iPad-first, plain CSS, system Thai fonts only */
:root {
  --brand: #0f4c5c; --brand-2: #16697a; --brand-soft: #e6f0f2;
  --ink: #1d2733; --ink-2: #4a5866; --ink-3: #7b8794; --line: #dde3e8; --bg: #f3f5f7; --card: #fff;
  --red: #c62828; --red-soft: #fdecea; --amber: #b26a00; --amber-soft: #fff4e0; --green: #1b7f4b; --green-soft: #e5f5ec;
  --radius: 14px; --tap: 48px; --shadow: 0 1px 2px rgba(16,24,40,.06), 0 1px 3px rgba(16,24,40,.08);
  --font: -apple-system, BlinkMacSystemFont, "Sukhumvit Set", "Thonburi", "Leelawadee UI", "Leelawadee", "Noto Sans Thai", "Tahoma", sans-serif;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; font-family: var(--font); font-size: 17px; line-height: 1.5; color: var(--ink); background: var(--bg); -webkit-tap-highlight-color: transparent; }
a { color: var(--brand-2); }
button, input, select, textarea { font: inherit; color: inherit; }
h1, h2, h3 { line-height: 1.25; margin: 0; }
.hidden { display: none !important; }
.viewer .owner-only { display: none !important; }
.muted { color: var(--ink-3); }
.small { font-size: 14px; }

/* ---------- top bar & nav ---------- */
.topbar { position: sticky; top: 0; z-index: 20; background: var(--brand); color: #fff; padding: env(safe-area-inset-top) 0 0; box-shadow: 0 2px 8px rgba(0,0,0,.12); }
.topbar-row { display: flex; align-items: center; gap: 12px; padding: 10px 20px; max-width: 1400px; margin: 0 auto; }
.logo { width: 40px; height: 40px; border-radius: 10px; background: #fff; color: var(--brand); display: grid; place-items: center; font-weight: 800; font-size: 16px; flex: 0 0 auto; }
.app-title { font-weight: 700; font-size: 18px; line-height: 1.2; }
.app-sub { font-size: 13px; opacity: .8; }
.spacer { flex: 1; }
.user-chip { display: flex; align-items: center; gap: 8px; font-size: 14px; }
.user-chip .role { background: rgba(255,255,255,.18); border-radius: 999px; padding: 2px 10px; }
.nav { display: flex; gap: 4px; overflow-x: auto; padding: 0 14px; max-width: 1400px; margin: 0 auto; scrollbar-width: none; }
.nav::-webkit-scrollbar { display: none; }
.nav a { flex: 0 0 auto; display: flex; align-items: center; gap: 6px; min-height: var(--tap); padding: 0 14px; color: rgba(255,255,255,.82); text-decoration: none; font-weight: 600; font-size: 16px; border-bottom: 3px solid transparent; }
.nav a.active { color: #fff; border-bottom-color: #ffd166; }
.badge { display: inline-grid; place-items: center; min-width: 22px; height: 22px; padding: 0 6px; border-radius: 999px; background: #ffd166; color: #3d2b00; font-size: 13px; font-weight: 700; }
.badge.red { background: var(--red); color: #fff; }

main { max-width: 1400px; margin: 0 auto; padding: 18px 20px calc(40px + env(safe-area-inset-bottom)); }
.page-head { display: flex; align-items: center; flex-wrap: wrap; gap: 12px; margin-bottom: 16px; }
.page-head h1 { font-size: 24px; }
.page-head .spacer { min-width: 8px; }

/* ---------- buttons & inputs ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: var(--tap); min-width: var(--tap); padding: 0 18px; border-radius: 12px; border: 1px solid var(--line); background: #fff; color: var(--ink); font-weight: 600; cursor: pointer; text-decoration: none; white-space: nowrap; }
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.danger { color: var(--red); border-color: #f2c4c0; }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.small { min-height: 44px; padding: 0 14px; font-size: 15px; }
.btn[disabled] { opacity: .45; pointer-events: none; }
.btn svg { width: 20px; height: 20px; }
.input, select.input, textarea.input { min-height: var(--tap); padding: 8px 12px; border: 1px solid #c9d2da; border-radius: 12px; background: #fff; width: 100%; }
textarea.input { min-height: 90px; }
.input:focus { outline: 3px solid rgba(22,105,122,.25); border-color: var(--brand-2); }
label.field { display: block; margin-bottom: 14px; }
label.field > span { display: block; font-size: 14px; color: var(--ink-2); margin-bottom: 4px; font-weight: 600; }
.row { display: flex; gap: 12px; flex-wrap: wrap; align-items: center; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 14px; }

/* ---------- date bar ---------- */
.datebar { display: flex; align-items: center; gap: 6px; background: #fff; border: 1px solid var(--line); border-radius: 14px; padding: 4px; box-shadow: var(--shadow); }
.datebar .btn { border: 0; }
.datebar .date-label { min-width: 190px; text-align: center; font-weight: 700; font-size: 18px; position: relative; }
.datebar .date-label input { position: absolute; inset: 0; opacity: 0; width: 100%; cursor: pointer; }
.datebar .date-label small { display: block; font-weight: 500; font-size: 13px; color: var(--ink-3); line-height: 1.1; }

/* ---------- status strip ---------- */
.status-strip { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin-bottom: 18px; }
.stat { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; display: flex; align-items: center; gap: 12px; text-decoration: none; color: inherit; box-shadow: var(--shadow); min-height: 72px; }
.stat .ico { width: 42px; height: 42px; border-radius: 12px; display: grid; place-items: center; background: var(--brand-soft); color: var(--brand); flex: 0 0 auto; }
.stat .ico svg { width: 22px; height: 22px; }
.stat .v { font-weight: 700; font-size: 18px; line-height: 1.2; }
.stat .l { font-size: 13px; color: var(--ink-3); }
.stat.warn .ico { background: var(--amber-soft); color: var(--amber); }
.stat.alert .ico { background: var(--red-soft); color: var(--red); }
.stat.ok .ico { background: var(--green-soft); color: var(--green); }
.meter { height: 6px; background: #e8edf1; border-radius: 3px; overflow: hidden; margin-top: 4px; width: 110px; }
.meter > i { display: block; height: 100%; background: var(--brand-2); }
.stat.warn .meter > i { background: var(--amber); }

/* ---------- sessions (§8.10) ---------- */
.sessions { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 4px; }
.sess { font-size: 13px; border-radius: 999px; padding: 1px 9px; background: #eef1f4; color: var(--ink-2); white-space: nowrap; }
.sess.here { background: var(--brand-soft); color: var(--brand); font-weight: 600; }

/* ---------- OA themes (§8.11) ---------- */
.themes { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 14px; }
.theme img { width: 100%; aspect-ratio: 16/10; object-fit: cover; border-radius: 10px; display: block; background: #e3e8ec; }
.theme.on { border-color: var(--green); box-shadow: 0 0 0 3px var(--green-soft); }

/* ---------- banners ---------- */
.banner { display: flex; flex-direction: column; gap: 2px; padding: 14px 18px; border-radius: var(--radius); margin-bottom: 16px; text-decoration: none; color: inherit; border: 1px solid; }
.banner.warn { background: var(--amber-soft); border-color: #f0c27a; color: #6b4300; }
.banner span { font-size: 15px; }

/* ---------- project cards ---------- */
.section-title { font-size: 15px; font-weight: 700; color: var(--ink-2); margin: 22px 0 10px; display: flex; align-items: center; gap: 8px; }
.cards { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px 18px; }
a.card { display: block; color: inherit; text-decoration: none; }
a.card:active { background: #fafbfc; }
.pcard { display: flex; flex-direction: column; gap: 10px; border-left: 6px solid var(--green); min-height: 170px; }
.pcard.missing { border-left-color: var(--red); background: linear-gradient(0deg, #fff, #fff 60%, var(--red-soft)); border-color: #f3c7c3; }
.pcard .top { display: flex; gap: 12px; align-items: flex-start; }
.pcard .name { font-weight: 700; font-size: 19px; line-height: 1.3; }
.pcard .meta { font-size: 14px; color: var(--ink-3); margin-top: 2px; }
.pcard .count { margin-left: auto; text-align: right; flex: 0 0 auto; }
.pcard .count b { display: block; font-size: 32px; line-height: 1; color: var(--brand); }
.pcard .count span { font-size: 13px; color: var(--ink-3); }
.pcard.missing .count b { color: var(--red); }
.missing-flag { display: inline-flex; align-items: center; gap: 6px; color: var(--red); font-weight: 700; font-size: 15px; background: #fff; border: 1px solid #f3c7c3; border-radius: 999px; padding: 4px 12px; width: fit-content; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { display: inline-flex; align-items: center; gap: 6px; border-radius: 999px; background: #f1f4f6; padding: 4px 10px; font-size: 14px; }
.chip b { color: var(--brand); }
.chip.k-employee { background: #e8f1fb; } .chip.k-subcontractor { background: #fff3e2; } .chip.k-supplier { background: #eef7ea; }
.pcard .foot { margin-top: auto; display: flex; justify-content: space-between; align-items: center; font-size: 14px; color: var(--ink-3); }
.pill { display: inline-block; border-radius: 999px; padding: 2px 10px; font-size: 13px; font-weight: 600; background: #eef1f4; color: var(--ink-2); }
.pill.red { background: var(--red-soft); color: var(--red); } .pill.amber { background: var(--amber-soft); color: var(--amber); } .pill.green { background: var(--green-soft); color: var(--green); }

/* ---------- photo grid ---------- */
.thumbs { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.thumb { position: relative; border-radius: 12px; overflow: hidden; background: #e3e8ec; aspect-ratio: 4/3; border: 0; padding: 0; cursor: pointer; display: block; width: 100%; }
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.thumb .cap { position: absolute; left: 0; right: 0; bottom: 0; padding: 18px 8px 5px; font-size: 13px; color: #fff; text-align: left; background: linear-gradient(transparent, rgba(0,0,0,.65)); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.thumb .star { position: absolute; top: 6px; right: 6px; background: #ffd166; color: #3d2b00; border-radius: 999px; font-size: 12px; font-weight: 700; padding: 1px 8px; }
.thumb .noimg { display: grid; place-items: center; height: 100%; color: var(--ink-3); font-size: 13px; }
.thumb.sel { outline: 4px solid var(--brand-2); outline-offset: -4px; }
.thumb .tick { position: absolute; top: 6px; left: 6px; width: 30px; height: 30px; border-radius: 50%; border: 2px solid #fff; background: rgba(0,0,0,.25); display: grid; place-items: center; color: #fff; font-weight: 800; }
.thumb.sel .tick { background: var(--brand-2); }

/* ---------- lists & tables ---------- */
.list { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.list-item { display: flex; gap: 14px; align-items: center; padding: 12px 16px; border-bottom: 1px solid var(--line); min-height: 64px; }
.list-item:last-child { border-bottom: 0; }
.list-item .main { flex: 1; min-width: 0; }
.list-item .title { font-weight: 700; }
.list-item .sub { font-size: 14px; color: var(--ink-3); }
.avatar { width: 44px; height: 44px; border-radius: 50%; background: var(--brand-soft); color: var(--brand); display: grid; place-items: center; font-weight: 700; flex: 0 0 auto; }
table.tbl { width: 100%; border-collapse: collapse; background: #fff; }
.tbl th, .tbl td { padding: 10px 12px; border-bottom: 1px solid var(--line); text-align: left; font-size: 15px; vertical-align: top; }
.tbl td.nw { white-space: nowrap; }
.tbl th { color: var(--ink-3); font-weight: 600; font-size: 13px; background: #fafbfc; }
.tabs { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 14px; }
.tabs button { min-height: 44px; padding: 0 16px; border-radius: 999px; border: 1px solid var(--line); background: #fff; font-weight: 600; cursor: pointer; }
.tabs button.on { background: var(--brand); color: #fff; border-color: var(--brand); }
.checks { display: flex; flex-wrap: wrap; gap: 8px; }
.check { display: inline-flex; align-items: center; gap: 8px; min-height: 44px; padding: 0 14px; border: 1px solid #c9d2da; border-radius: 12px; background: #fff; cursor: pointer; user-select: none; }
.check input { width: 20px; height: 20px; accent-color: var(--brand); }
.check:has(input:checked) { border-color: var(--brand-2); background: var(--brand-soft); }
.empty { text-align: center; padding: 40px 20px; color: var(--ink-3); }
.empty .big { font-size: 40px; }
.notes-list { list-style: none; margin: 0; padding: 0; }
.notes-list li { padding: 10px 0; border-bottom: 1px solid var(--line); }
.notes-list li:last-child { border-bottom: 0; }
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; margin-top: 14px; }
.two-col.wide-left { grid-template-columns: 1.5fr 1fr; }

/* ---------- modal, lightbox, toast ---------- */
.overlay { position: fixed; inset: 0; background: rgba(15,23,32,.55); z-index: 50; display: flex; align-items: center; justify-content: center; padding: 16px; }
.modal { background: #fff; border-radius: 18px; width: min(640px, 100%); max-height: calc(100vh - 32px); overflow: auto; padding: 20px 22px; box-shadow: 0 20px 50px rgba(0,0,0,.25); }
.modal h2 { font-size: 20px; margin-bottom: 14px; }
.modal .actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 18px; flex-wrap: wrap; }
.lightbox { position: fixed; inset: 0; background: rgba(0,0,0,.92); z-index: 60; display: flex; flex-direction: column; }
.lightbox .lb-img { flex: 1; min-height: 0; display: flex; align-items: center; justify-content: center; padding: 10px; }
.lightbox img { max-width: 100%; max-height: 100%; object-fit: contain; }
.lightbox .lb-bar { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; padding: 12px 16px calc(12px + env(safe-area-inset-bottom)); color: #fff; background: rgba(0,0,0,.5); }
.lightbox .lb-bar .btn { background: rgba(255,255,255,.12); color: #fff; border-color: rgba(255,255,255,.25); }
.lightbox .lb-bar select { max-width: 260px; }
.toast { position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom)); transform: translateX(-50%); background: #1d2733; color: #fff; padding: 12px 20px; border-radius: 12px; z-index: 80; box-shadow: 0 8px 24px rgba(0,0,0,.25); max-width: calc(100% - 32px); }
.toast.err { background: var(--red); }

/* ---------- login ---------- */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 20px; background: linear-gradient(160deg, var(--brand) 0%, var(--brand-2) 55%, #2a8c9a 100%); }
.login-card { background: #fff; border-radius: 22px; padding: 30px 28px; width: min(420px, 100%); box-shadow: 0 24px 60px rgba(0,0,0,.25); }
.login-card .logo { width: 56px; height: 56px; font-size: 20px; background: var(--brand); color: #fff; margin-bottom: 14px; }
.login-card h1 { font-size: 22px; } .login-card p { color: var(--ink-3); margin: 4px 0 20px; font-size: 15px; }
.login-card .btn { width: 100%; margin-top: 6px; }
.form-error { color: var(--red); font-size: 15px; min-height: 22px; margin: 4px 0; }

.pager { display: flex; gap: 10px; align-items: center; justify-content: center; margin-top: 16px; }
.loading { padding: 40px; text-align: center; color: var(--ink-3); }

/* ---------- responsive ---------- */
@media (min-width: 1200px) { .cards { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
@media (max-width: 900px) { .status-strip { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 640px) {
  body { font-size: 16px; }
  main { padding: 14px 12px 40px; }
  .topbar-row { padding: 8px 12px; } .app-sub, .user-chip .name { display: none; } .app-title { font-size: 16px; white-space: nowrap; }
  .cards, .two-col, .two-col.wide-left, .grid2 { grid-template-columns: 1fr; }
  .status-strip { gap: 8px; } .stat { padding: 10px; gap: 8px; } .stat .ico { width: 36px; height: 36px; }
  .datebar { width: 100%; } .datebar .date-label { flex: 1; min-width: 0; }
  .page-head h1 { font-size: 21px; }
  .thumbs { grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); }
  .tbl.responsive thead { display: none; }
  .tbl.responsive tr { display: block; border-bottom: 1px solid var(--line); padding: 6px 0; }
  .tbl.responsive td { display: block; border: 0; padding: 2px 12px; }
}
