/* Drive — หน้าตาเรียบแบบ frappe/drive: พื้นเทาอ่อน การ์ดขาว ขอบบาง มุมมน */
:root {
    --bg: #f4f5f6;
    --panel: #fff;
    --line: #e3e5e8;
    --line-strong: #6b7280; /* ขอบเข้มของกรอบรูป — ปรับเฉดที่นี่ที่เดียว */
    --text: #1a1c1f;
    --muted: #6b7280;
    --accent: #2c7be5;
    --danger: #d64545;
    --radius: 10px;
    --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
}

* { box-sizing: border-box; }

/* ต้องมาก่อนทุก rule ที่ตั้ง display
   .modal/.drop/.bar ตั้ง display:flex ไว้ ซึ่ง specificity เท่ากับ [hidden]{display:none}
   ของเบราว์เซอร์แต่ประกาศทีหลัง จึงชนะ -> el.hidden = true ไม่มีผล แผงพรีวิวเลยค้างคลุมทั้งหน้า
   (เจอตอนเจ้าของลองใช้จริง 2026-09-18) */
[hidden] { display: none !important; }

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font: 14px/1.5 "Noto Sans Thai", "Sarabun", -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
    display: grid;
    grid-template-columns: 236px 1fr;
    min-height: 100vh;
}

a { color: inherit; text-decoration: none; }
small { display: block; font-size: 11px; color: var(--muted); font-weight: 400; }

/* ---------- แถบข้าง ---------- */
.side {
    background: var(--panel);
    border-right: 1px solid var(--line);
    padding: 16px 12px calc(16px + env(safe-area-inset-bottom, 0px));
    display: flex;
    flex-direction: column;
    gap: 4px;
    position: sticky;
    top: 0;
    height: 100vh;
}

.brand {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 17px;
    font-weight: 700;
    padding: 4px 8px 14px;
}

.brand .dot {
    width: 16px;
    height: 16px;
    border-radius: 5px;
    background: linear-gradient(135deg, var(--accent), #6aa9f4);
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 10px;
    border-radius: 8px;
    color: #374151;
    font-weight: 500;
}

.nav-item:hover { background: #f1f3f5; }
.nav-item.on { background: #eaf2fd; color: var(--accent); }
.nav-item .ic { width: 18px; height: 18px; flex: none; }

.logout {
    margin-top: auto;
    border-top: 1px solid var(--line);
    padding-top: 12px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.logout .who { flex: 1; color: var(--muted); font-size: 13px; }
.logout button {
    border: 1px solid var(--line);
    background: #fff;
    border-radius: 7px;
    padding: 5px 10px;
    cursor: pointer;
    font: inherit;
    font-size: 12px;
}

/* ---------- ส่วนเนื้อหา ---------- */
.main {
    padding: 16px 20px calc(40px + env(safe-area-inset-bottom, 0px));
    min-width: 0;
}

.top {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
    margin-bottom: 14px;
}

.crumbs {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 15px;
    font-weight: 600;
    min-width: 0;
    flex-wrap: wrap;
}

.crumbs a:hover { color: var(--accent); }
.crumbs .sep { color: #c2c7ce; font-weight: 400; }

.search { margin-left: auto; }
.search input {
    width: 240px;
    max-width: 46vw;
    padding: 7px 12px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fff;
    font: inherit;
}
.search input:focus { outline: 2px solid #cfe1fb; border-color: var(--accent); }

.tools { display: flex; gap: 8px; }

.btn {
    border: 1px solid var(--line);
    background: #fff;
    color: var(--text);
    border-radius: 8px;
    padding: 7px 12px;
    font: inherit;
    cursor: pointer;
    white-space: nowrap;
}
.btn:hover { background: #f7f8f9; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { filter: brightness(1.05); }
.btn.danger { color: var(--danger); border-color: #f0c9c9; }
.btn.ghost { border-color: transparent; background: transparent; color: var(--muted); }
.btn.icon-only { padding: 7px 9px; }
.btn .ic { width: 16px; height: 16px; display: block; fill: currentColor; }

.bar {
    display: flex;
    align-items: center;
    gap: 8px;
    background: #eaf2fd;
    border: 1px solid #cfe1fb;
    border-radius: var(--radius);
    padding: 8px 12px;
    margin-bottom: 12px;
}
.bar #selcount, .bar #clipinfo { font-weight: 600; margin-right: auto; }

/* แถบคลิปบอร์ด — คนละสีกับแถบเลือกไฟล์ จะได้ไม่สับสนว่ากำลังอยู่สถานะไหน */
.bar.clip { background: #fff6e5; border-color: #f2ddb4; }

.hint { color: var(--muted); margin: 0 0 12px; }
.hint a { color: var(--accent); }
.empty { color: var(--muted); padding: 48px 8px; text-align: center; }

/* ---------- ตาราง/รายการไฟล์ ---------- */
.items {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(168px, 1fr));
    gap: 14px;
}

/* เจ้าของสั่ง 2026-09-18: ตัวการ์ดไม่มีกรอบ/เงา/พื้นหลังของตัวเอง
   ขอบที่เห็นบนหน้าจอมีที่เดียวคือกรอบรูป ส่วนคำบรรยายใต้รูปเป็นข้อความเปล่าๆ */
.card {
    position: relative;
    background: transparent;
    border: 0;
    box-shadow: none;
    /* กดค้างบนมือถือต้องได้เมนู ไม่ใช่แถบเลือกข้อความของเบราว์เซอร์ */
    user-select: none;
    -webkit-user-select: none;
    -webkit-touch-callout: none;
}

/* ตัดไว้รอย้าย — จางลงให้รู้ว่าของชิ้นนี้กำลังรอวางที่อื่น */
.card.cut { opacity: .45; }

.thumb {
    display: flex;
    align-items: center;
    justify-content: center;
    aspect-ratio: 4 / 3;
    background: #fff;
    /* มุมบนโค้ง มุมล่างเหลี่ยม — ด้านล่างเป็นเส้นตรงรับกับคำบรรยายที่วางต่อลงมา */
    border: 1px solid var(--line-strong);
    border-radius: var(--radius) var(--radius) 0 0;
    overflow: hidden;
    transition: border-color .12s, box-shadow .12s;
}
.card:hover .thumb { border-color: #374151; }
.card.sel .thumb { border-color: var(--accent); box-shadow: 0 0 0 2px #cfe1fb; }
/* object-position: top — เอกสารที่สแกนมาเป็นแนวตั้ง ถ้า crop ตรงกลางจะเห็นแต่พื้นขาว
   ชิดบนแล้วเห็นหัวกระดาษ/ชื่อเรื่อง ซึ่งเป็นส่วนที่ใช้แยกว่าเอกสารไหนเป็นไหน */
.thumb img { width: 100%; height: 100%; object-fit: cover; object-position: top; display: block; }

/* ส่องดูรูป: เอาเมาส์ไปวางแล้วขยาย 4 เท่าโดยยังอยู่ในกรอบเดิม
   ใช้ transform ล้วนๆ ซึ่งไม่เข้าไปยุ่งกับ layout เลย (การ์ดใบอื่นไม่ขยับ) ส่วนที่เกินกรอบ
   ถูกตัดทิ้งด้วย overflow:hidden ของ .thumb · จุดที่ขยายวิ่งตามเมาส์ผ่าน --zx/--zy (ดู app.js)
   เพราะที่ 4 เท่าจะเห็นแค่ 1/16 ของรูป ถ้าตรึงไว้กลางภาพก็ส่องได้แค่จุดเดียว
   @media (hover: hover) — บนมือถือ :hover จะค้างหลังแตะ ทำให้รูปค้างขยายจนกว่าจะแตะที่อื่น */
@media (hover: hover) {
    .items:not(.list) .thumb img {
        transition: transform .18s ease;
        transform-origin: var(--zx, 50%) var(--zy, 50%);
    }
    .items:not(.list) .card:hover .thumb img { transform: scale(4); }
}

.ic { width: 46px; height: 46px; fill: #9aa4b2; stroke: #9aa4b2; }
.ic-folder { fill: #f0b429; stroke: none; }
.ic-image { fill: #4b9e5f; stroke: #4b9e5f; }
.ic-pdf { fill: #d64545; stroke: #d64545; }
.ic-video { fill: #7a5af5; stroke: #7a5af5; }
.ic-sheet { fill: #2f9e6e; stroke: #2f9e6e; }
.ic-doc { fill: #2c7be5; stroke: #2c7be5; }

/* ชิดขอบซ้ายของกรอบรูป ไม่มีกล่อง ไม่มีเส้น */
.meta { padding: 8px 2px 10px; }
.name {
    font-weight: 500;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.sub { color: var(--muted); font-size: 12px; margin-top: 2px; }

.pick {
    position: absolute;
    top: 8px;
    left: 8px;
    width: 20px;
    height: 20px;
    border-radius: 6px;
    border: 1.5px solid #c2c7ce;
    background: rgba(255, 255, 255, .92);
    cursor: pointer;
    opacity: 0;
    transition: opacity .12s;
}
.card:hover .pick, .card.sel .pick { opacity: 1; }
.card.sel .pick { background: var(--accent); border-color: var(--accent); }
.card.sel .pick::after {
    content: "";
    position: absolute;
    left: 6px; top: 2px;
    width: 5px; height: 10px;
    border: solid #fff;
    border-width: 0 2px 2px 0;
    transform: rotate(45deg);
}

/* มุมมองรายการ */
.items.list { display: block; }
.items.list .card {
    display: grid;
    grid-template-columns: 44px 1fr;
    align-items: center;
    gap: 10px;
    border-radius: 8px;
    margin-bottom: 6px;
    box-shadow: none;
}
/* มุมมองรายการ: คำบรรยายอยู่ข้างๆ ไม่ใช่ข้างล่าง กรอบรูปจึงโค้งเท่ากันทั้ง 4 มุม
   (กติกา "มุมล่างเหลี่ยม" มีไว้ให้รูปต่อกับคำบรรยายที่อยู่ใต้รูป ซึ่งมุมมองนี้ไม่มี) */
.items.list .thumb { aspect-ratio: auto; height: 40px; width: 40px; border-radius: 6px; margin-left: 6px; }
.items.list .ic { width: 24px; height: 24px; }
.items.list .meta { padding: 8px 10px 8px 0; display: flex; gap: 12px; align-items: baseline; }
.items.list .name { flex: 1; min-width: 0; }
.items.list .sub { margin: 0; white-space: nowrap; }
.items.list .pick { position: static; opacity: 1; margin-left: 8px; }

/* ---------- เมนูคลิกขวา / กดค้าง ---------- */
.ctx {
    position: fixed;
    z-index: 70;
    min-width: 210px;
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 10px;
    box-shadow: 0 10px 28px rgba(16, 24, 40, .18);
    padding: 6px;
}
.ctx button {
    display: block;
    width: 100%;
    text-align: left;
    border: 0;
    background: none;
    padding: 9px 12px;
    border-radius: 7px;
    font: inherit;
    color: var(--text);
    cursor: pointer;
    white-space: nowrap;
}
.ctx button:hover { background: #f1f3f5; }
.ctx button.danger { color: var(--danger); }
.ctx hr { border: 0; border-top: 1px solid var(--line); margin: 5px 4px; }

/* ---------- ลากไฟล์มาวาง ---------- */
.drop {
    position: fixed;
    inset: 0;
    background: rgba(44, 123, 229, .08);
    border: 3px dashed var(--accent);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    font-weight: 600;
    color: var(--accent);
    z-index: 40;
    pointer-events: none;
}

/* ---------- พรีวิว ---------- */
.modal {
    position: fixed;
    inset: 0;
    background: rgba(16, 20, 28, .82);
    z-index: 50;
    display: flex;
    flex-direction: column;
}
.modal-top {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: calc(10px + env(safe-area-inset-top, 0px)) 14px 10px;
    color: #fff;
}
.modal-top span { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.modal-top .btn { background: rgba(255, 255, 255, .14); border-color: transparent; color: #fff; }
.modal-body {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 14px calc(14px + env(safe-area-inset-bottom, 0px));
    min-height: 0;
}
.modal-body img, .modal-body video { max-width: 100%; max-height: 100%; border-radius: 6px; }
.modal-body iframe { width: 100%; height: 100%; border: 0; background: #fff; border-radius: 6px; }
.modal-body pre {
    background: #fff;
    width: 100%;
    height: 100%;
    margin: 0;
    padding: 16px;
    overflow: auto;
    border-radius: 6px;
    white-space: pre-wrap;
    word-break: break-word;
}

/* ---------- toast ---------- */
.toast {
    position: fixed;
    left: 50%;
    bottom: calc(24px + env(safe-area-inset-bottom, 0px));
    transform: translateX(-50%);
    background: #1a1c1f;
    color: #fff;
    padding: 10px 16px;
    border-radius: 8px;
    z-index: 60;
    max-width: 90vw;
}

/* ---------- หน้า login ---------- */
.login-page { display: flex; align-items: center; justify-content: center; padding: 24px; }
.login-box {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 14px;
    box-shadow: var(--shadow);
    padding: 28px;
    width: 100%;
    max-width: 340px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}
.login-box .brand { padding: 0; }
.login-box .sub { color: var(--muted); margin: -8px 0 6px; }
.login-box label { display: grid; gap: 5px; font-size: 13px; color: #374151; }
.login-box input {
    padding: 9px 11px;
    border: 1px solid var(--line);
    border-radius: 8px;
    font: inherit;
}
.login-box input:focus { outline: 2px solid #cfe1fb; border-color: var(--accent); }
.login-box .btn { margin-top: 6px; padding: 10px; }
.error {
    background: #fdecec;
    border: 1px solid #f5c6c6;
    color: #a33a3a;
    border-radius: 8px;
    padding: 8px 10px;
    margin: 0;
    font-size: 13px;
}

/* ---------- จอเล็ก ---------- */
@media (max-width: 820px) {
    body { grid-template-columns: 1fr; }
    .side {
        position: static;
        height: auto;
        flex-direction: row;
        align-items: center;
        overflow-x: auto;
        border-right: 0;
        border-bottom: 1px solid var(--line);
        padding: 10px 12px;
    }
    .brand { padding: 0 10px 0 0; }
    .side nav { display: flex; gap: 4px; }
    .nav-item { padding: 6px 10px; white-space: nowrap; }
    .nav-item small { display: none; }
    .logout { margin-top: 0; border: 0; padding: 0 0 0 8px; }
    .logout .who { display: none; }
    .main { padding: 12px 14px 40px; }
    .search { order: 3; margin-left: 0; width: 100%; }
    .search input { width: 100%; max-width: none; }
    .items { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 10px; }
}
