/* =========================================================
   ES Operation Process — styles.css (FINAL)
   - Clean layout for Web & Mobile
   - Color-coded group headers (Row 1) + sticky dual headers
   - Editable Sheet1 (inline edit mode)
   - Cloudflare sticky header fix (dynamic offset via --op_hdr_h)
   ========================================================= */

/* ---------- Base / Reset ---------- */
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", "Liberation Sans", sans-serif;
  color: #1f2937;
  background: #f7fafc;
}
h1, h2, h3 { margin: 0 0 .75rem; line-height: 1.25; }
p { margin: 0 0 .75rem; }
.muted { color:#6b7280; }

/* ---------- Layout ---------- */
.app-header {
  display:flex; align-items:center; justify-content:space-between;
  padding: 14px 16px; background:#111827; color:#fff;
  position: sticky; top:0; z-index:1000;
}
.app-header h1 { font-size: 18px; font-weight: 700; letter-spacing: .2px; }

.lang-switch { display:flex; gap:6px; }
.lang-switch button{
  border:1px solid #374151; background:#1f2937; color:#e5e7eb;
  padding:6px 10px; border-radius:8px; cursor:pointer;
}
.lang-switch button[aria-pressed="true"]{ background:#4f46e5; border-color:#4f46e5; color:#fff; }

.top-nav{
  display:flex; gap:8px; padding:10px 12px; background:#fff; border-bottom:1px solid #e5e7eb;
  position: sticky; top:56px; z-index: 999; overflow-x: auto;
}
.top-nav .nav-link{
  padding:8px 12px; border-radius:10px; border:1px solid #e5e7eb; background:#fff; color:#111827;
  cursor:pointer; font-weight:600; flex:0 0 auto;
}
.top-nav .nav-link.active{ background:#111827; color:#fff; border-color:#111827; }
.top-nav .nav-link:focus { outline:2px solid #4f46e5; outline-offset:2px; }

.page{ display:none; padding:16px; max-width:1400px; margin:0 auto; }
.page.active{ display:block; }

.card{
  background:#fff; border:1px solid #e5e7eb; border-radius:14px; padding:16px; margin-bottom:16px;
  box-shadow: 0 8px 22px rgba(0,0,0,.03);
}

/* ---------- Stats ---------- */
.stats-grid{
  display:grid; grid-template-columns: repeat(7, minmax(0,1fr)); gap:12px; margin-bottom:12px;
}
.stat-card{
  background:#f9fafb; border:1px solid #e5e7eb; border-radius:12px; padding:12px;
}
.stat-card .label{ color:#6b7280; font-size:12px; margin-bottom:6px; }
.stat-card .value{ font-size:24px; font-weight:800; }

/* ---------- Toolbar ---------- */
.toolbar{ display:flex; align-items:center; gap:8px; margin: 10px 0; }
.toolbar .spacer{ flex:1; }
input[type="search"], input[type="text"], input[type="date"], input[type="number"], select, textarea{
  width:100%; padding:8px 10px; border:1px solid #d1d5db; border-radius:10px; background:#fff;
}
textarea{ min-height: 96px; resize: vertical; }

.btn{
  display:inline-flex; align-items:center; justify-content:center; gap:6px;
  border:1px solid #d1d5db; background:#fff; color:#111827; padding:8px 12px; border-radius:10px;
  cursor:pointer; transition: all .15s ease;
}
.btn:hover{ transform: translateY(-1px); box-shadow:0 4px 10px rgba(0,0,0,.06); }
.btn:active{ transform: translateY(0); }
.btn-primary{ background:#4f46e5; border-color:#4f46e5; color:#fff; }
.btn-primary:hover{ filter: brightness(1.05); }

/* Enable Edit toggle */
.toggle-edit{ display:inline-flex; align-items:center; gap:8px; padding:6px 10px; border:1px dashed #cbd5e1; border-radius:10px; background:#f8fafc; }
.toggle-edit input{ accent-color:#4f46e5; }

/* ---------- Forms ---------- */
.form-grid{
  display:grid; grid-template-columns: repeat(3, minmax(0,1fr)); gap:12px;
}
.form-grid > div label{ display:block; font-weight:700; margin-bottom:6px; }
.form-actions{ display:flex; justify-content:flex-end; gap:8px; margin-top:8px; }

/* ---------- Tables ---------- */
.table-container{ width:100%; overflow:auto; -webkit-overflow-scrolling:touch; }
table{ width:100%; border-collapse: separate; border-spacing:0; background:#fff; }
thead th, tbody td{ border:1px solid #e5e7eb; padding:8px 10px; text-align:left; vertical-align:top; }

/* Zebra rows */
tbody tr:nth-child(even) td{ background:#fcfcfd; }

/* ---- Sticky dual headers (group header row + column header row) ---- */
:root { --op_hdr_h: 36px; } /* will be updated by JS (adjustStickyOffsets) */

thead .group-header th{
  position: sticky;
  top: 0;
  z-index: 6;
  white-space: nowrap;    /* keep single-line height for Cloudflare Burmese wrap */
  line-height: 1.2;
  height: 36px;
  font-weight: 700;
  color:#111827;
}

thead .col-header th{
  position: sticky;
  top: var(--op_hdr_h, 36px);
  z-index: 7;
  background:#f3f4f6;
  font-weight:800; color:#111827; letter-spacing:.2px;
}

/* ---- Group header color coding ---- */
.h-op   { background: #e5e7eb; }
.h-order{ background: linear-gradient(180deg, #dbeafe 0%, #bfdbfe 100%); }     /* blue */
.h-inv  { background: linear-gradient(180deg, #dcfce7 0%, #bbf7d0 100%); }     /* green */
.h-wh   { background: linear-gradient(180deg, #ffedd5 0%, #fed7aa 100%); }     /* orange */
.h-del  { background: linear-gradient(180deg, #ede9fe 0%, #ddd6fe 100%); }     /* purple */

/* Clickable cells (jump to forms when empty) */
td.goto-inventory, td.goto-warehouse, td.goto-delivery{ cursor:pointer; }
td.is-empty{ background: #fff7ed !important; }        /* soft warning bg */
td.is-empty:hover{ background:#ffedd5 !important; }   /* hover highlight */
td.link-cell a{ color:#2563eb; text-decoration: underline; }

/* ---- Read/Write visual (Sheet1 inline edit) ---- */
table.editable tbody td{ background:#fffffb; }
table.editable tbody td:focus{ outline:2px solid #60a5fa; background:#eff6ff; }

/* ---------- Footer ---------- */
.app-footer{ padding: 16px; text-align:center; color:#6b7280; }

/* ---------- Toast ---------- */
#toast{
  position: fixed; left:50%; bottom:24px; transform:translateX(-50%);
  background:#111827; color:#fff; padding:10px 14px; border-radius:10px; opacity:0; pointer-events:none;
  transition: opacity .18s ease, transform .18s ease;
  box-shadow: 0 10px 30px rgba(0,0,0,.25); z-index:2000; max-width: 90%;
}
#toast.show{ opacity:1; transform:translateX(-50%) translateY(-4px); }

/* ---------- Responsive ---------- */
@media (max-width: 1024px){
  .stats-grid{ grid-template-columns: repeat(4, minmax(0,1fr)); }
}
@media (max-width: 768px){
  .page{ padding:12px; }
  .card{ border-radius:14px; padding:12px; }
  .form-grid{ grid-template-columns:1fr; gap:12px; }
  input, select, textarea, button{ font-size:16px; } /* prevent iOS zoom */
  .form-actions{
    position: sticky; bottom:0; background:#fff; padding:10px;
    border-top:1px solid #e5e7eb; margin-top:8px;
  }
  .stats-grid{ grid-template-columns: repeat(2, minmax(0,1fr)); }
  .stat-card .value{ font-size:20px; }

  .table-container{ overflow-x:auto; }
  table{ font-size:13px; min-width:960px; }
  /* Row1 can grow a bit on mobile → bump var & height */
  :root { --op_hdr_h: 42px; }
  thead .group-header th{ height: 42px; }
}

/* ---------- Utility ---------- */
.hidden{ display:none !important; }
.badge{
  display:inline-block; padding:2px 6px; border-radius:999px; font-size:11px; font-weight:700;
  background:#eef2ff; color:#3730a3; border:1px solid #c7d2fe;
}
.highlight{ background:#fef3c7; }
