/*
  VELAEA CENTER - Batch 21
  Final UI Polish + Mobile QA Layer
  Safe to include on all customer/admin pages.
*/

:root{
  --velaea-safe-x: clamp(12px, 3vw, 28px);
  --velaea-radius-mobile: 18px;
  --velaea-touch: 44px;
}

/* General hardening */
html{
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  scroll-behavior: smooth;
}

body{
  overflow-x: hidden;
}

img,svg,video,canvas{
  max-width: 100%;
  height: auto;
}

button,
.btn,
a.btn,
input,
select,
textarea{
  -webkit-tap-highlight-color: transparent;
}

button,
.btn,
a.btn{
  min-height: var(--velaea-touch);
}

input,
select,
textarea{
  font-size: 16px;
}

/* Consistent focus state */
a:focus-visible,
button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible{
  outline: 2px solid rgba(242,199,106,.75)!important;
  outline-offset: 3px;
}

/* Tables */
.table-wrap,
[data-table-wrap="true"]{
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  border-radius: 16px;
  scrollbar-width: thin;
  scrollbar-color: rgba(242,199,106,.45) rgba(255,255,255,.06);
}

table{
  max-width: 100%;
}

th,td{
  word-break: break-word;
}

/* Better empty/error states */
.empty,
.empty-state,
[data-empty-state="true"]{
  border: 1px dashed rgba(242,199,106,.2);
  border-radius: 16px;
  background: rgba(255,255,255,.025);
}

/* Toasts injected by velaea-ui-qa.js */
.velaea-toast-stack{
  position: fixed;
  right: 16px;
  bottom: 16px;
  display: grid;
  gap: 10px;
  z-index: 99999;
  pointer-events: none;
}

.velaea-toast{
  min-width: min(360px, calc(100vw - 32px));
  max-width: min(420px, calc(100vw - 32px));
  border: 1px solid rgba(242,199,106,.22);
  border-radius: 16px;
  padding: 12px 14px;
  background: rgba(6,17,31,.94);
  color: #f7fbff;
  box-shadow: 0 18px 50px rgba(0,0,0,.38);
  backdrop-filter: blur(14px);
  font: 800 13px/1.55 Inter,'Noto Sans Thai',Arial,sans-serif;
  pointer-events: auto;
}

/* Mobile navigation/tables/cards */
@media (max-width: 860px){
  .page,
  .content{
    padding-left: var(--velaea-safe-x)!important;
    padding-right: var(--velaea-safe-x)!important;
  }

  .top,
  .topbar,
  header{
    gap: 10px;
  }

  .top{
    align-items: center!important;
  }

  .top .brand,
  .top > a.brand{
    display: inline-flex!important;
    align-items: center;
    justify-content: center;
    min-height: 42px;
    padding: 0 12px;
    border: 1px solid rgba(242,199,106,.18);
    border-radius: 14px;
    background: rgba(255,255,255,.035);
    color: #f7fbff;
    font-weight: 950;
  }

  .top .brand img,
  .top > a.brand img{
    display: block;
    width: min(142px, 42vw)!important;
    max-height: 42px;
    object-fit: contain;
  }

  .top > div,
  .topbar > div,
  .nav-actions,
  .header-actions{
    max-width: 100%;
  }

  .top a.btn,
  .top .btn,
  .topbar .btn{
    padding-left: 12px;
    padding-right: 12px;
    white-space: nowrap;
  }

  .top > div:not(.brand),
  .topbar > div:last-child{
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }

  .top > div:not(.brand)::-webkit-scrollbar,
  .topbar > div:last-child::-webkit-scrollbar{
    display: none;
  }

  .hero,
  .welcome,
  .panel,
  .card{
    border-radius: var(--velaea-radius-mobile)!important;
  }

  .hero h1,
  .welcome h1{
    font-size: clamp(28px, 8vw, 36px)!important;
    line-height: 1.08!important;
  }

  .hero p,
  .welcome p{
    font-size: 14px!important;
  }

  .grid,
  .cards,
  .metrics,
  .toolbar,
  form[style*="grid-template-columns"]{
    grid-template-columns: 1fr!important;
  }

  .panel-pad,
  .panel-head{
    padding-left: 14px!important;
    padding-right: 14px!important;
  }

  table{
    min-width: 720px;
  }

  .table-wrap,
  [data-table-wrap="true"]{
    position: relative;
    margin-inline: -2px;
    border: 1px solid rgba(255,255,255,.075);
    background:
      linear-gradient(90deg,rgba(5,15,28,.96),rgba(5,15,28,0) 22px) left/34px 100% no-repeat,
      linear-gradient(270deg,rgba(5,15,28,.96),rgba(5,15,28,0) 22px) right/34px 100% no-repeat,
      rgba(255,255,255,.018);
    box-shadow: inset -16px 0 18px rgba(2,8,20,.22);
  }

  .table-wrap::after,
  [data-table-wrap="true"]::after{
    content: "เลื่อนดูข้อมูล";
    position: sticky;
    left: 12px;
    bottom: 10px;
    display: inline-flex;
    min-height: 28px;
    align-items: center;
    margin: 0 0 10px 10px;
    padding: 0 10px;
    border: 1px solid rgba(242,199,106,.28);
    border-radius: 999px;
    background: rgba(7,17,31,.88);
    color: #f2c76a;
    font-size: 11px;
    font-weight: 950;
    pointer-events: none;
    box-shadow: 0 12px 28px rgba(0,0,0,.24);
  }

  .panel-head{
    align-items: flex-start!important;
    flex-wrap: wrap;
  }

  .panel-head .btn,
  .panel-head button{
    flex: 0 0 auto;
  }

  .sidebar{
    display: none!important;
  }

  .app{
    display: block!important;
  }

  .main{
    width: 100%!important;
  }

  .velaea-toast-stack{
    left: 12px;
    right: 12px;
    bottom: calc(12px + env(safe-area-inset-bottom));
  }

  .velaea-toast{
    width: 100%;
    min-width: 0;
  }
}

/* Very small phones */
@media (max-width: 430px){
  .btn,
  a.btn,
  button{
    width: auto;
    max-width: 100%;
  }

  .top{
    align-items: flex-start!important;
  }

  .top{
    display: grid!important;
    grid-template-columns: 1fr;
  }

  .top > div:not(.brand){
    width: 100%;
    display: flex;
    gap: 8px;
    overflow-x: auto;
    padding-bottom: 2px;
  }

  .top > div:not(.brand) .btn{
    flex: 0 0 auto;
  }

  .brand img{
    max-width: 136px!important;
  }

  th,td{
    padding: 11px 10px!important;
    font-size: 12px!important;
  }
}

/* Print-friendly invoices/reports */
@media print{
  body{
    background: #fff!important;
    color: #000!important;
  }

  .sidebar,
  .topbar,
  .top,
  .btn,
  button{
    display: none!important;
  }

  .panel,
  .hero,
  .welcome,
  .card{
    box-shadow: none!important;
    border-color: #ddd!important;
  }
}
