/* ===========================
   CSS Variables & Reset
   =========================== */
:root {
    --bg:           #f7f7f5;
    --surface:      #ffffff;
    --surface-2:    #f0f0ed;
    --border:       #e5e5e2;
    --border-dark:  #d0d0cc;
    --text:         #1a1a18;
    --text-muted:   #6b6b67;
    --text-faint:   #a8a8a4;
    --accent:       #1a1a18;
    --accent-soft:  #f0f0ed;
    --danger:       #c0392b;
    --success:      #27ae60;
    --warning:      #e67e22;
    --nav-w:        220px;
    --topbar-h:     56px;
    --radius:       6px;
    --radius-lg:    10px;
    --shadow:       0 1px 3px rgba(0,0,0,.06), 0 1px 2px rgba(0,0,0,.04);
    --shadow-md:    0 4px 12px rgba(0,0,0,.08);
    --font-sans:    'Sarabun', sans-serif;
    --font-mono:    'Sarabun', monospace;
    --transition:   150ms ease;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { font-size: 15px; }

body {
    font-family: var(--font-sans);
    background: var(--bg);
    color: var(--text);
    line-height: 1.6;
    min-height: 100vh;
    display: flex;
}

/* ===========================
   Nav Overlay & Hamburger
   =========================== */
.nav-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.4);
    z-index: 99;
    backdrop-filter: blur(2px);
}
.nav-overlay.show { display: block; }

/* ─── Hamburger Button ─── */
.nav-hamburger {
    display: none;
    flex-direction: column;
    justify-content: center;
    gap: 5px;
    width: 40px;
    height: 40px;
    padding: 8px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    cursor: pointer;
    z-index: 201;
    flex-shrink: 0;
}
.nav-hamburger span {
    display: block;
    width: 100%;
    height: 2px;
    background: var(--text);
    border-radius: 2px;
    transition: transform 220ms ease, opacity 220ms ease;
    transform-origin: center;
}
.nav-hamburger.is-open span:nth-child(1) { transform: translateY(7px) rotate(45deg); }
.nav-hamburger.is-open span:nth-child(2) { opacity: 0; transform: scaleX(0); }
.nav-hamburger.is-open span:nth-child(3) { transform: translateY(-7px) rotate(-45deg); }

/* floating hamburger — sidebar mode (shown bottom-left on mobile) */
.nav-hamburger:not(.nav-hamburger--inline) {
    position: fixed;
    bottom: 20px;
    left: 16px;
    box-shadow: var(--shadow-md);
}
/* inline hamburger — topbar mode (inside nav bar) */
.nav-hamburger--inline { position: static; box-shadow: none; margin-left: auto; }

/* ===========================
   Navigation — Sidebar (side mode)
   =========================== */
.nav {
    width: var(--nav-w);
    min-height: 100vh;
    background: var(--surface);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    padding: 24px 0;
    position: fixed;
    top: 0;
    left: 0;
    z-index: 100;
    transition: transform 280ms cubic-bezier(.4,0,.2,1);
}

.nav-brand {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 0 20px 24px;
    border-bottom: 1px solid var(--border);
    margin-bottom: 16px;
    flex-shrink: 0;
}

.nav-logo {
    font-size: 20px;
    line-height: 1;
    color: var(--text);
}

.nav-title {
    font-size: 15px;
    font-weight: 600;
    letter-spacing: -.3px;
    color: var(--text);
}

.nav-menu {
    list-style: none;
    padding: 0 10px;
    flex: 1;
}

.nav-item:last-child {
    border-top: 1px solid var(--border);
    padding-top: 12px;
    margin-top: 16px;
}

.nav-link {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 9px 12px;
    border-radius: var(--radius);
    color: var(--text-muted);
    text-decoration: none;
    font-size: 14px;
    font-weight: 450;
    transition: background var(--transition), color var(--transition);
    letter-spacing: -.1px;
}

.nav-link:hover {
    background: var(--surface-2);
    color: var(--text);
}

.nav-item.active .nav-link {
    background: var(--accent);
    color: #fff;
}

.nav-item.active .nav-link .nav-icon {
    stroke: #fff;
}

.nav-icon {
    flex-shrink: 0;
    stroke: currentColor;
    opacity: .8;
}

/* ===========================
   Navigation — Topbar (top mode)
   =========================== */
.nav--top {
    width: 100%;
    min-height: var(--topbar-h, 56px);
    height: var(--topbar-h, 56px);
    flex-direction: row;
    align-items: center;
    padding: 0 20px;
    border-right: none;
    border-bottom: 1px solid var(--border);
    position: fixed;
    top: 0; left: 0; right: 0;
    z-index: 100;
    gap: 0;
    overflow: visible;
}

.nav--top .nav-brand {
    padding: 0;
    border-bottom: none;
    margin-bottom: 0;
    margin-right: 24px;
    border-right: 1px solid var(--border);
    padding-right: 20px;
    height: 100%;
    align-items: center;
}

.nav--top .nav-menu {
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 2px;
    flex: 1;
    padding: 0;
    overflow-x: auto;
    scrollbar-width: none;
}
.nav--top .nav-menu::-webkit-scrollbar { display: none; }

.nav--top .nav-item { flex-shrink: 0; }
.nav--top .nav-item:last-child {
    border-top: none;
    padding-top: 0;
    margin-top: 0;
    margin-left: auto;
    border-left: 1px solid var(--border);
    padding-left: 8px;
}

.nav--top .nav-link {
    padding: 7px 11px;
    font-size: 13px;
    gap: 7px;
    white-space: nowrap;
}

.nav--top .nav-user {
    border-top: none;
    margin-top: 0;
    padding: 0 0 0 16px;
    border-left: 1px solid var(--border);
    height: 100%;
    align-items: center;
}

/* ===========================
   Nav User Profile
   =========================== */
.nav-user {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 14px 20px;
    border-top: 1px solid var(--border);
    margin-top: 8px;
}
.nav-user-avatar {
    width: 32px;
    height: 32px;
    background: var(--accent);
    color: #fff;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 13px;
    font-weight: 600;
    flex-shrink: 0;
}
.nav-user-info {
    display: flex;
    flex-direction: column;
    overflow: hidden;
}
.nav-user-name {
    font-size: 13px;
    font-weight: 500;
    color: var(--text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.nav-user-role {
    font-size: 11px;
    color: var(--text-faint);
    text-transform: uppercase;
    letter-spacing: .4px;
}

/* ===========================
   Main Layout
   =========================== */
/* sidebar mode */
body:not(.nav-top) .main {
    margin-left: var(--nav-w);
    flex: 1;
    padding: 36px 40px;
    max-width: 100%;
}

/* top mode */
body.nav-top {
    flex-direction: column;
}
body.nav-top .main {
    margin-left: 0;
    margin-top: var(--topbar-h, 56px);
    flex: 1;
    padding: 32px 40px;
    max-width: 100%;
}

.main {
    flex: 1;
    padding: 36px 40px;
    max-width: 100%;
}

.page-header {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    margin-bottom: 28px;
}

.page-title {
    font-size: 22px;
    font-weight: 600;
    letter-spacing: -.5px;
    color: var(--text);
}

.page-subtitle {
    font-size: 13px;
    color: var(--text-muted);
    margin-top: 2px;
    letter-spacing: -.1px;
}

/* ===========================
   Search & Filters
   =========================== */
.toolbar {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 20px;
}

.search-wrap {
    position: relative;
    flex: 1;
    max-width: 380px;
}

.search-icon {
    position: absolute;
    left: 12px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-faint);
    pointer-events: none;
}

.search-input {
    width: 100%;
    padding: 9px 12px 9px 36px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-family: var(--font-sans);
    font-size: 14px;
    color: var(--text);
    transition: border-color var(--transition), box-shadow var(--transition);
    outline: none;
}

.search-input::placeholder { color: var(--text-faint); }

.search-input:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(26,26,24,.08);
}

.filter-select {
    padding: 9px 12px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-family: var(--font-sans);
    font-size: 13px;
    color: var(--text);
    cursor: pointer;
    outline: none;
    transition: border-color var(--transition);
}

.filter-select:focus { border-color: var(--accent); }

/* ===========================
   Stats Bar
   =========================== */
.stats-bar {
    font-size: 13px;
    color: var(--text-muted);
    margin-bottom: 12px;
    display: flex;
    align-items: center;
    gap: 6px;
}

.stats-bar strong { color: var(--text); }

.stats-legend {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    margin-left: 8px;
    font-size: 12px;
    color: var(--text-faint);
}
.stats-legend-dot {
    width: 26px;
    height: 5px;
    border-radius: 3px;
    background: #ef4444;
    flex-shrink: 0;
}
.stats-legend-dot--yellow {
    background: #00A809;
}

/* ===========================
   Table
   =========================== */
.table-wrap {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    overflow: hidden;
    box-shadow: var(--shadow);
    /* mobile scroll container จัดการโดย .table-scroll-wrap */
}

/* wrapper สำหรับ horizontal scroll บน mobile */
.table-scroll-wrap {
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: thin;
    scrollbar-color: var(--border-dark) transparent;
}
.table-scroll-wrap::-webkit-scrollbar { height: 4px; }
.table-scroll-wrap::-webkit-scrollbar-track { background: transparent; }
.table-scroll-wrap::-webkit-scrollbar-thumb { background: var(--border-dark); border-radius: 4px; }

.data-table {
    width: 100%;
    border-collapse: collapse;
}

.data-table thead tr {
    border-bottom: 1px solid var(--border);
    background: var(--surface-2);
}

.data-table th {
    padding: 11px 16px;
    text-align: left;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .6px;
    color: var(--text-muted);
    white-space: nowrap;
}

.data-table tbody tr {
    border-bottom: 1px solid var(--border);
    transition: background var(--transition);
}

.data-table tbody tr:last-child { border-bottom: none; }

.data-table tbody tr:hover { background: var(--surface-2); }

.data-table td {
    padding: 13px 16px;
    font-size: 13.5px;
    vertical-align: middle;
    color: var(--text);
}

.td-id {
    font-family: var(--font-mono);
    font-size: 12px;
    color: var(--text-muted);
    width: 60px;
}

.td-shop { font-weight: 500; max-width: 200px; }

.td-owner { color: var(--text-muted); font-size: 13px; }

.td-date { font-size: 12.5px; color: var(--text-muted); white-space: nowrap; }

/* ===========================
   Badges / Status
   =========================== */
.badge {
    display: inline-flex;
    align-items: center;
    padding: 3px 9px;
    border-radius: 20px;
    font-size: 11.5px;
    font-weight: 500;
    letter-spacing: .1px;
    white-space: nowrap;
}

.badge-active    { background: #e8f5e9; color: #2e7d32; }
.badge-inactive  { background: #fce4ec; color: #c62828; }
.badge-pending   { background: #fff8e1; color: #ef6c00; }
.badge-default   { background: var(--surface-2); color: var(--text-muted); }

/* ===========================
   Pagination
   =========================== */
.pagination {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    border-top: 1px solid var(--border);
    background: var(--surface);
    margin-top: 0;
}

.pag-info { font-size: 12.5px; color: var(--text-muted); }

.pag-btns {
    display: flex;
    gap: 4px;
}

.pag-btn {
    min-width: 32px;
    height: 32px;
    padding: 0 10px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 13px;
    font-family: var(--font-sans);
    color: var(--text-muted);
    cursor: pointer;
    transition: all var(--transition);
    text-decoration: none;
}

.pag-btn:hover:not(:disabled) {
    background: var(--surface-2);
    color: var(--text);
    border-color: var(--border-dark);
}

.pag-btn.active {
    background: var(--accent);
    border-color: var(--accent);
    color: #fff;
    font-weight: 500;
}

.pag-btn:disabled {
    opacity: .4;
    cursor: not-allowed;
}

/* ===========================
   Loading & States
   =========================== */
.loading-row td {
    padding: 48px 16px;
    text-align: center;
    color: var(--text-faint);
    font-size: 13px;
}

.spinner {
    width: 20px;
    height: 20px;
    border: 2px solid var(--border);
    border-top-color: var(--text);
    border-radius: 50%;
    animation: spin .7s linear infinite;
    display: inline-block;
    vertical-align: middle;
    margin-right: 8px;
}

@keyframes spin { to { transform: rotate(360deg); } }

.empty-state {
    text-align: center;
    padding: 60px 20px;
    color: var(--text-muted);
}

.empty-state svg { opacity: .25; margin-bottom: 12px; }
.empty-state p { font-size: 14px; }

/* ===========================
   Responsive — Mobile First
   =========================== */

/* ── Tablet (≤900px) ── */
@media (max-width: 900px) {

    /* sidebar เลื่อนออกซ้าย */
    .nav:not(.nav--top) {
        transform: translateX(-100%);
        box-shadow: none;
        z-index: 200;
    }
    .nav:not(.nav--top).nav--open {
        transform: translateX(0);
        box-shadow: 4px 0 24px rgba(0,0,0,.12);
    }

    /* floating hamburger ปรากฏ */
    .nav-hamburger:not(.nav-hamburger--inline) {
        display: flex;
    }

    /* main ไม่มี margin-left */
    .main {
        margin-left: 0 !important;
        padding: 24px 16px;
    }

    /* topbar — เปิด hamburger inline */
    .nav--top .nav-hamburger--inline {
        display: flex;
    }

    /* topbar menu พับลงมาเป็น dropdown */
    .nav--top .nav-menu {
        display: none;
        position: absolute;
        top: 100%;
        left: 0; right: 0;
        flex-direction: column;
        background: var(--surface);
        border-bottom: 1px solid var(--border);
        padding: 8px 12px 12px;
        gap: 2px;
        box-shadow: var(--shadow-md);
        z-index: 300;
        overflow-x: visible;
    }
    .nav--top.nav--open .nav-menu { display: flex; }
    .nav--top .nav-item:last-child {
        border-left: none;
        padding-left: 0;
        margin-left: 0;
        border-top: 1px solid var(--border);
        padding-top: 8px;
        margin-top: 4px;
    }
    .nav--top .nav-user { display: none; }

    /* page-header เล็กลง */
    .page-header { margin-bottom: 16px; }
    .page-title  { font-size: 18px; }
}

/* ── Mobile (≤600px) ── */
@media (max-width: 600px) {
    .main { padding: 16px 12px; }

    /* ── Table → Horizontal Scroll (ไม่ตัด column) ── */
    .table-wrap {
        border-radius: var(--radius-lg);
        overflow: hidden; /* clip border-radius */
    }
    .table-scroll-wrap {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }
    .data-table {
        min-width: 700px; /* บังคับ scroll แทนการพัง */
        width: 100%;
    }
    .data-table th,
    .data-table td {
        white-space: nowrap;
    }
    /* hint bar แสดงให้รู้ว่า scroll ได้ */
    .table-scroll-hint {
        display: flex;
        align-items: center;
        gap: 6px;
        font-size: 11px;
        color: var(--text-faint);
        padding: 6px 16px 0;
        user-select: none;
    }
    .table-scroll-hint svg { flex-shrink: 0; opacity: .5; }

    /* pagination */
    .pagination {
        flex-direction: column;
        gap: 10px;
        padding: 12px 16px;
    }
    .pag-btns { flex-wrap: wrap; justify-content: center; }

    /* toolbar/search */
    .toolbar {
        display: flex !important;
        flex-wrap: wrap;
        gap: 8px;
    }
    .toolbar > * { flex: 1 1 calc(50% - 4px); min-width: 0; }
    .toolbar .search-wrap { flex: 1 1 100%; }
    .toolbar-actions { flex: 1 1 100%; justify-content: flex-end; }
}


/* ===========================
   Clickable Row
   =========================== */
.clickable-row {
    cursor: pointer;
    transition: background var(--transition);
}

.clickable-row:hover { background: var(--surface-2); }

.row-hint {
    display: inline-block;
    margin-left: 8px;
    font-size: 11px;
    color: var(--text-faint);
    opacity: 0;
    transform: translateX(-4px);
    transition: opacity var(--transition), transform var(--transition);
}

.clickable-row:hover .row-hint {
    opacity: 1;
    transform: translateX(0);
}

/* ===========================
   Modal
   =========================== */
.modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.35);
    z-index: 200;
    opacity: 0;
    pointer-events: none;
    transition: opacity 200ms ease;
    backdrop-filter: blur(2px);
}

.modal-backdrop.show {
    opacity: 1;
    pointer-events: all;
}

.modal {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -48%) scale(.97);
    z-index: 201;
    width: 100%;
    max-width: 480px;
    background: var(--surface);
    border-radius: var(--radius-lg);
    box-shadow: 0 20px 60px rgba(0,0,0,.15), 0 4px 12px rgba(0,0,0,.08);
    opacity: 0;
    pointer-events: none;
    transition: opacity 200ms ease, transform 200ms ease;
    /* ไม่ใช้ overflow:hidden — transform บน modal ทำให้ fixed positioning ของ
       child elements (dropdown) ถูก contain และโดน clip ไปด้วย */
    overflow: visible;
}

.modal.show {
    opacity: 1;
    pointer-events: all;
    transform: translate(-50%, -50%) scale(1);
}

.modal-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 16px;
    padding: 24px 24px 20px;
    border-bottom: 1px solid var(--border);
    background: var(--surface-2);
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    overflow: hidden;
}

.modal-label {
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .6px;
    color: var(--text-faint);
    margin-bottom: 4px;
}

.modal-title {
    font-size: 18px;
    font-weight: 600;
    letter-spacing: -.4px;
    color: var(--text);
    line-height: 1.3;
}

.modal-close {
    flex-shrink: 0;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: none;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    cursor: pointer;
    color: var(--text-muted);
    transition: background var(--transition), color var(--transition);
}

.modal-close:hover {
    background: var(--surface);
    color: var(--text);
}

.modal-body {
    padding: 8px 0;
}

.modal-field {
    padding: 16px 24px;
    border-bottom: 1px solid var(--border);
}

.modal-field--last { border-bottom: none; }

.modal-field-label {
    display: block;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .5px;
    color: var(--text-faint);
    margin-bottom: 6px;
}

.modal-field-value {
    font-size: 14px;
    color: var(--text);
    line-height: 1.7;
    white-space: pre-wrap;
    word-break: break-word;
}

@media (max-width: 540px) {
    .modal {
        max-width: calc(100vw - 24px);
        max-height: 92vh;
        overflow-y: auto;
    }
    .modal-body-cols {
        grid-template-columns: 1fr;
    }
    .modal-col-left {
        border-right: none;
        border-bottom: 1px solid var(--border);
    }
    .form-textarea--full {
        height: auto;
        min-height: 100px;
        resize: vertical;
    }
    .modal-footer {
        flex-wrap: wrap;
        gap: 8px;
    }
    .btn-cancel, .btn-submit { flex: 1; justify-content: center; }
}

/* ===========================
   Modal Note Scrollbar
   =========================== */
.modal-field-value--note {
    max-height: 180px;
    overflow-y: auto;
    scrollbar-width: thin;
    scrollbar-color: var(--border-dark) transparent;
    padding-right: 4px;
}

.modal-field-value--note::-webkit-scrollbar {
    width: 5px;
}

.modal-field-value--note::-webkit-scrollbar-track {
    background: transparent;
}

.modal-field-value--note::-webkit-scrollbar-thumb {
    background: var(--border-dark);
    border-radius: 10px;
}

.modal-field-value--note::-webkit-scrollbar-thumb:hover {
    background: var(--text-faint);
}

/* ===========================
   Owner Email Sub-label
   =========================== */
.owner-email {
    display: block;
    font-size: 11px;
    color: var(--text-faint);
    margin-top: 1px;
    font-family: var(--font-mono);
}

/* ===========================
   Modal Field Header (label + copy btn)
   =========================== */
.modal-field-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 6px;
}

.modal-field-header .modal-field-label {
    margin-bottom: 0;
}

/* ===========================
   Copy Button
   =========================== */
.copy-btn {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 4px 10px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-family: var(--font-sans);
    font-size: 11.5px;
    font-weight: 500;
    color: var(--text-muted);
    cursor: pointer;
    transition: all var(--transition);
    white-space: nowrap;
}

.copy-btn:hover {
    background: var(--surface-2);
    border-color: var(--border-dark);
    color: var(--text);
}

.copy-btn.copied {
    background: #e8f5e9;
    border-color: #a5d6a7;
    color: #2e7d32;
}

.copy-btn svg {
    flex-shrink: 0;
    stroke: currentColor;
}

/* ===========================
   Toolbar Actions
   =========================== */
.toolbar-actions {
    display: flex;
    gap: 8px;
    margin-left: auto;
}

.btn-action {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 14px;
    border-radius: var(--radius);
    font-family: var(--font-sans);
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: all var(--transition);
    border: 1px solid var(--border);
    white-space: nowrap;
}

.btn-mine {
    background: var(--surface);
    color: var(--text-muted);
}
.btn-mine:hover {
    background: var(--surface-2);
    color: var(--text);
    border-color: var(--border-dark);
}
.btn-mine.active {
    background: var(--accent-soft);
    color: var(--text);
    border-color: var(--border-dark);
    font-weight: 600;
}

.btn-add {
    background: var(--accent);
    color: #fff;
    border-color: var(--accent);
}
.btn-add:hover {
    background: #333;
    border-color: #333;
}

/* ===========================
   Modal Add Form
   =========================== */
.modal-add {
    max-width: 760px;
}

.modal-body-cols {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0;
    min-height: 0;
}

.modal-col-left {
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
}

.modal-col-left .modal-field {
    flex: 0 0 auto;
}

.modal-col-right {
    display: flex;
    flex-direction: column;
}

.modal-field--note-col {
    flex: 1;
    display: flex;
    flex-direction: column;
    padding: 16px 24px;
    height: 100%;
}

.form-textarea--full {
    flex: 1;
    resize: none;
    min-height: 0;
    height: 100%;
}

.modal-field-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}

.form-input {
    width: 100%;
    padding: 9px 12px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-family: var(--font-sans);
    font-size: 13.5px;
    color: var(--text);
    transition: border-color var(--transition), box-shadow var(--transition);
    outline: none;
    margin-top: 6px;
}
.form-input::placeholder { color: var(--text-faint); }
.form-input:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(26,26,24,.07);
}
.form-select { cursor: pointer; }
.form-textarea {
    resize: vertical;
    min-height: 90px;
    line-height: 1.6;
}

.modal-footer {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 8px;
    padding: 16px 24px;
    border-top: 1px solid var(--border);
    background: var(--surface-2);
    border-radius: 0 0 var(--radius-lg) var(--radius-lg);
    overflow: hidden;
}

.btn-cancel {
    padding: 8px 16px;
    background: none;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-family: var(--font-sans);
    font-size: 13px;
    color: var(--text-muted);
    cursor: pointer;
    transition: all var(--transition);
}
.btn-cancel:hover { background: var(--surface); color: var(--text); }

.btn-submit {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 18px;
    background: var(--accent);
    border: 1px solid var(--accent);
    border-radius: var(--radius);
    font-family: var(--font-sans);
    font-size: 13px;
    font-weight: 500;
    color: #fff;
    cursor: pointer;
    transition: all var(--transition);
}
.btn-submit:hover:not(:disabled) { background: #333; border-color: #333; }
.btn-submit:disabled { opacity: .6; cursor: not-allowed; }

.form-error {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 14px;
    margin: 0 24px 4px;
    background: #fef2f2;
    border: 1px solid #fecaca;
    border-radius: var(--radius);
    font-size: 13px;
    color: #b91c1c;
}

.required { color: var(--danger); margin-left: 2px; }

/* ===========================
   Login Page
   =========================== */
.login-body {
    background: var(--bg);
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    padding: 24px;
}

.login-wrap {
    width: 100%;
    max-width: 380px;
}

.login-brand {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    margin-bottom: 28px;
}
.login-logo { font-size: 22px; }
.login-app  { font-size: 18px; font-weight: 600; letter-spacing: -.4px; }

.login-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 32px;
    box-shadow: var(--shadow-md);
}

.login-title {
    font-size: 20px;
    font-weight: 600;
    letter-spacing: -.4px;
    margin-bottom: 4px;
}
.login-sub {
    font-size: 13px;
    color: var(--text-muted);
    margin-bottom: 24px;
}

.login-error {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 12px;
    background: #fef2f2;
    border: 1px solid #fecaca;
    border-radius: var(--radius);
    font-size: 13px;
    color: #b91c1c;
    margin-bottom: 16px;
}

.form-group { margin-bottom: 16px; }
.form-label {
    display: block;
    font-size: 12.5px;
    font-weight: 500;
    color: var(--text-muted);
    margin-bottom: 6px;
    letter-spacing: -.1px;
}

.input-wrap { position: relative; }
.input-wrap .form-input { padding-right: 40px; margin-top: 0; }
.toggle-pw {
    position: absolute;
    right: 10px;
    top: 50%;
    transform: translateY(-50%);
    background: none;
    border: none;
    cursor: pointer;
    color: var(--text-faint);
    padding: 4px;
    display: flex;
    align-items: center;
    transition: color var(--transition);
}
.toggle-pw:hover { color: var(--text-muted); }

.btn-login {
    width: 100%;
    padding: 10px;
    background: var(--accent);
    border: none;
    border-radius: var(--radius);
    font-family: var(--font-sans);
    font-size: 14px;
    font-weight: 500;
    color: #fff;
    cursor: pointer;
    margin-top: 8px;
    transition: background var(--transition);
    letter-spacing: -.1px;
}
.btn-login:hover { background: #333; }

/* ===========================
   Table View Transition Animation
   =========================== */
.table-view-wrap {
    transition: opacity 200ms ease, transform 200ms ease;
}
.table-view-wrap.view-transitioning {
    opacity: 0;
    transform: translateY(6px);
    pointer-events: none;
}
.table-view-wrap.view-entering {
    animation: viewEnter 300ms ease forwards;
}
@keyframes viewEnter {
    from { opacity: 0; transform: translateY(-6px); }
    to   { opacity: 1; transform: translateY(0); }
}

/* ===========================
   Btn Mine pulse on active
   =========================== */
.btn-mine.active {
    background: var(--accent);
    color: #fff;
    border-color: var(--accent);
    animation: minePulse 400ms ease;
}
@keyframes minePulse {
    0%   { transform: scale(1); }
    40%  { transform: scale(1.06); }
    100% { transform: scale(1); }
}

/* ===========================
   Edit Button
   =========================== */
.td-action { width: 90px; text-align: right; }
.btn-edit {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 5px 10px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-family: var(--font-sans);
    font-size: 12px;
    font-weight: 500;
    color: var(--text-muted);
    cursor: pointer;
    transition: all var(--transition);
    white-space: nowrap;
}
.btn-edit:hover {
    background: var(--accent);
    border-color: var(--accent);
    color: #fff;
}

/* ===========================
   Incentive Column
   =========================== */
.td-incentive {
    font-size: 13px;
    color: var(--text-muted);
    white-space: nowrap;
}

/* ===========================
   Incentive Auto Input
   =========================== */
.incentive-hint {
    font-size: 11px;
    color: var(--success);
    margin-left: 6px;
    font-weight: 400;
}
.input-auto {
    background: #f0fdf4 !important;
    border-color: #86efac !important;
    color: #166534 !important;
    font-weight: 500;
}

/* ===========================
   Delete Button
   =========================== */
.btn-delete {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text-faint);
    cursor: pointer;
    transition: all var(--transition);
    margin-left: 4px;
    flex-shrink: 0;
}
.btn-delete:hover {
    background: #fef2f2;
    border-color: #fca5a5;
    color: var(--danger);
}

.td-action {
    white-space: nowrap;
}

/* Row delete animation */
.row-deleting {
    opacity: 0;
    transform: translateX(12px);
    transition: opacity 280ms ease, transform 280ms ease;
    pointer-events: none;
}

/* ===========================
   Confirm Modal
   =========================== */
.modal-confirm {
    max-width: 360px;
    text-align: center;
    padding: 32px 28px 24px;
}
.modal-confirm .modal-header { display: none; }

.confirm-icon {
    width: 48px;
    height: 48px;
    background: #fef2f2;
    border: 1px solid #fecaca;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto 16px;
    color: var(--danger);
}
.confirm-title {
    font-size: 16px;
    font-weight: 600;
    letter-spacing: -.3px;
    margin-bottom: 8px;
    color: var(--text);
}
.confirm-desc {
    font-size: 13.5px;
    color: var(--text-muted);
    line-height: 1.6;
    margin-bottom: 24px;
}
.confirm-actions {
    display: flex;
    gap: 8px;
    justify-content: center;
}
.btn-danger {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 18px;
    background: var(--danger);
    border: 1px solid var(--danger);
    border-radius: var(--radius);
    font-family: var(--font-sans);
    font-size: 13px;
    font-weight: 500;
    color: #fff;
    cursor: pointer;
    transition: all var(--transition);
}
.btn-danger:hover { background: #a93226; border-color: #a93226; }

/* ===========================
   Toast
   =========================== */
.toast {
    position: fixed;
    bottom: 28px;
    right: 28px;
    background: var(--text);
    color: #fff;
    font-family: var(--font-sans);
    font-size: 13.5px;
    font-weight: 450;
    padding: 10px 18px;
    border-radius: 8px;
    box-shadow: 0 4px 20px rgba(0,0,0,.15), 0 1px 4px rgba(0,0,0,.1);
    white-space: nowrap;
    z-index: 9999;
    opacity: 0;
    pointer-events: none;
    transform: translateY(10px);
    transition: opacity 220ms ease, transform 220ms ease;
}
.toast--show {
    opacity: 1;
    transform: translateY(0);
}
.toast--error {
    background: var(--danger);
}
.toast--success {
    background: #166534;
}

/* ===========================
   Checkbox Filter
   =========================== */
.checkbox-filter {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    padding: 7px 12px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    cursor: pointer;
    font-size: 13px;
    color: var(--text-muted);
    font-weight: 450;
    transition: all var(--transition);
    white-space: nowrap;
    user-select: none;
}
.checkbox-filter:hover {
    border-color: var(--border-dark);
    color: var(--text);
}
.checkbox-filter.active {
    background: #fffbeb;
    border-color: #fcd34d;
    color: #92400e;
}
.checkbox-filter input[type="checkbox"] {
    display: none;
}
.checkbox-box {
    width: 15px;
    height: 15px;
    border: 1.5px solid var(--border-dark);
    border-radius: 3px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: all var(--transition);
    flex-shrink: 0;
    background: var(--surface);
}
.checkbox-filter.active .checkbox-box {
    background: #f59e0b;
    border-color: #f59e0b;
}
.checkbox-filter.active .checkbox-box::after {
    content: '';
    display: block;
    width: 4px;
    height: 7px;
    border: 1.5px solid #fff;
    border-top: none;
    border-left: none;
    transform: rotate(45deg) translateY(-1px);
}
.checkbox-label { line-height: 1; }

/* ===========================
   Row Not Success Indicator
   =========================== */
.row-not-success td:first-child {
    border-left: 3px solid #ef4444;
    padding-left: 13px;
}

.row-incentive-month td:first-child {
    border-left: 3px solid #00A809;
    padding-left: 13px;
}

/* Checkbox ยังไม่ได้ส่งมอบ — โทนแดง */
.checkbox-filter#checkNotDelivered.active {
    background: #fef2f2;
    border-color: #fca5a5;
    color: #991b1b;
}
.checkbox-filter#checkNotDelivered.active .checkbox-box {
    background: #ef4444;
    border-color: #ef4444;
}
/* ===========================
   Nav Link Button (for chat trigger)
   =========================== */
.nav-link--btn {
    width: 100%;
    background: none;
    border: none;
    font-family: var(--font-sans);
    cursor: pointer;
    position: relative;
}
.nav-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 18px;
    height: 18px;
    padding: 0 5px;
    background: #ef4444;
    color: #fff;
    font-size: 10px;
    font-weight: 600;
    border-radius: 9px;
    margin-left: auto;
    line-height: 1;
}

/* ===========================
   Chat Modal Overlay
   =========================== */
.chat-modal-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.45);
    z-index: 300;
    backdrop-filter: blur(3px);
}
.chat-modal-overlay.show { display: block; }

/* ===========================
   Chat Modal Container
   =========================== */
.chat-modal {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%) scale(.96);
    width: min(900px, 94vw);
    height: min(620px, 88vh);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: 0 20px 60px rgba(0,0,0,.18), 0 4px 16px rgba(0,0,0,.08);
    display: flex;
    overflow: hidden;
    z-index: 301;
    opacity: 0;
    pointer-events: none;
    transition: opacity 200ms ease, transform 200ms ease;
}
.chat-modal--open {
    opacity: 1;
    pointer-events: auto;
    transform: translate(-50%, -50%) scale(1);
}

/* ===========================
   Chat Sidebar
   =========================== */
.chat-sidebar {
    width: 280px;
    flex-shrink: 0;
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    background: var(--surface);
}
.chat-sidebar-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 18px 16px 14px;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}
.chat-sidebar-title {
    font-size: 15px;
    font-weight: 600;
    letter-spacing: -.3px;
    color: var(--text);
}
.chat-close-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    background: none;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text-muted);
    cursor: pointer;
    transition: all var(--transition);
}
.chat-close-btn:hover {
    background: var(--surface-2);
    color: var(--text);
}
.chat-search-wrap {
    position: relative;
    padding: 10px 12px;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}
.chat-search-icon {
    position: absolute;
    left: 22px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-faint);
}
.chat-search-input {
    width: 100%;
    padding: 7px 10px 7px 30px;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-family: var(--font-sans);
    font-size: 13px;
    color: var(--text);
    outline: none;
    transition: border-color var(--transition);
}
.chat-search-input:focus { border-color: var(--border-dark); background: var(--surface); }
.chat-search-input::placeholder { color: var(--text-faint); }

/* ===========================
   Chat List
   =========================== */
.chat-list {
    flex: 1;
    overflow-y: auto;
    scrollbar-width: thin;
    scrollbar-color: var(--border) transparent;
}
.chat-list::-webkit-scrollbar { width: 4px; }
.chat-list::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

.chat-list-empty {
    padding: 24px 16px;
    text-align: center;
    font-size: 13px;
    color: var(--text-faint);
}

.chat-conv-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 14px;
    cursor: pointer;
    transition: background var(--transition);
    border-bottom: 1px solid var(--border);
}
.chat-conv-item:last-child { border-bottom: none; }
.chat-conv-item:hover { background: var(--surface-2); }

.chat-conv-avatar { flex-shrink: 0; }
.chat-conv-info { flex: 1; min-width: 0; }
.chat-conv-top {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 6px;
}
.chat-conv-name {
    font-size: 13.5px;
    font-weight: 500;
    color: var(--text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.chat-conv-time {
    font-size: 11px;
    color: var(--text-faint);
    white-space: nowrap;
    flex-shrink: 0;
}
.chat-conv-preview {
    font-size: 12px;
    color: var(--text-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    display: flex;
    align-items: center;
    gap: 6px;
    margin-top: 2px;
}
.chat-unread-dot {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 18px;
    height: 18px;
    padding: 0 5px;
    background: #ef4444;
    color: #fff;
    font-size: 10px;
    font-weight: 600;
    border-radius: 9px;
    margin-left: auto;
    flex-shrink: 0;
}

/* ===========================
   Chat Main Panel
   =========================== */
.chat-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    background: var(--bg);
}

.chat-empty-state {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 16px;
    color: var(--text-faint);
    font-size: 13.5px;
    text-align: center;
    line-height: 1.6;
    padding: 32px;
}

/* Chat Header */
.chat-header {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 14px 20px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}
.chat-header-name {
    font-size: 14px;
    font-weight: 600;
    color: var(--text);
    letter-spacing: -.2px;
}
.chat-header-role {
    font-size: 11px;
    color: var(--text-faint);
    text-transform: uppercase;
    letter-spacing: .4px;
}

/* Messages */
.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px 20px;
    display: flex;
    flex-direction: column;
    gap: 6px;
    scrollbar-width: thin;
    scrollbar-color: var(--border) transparent;
}
.chat-messages::-webkit-scrollbar { width: 4px; }
.chat-messages::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

.chat-bubble {
    display: flex;
    flex-direction: column;
    max-width: 68%;
    gap: 3px;
}
.chat-bubble--me {
    align-self: flex-end;
    align-items: flex-end;
}
.chat-bubble--them {
    align-self: flex-start;
    align-items: flex-start;
}
.chat-bubble-text {
    padding: 9px 14px;
    border-radius: 16px;
    font-size: 13.5px;
    line-height: 1.55;
    word-break: break-word;
}
.chat-bubble--me .chat-bubble-text {
    background: var(--accent);
    color: #fff;
    border-bottom-right-radius: 4px;
}
.chat-bubble--them .chat-bubble-text {
    background: var(--surface);
    color: var(--text);
    border: 1px solid var(--border);
    border-bottom-left-radius: 4px;
}
.chat-bubble-time {
    font-size: 10.5px;
    color: var(--text-faint);
    padding: 0 4px;
}

/* Input */
.chat-input-wrap {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    padding: 12px 16px;
    background: var(--surface);
    border-top: 1px solid var(--border);
    flex-shrink: 0;
}
.chat-textarea {
    flex: 1;
    padding: 9px 14px;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: 20px;
    font-family: var(--font-sans);
    font-size: 13.5px;
    color: var(--text);
    resize: none;
    outline: none;
    line-height: 1.5;
    transition: border-color var(--transition);
    max-height: 120px;
    overflow-y: auto;
    scrollbar-width: none;
}
.chat-textarea:focus { border-color: var(--border-dark); background: var(--surface); }
.chat-textarea::placeholder { color: var(--text-faint); }
.chat-textarea::-webkit-scrollbar { display: none; }

.chat-send-btn {
    width: 38px;
    height: 38px;
    background: var(--accent);
    border: none;
    border-radius: 50%;
    color: #fff;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: background var(--transition), transform var(--transition);
}
.chat-send-btn:hover { background: #333; transform: scale(1.05); }
.chat-send-btn:active { transform: scale(.95); }

/* ===========================
   Chat — Mobile Responsive
   =========================== */
@media (max-width: 640px) {
    .chat-modal {
        width: 100vw;
        height: 100dvh;
        top: 0; left: 0;
        transform: translateY(100%);
        border-radius: 0;
    }
    .chat-modal--open {
        transform: translateY(0);
    }
    .chat-sidebar {
        width: 100%;
        position: absolute;
        inset: 0;
        z-index: 2;
        background: var(--surface);
        transition: transform 250ms ease;
    }
    .chat-modal--chat-open .chat-sidebar {
        transform: translateX(-100%);
    }
    .chat-main {
        position: absolute;
        inset: 0;
        z-index: 1;
    }
    /* Back button on mobile */
    .chat-header::before {
        content: '';
        display: none;
    }
}

/* ===========================
   Chat — Tool Buttons (emoji / attach)
   =========================== */
.chat-tool-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 34px;
    height: 34px;
    flex-shrink: 0;
    background: none;
    border: 1px solid transparent;
    border-radius: var(--radius);
    color: var(--text-faint);
    cursor: pointer;
    transition: all var(--transition);
}
.chat-tool-btn:hover,
.chat-tool-btn.active {
    background: var(--surface-2);
    border-color: var(--border);
    color: var(--text);
}

/* ===========================
   Chat — Emoji Picker
   =========================== */
.chat-emoji-picker {
    position: absolute;
    bottom: calc(100% + 6px);
    left: 12px;
    width: 320px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-md);
    z-index: 10;
    flex-direction: column;
    overflow: hidden;
}
.chat-emoji-tabs {
    display: flex;
    gap: 2px;
    padding: 8px 10px 4px;
    border-bottom: 1px solid var(--border);
}
.chat-emoji-tab {
    flex: 1;
    padding: 5px;
    font-size: 18px;
    background: none;
    border: 1px solid transparent;
    border-radius: var(--radius);
    cursor: pointer;
    transition: all var(--transition);
    line-height: 1;
}
.chat-emoji-tab:hover { background: var(--surface-2); }
.chat-emoji-tab.active {
    background: var(--accent-soft);
    border-color: var(--border-dark);
}
.chat-emoji-grid {
    display: grid;
    grid-template-columns: repeat(8, 1fr);
    gap: 2px;
    padding: 8px;
    max-height: 200px;
    overflow-y: auto;
    scrollbar-width: thin;
    scrollbar-color: var(--border) transparent;
}
.chat-emoji-grid::-webkit-scrollbar { width: 4px; }
.chat-emoji-grid::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }
.chat-emoji-btn {
    font-size: 20px;
    padding: 4px;
    background: none;
    border: none;
    border-radius: var(--radius);
    cursor: pointer;
    line-height: 1;
    transition: background var(--transition);
    text-align: center;
}
.chat-emoji-btn:hover { background: var(--surface-2); }

/* ===========================
   Chat — File Preview Bar
   =========================== */
.chat-file-preview {
    align-items: center;
    gap: 10px;
    padding: 10px 14px;
    background: var(--surface-2);
    border-top: 1px solid var(--border);
    flex-shrink: 0;
}
.chat-file-preview-inner {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
}
.chat-file-preview-icon {
    flex-shrink: 0;
    font-size: 28px;
    line-height: 1;
}
.chat-file-preview-info {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 2px;
}
.chat-file-preview-name {
    font-size: 13px;
    font-weight: 500;
    color: var(--text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.chat-file-preview-size {
    font-size: 11px;
    color: var(--text-faint);
}
.chat-file-preview-remove {
    flex-shrink: 0;
    width: 24px;
    height: 24px;
    background: none;
    border: 1px solid var(--border);
    border-radius: 50%;
    color: var(--text-faint);
    cursor: pointer;
    font-size: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all var(--transition);
}
.chat-file-preview-remove:hover {
    background: #fef2f2;
    border-color: #fca5a5;
    color: var(--danger);
}

/* ===========================
   Chat — Image in bubble
   =========================== */
.chat-img-preview {
    max-width: 220px;
    max-height: 200px;
    border-radius: 10px;
    display: block;
    object-fit: cover;
    cursor: pointer;
    transition: opacity var(--transition);
}
.chat-img-preview:hover { opacity: .88; }

/* ===========================
   Chat — File bubble
   =========================== */
.chat-file-bubble {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 14px;
    border-radius: 14px;
    text-decoration: none;
    min-width: 180px;
    max-width: 260px;
    transition: opacity var(--transition);
}
.chat-bubble--me .chat-file-bubble {
    background: var(--accent);
    color: #fff;
    border-bottom-right-radius: 4px;
}
.chat-bubble--them .chat-file-bubble {
    background: var(--surface);
    color: var(--text);
    border: 1px solid var(--border);
    border-bottom-left-radius: 4px;
}
.chat-file-bubble:hover { opacity: .85; }
.chat-file-bubble-icon { font-size: 24px; flex-shrink: 0; line-height: 1; }
.chat-file-bubble-info {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 2px;
}
.chat-file-bubble-name {
    font-size: 13px;
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.chat-bubble--me .chat-file-bubble-name { color: #fff; }
.chat-bubble--them .chat-file-bubble-name { color: var(--text); }
.chat-file-bubble-size {
    font-size: 11px;
    opacity: .7;
}
.chat-file-bubble-dl {
    font-size: 14px;
    flex-shrink: 0;
    opacity: .7;
}

/* ===========================
   Chat — Upload spinner
   =========================== */
.upload-spinner {
    display: inline-block;
    width: 12px;
    height: 12px;
    border: 2px solid rgba(255,255,255,.4);
    border-top-color: #fff;
    border-radius: 50%;
    animation: chatSpin .7s linear infinite;
    vertical-align: middle;
    margin-right: 4px;
}
@keyframes chatSpin { to { transform: rotate(360deg); } }

/* ── emoji picker ต้อง relative ต่อ chat-main ── */
.chat-main { position: relative; }

/* ===========================
   Chat — Lightbox
   =========================== */
.chat-lightbox {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.92);
    z-index: 9999;
    align-items: center;
    justify-content: center;
    cursor: zoom-out;
}
.chat-lightbox--open { display: flex; }
.chat-lightbox-img {
    max-width: 92vw;
    max-height: 90vh;
    object-fit: contain;
    border-radius: var(--radius);
    box-shadow: 0 8px 40px rgba(0,0,0,.6);
    cursor: default;
    animation: lbIn 180ms ease;
}
@keyframes lbIn {
    from { opacity:0; transform:scale(.94); }
    to   { opacity:1; transform:scale(1); }
}
.chat-lightbox-close {
    position: absolute;
    top: 18px;
    right: 20px;
    background: rgba(255,255,255,.12);
    border: 1px solid rgba(255,255,255,.2);
    color: #fff;
    font-size: 18px;
    width: 38px;
    height: 38px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background var(--transition);
    z-index: 1;
}
.chat-lightbox-close:hover { background: rgba(255,255,255,.22); }

/* ===========================
   Chat — Image bubble cursor
   =========================== */
.chat-img-preview { cursor: zoom-in; }

/* ===========================
   Chat — Header delete button
   =========================== */
.chat-header-delete-btn {
    color: var(--text-faint);
    margin-left: auto;
}
.chat-header-delete-btn:hover {
    background: #fef2f2 !important;
    border-color: #fca5a5 !important;
    color: var(--danger) !important;
}

/* ===========================
   Chat — Emoji picker position fix
   =========================== */
.chat-input-wrap { position: relative; }
.chat-emoji-picker {
    position: absolute;
    bottom: calc(100% + 6px);
    left: 0;
    width: 320px;
}