:root {
  --bg: #f4f6f8;
  --panel: #ffffff;
  --panel-soft: #fafbfc;
  --text: #1f2937;
  --muted: #6b7280;
  --border: #d9dee5;
  --primary: #f7941d;
  --primary-strong: #e67e00;
  --primary-text: #161616;
  --success: #2e7d32;
  --danger: #c62828;
  --warning: #b26a00;
  --shadow: 0 10px 30px rgba(15, 23, 42, 0.08);
  --radius: 18px;
  --radius-sm: 12px;
  --sidebar-width: 270px;
  --sidebar-bg: #111827;
  --sidebar-text: #f9fafb;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
}
a { color: inherit; text-decoration: none; }
button, input, select, textarea { font: inherit; }
button { cursor: pointer; }

.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: var(--sidebar-width) 1fr;
}

.sidebar {
  background: var(--sidebar-bg);
  color: var(--sidebar-text);
  padding: 22px 18px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 10px 8px 16px 8px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.brand img {
  width: 52px;
  height: 52px;
  object-fit: contain;
  background: #ffffff;
  border-radius: 14px;
  padding: 6px;
}

.brand-title {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.brand-title strong {
  font-size: 18px;
  line-height: 1.1;
}

.brand-title span {
  font-size: 13px;
  color: rgba(255, 255, 255, 0.72);
}

.side-group { display: flex; flex-direction: column; gap: 8px; }
.side-label {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: rgba(255, 255, 255, 0.5);
  padding: 0 10px;
}
.side-link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 12px;
  border-radius: 12px;
  color: rgba(255, 255, 255, 0.88);
  transition: background .18s ease, color .18s ease;
}
.side-link:hover, .side-link.active {
  background: rgba(247, 148, 29, 0.16);
  color: #ffffff;
}
.sidebar-spacer { flex: 1 1 auto; }
.sidebar-footer {
  font-size: 12px;
  color: rgba(255, 255, 255, 0.55);
  padding: 0 10px;
}

.main { min-width: 0; display: flex; flex-direction: column; }
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  background: rgba(244, 246, 248, 0.92);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
  padding: 18px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}
.topbar-left h1 { margin: 0; font-size: 28px; line-height: 1.1; }
.topbar-left p { margin: 4px 0 0 0; color: var(--muted); font-size: 14px; }
.topbar-right { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.page-wrap { padding: 24px; display: flex; flex-direction: column; gap: 22px; }

.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
}
.card.soft { background: var(--panel-soft); box-shadow: none; }
.card h2, .card h3 { margin: 0 0 12px 0; }
.grid { display: grid; gap: 18px; }
.grid.cols-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.grid.cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid.cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.stat-card {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 18px;
  border-radius: 16px;
  border: 1px solid var(--border);
  background: linear-gradient(180deg, #ffffff 0%, #fafbfc 100%);
}
.stat-value { font-size: 30px; font-weight: 700; line-height: 1; }
.stat-label { font-size: 14px; color: var(--muted); }
.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 16px;
}
.inline { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.field { display: flex; flex-direction: column; gap: 6px; min-width: 180px; }
.field label, label { font-size: 14px; color: var(--muted); }
.input, .select, .textarea {
  width: 100%;
  border: 1px solid var(--border);
  background: #fff;
  color: var(--text);
  border-radius: 12px;
  padding: 12px 13px;
  outline: none;
}
.input:focus, .select:focus, .textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(247, 148, 29, 0.16);
}
.textarea { min-height: 110px; resize: vertical; }
.btn { border: none; border-radius: 12px; padding: 12px 16px; font-weight: 700; }
.btn.primary { background: var(--primary); color: var(--primary-text); }
.btn.primary:hover { background: var(--primary-strong); }
.btn.secondary { background: #eef1f4; color: var(--text); border: 1px solid var(--border); }
.btn.secondary:hover { background: #e6eaee; }
.btn.danger { background: #fff1f1; color: var(--danger); border: 1px solid #f3caca; }
.btn:disabled { opacity: .65; cursor: not-allowed; }
.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 10px;
  border-radius: 999px;
  background: #f3f4f6;
  color: var(--text);
  font-size: 12px;
  font-weight: 600;
}
.msg { min-height: 20px; font-size: 14px; }
.msg.good, .good { color: var(--success); }
.msg.bad, .bad { color: var(--danger); }
.msg.warn, .warn { color: var(--warning); }
.small, .muted { font-size: 13px; color: var(--muted); }
.search-results { display: grid; gap: 6px; margin-top: 8px; }
.search-result-btn {
  width: 100%;
  border: 1px solid var(--border);
  background: #fff;
  color: var(--text);
  border-radius: 8px;
  padding: 10px 12px;
  text-align: left;
  cursor: pointer;
}
.search-result-btn:hover, .search-result-btn.active { border-color: var(--primary); background: #fff8ed; }
.detail-panel {
  border: 1px solid var(--border);
  background: #fff;
  border-radius: 8px;
  padding: 10px 12px;
  margin-top: 8px;
}
.detail-grid { display: grid; gap: 6px; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); }
.detail-label { display: block; color: var(--muted); font-size: 12px; }
.detail-value { display: block; color: var(--text); font-weight: 700; overflow-wrap: anywhere; }
.table-wrap { overflow: auto; border: 1px solid var(--border); border-radius: 14px; }
.table { width: 100%; border-collapse: collapse; background: #fff; }
.table th, .table td { padding: 12px 14px; border-bottom: 1px solid var(--border); text-align: left; vertical-align: top; }
.table th { background: #fafbfc; font-size: 13px; color: var(--muted); }
.table tr:last-child td { border-bottom: none; }
.import-preview-wrap { margin-top: 14px; max-height: 360px; overflow: auto; }
.import-preview-table td { vertical-align: top; }
.import-row-valid td { background: #ecfdf5; }
.import-row-warning td { background: #fffbeb; }
.import-row-error td { background: #fef2f2; }
.hide { display: none !important; }

.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: linear-gradient(180deg, #f7f8fa 0%, #eef1f5 100%);
}
.login-wrap { width: 100%; max-width: 430px; }
.login-card { padding: 28px; }
.login-brand { display: flex; align-items: center; gap: 14px; margin-bottom: 22px; }
.login-brand img {
  width: 58px; height: 58px; object-fit: contain; border-radius: 14px; background: #fff; border: 1px solid var(--border); padding: 6px;
}
.login-brand h1 { margin: 0; font-size: 24px; line-height: 1.1; }
.login-brand p { margin: 4px 0 0 0; color: var(--muted); font-size: 14px; }
.login-footer { margin-top: 18px; color: var(--muted); font-size: 13px; text-align: center; }
.center-screen { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 24px; }

.site-footer {
  width: 100%;
  margin-top: 28px;
  border-top: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.86);
  color: var(--muted);
}

.site-footer-inner {
  width: 100%;
  max-width: 1180px;
  margin: 0 auto;
  padding: 14px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  font-size: 13px;
  line-height: 1.4;
}

.site-footer-links {
  display: flex;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
}

body.login-page {
  flex-direction: column;
  align-items: stretch;
  justify-content: flex-start;
}

body.login-page .login-wrap {
  margin: auto;
}

body.login-page .site-footer {
  flex: 0 0 auto;
  margin-top: 0;
}

@media (max-width: 1100px) {
  .grid.cols-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid.cols-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 860px) {
  .app-shell { grid-template-columns: 1fr; }
  .sidebar { display: none; }
  .grid.cols-4, .grid.cols-3, .grid.cols-2 { grid-template-columns: 1fr; }
  .topbar { padding: 16px; }
  .page-wrap { padding: 16px; }
  .site-footer-inner { padding: 14px 16px; flex-direction: column; align-items: flex-start; }
}
