:root {
  --bg: #eef2f5;
  --panel: #ffffff;
  --text: #17202a;
  --muted: #6a7480;
  --line: #d8e0e7;
  --accent: #0c5f73;
  --accent-2: #b7352d;
  --soft: #e7f4f6;
  --warn: #a96900;
  --shadow: 0 18px 50px rgba(20, 34, 45, 0.12);
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: Inter, "Segoe UI", Arial, sans-serif;
  color: var(--text);
  background: var(--bg);
}
button, input, select, textarea { font: inherit; }
button {
  border: 0;
  cursor: pointer;
  border-radius: 6px;
  padding: 10px 14px;
  font-weight: 700;
}
.primary { background: var(--accent); color: #fff; }
.secondary { background: #edf3f5; color: var(--text); border: 1px solid var(--line); }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.error { color: var(--accent-2); min-height: 18px; }
.eyebrow {
  color: var(--accent);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0;
  margin: 0 0 4px;
  text-transform: uppercase;
}
.stack { display: grid; gap: 14px; }
label { display: grid; gap: 6px; font-size: 13px; font-weight: 700; color: #3e4a55; }
input, select, textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 10px 12px;
  background: #fff;
  color: var(--text);
}
textarea { min-height: 86px; resize: vertical; }

.login-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    linear-gradient(135deg, rgba(12,95,115,.12), rgba(183,53,45,.08)),
    var(--bg);
}
.login-panel {
  width: min(440px, 100%);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 34px;
}
.login-panel h1, .topbar h1, h2, h3 { margin: 0; letter-spacing: 0; }

.app {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 320px 1fr;
  grid-template-rows: auto 1fr;
}
.topbar {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: minmax(220px, 340px) 1fr auto;
  gap: 18px;
  align-items: center;
  padding: 18px 22px;
  border-bottom: 1px solid var(--line);
  background: rgba(255,255,255,.92);
  position: sticky;
  top: 0;
  z-index: 5;
}
.searchbar {
  display: grid;
  grid-template-columns: 1fr 160px auto auto;
  gap: 10px;
  align-items: center;
}
.price-message { color: var(--muted); font-size: 12px; font-weight: 700; min-width: 110px; }
.account {
  display: flex;
  gap: 8px;
  align-items: center;
  white-space: nowrap;
}
.account span { font-size: 13px; color: var(--muted); }

.sidebar {
  border-right: 1px solid var(--line);
  background: #f9fbfc;
  min-height: 0;
  overflow: hidden;
  display: grid;
  grid-template-rows: auto 1fr;
}
.sidebar-head { padding: 16px; border-bottom: 1px solid var(--line); display: grid; gap: 10px; }
.system-list { overflow: auto; padding: 10px; }
.group-title {
  padding: 14px 8px 6px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}
.system-item {
  display: grid;
  grid-template-columns: 74px 1fr auto;
  gap: 10px;
  width: 100%;
  text-align: left;
  background: transparent;
  border: 1px solid transparent;
  padding: 10px 8px;
  border-radius: 6px;
  font-weight: 500;
}
.system-item:hover, .system-item.active { background: var(--soft); border-color: #b9d9df; }
.system-code { font-weight: 800; color: var(--accent); }
.system-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.count { color: var(--muted); font-size: 12px; }

.workspace { padding: 18px; overflow: auto; }
.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 8px 24px rgba(20,34,45,.06);
}
.system-panel { padding: 16px; min-height: calc(100vh - 112px); }
.section-head {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  align-items: center;
  margin-bottom: 14px;
}
.section-head.compact { margin: 0 0 8px; }
.totals {
  min-width: 190px;
  display: grid;
  justify-items: end;
  gap: 2px;
}
.totals span { font-size: 22px; font-weight: 900; color: var(--accent); }
.totals small { color: var(--muted); }

.visual-grid {
  display: grid;
  grid-template-columns: minmax(420px, 54%) minmax(420px, 46%);
  gap: 14px;
  min-height: 680px;
}
.drawing-box, .detail-box {
  border: 1px solid var(--line);
  border-radius: 8px;
  min-height: 680px;
  overflow: hidden;
  background: #fff;
}
.drawing-box {
  display: grid;
  grid-template-rows: auto 1fr;
  position: relative;
}
.image-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 10px;
  border-bottom: 1px solid var(--line);
  background: #f7fafb;
}
.image-tabs button {
  padding: 7px 10px;
  background: #fff;
  border: 1px solid var(--line);
  font-size: 12px;
}
.image-tabs button.active { background: var(--accent); color: #fff; }
.system-image {
  width: 100%;
  height: 100%;
  min-height: 630px;
  object-fit: contain;
  background: #fff;
}
.empty-state {
  position: absolute;
  inset: 52px 0 0;
  display: grid;
  place-items: center;
  color: var(--muted);
}
.detail-box { padding: 12px; display: grid; grid-template-rows: auto 1fr; }
.check { display: flex; align-items: center; gap: 8px; font-weight: 700; }
.check input { width: auto; }

.parts-table {
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 6px;
}
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { padding: 9px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
th {
  background: #edf3f5;
  position: sticky;
  top: 0;
  z-index: 1;
  text-align: left;
}
tr:hover td { background: #fbfdfd; }
.row-check { width: 28px; }
.part-code { font-weight: 900; color: #1f3a4d; white-space: nowrap; }
.flags { display: flex; flex-wrap: wrap; gap: 4px; }
.pill {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 4px 8px;
  background: #eef3f5;
  border: 1px solid var(--line);
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}
.pill.warn { color: var(--warn); background: #fff8e8; border-color: #f0d08d; }

.drawer {
  position: fixed;
  right: 0;
  top: 0;
  bottom: 0;
  width: min(520px, 96vw);
  background: #fff;
  box-shadow: var(--shadow);
  z-index: 20;
  padding: 24px;
  overflow: auto;
  border-left: 1px solid var(--line);
}
.icon-button {
  width: 36px;
  height: 36px;
  padding: 0;
  border: 1px solid var(--line);
  background: #fff;
  font-size: 24px;
}
.drawer .icon-button, .modal .icon-button { position: absolute; right: 14px; top: 14px; }
.detail-grid { display: grid; gap: 12px; margin-top: 18px; }
.source-image { width: 100%; max-height: 320px; object-fit: contain; border: 1px solid var(--line); border-radius: 6px; }
.price-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.price-card { border: 1px solid var(--line); border-radius: 6px; padding: 10px; display: grid; gap: 4px; }
.price-card strong { color: var(--accent); font-size: 18px; }

.modal {
  position: fixed;
  inset: 0;
  background: rgba(12, 24, 35, .45);
  display: grid;
  place-items: center;
  padding: 24px;
  z-index: 30;
}
.modal-card {
  position: relative;
  width: min(980px, 96vw);
  max-height: 92vh;
  overflow: auto;
  background: #fff;
  border-radius: 8px;
  padding: 24px;
  box-shadow: var(--shadow);
}
.modal-card.narrow { width: min(430px, 96vw); }
.admin-grid { display: grid; grid-template-columns: 320px 1fr; gap: 24px; }
.users-list { display: grid; gap: 8px; }
.user-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 10px;
}
.user-actions { display: flex; flex-wrap: wrap; gap: 6px; }
.user-actions button { padding: 7px 9px; font-size: 12px; }

@media (max-width: 1100px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { grid-row: 2; max-height: 300px; border-right: 0; border-bottom: 1px solid var(--line); }
  .workspace { grid-row: 3; }
  .topbar { grid-template-columns: 1fr; }
  .searchbar { grid-template-columns: 1fr; }
  .visual-grid { grid-template-columns: 1fr; }
  .admin-grid { grid-template-columns: 1fr; }
}
