/* Shared PO System styles & layout */
:root {
  --po-sidebar-w: 220px;
  --po-topbar-h: 56px;
}

/* Shared chip-tab styles (was inline in insights.html — promoted for reuse). */
.chip-tabs { display: flex; flex-wrap: wrap; gap: 0.4rem; margin-bottom: 1rem; }
.chip-tabs button {
  padding: 0.4rem 0.95rem;
  font-size: 0.78rem; font-weight: 700;
  background: var(--surface2); color: var(--text-dim);
  border: 1px solid var(--border);
  border-radius: 999px;
  cursor: pointer;
  transition: color 0.12s, border-color 0.12s, background 0.12s;
  letter-spacing: 0.01em;
}
.chip-tabs button:hover { color: var(--text); border-color: rgba(20,184,166,0.45); }
.chip-tabs button.active {
  color: #fff;
  background: var(--accent);
  border-color: var(--accent);
}
* { margin: 0; padding: 0; box-sizing: border-box; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  line-height: 1.5;
  min-height: 100vh;
}
a { color: inherit; text-decoration: none; }
button { font-family: inherit; }
input, select, textarea { font-family: inherit; color: inherit; }

/* Layout shell */
.app-shell { display: flex; min-height: 100vh; }
.sidebar {
  width: var(--po-sidebar-w);
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 1.25rem 0.85rem;
  position: fixed;
  inset: 0 auto 0 0;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  z-index: 10;
}
.sidebar-brand {
  display: flex; align-items: center; gap: 0.55rem;
  padding: 0.85rem 0.65rem 1.25rem;
  border-bottom: 1px solid var(--border);
  margin-bottom: 0.85rem;
  color: var(--text);            /* drives `currentColor` in the inline SVG */
  text-decoration: none;
  transition: opacity 0.12s;
}
.sidebar-brand:hover { opacity: 0.85; }
.sidebar-brand-mark {
  width: 39px; height: 39px;       /* +15% from 34px */
  flex-shrink: 0;
  display: block;
}
.sidebar-brand-mark .brand-stroke { stroke: currentColor; fill: none; }
.sidebar-brand-mark .brand-fill   { fill: currentColor; }
.sidebar-brand-mark .brand-focal  { fill: var(--accent); }
.sidebar-brand-mark .brand-dim    { fill: var(--text-dim); }
.sidebar-brand-text {
  font-size: 1.1rem; font-weight: 800;
  letter-spacing: -0.015em;
  line-height: 1;
}
.sidebar-brand-dot {
  color: var(--accent);
  font-weight: 900;
  font-size: 1.25em;
  line-height: 0;
  margin-left: 0.05em;
}
.sidebar-section {
  font-size: 0.6rem; font-weight: 700;
  text-transform: uppercase; letter-spacing: 0.6px;
  color: var(--text-dim);
  padding: 0.65rem 0.6rem 0.35rem;
}
.sidebar-link {
  display: flex; align-items: center; gap: 0.6rem;
  padding: 0.5rem 0.6rem;
  font-size: 0.82rem; font-weight: 600;
  color: var(--text-dim);
  border-radius: 6px;
  transition: all 0.12s;
  cursor: pointer;
}
.sidebar-link:hover { color: var(--text); background: var(--hover-link); }
.sidebar-link.active { color: var(--text); background: var(--active-link); }
.sidebar-link-icon {
  width: 18px; height: 18px; flex-shrink: 0;
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 0.85rem;
}
.sidebar-link-badge {
  margin-left: auto;
  background: var(--accent-faint);
  color: var(--text);
  font-size: 0.65rem;
  font-weight: 800;
  padding: 0.05rem 0.4rem;
  border-radius: 10px;
}
/* When a workflow link has fresh items waiting, the badge throbs with an
   expanding teal halo so it earns the eye without being loud. */
.sidebar-link-badge.throb {
  background: var(--accent);
  color: #fff;
  animation: sidebar-badge-throb 1.6s ease-out infinite;
}
@keyframes sidebar-badge-throb {
  0%   { box-shadow: 0 0 0 0 rgba(20,184,166,0.65); }
  70%  { box-shadow: 0 0 0 8px rgba(20,184,166,0); }
  100% { box-shadow: 0 0 0 0 rgba(20,184,166,0); }
}

/* Main area */
.main-area {
  margin-left: var(--po-sidebar-w);
  flex: 1;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}
.topbar {
  height: var(--po-topbar-h);
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  padding: 0 1.5rem;
  display: flex; align-items: center; justify-content: space-between;
  position: sticky; top: 0; z-index: 5;
}
.topbar-crumbs {
  display: flex; align-items: center; gap: 0.5rem;
  font-size: 0.82rem; color: var(--text-dim);
}
.topbar-crumbs a { color: var(--text-dim); }
.topbar-crumbs a:hover { color: var(--text); }
.topbar-crumbs .sep { opacity: 0.5; }
.topbar-crumbs .current { color: var(--text); font-weight: 600; }
.topbar-right {
  display: flex; align-items: center; gap: 0.85rem;
}
.topbar-theme-toggle {
  display: inline-flex; align-items: center; justify-content: center;
  width: 32px; height: 32px;
  background: var(--surface2);
  color: var(--text-dim);
  border: 1px solid var(--border);
  border-radius: 999px;
  cursor: pointer;
  padding: 0;
  transition: color 0.12s, border-color 0.12s, background 0.12s;
}
.topbar-theme-toggle:hover {
  color: var(--accent);
  border-color: var(--accent);
  background: var(--accent-faint);
}
.topbar-theme-toggle:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px var(--accent-faint);
}
.topbar-loc {
  font-size: 0.78rem; color: var(--text-dim);
  display: flex; align-items: center; gap: 0.4rem;
  padding: 0.3rem 0.7rem;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 6px;
}
.topbar-user {
  display: flex; align-items: center; gap: 0.55rem;
}
.topbar-avatar {
  width: 30px; height: 30px;
  border-radius: 50%;
  background: var(--accent-faint);
  color: var(--text);
  display: flex; align-items: center; justify-content: center;
  font-size: 0.72rem; font-weight: 800;
}
.topbar-user-name {
  font-size: 0.82rem; font-weight: 600;
}
.topbar-user-role {
  font-size: 0.65rem; color: var(--text-dim);
  text-transform: uppercase; letter-spacing: 0.3px;
}
.topbar-user-link {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  text-decoration: none;
  color: inherit;
  padding: 0.2rem 0.45rem;
  border-radius: 999px;
  border: 1px solid transparent;
  transition: background 0.12s, border-color 0.12s, transform 0.12s;
}
a.topbar-user-link { cursor: pointer; }
a.topbar-user-link:hover {
  background: rgba(13, 148, 136, 0.10);
  border-color: rgba(13, 148, 136, 0.35);
}
a.topbar-user-link:hover .topbar-user-name {
  color: #14b8a6;
}
.topbar-avatar-admin {
  background: linear-gradient(135deg, #0d9488 0%, #14b8a6 100%);
  color: #fff;
  box-shadow: 0 0 0 1px rgba(20, 184, 166, 0.35);
}
a.topbar-user-link:hover .topbar-avatar-admin {
  box-shadow: 0 0 0 2px rgba(20, 184, 166, 0.55);
}

.topbar-auth-btn {
  margin-left: 0.45rem;
  padding: 0.32rem 0.72rem;
  font-size: 0.7rem; font-weight: 700;
  letter-spacing: 0.02em;
  background: var(--surface2);
  color: var(--text-dim);
  border: 1px solid var(--border);
  border-radius: 999px;
  cursor: pointer;
  text-decoration: none;
  transition: color 0.12s, border-color 0.12s, background 0.12s;
  white-space: nowrap;
}
.topbar-auth-btn:hover {
  color: #fff;
  background: var(--accent);
  border-color: var(--accent);
}

.page-content {
  flex: 1;
  padding: 2rem 2.25rem 3rem;
  max-width: 1500px;
  width: 100%;
}

/* Page header */
.page-h {
  display: flex; justify-content: space-between; align-items: flex-start;
  gap: 1rem; flex-wrap: wrap;
  margin-bottom: 1.5rem;
}
.page-h h1 { font-size: 1.6rem; line-height: 1.15; margin-bottom: 0.25rem; }
.page-h .sub { font-size: 0.85rem; color: var(--text-dim); }
.page-h-actions { display: flex; gap: 0.5rem; align-items: center; }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; gap: 0.45rem;
  padding: 0.55rem 1.05rem;
  font-size: 0.82rem;
  font-weight: 700;
  border-radius: 7px;
  border: 1px solid transparent;
  cursor: pointer;
  transition: opacity 0.15s, background 0.15s, border-color 0.15s;
  white-space: nowrap;
}
.btn:hover:not(:disabled) { opacity: 0.88; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary { background: var(--accent); color: var(--on-accent); }
.btn-secondary { background: var(--surface2); color: var(--text); border-color: var(--border); }
.btn-secondary:hover:not(:disabled) { border-color: rgba(228,230,239,0.3); opacity: 1; background: var(--hover-link); }
.btn-success { background: var(--success); color: white; }
.btn-danger { background: var(--critical); color: white; }
.btn-ghost { background: transparent; color: var(--text-dim); }
.btn-ghost:hover:not(:disabled) { color: var(--text); background: var(--hover-link); opacity: 1; }
.btn-sm { padding: 0.35rem 0.75rem; font-size: 0.75rem; }
.btn-lg { padding: 0.75rem 1.5rem; font-size: 0.9rem; }

/* Cards */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
}
.card-pad { padding: 1.25rem; }
.card-hdr {
  padding: 0.9rem 1.25rem;
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
  gap: 0.5rem; flex-wrap: wrap;
}
.card-hdr h3 { font-size: 0.95rem; margin: 0; }
.card-hdr .sub { font-size: 0.72rem; color: var(--text-dim); }
.card-body { padding: 1.25rem; }

/* Status badges (full set) */
.sbadge {
  display: inline-flex; align-items: center; gap: 0.3rem;
  padding: 0.18rem 0.55rem;
  border-radius: 20px;
  font-size: 0.65rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  line-height: 1.4;
  white-space: nowrap;
}
.sbadge::before {
  content: '';
  width: 5px; height: 5px;
  border-radius: 50%;
  background: currentColor;
}
.sbadge-draft   { background: var(--surface2); color: var(--text-dim); }
.sbadge-review  { background: rgba(251,191,36,0.12); color: #fbbf24; }
.sbadge-approved{ background: rgba(52,211,153,0.12); color: var(--success); }
.sbadge-ordered { background: var(--accent-faint); color: var(--text); }
.sbadge-shipped { background: rgba(56,189,248,0.12); color: #38bdf8; }
.sbadge-received{ background: rgba(167,139,250,0.13); color: #a78bfa; }
.sbadge-completed{ background: rgba(52,211,153,0.12); color: var(--success); }
.sbadge-cancelled{ background: rgba(255,77,106,0.12); color: var(--critical); }
.sbadge-partial { background: rgba(251,191,36,0.12); color: #fbbf24; }

/* Tables */
.tbl-wrap {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
}
.tbl { width: 100%; border-collapse: collapse; font-size: 0.82rem; }
.tbl thead th {
  background: var(--surface2);
  padding: 0.55rem 0.9rem;
  text-align: left;
  font-size: 0.62rem; font-weight: 700;
  text-transform: uppercase; letter-spacing: 0.4px;
  color: var(--text-dim);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.tbl thead th.right { text-align: right; }
.tbl thead th.center { text-align: center; }
.tbl tbody td { padding: 0.65rem 0.9rem; border-bottom: 1px solid var(--border); vertical-align: middle; }
.tbl tbody tr:last-child td { border-bottom: none; }
.tbl tbody tr:hover { background: var(--hover-row); }
.tbl tbody td.right { text-align: right; }
.tbl tbody td.center { text-align: center; }
.tbl tbody td.num { font-variant-numeric: tabular-nums; font-weight: 700; }
.tbl-clickable tbody tr { cursor: pointer; }

/* Stat cards */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 1rem;
  margin-bottom: 1.75rem;
}
.stat {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 1.1rem 1.25rem;
}
.stat-link {
  display: block;
  text-decoration: none;
  color: inherit;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s, transform 0.15s;
}
.stat-link:hover {
  border-color: rgba(228,230,239,0.3);
  background: var(--hover-link);
  transform: translateY(-1px);
}
.stat-val { font-size: 1.7rem; font-weight: 800; line-height: 1.05; letter-spacing: -0.01em; }
.stat-lbl { font-size: 0.62rem; text-transform: uppercase; letter-spacing: 0.5px; color: var(--text-dim); font-weight: 700; margin-top: 0.35rem; }
.stat-meta { font-size: 0.72rem; color: var(--text-dim); margin-top: 0.4rem; display: flex; align-items: center; gap: 0.35rem; }
.stat-trend.up { color: var(--success); }
.stat-trend.down { color: var(--critical); }

/* Pills */
.pill {
  display: inline-flex; align-items: center; gap: 0.25rem;
  padding: 0.12rem 0.5rem;
  border-radius: 4px;
  font-size: 0.62rem; font-weight: 600;
  background: var(--surface2);
  color: var(--text-dim);
  white-space: nowrap;
}
.pill-loc { background: var(--surface2); border: 1px solid var(--border); color: var(--text-dim); }
.pill-critical { background: rgba(255,77,106,0.12); color: var(--critical); }
.pill-low { background: rgba(251,191,36,0.12); color: #fbbf24; }
.pill-success { background: rgba(52,211,153,0.12); color: var(--success); }
.pill-accent { background: var(--accent-faint); color: var(--text); }

/* Mono / IDs */
.mono { font-family: ui-monospace, 'SF Mono', Menlo, monospace; font-size: 0.75rem; color: var(--text-dim); }

/* Tabs */
.tabs {
  display: flex; gap: 0;
  border-bottom: 2px solid var(--border);
  margin-bottom: 1.25rem;
}
.tabs .tab {
  padding: 0.55rem 1.1rem;
  font-size: 0.82rem; font-weight: 700;
  color: var(--text-dim);
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  cursor: pointer;
  transition: color 0.15s;
  display: inline-flex; align-items: center; gap: 0.4rem;
}
.tabs .tab:hover { color: var(--text); }
.tabs .tab.active { color: var(--text); border-bottom-color: var(--text); }
.tabs .tab .count {
  background: var(--surface2);
  border-radius: 10px;
  padding: 0.05rem 0.45rem;
  font-size: 0.62rem;
}
.tabs .tab.active .count { background: var(--accent-faint); }

/* Form */
.field { margin-bottom: 1rem; }
.field label {
  display: block;
  font-size: 0.65rem; text-transform: uppercase; letter-spacing: 0.5px;
  color: var(--text-dim); font-weight: 700;
  margin-bottom: 0.35rem;
}
.field input, .field select, .field textarea {
  width: 100%;
  padding: 0.55rem 0.75rem;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 7px;
  font-size: 0.82rem;
  color: var(--text);
  font-weight: 500;
}
.field input:focus, .field select:focus, .field textarea:focus {
  outline: none; border-color: var(--accent);
}
.field textarea { resize: vertical; min-height: 80px; }
.field-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 0.85rem;
}

/* Modal */
.modal-overlay {
  display: none; position: fixed; inset: 0;
  background: rgba(0,0,0,0.7);
  z-index: 1000;
  align-items: center; justify-content: center;
  padding: 1rem;
}
.modal-overlay.active { display: flex; }
.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  width: 100%;
  max-width: 520px;
  max-height: 90vh;
  overflow-y: auto;
}
.modal-h {
  padding: 1.15rem 1.5rem;
  border-bottom: 1px solid var(--border);
  display: flex; justify-content: space-between; align-items: center;
}
.modal-h h3 { font-size: 1rem; margin: 0; }
.modal-close {
  background: none; border: none; color: var(--text-dim);
  cursor: pointer; padding: 0.25rem; font-size: 1.2rem; line-height: 1;
}
.modal-close:hover { color: var(--text); }
.modal-b { padding: 1.5rem; }
.modal-f { padding: 1rem 1.5rem; border-top: 1px solid var(--border); display: flex; gap: 0.5rem; justify-content: flex-end; }

/* Progress bar */
.pbar { height: 8px; background: var(--surface2); border-radius: 20px; overflow: hidden; }
.pbar-fill { height: 100%; background: var(--accent); transition: width 0.3s; }
.pbar-fill.success { background: var(--success); }
.pbar-fill.warn { background: #fbbf24; }

/* Empty state */
.empty {
  text-align: center;
  padding: 3rem 2rem;
  color: var(--text-dim);
}
.empty-icon { font-size: 2.5rem; margin-bottom: 0.75rem; opacity: 0.4; }
.empty h3 { font-size: 1rem; color: var(--text); margin-bottom: 0.4rem; }
.empty p { font-size: 0.82rem; line-height: 1.5; }

/* Timeline */
.timeline { position: relative; padding-left: 1.5rem; }
.timeline::before {
  content: ''; position: absolute;
  left: 6px; top: 6px; bottom: 6px;
  width: 1px; background: var(--border);
}
.tl-item { position: relative; padding-bottom: 1.1rem; }
.tl-item:last-child { padding-bottom: 0; }
.tl-dot {
  position: absolute; left: -1.5rem; top: 4px;
  width: 13px; height: 13px;
  border-radius: 50%;
  background: var(--surface2);
  border: 2px solid var(--border);
}
.tl-dot.done { background: var(--success); border-color: var(--success); }
.tl-dot.active { background: var(--accent); border-color: var(--accent); box-shadow: 0 0 0 4px var(--accent-faint); }
.tl-meta { font-size: 0.68rem; color: var(--text-dim); margin-bottom: 0.15rem; }
.tl-title { font-size: 0.82rem; font-weight: 600; margin-bottom: 0.15rem; }
.tl-desc { font-size: 0.75rem; color: var(--text-dim); line-height: 1.5; }

/* Location cards (locations.html grid) */
.loc-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 1rem;
  margin-top: 0.5rem;
}
.loc-card {
  display: block;
  text-decoration: none;
  color: inherit;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 1.1rem 1.15rem;
  transition: border-color 0.15s, transform 0.15s, box-shadow 0.15s;
}
.loc-card:hover {
  border-color: var(--accent);
  transform: translateY(-1px);
  box-shadow: 0 4px 14px -8px rgba(0,0,0,0.4);
}
.loc-card-h {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.6rem;
  margin-bottom: 0.9rem;
  min-width: 0;
}
.loc-card-h > div:first-child { min-width: 0; flex: 1; }
.loc-card-name {
  font-size: 1rem;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  letter-spacing: 0.01em;
}
.loc-card-state {
  font-size: 0.7rem;
  color: var(--text-dim);
  margin-top: 0.1rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}
.loc-card-stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.55rem 1rem;
  padding: 0.7rem 0;
  margin-bottom: 0.85rem;
  border-top: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
}
.loc-stat-v {
  font-size: 1rem;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  line-height: 1.15;
}
.loc-stat-l {
  font-size: 0.65rem;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-top: 0.1rem;
}
.loc-card-top {
  font-size: 0.62rem;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-bottom: 0.35rem;
}
.loc-card-list {
  display: flex;
  flex-direction: column;
  gap: 0.28rem;
  font-size: 0.75rem;
  line-height: 1.35;
  color: var(--text-dim);
}
.loc-card-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.6rem;
  min-width: 0;
}
.loc-card-row-name {
  flex: 1 1 auto;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--text);
  font-weight: 600;
}
.loc-card-row-amt {
  flex: 0 0 auto;
  white-space: nowrap;
  color: var(--text-dim);
  font-variant-numeric: tabular-nums;
  font-weight: 500;
  font-size: 0.72rem;
}

/* Responsive */
@media (max-width: 900px) {
  .sidebar { transform: translateX(-100%); transition: transform 0.2s; }
  .sidebar.open { transform: translateX(0); }
  .main-area { margin-left: 0; }
  .page-content { padding: 1.25rem 1rem 2rem; }
  .loc-grid { grid-template-columns: 1fr; }
}
