/* =========================================================
   KAM E-Form Online — Application UI & Locked A4 Form Styles
   ========================================================= */

:root {
  --cp-blue: #1B5E91;
  --cp-blue-dark: #13446b;
  --cp-blue-soft: #eef5fb;
  --cp-yellow: #F3BD2B;
  --makro-red: #E1251B;
  --lotus-teal: #009988;

  --bg-app: #f1f5f9;
  --bg-card: #ffffff;
  --border-ui: #dbe2ea;
  --text-main: #0f172a;
  --text-muted: #475569;
  --text-light: #64748b;
  --success: #059669;
  --warning: #d97706;
  --danger: #dc2626;
  --radius: 12px;
  --shadow-sm: 0 1px 3px rgba(15, 23, 42, 0.06);
  --shadow-md: 0 6px 20px rgba(15, 23, 42, 0.08);
}

*, *::before, *::after {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
  font-family: 'Sarabun', 'Leelawadee UI', 'Tahoma', sans-serif;
  background: var(--bg-app);
  color: var(--text-main);
  min-height: 100vh;
}

/* ==================== APP SHELL ==================== */
.app-layout {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  width: 268px;
  background: linear-gradient(180deg, #0f2c47 0%, #163d61 100%);
  color: #fff;
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  position: sticky;
  top: 0;
  height: 100vh;
  z-index: 30;
  box-shadow: 2px 0 14px rgba(15, 23, 42, 0.14);
}

.sidebar-brand {
  padding: 18px 16px 14px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.12);
}

.sidebar-brand-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 10px;
}

.sidebar-brand .brand-pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: #ffffff;
  padding: 5px 11px;
  border-radius: 8px;
}

.drawer-close-btn {
  display: none;
  width: 34px;
  height: 34px;
  border-radius: 8px;
  border: 1px solid rgba(255, 255, 255, 0.25);
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
  align-items: center;
  justify-content: center;
}

.drawer-close-btn:hover {
  background: rgba(255, 255, 255, 0.24);
}

.sidebar-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.52);
  backdrop-filter: blur(2px);
  z-index: 90;
  opacity: 0;
  transition: opacity 0.2s ease;
}

.sidebar-backdrop.show {
  display: block;
  opacity: 1;
}

.sidebar-brand h1 {
  margin: 0;
  font-size: 18px;
  font-weight: 700;
  letter-spacing: 0.2px;
}

.sidebar-brand p {
  margin: 4px 0 0;
  font-size: 12px;
  color: rgba(255, 255, 255, 0.72);
}

.sidebar-nav {
  padding: 10px 10px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  flex: 1;
  overflow-y: auto;
}

.nav-group-label {
  font-size: 10.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: rgba(255, 255, 255, 0.52);
  padding: 10px 12px 4px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 9px;
  width: 100%;
  text-align: left;
  padding: 9px 12px;
  border: none;
  border-radius: 9px;
  background: transparent;
  color: rgba(255, 255, 255, 0.86);
  font-family: inherit;
  font-size: 13.5px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.16s ease;
  position: relative;
}

.nav-item:hover {
  background: rgba(255, 255, 255, 0.1);
  color: #fff;
}

.nav-item.active {
  background: #ffffff;
  color: var(--cp-blue-dark);
  font-weight: 700;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.16);
}

.nav-item .nav-icon {
  font-size: 17px;
  width: 22px;
  text-align: center;
  flex-shrink: 0;
}

.nav-item .nav-badge {
  margin-left: auto;
  font-size: 11px;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: 999px;
  background: rgba(243, 189, 43, 0.22);
  color: #fde68a;
}

.nav-item.active .nav-badge {
  background: var(--cp-yellow);
  color: #1e293b;
}

.nav-item.highlight-shipto:not(.active) {
  background: rgba(243, 189, 43, 0.14);
  border: 1px solid rgba(243, 189, 43, 0.35);
  color: #fef3c7;
}

.nav-item.highlight-shipto:not(.active):hover {
  background: rgba(243, 189, 43, 0.24);
}

.sidebar-footer {
  padding: 14px 16px;
  border-top: 1px solid rgba(255, 255, 255, 0.12);
  font-size: 11.5px;
  color: rgba(255, 255, 255, 0.68);
  line-height: 1.5;
}

.sidebar-footer strong {
  color: #fff;
  display: block;
}

/* ==================== MAIN WORKSPACE ==================== */
.main-content {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.topbar {
  background: #fff;
  border-bottom: 1px solid var(--border-ui);
  padding: 12px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  position: sticky;
  top: 0;
  z-index: 40;
  box-shadow: 0 1px 4px rgba(15, 23, 42, 0.04);
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
  flex: 1;
}

.mobile-menu-btn {
  display: none;
  width: 40px;
  height: 40px;
  border-radius: 10px;
  border: 1px solid var(--border-ui);
  background: #f8fafc;
  color: var(--cp-blue-dark);
  font-size: 20px;
  font-weight: 700;
  cursor: pointer;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.mobile-menu-btn:hover {
  background: var(--cp-blue-soft);
  border-color: var(--cp-blue);
}

.topbar-title-wrap {
  min-width: 0;
}

.topbar-title-wrap h2 {
  margin: 0;
  font-size: 18px;
  font-weight: 700;
  color: var(--text-main);
  line-height: 1.25;
}

.topbar-title-wrap p {
  margin: 2px 0 0;
  font-size: 12.5px;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.view-container {
  padding: 22px 24px 48px;
  max-width: 1320px;
  width: 100%;
  margin: 0 auto;
}

.view-section {
  display: none;
}

.view-section.active {
  display: block;
  animation: fadeIn 0.18s ease;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ==================== BUTTONS & BADGES ==================== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 9px 15px;
  border-radius: 9px;
  border: 1px solid transparent;
  font-family: inherit;
  font-size: 13.5px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s ease;
  white-space: nowrap;
}

.btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.btn-primary {
  background: var(--cp-blue);
  color: #fff;
}
.btn-primary:hover:not(:disabled) {
  background: var(--cp-blue-dark);
}

.btn-accent {
  background: var(--cp-yellow);
  color: #1e293b;
}
.btn-accent:hover:not(:disabled) {
  background: #e5ad19;
}

.btn-success {
  background: var(--success);
  color: #fff;
}
.btn-success:hover:not(:disabled) {
  background: #047857;
}

.btn-outline {
  background: #fff;
  color: var(--text-main);
  border-color: var(--border-ui);
}
.btn-outline:hover:not(:disabled) {
  background: #f8fafc;
  border-color: #cbd5e1;
}

.btn-danger-outline {
  background: #fff;
  color: var(--danger);
  border-color: #fecaca;
}
.btn-danger-outline:hover:not(:disabled) {
  background: #fef2f2;
}

.btn-sm {
  padding: 6px 11px;
  font-size: 12.5px;
  border-radius: 7px;
}

.pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
}

.pill-blue { background: #e0f2fe; color: #0369a1; }
.pill-green { background: #dcfce7; color: #15803d; }
.pill-amber { background: #fef3c7; color: #b45309; }
.pill-slate { background: #e2e8f0; color: #334155; }
.pill-red { background: #fee2e2; color: #b91c1c; }

/* ==================== CARDS & FORMS ==================== */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border-ui);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  margin-bottom: 18px;
  overflow: hidden;
}

.card-header {
  padding: 14px 18px;
  background: #f8fafc;
  border-bottom: 1px solid var(--border-ui);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.card-header h3 {
  margin: 0;
  font-size: 15.5px;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 8px;
}

.card-header.card-header-shipto {
  background: linear-gradient(90deg, #fffbeb 0%, #fef3c7 100%);
  border-bottom-color: #fde68a;
}

.card-header.card-header-map {
  background: linear-gradient(90deg, #ecfdf5 0%, #d1fae5 100%);
  border-bottom-color: #a7f3d0;
}

.card-body {
  padding: 18px;
}

.card.card-overflow-visible {
  overflow: visible;
}

/* ==================== SEARCHABLE BRANCH PICKER ==================== */
.branch-picker {
  position: relative;
  width: 100%;
}

.bp-trigger {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  min-height: 40px;
  padding: 7px 12px;
  border: 1px solid #cbd5e1;
  border-radius: 8px;
  background: #ffffff;
  color: var(--text-light);
  font-size: 14px;
  cursor: pointer;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.bp-trigger:hover {
  border-color: var(--cp-blue);
  background: #f8fbff;
}

.branch-picker.open .bp-trigger,
.bp-trigger:focus {
  outline: none;
  border-color: var(--cp-blue);
  box-shadow: 0 0 0 3px rgba(27, 94, 145, 0.14);
}

.bp-trigger.has-value {
  color: var(--text-main);
}

.bp-trigger-icon {
  font-size: 15px;
  flex-shrink: 0;
}

.bp-trigger-text {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  display: inline-flex;
  align-items: center;
  gap: 7px;
}

.bp-code-pill {
  display: inline-block;
  background: var(--cp-blue);
  color: #fff;
  font-size: 12px;
  font-weight: 700;
  padding: 1px 7px;
  border-radius: 5px;
  letter-spacing: 0.3px;
}

.bp-caret {
  color: var(--text-muted);
  font-size: 13px;
  transition: transform 0.15s ease;
}

.branch-picker.open .bp-caret {
  transform: rotate(180deg);
}

.bp-dropdown {
  position: absolute;
  top: calc(100% + 5px);
  left: 0;
  right: 0;
  z-index: 120;
  background: #ffffff;
  border: 1.5px solid var(--cp-blue);
  border-radius: 10px;
  box-shadow: 0 14px 34px rgba(15, 23, 42, 0.18);
  overflow: hidden;
}

.bp-search-wrap {
  position: relative;
  padding: 8px 10px;
  background: #f8fafc;
  border-bottom: 1px solid #e2e8f0;
  display: flex;
  align-items: center;
}

.bp-search-ico {
  position: absolute;
  left: 19px;
  font-size: 14px;
  color: var(--text-light);
  pointer-events: none;
}

.bp-search-input {
  width: 100%;
  padding: 7px 30px 7px 32px !important;
  font-size: 13.5px !important;
  border-radius: 7px !important;
  border: 1px solid #cbd5e1 !important;
  background: #fff !important;
}

.bp-clear-btn {
  position: absolute;
  right: 16px;
  border: none;
  background: transparent;
  color: var(--text-light);
  cursor: pointer;
  font-size: 13px;
  padding: 2px 5px;
  border-radius: 4px;
}

.bp-clear-btn:hover {
  background: #e2e8f0;
  color: var(--text-main);
}

.bp-count-bar {
  padding: 5px 12px;
  font-size: 11.5px;
  color: var(--text-light);
  background: #f1f5f9;
  border-bottom: 1px solid #e2e8f0;
}

.bp-list {
  max-height: 270px;
  overflow-y: auto;
}

.bp-option {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  cursor: pointer;
  font-size: 13.5px;
  border-bottom: 1px solid #f1f5f9;
  transition: background 0.1s ease;
}

.bp-option:hover,
.bp-option.focused {
  background: var(--cp-blue-soft);
}

.bp-option.selected {
  background: #dbeafe;
  font-weight: 700;
}

.bp-opt-code {
  display: inline-block;
  min-width: 38px;
  text-align: center;
  font-weight: 700;
  font-size: 12.5px;
  padding: 2px 6px;
  border-radius: 5px;
  background: #e2e8f0;
  color: #1e293b;
}

.bp-option.selected .bp-opt-code {
  background: var(--cp-blue);
  color: #fff;
}

.bp-opt-name {
  flex: 1;
  color: var(--text-main);
}

.bp-opt-check {
  color: var(--cp-blue);
  font-weight: 800;
}

.bp-empty {
  padding: 18px 12px;
  text-align: center;
  color: var(--text-light);
  font-size: 13px;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(12, 1fr);
  gap: 14px;
}

.col-12 { grid-column: span 12; }
.col-8 { grid-column: span 8; }
.col-6 { grid-column: span 6; }
.col-4 { grid-column: span 4; }
.col-3 { grid-column: span 3; }

.field-group {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.field-group label {
  font-size: 13px;
  font-weight: 600;
  color: #334155;
}

.field-group .hint {
  font-size: 11.5px;
  color: var(--text-light);
}

input[type="text"],
input[type="date"],
input[type="number"],
input[type="url"],
select,
textarea {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid #cbd5e1;
  border-radius: 8px;
  font-family: inherit;
  font-size: 14px;
  color: var(--text-main);
  background: #fff;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--cp-blue);
  box-shadow: 0 0 0 3px rgba(27, 94, 145, 0.14);
}

textarea {
  resize: vertical;
  min-height: 70px;
}

.check-row {
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  align-items: center;
}

.check-label {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font-size: 13.5px;
  cursor: pointer;
  user-select: none;
  padding: 5px 10px;
  border-radius: 8px;
  border: 1px solid #e2e8f0;
  background: #f8fafc;
}

.check-label:hover {
  border-color: var(--cp-blue);
  background: var(--cp-blue-soft);
}

.check-label input[type="checkbox"],
.check-label input[type="radio"] {
  width: 16px;
  height: 16px;
  accent-color: var(--cp-blue);
  cursor: pointer;
}

.section-toggle {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  font-weight: 700;
  font-size: 15px;
}

.section-toggle input[type="checkbox"] {
  width: 18px;
  height: 18px;
  accent-color: var(--cp-blue);
}

/* ==================== DASHBOARD ==================== */
.stats-row {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 14px;
  margin-bottom: 20px;
}

.stat-card {
  background: #fff;
  border: 1px solid var(--border-ui);
  border-radius: var(--radius);
  padding: 16px 18px;
  box-shadow: var(--shadow-sm);
}

.stat-card .stat-label {
  font-size: 12.5px;
  color: var(--text-muted);
  font-weight: 600;
}

.stat-card .stat-value {
  font-size: 28px;
  font-weight: 800;
  color: var(--cp-blue-dark);
  margin-top: 4px;
}

.stat-card .stat-value.stat-version {
  font-size: 20px;
  padding-top: 6px;
}

/* Quick-Launch Form Portal Grid */
.quick-forms-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
}

.qf-card {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 14px;
  border: 1.5px solid #e2e8f0;
  border-radius: 11px;
  background: #ffffff;
  text-align: left;
  cursor: pointer;
  font-family: inherit;
  transition: all 0.16s ease;
}

.qf-card:hover {
  border-color: var(--cp-blue);
  background: #f8fbff;
  transform: translateY(-1px);
  box-shadow: 0 6px 16px rgba(27, 94, 145, 0.1);
}

.qf-card.qf-highlight {
  border-color: #f59e0b;
  background: #fffdf5;
}

.qf-card.qf-highlight:hover {
  background: #fffbeb;
  box-shadow: 0 6px 16px rgba(217, 119, 6, 0.14);
}

.qf-icon {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 19px;
  flex-shrink: 0;
}

.qf-blue { background: #e0f2fe; }
.qf-green { background: #dcfce7; }
.qf-indigo { background: #e0e7ff; }
.qf-amber { background: #fef3c7; }
.qf-red { background: #fee2e2; }
.qf-slate { background: #e2e8f0; }
.qf-teal { background: #ccfbf1; }

.qf-info {
  min-width: 0;
}

.qf-title {
  font-size: 14px;
  font-weight: 700;
  color: var(--text-main);
  line-height: 1.3;
}

.qf-desc {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 3px;
  line-height: 1.35;
}

/* Mobile Document Cards (hidden on desktop) */
.mobile-cards-list {
  display: none;
  flex-direction: column;
  gap: 12px;
}

.doc-mobile-card {
  border: 1px solid var(--border-ui);
  border-radius: 11px;
  padding: 14px;
  background: #ffffff;
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.doc-mc-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-wrap: wrap;
}

.doc-mc-title {
  font-size: 15px;
  font-weight: 700;
  color: var(--text-main);
}

.doc-mc-meta {
  font-size: 12.5px;
  color: var(--text-muted);
  display: flex;
  flex-wrap: wrap;
  gap: 8px 14px;
}

.doc-mc-actions {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 7px;
  padding-top: 8px;
  border-top: 1px solid #f1f5f9;
}

/* Responsive A4 Scale Wrapper */
.preview-btn-group {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: center;
}

.a4-scale-outer {
  margin: 0 auto 22px auto;
  position: relative;
  overflow: hidden;
  border-radius: 2px;
  box-shadow: 0 10px 28px rgba(15, 23, 42, 0.22);
  background: #ffffff;
}

.a4-scale-outer:last-child {
  margin-bottom: 0;
}

.a4-scale-outer .official-a4-page {
  margin: 0;
  box-shadow: none;
  transform-origin: top left;
}

.dashboard-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
  flex-wrap: wrap;
}

.search-box {
  position: relative;
  flex: 1;
  min-width: 240px;
  max-width: 420px;
}

.search-box input {
  padding-left: 36px;
}

.search-box .search-ico {
  position: absolute;
  left: 11px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-light);
}

.table-wrap {
  overflow-x: auto;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13.5px;
}

.data-table th {
  text-align: left;
  padding: 11px 14px;
  background: #f8fafc;
  color: #334155;
  font-weight: 700;
  border-bottom: 1px solid var(--border-ui);
  white-space: nowrap;
}

.data-table td {
  padding: 12px 14px;
  border-bottom: 1px solid #edf2f7;
  vertical-align: middle;
}

.data-table tr:hover td {
  background: #f8fafc;
}

.action-btns {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

/* ==================== EDIT SHIP-TO & GOOGLE MAP ==================== */
.shipto-banner {
  background: linear-gradient(135deg, #0f2c47 0%, #1b5e91 100%);
  color: #fff;
  border-radius: var(--radius);
  padding: 18px 22px;
  margin-bottom: 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
}

.shipto-banner h3 {
  margin: 0 0 4px;
  font-size: 17px;
}

.shipto-banner p {
  margin: 0;
  font-size: 13px;
  color: rgba(255, 255, 255, 0.85);
}

.shipto-selector-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.shipto-selector-bar select {
  min-width: 280px;
  max-width: 380px;
  background: #fff;
  color: var(--text-main);
}

.shipto-item-card {
  border: 1.5px solid #e2e8f0;
  border-radius: 10px;
  padding: 16px;
  background: #fcfdff;
  margin-bottom: 14px;
}

.shipto-item-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
  padding-bottom: 8px;
  border-bottom: 1px dashed #cbd5e1;
}

.shipto-item-header h4 {
  margin: 0;
  font-size: 14.5px;
  color: var(--cp-blue-dark);
  display: flex;
  align-items: center;
  gap: 8px;
}

/* Google Map Upload Dropzone */
.map-dropzone {
  border: 2px dashed #10b981;
  background: #f0fdf4;
  border-radius: 12px;
  padding: 26px 20px;
  text-align: center;
  cursor: pointer;
  transition: all 0.18s ease;
}

.map-dropzone:hover,
.map-dropzone.dragover {
  background: #dcfce7;
  border-color: #059669;
  transform: translateY(-1px);
}

.map-dropzone .dz-icon {
  font-size: 34px;
  margin-bottom: 6px;
}

.map-dropzone .dz-title {
  font-size: 15px;
  font-weight: 700;
  color: #065f46;
}

.map-dropzone .dz-sub {
  font-size: 12.5px;
  color: #047857;
  margin-top: 4px;
}

.map-gallery {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 16px;
  margin-top: 16px;
}

.map-card {
  border: 1px solid #cbd5e1;
  border-radius: 10px;
  overflow: hidden;
  background: #fff;
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
}

.map-card-img-wrap {
  background: #f1f5f9;
  height: 200px;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  position: relative;
  border-bottom: 1px solid #e2e8f0;
}

.map-card-img-wrap img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.map-card-badge {
  position: absolute;
  top: 8px;
  left: 8px;
  background: rgba(15, 44, 71, 0.88);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  padding: 3px 8px;
  border-radius: 6px;
}

.map-card-body {
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.map-card-actions {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding-top: 6px;
  border-top: 1px solid #f1f5f9;
}

/* Auth table in Create Form (ข้อ 5) */
.auth-input-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.auth-input-table th, .auth-input-table td {
  border: 1px solid #dbe2ea;
  padding: 7px 8px;
  text-align: center;
}

.auth-input-table th {
  background: #f8fafc;
  font-weight: 700;
}

.auth-input-table input[type="text"] {
  padding: 5px 8px;
  font-size: 13px;
}

/* ==================== PREVIEW STAGE ==================== */
.preview-toolbar {
  background: #fff;
  border: 1px solid var(--border-ui);
  border-radius: var(--radius);
  padding: 14px 18px;
  margin-bottom: 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  flex-wrap: wrap;
  box-shadow: var(--shadow-sm);
}

.lock-notice {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 13.5px;
  color: #991b1b;
  background: #fef2f2;
  border: 1px solid #fecaca;
  padding: 8px 13px;
  border-radius: 8px;
  font-weight: 600;
}

.preview-stage {
  background: #cbd5e1;
  border-radius: var(--radius);
  padding: 24px 16px;
  overflow-x: auto;
  text-align: center;
}

/* =========================================================================
   OFFICIAL LOCKED A4 DOCUMENT — CP AXTRA "Change Customer Data Request - HO"
   DO NOT MODIFY TEMPLATE STRUCTURE (ห้ามแก้ไข)
   Exact A4 pixel canvas: 794px x 1123px (210mm x 297mm @ 96dpi)
   ========================================================================= */
.official-a4-page {
  width: 794px;
  height: 1123px;
  background: #ffffff;
  padding: 18px 26px 16px 26px;
  margin: 0 auto 24px auto;
  text-align: left;
  box-shadow: 0 12px 32px rgba(15, 23, 42, 0.25);
  color: #000000;
  font-family: 'Sarabun', 'Tahoma', 'Cordia New', sans-serif;
  font-size: 10.5px;
  line-height: 1.18;
  position: relative;
  flex-shrink: 0;
  user-select: none;
  -webkit-user-select: none;
  pointer-events: none; /* Locked: cannot edit directly in preview */
  overflow: hidden;
}

.official-a4-page:last-child {
  margin-bottom: 0;
}

.official-frame {
  width: 100%;
  height: 100%;
  border: 1.6px solid #000000;
  display: flex;
  flex-direction: column;
  background: #ffffff;
  overflow: hidden;
}

/* Header Area */
.of-header {
  padding: 4px 8px 5px 8px;
  border-bottom: 1.2px solid #000000;
  flex-shrink: 0;
}

.of-header-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 1px;
}

.of-logo-left {
  width: 116px;
  padding-top: 1px;
}

.of-company-title {
  flex: 1;
  text-align: center;
  font-size: 16px;
  font-weight: 700;
  letter-spacing: 0.2px;
  padding-top: 1px;
  color: #000;
}

.of-header-right {
  width: 196px;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
}

.of-logo-right {
  margin-bottom: 0;
  margin-right: 4px;
}

.of-meta-line {
  width: 100%;
  display: flex;
  align-items: baseline;
  justify-content: flex-end;
  font-size: 9.8px;
  margin-top: 0;
}

.of-meta-line .of-label {
  white-space: nowrap;
  margin-right: 4px;
}

.of-header-bottom {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 3px;
  padding: 0 2px;
}

.of-branch-group {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 10px;
  font-weight: 700;
}

.of-char-boxes {
  display: inline-flex;
  align-items: stretch;
}

.of-char-box {
  width: 20px;
  height: 20px;
  border: 1px solid #000;
  border-right: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 11.5px;
  font-weight: 700;
  color: #0b2d52;
  background: #fff;
}

.of-char-box:last-child {
  border-right: 1px solid #000;
}

.of-char-box.of-char-box-compact {
  width: 15px;
  font-size: 10.5px;
}

.of-branch-name-box {
  width: 112px;
  height: 20px;
  border: 1px solid #000;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 9.8px;
  font-weight: 700;
  color: #0b2d52;
  padding: 0 4px;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.of-cv-group {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 10px;
  font-weight: 700;
}

.of-cv-boxes .of-char-box {
  width: 20px;
  height: 20px;
}

/* Gray Title / Section Bars */
.of-gray-bar {
  background: #d9d9d9;
  border-bottom: 1px solid #000000;
  padding: 2px 8px;
  display: flex;
  align-items: center;
  font-size: 10.5px;
  min-height: 19px;
  flex-shrink: 0;
}

.of-title-bar {
  justify-content: space-between;
  padding: 2px 10px;
  min-height: 21px;
}

.of-title-bar .of-form-name {
  flex: 1;
  text-align: center;
  font-size: 12px;
  font-weight: 700;
  padding-left: 88px;
}

.of-type-checks {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 9.8px;
  white-space: nowrap;
}

.of-sec-center {
  justify-content: center;
  font-weight: 700;
  font-size: 10.5px;
  min-height: 18px;
}

.of-item-bar {
  gap: 7px;
  min-height: 19px;
  padding: 1.5px 6px;
}

.of-item-num {
  font-weight: 700;
  min-width: 21px;
}

.of-item-title {
  font-size: 10px;
}

.of-underline {
  text-decoration: underline;
  font-weight: 600;
}

/* Official Checkbox (matches form template) */
.of-cb {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 12px;
  height: 12px;
  border: 1px solid #000;
  box-shadow: 1px 1px 0 rgba(0, 0, 0, 0.35);
  background: #fff;
  font-size: 10px;
  font-weight: 900;
  line-height: 1;
  color: #000;
  flex-shrink: 0;
  vertical-align: middle;
}

.of-cb-inline {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  white-space: nowrap;
}

/* Official Dotted Fill Line */
.of-dotted {
  display: inline-block;
  border-bottom: 1px dotted #444;
  min-height: 13px;
  padding: 0 3px;
  color: #0b2d52;
  font-weight: 600;
  font-size: 10px;
  line-height: 1.1;
  vertical-align: baseline;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.of-solid-line {
  display: inline-block;
  border-bottom: 1px dashed #333;
  min-height: 13px;
  padding: 0 3px;
  color: #0b2d52;
  font-weight: 600;
  font-size: 9.8px;
  line-height: 1.1;
  text-align: center;
}

/* Body Sections */
.of-body-block {
  padding: 3px 10px 3.5px 16px;
  border-bottom: 1px solid #000;
  font-size: 9.6px;
  flex-shrink: 0;
}

.of-row {
  display: flex;
  align-items: baseline;
  gap: 5px;
  margin-bottom: 2.5px;
}

.of-row:last-child {
  margin-bottom: 0;
}

.of-row-nowrap {
  white-space: nowrap;
}

.of-doc-row {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-top: 3px;
  font-size: 9.4px;
  flex-wrap: nowrap;
}

/* ข้อ 5 Authority Matrix */
.of-auth-grid {
  width: 100%;
  border-collapse: collapse;
  font-size: 8.9px;
  margin-bottom: 2px;
}

.of-auth-grid th {
  font-weight: 600;
  padding: 1px 2px 2px;
  text-align: center;
  white-space: nowrap;
}

.of-auth-grid td {
  padding: 1.5px 2px;
  vertical-align: middle;
  text-align: center;
}

.of-auth-grid td.of-auth-name {
  text-align: left;
  padding: 1px 5px 1px 3px;
  width: 22%;
}

.of-auth-grid td.of-auth-name .of-dotted {
  width: 100%;
  font-size: 9.2px;
}

/* ข้อ 6 Accounting Table */
.of-acc-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 9.6px;
  flex-shrink: 0;
}

.of-acc-table th {
  background: #d9d9d9;
  border-bottom: 1px solid #000;
  border-right: 1px solid #000;
  padding: 2px 6px;
  text-align: center;
  font-weight: 600;
}

.of-acc-table th:last-child,
.of-acc-table td:last-child {
  border-right: none;
}

.of-acc-table td {
  border-bottom: 1px solid #000;
  border-right: 1px solid #000;
  padding: 1.5px 7px;
  height: 17px;
  vertical-align: middle;
}

.of-acc-table td.of-acc-detail {
  color: #0b2d52;
  font-weight: 600;
  font-size: 9.6px;
}

/* Customer Signature Area */
.of-cust-sig {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 5px 32px 5px 136px;
  border-bottom: 1.2px solid #000;
  min-height: 76px;
  flex-shrink: 0;
}

.of-stamp-circle {
  width: 66px;
  height: 66px;
  border: 1px solid #000;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  font-size: 9.5px;
  color: #000;
  flex-shrink: 0;
}

.of-sig-right {
  width: 315px;
  font-size: 9.6px;
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.of-sig-line-row {
  display: flex;
  align-items: baseline;
  gap: 4px;
}

/* Bottom 3-Column Approval Table */
.of-approval-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 9.4px;
  flex: 1;
  table-layout: fixed;
}

.of-approval-table th {
  border-bottom: 1px solid #000;
  border-right: 1px solid #000;
  padding: 3px 6px;
  text-align: center;
  font-weight: 600;
  height: 21px;
}

.of-approval-table th:last-child,
.of-approval-table td:last-child {
  border-right: none;
}

.of-approval-table td {
  border-bottom: 1px solid #000;
  border-right: 1px solid #000;
  vertical-align: top;
  padding: 0;
}

.of-app-cell-full {
  height: 100%;
  padding: 10px 10px 4px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  min-height: 86px;
}

.of-app-sub {
  padding: 7px 12px 4px 10px;
  min-height: 43px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}

.of-app-sub + .of-app-sub {
  border-top: 1px solid #000;
}

.of-app-date-cell {
  text-align: center;
  padding: 2px 6px !important;
  height: 20px;
  vertical-align: middle !important;
}

/* Official Footer */
.of-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 2px 10px;
  font-size: 9px;
  color: #111;
  height: 18px;
  flex-shrink: 0;
  background: #fff;
}

/* ==================== PAGE 2+: GOOGLE MAP ATTACHMENT ==================== */
.of-map-content {
  flex: 1;
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  overflow: hidden;
}

.of-map-summary-box {
  border: 1px solid #000;
  padding: 7px 10px;
  font-size: 10.5px;
  background: #fafafa;
}

.of-map-summary-box .row-line {
  display: flex;
  gap: 8px;
  margin-bottom: 3px;
}

.of-map-summary-box .row-line:last-child {
  margin-bottom: 0;
}

.of-map-grid {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-height: 0;
}

.of-map-frame {
  flex: 1;
  border: 1.2px solid #000;
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
}

.of-map-frame-head {
  background: #e5e7eb;
  border-bottom: 1px solid #000;
  padding: 4px 10px;
  font-size: 10.5px;
  font-weight: 700;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.of-map-frame-img {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #fff;
  padding: 8px;
  min-height: 0;
  overflow: hidden;
}

.of-map-frame-img img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  display: block;
}

.of-map-frame-foot {
  border-top: 1px solid #ccc;
  padding: 4px 10px;
  font-size: 9.8px;
  background: #fcfcfc;
  color: #111;
}

/* ==================== TOAST & MODAL ==================== */
.toast {
  position: fixed;
  bottom: 22px;
  right: 22px;
  background: #0f172a;
  color: #fff;
  padding: 12px 18px;
  border-radius: 10px;
  font-size: 13.5px;
  font-weight: 600;
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.24);
  z-index: 9999;
  opacity: 0;
  transform: translateY(12px);
  pointer-events: none;
  transition: all 0.2s ease;
}

.toast.show {
  opacity: 1;
  transform: translateY(0);
}

.toast.toast-success { background: #065f46; }
.toast.toast-error { background: #991b1b; }

/* ==================== RESPONSIVE (DESKTOP / TABLET / MOBILE) ==================== */
@media (max-width: 1120px) {
  .quick-forms-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media (max-width: 1024px) {
  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: 282px;
    max-width: 85vw;
    height: 100vh;
    z-index: 100;
    transform: translateX(-105%);
    transition: transform 0.22s cubic-bezier(0.22, 1, 0.36, 1);
  }

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

  .mobile-menu-btn {
    display: inline-flex;
  }

  .drawer-close-btn {
    display: inline-flex;
  }

  .topbar {
    padding: 10px 16px;
  }

  .view-container {
    padding: 16px 16px 40px;
  }

  .stats-row {
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
  }

  .col-3, .col-4 {
    grid-column: span 6;
  }
  .col-8 {
    grid-column: span 12;
  }
}

@media (max-width: 768px) {
  .desktop-table-only {
    display: none;
  }

  .mobile-cards-list {
    display: flex;
  }

  .topbar-actions {
    display: none;
  }

  .topbar-title-wrap h2 {
    font-size: 16px;
  }

  .topbar-title-wrap p {
    display: none;
  }

  .quick-forms-grid {
    grid-template-columns: 1fr;
    gap: 10px;
  }

  .card-header {
    padding: 12px 14px;
    flex-wrap: wrap;
  }

  .card-body {
    padding: 14px;
  }

  .shipto-banner {
    padding: 14px 16px;
  }

  .shipto-selector-bar {
    width: 100%;
  }

  .shipto-selector-bar select {
    min-width: 0;
    max-width: none;
    width: 100%;
  }

  .preview-toolbar {
    padding: 12px 14px;
  }

  .preview-btn-group {
    width: 100%;
  }

  .preview-btn-group .btn {
    flex: 1 1 auto;
  }

  .preview-stage {
    padding: 14px 8px;
  }

  .map-gallery {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 640px) {
  .view-container {
    padding: 12px 10px 36px;
  }

  .stats-row {
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
  }

  .stat-card {
    padding: 12px 14px;
  }

  .stat-card .stat-value {
    font-size: 22px;
  }

  .form-grid {
    gap: 11px;
  }

  .form-grid > .field-group {
    grid-column: span 12 !important;
  }

  input[type="text"],
  input[type="date"],
  input[type="number"],
  input[type="url"],
  select,
  textarea {
    font-size: 16px;
    min-height: 42px;
  }

  .check-row {
    gap: 8px;
  }

  .check-label {
    font-size: 13px;
    padding: 7px 10px;
  }

  .toast {
    left: 12px;
    right: 12px;
    bottom: 14px;
    text-align: center;
  }
}

/* ==================== PRINT / LOCKED A4 OUTPUT ==================== */
@page {
  size: A4 portrait;
  margin: 0;
}

@media print {
  html, body {
    background: #fff !important;
    margin: 0 !important;
    padding: 0 !important;
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
  }

  .sidebar,
  .sidebar-backdrop,
  .topbar,
  .preview-toolbar,
  #view-dashboard,
  #view-create,
  #view-shipto,
  #view-suite-editor,
  #view-share,
  .toast {
    display: none !important;
  }

  .main-content,
  .view-container,
  #view-preview {
    display: block !important;
    padding: 0 !important;
    margin: 0 !important;
    max-width: none !important;
  }

  .preview-stage {
    background: #fff !important;
    padding: 0 !important;
    gap: 0 !important;
    overflow: visible !important;
  }

  .a4-scale-outer {
    width: 794px !important;
    height: 1123px !important;
    margin: 0 !important;
    page-break-after: always;
    break-after: page;
  }

  .a4-scale-outer:last-child {
    page-break-after: auto;
    break-after: auto;
  }

  .official-a4-page {
    transform: none !important;
    box-shadow: none !important;
    margin: 0 !important;
    page-break-after: always;
    break-after: page;
  }

  .official-a4-page:last-child {
    page-break-after: auto;
    break-after: auto;
  }
}
