/* assets/css/app.css */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #f1f5f9;
  --surface: #ffffff;
  --border: #e2e8f0;
  --text: #0f172a;
  --muted: #64748b;
  --primary: #2563eb;
  --primary-fg: #ffffff;
  --secondary: #f8fafc;
  --radius: 8px;
  --shadow: 0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.06);
  --shadow-md: 0 4px 6px rgba(0,0,0,.07), 0 2px 4px rgba(0,0,0,.06);
}

body { font-family: system-ui,-apple-system,sans-serif; background: var(--bg); color: var(--text); min-height: 100vh; font-size: 15px; }

/* ---------- Layout ---------- */
#app { min-height: 100vh; }
.page { display: none; }
.page.active { display: block; }

.container { max-width: 1280px; margin: 0 auto; padding: 0 16px; }

header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 100;
  box-shadow: var(--shadow);
}
.header-inner { padding: 12px 16px; display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.brand { display: flex; align-items: center; gap: 10px; }
.brand-icon { width: 36px; height: 36px; border-radius: 8px; background: var(--primary); color: #fff; display: grid; place-items: center; flex-shrink: 0; }
.brand-icon svg { width: 20px; height: 20px; }
.brand-name { font-weight: 700; font-size: 16px; }
.brand-sub { font-size: 12px; color: var(--muted); }
.header-right { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }

main { max-width: 1280px; margin: 0 auto; padding: 24px 16px; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 14px; border-radius: var(--radius);
  border: 1px solid transparent; cursor: pointer;
  font-size: 14px; font-weight: 500; text-decoration: none;
  transition: background .15s, opacity .15s; white-space: nowrap;
  line-height: 1.4;
}
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn svg { width: 15px; height: 15px; flex-shrink: 0; }

.btn-primary   { background: var(--primary); color: var(--primary-fg); border-color: var(--primary); }
.btn-primary:hover:not(:disabled) { background: #1d4ed8; }
.btn-secondary { background: var(--secondary); color: var(--text); border-color: var(--border); }
.btn-secondary:hover:not(:disabled) { background: #f1f5f9; }
.btn-ghost     { background: transparent; color: var(--text); border-color: transparent; }
.btn-ghost:hover:not(:disabled) { background: var(--secondary); }
.btn-danger    { background: #dc2626; color: #fff; border-color: #dc2626; }
.btn-danger:hover:not(:disabled) { background: #b91c1c; }
.btn-outline   { background: transparent; color: var(--text); border-color: var(--border); }
.btn-outline:hover:not(:disabled) { background: var(--secondary); }
.btn-sm { padding: 5px 10px; font-size: 13px; }
.btn-xs { padding: 3px 8px; font-size: 12px; }
.btn-icon { padding: 7px; }

/* ---------- Forms ---------- */
.form-group { display: flex; flex-direction: column; gap: 5px; }
.form-label { font-size: 13px; font-weight: 500; color: var(--text); }
.form-input, .form-select, .form-textarea {
  padding: 8px 12px; border: 1px solid var(--border); border-radius: var(--radius);
  font-size: 14px; width: 100%; background: var(--surface); color: var(--text);
  transition: border-color .15s;
}
.form-input:focus, .form-select:focus, .form-textarea:focus {
  outline: none; border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37,99,235,.12);
}
.form-textarea { resize: vertical; min-height: 60px; }
.form-grid { display: grid; gap: 12px; }
.form-grid-2 { grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); }
.form-grid-3 { grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); }
.col-span-2 { grid-column: 1 / -1; }

/* ---------- Cards ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.card-header { padding: 14px 16px; border-bottom: 1px solid var(--border); }
.card-title { font-weight: 600; font-size: 15px; display: flex; align-items: center; gap: 6px; }
.card-body { padding: 16px; }

/* ---------- Badges ---------- */
.badge {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 2px 8px; border-radius: 99px; font-size: 12px;
  font-weight: 500; border: 1px solid transparent;
}
.badge-dot { width: 6px; height: 6px; border-radius: 50%; flex-shrink: 0; }
.badge-pending   { background: #fef3c7; color: #92400e; border-color: #fde68a; }
.badge-pending .badge-dot { background: #f59e0b; }
.badge-in_production { background: #dbeafe; color: #1e3a8a; border-color: #bfdbfe; }
.badge-in_production .badge-dot { background: #3b82f6; }
.badge-ready     { background: #d1fae5; color: #064e3b; border-color: #a7f3d0; }
.badge-ready .badge-dot { background: #10b981; }
.badge-dispatched { background: #f1f5f9; color: #475569; border-color: #cbd5e1; }
.badge-dispatched .badge-dot { background: #64748b; }
.badge-closed    { background: #fee2e2; color: #7f1d1d; border-color: #fecaca; }
.badge-closed .badge-dot { background: #ef4444; }
.badge-role      { background: #f8fafc; color: var(--text); border-color: var(--border); }
.badge-no-role   { background: transparent; color: var(--muted); border-color: var(--border); }

/* ---------- Tabs ---------- */
.tabs-list {
  display: flex; gap: 4px; flex-wrap: wrap; padding: 4px;
  background: var(--secondary); border: 1px solid var(--border);
  border-radius: calc(var(--radius) + 2px); margin-bottom: 16px;
}
.tab-btn {
  padding: 6px 14px; border-radius: 6px; border: none; cursor: pointer;
  font-size: 13px; font-weight: 500; background: transparent; color: var(--muted);
  display: flex; align-items: center; gap: 5px; transition: all .15s;
}
.tab-btn:hover { background: var(--surface); color: var(--text); }
.tab-btn.active { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
.tab-panel { display: none; }
.tab-panel.active { display: block; }

/* ---------- PO Grid ---------- */
.po-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(340px, 1fr)); gap: 12px; margin-top: 16px; }
.po-card { padding: 14px; }
.po-card:hover { box-shadow: var(--shadow-md); }
.po-card-header { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; margin-bottom: 10px; }
.po-customer { font-weight: 600; font-size: 15px; }
.po-meta { font-size: 12px; color: var(--muted); display: flex; flex-wrap: wrap; gap: 8px; margin-top: 3px; }
.po-meta-item { display: flex; align-items: center; gap: 3px; }
.po-note { font-size: 12px; color: var(--muted); border-left: 2px solid var(--border); padding-left: 8px; margin-bottom: 8px; }

/* ---------- PO Items ---------- */
.item-row { border: 1px solid var(--border); border-radius: 6px; padding: 10px; background: var(--secondary); margin-bottom: 8px; }
.item-row:last-child { margin-bottom: 0; }
.item-row-header { display: flex; justify-content: space-between; align-items: flex-start; gap: 8px; margin-bottom: 6px; }
.item-name { font-weight: 500; font-size: 14px; }
.item-stats { font-size: 12px; color: var(--muted); display: flex; flex-wrap: wrap; gap: 6px; margin-top: 3px; }
.item-stats .pending { color: #b45309; font-weight: 600; }
.item-stats .ok { color: #065f46; }
.item-actions { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 8px; }
.item-note { font-size: 12px; color: var(--muted); border-left: 2px solid var(--border); padding-left: 8px; margin-top: 4px; font-style: italic; }
.closed-reason { font-size: 12px; background: #fee2e2; color: #7f1d1d; border: 1px solid #fecaca; border-radius: 4px; padding: 4px 8px; margin-top: 4px; }

/* Dispatch collapse */
.dispatch-list { margin-top: 8px; }
details > summary { cursor: pointer; font-size: 12px; color: var(--muted); display: inline-flex; align-items: center; gap: 4px; user-select: none; }
details > summary:hover { color: var(--text); }
.dispatch-entry { border: 1px solid var(--border); border-radius: 4px; padding: 6px 8px; background: var(--surface); margin-top: 4px; font-size: 12px; }
.dispatch-entry-row { display: flex; justify-content: space-between; }
.dispatch-entry .muted { color: var(--muted); }

/* ---------- Toolbar ---------- */
.toolbar { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 16px; }
.toolbar-left { display: flex; align-items: center; gap: 8px; flex: 1; min-width: 200px; max-width: 400px; }
.search-wrap { position: relative; flex: 1; }
.search-icon { position: absolute; left: 10px; top: 50%; transform: translateY(-50%); color: var(--muted); pointer-events: none; }
.search-wrap input { padding-left: 32px; }
.toolbar-right { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }

/* ---------- Stats bar ---------- */
.stats-bar { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 10px; margin-bottom: 16px; }
.stat-card { padding: 12px; }
.stat-label { font-size: 12px; color: var(--muted); }
.stat-value { font-size: 24px; font-weight: 700; margin-top: 2px; }
.stat-value.warn { color: #b45309; }

/* ---------- Table ---------- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th { text-align: left; padding: 8px 10px; border-bottom: 2px solid var(--border); color: var(--muted); font-weight: 600; font-size: 12px; white-space: nowrap; }
td { padding: 8px 10px; border-bottom: 1px solid var(--border); vertical-align: top; }
tr:last-child td { border-bottom: none; }
tr:hover td { background: var(--secondary); }

/* ---------- Modal ---------- */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,.45);
  display: flex; align-items: center; justify-content: center;
  z-index: 1000; padding: 16px;
}
.modal { background: var(--surface); border-radius: calc(var(--radius) + 4px); box-shadow: 0 20px 40px rgba(0,0,0,.2); width: 100%; max-width: 700px; max-height: 90vh; overflow-y: auto; }
.modal-sm { max-width: 440px; }
.modal-lg { max-width: 900px; }
.modal-header { padding: 16px 20px; border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; gap: 12px; position: sticky; top: 0; background: var(--surface); z-index: 1; }
.modal-title { font-weight: 600; font-size: 16px; }
.modal-body { padding: 20px; }
.modal-footer { padding: 14px 20px; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: 8px; }

/* ---------- Auth page ---------- */
.auth-page { min-height: 100vh; display: flex; align-items: center; justify-content: center; background: linear-gradient(135deg, #eff6ff 0%, #f8fafc 100%); padding: 24px; }
.auth-card { width: 100%; max-width: 420px; }
.auth-icon { width: 48px; height: 48px; background: var(--primary); color: #fff; border-radius: 12px; display: grid; place-items: center; margin: 0 auto 12px; }
.auth-icon svg { width: 24px; height: 24px; }
.auth-title { text-align: center; font-size: 22px; font-weight: 700; margin-bottom: 4px; }
.auth-sub { text-align: center; color: var(--muted); font-size: 14px; margin-bottom: 20px; }

/* ---------- Alert ---------- */
.alert { padding: 12px 14px; border-radius: var(--radius); border: 1px solid; font-size: 14px; display: flex; align-items: flex-start; gap: 8px; margin-bottom: 12px; }
.alert svg { width: 16px; height: 16px; flex-shrink: 0; margin-top: 1px; }
.alert-warn { background: #fef3c7; color: #92400e; border-color: #fde68a; }
.alert-error { background: #fee2e2; color: #7f1d1d; border-color: #fecaca; }
.alert-info { background: #dbeafe; color: #1e3a8a; border-color: #bfdbfe; }

/* ---------- Item block in modal ---------- */
.item-block { border: 1px solid var(--border); border-radius: var(--radius); padding: 12px; background: var(--secondary); }
.item-block-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.item-block-num { font-size: 12px; font-weight: 600; color: var(--muted); }

/* ---------- Empty state ---------- */
.empty { text-align: center; padding: 48px 16px; color: var(--muted); font-size: 14px; }

/* ---------- Spinner ---------- */
.spinner { display: inline-block; width: 20px; height: 20px; border: 2px solid rgba(255,255,255,.3); border-top-color: #fff; border-radius: 50%; animation: spin .7s linear infinite; }
.spinner-dark { border: 2px solid var(--border); border-top-color: var(--primary); }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Toast ---------- */
#toast-container { position: fixed; bottom: 20px; right: 20px; z-index: 9999; display: flex; flex-direction: column; gap: 8px; max-width: 360px; }
.toast { background: #1e293b; color: #f8fafc; padding: 12px 16px; border-radius: var(--radius); box-shadow: var(--shadow-md); font-size: 14px; display: flex; align-items: center; gap: 8px; animation: toastIn .2s ease; }
.toast.success { background: #065f46; }
.toast.error   { background: #7f1d1d; }
@keyframes toastIn { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }

/* ---------- Admin panel ---------- */
.user-row { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 10px; border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 14px; }
.user-info .name { font-weight: 500; }
.user-info .email { font-size: 12px; color: var(--muted); }
.role-buttons { display: flex; flex-wrap: wrap; gap: 6px; }

/* ---------- Bulk actions ---------- */
.bulk-bar { padding: 6px 0; border-bottom: 1px solid var(--border); margin-bottom: 8px; display: flex; gap: 8px; flex-wrap: wrap; }

/* ---------- Invoice summary ---------- */
.invoice-summary { display: flex; flex-wrap: wrap; gap: 10px; margin-bottom: 16px; }
.invoice-chip { background: var(--secondary); border: 1px solid var(--border); border-radius: 6px; padding: 6px 10px; font-size: 13px; }
.invoice-chip strong { display: block; font-size: 14px; }

/* ---------- Responsive ---------- */
@media (max-width: 640px) {
  .po-grid { grid-template-columns: 1fr; }
  .stats-bar { grid-template-columns: 1fr 1fr; }
  .tabs-list { gap: 2px; }
  .tab-btn { padding: 5px 10px; font-size: 12px; }
}

/* ── Item card: SRP-code primary heading ── */
.item-primary-line {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  margin-bottom: 2px;
}
.item-srp-heading {
  font-size: 15px;
  font-weight: 700;
  color: var(--text);
  letter-spacing: .01em;
}
.item-dim-tag {
  display: inline-block;
  font-size: 12px;
  font-weight: 600;
  color: var(--primary);
  background: color-mix(in srgb, var(--primary) 10%, transparent);
  border: 1px solid color-mix(in srgb, var(--primary) 25%, transparent);
  border-radius: 4px;
  padding: 1px 7px;
}
