:root {
  --bg: #f5f7fa;
  --card: #ffffff;
  --border: #dfe4ec;
  --text: #1f2937;
  --muted: #6b7280;
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --alert-bg: #fee2e2;
  --alert-text: #b91c1c;
  --min-border: #111827;
  --hover: #f1f5f9;
}

* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  font-family: "Pretendard", "Malgun Gothic", -apple-system, BlinkMacSystemFont, sans-serif;
  font-size: 13px;
  color: var(--text);
  background: var(--bg);
}

body {
  display: flex;
  flex-direction: column;
}

.hidden {
  display: none !important;
}

.muted {
  color: var(--muted);
  margin: 4px 0 0;
}

.error-text {
  color: var(--alert-text);
  margin-top: 8px;
  font-size: 12px;
}

/* Topbar */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 16px;
  background: var(--card);
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}

.topbar-left, .topbar-right {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.topbar h1 {
  margin: 0;
  font-size: 16px;
  font-weight: 700;
}

.badge {
  display: inline-block;
  padding: 3px 8px;
  border-radius: 999px;
  background: #eff6ff;
  color: #1d4ed8;
  font-size: 12px;
  font-weight: 600;
}

.badge-subtle {
  background: #ecfdf5;
  color: #047857;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 6px 12px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--text);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
}

.btn:hover {
  background: var(--hover);
}

.btn-primary {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}

.btn-primary:hover {
  background: var(--primary-hover);
}

.btn-sm {
  padding: 4px 8px;
  font-size: 12px;
}

.btn-icon {
  border: none;
  background: transparent;
  font-size: 16px;
  cursor: pointer;
  color: var(--muted);
  padding: 4px 8px;
}

.btn-icon:hover {
  color: var(--text);
}

/* Tabs */
.tabs {
  display: flex;
  gap: 4px;
  padding: 8px 16px 0;
  background: var(--card);
  border-bottom: 1px solid var(--border);
}

.tab-btn {
  padding: 8px 16px;
  border: 1px solid transparent;
  border-bottom: none;
  border-radius: 8px 8px 0 0;
  background: transparent;
  color: var(--muted);
  font-weight: 600;
  cursor: pointer;
}

.tab-btn.active {
  background: var(--bg);
  color: var(--primary);
  border-color: var(--border);
  margin-bottom: -1px;
}

/* Main */
.main-wrap {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  padding: 12px 16px;
}

.tab-panel {
  display: none;
  flex: 1;
  min-height: 0;
  flex-direction: column;
  gap: 8px;
}

.tab-panel.active {
  display: flex;
}

/* Toolbar */
.toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  background: var(--card);
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
}

.check-label, .select-label {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-weight: 600;
  white-space: nowrap;
}

select, .search-input {
  padding: 6px 8px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 12px;
  background: #fff;
}

.search-input {
  flex: 1;
  min-width: 220px;
}

/* Status bar */
.status-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  font-size: 12px;
  color: var(--muted);
}

.legend {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.legend-chip {
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 600;
}

.legend-alert {
  background: var(--alert-bg);
  color: var(--alert-text);
}

.legend-min {
  border: 2px solid var(--min-border);
  color: var(--text);
  background: #fff;
}

/* Matrix layout */
.matrix-layout {
  flex: 1;
  min-height: 0;
  display: flex;
  gap: 12px;
}

.table-wrap {
  flex: 1;
  min-height: 0;
  overflow: auto;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 8px;
}

.data-table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  font-size: 12px;
}

.data-table th, .data-table td {
  padding: 7px 10px;
  border-bottom: 1px solid var(--border);
  border-right: 1px solid #eef2f6;
  white-space: nowrap;
}

.data-table thead th {
  position: sticky;
  top: 0;
  z-index: 2;
  background: #f8fafc;
  font-weight: 700;
  text-align: left;
  border-bottom: 2px solid var(--border);
}

.data-table tbody tr:hover td {
  background: var(--hover);
}

.num {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

/* Sticky first 3 columns in matrix */
.matrix-table th.col-sku, .matrix-table td.col-sku {
  position: sticky;
  left: 0;
  z-index: 1;
  background: var(--card);
  min-width: 110px;
}

.matrix-table th.col-name, .matrix-table td.col-name {
  position: sticky;
  left: 110px;
  z-index: 1;
  background: var(--card);
  max-width: 220px;
  overflow: hidden;
  text-overflow: ellipsis;
}

.matrix-table thead th.col-sku,
.matrix-table thead th.col-name {
  z-index: 3;
  background: #f8fafc;
}

.matrix-cell {
  cursor: pointer;
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.matrix-cell.empty {
  color: #cbd5e1;
  cursor: default;
}

.matrix-cell.is-alert {
  background: var(--alert-bg) !important;
  color: var(--alert-text);
  font-weight: 700;
}

.matrix-cell.is-min {
  outline: 2px solid var(--min-border);
  outline-offset: -2px;
  font-weight: 700;
}

.matrix-cell.is-selected {
  box-shadow: inset 0 0 0 2px var(--primary);
}

/* Detail panel */
.detail-panel {
  width: 360px;
  flex-shrink: 0;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 8px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.detail-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  background: #f8fafc;
}

.detail-header h3 {
  margin: 0;
  font-size: 14px;
}

.detail-body {
  flex: 1;
  overflow: auto;
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.detail-card {
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 10px;
  background: #fcfdff;
}

.detail-card-title {
  font-weight: 700;
  margin-bottom: 6px;
  word-break: break-word;
}

.detail-grid {
  display: grid;
  grid-template-columns: 80px 1fr;
  gap: 4px 8px;
  font-size: 12px;
}

.detail-grid dt {
  color: var(--muted);
}

.detail-grid dd {
  margin: 0;
  font-weight: 600;
  word-break: break-all;
}

/* Pager */
.pager {
  display: flex;
  align-items: center;
  gap: 8px;
}

/* Modal */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}

.modal-card {
  width: 340px;
  background: var(--card);
  padding: 24px;
  border-radius: 12px;
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.2);
}

.modal-card h2 {
  margin: 0 0 6px;
  font-size: 16px;
}

.modal-card form {
  margin-top: 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.modal-card input[type="email"],
.modal-card input[type="password"] {
  padding: 9px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 13px;
}

@media (max-width: 900px) {
  .matrix-layout {
    flex-direction: column;
  }
  .detail-panel {
    width: 100%;
    max-height: 45vh;
  }
}
