/* ═══════════════════════════════════════════════════════════
   core.css — PerilOps shared styles
   ═══════════════════════════════════════════════════════════ */

/* ── 0. View Transitions — elimina flash blanco entre paginas ── */
@view-transition { navigation: auto; }
::view-transition-old(root),
::view-transition-new(root) { animation-duration: 0s; }

/* ── 1. CSS Custom Properties (Light theme) — PerilDS tokens ── */
:root {
  /* Colors — Semantic */
  --bg: #f8fafc;
  --bg-subtle: #f1f5f9;
  --card: #ffffff;
  --border: #e2e8f0;
  --border-light: #f1f5f9;
  --text: #1e293b;
  --text-secondary: #475569;
  --muted: #94a3b8;
  --accent: #3b82f6;
  --accent-hover: #2563eb;
  --accent-light: rgba(59,130,246,0.08);
  --success: #16a34a;
  --success-light: #dcfce7;
  --warning: #d97706;
  --warning-light: #fef3c7;
  --error: #dc2626;
  --error-light: #fee2e2;
  --info: #0284c7;
  --info-light: #e0f2fe;
  --auto: #7c3aed;
  --auto-light: #ede9fe;

  /* Colors — Gray scale */
  --gray-50: #f8fafc;
  --gray-100: #f1f5f9;
  --gray-200: #e2e8f0;
  --gray-300: #cbd5e1;
  --gray-400: #94a3b8;
  --gray-500: #64748b;
  --gray-600: #475569;
  --gray-700: #334155;
  --gray-800: #1e293b;
  --gray-900: #0f172a;

  /* Typography — Inter + JetBrains Mono */
  --font-sans: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-mono: "JetBrains Mono", "Consolas", "SF Mono", "Liberation Mono", monospace;

  /* Type scale (px) */
  --text-xs: 11px;
  --text-sm: 12px;
  --text-base: 13px;
  --text-md: 14px;
  --text-lg: 16px;
  --text-xl: 18px;
  --text-2xl: 24px;
  --text-3xl: 32px;

  /* Spacing scale (4px base) */
  --space-0: 0;
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 20px;
  --space-6: 24px;
  --space-8: 32px;
  --space-10: 40px;
  --space-12: 48px;
  --space-16: 64px;

  /* Line heights */
  --leading-none: 1;
  --leading-tight: 1.2;
  --leading-snug: 1.375;
  --leading-normal: 1.5;
  --leading-relaxed: 1.625;

  /* Font weights */
  --font-normal: 400;
  --font-medium: 500;
  --font-semibold: 600;
  --font-bold: 700;
  --font-extrabold: 800;

  /* Border widths */
  --border-width: 1px;
  --border-width-2: 2px;

  /* Opacity */
  --opacity-disabled: 0.5;
  --opacity-muted: 0.6;
  --opacity-hover: 0.8;

  /* Focus ring */
  --ring-width: 2px;
  --ring-offset: 2px;
  --ring-color: var(--accent);

  /* Layout */
  --header-height: 56px;
  --content-max: 1440px;

  /* Radius */
  --radius-sm: 6px;
  --radius-md: 8px;
  --radius-lg: 10px;
  --radius-xl: 12px;
  --radius-full: 9999px;

  /* Shadows */
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.05);
  --shadow-md: 0 1px 3px rgba(0,0,0,0.1), 0 1px 2px rgba(0,0,0,0.06);
  --shadow-lg: 0 4px 6px rgba(0,0,0,0.07), 0 2px 4px rgba(0,0,0,0.06);
  --shadow-glow: 0 0 0 3px rgba(59,130,246,0.15);

  /* Z-index scale (100-step for breathing room) */
  --z-base: 0;
  --z-dropdown: 100;
  --z-sticky: 200;
  --z-sidebar: 300;
  --z-modal-bg: 400;
  --z-modal: 500;
  --z-toast: 600;
  --z-tooltip: 700;

  /* Transitions */
  --ease-out: ease-out;
  --duration-fast: 150ms;
  --duration-normal: 200ms;
  --duration-slow: 300ms;
}

/* ── 2. Dark mode ── */
[data-theme="dark"] {
  --bg: #0f172a;
  --bg-subtle: #1e293b;
  --card: #1e293b;
  --border: #334155;
  --border-light: #1e293b;
  --text: #f1f5f9;
  --text-secondary: #cbd5e1;
  --muted: #64748b;
  --accent: #60a5fa;
  --accent-hover: #93bbfd;
  --accent-light: rgba(96,165,250,0.1);
  --success: #4ade80;
  --success-light: rgba(74,222,128,0.12);
  --warning: #fbbf24;
  --warning-light: rgba(251,191,36,0.12);
  --error: #f87171;
  --error-light: rgba(248,113,113,0.12);
  --info: #38bdf8;
  --info-light: rgba(56,189,248,0.12);
  --auto: #a78bfa;
  --auto-light: rgba(167,139,250,0.12);
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.3);
  --shadow-md: 0 1px 3px rgba(0,0,0,0.4);
  --shadow-lg: 0 4px 6px rgba(0,0,0,0.4);
  --shadow-glow: 0 0 0 3px rgba(96,165,250,0.2);
}

/* ── 2b. Reduced motion — respeta preferencia del usuario (WCAG AA) ── */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

/* ── 3. Reset ── */
*, *::before, *::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html, body {
  height: 100%;
}
html {
  scrollbar-gutter: stable;
}

body {
  font-family: var(--font-sans);
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  display: flex;
  flex-direction: column;
  -webkit-font-smoothing: antialiased;
}

a {
  color: var(--accent);
  text-decoration: none;
}
a:hover { color: var(--accent-hover); text-decoration: underline; }

/* ── 4. SVG Icon sizing ── */
.icon {
  width: 20px;
  height: 20px;
  flex-shrink: 0;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
  vertical-align: middle;
}
.icon-sm { width: 16px; height: 16px; }
.icon-lg { width: 24px; height: 24px; }
.icon-xl { width: 36px; height: 36px; }

/* ── 5. Header ── */
.po-header {
  background: var(--card);
  border-bottom: 1px solid var(--border);
  padding: 0 24px;
  height: var(--header-height);
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
  position: sticky;
  top: 0;
  z-index: var(--z-sticky);
}

.po-header-left {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-shrink: 0;
}

.po-header-logo {
  height: 36px;
  flex-shrink: 0;
}

.po-header-brand-name {
  font-size: 18px;
  font-weight: 800;
  color: var(--text);
  margin: 0;
  line-height: 1;
  letter-spacing: -0.3px;
}

.po-header-right {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
  justify-content: flex-end;
}

/* ── 6. Navigation ── */
.po-nav {
  display: flex;
  gap: 2px;
  align-items: center;
  justify-content: center;
  flex: 1;
}

.po-nav-item {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 500;
  color: var(--muted);
  text-decoration: none;
  transition: color var(--duration-fast), background var(--duration-fast);
  white-space: nowrap;
}

.po-nav-item:hover {
  color: var(--text);
  background: var(--bg-subtle);
  text-decoration: none;
}

.po-nav-item.active {
  color: var(--accent);
  background: var(--accent-light);
  font-weight: 600;
}

.po-nav-item .icon {
  width: 16px;
  height: 16px;
}

.po-nav-item--icon { padding: 8px; }

/* ── 7. Dark mode toggle ── */
.theme-toggle {
  background: var(--bg-subtle);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 6px;
  cursor: pointer;
  color: var(--muted);
  display: flex;
  align-items: center;
  transition: color var(--duration-fast), border-color var(--duration-fast);
}

.theme-toggle:hover {
  color: var(--accent);
  border-color: var(--accent);
}

/* ── 9. Footer ── */
.po-footer {
  text-align: center;
  padding: 16px 24px;
  font-size: 12px;
  color: var(--muted);
  border-top: 1px solid var(--border);
}

/* ── 10. Buttons ── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 20px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  border: none;
  transition: background var(--duration-fast), box-shadow var(--duration-fast);
  font-family: inherit;
}

.btn-primary {
  background: var(--accent);
  color: #fff;
}
.btn-primary:hover { background: var(--accent-hover); }
.btn-primary:disabled { opacity: .5; cursor: not-allowed; }

.btn-secondary {
  background: var(--bg-subtle);
  color: var(--text-secondary);
  border: 1px solid var(--border);
}
.btn-secondary:hover { background: var(--border); }

.btn-success { background: var(--success); color: #fff; }
.btn-success:hover { filter: brightness(1.1); }

.btn-danger { background: var(--error); color: #fff; }
.btn-danger:hover { filter: brightness(1.1); }

.btn .sub-text { font-size: 11px; font-weight: 500; opacity: .8; }

/* ── 11. Card ── */
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
}

/* ── 12. Upload zone ── */
.upload-zone {
  max-width: 640px;
  margin: 40px auto 0;
  border: 2px dashed var(--border);
  border-radius: var(--radius-lg);
  padding: 48px 40px;
  text-align: center;
  cursor: pointer;
  transition: border-color var(--duration-fast), background var(--duration-fast);
  background: var(--card);
}

.upload-zone:hover,
.upload-zone.dragover {
  border-color: var(--accent);
  background: var(--accent-light);
}

.upload-zone .icon-upload-big {
  width: 48px;
  height: 48px;
  margin: 0 auto 12px;
  color: var(--accent);
  opacity: .5;
}

.upload-zone h2, .upload-zone h3 {
  font-size: 17px;
  font-weight: 700;
  margin-bottom: 6px;
}

.upload-zone p {
  font-size: 13px;
  color: var(--muted);
}

.upload-zone input[type="file"] { display: none; }

/* ── 13. Toast ── */
.toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  background: var(--text);
  color: var(--bg);
  padding: 10px 20px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 600;
  box-shadow: var(--shadow-lg);
  opacity: 0;
  transform: translateY(8px);
  transition: opacity var(--duration-normal), transform var(--duration-normal);
  pointer-events: none;
  z-index: var(--z-toast);
}

.toast.show, .toast.visible {
  opacity: 1;
  transform: translateY(0);
  pointer-events: auto;
}
.toast.success { background: var(--success); color: #fff; }
.toast.error { background: var(--error); color: #fff; }
.toast.info { background: var(--info); color: #fff; }
.toast { display: flex; align-items: center; gap: 10px; }
.toast-close {
  background: none; border: none; color: inherit; font-size: 18px;
  cursor: pointer; padding: 0 2px; opacity: 0.8; line-height: 1;
}
.toast-close:hover { opacity: 1; }

/* ── 13b. Confirm Modal (PO.confirm) ── */
.po-confirm-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  z-index: var(--z-modal);
  display: flex;
  align-items: center;
  justify-content: center;
  animation: fadeIn 0.15s ease;
}
.po-confirm-box {
  background: var(--card);
  border-radius: var(--radius-lg);
  padding: 24px 28px;
  max-width: 380px;
  width: 90%;
  box-shadow: var(--shadow-lg);
  text-align: center;
  animation: popIn 0.2s ease;
}
.po-confirm-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  margin: 0 0 6px;
}
.po-confirm-subtitle {
  font-size: 12px;
  color: var(--muted);
  display: block;
}
.po-confirm-actions {
  display: flex;
  gap: 8px;
  margin-top: 18px;
  justify-content: center;
}
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes popIn { from { transform: scale(0.9); opacity: 0; } to { transform: scale(1); opacity: 1; } }

/* ── 13c. Utility classes ── */
.num { font-variant-numeric: tabular-nums; text-align: right; }
.mono { font-family: var(--font-mono); }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }
.sr-only:focus { position: fixed; top: 0; left: 0; width: auto; height: auto; padding: 8px 16px; margin: 0; overflow: visible; clip: auto; white-space: normal; background: var(--accent); color: #fff; z-index: 9999; font-size: 14px; font-weight: 600; }
.text-right { text-align: right; }
.text-center { text-align: center; }
.text-muted { color: var(--muted); }
.text-success { color: var(--success); }
.text-error { color: var(--error); }
.text-warning { color: var(--warning); }

/* ── Spacing utilities ── */
.mt-1 { margin-top: var(--space-1); }
.mt-2 { margin-top: var(--space-2); }
.mt-3 { margin-top: var(--space-3); }
.mt-4 { margin-top: var(--space-4); }
.mt-6 { margin-top: var(--space-6); }
.mb-1 { margin-bottom: var(--space-1); }
.mb-2 { margin-bottom: var(--space-2); }
.mb-3 { margin-bottom: var(--space-3); }
.mb-4 { margin-bottom: var(--space-4); }
.mb-6 { margin-bottom: var(--space-6); }
.gap-1 { gap: var(--space-1); }
.gap-2 { gap: var(--space-2); }
.gap-3 { gap: var(--space-3); }
.gap-4 { gap: var(--space-4); }
.p-2 { padding: var(--space-2); }
.p-3 { padding: var(--space-3); }
.p-4 { padding: var(--space-4); }
.px-4 { padding-left: var(--space-4); padding-right: var(--space-4); }
.py-2 { padding-top: var(--space-2); padding-bottom: var(--space-2); }

/* ── Layout utilities ── */
.flex { display: flex; }
.flex-col { flex-direction: column; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.flex-1 { flex: 1; }
.flex-wrap { flex-wrap: wrap; }
.grid { display: grid; }
.w-full { width: 100%; }
.hidden { display: none; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.relative { position: relative; }

/* ── Grid system (po-grid) ── */
.po-grid { display: grid; gap: var(--space-4); }
.po-grid--auto { grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); }
.po-grid--2 { grid-template-columns: 1fr; }
.po-grid--3 { grid-template-columns: 1fr; }
.po-grid--4 { grid-template-columns: 1fr; }

@media (min-width: 768px) {
  .po-grid--2 { grid-template-columns: repeat(2, 1fr); }
  .po-grid--3 { grid-template-columns: repeat(3, 1fr); }
  .po-grid--4 { grid-template-columns: repeat(2, 1fr); }
}
@media (min-width: 1024px) {
  .po-grid--3 { grid-template-columns: repeat(3, 1fr); }
  .po-grid--4 { grid-template-columns: repeat(4, 1fr); }
}

/* ── Typography utilities ── */
.text-xs { font-size: var(--text-xs); }
.text-sm { font-size: var(--text-sm); }
.text-base { font-size: var(--text-base); }
.text-md { font-size: var(--text-md); }
.text-lg { font-size: var(--text-lg); }
.text-xl { font-size: var(--text-xl); }
.text-2xl { font-size: var(--text-2xl); }
.font-medium { font-weight: 500; }
.font-semibold { font-weight: 600; }
.font-bold { font-weight: 700; }
.font-extrabold { font-weight: 800; }
.tabular-nums { font-variant-numeric: tabular-nums; }

/* ── 13d. Shortcuts overlay (PO.shortcuts) ── */
.po-shortcuts-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  z-index: var(--z-modal);
  display: flex;
  align-items: center;
  justify-content: center;
  animation: fadeIn 0.15s ease;
}
.po-shortcuts-box {
  background: var(--card);
  border-radius: var(--radius-lg);
  padding: 0;
  max-width: 420px;
  width: 90%;
  box-shadow: var(--shadow-lg);
  animation: popIn 0.2s ease;
  overflow: hidden;
}
.po-shortcuts-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}
.po-shortcuts-header h3 {
  font-size: 15px;
  font-weight: 700;
  margin: 0;
}
.po-shortcuts-close {
  background: none;
  border: none;
  font-size: 20px;
  cursor: pointer;
  color: var(--muted);
  line-height: 1;
  padding: 0 4px;
}
.po-shortcuts-close:hover { color: var(--text); }
.po-shortcuts-section {
  padding: 12px 20px;
  border-bottom: 1px solid var(--border-light);
}
.po-shortcuts-section:last-child { border-bottom: none; }
.po-shortcuts-group-title {
  font-size: 10px;
  text-transform: uppercase;
  font-weight: 700;
  color: var(--muted);
  letter-spacing: 0.05em;
  margin-bottom: 8px;
}
.po-shortcut-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 4px 0;
  font-size: 13px;
}
.po-shortcut-row kbd {
  display: inline-block;
  min-width: 48px;
  text-align: center;
  font-size: 11px;
  font-family: var(--font-mono);
  font-weight: 600;
  background: var(--bg-subtle);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 2px 8px;
  color: var(--text-secondary);
}
.po-shortcut-row span {
  color: var(--text);
}

/* ── 13e. Command Palette (Ctrl+K) ── */
.po-palette-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  z-index: var(--z-modal);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding-top: 120px;
  animation: fadeIn 0.1s ease;
}
.po-palette-box {
  background: var(--card);
  border-radius: var(--radius-lg);
  max-width: 520px;
  width: 92%;
  box-shadow: 0 16px 48px rgba(0,0,0,0.2);
  overflow: hidden;
  animation: popIn 0.15s ease;
}
.po-palette-input {
  width: 100%;
  padding: 14px 18px;
  border: none;
  border-bottom: 1px solid var(--border);
  font-size: 15px;
  font-family: var(--font-sans);
  color: var(--text);
  background: transparent;
  outline: none;
}
.po-palette-input::placeholder { color: var(--muted); }
.po-palette-list {
  max-height: 320px;
  overflow-y: auto;
}
.po-palette-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 18px;
  cursor: pointer;
  transition: background 0.1s;
}
.po-palette-item:hover,
.po-palette-item.selected {
  background: var(--accent-light);
}
.po-palette-item.selected {
  border-left: 3px solid var(--accent);
}
.po-palette-label {
  font-size: 13px;
  font-weight: 500;
  color: var(--text);
}
.po-palette-cat {
  font-size: 11px;
  color: var(--muted);
  text-transform: uppercase;
  font-weight: 600;
  letter-spacing: 0.03em;
}
.po-palette-empty {
  padding: 24px 18px;
  text-align: center;
  font-size: 13px;
  color: var(--muted);
}

/* ── 13f. Main content ── */
main { flex: 1; min-height: 0; overflow: auto; display: flex; flex-direction: column; }

/* ── 14. Breadcrumb ── */
.breadcrumb {
  padding: 8px 24px;
  font-size: 12px;
  color: var(--muted);
  background: var(--card);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: 0;
}

.breadcrumb a {
  color: var(--accent);
  text-decoration: none;
}
.breadcrumb a:hover { text-decoration: underline; }
.breadcrumb .sep { margin: 0 6px; opacity: .4; }

/* ── 15. Section heading ── */
.section-heading {
  font-size: 14px;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 16px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border);
}

/* ── 16. Kbd shortcut badge ── */
.kbd {
  font-size: 9px;
  background: var(--bg-subtle);
  padding: 2px 5px;
  border-radius: 4px;
  color: var(--muted);
  margin-left: 4px;
  border: 1px solid var(--border);
  font-family: var(--font-mono);
  font-weight: 600;
}

/* ── 17. Animation ── */
@keyframes fadeSlideUp {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ── 18. Scrollbar ── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--muted); }

/* ── 19. Focus ring ── */
:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* ═══════════════════════════════════════════════════════════
   DESIGN SYSTEM COMPONENTS — PerilDS v1.0.0
   Nomenclatura BEM: po-[block]  po-[block]-[element]  po-[block]--[modifier]
   Estados: .is-active, .is-loading, .is-disabled
   ═══════════════════════════════════════════════════════════ */

/* ── C1. po-btn — Buttons ── */
.po-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 20px;
  border-radius: var(--radius-sm);
  font-size: var(--text-base);
  font-weight: var(--font-semibold);
  font-family: inherit;
  cursor: pointer;
  border: var(--border-width) solid transparent;
  transition: background var(--duration-fast), box-shadow var(--duration-fast), border-color var(--duration-fast);
  text-decoration: none;
  line-height: var(--leading-tight);
  white-space: nowrap;
}
.po-btn:hover { text-decoration: none; }
.po-btn:focus-visible { outline: var(--ring-width) solid var(--ring-color); outline-offset: var(--ring-offset); }
.po-btn.is-disabled, .po-btn:disabled { opacity: var(--opacity-disabled); cursor: not-allowed; pointer-events: none; }

/* Variants */
.po-btn--primary { background: var(--accent); color: #fff; }
.po-btn--primary:hover { background: var(--accent-hover); }

.po-btn--secondary { background: var(--bg-subtle); color: var(--text-secondary); border-color: var(--border); }
.po-btn--secondary:hover { background: var(--border); }

.po-btn--success { background: var(--success); color: #fff; }
.po-btn--success:hover { filter: brightness(1.1); }

.po-btn--danger { background: var(--error); color: #fff; }
.po-btn--danger:hover { filter: brightness(1.1); }

.po-btn--ghost { background: transparent; color: var(--text-secondary); }
.po-btn--ghost:hover { background: var(--bg-subtle); }

.po-btn--ai { background: var(--auto); color: #fff; }
.po-btn--ai:hover { filter: brightness(1.15); }

/* Sizes */
.po-btn--sm { padding: 5px 12px; font-size: var(--text-sm); }
.po-btn--xs { padding: 3px 8px; font-size: var(--text-xs); }
.po-btn--icon { padding: 6px; aspect-ratio: 1; }

/* Loading state */
.po-btn.is-loading { position: relative; color: transparent; pointer-events: none; }
.po-btn.is-loading::after {
  content: ''; position: absolute; width: 16px; height: 16px;
  border: 2px solid rgba(255,255,255,0.3); border-top-color: #fff;
  border-radius: 50%; animation: po-spin 0.6s linear infinite;
}
.po-btn--secondary.is-loading::after { border-color: var(--border); border-top-color: var(--text-secondary); }

/* ── C2. po-input — Text inputs ── */
.po-input {
  width: 100%;
  padding: 8px 12px;
  border: var(--border-width) solid var(--border);
  border-radius: var(--radius-sm);
  font-size: var(--text-base);
  font-family: inherit;
  color: var(--text);
  background: var(--card);
  transition: border-color var(--duration-fast), box-shadow var(--duration-fast);
  line-height: var(--leading-normal);
}
.po-input::placeholder { color: var(--muted); }
.po-input:focus { border-color: var(--accent); box-shadow: var(--shadow-glow); outline: none; }
.po-input.is-error { border-color: var(--error); }
.po-input.is-error:focus { box-shadow: 0 0 0 3px rgba(220,38,38,0.15); }
.po-input.is-warn { border-color: var(--warning); }
.po-input.is-warn:focus { box-shadow: 0 0 0 3px rgba(251,191,36,0.15); }
.po-input:disabled { background: var(--bg-subtle); color: var(--muted); cursor: not-allowed; }
.po-input--sm { padding: 5px 8px; font-size: var(--text-sm); }

/* Input group (prefix icon / suffix addon) */
.po-input-group { position: relative; }
.po-input-group .po-input { padding-left: 36px; }
.po-input-group .icon { position: absolute; left: 10px; top: 50%; transform: translateY(-50%); color: var(--muted); pointer-events: none; }

/* ── C3. po-select — Dropdowns ── */
.po-select {
  width: 100%;
  padding: 8px 32px 8px 12px;
  border: var(--border-width) solid var(--border);
  border-radius: var(--radius-sm);
  font-size: var(--text-base);
  font-family: inherit;
  color: var(--text);
  background: var(--card) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%2394a3b8' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E") no-repeat right 10px center;
  appearance: none;
  cursor: pointer;
  transition: border-color var(--duration-fast), box-shadow var(--duration-fast);
  line-height: var(--leading-normal);
}
.po-select:focus { border-color: var(--accent); box-shadow: var(--shadow-glow); outline: none; }
.po-select:disabled { background-color: var(--bg-subtle); color: var(--muted); cursor: not-allowed; }
.po-select.is-error { border-color: var(--error); }
.po-select.is-error:focus { box-shadow: 0 0 0 3px rgba(220,38,38,0.15); }
.po-select.is-warn { border-color: var(--warning); }
.po-select.is-warn:focus { box-shadow: 0 0 0 3px rgba(251,191,36,0.15); }
.po-select--sm { padding: 5px 28px 5px 8px; font-size: var(--text-sm); }

/* ── C4. po-textarea — Multiline ── */
.po-textarea {
  width: 100%;
  padding: 8px 12px;
  border: var(--border-width) solid var(--border);
  border-radius: var(--radius-sm);
  font-size: var(--text-base);
  font-family: inherit;
  color: var(--text);
  background: var(--card);
  resize: vertical;
  min-height: 80px;
  line-height: var(--leading-normal);
  transition: border-color var(--duration-fast), box-shadow var(--duration-fast);
}
.po-textarea:focus { border-color: var(--accent); box-shadow: var(--shadow-glow); outline: none; }

/* ── C5. po-checkbox — Custom checkbox ── */
.po-checkbox {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  font-size: var(--text-base);
  color: var(--text);
}
.po-checkbox input[type="checkbox"] {
  width: 16px; height: 16px;
  border: var(--border-width) solid var(--border);
  border-radius: 4px;
  appearance: none;
  background: var(--card);
  cursor: pointer;
  transition: background var(--duration-fast), border-color var(--duration-fast);
  flex-shrink: 0;
  position: relative;
}
.po-checkbox input[type="checkbox"]:checked {
  background: var(--accent);
  border-color: var(--accent);
}
.po-checkbox input[type="checkbox"]:checked::after {
  content: '';
  position: absolute;
  left: 50%; top: 45%;
  width: 5px; height: 9px;
  border: solid #fff;
  border-width: 0 2px 2px 0;
  transform: translate(-50%, -50%) rotate(45deg);
}
.po-checkbox input[type="checkbox"]:focus-visible { outline: var(--ring-width) solid var(--ring-color); outline-offset: var(--ring-offset); }

/* ── C6. po-field — Label + input + hint + error ── */
.po-field {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.po-field-label {
  font-size: var(--text-sm);
  font-weight: var(--font-semibold);
  color: var(--text);
}
.po-field-hint {
  font-size: var(--text-xs);
  color: var(--muted);
}
.po-field-error {
  font-size: var(--text-xs);
  color: var(--error);
  font-weight: var(--font-medium);
}
.po-field.is-error .po-field-label { color: var(--error); }
.po-field.is-warn .po-field-label { color: var(--warning); }

/* ── C7. po-card — Content container ── */
.po-card {
  background: var(--card);
  border: var(--border-width) solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
}
.po-card-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.po-card-body { padding: 16px 20px; }
.po-card-footer {
  padding: 12px 20px;
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 8px;
}

/* ── C8. po-kpi — KPI metric card ── */
.po-kpi {
  background: var(--card);
  border: var(--border-width) solid var(--border);
  border-radius: var(--radius-md);
  padding: 18px 20px;
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.po-kpi__label {
  font-size: var(--text-xs);
  font-weight: var(--font-semibold);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--muted);
}
.po-kpi__value {
  font-size: var(--text-3xl);
  font-weight: var(--font-bold);
  color: var(--text);
  line-height: var(--leading-none);
  font-variant-numeric: tabular-nums;
}
.po-kpi__value--sm { font-size: var(--text-lg); font-weight: var(--font-semibold); color: var(--text-secondary); }

/* ── C9. po-badge — Status indicators ── */
.po-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 10px;
  font-weight: var(--font-semibold);
  padding: 2px 8px;
  border-radius: var(--radius-full);
  white-space: nowrap;
  text-transform: uppercase;
  letter-spacing: 0.02em;
  line-height: var(--leading-snug);
}
.po-badge--ok { background: var(--success-light); color: var(--success); }
.po-badge--warn { background: var(--warning-light); color: var(--warning); }
.po-badge--err { background: var(--error-light); color: var(--error); }
.po-badge--info { background: var(--info-light); color: var(--info); }
.po-badge--ai { background: var(--auto-light); color: var(--auto); }
.po-badge--muted { background: var(--bg-subtle); color: var(--muted); border: 1px solid var(--border); }
.po-badge--dot::before {
  content: '';
  width: 6px; height: 6px;
  border-radius: 50%;
  background: currentColor;
  flex-shrink: 0;
}

/* ── C10. po-table — Data tables ── */
.po-table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }

.po-table-frame {
  position: relative;
  border: var(--border-width) solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--card);
  overflow: clip;
  isolation: isolate;
}

.po-table-frame > table,
.po-table-frame > .po-table,
.po-table-frame > .po-table--dashboard {
  border-collapse: separate;
  border-spacing: 0;
  background: transparent;
  clip-path: inset(0 round calc(var(--radius-lg) - 1px));
}

.po-table-frame :is(.po-table, .po-table--dashboard) thead th:first-child {
  border-top-left-radius: calc(var(--radius-lg) - 1px);
}

.po-table-frame :is(.po-table, .po-table--dashboard) thead th:last-child {
  border-top-right-radius: calc(var(--radius-lg) - 1px);
}

.po-table-frame :is(.po-table, .po-table--dashboard) thead th {
  background-clip: border-box;
}


.po-table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--text-sm);
}
.po-table th {
  text-align: left;
  font-size: var(--text-xs);
  font-weight: var(--font-semibold);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  padding: 8px 12px;
  border-bottom: var(--border-width-2) solid var(--border);
  white-space: nowrap;
  position: sticky;
  top: 0;
  background: var(--card);
  z-index: 2;
  box-shadow: inset 0 1px 0 var(--border);
}
.po-table td {
  padding: 8px 12px;
  border-bottom: 1px solid var(--border-light);
  color: var(--text);
  vertical-align: middle;
}
.po-table tr:hover td { background: var(--bg-subtle); }
.po-table td.num { text-align: right; font-variant-numeric: tabular-nums; }

/* Variants */
.po-table--striped tr:nth-child(even) td { background: var(--bg-subtle); }
.po-table--compact th, .po-table--compact td { padding: 4px 8px; }

/* Sortable */
.po-table th[data-sort] { cursor: pointer; user-select: none; }
.po-table th[data-sort]:hover { color: var(--accent); }
.po-table th[data-sort]::after { content: ' \2195'; opacity: 0.3; font-size: 10px; }
.po-table th[data-sort].asc::after { content: ' \2191'; opacity: 1; }
.po-table th[data-sort].desc::after { content: ' \2193'; opacity: 1; }

/* Dashboard table variant */
.po-table--dashboard {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  background: transparent;
  font-size: var(--text-sm);
  table-layout: fixed;
}

.po-table--dashboard colgroup .col-chk { width: 36px; }
.po-table--dashboard colgroup .col-fecha { width: 7%; }
.po-table--dashboard colgroup .col-nfra { width: 10%; }
.po-table--dashboard colgroup .col-prov { width: 16%; }
.po-table--dashboard colgroup .col-cat { width: 16%; }
.po-table--dashboard colgroup .col-concepto { width: auto; }
.po-table--dashboard colgroup .col-subtotal { width: 7%; }
.po-table--dashboard colgroup .col-total { width: 7%; }
.po-table--dashboard colgroup .col-estado { width: 88px; }

.po-table--dashboard .dash-empty-row td {
  text-align: center !important;
  padding: 14px !important;
  color: var(--muted);
  font-size: var(--text-sm);
  cursor: default !important;
}

.po-table--dashboard .dash-empty-row:hover { background: transparent !important; }

.po-table--dashboard thead th {
  background: var(--bg-subtle);
  color: var(--muted);
  font-weight: var(--font-semibold);
  padding: 7px 8px;
  text-align: left;
  white-space: nowrap;
  position: sticky;
  top: 0;
  font-size: var(--text-xs);
  text-transform: none;
  letter-spacing: 0;
  border-top: none;
  border-bottom: var(--border-width) solid var(--border);
  z-index: 10;
  box-shadow: inset 0 1px 0 var(--border);
}

.po-table--dashboard thead th:last-child { text-align: center; }
.po-table--dashboard thead th.num { text-align: right; }
.po-table--dashboard thead th.sortable { cursor: pointer; user-select: none; }
.po-table--dashboard thead th.sortable:hover { color: var(--accent); }
.po-table--dashboard thead th.sorted .sort-arrow { opacity: 1; color: var(--accent); }

.po-table--dashboard tbody tr {
  cursor: pointer;
  height: 42px;
}

.po-table--dashboard tbody tr:not(:last-child) td { border-bottom: 1px solid var(--border-light); }
.po-table--dashboard tbody tr.zebra-alt:not(.group-header):not(.section-sep) { background: var(--bg); }
.po-table--dashboard tbody tr:hover { background: color-mix(in srgb, var(--accent) 5%, var(--bg)); }

.po-table--dashboard td {
  padding: 8px 8px;
  line-height: 1.3;
  white-space: nowrap;
  position: relative;
  z-index: 1;
}

.po-table--dashboard td:last-child { text-align: center; }
.po-table--dashboard td.truncatable { overflow: hidden; text-overflow: ellipsis; max-width: 0; }
.po-table--dashboard .num { text-align: right; font-variant-numeric: tabular-nums; font-weight: var(--font-medium); }

.po-table--dashboard tbody tr.expected-row td,
.po-table--dashboard tbody tr.expected-row td.num {
  color: var(--auto);
}

.po-table--dashboard tbody tr.auto-row td { color: var(--accent); }

.po-table--dashboard .dash-type-tag {
  display: inline-block;
  font-size: 9px;
  font-weight: var(--font-semibold);
  padding: 1px 6px;
  border-radius: var(--radius-sm);
  letter-spacing: 0.2px;
}

.po-table--dashboard .dash-type-tag.tag-auto {
  background: color-mix(in srgb, var(--accent) 10%, var(--card));
  color: var(--accent);
}

.po-table--dashboard .dash-type-tag.tag-expected {
  background: color-mix(in srgb, var(--auto) 10%, var(--card));
  color: var(--auto);
}

.po-table--dashboard .row-actions {
  display: none;
  gap: 2px;
  align-items: center;
}

.po-table--dashboard tbody tr:hover .row-actions { display: inline-flex; }
.po-table--dashboard tbody tr:hover .dash-status-pill { display: none; }

.po-table--dashboard .row-actions button {
  width: 26px;
  height: 26px;
  border: none;
  background: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--duration-fast);
  padding: 0;
}

.po-table--dashboard .row-actions button svg {
  width: 15px;
  height: 15px;
  stroke: currentColor;
  fill: none;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.po-table--dashboard .row-actions button.act-approve { color: var(--success); opacity: 0.5; }
.po-table--dashboard .row-actions button.act-approve:hover { opacity: 1; background: var(--success-light); }
.po-table--dashboard .row-actions button.act-edit { color: var(--accent); opacity: 0.5; }
.po-table--dashboard .row-actions button.act-edit:hover { opacity: 1; background: var(--accent-light); }
.po-table--dashboard .row-actions button.act-delete { color: var(--error); opacity: 0.5; }
.po-table--dashboard .row-actions button.act-delete:hover { opacity: 1; background: var(--error-light); }

.po-table--dashboard tbody tr.group-header td {
  background: var(--border);
  padding: 6px 8px !important;
  font-size: var(--text-xs);
  font-weight: var(--font-bold);
  color: var(--text);
  border-bottom: 1px solid var(--border) !important;
  cursor: pointer;
  user-select: none;
}

.po-table--dashboard tbody tr.group-header td .gi {
  display: inline-block;
  width: 14px;
  font-size: 9px;
  color: var(--muted);
}

.po-table--dashboard tbody tr.group-header td .gc {
  font-weight: var(--font-normal);
  color: var(--muted);
  font-size: 10px;
  margin-left: 4px;
}

.po-table--dashboard tbody tr.group-header td .gs {
  float: right;
  font-variant-numeric: tabular-nums;
  font-size: 11px;
  font-weight: var(--font-bold);
  color: var(--text);
}

.po-table--dashboard tbody tr.section-sep td {
  padding: 6px 10px !important;
  font-size: var(--text-xs);
  font-weight: var(--font-semibold);
  letter-spacing: 0.3px;
  border-bottom: 1px solid var(--border) !important;
  border-top: 1px solid var(--border) !important;
}

.po-table--dashboard tbody tr.section-sep td:first-child {
  width: 36px;
  text-align: center;
  padding-right: 0 !important;
}

.po-table--dashboard tbody tr.section-sep.auto-sep td {
  background: var(--bg-subtle);
  color: var(--muted);
  border-color: var(--border) !important;
}

.po-table--dashboard tbody tr.section-sep.expected-sep td {
  background: color-mix(in srgb, var(--auto) 8%, var(--card));
  color: var(--auto);
  border-color: color-mix(in srgb, var(--auto) 15%, var(--border)) !important;
}

.po-table--dashboard .expand-row { display: none; }
.po-table--dashboard .expand-row.open { display: table-row; }
.po-table--dashboard .expand-content { padding: 0; background: var(--bg-subtle); }
.po-table--dashboard .expand-table { width: 100%; border-collapse: collapse; font-size: var(--text-sm); }
.po-table--dashboard .expand-table th {
  background: var(--bg);
  padding: 6px 12px;
  text-align: left;
  font-weight: var(--font-bold);
  color: var(--muted);
  font-size: 9px;
  text-transform: uppercase;
  border-bottom: 1px solid var(--border);
}

.po-table--dashboard .expand-table td {
  padding: 8px 12px;
  border-bottom: 1px solid var(--border-light);
}

.po-table--dashboard .sort-arrow {
  font-size: 9px;
  margin-left: 2px;
  opacity: 0.4;
}

.po-table--dashboard .dash-status-pill {
  padding: 3px 10px;
  border-radius: 16px;
  font-size: 10px;
  font-weight: var(--font-semibold);
  display: inline-block;
  white-space: nowrap;
  text-align: center;
  border: 1px solid transparent;
  min-width: 72px;
}

.po-table--dashboard .dash-status-pill.pending {
  background: var(--bg-subtle);
  color: var(--muted);
  border-color: var(--border);
}

.po-table--dashboard .dash-status-pill.alerta {
  background: var(--warning-light);
  color: var(--warning);
  border-color: var(--warning);
}

.po-table--dashboard .dash-status-pill.ok {
  background: var(--success-light);
  color: var(--success);
  border-color: var(--success);
}

.po-table--dashboard .dash-status-pill.flagged {
  background: var(--error-light);
  color: var(--error);
  border-color: var(--error);
}

.po-table--dashboard .dash-status-pill.expected {
  background: var(--auto-light);
  color: var(--auto);
  border-color: var(--auto);
  border-style: dashed;
}

.po-table--dashboard tfoot td {
  background: var(--card);
  font-size: var(--text-xs);
  padding: 8px 8px;
  position: sticky;
  bottom: 0;
  z-index: 10;
  border-top: 1px solid var(--border);
  color: var(--muted);
}

.po-table--dashboard tfoot td.ft-label { font-weight: var(--font-semibold); color: var(--text-secondary); }
.po-table--dashboard tfoot td.ft-val {
  font-variant-numeric: tabular-nums;
  text-align: right;
  color: var(--text-secondary);
  font-weight: var(--font-semibold);
}

.po-table--dashboard tfoot td.ft-total {
  font-variant-numeric: tabular-nums;
  text-align: right;
  color: var(--text);
  font-weight: var(--font-semibold);
}

/* ── Tablet (≤900px): hide categoría, compact padding ── */
@media (max-width: 900px) {
  .po-table--dashboard td { padding: 6px 6px; font-size: var(--text-xs); }
  .po-table--dashboard th:nth-child(5),
  .po-table--dashboard td:nth-child(5) { display: none; } /* categoría */
  .po-table--dashboard td.truncatable { max-width: 140px; }
}

/* ── Mobile (≤768px): show checkbox, fecha, proveedor, total, estado dot ── */
@media (max-width: 768px) {
  .po-table--dashboard { table-layout: auto; width: 100%; }
  .po-table--dashboard colgroup { display: none; }
  /* Hidden columns: N.Factura(3), Categoria(5), Concepto(6), Subtotal(7) */
  .po-table--dashboard th:nth-child(3),
  .po-table--dashboard td:nth-child(3),
  .po-table--dashboard th:nth-child(5),
  .po-table--dashboard td:nth-child(5),
  .po-table--dashboard th:nth-child(6),
  .po-table--dashboard td:nth-child(6),
  .po-table--dashboard th:nth-child(7),
  .po-table--dashboard td:nth-child(7) {
    display: none;
  }
  .po-table--dashboard td,
  .po-table--dashboard th { padding: 8px 6px; font-size: var(--text-sm); }
  .po-table--dashboard td { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  /* Row separation */
  .po-table--dashboard tbody tr:not(:last-child) td { border-bottom: 1px solid var(--border); }
  .po-table--dashboard tbody tr.zebra-alt:not(.group-header):not(.section-sep) {
    background: color-mix(in srgb, var(--bg-subtle) 60%, var(--card));
  }
  /* Rows tappable — cursor pointer for touch feedback */
  .po-table--dashboard tbody tr[data-idx] { cursor: pointer; }
  .po-table--dashboard tbody tr[data-idx]:active { background: color-mix(in srgb, var(--accent) 6%, var(--card)); }
  /* Checkbox — fixed narrow */
  .po-table--dashboard th:first-child,
  .po-table--dashboard td:first-child { width: 28px; padding-left: 6px; padding-right: 2px; }
  /* Fecha — compact date */
  .po-table--dashboard th:nth-child(2),
  .po-table--dashboard td:nth-child(2) { width: 76px; white-space: nowrap; }
  /* Proveedor — force truncation to fill remaining space */
  .po-table--dashboard td:nth-child(4) { max-width: 1px; }
  /* Total — numeric fixed */
  .po-table--dashboard th:nth-child(8),
  .po-table--dashboard td:nth-child(8) { width: 62px; white-space: nowrap; text-align: right; }
  /* Estado — just the dot, centered, no flex needed */
  .po-table--dashboard th:last-child,
  .po-table--dashboard td:last-child {
    width: 28px; text-align: center; white-space: nowrap; overflow: visible; padding-right: 6px;
  }
  /* Touch-friendly checkboxes */
  .po-table--dashboard .row-checkbox { width: 16px; height: 16px; }
  /* Status pill → colored dot on mobile */
  .po-table--dashboard .dash-status-pill {
    display: inline-block; vertical-align: middle;
    font-size: 0; line-height: 0; overflow: hidden;
    width: 10px; height: 10px; min-width: 10px;
    border-radius: 50%; padding: 0;
    box-shadow: 0 0 0 2px color-mix(in srgb, currentColor 15%, transparent);
  }
  .po-table--dashboard .dash-status-pill.ok { background: var(--success); border-color: var(--success); color: var(--success); }
  .po-table--dashboard .dash-status-pill.flagged { background: var(--error); border-color: var(--error); color: var(--error); }
  .po-table--dashboard .dash-status-pill.alerta { background: var(--warning); border-color: var(--warning); color: var(--warning); }
  .po-table--dashboard .dash-status-pill.pending { background: var(--border); border-color: var(--border); color: var(--border); }
  .po-table--dashboard .dash-status-pill.expected { background: var(--auto); border-color: var(--auto); color: var(--auto); }
  /* Row actions: HIDDEN on mobile — actions via tap (open) or long-press (bottom sheet) */
  .po-table--dashboard .row-actions { display: none !important; }
  /* Contain table frame */
  .po-table-frame { overflow-x: hidden; }
}

/* ── Small mobile (≤480px): hide fecha too, max compact ── */
@media (max-width: 480px) {
  .po-table--dashboard th:nth-child(2),
  .po-table--dashboard td:nth-child(2) { display: none; }
  .po-table--dashboard td { padding: 6px 4px; font-size: 12px; }
  .po-table--dashboard th { padding: 6px 4px; font-size: 11px; }
  /* Shrink avatars on small mobile */
  .po-table--dashboard .po-avatar--sm { width: 20px; height: 20px; font-size: 8px; }
  .po-table--dashboard .po-avatar--sm img { width: 20px; height: 20px; }
  /* Tighter checkbox column */
  .po-table--dashboard th:first-child,
  .po-table--dashboard td:first-child { width: 24px; padding-left: 4px; }
  .po-table--dashboard .row-checkbox { width: 14px; height: 14px; }
}

/* ── C11. po-tabs — Tab navigation ── */
.po-tabs {
  display: flex;
  gap: 0;
  border-bottom: var(--border-width-2) solid var(--border);
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}
.po-tabs::-webkit-scrollbar { display: none; }

.po-tab {
  padding: 10px 16px;
  font-size: var(--text-sm);
  font-weight: var(--font-medium);
  color: var(--muted);
  cursor: pointer;
  border: none;
  background: none;
  white-space: nowrap;
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  transition: color var(--duration-fast), border-color var(--duration-fast);
  font-family: inherit;
}
.po-tab:hover { color: var(--text); }
.po-tab.is-active {
  color: var(--accent);
  border-bottom-color: var(--accent);
  font-weight: var(--font-semibold);
}

/* ── C12. po-modal — Dialog ── */
.po-modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  z-index: var(--z-modal);
  display: flex;
  align-items: center;
  justify-content: center;
  animation: fadeIn 0.15s ease;
}
.po-modal {
  background: var(--card);
  border-radius: var(--radius-lg);
  max-width: 600px;
  width: 90%;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: var(--shadow-lg);
  animation: popIn 0.2s ease;
}
.po-modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}
.po-modal-header h3 { font-size: 15px; font-weight: var(--font-bold); margin: 0; }
.po-modal-body { padding: 20px; }
.po-modal-footer {
  padding: 12px 20px;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}
.po-modal-close {
  background: none; border: none; font-size: 20px;
  cursor: pointer; color: var(--muted); line-height: 1; padding: 0 4px;
}
.po-modal-close:hover { color: var(--text); }

@media (max-width: 640px) {
  .po-modal { width: 95%; max-width: none; align-self: flex-end; border-radius: var(--radius-lg) var(--radius-lg) 0 0; }
}

/* ── C13. po-breadcrumb — Navigation path ── */
.po-breadcrumb {
  padding: 8px 24px;
  font-size: var(--text-sm);
  color: var(--muted);
  background: var(--card);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: 0;
}
.po-breadcrumb a { color: var(--accent); text-decoration: none; }
.po-breadcrumb a:hover { text-decoration: underline; }
.po-breadcrumb-sep { margin: 0 6px; opacity: 0.4; }
.po-breadcrumb-current { color: var(--text); font-weight: var(--font-medium); }

/* ── C14. po-drop-zone — File upload area ── */
.po-drop-zone {
  border: var(--border-width-2) dashed var(--border);
  border-radius: var(--radius-lg);
  padding: 48px 40px;
  text-align: center;
  cursor: pointer;
  transition: border-color var(--duration-fast), background var(--duration-fast);
  background: var(--card);
}
.po-drop-zone:hover,
.po-drop-zone.is-dragover {
  border-color: var(--accent);
  background: var(--accent-light);
}
.po-drop-zone__icon { width: 48px; height: 48px; margin: 0 auto 12px; color: var(--accent); opacity: 0.5; }
.po-drop-zone__title { font-size: 17px; font-weight: var(--font-bold); margin-bottom: 6px; }
.po-drop-zone__text { font-size: var(--text-base); color: var(--muted); }
.po-drop-zone input[type="file"] { display: none; }

@media (max-width: 640px) {
  .po-drop-zone { padding: 24px 16px; }
  .po-drop-zone__title { font-size: 15px; }
}

/* ── C15. po-progress + po-spinner + po-skeleton ── */
.po-progress {
  width: 100%;
  height: 6px;
  background: var(--bg-subtle);
  border-radius: var(--radius-full);
  overflow: hidden;
}
.po-progress__fill {
  height: 100%;
  background: var(--accent);
  border-radius: var(--radius-full);
  transition: width var(--duration-slow) ease;
}
.po-progress--success .po-progress__fill { background: var(--success); }

.po-spinner {
  display: inline-block;
  width: 20px; height: 20px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: po-spin 0.6s linear infinite;
}
.po-spinner--sm { width: 14px; height: 14px; border-width: 1.5px; }
.po-spinner--lg { width: 32px; height: 32px; border-width: 3px; }

.po-skeleton {
  background: linear-gradient(90deg, var(--border-light) 25%, var(--border) 50%, var(--border-light) 75%);
  background-size: 200% 100%;
  animation: po-shimmer 1.5s ease-in-out infinite;
  border-radius: var(--radius-sm);
  color: transparent;
}

/* ── C16. po-search — Search input with icon ── */
.po-search {
  position: relative;
  display: flex;
  align-items: center;
}
.po-search .po-input { padding-left: 36px; padding-right: 32px; }
.po-search__icon {
  position: absolute;
  left: 10px;
  color: var(--muted);
  pointer-events: none;
  width: 16px; height: 16px;
}
.po-search__clear {
  position: absolute;
  right: 8px;
  background: none;
  border: none;
  color: var(--muted);
  cursor: pointer;
  padding: 4px;
  font-size: 16px;
  line-height: 1;
  display: none;
}
.po-search__clear:hover { color: var(--text); }
.po-search.has-value .po-search__clear { display: block; }

/* ── C17. po-empty — Empty state placeholder ── */
.po-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 48px 24px;
  text-align: center;
  color: var(--muted);
}
.po-empty__icon { width: 48px; height: 48px; margin-bottom: 12px; opacity: 0.4; }
.po-empty__title { font-size: var(--text-lg); font-weight: var(--font-semibold); color: var(--text-secondary); margin-bottom: 4px; }
.po-empty__text { font-size: var(--text-base); max-width: 360px; }

/* ── C18. po-view — Tab-panel visibility ── */
.po-view { display: none; }
.po-view.is-active { display: block; }

/* ── C19. po-alert — Inline messages ── */
.po-alert {
  padding: 12px 16px;
  border-radius: var(--radius-md);
  font-size: var(--text-sm);
  display: flex;
  align-items: flex-start;
  gap: 10px;
  line-height: var(--leading-normal);
}
.po-alert--info { background: var(--info-light); color: var(--info); }
.po-alert--warn { background: var(--warning-light); color: var(--warning); }
.po-alert--err { background: var(--error-light); color: var(--error); }
.po-alert--ok { background: var(--success-light); color: var(--success); }

/* ── C20. po-accordion — Collapsible sections ── */
.po-accordion {}
.po-accordion-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  cursor: pointer;
  font-weight: var(--font-semibold);
  font-size: var(--text-base);
  border-bottom: 1px solid var(--border);
  user-select: none;
  transition: background var(--duration-fast);
}
.po-accordion-header:hover { background: var(--bg-subtle); }
.po-accordion-header .icon { transition: transform var(--duration-fast); }
.po-accordion-header.is-open .icon { transform: rotate(180deg); }
.po-accordion-body { display: none; padding: 16px; }
.po-accordion-body.is-open { display: block; }

/* ── C21. po-toggle — Switch ── */
.po-toggle {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  font-size: var(--text-base);
}
.po-toggle__switch {
  position: relative;
  width: 36px; height: 20px;
  background: var(--border);
  border-radius: var(--radius-full);
  transition: background var(--duration-fast);
  flex-shrink: 0;
}
.po-toggle__switch::after {
  content: '';
  position: absolute;
  top: 2px; left: 2px;
  width: 16px; height: 16px;
  background: #fff;
  border-radius: 50%;
  transition: transform var(--duration-fast);
  box-shadow: var(--shadow-sm);
}
.po-toggle input { display: none; }
.po-toggle input:checked + .po-toggle__switch { background: var(--accent); }
.po-toggle input:checked + .po-toggle__switch::after { transform: translateX(16px); }

/* ═══════════════════════════════════════════════════════════
   ANIMATIONS — Design System standardized
   ═══════════════════════════════════════════════════════════ */
@keyframes po-spin { to { transform: rotate(360deg); } }
@keyframes po-pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.5; } }
@keyframes po-shimmer { 0% { background-position: 200% 0; } 100% { background-position: -200% 0; } }
@keyframes po-slide-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }
@keyframes po-fade-in { from { opacity: 0; } to { opacity: 1; } }

/* ── Skeleton loading — shows page structure with animated placeholders ── */
.po-skeleton {
  color: transparent !important;
  background: linear-gradient(90deg, var(--border) 25%, var(--bg-subtle) 50%, var(--border) 75%);
  background-size: 200% 100%;
  animation: po-shimmer 1.5s ease infinite;
  border-radius: var(--radius-sm);
  pointer-events: none;
  min-width: 3ch;
}
.po-skeleton::selection { background: transparent; }

/* ═══════════════════════════════════════════════════════════
   RESPONSIVE — Global breakpoints
   ═══════════════════════════════════════════════════════════ */

/* ── 19. Responsive ── */
@media (max-width: 1024px) {
  .po-nav-item span:not(.icon) {
    display: none;
  }
  .po-nav-item {
    padding: 8px 10px;
  }
}

@media (max-width: 768px) {
  .po-header {
    padding: 0 16px;
    gap: 8px;
  }
  .po-nav-item span:not(.icon) {
    display: none;
  }
}

@media (max-width: 640px) {
  .po-header {
    padding: 0 10px;
    gap: 4px;
  }
  .po-header-brand-name { display: none; }
  .po-header-left { gap: 6px; }
  .po-nav { gap: 0; overflow-x: auto; scrollbar-width: none; -webkit-overflow-scrolling: touch; }
  .po-nav::-webkit-scrollbar { display: none; }
  .po-nav-item { padding: 8px 8px; }
  .po-header-right { gap: 4px; }
}

@media (max-width: 480px) {
  .po-breadcrumb { flex-wrap: wrap; padding: 8px 12px; gap: 4px; }
  /* Switch from app-shell layout to natural page scroll on small mobile */
  html, body { height: auto; }
  body { min-height: 100vh; }
  main { flex: none; overflow: visible; min-height: auto; }
}

/* ═══════════════════════════════════════════════════════════
   REFINEMENTS — Enhanced interaction states
   ═══════════════════════════════════════════════════════════ */

/* Buttons — tactile press feedback */
.po-btn:active:not(:disabled):not(.is-loading) { transform: scale(0.97); }

/* Buttons — outline variant */
.po-btn--outline {
  background: transparent;
  color: var(--accent);
  border-color: var(--accent);
}
.po-btn--outline:hover { background: var(--accent-light); }

/* Cards — interactive variant with hover lift */
.po-card--interactive {
  transition: box-shadow var(--duration-fast), border-color var(--duration-fast), transform var(--duration-fast);
  cursor: pointer;
}
.po-card--interactive:hover {
  box-shadow: var(--shadow-lg);
  border-color: var(--accent);
  transform: translateY(-1px);
}

/* KPI — accent border variants */
.po-kpi--accent { border-left: 3px solid var(--accent); }
.po-kpi--success-border { border-left: 3px solid var(--success); }
.po-kpi--warning-border { border-left: 3px solid var(--warning); }
.po-kpi--error-border { border-left: 3px solid var(--error); }

/* Badge — pulse animation for live data */
.po-badge--pulse::before { animation: po-pulse 2s ease-in-out infinite; }

/* Badge — large variant */
.po-badge--lg { font-size: var(--text-xs); padding: 3px 10px; }

/* Table — selected row */
.po-table tr.is-selected td { background: var(--accent-light); }
.po-table tr.is-selected:hover td { background: var(--accent-light); }

/* Alert — with close button */
.po-alert--dismissible { justify-content: space-between; }
.po-alert__close {
  background: none;
  border: none;
  color: currentColor;
  opacity: 0.6;
  cursor: pointer;
  font-size: 16px;
  line-height: 1;
  padding: 0 2px;
  flex-shrink: 0;
}
.po-alert__close:hover { opacity: 1; }

/* ═══════════════════════════════════════════════════════════
   NEW COMPONENTS — PerilDS v1.1.0
   ═══════════════════════════════════════════════════════════ */

/* ── C22. po-tooltip — CSS-only tooltips via data-tooltip ── */
[data-tooltip] {
  position: relative;
}
[data-tooltip]::after {
  content: attr(data-tooltip);
  position: absolute;
  bottom: calc(100% + 8px);
  left: 50%;
  transform: translateX(-50%) translateY(4px);
  padding: 5px 10px;
  background: var(--gray-900);
  color: #fff;
  font-size: var(--text-xs);
  font-weight: var(--font-medium);
  border-radius: var(--radius-sm);
  white-space: nowrap;
  pointer-events: none;
  opacity: 0;
  transition: opacity var(--duration-fast), transform var(--duration-fast);
  z-index: var(--z-tooltip);
  line-height: var(--leading-snug);
}
[data-tooltip]::before {
  content: '';
  position: absolute;
  bottom: calc(100% + 4px);
  left: 50%;
  transform: translateX(-50%) translateY(4px);
  border: 4px solid transparent;
  border-top-color: var(--gray-900);
  pointer-events: none;
  opacity: 0;
  transition: opacity var(--duration-fast), transform var(--duration-fast);
  z-index: var(--z-tooltip);
}
[data-tooltip]:hover::after,
[data-tooltip]:hover::before {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ── C23. po-tag — Removable tags / labels ── */
.po-tag {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 10px;
  background: var(--bg-subtle);
  border: var(--border-width) solid var(--border);
  border-radius: var(--radius-full);
  font-size: var(--text-xs);
  font-weight: var(--font-semibold);
  color: var(--text-secondary);
  white-space: nowrap;
  line-height: var(--leading-snug);
}
.po-tag__remove {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: transparent;
  border: none;
  color: var(--muted);
  font-size: 14px;
  cursor: pointer;
  line-height: 1;
  padding: 0;
  margin-left: 2px;
  margin-right: -4px;
  transition: background var(--duration-fast), color var(--duration-fast);
}
.po-tag__remove:hover { background: var(--error-light); color: var(--error); }
.po-tag--accent { background: var(--accent-light); border-color: transparent; color: var(--accent); }
.po-tag--success { background: var(--success-light); border-color: transparent; color: var(--success); }
.po-tag--warning { background: var(--warning-light); border-color: transparent; color: var(--warning); }
.po-tag--error { background: var(--error-light); border-color: transparent; color: var(--error); }
.po-tag--ai { background: var(--auto-light); border-color: transparent; color: var(--auto); }

/* ── C24. po-stat — Metric with trend indicator ── */
.po-stat {
  background: var(--card);
  border: var(--border-width) solid var(--border);
  border-radius: var(--radius-md);
  padding: 18px 20px;
  box-shadow: var(--shadow-sm);
}
.po-stat__label {
  font-size: var(--text-xs);
  font-weight: var(--font-semibold);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--muted);
  margin-bottom: 4px;
}
.po-stat__row {
  display: flex;
  align-items: baseline;
  gap: 10px;
}
.po-stat__value {
  font-size: var(--text-2xl);
  font-weight: var(--font-bold);
  color: var(--text);
  line-height: var(--leading-none);
  font-variant-numeric: tabular-nums;
}
.po-stat__trend {
  font-size: var(--text-xs);
  font-weight: var(--font-bold);
  display: inline-flex;
  align-items: center;
  gap: 2px;
  padding: 2px 8px;
  border-radius: var(--radius-full);
}
.po-stat__trend--up { color: var(--success); background: var(--success-light); }
.po-stat__trend--down { color: var(--error); background: var(--error-light); }
.po-stat__trend--flat { color: var(--muted); background: var(--bg-subtle); }
.po-stat__sub {
  font-size: var(--text-xs);
  color: var(--muted);
  margin-top: 4px;
}

/* ── C25. po-timeline — Vertical event list ── */
.po-timeline {
  display: flex;
  flex-direction: column;
  position: relative;
  padding-left: 28px;
}
.po-timeline::before {
  content: '';
  position: absolute;
  left: 7px;
  top: 6px;
  bottom: 6px;
  width: 2px;
  background: var(--border);
  border-radius: 1px;
}
.po-timeline__item {
  position: relative;
  padding-bottom: 20px;
}
.po-timeline__item:last-child { padding-bottom: 0; }
.po-timeline__dot {
  position: absolute;
  left: -24px;
  top: 4px;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--card);
  border: 2px solid var(--border);
  z-index: 1;
}
.po-timeline__item--active .po-timeline__dot {
  border-color: var(--accent);
  background: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-light);
}
.po-timeline__item--success .po-timeline__dot { border-color: var(--success); background: var(--success); }
.po-timeline__item--error .po-timeline__dot { border-color: var(--error); background: var(--error); }
.po-timeline__item--warning .po-timeline__dot { border-color: var(--warning); background: var(--warning); }
.po-timeline__title {
  font-size: var(--text-sm);
  font-weight: var(--font-semibold);
  color: var(--text);
  line-height: var(--leading-tight);
}
.po-timeline__meta {
  font-size: var(--text-xs);
  color: var(--muted);
  margin-top: 2px;
}
.po-timeline__detail {
  font-size: var(--text-xs);
  color: var(--text-secondary);
  margin-top: 4px;
}

/* ── C26. po-avatar — Initials circle + logo image ── */
.po-avatar {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: 22%;
  background: var(--accent-light);
  color: var(--accent);
  font-size: var(--text-xs);
  font-weight: var(--font-bold);
  text-transform: uppercase;
  flex-shrink: 0;
  letter-spacing: -0.02em;
  border: 1.5px solid var(--border);
  box-shadow: var(--shadow-sm);
}
.po-avatar--sm { width: 24px; height: 24px; font-size: 9px; }
.po-avatar--lg { width: 40px; height: 40px; font-size: var(--text-sm); }
.po-avatar--success { background: var(--success-light); color: var(--success); }
.po-avatar--warning { background: var(--warning-light); color: var(--warning); }
.po-avatar--error { background: var(--error-light); color: var(--error); }
.po-avatar--auto { background: var(--auto-light); color: var(--auto); }
.po-avatar--muted { background: var(--bg-subtle); color: var(--muted); }
/* Image variant — logo with initials fallback (squircle) */
.po-avatar--img {
  position: relative;
  overflow: hidden;
  padding: 0;
  background: var(--bg);
  border-radius: 22%;
}
.po-avatar--img img {
  position: absolute;
  inset: 3px;
  width: calc(100% - 6px);
  height: calc(100% - 6px);
  object-fit: contain;
  border-radius: 0;
}

/* ── C27. po-dl — Description list (key-value pairs) ── */
.po-dl {
  display: grid;
  grid-template-columns: minmax(100px, auto) 1fr;
  gap: 6px 16px;
  font-size: var(--text-sm);
  align-items: baseline;
}
.po-dl__dt {
  font-weight: var(--font-medium);
  color: var(--muted);
  white-space: nowrap;
}
.po-dl__dd {
  color: var(--text);
  word-break: break-word;
}
.po-dl--striped .po-dl__dt,
.po-dl--striped .po-dl__dd {
  padding: 6px 8px;
}
.po-dl--striped .po-dl__dt:nth-of-type(odd),
.po-dl--striped .po-dl__dd:nth-of-type(odd) {
  background: var(--bg-subtle);
  border-radius: var(--radius-sm);
}

/* ── C28. po-divider — Section separator ── */
.po-divider {
  display: flex;
  align-items: center;
  gap: 12px;
  color: var(--muted);
  font-size: var(--text-xs);
  font-weight: var(--font-semibold);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin: var(--space-6) 0;
}
.po-divider::before,
.po-divider::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--border);
}
.po-divider--plain {
  height: 1px;
  background: var(--border);
  display: block;
  margin: var(--space-4) 0;
}

/* ── C29. po-stepper — Process flow indicator ── */
.po-stepper {
  display: flex;
  align-items: center;
}
.po-step {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: var(--text-sm);
  color: var(--muted);
  white-space: nowrap;
}
.po-step__dot {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--bg-subtle);
  border: 2px solid var(--border);
  font-size: var(--text-xs);
  font-weight: var(--font-bold);
  color: var(--muted);
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background var(--duration-fast), border-color var(--duration-fast);
}
.po-step--active .po-step__dot {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  box-shadow: 0 0 0 3px var(--accent-light);
}
.po-step--active { color: var(--accent); font-weight: var(--font-semibold); }
.po-step--done .po-step__dot {
  background: var(--success);
  border-color: var(--success);
  color: #fff;
}
.po-step--done { color: var(--success); }
.po-stepper__line {
  flex: 0 0 40px;
  height: 2px;
  background: var(--border);
  margin: 0 4px;
}
.po-stepper__line--done { background: var(--success); }

@media (max-width: 640px) {
  .po-stepper { flex-wrap: wrap; gap: 8px; }
  .po-stepper__line { flex: 0 0 16px; }
  .po-step { font-size: var(--text-xs); gap: 4px; }
  .po-step__dot { width: 24px; height: 24px; }
}
