/* ============================================================
   Kappino — AI Inventory Automation Engine UI
   Scoped to .view[data-view="ai-inventory"]. All classes are
   aiv-* prefixed so they never collide with styles.css /
   marketing.css / whatsapp.css. Modal + toast classes render at
   document.body level, so they are intentionally unscoped.
   ============================================================ */
.view[data-view="ai-inventory"] {
  --aiv-accent: #4f46e5;
  --aiv-accent-dark: #4338ca;
  --aiv-accent-soft: #eef0fe;
  --aiv-ink: #0f172a;
  --aiv-muted: #64748b;
  --aiv-line: #e6e9ee;
  --aiv-card: #ffffff;
  --aiv-radius: 14px;
  --aiv-shadow: 0 1px 2px rgba(15, 23, 42, .04), 0 8px 24px rgba(15, 23, 42, .06);
  color: var(--aiv-ink);
}

/* ---- tabs ---- */
.view[data-view="ai-inventory"] .aiv-tabs {
  display: flex; gap: 4px; flex-wrap: wrap;
  border-bottom: 1px solid var(--aiv-line); margin: 14px 0 18px;
}
.view[data-view="ai-inventory"] .aiv-tab {
  appearance: none; border: 0; background: transparent; cursor: pointer;
  padding: 10px 16px; font-size: 13.5px; font-weight: 600; color: var(--aiv-muted);
  border-bottom: 2px solid transparent; margin-bottom: -1px; border-radius: 8px 8px 0 0;
  transition: color .15s, border-color .15s, background .15s;
}
.view[data-view="ai-inventory"] .aiv-tab:hover { color: var(--aiv-accent-dark); background: var(--aiv-accent-soft); }
.view[data-view="ai-inventory"] .aiv-tab.active { color: var(--aiv-accent-dark); border-bottom-color: var(--aiv-accent); }
.view[data-view="ai-inventory"] .aiv-panel { min-height: 320px; }

/* ---- loading / empty ---- */
.view[data-view="ai-inventory"] .aiv-loading,
.view[data-view="ai-inventory"] .aiv-empty {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 10px; padding: 56px 20px; color: var(--aiv-muted); text-align: center;
}
.view[data-view="ai-inventory"] .aiv-spinner {
  width: 30px; height: 30px; border-radius: 50%;
  border: 3px solid var(--aiv-line); border-top-color: var(--aiv-accent);
  animation: aiv-spin .8s linear infinite;
}
@keyframes aiv-spin { to { transform: rotate(360deg); } }
.view[data-view="ai-inventory"] .aiv-empty-ico { font-size: 30px; }
.view[data-view="ai-inventory"] .aiv-empty-title { font-weight: 700; color: var(--aiv-ink); font-size: 15px; }

/* ---- layout ---- */
.view[data-view="ai-inventory"] .aiv-section-title { font-size: 15px; font-weight: 700; }
.view[data-view="ai-inventory"] .aiv-section-sub { font-size: 12.5px; color: var(--aiv-muted); }
.view[data-view="ai-inventory"] .aiv-spacer { height: 14px; }
.view[data-view="ai-inventory"] .aiv-grid { display: grid; gap: 14px; }
.view[data-view="ai-inventory"] .aiv-grid.cols-2 { grid-template-columns: repeat(2, 1fr); }
.view[data-view="ai-inventory"] .aiv-grid.cols-4 { grid-template-columns: repeat(4, 1fr); }
@media (max-width: 1100px) {
  .view[data-view="ai-inventory"] .aiv-grid.cols-4 { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 680px) {
  .view[data-view="ai-inventory"] .aiv-grid.cols-2,
  .view[data-view="ai-inventory"] .aiv-grid.cols-4 { grid-template-columns: 1fr; }
}

/* ---- stat tiles ---- */
.view[data-view="ai-inventory"] .aiv-stat {
  background: var(--aiv-card); border: 1px solid var(--aiv-line);
  border-radius: var(--aiv-radius); padding: 16px; box-shadow: var(--aiv-shadow);
}
.view[data-view="ai-inventory"] .aiv-stat-label {
  font-size: 11.5px; font-weight: 600; color: var(--aiv-muted);
  text-transform: uppercase; letter-spacing: .04em;
}
.view[data-view="ai-inventory"] .aiv-stat-value { font-size: 24px; font-weight: 800; margin-top: 6px; }
.view[data-view="ai-inventory"] .aiv-stat-foot { font-size: 12px; color: var(--aiv-muted); margin-top: 4px; }
.view[data-view="ai-inventory"] .aiv-stat-foot.up { color: #0a7d3f; }
.view[data-view="ai-inventory"] .aiv-stat-foot.down { color: #c0392b; }

/* ---- card ---- */
.view[data-view="ai-inventory"] .aiv-card {
  background: var(--aiv-card); border: 1px solid var(--aiv-line);
  border-radius: var(--aiv-radius); box-shadow: var(--aiv-shadow); overflow: hidden;
}
.view[data-view="ai-inventory"] .aiv-card-head {
  display: flex; align-items: flex-start; justify-content: space-between; gap: 12px;
  padding: 14px 16px; border-bottom: 1px solid var(--aiv-line);
}
.view[data-view="ai-inventory"] .aiv-card-title { font-weight: 700; font-size: 14px; }
.view[data-view="ai-inventory"] .aiv-card-sub { font-size: 12px; color: var(--aiv-muted); margin-top: 2px; }
.view[data-view="ai-inventory"] .aiv-card-body { padding: 16px; }

/* ---- buttons ---- */
.view[data-view="ai-inventory"] .aiv-btn,
.aiv-modal .aiv-btn {
  appearance: none; cursor: pointer; font-size: 13px; font-weight: 600;
  padding: 9px 14px; border-radius: 9px; border: 1px solid var(--aiv-line, #e6e9ee);
  background: #fff; color: #0f172a; transition: filter .15s, background .15s;
}
.view[data-view="ai-inventory"] .aiv-btn:hover { background: #f1f5f9; }
.view[data-view="ai-inventory"] .aiv-btn:disabled,
.aiv-modal .aiv-btn:disabled { opacity: .55; cursor: not-allowed; }
.view[data-view="ai-inventory"] .aiv-btn.primary,
.aiv-modal .aiv-btn.primary { background: #4338ca; border-color: #4338ca; color: #fff; }
.view[data-view="ai-inventory"] .aiv-btn.primary:hover { filter: brightness(1.1); background: #4338ca; }
.view[data-view="ai-inventory"] .aiv-btn.danger,
.aiv-modal .aiv-btn.danger { background: #e74c3c; border-color: #e74c3c; color: #fff; }
.view[data-view="ai-inventory"] .aiv-btn.ghost { background: transparent; }
.view[data-view="ai-inventory"] .aiv-btn.sm,
.aiv-modal .aiv-btn.sm { padding: 6px 10px; font-size: 12px; }
.view[data-view="ai-inventory"] .aiv-btn-row { display: flex; gap: 8px; flex-wrap: wrap; }

/* ---- badges ---- */
.view[data-view="ai-inventory"] .aiv-badge,
.aiv-modal .aiv-badge {
  display: inline-block; padding: 3px 9px; border-radius: 999px;
  font-size: 11px; font-weight: 700; line-height: 1.5; white-space: nowrap;
}
.aiv-badge.green { background: #e7f9ee; color: #0a7d3f; }
.aiv-badge.red { background: #fdecea; color: #c0392b; }
.aiv-badge.amber { background: #fff4e0; color: #b9770e; }
.aiv-badge.blue { background: #e8f1fe; color: #1d68d6; }
.aiv-badge.violet { background: #f1ecfd; color: #6b3fd4; }
.aiv-badge.slate { background: #eef1f5; color: #51606f; }

/* ---- confidence pill ---- */
.aiv-conf {
  display: inline-block; padding: 3px 8px; border-radius: 999px;
  font-size: 11px; font-weight: 700;
}
.aiv-conf.hi { background: #e7f9ee; color: #0a7d3f; }
.aiv-conf.mid { background: #fff4e0; color: #b9770e; }
.aiv-conf.lo { background: #fdecea; color: #c0392b; }

/* ---- tables ---- */
.view[data-view="ai-inventory"] .aiv-table-wrap,
.aiv-modal .aiv-table-wrap { overflow-x: auto; }
.aiv-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.aiv-table th {
  text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: .04em;
  color: #64748b; padding: 9px 12px; border-bottom: 1px solid #e6e9ee; white-space: nowrap;
}
.aiv-table td { padding: 10px 12px; border-bottom: 1px solid #e6e9ee; vertical-align: top; }
.aiv-table tr:last-child td { border-bottom: 0; }
.aiv-table tr.aiv-clickable { cursor: pointer; }
.aiv-table tbody tr:hover td { background: #fafbfc; }

/* ---- list rows ---- */
.view[data-view="ai-inventory"] .aiv-list { display: flex; flex-direction: column; }
.view[data-view="ai-inventory"] .aiv-row {
  display: flex; align-items: center; gap: 12px; padding: 12px 14px;
  border-bottom: 1px solid var(--aiv-line); cursor: pointer;
}
.view[data-view="ai-inventory"] .aiv-row:last-child { border-bottom: 0; }
.view[data-view="ai-inventory"] .aiv-row:hover { background: #fafbfc; }
.view[data-view="ai-inventory"] .aiv-row-main { flex: 1; min-width: 0; }
.view[data-view="ai-inventory"] .aiv-row-title {
  font-weight: 600; font-size: 13.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.view[data-view="ai-inventory"] .aiv-row-sub {
  font-size: 12px; color: var(--aiv-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.view[data-view="ai-inventory"] .aiv-file-ico {
  width: 38px; height: 38px; border-radius: 10px; flex-shrink: 0; font-size: 18px;
  display: flex; align-items: center; justify-content: center; background: var(--aiv-accent-soft);
}

/* ---- dropzone ---- */
.view[data-view="ai-inventory"] .aiv-dropzone {
  border: 2px dashed #c7cbe8; border-radius: var(--aiv-radius);
  background: var(--aiv-accent-soft); padding: 34px 20px; text-align: center;
  transition: border-color .15s, background .15s;
}
.view[data-view="ai-inventory"] .aiv-dropzone.drag {
  border-color: var(--aiv-accent); background: #e3e6fd;
}
.view[data-view="ai-inventory"] .aiv-drop-ico { font-size: 30px; }
.view[data-view="ai-inventory"] .aiv-drop-title { font-weight: 700; font-size: 15px; margin-top: 8px; }
.view[data-view="ai-inventory"] .aiv-drop-sub { font-size: 12.5px; color: var(--aiv-muted); margin-top: 4px; }

/* ---- key/value detail grid ---- */
.aiv-kv-grid {
  display: grid; grid-template-columns: repeat(2, 1fr); gap: 0 22px;
}
@media (max-width: 560px) { .aiv-kv-grid { grid-template-columns: 1fr; } }
.aiv-kv-grid > div {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 9px 0; border-bottom: 1px solid #eef1f5; font-size: 13px;
}
.aiv-kv-grid > div > span { color: #64748b; }

/* ---- purchasing bars ---- */
.aiv-bar-row { display: flex; align-items: center; gap: 10px; padding: 6px 0; font-size: 12.5px; }
.aiv-bar-label { width: 64px; color: #64748b; flex-shrink: 0; }
.aiv-bar-track { flex: 1; height: 10px; background: #eef1f5; border-radius: 999px; overflow: hidden; }
.aiv-bar-fill { display: block; height: 100%; background: #4f46e5; border-radius: 999px; }
.aiv-bar-val { width: 86px; text-align: right; font-weight: 600; flex-shrink: 0; }

/* ---- mini rows (expiry / cost lists) ---- */
.aiv-mini-row {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 9px 0; border-bottom: 1px solid #eef1f5; font-size: 13px;
}
.aiv-mini-row:last-child { border-bottom: 0; }

/* ---- form fields ---- */
.view[data-view="ai-inventory"] .aiv-field,
.aiv-modal .aiv-field { margin-bottom: 14px; }
.view[data-view="ai-inventory"] .aiv-label,
.aiv-modal .aiv-label { display: block; font-size: 12.5px; font-weight: 600; margin-bottom: 5px; }
.view[data-view="ai-inventory"] .aiv-input,
.view[data-view="ai-inventory"] .aiv-select,
.aiv-modal .aiv-input,
.aiv-modal .aiv-select {
  width: 100%; box-sizing: border-box; padding: 9px 11px; font-size: 13px;
  border: 1px solid #e6e9ee; border-radius: 9px; background: #fff; color: #0f172a;
  font-family: inherit;
}
.aiv-modal .aiv-input:focus, .aiv-modal .aiv-select:focus {
  outline: none; border-color: #4f46e5; box-shadow: 0 0 0 3px #eef0fe;
}
.view[data-view="ai-inventory"] .aiv-hint,
.aiv-modal .aiv-hint { font-size: 11.5px; color: #64748b; margin-top: 4px; }

/* ---- toggle rows + switch ---- */
.view[data-view="ai-inventory"] .aiv-toggle-row,
.aiv-modal .aiv-toggle-row {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 11px 0; border-bottom: 1px solid #eef1f5; font-size: 13px;
}
.view[data-view="ai-inventory"] .aiv-toggle-row:last-child { border-bottom: 0; }
.aiv-switch { position: relative; width: 42px; height: 24px; flex-shrink: 0; }
.aiv-switch input { opacity: 0; width: 0; height: 0; }
.aiv-switch-slider {
  position: absolute; inset: 0; background: #cbd5e1; border-radius: 999px;
  cursor: pointer; transition: background .15s;
}
.aiv-switch-slider::before {
  content: ""; position: absolute; height: 18px; width: 18px; left: 3px; top: 3px;
  background: #fff; border-radius: 50%; transition: transform .15s;
}
.aiv-switch input:checked + .aiv-switch-slider { background: #4f46e5; }
.aiv-switch input:checked + .aiv-switch-slider::before { transform: translateX(18px); }

/* ---- banners ---- */
.view[data-view="ai-inventory"] .aiv-banner,
.aiv-modal .aiv-banner {
  display: flex; align-items: center; gap: 10px; padding: 13px 15px;
  border-radius: 12px; font-size: 13px; margin-bottom: 16px; line-height: 1.45;
}
.aiv-banner.warn { background: #fff4e0; color: #8a5a00; border: 1px solid #f4d99a; }
.aiv-banner.ok { background: #e7f9ee; color: #0a6b38; border: 1px solid #b6e8c8; }
.aiv-banner.info { background: #eef0fe; color: #3730a3; border: 1px solid #c7cbf3; }

/* ---- misc ---- */
.view[data-view="ai-inventory"] .aiv-muted,
.aiv-modal .aiv-muted { color: #64748b; }

/* ---- modal (rendered at body level — unscoped) ---- */
.aiv-modal-backdrop {
  position: fixed; inset: 0; background: rgba(15, 23, 42, .45);
  display: flex; align-items: center; justify-content: center; z-index: 9000;
  opacity: 0; transition: opacity .18s; padding: 20px;
}
.aiv-modal-backdrop.open { opacity: 1; }
.aiv-modal {
  background: #fff; border-radius: 16px; width: 100%; max-width: 460px;
  max-height: 88vh; overflow: hidden; display: flex; flex-direction: column;
  box-shadow: 0 24px 60px rgba(15, 23, 42, .3); transform: translateY(8px); transition: transform .18s;
}
.aiv-modal-backdrop.open .aiv-modal { transform: translateY(0); }
.aiv-modal.wide { max-width: 620px; }
.aiv-modal.xl { max-width: 880px; }
.aiv-modal-head {
  display: flex; align-items: flex-start; justify-content: space-between;
  padding: 16px 18px; border-bottom: 1px solid #e6e9ee;
}
.aiv-modal-title { font-weight: 700; font-size: 15px; }
.aiv-modal-sub { font-size: 12px; color: #64748b; margin-top: 2px; }
.aiv-modal-x { appearance: none; border: 0; background: transparent; font-size: 22px; line-height: 1; cursor: pointer; color: #94a3b8; }
.aiv-modal-body { padding: 18px; overflow-y: auto; }
.aiv-modal-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 14px 18px; border-top: 1px solid #e6e9ee; flex-wrap: wrap; }

/* ---- toast ---- */
.aiv-toast-wrap { position: fixed; bottom: 22px; right: 22px; display: flex; flex-direction: column; gap: 8px; z-index: 9500; }
.aiv-toast {
  display: flex; align-items: center; gap: 9px; background: #0f172a; color: #fff;
  padding: 11px 15px; border-radius: 10px; font-size: 13px; box-shadow: 0 8px 24px rgba(15, 23, 42, .3);
}
.aiv-toast.success { background: #0a7d3f; }
.aiv-toast.error { background: #c0392b; }
.aiv-toast.info { background: #4338ca; }
.aiv-toast-ico { font-weight: 700; }
