:root {
  --bg: #f4f6f8;
  --panel: #fff;
  --text: #1d2733;
  --muted: #66758a;
  --line: #dce2ea;
  --accent: #2364aa;
  --accent-dark: #174c86;
  --good: #1f8a5b;
  --warn: #a86200;
  --shadow: 0 12px 30px rgba(29, 39, 51, .08);
}

* { box-sizing: border-box; }
body { margin: 0; min-height: 100vh; background: var(--bg); color: var(--text); font-family: Arial, Helvetica, sans-serif; }
button, input, select, textarea { font: inherit; }
.hidden { display: none !important; }

.login { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.login-card { width: min(430px, 100%); display: grid; gap: 14px; padding: 24px; border: 1px solid var(--line); border-radius: 8px; background: #fff; box-shadow: var(--shadow); }
.brand { display: flex; align-items: center; gap: 12px; margin-bottom: 16px; }
.brand-mark { width: 42px; height: 42px; display: block; flex: 0 0 42px; border-radius: 8px; background: #e8f1fb; object-fit: cover; }
.brand strong, .brand span { display: block; }
.brand span, label span, small, .hint, .user { color: var(--muted); font-size: 13px; }
.remember-login { display: flex; align-items: center; gap: 9px; }
.remember-login input { width: 18px; min-height: 18px; flex: 0 0 18px; }
.remember-login span { color: var(--text); font-size: 14px; }
.error { min-height: 18px; margin: 0; color: #b42318; font-size: 13px; }

.shell { display: grid; grid-template-columns: 248px 1fr; min-height: 100vh; }
aside { padding: 22px 16px; background: #18212d; color: #fff; }
aside .brand span { color: #b8c4d2; }
nav { display: grid; gap: 8px; }
.nav { min-height: 42px; border: 0; border-radius: 8px; padding: 9px 12px; background: transparent; color: #dce5ef; text-align: left; cursor: pointer; }
.nav:hover, .nav.active { background: #243246; color: #fff; }

main { padding: 24px; min-width: 0; }
.topbar { display: flex; justify-content: space-between; align-items: center; gap: 16px; margin-bottom: 20px; }
h1 { margin: 0 0 4px; font-size: 28px; }
h2 { margin: 0 0 14px; font-size: 18px; }
p { margin: 0; }
.actions { display: flex; align-items: center; gap: 10px; }

input, select, textarea { width: 100%; min-height: 40px; border: 1px solid var(--line); border-radius: 6px; padding: 9px 10px; background: #fff; color: var(--text); }
textarea { resize: vertical; min-height: 280px; }
.primary, .ghost, .danger { min-height: 40px; border-radius: 6px; padding: 9px 14px; border: 1px solid transparent; cursor: pointer; white-space: nowrap; }
.primary { background: var(--accent); color: #fff; font-weight: 700; }
.primary:hover { background: var(--accent-dark); }
.ghost { background: #fff; border-color: var(--line); color: var(--text); }
.danger { background: #fff; border-color: #f1b7b0; color: #b42318; font-weight: 700; }
.danger:hover { background: #fff4f2; }

.view { display: none; }
.view.visible { display: block; }
.metrics { display: grid; grid-template-columns: repeat(4, minmax(150px, 1fr)); gap: 14px; margin-bottom: 16px; }
.metrics article, .panel { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; box-shadow: var(--shadow); }
.metrics article { padding: 18px; }
.metrics span { display: block; color: var(--muted); font-size: 13px; margin-bottom: 8px; }
.metrics strong { font-size: 30px; }
.panel { padding: 16px; }
.panel-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 14px; }
.table-wrap { overflow-x: auto; }
table { width: 100%; min-width: 980px; border-collapse: collapse; }
th, td { padding: 11px 8px; border-bottom: 1px solid var(--line); text-align: left; font-size: 14px; }
th { color: var(--muted); font-size: 12px; text-transform: uppercase; }
.status { display: inline-flex; min-height: 24px; align-items: center; border-radius: 6px; padding: 3px 8px; font-size: 12px; font-weight: 700; }
.status.pending { background: #fff3df; color: var(--warn); }
.status.posted { background: #e6f5ee; color: var(--good); }
.status.error { background: #fff4f2; color: #b42318; }
.history-comment { min-width: 240px; max-width: 420px; white-space: pre-wrap; }

.grid { display: grid; grid-template-columns: repeat(2, minmax(220px, 1fr)); gap: 14px; max-width: 980px; }
.full { grid-column: 1 / -1; }
.total { display: flex; justify-content: space-between; align-items: center; min-height: 40px; border: 1px solid var(--line); border-radius: 6px; padding: 9px 12px; background: #f8fafc; }
.positions-block { display: grid; gap: 10px; }
.panel-head.compact { margin-bottom: 0; }
.panel-head.compact h2 { margin: 0; font-size: 16px; }
.position-rows { display: grid; gap: 10px; }
.position-row { display: grid; grid-template-columns: minmax(130px, .75fr) minmax(220px, 1.35fr) minmax(130px, .8fr) 110px 110px auto; gap: 10px; align-items: end; border: 1px solid var(--line); border-radius: 8px; padding: 10px; background: #fbfcfe; }
.position-row label span { white-space: nowrap; }
.position-row .remove-position { min-height: 40px; }
.people { overflow-x: auto; border: 1px solid var(--line); border-radius: 8px; background: #fff; }
.employee-table { width: 100%; min-width: 1320px; border-collapse: collapse; }
.employee-table th, .employee-table td { padding: 10px 8px; border-bottom: 1px solid var(--line); vertical-align: top; text-align: left; }
.employee-table th { position: sticky; top: 0; z-index: 1; background: #f5f7fa; color: var(--muted); font-size: 13px; font-weight: 700; }
.employee-table tr:last-child td { border-bottom: 0; }
.employee-table strong { display: block; min-width: 180px; }
.employee-table small, .muted { color: var(--muted); font-size: 12px; }
.employee-table input, .employee-table select { width: 100%; min-height: 36px; padding: 7px 8px; }
.employee-table .fixed-rate, .employee-table .monthly-salary, .employee-table .advance-amount { min-width: 92px; }
.employee-table .advance-comment { min-width: 180px; }
.employee-actions { min-width: 170px; }
.employee-actions button { width: 100%; min-height: 34px; padding: 6px 10px; margin-bottom: 6px; }
.employee-actions button:last-child { margin-bottom: 0; }
.open-report { min-height: 34px; padding: 6px 10px; }
.sku-edit { display: grid; grid-template-columns: minmax(120px, 1fr) auto; gap: 6px; align-items: center; min-width: 260px; }
.sku-edit input { min-height: 34px; padding: 6px 8px; }
.sku-edit button { min-height: 34px; padding: 6px 10px; white-space: nowrap; }
.modal { position: fixed; inset: 0; z-index: 20; display: grid; place-items: center; padding: 20px; background: rgba(15, 23, 34, .55); }
.modal-card { width: min(980px, 100%); max-height: min(760px, calc(100vh - 40px)); overflow: auto; padding: 16px; border: 1px solid var(--line); border-radius: 8px; background: #fff; box-shadow: var(--shadow); }
.report-detail { display: grid; gap: 14px; }
.detail-grid { display: grid; grid-template-columns: repeat(3, minmax(160px, 1fr)); gap: 10px; margin: 0; }
.detail-grid div { padding: 10px; border: 1px solid var(--line); border-radius: 8px; background: #fbfcfe; }
.detail-grid dt { color: var(--muted); font-size: 12px; }
.detail-grid dd { margin: 4px 0 0; font-weight: 700; }
.report-detail h3 { margin: 4px 0 0; font-size: 16px; }
.compact-table table { min-width: 760px; }
.comment-box { min-height: 72px; padding: 12px; border: 1px solid var(--line); border-radius: 8px; background: #fbfcfe; white-space: pre-wrap; }
.comment-box p { margin: 0 0 8px; }
.comment-box p:last-child { margin-bottom: 0; }
.review-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.control-list { display: grid; gap: 10px; margin-bottom: 16px; }
.control-item { display: grid; gap: 4px; padding: 12px; border: 1px solid var(--line); border-left: 4px solid var(--warn); border-radius: 8px; background: #fffdf7; }
.control-item.high { border-left-color: #b42318; background: #fff8f6; }
.control-item span { color: var(--muted); white-space: pre-wrap; }
.backup-list { display: grid; gap: 8px; }
.backup-item { display: flex; justify-content: space-between; gap: 12px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 8px; background: #fbfcfe; }
.backup-item span { color: var(--muted); font-size: 13px; }
.report-email { display: grid; grid-template-columns: 180px minmax(240px, 420px); gap: 10px; align-items: center; margin-bottom: 12px; }
.report-email span { color: var(--muted); font-size: 13px; }
.marketplace-summary { display: grid; grid-template-columns: 180px minmax(280px, 1fr); gap: 10px; align-items: start; margin-bottom: 12px; }
.marketplace-summary span { color: var(--muted); font-size: 13px; padding-top: 8px; }
.marketplace-summary textarea { min-height: 110px; resize: vertical; }
.smtp-grid { display: grid; grid-template-columns: repeat(4, minmax(150px, 1fr)); gap: 10px; margin: 0 0 12px 0; padding: 12px; border: 1px solid var(--line); border-radius: 8px; background: #fbfcfe; }
.smtp-grid label { display: grid; gap: 5px; }
.smtp-grid label span, .smtp-grid small { color: var(--muted); font-size: 13px; }
.smtp-grid small { align-self: end; min-height: 40px; display: flex; align-items: center; }
.production-map { margin-top: 18px; }
.production-map h3 { margin: 0 0 10px; font-size: 16px; }
.mapping-list { display: grid; gap: 10px; }
.mapping-row { display: grid; grid-template-columns: minmax(180px, 1fr) minmax(220px, 1.1fr) auto minmax(220px, 1.1fr) auto auto; gap: 10px; align-items: end; border: 1px solid var(--line); border-radius: 8px; padding: 10px; background: #fbfcfe; }
.mapping-title strong, .mapping-title span { display: block; }
.mapping-title span, .mapping-status { color: var(--muted); font-size: 13px; }
.mapping-status { grid-column: 1 / -1; min-height: 18px; }
.empty-map { border: 1px dashed var(--line); border-radius: 8px; padding: 14px; color: var(--muted); background: #fbfcfe; }
pre { min-height: 260px; overflow: auto; border: 1px solid var(--line); border-radius: 8px; padding: 14px; background: #101820; color: #e9f2fb; }

@media (max-width: 900px) {
  .shell { grid-template-columns: 1fr; }
  aside { position: sticky; top: 0; z-index: 2; padding: max(10px, env(safe-area-inset-top)) 12px 12px; }
  aside .brand { margin-bottom: 10px; }
  nav { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 2px; scrollbar-width: none; }
  nav::-webkit-scrollbar { display: none; }
  .nav { flex: 0 0 auto; min-height: 40px; white-space: nowrap; }
  .topbar, .actions { align-items: stretch; flex-direction: column; }
  .metrics, .grid { grid-template-columns: 1fr; }
  .position-row { grid-template-columns: 1fr; }
  .mapping-row { grid-template-columns: 1fr; }
  .detail-grid { grid-template-columns: 1fr; }
  .report-email { grid-template-columns: 1fr; }
  .marketplace-summary { grid-template-columns: 1fr; }
  .smtp-grid { grid-template-columns: 1fr; }
  main { padding: 16px max(12px, env(safe-area-inset-right)) calc(22px + env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left)); }
  h1 { font-size: 24px; }
  .panel { padding: 14px; }
  .login { padding: 16px; }
  .login-card { padding: 18px; }
  .primary, .ghost, .danger, input, select { min-height: 44px; }
}

@media (max-width: 520px) {
  .brand-mark { width: 38px; height: 38px; flex-basis: 38px; }
  .brand { gap: 10px; }
  .metrics strong { font-size: 26px; }
  textarea { min-height: 220px; }
  table { min-width: 760px; }
}
