:root{
  --bg:#f6f3fb;
  --surface:#ffffff;
  --surface-2:#f8f7fc;
  --text:#1f1a2f;
  --muted:#6e6785;
  --primary:#6f42c1;
  --primary-2:#5b34a4;
  --primary-soft:#efe8ff;
  --line:#e6def4;
  --success:#1f9d63;
  --danger:#d64545;
  --warning:#ee9b00;
  --blue:#3c78d8;
  --shadow:0 18px 40px rgba(87, 65, 143, 0.10);
  --radius-lg:24px;
  --radius-md:18px;
  --radius-sm:14px;
}

*{box-sizing:border-box}
html{scroll-behavior:smooth}
body{
  margin:0;
  font-family:"IBM Plex Sans Thai",system-ui,-apple-system,BlinkMacSystemFont,"Segoe UI",sans-serif;
  background:
    radial-gradient(circle at top right, rgba(111,66,193,.12), transparent 22%),
    radial-gradient(circle at left center, rgba(60,120,216,.08), transparent 18%),
    var(--bg);
  color:var(--text);
}
button,input,select,textarea{font:inherit}
button{cursor:pointer}
.hidden{display:none!important}

.app-shell{
  min-height:100vh;
  display:flex;
  flex-direction:column;
}

.topbar{
  position:sticky;
  top:0;
  z-index:20;
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:16px;
  min-height:64px;
  padding:0 20px;
  background:rgba(246,243,251,.88);
  backdrop-filter:blur(14px);
  border-bottom:1px solid rgba(230,222,244,.8);
  box-shadow:0 8px 24px rgba(87,65,143,.08);
}

.brand{display:flex;align-items:center;gap:10px}
.brand-logo-link{
  display:inline-flex;
  align-items:center;
  justify-content:center;
  text-decoration:none;
}
.brand-badge{
  width:32px;height:32px;border-radius:0;
  display:grid;place-items:center;
  background:transparent;
  box-shadow:none;
}
.brand-text h1{margin:0;font-size:1.05rem;line-height:1.2}

.topbar-actions{
  display:flex;
  align-items:center;
  justify-content:flex-end;
  gap:10px;
}

.topbar-user{
  display:flex;align-items:center;gap:12px;
  padding:10px 12px;background:#fff;border:1px solid var(--line);
  border-radius:999px;box-shadow:var(--shadow);
}
#topbarUserName{font-size:.85rem;white-space:nowrap;overflow:hidden;text-overflow:ellipsis;max-width:240px}
.role-badge{flex-shrink:0;border-radius:20px;padding:3px 10px;font-size:0.75rem;font-weight:700;letter-spacing:.04em}
.role-badge.admin{background:#fff7e6;color:#8a6300}
.role-badge.staff{background:#edf8f2;color:#15734f}
.role-badge.user{background:var(--primary-soft);color:var(--primary)}
.btn-home{display:inline-flex;align-items:center;justify-content:center;background:#fff;border:1px solid var(--line);border-radius:14px;color:var(--text);cursor:pointer;padding:8px 12px;font-size:.95rem;line-height:1;text-decoration:none;transition:background .2s,transform .12s;flex-shrink:0;box-shadow:var(--shadow);white-space:nowrap}
.btn-home:hover{background:var(--surface-2);transform:translateY(-1px)}
.btn-logout{background:var(--surface);border:1px solid var(--line);border-radius:14px;color:var(--text);cursor:pointer;padding:8px 12px;font-size:.95rem;transition:background .2s,transform .12s;flex-shrink:0;box-shadow:var(--shadow)}
.btn-logout:hover{background:var(--surface-2);transform:translateY(-1px)}

.page{
  width:min(1280px,100%);
  margin:0 auto;
  padding:24px 16px 40px;
}

.view{display:none}
.view.active{display:block}

.hero{
  display:grid;
  grid-template-columns:1.4fr .8fr;
  gap:22px;
  align-items:start;
}
.hero-left,.hero-right,.panel,.auth-card,.service-card,.welcome-card,.feature-card,.step-card{
  background:var(--surface);
  border:1px solid var(--line);
  border-radius:var(--radius-lg);
  box-shadow:var(--shadow);
}
.hero-left{padding:28px}
.hero-right{padding:0}
.hero-left h2{font-size:2.2rem;line-height:1.15;margin:14px 0 10px}
.hero-copy{font-size:1.05rem;color:var(--muted);max-width:720px}
.hero-actions{display:flex;gap:12px;flex-wrap:wrap;margin-top:22px}
.hero-grid{
  display:grid;grid-template-columns:repeat(3,1fr);gap:14px;margin-top:24px;
}
.feature-card{padding:18px}
.feature-icon,.service-icon{
  width:54px;height:54px;border-radius:18px;display:grid;place-items:center;
  background:var(--primary-soft);font-size:1.6rem;margin-bottom:10px;
}
.feature-card h3,.service-card h3{margin:0 0 8px;font-size:1.05rem}
.feature-card p,.service-card p{margin:0;color:var(--muted);line-height:1.55}

.panel{padding:20px}
.panel-highlight{height:100%}
.panel-gradient{
  background:linear-gradient(145deg,#6f42c1,#4f2f90);
  color:#fff;border:none;
}
.panel-gradient p,.panel-gradient code{color:rgba(255,255,255,.9)}
.panel-gradient code{
  background:rgba(255,255,255,.14);
  padding:2px 8px;border-radius:10px;
}
.login-logo-box img {
  width: 104px;
  height: 104px;
  object-fit: contain;
  border-radius: 16px; /* ทำให้นุ่มขึ้น */
}



.auth-notes{margin-top:18px;display:grid;gap:10px}
.note-row{
  display:flex;gap:10px;align-items:flex-start;
  background:rgba(255,255,255,.10);border:1px solid rgba(255,255,255,.14);
  padding:12px 14px;border-radius:14px;
}

.guide-section{margin-top:22px}
.section-head{margin-bottom:16px}
.section-head h3,.view-head h2,.auth-head h3{margin:0 0 6px}
.section-head p,.view-head p,.auth-head p{margin:0;color:var(--muted)}
.steps{display:grid;grid-template-columns:repeat(4,1fr);gap:14px}
.step-card{padding:18px}
.step-no{
  width:36px;height:36px;border-radius:12px;display:grid;place-items:center;
  background:var(--primary-soft);color:var(--primary);font-weight:700;margin-bottom:12px;
}

.auth-layout{
  max-width: 480px;
  margin: 40px auto;   /* มีระยะบนล่างนิดนึง */
  padding: 16px;
}
/*{
  display:grid;
  grid-template-columns:.9fr 1.1fr;
  gap:22px;
  align-items:start;
}*/


.auth-side{position:sticky;top:96px}
.auth-card{padding:24px}
.auth-head{margin-bottom:18px}

.form-block{display:grid;gap:14px}
.form-block + .form-block{margin-top:18px;padding-top:18px;border-top:1px dashed var(--line)}
.section-mini-title{font-weight:700}
.field{display:grid;gap:8px}
.field span{font-size:.92rem;font-weight:600}
.field input,.field select,.field textarea{
  width:100%;
  border:1px solid var(--line);
  background:#fff;
  min-height:48px;
  border-radius:16px;
  padding:12px 14px;
  outline:none;
  transition:.2s border-color,.2s box-shadow,.2s transform;
}
.field textarea{min-height:110px;resize:vertical}
.field-help{color:var(--muted);font-size:.88rem}
.field input:focus,.field select:focus,.field textarea:focus{
  border-color:rgba(111,66,193,.7);
  box-shadow:0 0 0 4px rgba(111,66,193,.12);
}
.field-grid{
  display:grid;grid-template-columns:repeat(2,1fr);gap:14px;
}
/*เพิ่ม*/
.request-panel .field-grid{
  grid-template-columns:1fr;
}
/**/



.field-empty{visibility:hidden}
.inline-field{align-items:end}
.grow{flex:1}
.checkbox-field{align-content:end}
.checkbox-wrap{
  min-height:48px;display:flex;align-items:center;gap:10px;
  border:1px solid var(--line);border-radius:16px;padding:0 14px;background:#fff;
}
.password-wrap{position:relative}
.password-wrap input{padding-right:48px}
.btn-icon{
  position:absolute;top:50%;right:8px;transform:translateY(-50%);
  width:36px;height:36px;border:none;border-radius:12px;background:transparent;
}

.btn{
  border:none;
  min-height:48px;
  padding:0 18px;
  border-radius:16px;
  font-weight:600;
  transition:.18s transform,.18s box-shadow,.18s opacity,.18s background;
}
.btn:hover{transform:translateY(-1px)}
.btn:active{transform:translateY(1px) scale(.99)}
.btn:disabled{opacity:.55;cursor:not-allowed;transform:none}
.btn-primary{
  color:#fff;background:linear-gradient(135deg,var(--primary),#8756e8);
  box-shadow:0 12px 24px rgba(111,66,193,.22);
}
.btn-primary:hover{background:linear-gradient(135deg,var(--primary-2),#7d4ce2)}
.btn-soft{background:var(--primary-soft);color:var(--primary)}
.btn-outline{background:#fff;border:1px solid var(--line);color:var(--text)}
.btn-ghost{background:transparent;color:var(--muted)}
.btn-sm{min-height:40px;padding:0 14px;border-radius:14px}
.btn-lg{min-height:54px;padding:0 24px}
.w-full{width:100%}

.chip{
  display:inline-flex;align-items:center;gap:8px;
  min-height:34px;padding:0 12px;border-radius:999px;font-size:.9rem;font-weight:700;
}
.chip-primary{background:var(--primary-soft);color:var(--primary)}
.chip-soft{background:#f1eef9;color:#5b5470}

.status-box{
  margin-top:16px;padding:14px 16px;border-radius:16px;
  border:1px solid var(--line);background:var(--surface-2);font-size:.95rem;
}
.status-box.success{background:#edf8f2;border-color:#cceedd;color:#15734f}
.status-box.warning{background:#fff7e6;border-color:#ffe4a8;color:#8a6300}
.status-box.danger{background:#fff0f0;border-color:#ffc7c7;color:#aa3434}
.auth-footer{margin-top:18px}

.welcome-card{
  display:flex;justify-content:space-between;gap:16px;align-items:center;
  padding:24px;margin-bottom:18px;
}
.welcome-card h2{margin:8px 0 6px;font-size:1.8rem}
.welcome-card p{margin:0;color:var(--muted)}

.module-grid{
  display:grid;grid-template-columns:repeat(3,1fr);gap:16px;
}
.service-card{padding:20px}
.accent-purple{background:linear-gradient(180deg,#fff,#faf7ff)}
.accent-blue{background:linear-gradient(180deg,#fff,#f5faff)}
.accent-slate{background:linear-gradient(180deg,#fff,#fafbfc)}

.dashboard-grid{
  margin-top:18px;
  display:grid;grid-template-columns:.9fr 1.1fr;gap:16px;
}
.stats-grid{
  display:grid;grid-template-columns:repeat(2,1fr);gap:12px;
}
.stat-card{
  border:1px solid var(--line);background:var(--surface-2);
  border-radius:18px;padding:16px;
}
.stat-card .label{color:var(--muted);font-size:.92rem}
.stat-card .value{font-size:1.8rem;font-weight:700;margin-top:6px}

.view-head{
  display:flex;justify-content:space-between;align-items:flex-start;gap:16px;margin-bottom:16px;
}
.view-head-actions{display:flex;gap:10px;flex-wrap:wrap}
.toolbar{
  display:flex;gap:12px;align-items:flex-end;flex-wrap:wrap;margin-bottom:16px;
}
.content-grid{
  display:grid;grid-template-columns:1.15fr .85fr;gap:16px;align-items:start;
}
.catalog-panel{
  display:flex;
  flex-direction:column;
  min-height:0;
  max-height:calc(100vh - 180px);
  overflow:hidden;
}

/*ปิด4 เพื่อแก้การตรึ่งใบคำขอ
.request-panel{
  max-height:calc(100vh - 180px);
  overflow:auto;
}
*/
/*แก้ขนาดใบคำขอ*/
.request-panel{
  height:520px;
  max-height:520px;
  min-height:520px;
  overflow:auto;
  overscroll-behavior:contain;
  -webkit-overflow-scrolling:touch;
}


/*ก่อนแก้*//*
.asset-sheet-wrap{
  flex:1;
  min-height:0;
  overflow:auto;
  overscroll-behavior:contain;
  padding-right:4px;
}
.asset-sheet,.selection-sheet{
  border:1px solid var(--line);
  border-radius:18px;
  background:#fff;
  overflow:hidden;
}
.asset-table,.selection-table{
  width:100%;
  border-collapse:collapse;
}*/

/*ชุดแก้*/
.asset-sheet-wrap{
  flex:1;
  min-height:0;
  overflow-x:auto;
  overflow-y:auto;
  overscroll-behavior:contain;
  -webkit-overflow-scrolling:touch;
  padding-right:4px;
}

.asset-sheet,
.selection-sheet{
  border:1px solid var(--line);
  border-radius:18px;
  background:#fff;
  overflow:visible;
}

.asset-table,
.selection-table{
  width:max-content;
  min-width:100%;
  border-collapse:collapse;
}
/**/
/*ปิดอันเดิม 
.asset-table th,.asset-table td,.selection-table th,.selection-table td{
  padding:12px 14px;
  border-bottom:1px solid #eee7f7;
  text-align:left;
  vertical-align:middle;
  font-size:.94rem;
}
.asset-table thead th,.selection-table thead th{
  background:#f6f2ff;
  color:#4b3a73;
  font-size:.84rem;
  font-weight:700;
  letter-spacing:.02em;
}
.thumb-col{width:78px}
*/

/*เปิดแก้ 3*/
.asset-table th,.asset-table td,.selection-table th,.selection-table td{
  padding:12px 14px;
  border-bottom:1px solid #eee7f7;
  text-align:left;
  vertical-align:middle;
  font-size:.94rem;
}

.asset-table thead th,
.selection-table thead th{
  background:#f6f2ff;
  color:#4b3a73;
  font-size:.84rem;
  font-weight:700;
  letter-spacing:.02em;
}

/* ความกว้างคอลัมน์รูป */
.thumb-col{
  width:78px;
}

/* ตรึงหัวตาราง */
.asset-table thead th{
  position:sticky;
  top:0;
  z-index:4;
  background:#f6f2ff;
}

/* ตรึงคอลัมน์รูป */
.asset-table th:nth-child(1),
.asset-table td:nth-child(1){
  position:sticky;
  left:0;
  z-index:3;
  background:#fff;
}

/* ตรึงคอลัมน์รหัส */
.asset-table th:nth-child(2),
.asset-table td:nth-child(2){
  position:sticky;
  left:78px;
  z-index:3;
  background:#fff;
  box-shadow:2px 0 8px rgba(0,0,0,.06);
}

/* ให้หัวตาราง 2 คอลัมน์แรกอยู่ชั้นบนสุด */
.asset-table thead th:nth-child(1),
.asset-table thead th:nth-child(2){
  z-index:5;
  background:#f6f2ff;
}
/*สิ้นสุดแก้ 3*/

.catalog-thumb{
  width:48px;
  height:48px;
  border-radius:12px;
  object-fit:cover;
  border:1px solid var(--line);
  background:#fff;
  display:block;
}
.catalog-thumb-fallback{
  display:grid;
  place-items:center;
  background:linear-gradient(135deg,#f3ecff,#e9f6ff);
  color:#5b5470;
  font-size:.75rem;
  font-weight:700;
}
.asset-table tbody tr.is-selected{
  background:#faf6ff;
}
.asset-table tbody tr:hover{
  background:#fbf9ff;
}
.selection-sheet-head{
  padding:12px 14px;
  background:#f8f7fc;
  border-bottom:1px solid var(--line);
  font-weight:700;
  color:#4b3a73;
}
.inline-status{
  display:inline-flex;
  align-items:center;
  min-height:28px;
  padding:0 10px;
  border-radius:999px;
  background:#f1eef9;
  color:#5b5470;
  font-size:.84rem;
  font-weight:700;
  white-space:nowrap;
}
.qty-col,.action-col{white-space:nowrap}
.qty-input{
  width:84px;
  border:1px solid var(--line);
  background:#fff;
  min-height:40px;
  border-radius:12px;
  padding:8px 10px;
}
.qty-caption{
  margin-top:4px;
  font-size:.76rem;
  color:var(--muted);
}
.cards-grid{
  display:grid;grid-template-columns:repeat(2,1fr);gap:14px;
  max-height:calc(100vh - 260px);overflow:auto;padding-right:4px;
}
.asset-card,.supply-card,.request-card{
  border:1px solid var(--line);background:#fff;border-radius:20px;padding:16px;
}
.asset-card.is-selected{
  border-color:rgba(111,66,193,.45);
  background:linear-gradient(180deg,#fff,#f7f1ff);
  box-shadow:0 14px 32px rgba(111,66,193,.14);
}
.asset-card h4,.supply-card h4,.request-card h4{margin:0 0 8px}
.asset-meta,.supply-meta,.request-meta{
  display:grid;gap:6px;color:var(--muted);font-size:.93rem;
}
.card-actions{margin-top:14px;display:flex;gap:10px;flex-wrap:wrap}
.sticky-panel{position:sticky;top:96px}
.selected-asset-list{display:grid;gap:10px}
.selected-asset-empty{
  min-height:72px;display:grid;place-items:center;padding:14px;
  border:1px dashed var(--line);border-radius:16px;color:var(--muted);background:var(--surface-2);
}

/*เพิ่ม*/
.request-panel .selected-asset-list{
  width:100%;
  max-width:100%;
  overflow-x:auto;
  overflow-y:hidden;
  -webkit-overflow-scrolling:touch;
}

.request-panel .selection-sheet{
  width:100%;
  max-width:100%;
  overflow-x:auto;
  overflow-y:hidden;
}

.request-panel .selection-table{
  width:max-content;
  min-width:640px;
}

/**/

.badge{
  display:inline-flex;align-items:center;min-height:28px;padding:0 10px;
  border-radius:999px;font-size:.84rem;font-weight:700;
}
.badge.pending{background:#fff5e6;color:#9a6900}
.badge.approved{background:#e7f8ef;color:#15734f}
.badge.rejected{background:#fff0f0;color:#a03030}
.badge.borrowed{background:#efe8ff;color:#5f3bb2}
.badge.returned{background:#eef3f7;color:#435b70}

.stack-list{display:grid;gap:12px}
.empty-state{
  display:grid;place-items:center;min-height:180px;
  color:var(--muted);border:1px dashed var(--line);border-radius:18px;
  background:rgba(255,255,255,.55);
}
.request-top{
  display:flex;justify-content:space-between;gap:12px;align-items:flex-start;margin-bottom:10px;
}
.request-type{font-size:.88rem;color:var(--muted)}
.request-details{display:grid;gap:6px;color:var(--muted);font-size:.94rem}
.request-items-toggle{
  margin-top:12px;
  border-top:1px dashed var(--line);
  padding-top:12px;
}
.request-items-toggle summary{
  cursor:pointer;
  font-weight:700;
  color:#4b3a73;
  list-style:none;
}
.request-items-toggle summary::-webkit-details-marker{display:none}
.request-items-table-wrap{
  margin-top:10px;
  border:1px solid var(--line);
  border-radius:14px;
  overflow:auto;
}
.request-items-table{
  width:100%;
  border-collapse:collapse;
}
.request-items-table th,.request-items-table td{
  padding:10px 12px;
  border-bottom:1px solid #eee7f7;
  text-align:left;
  font-size:.9rem;
}
.request-items-table th{
  background:#f8f7fc;
  color:#4b3a73;
  font-size:.8rem;
  font-weight:700;
}

.overlay,.modal{
  position:fixed;inset:0;display:grid;place-items:center;
  background:rgba(25,18,43,.32);z-index:90;padding:16px;
}
.overlay-card,.modal-card{
  width:min(92vw,380px);background:#fff;border-radius:26px;padding:28px;
  box-shadow:0 30px 60px rgba(25,18,43,.22);text-align:center;
}
.spinner{
  width:56px;height:56px;border-radius:50%;
  border:4px solid rgba(111,66,193,.18);
  border-top-color:var(--primary);
  margin:0 auto 16px;
  animation:spin .9s linear infinite;
}
.success-icon{
  width:78px;height:78px;border-radius:24px;margin:0 auto 16px;
  display:grid;place-items:center;background:#e9f8f0;color:var(--success);
  font-size:2rem;font-weight:700;
}
.success-card h3{margin:0 0 8px}
.success-card p{margin:0 0 18px;color:var(--muted)}

.toast{
  position:fixed;left:50%;bottom:20px;transform:translateX(-50%);
  min-width:min(90vw,420px);
  background:#1f1a2f;color:#fff;padding:14px 16px;border-radius:16px;
  box-shadow:0 16px 36px rgba(18,11,33,.25);z-index:100;
}
.toast.success{background:#15734f}
.toast.error{background:#aa3434}
.toast.warning{background:#8a6300}

.plain-list{margin:14px 0 0;padding-left:18px;display:grid;gap:10px;color:var(--muted)}
@keyframes spin{to{transform:rotate(360deg)}}

/*ปิดอันเดิม*/
/*
@media (max-width: 1100px){
  .hero,.auth-layout,.content-grid,.dashboard-grid{grid-template-columns:1fr}
  .auth-side,.sticky-panel{position:static}
  .catalog-panel,.request-panel{max-height:none}
  .asset-sheet-wrap{overflow:visible;padding-right:0}
  }
*/

/*เปิดแก้2.1*/
@media (max-width: 1100px){
  .hero,.auth-layout,.content-grid,.dashboard-grid{grid-template-columns:1fr}
  .auth-side,.sticky-panel{position:static}

  .catalog-panel{
    height:520px;
    max-height:520px;
    overflow:hidden;
  }
  /*ปิด แก้4
  .request-panel{
    max-height:none;
  }
  */
  /*เปิดแก้*/
  .request-panel{
  height:520px;
  max-height:520px;
  min-height:520px;
  overflow-y:auto;
  overflow-x:hidden;
  overscroll-behavior:contain;
  -webkit-overflow-scrolling:touch;
}
/**/


  .asset-sheet-wrap{
    overflow-x:auto;
    overflow-y:auto;
    padding-right:0;
    -webkit-overflow-scrolling:touch;
  }
}


/*ปิดอันเดิม*/
/*
@media (max-width: 820px){
  .topbar{padding:14px 14px}
  .brand-text h1{font-size:1rem}
  .hero-left{padding:22px}
  .hero-left h2{font-size:1.8rem}
  .hero-grid,.module-grid,.steps,.cards-grid{grid-template-columns:1fr}
  .stats-grid,.field-grid{grid-template-columns:1fr}
  .welcome-card,.view-head{flex-direction:column;align-items:stretch}
  .page{padding:18px 12px 32px}
  .asset-table th,.asset-table td,.selection-table th,.selection-table td{padding:10px}
  .asset-table,.selection-table,.request-items-table{min-width:760px}
  }
*/
/*เปิดแก้2.2*/
@media (max-width: 820px){
  .topbar{padding:14px 14px}
  .brand-text h1{font-size:1rem}
  .hero-left{padding:22px}
  .hero-left h2{font-size:1.8rem}
  .hero-grid,.module-grid,.steps,.cards-grid{grid-template-columns:1fr}
  .stats-grid,.field-grid{grid-template-columns:1fr}
  .welcome-card,.view-head{flex-direction:column;align-items:stretch}
  .page{padding:18px 12px 32px}

  .catalog-panel{
    height:520px;
    max-height:520px;
    overflow:hidden;
  }

  .asset-sheet-wrap{
    height:100%;
    overflow-x:auto;
    overflow-y:auto;
    -webkit-overflow-scrolling:touch;
  }

  .asset-table th,.asset-table td,.selection-table th,.selection-table td{
    padding:10px;
  }

  .asset-table,.selection-table,.request-items-table{
    min-width:760px;
  }
}
@media (max-width: 560px){
  .brand-badge{width:32px;height:32px;border-radius:0}
  .topbar-user{width:100%;justify-content:space-between}
  .topbar{height:auto;padding:12px 14px;align-items:flex-start;gap:12px;flex-wrap:wrap}
  .brand{width:100%;align-items:flex-start}
  .topbar-actions{width:100%;flex-wrap:wrap}
  .btn-home{width:100%}
  #topbarUserName{max-width:none}
  .hero-actions,.view-head-actions,.card-actions{display:grid;grid-template-columns:1fr}
}
/*เพิ่ม 4 3) แก้ media 820px ถ้าในช่วง @media (max-width: 820px) ยังไม่มี .request-panel ให้ เพิ่ม อันนี้เข้าไป:*/
.request-panel{
  height:520px;
  max-height:520px;
  min-height:520px;
  overflow:auto;
}
/*แก้ขนาดคอลัมตัดบรรทัดได้ไม่เกิน 3 บรรทัด*/
.cell-name,
.cell-category{
  display:-webkit-box;
  -webkit-box-orient:vertical;
  -webkit-line-clamp:3;
  overflow:hidden;
  text-overflow:ellipsis;
  white-space:normal;
  line-height:1.45;
  max-height:4.35em; /* 3 บรรทัด */
  word-break:break-word;
}

.line-clamp-3{
  display:-webkit-box;
  -webkit-box-orient:vertical;
  -webkit-line-clamp:3;
  overflow:hidden;
  text-overflow:ellipsis;
  white-space:normal;
  line-height:1.45;
  max-height:4.35em;
  word-break:break-word;
}
.asset-table th:nth-child(4),
.asset-table td:nth-child(4){
  width:220px;
  max-width:220px;
}

.asset-table th:nth-child(5),
.asset-table td:nth-child(5){
  width:150px;
  max-width:150px;
}
.request-card{
  min-width:0;
  overflow:hidden;
}

.request-card h4{
  margin:0 0 8px;
  overflow-wrap:anywhere;
  word-break:break-word;
  white-space:normal;
}

.request-top{
  display:flex;
  justify-content:space-between;
  gap:12px;
  align-items:flex-start;
  margin-bottom:10px;
  min-width:0;
}

.request-top > div{
  min-width:0;
  flex:1;
}

.request-details{
  display:grid;
  gap:6px;
  color:var(--muted);
  font-size:.94rem;
  min-width:0;
}

.request-details div{
  overflow-wrap:anywhere;
  word-break:break-word;
}

.request-items-table-wrap{
  width:100%;
  max-width:100%;
  overflow-x:auto;
  overflow-y:hidden;
  -webkit-overflow-scrolling:touch;
}

.request-items-table{
  width:max-content;
  min-width:100%;
  border-collapse:collapse;
}

.request-items-table th,
.request-items-table td{
  overflow-wrap:anywhere;
  word-break:break-word;
}

@media (max-width: 820px){
  .request-card{
    padding:14px;
  }

  .request-card h4{
    font-size:1rem;
    line-height:1.45;
  }

  .request-items-table{
    min-width:640px;
  }
}
/* =========================================================
   EDIT MODAL
   ========================================================= */
.edit-card {
  max-width: 540px;
  width: 100%;
  max-height: 90vh;
  overflow-y: auto;
  padding: 0;
  border-radius: var(--radius-lg, 1rem);
  background: var(--surface, #fff);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1.25rem 1.5rem 0;
}

.modal-header h3 {
  font-size: 1.1rem;
  font-weight: 700;
  margin: 0;
}

.btn-icon {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 1.1rem;
  color: var(--text-muted, #6b7280);
  padding: 0.25rem 0.5rem;
  border-radius: 0.375rem;
  line-height: 1;
  transition: background 0.15s;
}
.btn-icon:hover { background: var(--surface-hover, #f3f4f6); }

.edit-card .form-block {
  padding: 1.25rem 1.5rem 1.5rem;
  gap: 1rem;
}

.modal-actions {
  display: flex;
  gap: 0.75rem;
  margin-top: 0.5rem;
  flex-wrap: wrap;
}

.modal-actions .btn { flex: 1; min-width: 0; }

.btn-danger {
  color: #dc2626 !important;
  border-color: #dc2626 !important;
}
.btn-danger:hover {
  background: #fef2f2 !important;
}

/* Edit button on request cards */
.request-actions {
  padding: 0.75rem 1rem 0.25rem;
  border-top: 1px solid var(--border, #e5e7eb);
  margin-top: 0.5rem;
}

/* CANCELLED badge */
.badge.cancelled {
  background: #f3f4f6;
  color: #6b7280;
}

/* =========================================================
   EDIT MODAL — Item editor & picker
   ========================================================= */
.mt-1 { margin-top: 0.5rem; }

.edit-item-list {
  display: flex;
  flex-direction: column;
  gap: 0.375rem;
  min-height: 2rem;
  background: var(--surface-alt, #f9fafb);
  border: 1px solid var(--border, #e5e7eb);
  border-radius: var(--radius, 0.5rem);
  padding: 0.5rem;
}

.edit-item-empty, .edit-picker-empty {
  color: var(--text-muted, #9ca3af);
  font-size: 0.85rem;
  text-align: center;
  padding: 0.25rem 0;
}

.edit-item-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  background: var(--surface, #fff);
  border: 1px solid var(--border, #e5e7eb);
  border-radius: var(--radius-sm, 0.375rem);
  padding: 0.375rem 0.5rem;
}

.edit-item-name {
  flex: 1;
  font-size: 0.875rem;
  line-height: 1.3;
  min-width: 0;
  word-break: break-word;
}

.edit-item-qty {
  width: 4.5rem;
  flex-shrink: 0;
  text-align: center;
  font-size: 0.875rem;
}

.edit-item-remove {
  flex-shrink: 0;
  color: #ef4444;
  font-size: 0.875rem;
}

/* Picker panel */
.edit-picker {
  border: 1px solid var(--border, #e5e7eb);
  border-radius: var(--radius, 0.5rem);
  background: var(--surface, #fff);
  margin-top: 0.5rem;
  overflow: hidden;
}

.edit-picker-head {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 0.75rem;
  border-bottom: 1px solid var(--border, #e5e7eb);
  background: var(--surface-alt, #f9fafb);
}

.edit-search-input {
  flex: 1;
  border: 1px solid var(--border, #e5e7eb);
  border-radius: var(--radius-sm, 0.375rem);
  padding: 0.375rem 0.625rem;
  font-size: 0.875rem;
  background: var(--surface, #fff);
  min-width: 0;
}
.edit-search-input:focus { outline: 2px solid var(--primary, #2563eb); }

.edit-picker-list {
  max-height: 220px;
  overflow-y: auto;
  padding: 0.375rem 0;
}

.edit-picker-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.4rem 0.75rem;
  transition: background 0.1s;
}
.edit-picker-row:hover { background: var(--surface-alt, #f9fafb); }
.edit-picker-row.is-selected { background: #eff6ff; }

.edit-picker-name {
  flex: 1;
  font-size: 0.875rem;
  min-width: 0;
  word-break: break-word;
}

.edit-picker-sub {
  font-size: 0.78rem;
  color: var(--text-muted, #6b7280);
  white-space: nowrap;
  flex-shrink: 0;
}

/* =========================================================
   EDIT MODAL — inline saving feedback
   ========================================================= */

/* Animated progress bar across top of modal while saving */
.edit-progress-bar {
  height: 3px;
  background: linear-gradient(90deg, var(--primary, #2563eb) 0%, #60a5fa 50%, var(--primary, #2563eb) 100%);
  background-size: 200% 100%;
  animation: progressSlide 1.2s linear infinite;
  border-radius: 3px 3px 0 0;
}
.edit-progress-bar.hidden { display: none; }

@keyframes progressSlide {
  0%   { background-position: 100% 0; }
  100% { background-position: -100% 0; }
}

/* Inline spinner inside the save button */
.btn-spinner {
  display: inline-block;
  width: 0.85em;
  height: 0.85em;
  border: 2px solid rgba(255,255,255,0.4);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.65s linear infinite;
  vertical-align: middle;
  margin-right: 0.25em;
}

/* Disabled state on modal buttons while submitting */
#editRequestForm button:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

/* 3-button modal actions — stack on small screens */
.modal-actions {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  margin-top: 0.5rem;
}
.modal-actions .btn {
  flex: 1 1 auto;
  min-width: 8rem;
  text-align: center;
}
/* Danger (ยกเลิกคำขอ) always full-width on its own row */
.modal-actions .btn-danger {
  flex-basis: 100%;
}

@media (max-width:560px){
  .page{padding:16px 10px 28px}
  .hero-left,.auth-card,.panel,.feature-card,.step-card{padding:18px}
  .hero-left h2{font-size:1.55rem}
  .hero-copy{font-size:.96rem}
  .brand{align-items:flex-start}
  .brand-badge{width:32px;height:32px;border-radius:0}
  .topbar-user{gap:8px;padding:8px 10px}
  .btn{width:100%}
  .hero-actions,.view-head-actions,.card-actions{display:grid;grid-template-columns:1fr}
  .auth-card{padding:18px}
  .field input,.field select,.field textarea{min-height:46px}
}
.brand-badge {
  display: flex;
  justify-content: center;
  align-items: center;
  margin-bottom: 0;
}

.brand-badge img {
  width: 32px;
  height: 32px;
  object-fit: contain;
  border-radius: 0;
  padding: 0;
  background: transparent;
  box-shadow: none;
}
body {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.app-footer {
  margin-top: auto;
  text-align: center;
  font-size: 13px;
  color: #6b6b6b;
  padding: 16px;
  border-top: 1px solid #eee;
}

/* Navy / gold / white theme override */
:root{
  --bg:#f7f9fc;
  --surface:#ffffff;
  --surface-2:#f8fafc;
  --text:#172033;
  --muted:#667085;
  --primary:#102a43;
  --primary-2:#0b1f33;
  --primary-soft:#fff4d6;
  --line:#d9e2ec;
  --success:#027a48;
  --danger:#b42318;
  --warning:#c7961f;
  --blue:#173f5f;
  --shadow:0 10px 24px rgba(16,42,67,.10);
  --radius-lg:8px;
  --radius-md:8px;
  --radius-sm:8px;
}

body{
  background:linear-gradient(180deg,#eef3f8 0%,#f7f9fc 48%,#fff 100%);
}

.topbar{
  background:rgba(255,255,255,.94);
  border-bottom:1px solid var(--line);
  box-shadow:var(--shadow);
}

.hero-left,
.hero-right,
.panel,
.auth-card,
.service-card,
.welcome-card,
.feature-card,
.step-card,
.request-card,
.asset-card,
.supply-card,
.stat-card,
.asset-sheet,
.selection-sheet,
.overlay-card,
.modal-card,
.edit-card{
  border-radius:8px;
}

.panel-gradient{
  background:linear-gradient(145deg,#102a43,#173f5f);
}

.feature-icon,
.service-icon,
.step-no,
.chip-primary,
.btn-soft,
.badge.borrowed,
.asset-card.is-selected{
  background:var(--primary-soft);
  color:var(--primary);
}

.btn,
.btn-home,
.btn-logout,
.topbar-user,
.role-badge,
.chip,
.badge,
.inline-status,
.field input,
.field select,
.field textarea,
.checkbox-wrap,
.qty-input,
.status-box,
.toast{
  border-radius:8px;
}

.field input:focus,
.field select:focus,
.field textarea:focus{
  border-color:rgba(199,150,31,.85);
  box-shadow:0 0 0 4px rgba(199,150,31,.16);
}

.btn-primary{
  background:var(--primary);
  box-shadow:none;
}

.btn-primary:hover{
  background:var(--primary-2);
}

.asset-table thead th,
.selection-table thead th,
.request-items-table th,
.selection-sheet-head{
  background:#eef3f8;
  color:var(--primary);
}

.asset-card.is-selected{
  border-color:rgba(199,150,31,.55);
  box-shadow:0 12px 26px rgba(16,42,67,.10);
}

.accent-purple,
.accent-blue,
.accent-slate{
  background:#fff;
}
