/* ===========================================================
   ระบบจองแผงตลาด — ดีไซน์ซิสเต็มกลาง
   ใช้ร่วมกันทุกหน้า: login / index / map / receipt / admin_dashboard
   Breakpoints: 1200 (โน้ตบุ๊กเล็ก) · 1024 (iPad แนวนอน)
                860 (iPad แนวตั้ง) · 640 (มือถือ)
   =========================================================== */

:root {
    /* ── สีแบรนด์: โทนอำพัน/ส้มไหม้ ถอดจากโลโก้ตลาดนัดกลางคืน ──
       ใช้กับ "ตัวตนของระบบ" เท่านั้น — ลิงก์ หัวข้อ ขอบที่กำลังโฟกัส แถบเครื่องมือ
       ไม่ใช้สื่อสถานะ เพราะสถานะมีภาษาสีของตัวเองอยู่ด้านล่าง */
    --brand:        #b45309;   /* อำพันเข้ม · ตัวอักษรบนพื้นขาว 5.1:1 */
    --brand-2:      #f59e0b;   /* อำพันสด · ใช้เน้นบนพื้นเข้มเท่านั้น */
    --brand-soft:   #fef3c7;
    --brand-line:   #fcd34d;

    /* ── สีลงมือทำ: ปุ่มหลักทุกปุ่มที่ "ยืนยัน/บันทึก/จอง" ──
       แยกจากสีแบรนด์ตั้งใจ เพื่อให้ตาหาปุ่มที่ต้องกดเจอทันทีในหน้าที่มีสีอำพันเยอะ */
    --accent:       #2563eb;
    --accent-soft:  #eff6ff;
    --accent-line:  #bfdbfe;

    /* ── ภาษาสีของสถานะ: ห้ามซ้ำกับสีแบรนด์ ──
       ค่าทั้งหมดถูกยกให้เข้ม พอที่ตัวอักษรบนพื้นอ่อนคู่กันจะผ่าน 4.5:1
       (ชุดเดิมสีเหลือง #d97706 บนพื้น #fffbeb ได้แค่ 3.1:1 — อ่านยากกลางแดด) */
    --ok:           #047857;   /* ว่าง · อนุมัติแล้ว      5.5:1 */
    --ok-soft:      #ecfdf5;
    --warn:         #a16207;   /* รอตรวจสอบ · รอเปิดจอง   4.9:1 */
    --warn-soft:    #fefce8;
    --danger:       #be123c;   /* เต็ม · ปิดรับจอง        6.3:1 */
    --danger-soft:  #fff1f2;
    --info:         #0369a1;   /* ข้อมูลทั่วไป            5.9:1 */
    --info-soft:    #f0f9ff;
    --violet:       #6d28d9;   /* เช็คอินแล้ว             7.1:1 */
    --violet-soft:  #f5f3ff;

    /* พื้นหลังเป็นเทาอมอุ่น ไม่ใช่ครีม — ครีมจะไปกลืนกับสถานะ "รอ" ที่เป็นสีเหลือง */
    --bg:           #f7f5f2;
    --surface:      #ffffff;
    --surface-2:    #faf8f5;
    --line:         #e9e5df;
    --line-strong:  #d8d2c9;

    --ink:          #241c14;
    --ink-2:        #554c42;
    /* สีข้อความรอง — เดิม #757c90 / #857a6e ได้แค่ 4.2:1 ตกเกณฑ์ WCAG AA
       ค่านี้ใช้กับ .muted, .hint, แท็บที่ไม่ได้เลือก และปุ่ม .btn--quiet ซึ่งเป็นข้อความที่ต้องอ่านออกจริง
       ไม่ใช่แค่ของประดับ จึงต้องผ่าน 4.5:1 บนพื้นทั้งสามระดับ (ขาว / surface-2 / bg) */
    --muted:        #736a60;   /* 5.3:1 บนขาว · 4.9:1 บนพื้นหน้า */

    --r-sm: 8px;
    --r:    12px;
    --r-lg: 16px;
    --r-pill: 999px;

    /* เงาอมน้ำตาลอ่อน ๆ ให้เข้ากับพื้นอุ่น — เงาสีเทาอมฟ้าจะดูสกปรกบนพื้นนี้ */
    --sh-sm: 0 1px 2px rgba(60, 42, 20, .06);
    --sh:    0 2px 8px rgba(60, 42, 20, .08);
    --sh-lg: 0 18px 45px rgba(45, 32, 16, .22);

    --gap: 18px;
    --safe-b: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
    margin: 0;
    padding: 24px 20px calc(56px + var(--safe-b));
    font-family: 'Kanit', 'Segoe UI', sans-serif;
    font-weight: 300;
    background: var(--bg);
    color: var(--ink);
    font-size: 15px;
    line-height: 1.55;
    -webkit-font-smoothing: antialiased;
    -webkit-tap-highlight-color: rgba(180, 83, 9, .1);
}

h1, h2, h3, h4 { margin: 0; font-weight: 600; line-height: 1.3; letter-spacing: -.01em; }
h2 { font-size: 20px; }
h3 { font-size: 17px; }
h4 { font-size: 15px; }
a  { color: var(--brand); }

/* ⌨️ วงแหวนโฟกัสสำหรับคนที่ใช้แป้นพิมพ์ — เดิมปุ่มไม่มีเลย กด Tab แล้วไม่รู้ว่าอยู่ตรงไหน
   ใช้ :focus-visible เพื่อไม่ให้วงแหวนโผล่ตอนใช้เมาส์กด */
:where(a, button, .btn, .tile, [tabindex]):focus-visible,
input:focus-visible, select:focus-visible, textarea:focus-visible {
    outline: 2px solid var(--brand);
    outline-offset: 2px;
    border-radius: var(--r-sm);
}

/* 🚦 เคารพการตั้งค่า "ลดการเคลื่อนไหว" ของเครื่อง (คนที่เวียนหัวง่ายเปิดไว้) */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: .01ms !important; animation-iteration-count: 1 !important;
        transition-duration: .01ms !important; scroll-behavior: auto !important;
    }
}

/* ---------- ไอคอน SVG (แทนอีโมจิ) ---------- */
.ic       { width: 1.15em; height: 1.15em; flex: none; vertical-align: -.19em; }
.ic--lg   { width: 22px; height: 22px; vertical-align: middle; }
.ic--tile { width: 21px; height: 21px; }

.page { width: 100%; max-width: 1180px; margin: 0 auto; }
.page--wide   { max-width: 1440px; }
.page--narrow { max-width: 560px; }

.muted   { color: var(--muted); }
.small   { font-size: 13px; }
.tiny    { font-size: 12px; }
.strong  { font-weight: 600; }
.right   { text-align: right; }
.center  { text-align: center; }
.nowrap  { white-space: nowrap; }
.stack   { display: flex; flex-direction: column; gap: 10px; }
.row     { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.row--between { justify-content: space-between; }
.grow    { flex: 1; min-width: 0; }
.mt-0 { margin-top: 0; } .mb-0 { margin-bottom: 0; }
.mt-2 { margin-top: 18px; } .mb-2 { margin-bottom: 18px; }
.hide { display: none !important; }
.tnum { font-variant-numeric: tabular-nums; }

/* ---------- Topbar ---------- */
.topbar {
    display: flex; align-items: center; justify-content: space-between;
    gap: 16px; flex-wrap: wrap;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--r-lg);
    padding: 14px 20px;
    margin-bottom: var(--gap);
    box-shadow: var(--sh-sm);
}
.topbar__title { display: flex; align-items: center; gap: 12px; min-width: 0; }
.topbar__title img { height: 38px; width: auto; border-radius: var(--r-sm); }
.topbar__title h2 { font-size: 18px; }
.topbar__actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }

.who {
    display: inline-flex; align-items: center; gap: 7px;
    background: var(--surface-2); border: 1px solid var(--line);
    border-radius: var(--r-pill); padding: 5px 14px;
    font-size: 13px; font-weight: 500; color: var(--ink-2);
}

/* ---------- Card ---------- */
.card {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--r-lg);
    box-shadow: var(--sh-sm);
    margin-bottom: var(--gap);
    overflow: hidden;
}
.card__hd {
    display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap;
    padding: 15px 20px;
    border-bottom: 1px solid var(--line);
    background: var(--surface);
}
.card__hd h3 { font-size: 15px; font-weight: 600; }
.card__hd .small { font-weight: 300; }
.card__bd { padding: 20px; }
.card__bd > :last-child { margin-bottom: 0; }
.card--flat { box-shadow: none; }
.card--accent { border-top: 3px solid var(--brand); }
.card--accent-ok   { border-top: 3px solid var(--ok); }
.card--accent-warn { border-top: 3px solid var(--warn); }

/* ---------- Buttons ---------- */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 7px;
    padding: 9px 16px;
    border: 1px solid transparent;
    border-radius: var(--r-sm);
    background: var(--accent); color: #fff;   /* ปุ่มหลัก = สีลงมือทำ ไม่ใช่สีแบรนด์ */
    font-family: inherit; font-size: 14px; font-weight: 500;
    line-height: 1.4;
    text-decoration: none; cursor: pointer;
    transition: filter .15s ease, background .15s ease, border-color .15s ease;
    white-space: nowrap;
    touch-action: manipulation;
}
.btn:hover    { filter: brightness(1.07); }
.btn:active   { filter: brightness(.95); }
.btn:disabled, .btn[disabled] { opacity: .45; cursor: not-allowed; filter: none; }

.btn--ok     { background: var(--ok); }
.btn--warn   { background: var(--warn); }
.btn--danger { background: var(--danger); }
.btn--info   { background: var(--info); }
.btn--dark   { background: var(--ink); }
.btn--brand  { background: var(--brand); }   /* ปุ่มที่เป็นตัวตนของตลาด เช่น สแกน QR เช็คอิน */
.btn--ghost  { background: var(--surface); color: var(--ink-2); border-color: var(--line-strong); }
.btn--ghost:hover { background: var(--surface-2); filter: none; }
.btn--line   { background: #06c755; }
.btn--quiet  { background: transparent; color: var(--muted); border-color: transparent; }
.btn--quiet:hover { background: var(--surface-2); color: var(--ink); filter: none; }

.btn--sm    { padding: 5px 11px; font-size: 12.5px; border-radius: 7px; }
.btn--lg    { padding: 12px 22px; font-size: 16px; }
.btn--block { width: 100%; }

/* ---------- Forms ---------- */
.field { margin-bottom: 14px; }
.field > label {
    display: block; margin-bottom: 6px;
    font-size: 13px; font-weight: 500; color: var(--ink-2);
}
.field .hint, .hint { display: block; margin-top: 5px; font-size: 12px; color: var(--muted); }

input[type=text], input[type=password], input[type=number], input[type=date],
input[type=time], input[type=datetime-local], input[type=file], input[type=tel], select, textarea {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--line-strong);
    border-radius: var(--r-sm);
    background: var(--surface);
    font-family: inherit; font-size: 14px; font-weight: 300; color: var(--ink);
    transition: border-color .15s ease, box-shadow .15s ease;
}
input:focus, select:focus, textarea:focus {
    outline: none;
    border-color: var(--brand);
    box-shadow: 0 0 0 3px rgba(180, 83, 9, .14);
}
input[type=color] { width: 38px; height: 38px; padding: 2px; border-radius: var(--r-sm); border: 1px solid var(--line-strong); background: var(--surface); cursor: pointer; }
textarea { resize: vertical; min-height: 62px; }
.input--sm { padding: 7px 10px; font-size: 13px; }
.check { display: inline-flex; align-items: center; gap: 7px; font-size: 13.5px; color: var(--ink-2); cursor: pointer; }
.check input { width: auto; margin: 0; accent-color: var(--brand); flex: none; }

/* แถวของช่องติ๊ก — อย่าใส่ไว้ใน .field เพราะ .field > label จะบังคับเป็น block แล้วข้อความตกบรรทัด */
.check-row { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 20px; margin-bottom: 14px; }
.check-row .check { min-height: 30px; }
@media (max-width: 460px) {
    /* จอแคบวางซ้อนกันอ่านง่ายกว่า และนิ้วกดไม่พลาด */
    .check-row { flex-direction: column; align-items: flex-start; gap: 8px; }
}

/* ---------- Grid ---------- */
.grid    { display: grid; gap: var(--gap); }
.grid--2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid--3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid--tight { gap: 12px; }
.grid--form  { grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); align-items: end; }

/* ---------- Table ---------- */
.table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.table th, .table td { padding: 10px 14px; text-align: left; border-bottom: 1px solid var(--line); }
.table th {
    background: var(--surface-2); color: var(--ink-2);
    font-weight: 600; font-size: 12.5px;
    position: sticky; top: 0; z-index: 1;
}
.table tbody tr:last-child td { border-bottom: none; }
.table tbody tr:hover { background: var(--surface-2); }
.table td.right, .table th.right { text-align: right; }

.scroll-y {
    max-height: 300px;
    overflow-y: auto; overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    border: 1px solid var(--line); border-radius: var(--r);
}
.scroll-x { width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch; }

.empty { padding: 28px 16px; text-align: center; color: var(--muted); font-size: 13.5px; }

/* ---------- Chips / badges ---------- */
.chip {
    display: inline-flex; align-items: center; gap: 5px;
    padding: 3px 10px; border-radius: var(--r-pill);
    font-size: 12px; font-weight: 500; line-height: 1.6;
    border: 1px solid transparent;
}
.chip--ok     { background: var(--ok-soft);     color: var(--ok);     border-color: #a7f3d0; }
.chip--warn   { background: var(--warn-soft);   color: var(--warn);   border-color: #fde68a; }
.chip--danger { background: var(--danger-soft); color: var(--danger); border-color: #fecdd3; }
.chip--info   { background: var(--info-soft);   color: var(--info);   border-color: #bae6fd; }
.chip--brand  { background: var(--brand-soft);  color: var(--brand);  border-color: var(--brand-line); }
.chip--muted  { background: var(--surface-2);   color: var(--muted);  border-color: var(--line); }
.chip--violet { background: var(--violet-soft); color: var(--violet); border-color: #ddd6fe; }
.chip .ic     { width: 13px; height: 13px; }

/* ---------- Alerts ---------- */
.alert {
    display: flex; align-items: flex-start; gap: 11px;
    padding: 13px 17px;
    border-radius: var(--r);
    border: 1px solid var(--line);
    background: var(--surface-2);
    font-size: 14px;
    margin-bottom: var(--gap);
}
.alert__icon { flex: none; line-height: 1; margin-top: 1px; }
.alert__icon .ic { width: 19px; height: 19px; }
.alert--info   { background: var(--info-soft);   border-color: #bae6fd; color: #075985; }
.alert--warn   { background: var(--warn-soft);   border-color: #fde68a; color: #854d0e; }
.alert--ok     { background: var(--ok-soft);     border-color: #a7f3d0; color: #065f46; }
.alert--danger { background: var(--danger-soft); border-color: #fecdd3; color: #9f1239; }
.alert--brand  { background: var(--brand-soft);  border-color: var(--brand-line); color: #7c3d09; }

/* ---------- Stats ---------- */
.stat {
    background: var(--surface); border: 1px solid var(--line);
    border-radius: var(--r-lg); padding: 16px 18px;
    box-shadow: var(--sh-sm);
}
.stat__label { font-size: 12.5px; color: var(--muted); font-weight: 400; margin-bottom: 4px; }
.stat__value { font-size: 24px; font-weight: 600; color: var(--ink); letter-spacing: -.02em; }
.stat--click { cursor: pointer; transition: border-color .15s ease, box-shadow .15s ease; }
.stat--click:hover { border-color: var(--brand-line); box-shadow: var(--sh); }

/* ---------- Tiles (เมนูจัดการในแผงควบคุม) ---------- */
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(255px, 1fr)); gap: 12px; }
.tile {
    display: flex; align-items: flex-start; gap: 12px; text-align: left;
    padding: 15px 16px;
    background: var(--surface); color: var(--ink);
    border: 1px solid var(--line); border-radius: var(--r);
    font-family: inherit; font-size: 14px; font-weight: 300;
    cursor: pointer; text-decoration: none;
    transition: border-color .15s ease, box-shadow .15s ease, transform .15s ease;
}
.tile:hover { border-color: var(--brand-line); box-shadow: var(--sh); transform: translateY(-2px); }
.tile:active { transform: none; }
.tile__icon { font-size: 24px; line-height: 1.1; flex: none; }
.tile__body { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.tile__body b { font-size: 15px; font-weight: 600; }
.tile__desc { font-size: 12.5px; color: var(--muted); line-height: 1.45; }

/* ---------- แถวรายการแจ้งเตือน ---------- */
.alert-row {
    display: flex; align-items: center; justify-content: space-between;
    gap: 12px; flex-wrap: wrap;
    padding: 12px 14px; margin-bottom: 9px;
    background: var(--surface-2);
    border: 1px solid var(--line); border-radius: var(--r);
}
.alert-row:last-child { margin-bottom: 0; }

/* ---------- ตารางสรุปเงิน ---------- */
.money-table td, .money-table th { padding: 9px 12px; }
.money-table .dot { display: inline-block; margin-right: 7px; vertical-align: middle; }
.money-table .right { font-variant-numeric: tabular-nums; white-space: nowrap; }
.money-sub td { border-top: 1px solid var(--line); font-weight: 500; }
.money-total td { border-top: 2px solid var(--line-strong); font-weight: 600; font-size: 15px; }
.money-table tbody tr:hover { background: transparent; }

/* ---------- Progress ---------- */
.bar { height: 9px; background: var(--surface-2); border-radius: var(--r-pill); overflow: hidden; border: 1px solid var(--line); }
/* ความกว้างถูกใส่มาจากฝั่งเซิร์ฟเวอร์ครั้งเดียวตอนเรนเดอร์ แล้วไม่เปลี่ยนอีก
   transition ที่เคยมีจึงไม่เคยทำงานจริงสักครั้ง — ตัดทิ้ง */
.bar__fill { height: 100%; background: var(--brand); border-radius: var(--r-pill); }

/* ---------- Dialog ---------- */
dialog {
    border: none; padding: 0;
    border-radius: var(--r-lg);
    box-shadow: var(--sh-lg);
    width: 95%; max-width: 560px; max-height: 88vh;
    background: var(--surface); color: var(--ink);
    font-family: inherit;
    overflow: hidden;
}
dialog::backdrop { background: rgba(17, 20, 33, .55); backdrop-filter: blur(2px); }
.dlg__hd {
    display: flex; align-items: center; justify-content: space-between; gap: 12px;
    padding: 16px 20px; border-bottom: 1px solid var(--line);
    background: var(--surface);
}
.dlg__hd h3 { font-size: 16px; }
.dlg__bd { padding: 20px; overflow-y: auto; -webkit-overflow-scrolling: touch; max-height: calc(88vh - 62px); }
.dlg__ft { display: flex; gap: 9px; flex-wrap: wrap; margin-top: 18px; }
.dlg__ft .btn { flex: 1; min-width: 130px; }
.dlg--wide { max-width: 900px; }

/* ---------- Calendar ----------
   ช่องวันบนมือถือกว้างจริงแค่ ~41px — ป้ายยาวอย่าง "ผ่านไปแล้ว" จึงตกเป็น 3 บรรทัด
   ดันปฏิทินยาวเกินสองหน้าจอ กว่าจะเลื่อนเจอวันที่จองได้จริง
   จึงเปลี่ยนเป็น: ตัวเลขวันเด่น + ป้ายสั้นสีตามสถานะ + คำอธิบายสีอยู่เหนือปฏิทินครั้งเดียว
   วันที่ผ่านไปแล้วไม่ต้องมีป้าย ปล่อยให้จมไปกับพื้น เพื่อให้สายตาไปเจอวันที่จองได้ก่อน   */
.cal { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 7px; }
.cal__dow {
    text-align: center; padding: 7px 2px;
    font-size: 12.5px; font-weight: 600; color: var(--ink-2);
    background: var(--surface-2); border-radius: var(--r-sm);
}
.cal__dow--sun { color: var(--danger); }
.cal__dow--sat { color: var(--info); }

/* คำอธิบายสีของปฏิทิน — จำเป็นเพราะป้ายในช่องถูกย่อให้สั้นที่สุด */
.cal-key { display: flex; flex-wrap: wrap; gap: 7px 16px; margin-bottom: 14px; font-size: 12.5px; }
.cal-key__item { display: inline-flex; align-items: center; gap: 6px; color: var(--ink-2); }
.cal-key__sw { width: 13px; height: 13px; border-radius: 4px; border: 1px solid; flex: none; }
.cal-key__sw--open   { background: var(--ok-soft);     border-color: #6ee7b7; }
.cal-key__sw--wait   { background: var(--warn-soft);   border-color: #fcd34d; }
.cal-key__sw--closed { background: var(--surface);     border-color: var(--line-strong); }
.cal-key__sw--past   { background: var(--surface-2);   border-color: var(--line); }

.day {
    position: relative;
    display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
    min-height: 74px; padding: 8px 3px;
    background: var(--surface-2);
    border: 1px solid var(--line);
    border-radius: var(--r);
    transition: transform .15s ease, box-shadow .15s ease, border-color .15s ease;
}
.day__num  { font-size: 17px; font-weight: 600; color: var(--ink); line-height: 1.1; }
.day__tag  { font-size: 10.5px; font-weight: 500; line-height: 1.2; text-align: center; }
.day__time { font-size: 10px; font-weight: 500; color: var(--ink-2); text-align: center; line-height: 1.25; }

.day--open   { background: var(--ok-soft);     border-color: #6ee7b7; cursor: pointer; }
.day--open   .day__tag { color: var(--ok); }
.day--open   .day__num { color: #064e3b; }
.day--open:hover  { transform: translateY(-2px); box-shadow: var(--sh); border-color: var(--ok); }

.day--wait   { background: var(--warn-soft);   border-color: #fcd34d; cursor: pointer; }
.day--wait   .day__tag { color: var(--warn); }
.day--wait:hover  { transform: translateY(-2px); box-shadow: var(--sh); border-color: var(--warn); }

/* "ปิดรับจอง" คือสถานะปกติของวันส่วนใหญ่ (ตลาดออกไม่กี่วันต่อเดือน) — ไม่ใช่เรื่องผิดปกติ
   ถ้าย้อมแดงทั้งเดือนจะกลบวันที่จองได้จริงจนหาไม่เจอ และดูเหมือนระบบมีปัญหา
   จึงให้ปิดเป็นสีเรียบเงียบ แล้วเก็บสีสดไว้ให้สองสถานะที่ต้องลงมือ: จองได้ (เขียว) · รอเปิด (เหลือง) */
.day--closed { background: var(--surface); border-color: var(--line-strong); }
.day--closed .day__tag { color: var(--muted); }
.day--closed .day__num { color: var(--ink-2); }

/* ผ่านไปแล้ว = ไม่ต้องดึงสายตา แต่ยังต้องอ่านตัวเลขออก จึงลดด้วยสี ไม่ใช่ opacity
   (opacity ทำให้ตัวหนังสือฟุ้งไม่คม บนจอความละเอียดต่ำ) */
.day--past   { background: var(--surface-2); border-color: var(--line); }
.day--past   .day__num { color: #a89e92; font-weight: 400; }

/* วันนี้ — ต้องหาเจอทันทีที่เปิดหน้า */
.day--today { box-shadow: inset 0 0 0 2px var(--brand); }
.day--today .day__num { color: var(--brand); font-weight: 700; }

/* แอดมินกดได้ทุกวัน รวมวันที่ผ่านไปแล้ว → ต้องไม่ดูจางจนเหมือนกดไม่ได้ */
.day--admin  { cursor: pointer; }
.day--admin.day--past .day__num { color: var(--ink-2); font-weight: 600; }
.day--admin:hover { transform: translateY(-2px); box-shadow: var(--sh); border-color: var(--brand-line); }
.day--admin.day--today:hover { box-shadow: inset 0 0 0 2px var(--brand), var(--sh); }
.day--void   { border: none; background: none; min-height: 0; }

/* ---------- Auth (login) ---------- */
.auth { width: 100%; max-width: 430px; margin: 6vh auto 0; }
.auth__brand { text-align: center; margin-bottom: 22px; }
.auth__brand h1 { font-size: 22px; }
.auth__brand p  { margin: 6px 0 0; color: var(--muted); font-size: 14px; }
.tabs { display: grid; grid-template-columns: 1fr 1fr; gap: 4px; padding: 4px; background: var(--surface-2); border-bottom: 1px solid var(--line); }
.tabs button {
    padding: 10px; border: none; border-radius: var(--r-sm);
    background: transparent; color: var(--muted);
    font-family: inherit; font-size: 14px; font-weight: 500; cursor: pointer;
    transition: background .15s ease, color .15s ease;
}
.tabs button.is-active { background: var(--surface); color: var(--brand); box-shadow: var(--sh-sm); }

/* ---------- Map page ---------- */
.map-layout { display: flex; gap: var(--gap); align-items: flex-start; }
.map-wrap { position: relative; flex: 4; min-width: 0; }
#market-map {
    width: 100%; height: 640px;
    border: 1px solid var(--line); border-radius: var(--r-lg);
    background: var(--surface); z-index: 1;
}
.map-fs-btn { position: absolute; right: 12px; top: 12px; z-index: 401; box-shadow: var(--sh); }
body.map-fs { overflow: hidden; }
body.map-fs .map-wrap { position: fixed; inset: 0; z-index: 2000; margin: 0; }
body.map-fs #market-map { height: 100%; border-radius: 0; border: none; }
/* กว้างพอให้แถวสถานะอยู่บรรทัดเดียวบนจอเดสก์ท็อป */
.side { flex: 1.15; min-width: 340px; }

.lock-label { background: none !important; border: none !important; box-shadow: none !important; color: #fff !important; text-shadow: 0 1px 3px rgba(0,0,0,.75); text-align: center; line-height: 1.2; }
.lock-id-txt { font-size: 13px; font-weight: 600; }
.lock-price  { font-size: 9.5px; color: #fde68a; }
.status-txt  { font-size: 9.5px; font-weight: 300; display: block; margin-top: -2px; }
.lock-disabled { cursor: not-allowed !important; pointer-events: none !important; }

/* แถวสถานะแบบบรรทัดเดียว — ตัดบรรทัดเองเมื่อจอแคบ */
.statline { display: flex; flex-wrap: wrap; align-items: center; gap: 5px 9px; font-size: 12.5px; }
.statline__item { display: inline-flex; align-items: center; gap: 4px; color: var(--ink-2); white-space: nowrap; }
.statline__item b { color: var(--ink); font-size: 13.5px; }
.statline .dot { width: 8px; height: 8px; }
.statline--mine { margin-top: 9px; padding-top: 9px; border-top: 1px solid var(--line); gap: 8px; }

.legend { display: flex; flex-direction: column; gap: 9px; font-size: 13.5px; }
.legend__row { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.legend__key { display: inline-flex; align-items: center; gap: 8px; color: var(--ink-2); }
.dot { width: 10px; height: 10px; border-radius: 50%; flex: none; }

/* แผงเครื่องมือเป็นพื้นที่ทำงาน ไม่ใช่คำเตือน — พื้นอำพันเต็มผืนดังเกินหน้าที่ของมัน
   ใช้พื้นอุ่นกลาง ๆ แล้วขีดเส้นบนเป็นสีแบรนด์แทน ยังบอกได้ว่านี่คือของแอดมิน
   ใช้ inset shadow ไม่ใช่ border-top หนา ๆ เพราะเส้นขอบหนาจะบานเป็นลิ่มตรงมุมโค้ง
   ส่วน inset shadow วิ่งตามความโค้งของมุมพอดี */
.toolbar {
    background: var(--surface-2);
    border: 1px solid var(--line-strong);
    box-shadow: inset 0 3px 0 var(--brand);
    border-radius: var(--r-lg); margin-bottom: var(--gap); overflow: hidden;
}
.toolbar__hd { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; padding: 12px 18px; }
.toolbar__bd { padding: 0 18px 16px; display: flex; flex-direction: column; gap: 10px; }
.modes { display: flex; gap: 10px; flex-wrap: wrap; }
.mode {
    display: flex; align-items: flex-start; gap: 9px;
    flex: 1; min-width: 215px; padding: 11px 14px;
    background: var(--surface); border: 1.5px solid var(--line); border-radius: var(--r);
    cursor: pointer; transition: border-color .15s ease;
}
.mode.is-active { border-color: var(--brand); }
.mode input { margin-top: 4px; accent-color: var(--brand); }
.mode b { font-size: 13.5px; font-weight: 600; }
.coord { display: inline-flex; align-items: center; gap: 6px; background: var(--surface); border: 1px solid var(--brand-line); border-radius: var(--r-pill); padding: 5px 14px; font-size: 13px; font-weight: 500; }
.coord input { width: 34px; padding: 0; border: none; background: transparent; color: var(--brand); font-weight: 600; text-align: center; }
.coord input:focus { box-shadow: none; }

#btnConfirmDelete {
    display: none; position: fixed; bottom: calc(22px + var(--safe-b)); left: 50%; transform: translateX(-50%);
    z-index: 950; box-shadow: var(--sh-lg); border-radius: var(--r-pill); padding: 13px 28px; font-size: 15px;
}

/* ---------- โหมดรอเวลาเปิดจอง (นับถอยหลัง) ---------- */
.lockbar {
    position: sticky; top: 0; z-index: 500;
    display: flex; align-items: center; justify-content: space-between;
    gap: 14px; flex-wrap: wrap;
    background: var(--warn-soft); border: 1px solid #fde68a; color: #92400e;
    border-radius: var(--r-lg); padding: 14px 20px; margin-bottom: var(--gap);
    box-shadow: var(--sh-sm);
}
.lockbar__time {
    font-size: 27px; font-weight: 600; color: var(--danger);
    font-variant-numeric: tabular-nums; letter-spacing: -.01em; line-height: 1.2;
}
.lockbar.is-open { background: var(--ok-soft); border-color: #a7f3d0; color: #065f46; }
.lockbar.is-open .lockbar__time { color: var(--ok); }

/* การ์ดที่ต้องถูกล็อกระหว่างรอเวลา (ตะกร้า) */
.lockable { position: relative; }
body.is-locked .lockable { pointer-events: none; }
body.is-locked .lockable::after {
    content: ''; position: absolute; inset: 0; z-index: 3;
    background: rgba(248, 250, 252, .6);
    border-radius: inherit;
}

/* ---------- แถบยืนยันติดขอบล่าง (แท็บเล็ต/มือถือ) ---------- */
.actionbar {
    display: none;
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 900;
    align-items: center; gap: 12px;
    background: var(--surface);
    border-top: 1px solid var(--line);
    box-shadow: 0 -6px 24px rgba(20, 24, 40, .10);
    padding: 10px 14px calc(10px + var(--safe-b));
}
.actionbar__info { flex: 1; min-width: 0; line-height: 1.25; font-size: 13px; }
.actionbar__info b { font-size: 15px; }
.actionbar .btn { flex: none; }

/* ---------- Receipt ---------- */
.receipt { max-width: 480px; margin: 0 auto; }
.receipt__hd { text-align: center; padding: 26px 24px 20px; border-bottom: 1px dashed var(--line-strong); }
.receipt__hd img { max-height: 54px; margin-bottom: 10px; border-radius: var(--r-sm); }
.r-row { display: flex; justify-content: space-between; gap: 14px; padding: 6px 0; font-size: 14px; }
.r-row span:first-child { color: var(--muted); }
.r-row b { font-weight: 500; text-align: right; }
.r-total { display: flex; justify-content: space-between; gap: 14px; margin-top: 12px; padding-top: 12px; border-top: 2px dashed var(--line-strong); font-size: 19px; font-weight: 600; color: var(--brand); }
.r-status { padding: 12px; border-radius: var(--r); text-align: center; font-weight: 500; font-size: 15px; }

/* QR รหัสบิลบนใบเสร็จ — คุมขนาดให้พอดี ไม่แย่งพื้นที่รายละเอียดบิล */
.qr-box {
    display: flex; flex-direction: column; align-items: center; gap: 5px;
    margin: 16px auto 4px; padding: 12px 14px;
    max-width: 240px;
    border: 1px dashed var(--line-strong); border-radius: var(--r);
    background: #fff;
}
.qr-img { line-height: 0; }
.qr-img img, .qr-img canvas { width: 118px; height: 118px; display: block; }
.qr-code {
    font-size: 14px; font-weight: 600; letter-spacing: .04em;
    color: var(--ink); word-break: break-all; text-align: center;
}

/* ===========================================================
   RESPONSIVE
   =========================================================== */

/* --- โน้ตบุ๊กเล็ก / iPad Pro แนวนอน --- */
@media (max-width: 1200px) {
    #market-map { height: 560px; }
    .side { min-width: 330px; flex: 1; }
}

/* --- iPad แนวนอน --- */
@media (max-width: 1024px) {
    .map-layout { flex-direction: column; }
    .map-wrap, .side { width: 100%; flex: none; min-width: 0; }
    #market-map { height: 48vh; min-height: 380px; }
    /* จอยังกว้างพอสำหรับ 2 คอลัมน์ — ไม่ควรยุบเหลือ 1 */
    .grid--3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .side .card { margin-bottom: 12px; }
}

/* --- iPad แนวตั้ง / มือถือใหญ่ --- */
@media (max-width: 860px) {
    body { padding: 18px 15px calc(48px + var(--safe-b)); }
    .grid--3, .grid--2 { grid-template-columns: 1fr; }
    .card__bd, .card__hd { padding: 16px; }

    /* กัน iOS Safari ซูมจอเองตอนโฟกัสช่องกรอก (ต้อง >= 16px) */
    input[type=text], input[type=password], input[type=number], input[type=date],
    input[type=time], input[type=datetime-local], input[type=file], input[type=tel],
    select, textarea, .input--sm { font-size: 16px; }

    .topbar { padding: 13px 16px; }
    .topbar__title { width: 100%; }
    .topbar__actions { width: 100%; display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
    .topbar__actions .who { grid-column: 1 / -1; justify-content: center; }
    .topbar__actions .btn { width: 100%; }

    .modes { flex-direction: column; }
    .mode { min-width: 0; }

    .actionbar.is-on { display: flex; }
    body.has-actionbar { padding-bottom: calc(92px + var(--safe-b)); }

    .lockbar { padding: 12px 16px; }
    .lockbar__time { font-size: 24px; }
}

/* --- มือถือ --- */
@media (max-width: 640px) {
    body { padding: 12px 11px calc(40px + var(--safe-b)); font-size: 14.5px; }
    h2 { font-size: 18px; }
    .card { border-radius: var(--r); margin-bottom: 14px; }
    .card__bd, .card__hd { padding: 14px; }
    .page, .page--wide { max-width: 100%; }

    /* ปฏิทินโหมดกระชับ — 7 คอลัมน์บนจอ 375px (ช่องกว้างจริง ~41px) */
    .cal { gap: 5px; }
    .cal__dow { padding: 6px 2px; font-size: 11.5px; }
    .day { min-height: 62px; padding: 6px 2px; gap: 2px; border-radius: var(--r-sm); }
    .day__num  { font-size: 15px; }
    .day__tag  { font-size: 9.5px; }
    .day__time { font-size: 9px; }
    .cal-key { gap: 6px 13px; font-size: 12px; margin-bottom: 12px; }
    .chip { font-size: 9.5px; padding: 2px 6px; line-height: 1.35; }

    /* ปุ่มเปลี่ยนเดือนคือทางเดียวที่แม่ค้าจะไปหาวันในเดือนหน้า — ให้เต็มแถวและกดโดนแน่ ๆ */
    .cal-nav { display: grid; grid-template-columns: 1fr auto 1fr; gap: 7px; width: 100%; }
    .cal-nav .btn { width: 100%; }

    /* โมดัลเป็น bottom sheet — หัวโมดัลค้างให้เห็นปุ่มปิดตลอด */
    dialog, dialog.dlg--wide {
        width: 100%; max-width: none; max-height: 92vh;
        margin: auto auto 0;
        border-radius: 18px 18px 0 0;
    }
    .dlg__hd { position: sticky; top: 0; z-index: 5; }
    .dlg__bd { padding: 16px; max-height: calc(92vh - 60px); padding-bottom: calc(16px + var(--safe-b)); }
    .dlg__ft { flex-direction: column; }
    .dlg__ft .btn { min-width: 100%; }

    #market-map { height: 58vh; min-height: 320px; border-radius: var(--r); }
    /* ป้ายบนแผงเล็กมากบนมือถือ — ย่อตัวหนังสือ
       บรรทัดราคามีเฉพาะผังของแอดมิน (ลูกค้าไม่ได้รับบรรทัดนี้เลย ดู map.php) ห้ามซ่อนตรงนี้
       ไม่งั้นแอดมินบนมือถือจะไม่เห็นราคาแผง */
    .lock-price { font-size: 8.5px; }
    .lock-id-txt { font-size: 11px; }
    .status-txt { font-size: 8.5px; }

    .table th, .table td { padding: 9px 11px; }
    /* ตารางข้อมูลหลายคอลัมน์ต้องกว้างพอที่จะอ่านออก แล้วให้เลื่อนแนวนอนในกล่องตัวเอง */
    .table { min-width: 520px; }
    /* ...ยกเว้นตารางสรุปเงิน ซึ่งมีแค่ 2 คอลัมน์ — บังคับ 520px ทำให้ทั้งหน้าเลื่อนออกนอกจอ */
    .money-table { min-width: 0; }
    .money-table td, .money-table th { padding: 8px 6px; }
    .r-row { font-size: 13.5px; }
    .stat__value { font-size: 21px; }
}

/* --- อุปกรณ์ทัชสกรีน (ไม่อิงความกว้างจอ) --- */
@media (hover: none) and (pointer: coarse) {
    .btn      { min-height: 44px; padding-top: 10px; padding-bottom: 10px; }
    /* ปุ่มเล็กก็ยังต้องกดโดนด้วยนิ้ว — 36px เตี้ยเกินไปสำหรับปุ่มที่ต้องกดจริง เช่น เปลี่ยนเดือน */
    .btn--sm  { min-height: 40px; padding-top: 8px; padding-bottom: 8px; }
    .btn--quiet { min-height: 40px; }
    .tabs button { min-height: 46px; }
    .check input { transform: scale(1.15); margin-right: 3px; }
    input, select, textarea { min-height: 44px; }
    /* ช่องติ๊กต้องไม่ถูกยืดเป็น 44px (กล่องจะสูงผิดรูป) — ให้ป้ายกำกับเป็นพื้นที่กดแทน */
    input[type=checkbox], input[type=radio] { min-height: 0; }
    .check { min-height: 44px; }
    textarea { min-height: 76px; }
    input[type=color] { min-height: 40px; height: 40px; }
    .coord input { min-height: 0; }
    .day { min-height: 84px; }
    /* ไม่ต้องมีเอฟเฟกต์ hover บนจอสัมผัส */
    .day--open:hover, .day--wait:hover, .day--admin:hover,
    .stat--click:hover, .card:hover { transform: none; box-shadow: var(--sh-sm); }
}

/* ---------- Print ---------- */
@media print {
    body { background: #fff; padding: 0; }
    .no-print, .topbar, .actionbar, .lockbar, .map-fs-btn { display: none !important; }
    /* QR ต้องติดไปกับหน้าที่พิมพ์เสมอ และห้ามถูกตัดกลางหน้า */
    .qr-box { break-inside: avoid; page-break-inside: avoid; border-color: #999; }
    .qr-img img, .qr-img canvas { print-color-adjust: exact; -webkit-print-color-adjust: exact; }
    .card, .receipt { box-shadow: none; border: none; }
    dialog { position: static; max-height: none; box-shadow: none; }
    .dlg__bd { max-height: none; overflow: visible; }
    .table { min-width: 0; }
}
