/* Layout kiểu IntlManager — mobile: drawer + topbar + bottom nav; desktop: sidebar cố định */

/*
 * Safari iOS / Add to Home Screen: viewport-fit=cover + black-translucent → nội dung có thể
 * lấn dưới tai thỏ/status bar; dùng env(safe-area-inset-*) + -webkit-fill-available cho chiều cao.
 */
html {
  height: 100%;
  height: -webkit-fill-available;
}

:root {
  --color-primary: #1a7a82;
  --color-primary-2: #155e64;
  --color-primary-3: #e6f4f5;
  --color-accent: #d4a017;
  --color-bg: #faf9f6;
  --color-surface: #ffffff;
  --color-text: #1f2937;
  --color-text-muted: #64748b;
  --color-border: #e2e8f0;
  --color-danger: #991b1b;
  --color-success: #059669;
  --radius-md: 8px;
  --radius-lg: 12px;
  --radius-xl: 16px;
}

.msoi {
  font-family: 'Material Symbols Rounded';
  font-variation-settings: 'FILL' 0, 'wght' 400, 'GRAD' 0, 'opsz' 24;
  font-size: 20px;
  line-height: 1;
  display: inline-block;
  vertical-align: middle;
}

body {
  min-height: 100%;
  min-height: 100dvh;
  min-height: -webkit-fill-available;
  background: var(--color-bg);
  color: var(--color-text);
}

#login-screen {
  padding-top: env(safe-area-inset-top, 0px);
  padding-bottom: env(safe-area-inset-bottom, 0px);
  padding-left: env(safe-area-inset-left, 0px);
  padding-right: env(safe-area-inset-right, 0px);
}

/*
 * Safari iOS 16.4+ (Safari và PWA «Add to Home Screen»): nếu ô nhập có font nhỏ hơn 16px,
 * trình duyệt tự zoom khi focus. Chuyển giữa các ô (hai cột, ô VAT, v.v.) làm viewport nhảy,
 * dễ có cảm giác «trôi ngang» / khó nhập.
 * Ép font tối thiểu 16px trên breakpoint mobile/tablet portrait (đồng breakpoint bottom nav).
 */
@media (max-width: 1023px) {
  input:not([type='checkbox']):not([type='radio']):not([type='hidden']):not([type='range']):not([type='submit']):not([type='reset']):not([type='button']),
  select,
  textarea {
    font-size: 16px !important;
    line-height: 1.45;
  }
}

#app-shell {
  flex-direction: column;
  min-height: 100dvh;
  min-width: 0;
}

/* Cố định chiều cao vùng app = viewport để #pc-scroll thật sự cuộn bên trong.
   Nếu không, shell kéo cao theo nội dung → cuộn cả trang → sticky không kích hoạt (desktop). */
#app-shell:not(.hidden) {
  height: 100dvh;
  height: -webkit-fill-available;
  max-height: 100dvh;
  max-height: -webkit-fill-available;
  overflow: hidden;
}

#pc-overlay {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 90;
  background: rgba(0, 0, 0, 0.45);
}

#pc-overlay.open {
  display: block;
}

@media (min-width: 1024px) {
  #pc-overlay {
    display: none !important;
  }
}

#pc-sidebar {
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  z-index: 100;
  width: min(17rem, 88vw);
  display: flex;
  flex-direction: column;
  transform: translateX(-100%);
  transition: transform 0.25s ease;
  box-shadow: 4px 0 20px rgba(0, 0, 0, 0.12);
  padding-top: env(safe-area-inset-top, 0px);
  padding-bottom: env(safe-area-inset-bottom, 0px);
  padding-left: env(safe-area-inset-left, 0px);
}

#pc-sidebar.open {
  transform: translateX(0);
}

@media (min-width: 1024px) {
  #pc-sidebar {
    width: 15rem;
    transform: none !important;
    transition: none;
    box-shadow: none;
  }
}

#pc-topbar {
  position: sticky;
  top: 0;
  z-index: 40;
  /* Thanh mobile: tránh chồng lên tai thỏ / vùng trạng thái khi cài PWA */
  padding-top: env(safe-area-inset-top, 0px);
  padding-left: max(0.75rem, env(safe-area-inset-left, 0px));
  padding-right: max(0.75rem, env(safe-area-inset-right, 0px));
  min-height: calc(3.5rem + env(safe-area-inset-top, 0px));
  height: auto;
  flex-shrink: 0;
  box-sizing: border-box;
}

@media (min-width: 1024px) {
  #pc-topbar {
    display: none !important;
  }
}

#pc-main {
  flex: 1;
  min-height: 0;
  min-width: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

@media (max-width: 1023px) {
  #pc-main {
    padding-bottom: calc(3.75rem + env(safe-area-inset-bottom, 0px));
    /* Tránh nội dung sát mép tai thỏ khi xoay ngang */
    padding-left: env(safe-area-inset-left, 0px);
    padding-right: env(safe-area-inset-right, 0px);
  }
}

@media (min-width: 1024px) {
  #pc-main {
    margin-left: 15rem;
    padding-bottom: 0;
  }
}

#pc-scroll {
  flex: 1;
  min-height: 0;
  min-width: 0;
  overflow-x: hidden;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

/* Sticky theo scrollport của #pc-scroll (phải có overflow thật trên #pc-scroll) */
#o-sticky-order-bar {
  position: sticky;
  top: 0;
  z-index: 30;
  width: 100%;
  max-width: 100%;
}

/* Safari iOS: sticky + backdrop-filter ở khối nhập đầu dễ gây giật/vỡ layout.
   Mobile chuyển về static để ưu tiên ổn định hiển thị. */
@media (max-width: 1023px) {
  #o-sticky-order-bar {
    position: static;
    top: auto;
    backdrop-filter: none;
  }
}

#pc-bottom-nav {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 50;
  display: flex;
  align-items: stretch;
  justify-content: space-around;
  padding-bottom: max(0px, env(safe-area-inset-bottom));
  height: calc(3.75rem + max(0px, env(safe-area-inset-bottom)));
  background: #fff;
  border-top: 1px solid #e2e8f0;
  box-shadow: 0 -2px 12px rgba(0, 0, 0, 0.06);
}

@media (min-width: 1024px) {
  #pc-bottom-nav {
    display: none !important;
  }
}

.pc-bnav {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  padding: 6px 4px;
  border: none;
  background: transparent;
  cursor: pointer;
  font-size: 10px;
  font-weight: 600;
  color: #64748b;
  line-height: 1.15;
  max-width: 20%;
}

.pc-bnav.active {
  color: #0f766e;
  background: #e6f4f5;
}

.pc-snav {
  width: 100%;
  text-align: left;
  padding: 0.65rem 0.75rem;
  border-radius: 0.5rem;
  font-size: 0.875rem;
  color: #ccfbf1;
  border: none;
  background: transparent;
  cursor: pointer;
}

.pc-snav:hover {
  background: rgba(255, 255, 255, 0.08);
}

.pc-snav.active {
  background: #115e59;
  color: #fff;
  font-weight: 600;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  border: 1.5px solid transparent;
  border-radius: 12px;
  padding: 10px 16px;
  min-height: 44px;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  letter-spacing: 0.01em;
  transition: background 0.15s, border-color 0.15s, transform 0.12s, color 0.15s;
}
.btn:active {
  transform: scale(0.98);
}
.bp {
  background: var(--color-primary);
  color: #fff;
  border-color: var(--color-primary);
}
.bp:hover {
  background: var(--color-primary-2);
  border-color: var(--color-primary-2);
}
.bg {
  background: #f1f5f9;
  color: #374151;
  border-color: #e2e8f0;
}
.bd {
  background: var(--color-danger);
  color: #fff;
  border-color: var(--color-danger);
}
.btn-ghost {
  background: #fff;
  color: var(--color-primary);
  border-color: var(--color-primary);
}
.btn-ghost:hover {
  background: var(--color-primary-3);
}

#btn-save-order,
#btn-export-excel {
  box-shadow: 0 4px 14px rgba(26, 122, 130, 0.22);
}

/* Khu action đầu form: mobile full-width để dễ bấm và không vỡ hàng trên Safari. */
.order-material-header-actions {
  width: 100%;
}
.order-material-header-actions > .btn {
  width: 100%;
}
@media (min-width: 640px) {
  .order-material-header-actions {
    width: auto;
  }
  .order-material-header-actions > .btn {
    width: auto;
  }
}

/* iOS Safari form controls: cố định chiều cao để tránh render lệch/cắt chữ. */
@supports (-webkit-touch-callout: none) {
  #panel-nhap input[type='date'],
  #panel-nhap select {
    min-height: 44px;
    line-height: 1.2;
  }
}

.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: rgba(11, 28, 48, 0.5);
  backdrop-filter: blur(4px);
  animation: fadeIn 0.15s ease;
}
.modal-body {
  position: relative;
  width: 100%;
  max-width: 520px;
  max-height: 90dvh;
  overflow-y: auto;
  border-radius: var(--radius-xl);
  background: #fff;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.2);
  padding: 22px;
  animation: mIn 0.15s ease;
}
.modal-close {
  position: absolute;
  top: 10px;
  right: 12px;
  border: none;
  background: transparent;
  font-size: 20px;
  color: #94a3b8;
  cursor: pointer;
}
.modal-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 15px;
  font-weight: 700;
  margin-bottom: 10px;
}
.modal-content {
  font-size: 13px;
  color: var(--color-text-muted);
}
.modal-message {
  margin: 0;
}
.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 16px;
}
.ui-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  display: inline-block;
}
.ui-dot-info { background: #1d4ed8; }
.ui-dot-danger { background: var(--color-danger); }

#toast-container {
  position: fixed;
  right: 16px;
  bottom: calc(70px + max(0px, env(safe-area-inset-bottom)));
  z-index: 99999;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.toast-item {
  min-width: 260px;
  max-width: 360px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  background: #fff;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.12);
  padding: 11px 12px;
  font-size: 13px;
  display: flex;
  align-items: center;
  gap: 8px;
  transition: opacity 0.25s ease;
}
.toast-success { border-left: 3px solid var(--color-success); }
.toast-error { border-left: 3px solid var(--color-danger); }
.toast-info { border-left: 3px solid #1d4ed8; }
.toast-msg { flex: 1; }
.toast-close {
  border: none;
  background: transparent;
  color: #94a3b8;
  cursor: pointer;
  font-size: 16px;
}

#panel-ds .bg-white.rounded-xl {
  border-radius: var(--radius-lg);
  border-color: var(--color-border);
}
#panel-ds input,
#panel-ds select,
#panel-nhap input,
#panel-nhap select,
#panel-nhap textarea {
  transition: border-color 0.15s, box-shadow 0.15s, background 0.15s;
}
#panel-ds input:focus,
#panel-ds select:focus,
#panel-nhap input:focus,
#panel-nhap select:focus,
#panel-nhap textarea:focus {
  outline: none;
  background: #fff;
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px rgba(26, 122, 130, 0.1);
}
#panel-ds thead th {
  letter-spacing: 0.08em;
  text-transform: uppercase;
  font-size: 10px;
  color: #64748b;
}
#panel-ds tbody td:nth-child(2),
#panel-ds tbody td:nth-child(6),
#panel-ds tbody td:nth-child(8) {
  font-variant-numeric: tabular-nums;
}
.order-list-status {
  border-radius: 999px !important;
  font-weight: 700 !important;
  font-size: 11px !important;
}

@keyframes mIn {
  from { opacity: 0; transform: scale(0.97) translateY(5px); }
  to { opacity: 1; transform: scale(1) translateY(0); }
}
@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}
