/* TAI FAITH Sales Order Portal — mobile-first responsive */
:root {
  --navy: #1f4e79;
  --blue: #2e75b6;
  --bg: #f4f6f9;
  --card: #fff;
  --warn: #c00000;
  --ok: #006100;
  --entry: #fff2cc;
  --radius: 10px;
  --shadow: 0 2px 8px rgba(0,0,0,.08);
}

* { box-sizing: border-box; margin: 0; padding: 0; }
body {
  font-family: "Sarabun", "Noto Sans Thai", system-ui, sans-serif;
  background: var(--bg);
  color: #222;
  line-height: 1.5;
  min-height: 100vh;
}

header {
  background: var(--navy);
  color: #fff;
  padding: 12px 16px;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 100;
}
header h1 { font-size: 1.1rem; font-weight: 700; }
header .sub { font-size: .75rem; opacity: .85; }
.role-bar { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.role-bar select, .role-bar input {
  padding: 6px 10px;
  border-radius: 6px;
  border: none;
  font-size: .85rem;
}

main { max-width: 960px; margin: 0 auto; padding: 12px; }

.tabs { display: flex; gap: 4px; margin-bottom: 12px; overflow-x: auto; }
.tab {
  padding: 8px 14px;
  border: none;
  background: #dde5ed;
  border-radius: var(--radius) var(--radius) 0 0;
  cursor: pointer;
  white-space: nowrap;
  font-size: .9rem;
}
.tab.active { background: var(--card); font-weight: 700; color: var(--navy); }

.panel { display: none; background: var(--card); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); }
.panel.active { display: block; }

.card { background: var(--card); border-radius: var(--radius); padding: 14px; margin-bottom: 12px; box-shadow: var(--shadow); }
.card h2 { font-size: 1rem; color: var(--navy); margin-bottom: 10px; }

label { display: block; font-size: .8rem; color: #555; margin-bottom: 4px; }
input, select, textarea {
  width: 100%;
  padding: 10px;
  border: 1px solid #ccc;
  border-radius: 6px;
  font-size: .95rem;
  margin-bottom: 10px;
}
textarea { min-height: 60px; resize: vertical; }

.grid-2 { display: grid; grid-template-columns: 1fr; gap: 10px; }
@media (min-width: 640px) { .grid-2 { grid-template-columns: 1fr 1fr; } }

.search-results { max-height: 200px; overflow-y: auto; border: 1px solid #ddd; border-radius: 6px; }
.search-item {
  padding: 10px;
  border-bottom: 1px solid #eee;
  cursor: pointer;
}
.search-item:hover, .search-item.selected { background: var(--entry); }
.search-item small { color: #666; display: block; }

.product-preview {
  display: flex; gap: 12px; align-items: flex-start; flex-wrap: wrap;
  background: #f9fafb; padding: 12px; border-radius: 8px; margin-bottom: 10px;
}
.product-preview img {
  width: 80px; height: 80px; object-fit: contain;
  border: 1px solid #ddd; border-radius: 6px; background: #fff;
}
.product-preview .meta { flex: 1; min-width: 180px; }
.badge {
  display: inline-block; padding: 2px 8px; border-radius: 4px;
  font-size: .75rem; font-weight: 600;
}
.badge-warn { background: #fdecea; color: var(--warn); }
.badge-ok { background: #e6f4ea; color: var(--ok); }

.line-table { width: 100%; border-collapse: collapse; font-size: .85rem; margin: 10px 0; }
.line-table th { background: var(--navy); color: #fff; padding: 8px; text-align: left; }
.line-table td { padding: 8px; border-bottom: 1px solid #eee; }
.line-table input { margin: 0; padding: 6px; }

.btn {
  padding: 10px 18px;
  border: none;
  border-radius: 8px;
  font-size: .95rem;
  font-weight: 600;
  cursor: pointer;
  margin: 4px 4px 4px 0;
}
.btn-primary { background: var(--blue); color: #fff; }
.btn-navy { background: var(--navy); color: #fff; }
.btn-warn { background: var(--warn); color: #fff; }
.btn-outline { background: #fff; border: 1px solid var(--navy); color: var(--navy); }
.btn:disabled { opacity: .5; cursor: not-allowed; }

.totals { text-align: right; font-size: .95rem; margin-top: 10px; }
.totals .grand { font-size: 1.2rem; font-weight: 700; color: var(--navy); }

.order-list .order-card {
  border-left: 4px solid var(--blue);
  padding: 12px;
  margin-bottom: 8px;
  background: #fafbfc;
  border-radius: 0 8px 8px 0;
  cursor: pointer;
}
.order-list .order-card:hover { background: var(--entry); }
.status { font-weight: 700; font-size: .8rem; }

.msg { padding: 10px; border-radius: 6px; margin: 8px 0; font-size: .9rem; }
.msg-error { background: #fdecea; color: var(--warn); }
.msg-ok { background: #e6f4ea; color: var(--ok); }
.msg-sticky { position: sticky; top: 56px; z-index: 90; }

.req { color: var(--warn); font-weight: 700; margin-left: 2px; }
.field-tag {
  display: inline-block; margin-left: 8px; font-size: .7rem; font-weight: 600;
  padding: 1px 6px; border-radius: 4px; vertical-align: middle;
}
.req-tag { background: #fdecea; color: var(--warn); }
.opt-tag { background: #eef2f6; color: #556; }
.field-error {
  color: var(--warn); font-size: .8rem; margin: -6px 0 10px; min-height: 1.1em;
}
.field-group.has-error input,
.field-group.has-error select,
.field-group.has-error textarea,
input.input-error, select.input-error, textarea.input-error {
  border-color: var(--warn) !important;
  box-shadow: 0 0 0 2px rgba(192, 0, 0, .12);
  background: #fff8f8;
}
.checkbox-row { display: flex; align-items: center; gap: 8px; margin: 6px 0 10px; }
.checkbox-row input { width: auto; margin: 0; }

.completeness-bar {
  display: flex; align-items: center; gap: 10px; margin-bottom: 12px;
  font-size: .85rem; color: #444;
}
.completeness-track {
  flex: 1; height: 8px; background: #dde5ed; border-radius: 99px; overflow: hidden;
}
.completeness-fill {
  height: 100%; width: 0; background: var(--blue); transition: width .25s ease;
}

.action-row { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }
.btn.is-loading { position: relative; pointer-events: none; opacity: .85; }

.modal {
  position: fixed; inset: 0; background: rgba(0,0,0,.45);
  display: flex; align-items: center; justify-content: center; z-index: 200; padding: 16px;
}
.modal[hidden] { display: none !important; }
.modal-card {
  background: #fff; border-radius: 12px; padding: 20px; max-width: 420px; width: 100%;
  box-shadow: var(--shadow);
}

.audit-item { font-size: .8rem; padding: 6px 0; border-bottom: 1px solid #eee; }

/* Order Center V1.3.2 */
.hint { font-size: .8rem; color: #666; margin: -4px 0 8px; }
.seg-group { display: flex; gap: 8px; margin-bottom: 12px; flex-wrap: nowrap; }
.seg-group.wrap { flex-wrap: wrap; }
.seg {
  flex: 1; min-width: 0; padding: 12px 10px; border: 2px solid #c5d0dc;
  background: #fff; border-radius: 10px; font-size: .9rem; font-weight: 600;
  cursor: pointer; color: #334;
}
.seg.active { border-color: var(--navy); background: #e8f0f8; color: var(--navy); }
.btn-lg { min-height: 48px; font-size: 1rem; padding: 14px 18px; }
.product-grid {
  display: grid; grid-template-columns: 1fr; gap: 10px;
  max-height: 360px; overflow-y: auto; margin-bottom: 10px;
}
.product-card {
  display: flex; gap: 12px; padding: 12px; border: 1px solid #e2e8f0;
  border-radius: 12px; background: #fafbfc; cursor: pointer;
}
.product-card:active, .product-card:hover { border-color: var(--blue); background: var(--entry); }
.product-card img, .product-card .ph {
  width: 72px; height: 72px; object-fit: contain; border-radius: 8px;
  background: #fff; border: 1px solid #ddd; flex-shrink: 0;
}
.product-card .ph { background: #eee; }
.pc-zh { font-weight: 700; font-size: .95rem; }
.pc-th { color: #555; font-size: .85rem; }
.pc-spec { color: #777; font-size: .75rem; margin: 2px 0; }
.pc-meta { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-top: 4px; }
.lines-cards { display: flex; flex-direction: column; gap: 8px; margin: 10px 0; }
.line-card {
  display: flex; justify-content: space-between; gap: 10px; align-items: center;
  padding: 12px; background: #f7f9fc; border-radius: 10px; border: 1px solid #e5eaf0;
}
.line-card-right { text-align: right; }
.desktop-only { display: none; }
.timeline { margin: 14px 0; }
.timeline h3 { font-size: .95rem; color: var(--navy); margin-bottom: 10px; }
.tl-track {
  display: flex; flex-direction: column; gap: 0; border-left: 3px solid #dde5ed;
  margin-left: 8px; padding-left: 14px;
}
.tl-step { position: relative; padding: 8px 0 8px 4px; opacity: .45; }
.tl-step.done, .tl-step.current { opacity: 1; }
.tl-dot {
  position: absolute; left: -22px; top: 12px; width: 12px; height: 12px;
  border-radius: 50%; background: #c5d0dc; border: 2px solid #fff;
}
.tl-step.done .tl-dot { background: var(--ok); }
.tl-step.current .tl-dot { background: var(--blue); box-shadow: 0 0 0 3px rgba(46,117,182,.25); }
.tl-step.rejected .tl-dot { background: var(--warn); }
.tl-label { font-size: .9rem; font-weight: 600; }
.print-row { display: flex; flex-wrap: wrap; gap: 8px; margin: 12px 0; }
.print-row .btn { flex: 1 1 40%; min-width: 120px; }
.company-profile .co-head { display: flex; gap: 12px; align-items: center; margin-bottom: 10px; }
.co-logo { height: 56px; object-fit: contain; }
.co-logo-ph {
  width: 96px; height: 56px; background: var(--navy); color: #fff;
  display: flex; align-items: center; justify-content: center; font-weight: 700; border-radius: 8px; font-size: .75rem;
}
.cust-create { margin-top: 10px; padding-top: 10px; border-top: 1px dashed #ccd; }
.detail-lines { margin: 10px 0; padding-left: 18px; }
.btn-icon { background: transparent; border: none; cursor: pointer; font-size: 1rem; padding: 6px 10px; }
.tabs { -webkit-overflow-scrolling: touch; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tab { flex: 1 0 auto; min-width: 72px; padding: 12px 10px; font-size: .85rem; }

@media (min-width: 640px) {
  .desktop-only { display: table; }
  .lines-cards { display: none; }
  .product-grid { grid-template-columns: 1fr 1fr; }
  .tl-track {
    flex-direction: row; border-left: none; margin-left: 0; padding-left: 0;
    overflow-x: auto; gap: 4px;
  }
  .tl-step { flex: 1; min-width: 72px; text-align: center; padding: 8px 4px; }
  .tl-dot { position: static; margin: 0 auto 6px; }
}

@media (max-width: 480px) {
  header h1 { font-size: .95rem; }
  .line-table { font-size: .75rem; }
  .btn { width: 100%; margin: 4px 0; }
  .action-row .btn { width: 100%; }
  .print-row .btn { flex: 1 1 100%; }
  main { padding: 8px; overflow-x: hidden; }
  .panel, .card { overflow-x: hidden; }
  input, select, textarea, .btn, .seg { font-size: 16px; } /* prevent iOS zoom */
}

