/* ERP Web - Main Stylesheet */
:root {
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --sidebar-bg: #111827;
  --sidebar-text: #d1d5db;
  --sidebar-active: #2563eb;
  --sidebar-hover: #374151;
  --bg: #f3f4f6;
  --surface: #ffffff;
  --border: #e5e7eb;
  --text: #111827;
  --text-soft: #6b7280;
  --red: #dc2626;
  --red-soft: #fef2f2;
  --orange: #ea580c;
  --orange-soft: #fff7ed;
  --green: #16a34a;
  --green-soft: #f0fdf4;
  --blue-soft: #eff6ff;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; height: 100%; }
body {
  font-family: var(--font);
  color: var(--text);
  background: var(--bg);
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
}
#root { height: 100%; }
button { font-family: inherit; cursor: pointer; }
input, select { font-family: inherit; }

/* ===== Layout ===== */
.layout {
  display: flex;
  height: 100vh;
  overflow: hidden;
}

.sidebar {
  width: 140px;
  background: var(--sidebar-bg);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
}

.sidebar-title {
  padding: 14px 16px;
  border-bottom: 1px solid #374151;
  font-size: 13px;
  font-weight: 700;
  color: #60a5fa;
  line-height: 1.4;
}

.sidebar-nav {
  flex: 1;
  overflow-y: auto;
  padding: 8px 0;
}

.nav-btn {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 16px;
  font-size: 13px;
  text-align: left;
  background: none;
  border: none;
  color: var(--sidebar-text);
  transition: background 0.15s;
}
.nav-btn:hover { background: var(--sidebar-hover); color: white; }
.nav-btn.active { background: var(--sidebar-active); color: white; }

.main-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.main-header {
  background: white;
  border-bottom: 1px solid var(--border);
  padding: 12px 24px;
  flex-shrink: 0;
}

.main-header h2 {
  margin: 0;
  font-size: 16px;
  font-weight: 600;
  color: var(--text);
}

.main-content {
  flex: 1;
  overflow: auto;
  padding: 16px;
}

/* ===== Cards / Surface ===== */
.card {
  background: var(--surface);
  border-radius: 8px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.08);
  padding: 16px;
}

.card-toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 12px;
  flex-wrap: wrap;
}

/* ===== Buttons ===== */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 6px 12px;
  border-radius: 6px;
  font-size: 13px;
  border: 1px solid transparent;
  cursor: pointer;
  transition: background 0.15s;
}
.btn-default { background: #f3f4f6; color: #374151; border-color: #e5e7eb; }
.btn-default:hover { background: #e5e7eb; }
.btn-primary { background: var(--primary); color: white; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-success { background: #16a34a; color: white; }
.btn-success:hover { background: #15803d; }
.btn-danger { background: var(--red); color: white; }
.btn-danger:hover { background: #b91c1c; }
.btn-orange { background: #ea580c; color: white; }
.btn-orange:hover { background: #c2410c; }
.btn-green-outline { background: #f0fdf4; color: #16a34a; border-color: #bbf7d0; }
.btn-green-outline:hover { background: #dcfce7; }
.btn-blue-outline { background: var(--blue-soft); color: var(--primary); border-color: #bfdbfe; }
.btn-blue-outline:hover { background: #dbeafe; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* ===== Tables ===== */
/* 限定滚动高度，配合 sticky 表头实现「表头冻结、表体滚动」 */
.table-wrap { overflow: auto; max-height: calc(100vh - 240px); }
.data-table {
  min-width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
.data-table th {
  padding: 8px 12px;
  text-align: left;
  font-weight: 600;
  background: #f9fafb;
  border: 1px solid var(--border);
  color: #374151;
  white-space: nowrap;
}
/* 表头冻结：滚动时固定在滚动容器顶部。collapse 模式下用 box-shadow 保住底边线 */
.data-table thead th {
  position: sticky;
  top: var(--thead-top, 0px);
  z-index: 5;
  box-shadow: inset 0 -1px 0 var(--border), inset 0 1px 0 var(--border);
}
.data-table td {
  padding: 6px 12px;
  border: 1px solid var(--border);
  color: var(--text);
}
.data-table tr:hover td { background: #f9fafb; }
.data-table td.right { text-align: right; }
.data-table td.center { text-align: center; }
.empty-row td { text-align: center; color: var(--text-soft); padding: 24px; }

/* Freeze table */
.freeze-table {
  border-collapse: separate;
  border-spacing: 0;
  font-size: 12px;
}
.freeze-table th, .freeze-table td {
  padding: 6px 8px;
  border-right: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.freeze-table th {
  background: #f3f4f6;
  font-weight: 600;
  position: sticky;
  top: 0;
  z-index: 20;
  border-top: 1px solid var(--border);
}
.freeze-table th:first-child, .freeze-table td:first-child {
  border-left: 1px solid var(--border);
}
.sticky-c0 { position: sticky; left: 0; z-index: 10; background: white; }
.sticky-c1 { position: sticky; left: 80px; z-index: 10; background: white; }
.sticky-c2 { position: sticky; left: 150px; z-index: 10; background: white; }
.sticky-c3 { position: sticky; left: 350px; z-index: 10; background: white; }
.sticky-c4 { position: sticky; left: 330px; z-index: 10; background: white; }
.sticky-c5 { position: sticky; left: 390px; z-index: 10; background: white; }
.sticky-c6 { position: sticky; left: 450px; z-index: 10; background: white; }
.freeze-table th.sticky-c0,
.freeze-table th.sticky-c1,
.freeze-table th.sticky-c2,
.freeze-table th.sticky-c3,
.freeze-table th.sticky-c4,
.freeze-table th.sticky-c5,
.freeze-table th.sticky-c6 { z-index: 30; background: #f3f4f6; }

/* ===== Form inputs ===== */
.cell-input {
  width: 100%;
  padding: 2px 6px;
  font-size: 12px;
  border: 1px solid #93c5fd;
  border-radius: 4px;
  outline: none;
}
.cell-input:focus { border-color: var(--primary); }

/* ===== Colors for turnover / cells ===== */
.bg-orange { background: #fed7aa !important; }
.bg-green  { background: #bbf7d0 !important; }
.bg-red    { background: #fecaca !important; }
.bg-blue-light { background: #dbeafe !important; }
.bg-manual { background: #bfdbfe !important; }
.bg-seasonal { background: #f3f4f6; }
.bg-transit { background: #eff6ff; }
.text-blue { color: #1d4ed8; }
.text-orange { color: #c2410c; }
.text-red { color: #b91c1c; }
.text-green { color: #15803d; }
.text-soft { color: var(--text-soft); }
.text-bold { font-weight: 600; }
.font-medium { font-weight: 500; }

/* ===== Summary cards ===== */
.summary-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
  margin-bottom: 16px;
}
.summary-card {
  background: white;
  border-radius: 8px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.08);
  padding: 16px;
}
.summary-card .label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: var(--text-soft);
  margin-bottom: 4px;
}
.summary-card .value {
  font-size: 24px;
  font-weight: 700;
}
.summary-card .hint { font-size: 11px; color: var(--text-soft); margin-top: 2px; }

/* ===== Risk row colors ===== */
.row-danger { background: #fef2f2; }
.row-urgent { background: #fff7ed; }
.row-normal { background: white; }
.row-overstock { background: #eff6ff; }

/* ===== Badges ===== */
.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 9999px;
  font-size: 11px;
  font-weight: 500;
}
.badge-red { background: #fee2e2; color: #b91c1c; }
.badge-orange { background: #ffedd5; color: #c2410c; }
.badge-green { background: #dcfce7; color: #15803d; }
.badge-blue { background: #dbeafe; color: #1d4ed8; }

/* ===== Filter tabs ===== */
.filter-tabs {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
  margin-bottom: 12px;
}
.filter-tab {
  padding: 5px 12px;
  border-radius: 6px;
  font-size: 12px;
  border: 1px solid var(--border);
  background: #f9fafb;
  color: #374151;
  cursor: pointer;
}
.filter-tab:hover { background: #f3f4f6; }
.filter-tab.active { background: var(--primary); color: white; border-color: var(--primary); }

/* ===== Message ===== */
.msg-success { color: #16a34a; font-size: 13px; }
.msg-error { color: #dc2626; font-size: 13px; }

/* ===== Legend ===== */
.legend { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; font-size: 12px; color: var(--text-soft); }
.legend-item { display: flex; align-items: center; gap: 4px; }
.legend-box { width: 14px; height: 14px; border: 1px solid var(--border); border-radius: 2px; }

/* ===== Import/export ===== */
.import-link { text-decoration: none; }

/* ===== Loading ===== */
.loading { color: var(--text-soft); padding: 16px; font-size: 13px; }
.error-msg { color: var(--red); padding: 16px; font-size: 13px; }

/* ===== Icon action buttons ===== */
.icon-btn {
  background: none;
  border: none;
  padding: 2px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
}
.icon-btn-edit { color: #2563eb; }
.icon-btn-edit:hover { color: #1d4ed8; }
.icon-btn-del { color: #dc2626; }
.icon-btn-del:hover { color: #b91c1c; }
.icon-btn-ok { color: #16a34a; }
.icon-btn-ok:hover { color: #15803d; }
.icon-btn-cancel { color: #9ca3af; }
.icon-btn-cancel:hover { color: #6b7280; }
