/* ============================================================
   StockMaster Pro - Components CSS
   Buttons, Cards, Badges, Tables, Forms, Modals
   ============================================================ */

/* ---- CARD ---- */
.im-card {
  background: var(--bg-card);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
}
.im-card-body { padding: 22px; }
.im-card-head {
  display: flex; justify-content: space-between;
  align-items: center; margin-bottom: 18px;
  flex-wrap: wrap; gap: 10px;
}
.im-card-title {
  font-size: 0.95rem; font-weight: 700;
  color: var(--text-dark); display: flex;
  align-items: center; gap: 8px;
}
.im-card-actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

/* ---- BUTTONS ---- */
.im-btn {
  border: none; padding: 9px 18px;
  border-radius: var(--radius-sm);
  font-size: 0.82rem; font-weight: 600;
  cursor: pointer; display: inline-flex;
  align-items: center; gap: 6px;
  transition: var(--transition);
  font-family: inherit; white-space: nowrap;
  line-height: 1;
}
.im-btn:disabled { opacity: 0.45; cursor: not-allowed; }
.im-btn-primary { background: var(--primary); color: #fff; }
.im-btn-primary:hover:not(:disabled) { background: var(--primary-dark); }
.im-btn-success { background: var(--success); color: #fff; }
.im-btn-success:hover:not(:disabled) { background: #059669; }
.im-btn-warning { background: var(--warning); color: #fff; }
.im-btn-warning:hover:not(:disabled) { background: #d97706; }
.im-btn-danger { background: var(--danger); color: #fff; }
.im-btn-danger:hover:not(:disabled) { background: #dc2626; }
.im-btn-ghost {
  background: var(--bg-soft); border: 1px solid var(--border);
  color: var(--text-muted);
}
.im-btn-ghost:hover:not(:disabled) { background: #f1f5f9; color: var(--text-dark); }
.im-btn-sm { padding: 6px 13px; font-size: 0.78rem; }
.im-btn-xs { padding: 4px 10px; font-size: 0.73rem; }
.im-btn-icon {
  width: 32px; height: 32px; padding: 0;
  justify-content: center; background: var(--bg-soft);
  border: 1px solid var(--border); color: var(--text-muted);
  border-radius: var(--radius-sm);
}
.im-btn-icon:hover { background: #f1f5f9; color: var(--text-dark); }

/* ---- FORM ELEMENTS ---- */
.im-input {
  background: var(--bg-card); border: 1px solid #cbd5e1;
  border-radius: var(--radius-sm); padding: 9px 13px;
  color: var(--text-dark); font-size: 0.84rem;
  font-family: inherit; outline: none;
  transition: var(--transition); width: 100%;
}
.im-input:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(79,70,229,0.1); }
.im-input:disabled { background: var(--bg-soft); color: var(--text-muted); }
.im-input[readonly] { background: var(--bg-soft); }
.im-label { display: block; font-size: 0.77rem; color: #475569; font-weight: 600; margin-bottom: 5px; }
.im-form-group { margin-bottom: 14px; }
.im-form-hint { font-size: 0.71rem; color: var(--text-light); margin-top: 4px; }
.im-form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.im-form-row-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 14px; }

/* ---- BADGES ---- */
.im-badge {
  display: inline-flex; align-items: center;
  padding: 3px 10px; border-radius: 20px;
  font-size: 0.71rem; font-weight: 600; white-space: nowrap;
}
.im-badge-green  { background: #d1fae5; color: #065f46; }
.im-badge-yellow { background: #fef3c7; color: #92400e; }
.im-badge-red    { background: #fee2e2; color: #991b1b; }
.im-badge-blue   { background: #dbeafe; color: #1e40af; }
.im-badge-purple { background: #ede9fe; color: #5b21b6; }
.im-badge-gray   { background: #f1f5f9; color: #475569; }
.im-badge-orange { background: #ffedd5; color: #c2410c; }
.im-badge-teal   { background: #ccfbf1; color: #134e4a; }

/* ---- TABLE ---- */
.im-table-wrap { overflow-x: auto; border-radius: var(--radius-sm); border: 1px solid var(--border); }
.im-table { width: 100%; border-collapse: collapse; font-size: 0.82rem; }
.im-table th {
  padding: 11px 15px; background: var(--bg-soft);
  color: #475569; font-weight: 600;
  text-transform: uppercase; font-size: 0.68rem;
  letter-spacing: 0.5px; border-bottom: 1px solid var(--border);
  white-space: nowrap; text-align: left;
}
.im-table td {
  padding: 11px 15px; color: var(--text-mid);
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
.im-table tr:last-child td { border-bottom: none; }
.im-table tr:hover td { background: #fafbff; }
.im-table-actions { display: flex; gap: 4px; align-items: center; }

/* Product cell */
.im-prod-cell { display: flex; align-items: center; gap: 10px; }
.im-prod-ico {
  width: 34px; height: 34px; border-radius: var(--radius-sm);
  display: flex; align-items: center; justify-content: center;
  font-size: 0.95rem; flex-shrink: 0;
}
.im-prod-name { font-weight: 600; color: var(--text-dark); font-size: 0.84rem; }
.im-prod-sku { font-size: 0.69rem; color: var(--text-light); }

/* Stock bar */
.im-stock-cell { display: flex; align-items: center; gap: 8px; min-width: 120px; }
.im-stock-bar { flex: 1; max-width: 65px; height: 5px; background: var(--border); border-radius: 10px; overflow: hidden; }
.im-stock-fill { height: 100%; border-radius: 10px; transition: width 0.4s; }
.im-stock-txt { font-size: 0.77rem; color: var(--text-muted); font-weight: 500; white-space: nowrap; }

/* ---- FILTER BAR ---- */
.im-filter-bar {
  display: flex; gap: 10px; flex-wrap: wrap;
  margin-bottom: 16px; align-items: center;
}
.im-filter-bar .im-input { max-width: 200px; }
.im-filter-bar .im-search { flex: 1; min-width: 180px; max-width: 300px; }

/* ---- TABS ---- */
.im-tabs {
  display: flex; gap: 4px;
  background: #f1f5f9; border-radius: 10px;
  padding: 4px; margin-bottom: 18px; flex-wrap: wrap;
}
.im-tab {
  padding: 7px 15px; border-radius: 7px;
  cursor: pointer; font-size: 0.8rem; font-weight: 600;
  color: var(--text-muted); border: none;
  background: transparent; transition: var(--transition);
  display: flex; align-items: center; gap: 5px;
  font-family: inherit;
}
.im-tab.active { background: #fff; color: var(--primary); box-shadow: var(--shadow); }
.im-tab:hover:not(.active) { color: var(--text-dark); }

/* ---- MODAL ---- */
.im-overlay {
  display: none; position: fixed; inset: 0;
  background: rgba(15,23,42,0.5);
  z-index: 9999; align-items: center; justify-content: center;
  backdrop-filter: blur(3px); padding: 16px;
}
.im-overlay.open { display: flex; }
.im-modal {
  background: var(--bg-card); border-radius: 16px;
  width: 100%; max-width: 540px;
  box-shadow: 0 24px 48px rgba(0,0,0,0.12);
  max-height: 92vh; overflow: hidden;
  display: flex; flex-direction: column;
}
.im-modal-md { max-width: 680px; }
.im-modal-lg { max-width: 820px; }
.im-modal-sm { max-width: 400px; }
.im-modal-header {
  padding: 20px 24px 0;
  display: flex; justify-content: space-between; align-items: flex-start;
  flex-shrink: 0;
}
.im-modal-header h3 { font-size: 1.05rem; font-weight: 700; color: var(--text-dark); }
.im-modal-header p { font-size: 0.8rem; color: var(--text-muted); margin-top: 3px; }
.im-modal-close {
  background: var(--bg-soft); border: none;
  border-radius: var(--radius-sm); width: 30px; height: 30px;
  cursor: pointer; font-size: 0.9rem; color: var(--text-muted);
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0; transition: var(--transition);
}
.im-modal-close:hover { background: #fee2e2; color: var(--danger); }
.im-modal-body { padding: 18px 24px; overflow-y: auto; flex: 1; }
.im-modal-footer {
  padding: 0 24px 20px;
  display: flex; gap: 10px; justify-content: flex-end;
  flex-shrink: 0;
}

/* ---- ALERT STRIP ---- */
.im-alert {
  border-radius: var(--radius-sm); padding: 10px 15px;
  font-size: 0.81rem; display: flex; align-items: center;
  gap: 8px; margin-bottom: 14px; flex-wrap: wrap;
}
.im-alert-yellow { background: #fef3c7; border: 1px solid #fde68a; color: #92400e; }
.im-alert-red    { background: #fee2e2; border: 1px solid #fca5a5; color: #991b1b; }
.im-alert-blue   { background: #dbeafe; border: 1px solid #93c5fd; color: #1e40af; }
.im-alert-green  { background: #d1fae5; border: 1px solid #6ee7b7; color: #065f46; }

/* ---- PERM NOTICE ---- */
.im-perm-notice {
  background: #fef3c7; border: 1px solid #fde68a;
  border-radius: var(--radius-sm); padding: 10px 15px;
  font-size: 0.8rem; color: #92400e;
  margin-bottom: 14px; display: flex; align-items: center; gap: 8px;
}

/* ---- EMPTY STATE ---- */
.im-empty { text-align: center; padding: 48px 20px; color: var(--text-light); }
.im-empty-icon { font-size: 2.8rem; margin-bottom: 10px; }
.im-empty-text { font-size: 0.88rem; font-weight: 500; color: var(--text-muted); }
.im-empty-sub { font-size: 0.78rem; margin-top: 4px; }

/* ---- TIMELINE ---- */
.im-timeline { display: flex; flex-direction: column; gap: 10px; }
.im-tl-item { display: flex; gap: 12px; align-items: flex-start; }
.im-tl-dot { width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0; margin-top: 6px; }
.im-tl-body {
  flex: 1; background: var(--bg-soft);
  border-radius: var(--radius-sm); padding: 10px 14px;
  border: 1px solid var(--border); font-size: 0.8rem;
}
.im-tl-meta { display: flex; justify-content: space-between; align-items: center; margin-bottom: 4px; }
.im-tl-action { font-weight: 700; color: var(--text-dark); }
.im-tl-time { font-size: 0.69rem; color: var(--text-light); }
.im-tl-detail { color: #475569; margin-top: 3px; }

/* ---- PERM MATRIX ---- */
.im-perm-wrap { overflow-x: auto; }
.im-perm-table { width: 100%; border-collapse: collapse; font-size: 0.75rem; }
.im-perm-table th {
  padding: 8px 10px; background: var(--bg-soft);
  border: 1px solid var(--border); text-align: center;
  font-weight: 600; color: #475569; white-space: nowrap;
}
.im-perm-table th:first-child { text-align: left; min-width: 160px; }
.im-perm-table td { padding: 7px 10px; border: 1px solid var(--border); text-align: center; }
.im-perm-table td:first-child { text-align: left; font-weight: 500; color: var(--text-mid); }
.im-perm-cat td {
  background: #f1f5f9; font-weight: 700;
  color: var(--primary); font-size: 0.7rem;
  text-transform: uppercase; letter-spacing: 0.5px;
}

/* ---- MISC HELPERS ---- */
.im-divider { border: none; border-top: 1px solid var(--border); margin: 18px 0; }
.im-tag { background: var(--primary-light); color: #3730a3; font-size: 0.69rem; padding: 2px 8px; border-radius: 4px; font-weight: 600; margin-right: 4px; display: inline-block; }
.im-tag-green { background: #d1fae5; color: #065f46; }
.im-tag-gray  { background: #f1f5f9; color: #64748b; }
.im-flex { display: flex; align-items: center; gap: 8px; }
.im-flex-between { display: flex; justify-content: space-between; align-items: center; }
.im-grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.im-grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 16px; }
.im-mt-8 { margin-top: 8px; }
.im-mt-16 { margin-top: 16px; }
.im-mb-16 { margin-bottom: 16px; }
.im-text-muted { color: var(--text-light); font-size: 0.78rem; }
.im-text-bold { font-weight: 700; }
.im-text-success { color: var(--success); }
.im-text-danger { color: var(--danger); }
.im-w100 { width: 100%; }

@media (max-width: 640px) {
  .im-form-row, .im-form-row-3, .im-grid-2, .im-grid-3 { grid-template-columns: 1fr; }
  .im-modal { max-width: 100%; border-radius: 12px 12px 0 0; align-self: flex-end; max-height: 95vh; }
}
