/* Peptelligence Admin — standalone clinical theme, no Hypatia deps. */

:root {
  --primary: #1E40AF;
  --accent:  #3B82F6;
  --ok:      #059669;
  --warn:    #D97706;
  --err:     #DC2626;
  --bg:      #F4F7FB;
  --surface: #FFFFFF;
  --border:  #E2E8F0;
  --muted:   #64748B;
  --text:    #0F172A;
  --radius:  10px;
  --shadow:  0 2px 6px rgba(15, 23, 42, 0.04);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; height: 100%; }
body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, Inter, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.45;
}

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

/* ── Layout ───────────────────────────────────────────────────────── */
#layout {
  display: grid;
  grid-template-columns: 240px 1fr;
  min-height: 100vh;
}

#side {
  background: #0F172A;
  color: #E2E8F0;
  display: flex;
  flex-direction: column;
  padding: 18px 0 14px;
}
#brand { padding: 0 20px 16px; border-bottom: 1px solid rgba(255,255,255,.08); }
#brand-name { font-size: 16px; font-weight: 800; letter-spacing: -.02em; color: #fff; }
#brand-sub  { font-size: 11px; color: #94a3b8; margin-top: 2px; }

#side nav { display: flex; flex-direction: column; padding: 10px 10px; gap: 2px; }
.nav {
  display: flex; align-items: center; gap: 8px;
  background: transparent; border: 0; color: #cbd5e1;
  text-align: left; padding: 9px 12px; border-radius: 8px;
  font-size: 13px; cursor: pointer; transition: background .12s, color .12s;
}
.nav:hover { background: rgba(255,255,255,.06); color: #fff; }
.nav.active { background: var(--primary); color: #fff; }

.badge {
  display: none;
  margin-left: auto; padding: 2px 7px; border-radius: 999px;
  font-size: 10px; font-weight: 700; background: rgba(248,113,113,.2); color: #fca5a5;
}
.badge.visible { display: inline-block; }

#side-foot { margin-top: auto; padding: 12px 14px 0; border-top: 1px solid rgba(255,255,255,.08); }
#who .who-name { font-size: 12px; font-weight: 700; color: #fff; }
#who .who-role { font-size: 10px; color: #94a3b8; margin-top: 1px; }
#signout {
  margin-top: 8px; width: 100%; padding: 7px 10px; border: 1px solid rgba(255,255,255,.1);
  background: transparent; color: #cbd5e1; border-radius: 7px; font-size: 11px;
  cursor: pointer;
}
#signout:hover { background: rgba(255,255,255,.05); color: #fff; }
#viewstore { display: block; margin-top: 10px; font-size: 11px; color: #94a3b8; }

/* ── Main ──────────────────────────────────────────────────────────── */
#main { display: flex; flex-direction: column; min-width: 0; }
#topbar {
  display: flex; align-items: center; gap: 12px;
  padding: 14px 24px; background: var(--surface);
  border-bottom: 1px solid var(--border);
}
#topbar h1 { margin: 0; font-size: 18px; font-weight: 800; flex: 1; }
#topbar .actions { display: flex; gap: 8px; }

.panel { display: none; padding: 20px 24px; }
.panel.active { display: block; }

.toolbar { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; }
.toolbar .spacer { flex: 1; }
.hint { font-size: 12px; color: var(--muted); }

.input, .form input, .form textarea, .form select {
  width: 100%; padding: 9px 11px; font-family: inherit; font-size: 13px;
  border: 1px solid var(--border); border-radius: 7px; background: #fff;
  outline: none; transition: border-color .15s, box-shadow .15s;
}
.input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(59,130,246,.15);
}
textarea.input { resize: vertical; min-height: 80px; line-height: 1.5; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}
.card.form { padding: 20px; }
.card.form h2 { font-size: 14px; margin: 4px 0 10px; text-transform: uppercase;
                 letter-spacing: .06em; color: var(--muted); }
.card.form label { display: block; margin-bottom: 10px; font-size: 12px;
                    color: var(--muted); font-weight: 600; }
.card.form .row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
@media (max-width: 720px) {
  .card.form .row { grid-template-columns: 1fr; }
}

/* ── Tables ────────────────────────────────────────────────────────── */
table.data { width: 100%; border-collapse: collapse; }
table.data th, table.data td { padding: 10px 14px; text-align: left; vertical-align: middle; }
table.data th {
  font-size: 10px; font-weight: 700; text-transform: uppercase;
  letter-spacing: .06em; color: var(--muted);
  background: #F8FAFC; border-bottom: 1px solid var(--border);
}
table.data td { border-bottom: 1px solid #F1F5F9; font-size: 13px; }
table.data tr:last-child td { border-bottom: 0; }
table.data tr:hover td { background: #FAFCFF; }
td.num { font-variant-numeric: tabular-nums; white-space: nowrap; }
td.mono { font-family: "Roboto Mono", ui-monospace, monospace; font-size: 11px; }
td.sub  { font-size: 11px; color: var(--muted); }

.product-cell { display: flex; align-items: center; gap: 10px; }
.thumb {
  width: 36px; height: 36px; border-radius: 7px; object-fit: cover;
  background: #F1F5F9; border: 1px solid var(--border); flex-shrink: 0;
  display: inline-flex; align-items: center; justify-content: center; font-size: 18px;
}
.thumb.placeholder { color: var(--muted); }
.name { font-weight: 600; font-size: 13px; }
.sub  { font-size: 11px; color: var(--muted); }

td.loading, td.empty, td.error {
  text-align: center; padding: 34px 10px; color: var(--muted);
}
td.error { color: var(--err); }

/* ── Pills ─────────────────────────────────────────────────────────── */
.pill {
  display: inline-block; padding: 2px 8px; border-radius: 999px;
  font-size: 10px; font-weight: 700; letter-spacing: .04em;
  text-transform: uppercase;
}
.pill.green { background: #DCFCE7; color: #15803D; }
.pill.amber { background: #FEF3C7; color: #92400E; }
.pill.red   { background: #FEE2E2; color: #991B1B; }
.pill.blue  { background: #DBEAFE; color: #1D4ED8; }
.pill.gray  { background: #F1F5F9; color: var(--muted); }

/* ── Buttons ──────────────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  padding: 7px 14px; border-radius: 7px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text);
  font-family: inherit; font-size: 12px; font-weight: 600; cursor: pointer;
  transition: background .15s, border-color .15s, color .15s;
}
.btn:hover { background: #F8FAFC; }
.btn.primary { background: var(--primary); color: #fff; border-color: var(--primary); }
.btn.primary:hover { background: var(--accent); border-color: var(--accent); }
.btn.ghost { background: transparent; }
.btn.danger { border-color: #FECACA; color: #991B1B; background: #FFF5F5; }
.btn.danger:hover { background: #FEE2E2; }
.btn.sm { padding: 4px 10px; font-size: 11px; }
.row-actions { display: flex; gap: 6px; }
.actions.end { display: flex; gap: 8px; justify-content: flex-end; margin-top: 14px; }

/* ── Modal ────────────────────────────────────────────────────────── */
.modal {
  position: fixed; inset: 0; background: rgba(15,23,42,.55);
  display: none; align-items: center; justify-content: center;
  z-index: 200; padding: 20px;
}
.modal.open { display: flex; }
.modal-box {
  background: var(--surface); border-radius: 14px; padding: 22px 22px 18px;
  width: 540px; max-width: 96vw; max-height: 92vh; overflow-y: auto;
  box-shadow: 0 30px 60px rgba(15,23,42,.25);
}
.modal-title { font-size: 17px; font-weight: 800; }
.modal-sub   { font-size: 11px; color: var(--muted); margin: 2px 0 14px; }
.modal-box .row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.modal-box label { display: block; margin-bottom: 10px; font-size: 12px;
                    color: var(--muted); font-weight: 600; }
@media (max-width: 620px) {
  .modal-box .row { grid-template-columns: 1fr; }
}

/* ── Image upload widget (product modal) ──────────────────────── */
.image-upload { margin-bottom: 12px; }
.image-upload-label {
  display: block; font-size: 11px; font-weight: 600; color: var(--muted);
  letter-spacing: .06em; text-transform: uppercase; margin-bottom: 6px;
}
.image-upload-row {
  display: flex; gap: 14px; align-items: flex-start;
  background: #F8FAFC; border: 1px dashed var(--border); border-radius: 10px;
  padding: 12px;
}
#pm-image-preview {
  width: 96px; height: 96px; object-fit: cover;
  border-radius: 8px; border: 1px solid var(--border);
  background: #fff; flex-shrink: 0;
}
.image-upload-actions {
  display: flex; flex-wrap: wrap; gap: 8px; flex: 1; align-items: center;
}
.image-upload-btn { cursor: pointer; }
.image-upload-btn input[type=file] { display: none; }
#pm-image-status { font-size: 11px; color: var(--muted); min-height: 14px; flex-basis: 100%; }

/* ── Toast ───────────────────────────────────────────────── */
#toast {
  position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%);
  background: #0F172A; color: #fff; padding: 10px 18px; border-radius: 9px;
  font-size: 12px; font-weight: 600; box-shadow: 0 10px 30px rgba(15,23,42,.25);
  opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s;
  z-index: 300;
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(-4px); }

/* ── Overview + inventory alerts (Block B) ────────────────────── */
.kpi-grid {
  display: grid; gap: 12px; margin-bottom: 18px;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
}
.kpi-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 14px 16px;
}
.kpi-label { font-size: 10px; font-weight: 700; text-transform: uppercase;
             letter-spacing: .08em; color: var(--muted); }
.kpi-value { font-size: 26px; font-weight: 800; margin-top: 4px;
             font-variant-numeric: tabular-nums; color: var(--text); }
.kpi-sub   { font-size: 11px; color: var(--muted); margin-top: 2px; }

.alerts-card { padding: 0; }
.alerts-card .card-header {
  display: flex; align-items: center; gap: 12px;
  padding: 14px 16px; border-bottom: 1px solid var(--border);
}
.alerts-card .card-header h2 {
  margin: 0; font-size: 13px; font-weight: 800;
  text-transform: uppercase; letter-spacing: .06em; color: var(--text);
  flex: 1;
}
.alerts-list .loading,
.alerts-list .empty,
.alerts-list .error {
  padding: 22px 16px; text-align: center; color: var(--muted); font-size: 13px;
}
.alerts-list .error { color: var(--err); }
.alert-row {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 16px; border-bottom: 1px solid #F1F5F9;
}
.alert-row:last-child { border-bottom: 0; }
.alert-main { flex: 1; min-width: 0; }
.alert-name { font-weight: 600; font-size: 13px; color: var(--text); }
.alert-actions { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }

.stock-adjust-btn {
  margin-left: 6px; padding: 1px 7px; font-weight: 700; line-height: 1;
  min-width: 22px; font-size: 13px;
}

/* ── Spec sheet + docs sections inside product modal ────────────── */
.spec-section, .docs-section {
  margin-top: 12px; padding: 12px;
  background: #F8FAFC; border: 1px solid var(--border);
  border-radius: 10px;
}
.spec-header {
  font-size: 11px; font-weight: 700; text-transform: uppercase;
  letter-spacing: .06em; color: var(--muted); margin-bottom: 8px;
}
.spec-section .row { margin-bottom: 0; }
.doc-row {
  display: flex; flex-wrap: wrap; align-items: center; gap: 10px;
  padding: 8px 0; border-bottom: 1px dashed var(--border);
}
.doc-row:last-of-type { border-bottom: 0; }
.doc-label   { font-weight: 600; font-size: 12px; min-width: 220px; }
.doc-actions { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.doc-status  { font-size: 11px; color: var(--muted); flex-basis: 100%; }
.doc-link    { font-size: 11px; font-weight: 600; color: var(--primary); }
.doc-link.hidden { display: none; }
.doc-upload-btn { cursor: pointer; }
.doc-upload-btn input[type=file] { display: none; }

/* ── Citations editor inside product modal (Block 3) ─────────── */
.cite-list { list-style: none; padding: 0; margin: 8px 0 0; }
.cite-list li {
  display: flex; align-items: flex-start; gap: 10px;
  padding: 8px 0; border-bottom: 1px dashed var(--border);
  font-size: 12px; line-height: 1.5;
}
.cite-list li:last-child { border-bottom: 0; }
.cite-title   { font-weight: 700; color: var(--text); }
.cite-meta    { color: var(--muted); font-size: 11px; }
.cite-main    { flex: 1; min-width: 0; }
.cite-remove  {
  border: 1px solid #FECACA; color: #991B1B; background: #FFF5F5;
  border-radius: 6px; padding: 3px 8px; font-size: 11px; cursor: pointer;
  font-weight: 600; flex-shrink: 0;
}
.cite-remove:hover { background: #FEE2E2; }

/* ── Gallery manager inside product modal (Block 14) ─────────── */
.gallery-list {
  display: flex; flex-wrap: wrap; gap: 8px; min-height: 0;
}
.gallery-item {
  position: relative; width: 72px; height: 72px;
  border-radius: 8px; overflow: hidden; background: #f8fafc;
  border: 1px solid var(--border);
}
.gallery-item img { width: 100%; height: 100%; object-fit: cover; display: block; }
.gallery-item .g-remove {
  position: absolute; top: 2px; right: 2px;
  width: 20px; height: 20px; border-radius: 50%;
  border: 0; background: rgba(15,23,42,.75); color: #fff;
  font-size: 12px; font-weight: 700; cursor: pointer;
  line-height: 1; padding: 0;
}
.gallery-item .g-remove:hover { background: #991B1B; }

/* ── Mobile ──────────────────────────────────────────────── */
@media (max-width: 820px) {
  #layout { grid-template-columns: 1fr; }
  #side {
    flex-direction: row; overflow-x: auto; padding: 10px;
    border-bottom: 1px solid rgba(255,255,255,.1);
  }
  #brand { border: 0; padding: 0 16px 0 8px; white-space: nowrap; }
  #side nav { flex-direction: row; flex: 1; gap: 4px; padding: 0 6px; }
  .nav { white-space: nowrap; padding: 7px 10px; font-size: 12px; }
  #side-foot { display: none; }
  .panel { padding: 14px; }
  #topbar { padding: 12px 14px; }
}
