/* Inventory Manager - Light Theme */
:root {
  --bg: #ffffff;
  --bg-alt: #f8f9fa;
  --border: #e2e8f0;
  --text: #1a202c;
  --text-muted: #718096;
  --primary: #3182ce;
  --primary-hover: #2b6cb0;
  --danger: #e53e3e;
  --danger-hover: #c53030;
  --success: #38a169;
  --warning: #d69e2e;
  --shadow: 0 1px 3px rgba(0,0,0,0.08);
  --radius: 5px;
  --nav-bg: #2c5282;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg-alt);
  color: var(--text);
  font-size: 13px;
  line-height: 1.5;
}

/* ── Nav ── */
#nav-bar {
  position: sticky;
  top: 0;
  z-index: 100;
}

/* Top bar — app-level links (Dashboard, Docs, Admin) */
.nav-top {
  background: var(--nav-bg);
  padding: 0 16px;
  transition: background 0.2s ease;
  display: flex;
  align-items: center;
  height: 42px;
  gap: 3px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}
.nav-top::-webkit-scrollbar { display: none; }

.nav-top .brand {
  font-weight: 700;
  font-size: 15px;
  color: white;
  margin-right: 10px;
  text-decoration: none;
  white-space: nowrap;
  flex-shrink: 0;
  letter-spacing: -0.01em;
}

.nav-top a {
  padding: 5px 11px;
  border-radius: var(--radius);
  color: rgba(255,255,255,0.72);
  text-decoration: none;
  font-weight: 500;
  font-size: 13px;
  white-space: nowrap;
  flex-shrink: 0;
  transition: background 0.15s, color 0.15s;
}

.nav-top a:hover, .nav-top a.active {
  background: rgba(255,255,255,0.15);
  color: white;
}

#global-purchaser {
  margin-left: auto;
  width: auto;
  min-width: 130px;
  padding: 3px 8px;
  font-size: 12px;
  border: 1px solid rgba(255,255,255,0.25);
  border-radius: var(--radius);
  background: rgba(255,255,255,0.1);
  color: white;
  flex-shrink: 0;
  min-height: 0;
}

#global-purchaser option { color: var(--text); background: var(--bg); }

/* Bottom bar — section navigation (Components, Builds, Kits, Logs) */
.nav-bottom {
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  padding: 0 16px;
  display: flex;
  align-items: center;
  height: 40px;
  gap: 2px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}
.nav-bottom::-webkit-scrollbar { display: none; }

.nav-bottom a {
  padding: 5px 10px;
  border-radius: var(--radius);
  color: var(--text-muted);
  text-decoration: none;
  font-weight: 500;
  font-size: 13px;
  white-space: nowrap;
  flex-shrink: 0;
  transition: background 0.15s, color 0.15s;
}

.nav-bottom a:hover, .nav-bottom a.active {
  background: var(--bg-alt);
  color: var(--primary);
}

/* ── Layout ── */
.container {
  max-width: 1400px;
  margin: 0 auto;
  padding: 16px;
}

.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 14px;
  flex-wrap: wrap;
}

.page-header h1 {
  font-size: 18px;
  font-weight: 700;
}

/* ── Cards ── */
.card {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.card-header {
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  font-weight: 600;
  font-size: 11px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.card-body { padding: 14px; }

/* ── Stats grid ── */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 10px;
  margin-bottom: 16px;
}

.stat-card {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
  box-shadow: var(--shadow);
}

.stat-card .value {
  font-size: 22px;
  font-weight: 700;
  color: var(--primary);
  line-height: 1;
  margin-bottom: 3px;
}

.stat-card .label {
  font-size: 11px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

/* ── Tables ── */
.table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

table {
  width: 100%;
  border-collapse: collapse;
}

th {
  background: var(--bg-alt);
  padding: 7px 10px;
  text-align: left;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

th.sortable, th.sortable-srv {
  cursor: pointer;
  user-select: none;
}

th.sortable:hover, th.sortable-srv:hover { color: var(--primary); background: #edf2f7; }
th.sort-asc::after  { content: ' ▲'; color: var(--primary); }
th.sort-desc::after { content: ' ▼'; color: var(--primary); }

td {
  padding: 7px 10px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
  font-size: 13px;
}

tr:last-child td { border-bottom: none; }
tr:hover td { background: var(--bg-alt); }

/* ── Badges ── */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 6px;
  border-radius: 10px;
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  white-space: nowrap;
}

.badge-green  { background: #c6f6d5; color: #276749; }
.badge-amber  { background: #fefcbf; color: #744210; }
.badge-red    { background: #fed7d7; color: #742a2a; }
.badge-blue   { background: #bee3f8; color: #2a4365; }
.badge-gray   { background: #e2e8f0; color: #4a5568; }
.badge-purple { background: #e9d8fd; color: #44337a; }

.badge-Pending          { background: #bee3f8; color: #2a4365; }
.badge-Completed        { background: #c6f6d5; color: #276749; }
.badge-CANCELED         { background: #e2e8f0; color: #4a5568; }
.badge-ReverseRequested { background: #fefcbf; color: #744210; }
.badge-Reversed         { background: #e9d8fd; color: #44337a; }

/* ── Buttons ── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 6px 12px;
  border-radius: var(--radius);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  border: none;
  transition: background 0.15s, opacity 0.15s;
  text-decoration: none;
  white-space: nowrap;
}

.btn-primary  { background: var(--primary); color: white; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-danger   { background: var(--danger); color: white; }
.btn-danger:hover { background: var(--danger-hover); }
.btn-success  { background: var(--success); color: white; }
.btn-success:hover { background: #2f855a; }
.btn-warning  { background: var(--warning); color: white; }
.btn-warning:hover { background: #b7791f; }
.btn-outline  { background: transparent; color: var(--primary); border: 1px solid var(--primary); }
.btn-outline:hover { background: #ebf8ff; }
.btn-sm { padding: 3px 8px; font-size: 11px; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* ── Forms ── */
.form-group { margin-bottom: 12px; }

label {
  display: block;
  font-size: 12px;
  font-weight: 500;
  margin-bottom: 4px;
  color: var(--text);
}

input[type="text"],
input[type="number"],
input[type="date"],
select,
textarea {
  width: 100%;
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 13px;
  background: var(--bg);
  color: var(--text);
  transition: border-color 0.15s, box-shadow 0.15s;
}

input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 2px rgba(49,130,206,0.15);
}

.form-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 12px;
}

/* ── Filters bar ── */
.filters {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: flex-end;
}

.filters .form-group { margin: 0; }

.filters select,
.filters input { font-size: 12px; }

/* ── Modals ── */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.45);
  z-index: 1000;
  align-items: center;
  justify-content: center;
  padding: 12px;
}

.modal-overlay.open { display: flex; }

.modal {
  background: var(--bg);
  border-radius: 7px;
  box-shadow: 0 16px 48px rgba(0,0,0,0.2);
  width: 460px;
  max-width: 100%;
  max-height: 92vh;
  overflow-y: auto;
}

.modal-header {
  padding: 13px 16px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-weight: 600;
  font-size: 14px;
}

.modal-close {
  background: none;
  border: none;
  font-size: 20px;
  cursor: pointer;
  color: var(--text-muted);
  padding: 0;
  line-height: 1;
}

.modal-body { padding: 16px; }
.modal-footer {
  padding: 10px 16px;
  border-top: 1px solid var(--border);
  display: flex;
  gap: 8px;
  justify-content: flex-end;
}

/* ── Adjust-Inventory modal ── */
.adj-current {
  font-size: 13px;
  color: var(--text-muted);
  margin-bottom: 10px;
}
.adj-current strong { color: var(--text); font-size: 15px; }
.adj-preview {
  background: var(--bg-alt);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 12px;
  margin: 10px 0 14px;
  font-size: 14px;
  text-align: center;
}
.adj-preview.adj-preview-empty { color: var(--text-muted); font-style: italic; }
.adj-preview.adj-preview-bad { background: #fed7d7; color: #742a2a; border-color: #fc8181; }
.adj-preview .adj-delta-pill {
  display: inline-block;
  margin-left: 8px;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--bg);
  font-size: 12px;
  font-weight: 600;
}
.adj-summary {
  text-align: center;
  margin-bottom: 16px;
  padding: 16px;
  background: var(--bg-alt);
  border-radius: var(--radius);
}
.adj-summary-name {
  font-size: 13px;
  color: var(--text-muted);
  margin-bottom: 8px;
}
.adj-summary-change {
  font-size: 28px;
  font-weight: 600;
  margin-bottom: 6px;
}
.adj-summary-change .adj-arrow { color: var(--text-muted); margin: 0 12px; }
.adj-summary-delta { font-size: 14px; }
.adj-warning-banner {
  background: #fefcbf;
  color: #744210;
  border: 1px solid #faf089;
  padding: 10px 12px;
  border-radius: var(--radius);
  margin-bottom: 12px;
  font-size: 13px;
  font-weight: 500;
  text-align: center;
}
.form-hint {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 4px;
}
.form-hint.form-hint-warn { color: #c05621; }

.selection-bar {
  display: flex;
  gap: 8px;
  align-items: center;
  background: var(--bg-alt);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 8px 12px;
  margin-bottom: 10px;
  font-size: 13px;
}
.selection-bar > span:first-child { font-weight: 600; margin-right: 8px; }

/* ── Alerts ── */
.alert {
  padding: 9px 13px;
  border-radius: var(--radius);
  margin-bottom: 12px;
  font-size: 12px;
}

.alert-success { background: #c6f6d5; color: #276749; }
.alert-danger  { background: #fed7d7; color: #742a2a; }
.alert-warning { background: #fefcbf; color: #744210; }
.alert-info    { background: #bee3f8; color: #2a4365; }

/* ── Component image ── */
.comp-image {
  width: 36px;
  height: 36px;
  object-fit: cover;
  border-radius: 4px;
  border: 1px solid var(--border);
}

.comp-placeholder {
  width: 36px;
  height: 36px;
  background: var(--bg-alt);
  border: 1px solid var(--border);
  border-radius: 4px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  font-size: 14px;
}

/* ── Qty indicators ── */
.qty-ok   { color: var(--success); font-weight: 600; }
.qty-warn { color: var(--warning); font-weight: 600; }
.qty-low  { color: var(--danger);  font-weight: 600; }

/* ── Two-column layout ── */
.two-col {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}

/* ── Search input ── */
.search-wrap {
  position: relative;
  flex: 1;
  min-width: 160px;
}

.search-wrap input { padding-left: 28px; }

.search-icon {
  position: absolute;
  left: 9px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
  font-size: 12px;
}

/* ── Empty / Loading ── */
.empty {
  text-align: center;
  padding: 32px 16px;
  color: var(--text-muted);
}

.empty .empty-icon { font-size: 32px; margin-bottom: 8px; }
.empty p { font-size: 13px; }

.loading {
  text-align: center;
  padding: 24px;
  color: var(--text-muted);
}

/* ── Clickable rows ── */
.row-link { cursor: pointer; }
.row-link:hover td { background: #ebf8ff !important; }

/* ── Toast ── */
#toast {
  position: fixed;
  bottom: 16px;
  right: 16px;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.toast {
  padding: 10px 14px;
  border-radius: var(--radius);
  font-size: 12px;
  font-weight: 500;
  box-shadow: 0 4px 12px rgba(0,0,0,0.15);
  animation: slide-in 0.18s ease;
  max-width: 320px;
}

.toast-success {
  background: #059669;
  color: white;
  padding: 12px 20px;
  border-radius: 8px;
  font-weight: 500;
  box-shadow: 0 4px 12px rgba(0,0,0,0.15);
  animation: toast-slide-in 0.3s ease-out;
}
.toast-error   { background: #742a2a; color: white; }
.toast-info    { background: #2a4365; color: white; }

@keyframes slide-in {
  from { opacity: 0; transform: translateX(16px); }
  to   { opacity: 1; transform: translateX(0); }
}

@keyframes toast-slide-in {
  from { transform: translateY(20px); opacity: 0; }
  to   { transform: translateY(0); opacity: 1; }
}

/* ── Detail page hero ── */
.detail-hero {
  display: flex;
  gap: 16px;
  margin-bottom: 16px;
  align-items: flex-start;
}

.detail-hero img {
  width: 90px;
  height: 90px;
  object-fit: cover;
  border-radius: 6px;
  border: 1px solid var(--border);
  flex-shrink: 0;
}

.detail-hero .placeholder {
  width: 90px;
  height: 90px;
  background: var(--bg-alt);
  border: 1px dashed var(--border);
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 32px;
  flex-shrink: 0;
}

.kv-list {
  display: grid;
  grid-template-columns: 120px 1fr;
  gap: 6px 10px;
  font-size: 12px;
}

.kv-list .kv-key {
  color: var(--text-muted);
  font-weight: 500;
}

/* ── Responsive breakpoints ── */

/* Tablet */
@media (max-width: 900px) {
  .stats-grid { grid-template-columns: repeat(3, 1fr); }
}

/* Mobile */
@media (max-width: 640px) {
  body { font-size: 12px; }

  .container { padding: 8px; }

  .page-header { margin-bottom: 6px; }
  .page-header h1 { font-size: 14px; overflow-wrap: break-word; word-break: break-word; }

  .stats-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 6px;
    margin-bottom: 8px;
  }

  .stat-card { padding: 7px 10px; }
  .stat-card .value { font-size: 15px; }
  .stat-card .label { font-size: 10px; }

  .two-col { grid-template-columns: 1fr; gap: 8px; }

  .card-header { padding: 7px 10px; }
  .card-body { padding: 8px; }

  .filters { gap: 4px; }
  .filters .form-group,
  .search-wrap { min-width: 0; flex: 1 1 120px; }
  .filters input[type="date"] { max-width: 140px; min-width: 0; }

  .form-row { grid-template-columns: 1fr; gap: 0; }
  .form-group { margin-bottom: 8px; }

  /* Tighter table cells on mobile */
  td, th { padding: 4px 6px; }

  /* Long text in cells/alerts won't overflow their containers */
  td { overflow-wrap: break-word; font-size: 12px; }
  .alert { overflow-wrap: break-word; }

  /* Hide image column on components list */
  .hide-mobile { display: none; }

  /* Detail hero stacks on mobile */
  .detail-hero {
    flex-direction: column;
    align-items: center;
  }
  .detail-hero img,
  .detail-hero .placeholder { width: 80px; height: 80px; }

  /* KV list: narrower label column on small screens */
  .kv-list { grid-template-columns: 90px 1fr; }

  /* Page header button goes full-width on very small screens */
  .page-header { flex-direction: column; align-items: flex-start; }
  .page-header > div,
  .page-header > button,
  .page-header > a { align-self: flex-start; }

  /* Prevent iOS Safari from zooming on input focus (needs ≥16px) */
  input[type="text"],
  input[type="number"],
  input[type="date"],
  select,
  textarea { font-size: 16px; }

  /* Compact input padding */
  input, select, textarea { padding: 5px 8px; }

  /* Touch-friendly input / select heights */
  input[type="text"],
  input[type="number"],
  input[type="date"],
  select { min-height: 38px; }
  textarea { min-height: 60px; }

  /* Compact tap targets for buttons on mobile */
  .btn:not(.btn-sm) { padding: 8px 12px; font-size: 13px; }
  .btn-sm { padding: 5px 8px; font-size: 12px; min-height: 30px; }

  /* Modal: full-width bottom sheet */
  .modal { width: 100%; border-radius: 12px 12px 0 0; max-height: 88vh; }
  .modal-overlay { padding: 0; align-items: flex-end; }
  .modal-header { padding: 10px 14px; }
  .modal-body { padding: 12px; }

  /* Full-width stacked buttons in modal footer — easy to tap */
  .modal-footer {
    flex-direction: column-reverse;
    gap: 8px;
    padding: 10px 12px;
  }
  .modal-footer .btn {
    width: 100%;
    justify-content: center;
    padding: 10px;
    font-size: 14px;
  }

  /* Plan summary spacing */
  #plan-summary { margin-top: 10px; }

  /* Toast full-width */
  #toast { left: 10px; right: 10px; }
  .toast { max-width: 100%; }
}

@media (max-width: 400px) {
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
  .btn-sm { padding: 4px 8px; font-size: 11px; }
}

/* ── Fullscreen Image Overlay ── */
.img-fullscreen {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.88);
  z-index: 2000;
  align-items: center;
  justify-content: center;
}

.img-fullscreen.open { display: flex; }

.img-fullscreen img {
  max-width: 95vw;
  max-height: 95vh;
  object-fit: contain;
  border-radius: 4px;
  box-shadow: 0 8px 48px rgba(0,0,0,0.6);
}

.img-fullscreen-close {
  position: absolute;
  top: 14px;
  right: 18px;
  background: rgba(255,255,255,0.12);
  border: none;
  color: white;
  font-size: 28px;
  line-height: 1;
  cursor: pointer;
  border-radius: 50%;
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* ── Tab buttons ── */
.tab-btn { border-radius: var(--radius); }
.tab-btn.active {
  background: var(--primary);
  color: white;
  border-color: var(--primary);
}

/* ── Placeholder block ── */
.placeholder {
  background: var(--bg-alt);
  border: 1px dashed var(--border);
  border-radius: 6px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 32px;
  flex-shrink: 0;
}
