/* T-Go V1.47 — System-wide UI consistency pass
   Scope: visual normalization only. No business logic.
   Goals: consistent Thai font sizing, line-height, spacing, controls, table overflow, and anti-overlap guards. */

:root{
  --tgo-font-thai:"Noto Sans Thai","Segoe UI",Tahoma,Arial,sans-serif;
  --tgo-font-size-xs:12px;
  --tgo-font-size-sm:13px;
  --tgo-font-size-md:14px;
  --tgo-font-size-lg:16px;
  --tgo-font-size-xl:20px;
  --tgo-line-height:1.55;
  --tgo-control-height:38px;
  --tgo-control-radius:8px;
  --tgo-card-radius:14px;
  --tgo-gap-xs:6px;
  --tgo-gap-sm:8px;
  --tgo-gap-md:12px;
  --tgo-gap-lg:16px;
  --tgo-border:#e5e7eb;
  --tgo-text:#1f2937;
  --tgo-muted:#6b7280;
  --tgo-surface:#ffffff;
  --tgo-soft:#f8fafc;
  --tgo-primary:#2563eb;
}

html,body{
  font-family:var(--tgo-font-thai) !important;
  font-size:var(--tgo-font-size-md);
  line-height:var(--tgo-line-height);
  text-rendering:optimizeLegibility;
  -webkit-font-smoothing:antialiased;
}
body,button,input,select,textarea,table{
  font-family:var(--tgo-font-thai) !important;
}

/* Thai text and labels should never compress into each other. */
*,*::before,*::after{ box-sizing:border-box; }
label,.label,.form-label,.field-label,.muted,.subtext,.small,.badge,.pill,
.card,.card-title,.section-title,.page-title,.table-title,.toolbar,.filter-bar,
.module-card,.nav-item,.btn,button,input,select,textarea{
  line-height:var(--tgo-line-height);
}

/* Global page rhythm */
.content,.main-content,.workspace,.page,.panel,.module-page,
#content,.content-area,.tgo-page,.tgo-shell-page{
  min-width:0;
}

.page-header,.module-header,.section-header,.toolbar,.action-bar,.filter-bar,
.card-header,.panel-header{
  display:flex;
  flex-wrap:wrap;
  align-items:center;
  gap:var(--tgo-gap-md);
  min-width:0;
}

.page-header > *, .module-header > *, .section-header > *, .toolbar > *,
.action-bar > *, .filter-bar > *, .card-header > *, .panel-header > *{
  min-width:0;
}

h1,.h1,.page-title{ font-size:24px; line-height:1.32; font-weight:700; letter-spacing:-.01em; }
h2,.h2,.section-title{ font-size:20px; line-height:1.36; font-weight:700; letter-spacing:-.005em; }
h3,.h3,.card-title{ font-size:16px; line-height:1.45; font-weight:700; }
h4,h5,h6{ line-height:1.45; }
p{ line-height:var(--tgo-line-height); }

/* Controls: same height and typography across modules. */
input:not([type="checkbox"]):not([type="radio"]),select,textarea,
.form-input,.input,.select,.textarea,.tgo-input,.tgo-select,.tgo-textarea{
  font-size:var(--tgo-font-size-md) !important;
  line-height:1.45 !important;
  border-radius:var(--tgo-control-radius);
  min-height:var(--tgo-control-height);
  padding:8px 12px;
  max-width:100%;
}
textarea,.textarea,.tgo-textarea{ min-height:88px; resize:vertical; }

button,.btn,.tgo-btn,[role="button"]{
  font-family:var(--tgo-font-thai) !important;
  font-size:var(--tgo-font-size-md) !important;
  line-height:1.35 !important;
  min-height:36px;
  border-radius:var(--tgo-control-radius);
  display:inline-flex;
  align-items:center;
  justify-content:center;
  gap:6px;
  white-space:normal;
  text-align:center;
  max-width:100%;
}
.btn-sm,.small-btn,button.btn-sm{ font-size:var(--tgo-font-size-sm) !important; min-height:32px; padding:6px 10px; }
.btn-lg,button.btn-lg{ font-size:var(--tgo-font-size-lg) !important; min-height:42px; padding:9px 16px; }

/* Cards and panels: prevent text clipping/overlap. */
.card,.panel,.box,.tile,.stat-card,.metric-card,.module-card,
.tgo-card,.office-card,.kpi-card,.summary-card{
  min-width:0;
  overflow-wrap:anywhere;
  border-radius:var(--tgo-card-radius);
}
.card *, .panel *, .box *, .tile *, .stat-card *, .metric-card *, .module-card *,
.tgo-card *, .office-card *, .kpi-card *, .summary-card *{
  min-width:0;
}

/* Tables: normalize font and stop columns from squeezing into unreadable overlap. */
table,.table,.data-table{
  width:100%;
  border-collapse:separate;
  border-spacing:0;
  font-size:var(--tgo-font-size-sm) !important;
  line-height:1.45;
}
th,td{
  font-size:var(--tgo-font-size-sm) !important;
  line-height:1.45 !important;
  vertical-align:middle;
  padding:10px 12px;
  overflow-wrap:anywhere;
}
th{ font-weight:700; white-space:nowrap; }
.table-wrap,.table-container,.data-table-wrap,.overflow-x-auto,
.tgo-table-wrap,.list-table-wrap{
  width:100%;
  max-width:100%;
  overflow-x:auto;
  -webkit-overflow-scrolling:touch;
}

/* Badges/pills/status: consistent and non-overlapping. */
.badge,.pill,.status,.tag,.chip,.status-badge,.tgo-badge{
  display:inline-flex;
  align-items:center;
  justify-content:center;
  gap:4px;
  min-height:24px;
  padding:3px 8px;
  border-radius:999px;
  font-size:12px !important;
  line-height:1.3 !important;
  white-space:nowrap;
  max-width:100%;
}

/* Lists and rows. */
.list-row,.row-card,.item-row,.record-row,.tgo-row{
  display:flex;
  align-items:center;
  gap:var(--tgo-gap-md);
  min-width:0;
}
.list-row > *, .row-card > *, .item-row > *, .record-row > *, .tgo-row > *{ min-width:0; }

/* Modal/drawer/full-page forms: keep header/footer readable and body scrollable. */
.mdbg,.modal-backdrop,.drawer-backdrop,.full-page-form-backdrop{
  font-family:var(--tgo-font-thai) !important;
}
.md,.modal,.drawer,.full-page-form,.tgo-drawer,.tgo-modal{
  max-width:min(1100px, calc(100vw - 32px));
  max-height:calc(100vh - 32px);
  overflow:auto;
  font-size:var(--tgo-font-size-md);
  line-height:var(--tgo-line-height);
}
.modal-header,.drawer-header,.form-header{
  display:flex;
  align-items:flex-start;
  justify-content:space-between;
  gap:var(--tgo-gap-md);
  flex-wrap:wrap;
}
.modal-footer,.drawer-footer,.form-footer,.sticky-footer{
  display:flex;
  justify-content:flex-end;
  align-items:center;
  flex-wrap:wrap;
  gap:var(--tgo-gap-sm);
}

/* Form grid: responsive so labels and inputs do not overlap. */
.form-grid,.grid-form,.fields-grid,.tgo-form-grid{
  display:grid;
  grid-template-columns:repeat(auto-fit,minmax(220px,1fr));
  gap:var(--tgo-gap-md);
  align-items:start;
}
.form-row,.field,.form-field,.tgo-field{
  min-width:0;
}
.form-row label,.field label,.form-field label,.tgo-field label{
  display:block;
  margin-bottom:5px;
  font-size:var(--tgo-font-size-sm) !important;
  font-weight:600;
  color:var(--tgo-text);
}

/* Sidebar and module cards: consistent icon/text alignment. */
.sidebar,.nav,.module-grid,.module-card-grid{ font-family:var(--tgo-font-thai) !important; }
.nav-item,.sidebar .nav-item{
  min-height:42px;
  line-height:1.35;
}
.nav-item-label,.sidebar-label,.module-card-title{
  overflow:hidden;
  text-overflow:ellipsis;
  white-space:nowrap;
}
.module-card p,.module-card .module-desc{
  font-size:var(--tgo-font-size-sm) !important;
  line-height:1.45;
}

/* Iframe host: avoid clipping embedded modules. */
iframe{
  max-width:100%;
}
.iframe-wrap,.module-iframe-wrap,.tgo-iframe-shell{
  width:100%;
  min-width:0;
  overflow:hidden;
}

/* Mobile refinements. */
@media (max-width: 768px){
  :root{ --tgo-font-size-md:13px; --tgo-control-height:38px; }
  h1,.h1,.page-title{ font-size:21px; }
  h2,.h2,.section-title{ font-size:18px; }
  .content,.main-content,.workspace,.page,.panel,.module-page{ padding-left:12px; padding-right:12px; }
  .toolbar,.action-bar,.filter-bar{ align-items:stretch; }
  .toolbar > button,.action-bar > button,.filter-bar > button,
  .toolbar > .btn,.action-bar > .btn,.filter-bar > .btn{
    flex:1 1 140px;
  }
  input:not([type="checkbox"]):not([type="radio"]),select,textarea{ width:100%; }
  th,td{ padding:9px 10px; }
}

/* Print should remain controlled by each print template. */
@media print{
  .tgo-ui-normalized-only{ display:none !important; }
}

/* V1.49: keep Costsheet item sequence column compact */
.twrap table th:nth-child(2):has(+ th),
.twrap table td:nth-child(2){box-sizing:border-box;}
.twrap .cs-seq-input{width:42px!important;min-width:42px!important;max-width:42px!important;text-align:center!important;}


/* V1.51: Costsheet sequence column must stay compact. */
#costsheetPage .cs-v2-items-table{table-layout:fixed!important;width:100%!important;min-width:980px!important;}
#costsheetPage .cs-v2-items-table .cs-col-select{width:42px!important;}
#costsheetPage .cs-v2-items-table .cs-col-seq{width:64px!important;}
#costsheetPage .cs-v2-items-table th.cs-v2-seq-cell,
#costsheetPage .cs-v2-items-table td.cs-v2-seq-cell{width:64px!important;min-width:64px!important;max-width:64px!important;text-align:center!important;padding-left:6px!important;padding-right:6px!important;box-sizing:border-box!important;}
#costsheetPage .cs-v2-items-table .cs-seq-input{width:48px!important;min-width:48px!important;max-width:48px!important;text-align:center!important;box-sizing:border-box!important;}


/* V1.51: Costsheet item table: sequence is display-only and row checkbox moves to last column. */
#costsheetPage .cs-v2-items-table{table-layout:fixed!important;width:100%!important;min-width:980px!important;}
#costsheetPage .cs-v2-items-table .cs-col-seq{width:46px!important;}
#costsheetPage .cs-v2-items-table .cs-col-select{width:48px!important;}
#costsheetPage .cs-v2-items-table th.cs-v2-seq-cell,
#costsheetPage .cs-v2-items-table td.cs-v2-seq-cell{width:46px!important;min-width:46px!important;max-width:46px!important;text-align:center!important;padding-left:4px!important;padding-right:4px!important;box-sizing:border-box!important;}
#costsheetPage .cs-v2-items-table .cs-seq-text{display:inline-flex!important;align-items:center!important;justify-content:center!important;width:34px!important;min-width:34px!important;height:24px!important;border-radius:999px!important;background:#eef2f7!important;color:#334155!important;font-size:12px!important;font-weight:700!important;}
#costsheetPage .cs-v2-items-table th.cs-v2-select-cell,
#costsheetPage .cs-v2-items-table td.cs-v2-select-cell{width:48px!important;min-width:48px!important;max-width:48px!important;text-align:center!important;padding-left:4px!important;padding-right:4px!important;box-sizing:border-box!important;}
#costsheetPage .cs-v2-items-table th:first-child,
#costsheetPage .cs-v2-items-table td:first-child{width:46px!important;min-width:46px!important;max-width:46px!important;}
#costsheetPage .cs-v2-items-table th:last-child,
#costsheetPage .cs-v2-items-table td:last-child{width:48px!important;min-width:48px!important;max-width:48px!important;}


/* V1.52: Compact DB status button Option D. Scope only the DB button after T-Go logo; do not alter logo. */
#tgo-db-status-pill.tgo-db-compact-status{
  width:48px!important; min-width:48px!important; max-width:48px!important;
  height:26px!important; padding:0 7px!important; border-radius:8px!important;
  font-size:0!important; line-height:1!important; gap:6px!important;
}
.sidebar.collapsed #tgo-db-status-pill.tgo-db-compact-status{display:none!important;}
