:root {
  --bg: #f6f7f9;
  --panel: #ffffff;
  --ink: #1f2933;
  --muted: #68727f;
  --line: #dbe1e8;
  --accent: #256f6c;
  --accent-strong: #184f4d;
  --warn: #b45309;
  --danger: #b42318;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--ink);
  background: var(--bg);
}

button, input, select, textarea {
  font: inherit;
}

button {
  border: 0;
  border-radius: 6px;
  background: var(--accent);
  color: white;
  min-height: 38px;
  padding: 0 14px;
  cursor: pointer;
}

button:hover { background: var(--accent-strong); }

button.secondary {
  background: #eef3f5;
  color: #26313d;
  border: 1px solid var(--line);
}

button.secondary:hover {
  background: #dfe7eb;
}

.link-button {
  min-height: auto;
  padding: 0;
  background: transparent;
  color: var(--accent);
  font-weight: 700;
  text-align: left;
}

.link-button:hover {
  background: transparent;
  color: var(--accent-strong);
  text-decoration: underline;
}

input, select, textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: white;
  color: var(--ink);
  padding: 9px 10px;
}

textarea { min-height: 78px; resize: vertical; }

label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 13px;
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 1120px;
}

th, td {
  border-bottom: 1px solid var(--line);
  padding: 10px 12px;
  text-align: left;
  vertical-align: top;
  font-size: 13px;
}

th {
  position: sticky;
  top: 0;
  background: #eef3f5;
  color: #4a5562;
  font-weight: 700;
  white-space: nowrap;
}

td {
  color: #26313d;
}

td:nth-child(1),
td:nth-child(3),
td:nth-child(5),
td:nth-child(6),
td:nth-child(7) {
  white-space: nowrap;
}

.hidden { display: none !important; }

.login-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background: linear-gradient(135deg, #eef3f5, #f8faf7 52%, #edf4ef);
}

.login-panel {
  width: min(860px, 100%);
  display: grid;
  grid-template-columns: 1.2fr 0.8fr;
  gap: 36px;
  align-items: center;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 42px;
  box-shadow: 0 20px 60px rgba(31, 41, 51, 0.12);
}

.login-panel h1 {
  margin: 6px 0 10px;
  font-size: 34px;
  letter-spacing: 0;
}

.eyebrow {
  margin: 0;
  color: var(--accent);
  font-weight: 700;
}

.muted { color: var(--muted); line-height: 1.7; }
.error { color: var(--danger); min-height: 20px; margin: 0; }
.stack { display: grid; gap: 16px; }

.app-shell {
  display: grid;
  grid-template-columns: 220px 1fr;
  min-height: 100vh;
}

.sidebar {
  display: flex;
  flex-direction: column;
  gap: 18px;
  padding: 18px;
  background: #182326;
  color: white;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 56px;
}

.mark {
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border-radius: 6px;
  background: #e6b54a;
  color: #172024;
  font-weight: 800;
}

.brand small {
  display: block;
  color: #a8b3ba;
  margin-top: 3px;
}

nav {
  display: grid;
  gap: 8px;
}

.nav-btn, .ghost {
  width: 100%;
  text-align: left;
  background: transparent;
  color: #d9e3e7;
}

.nav-btn.active, .nav-btn:hover, .ghost:hover {
  background: rgba(255,255,255,0.1);
}

.ghost { border: 1px solid rgba(255,255,255,0.18); }
#archiveBtn { margin-top: auto; }

.workspace {
  min-width: 0;
  padding: 18px;
}

.topbar {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 18px;
}

.topbar h2 {
  margin: 0 0 4px;
  font-size: 24px;
}

.topbar p {
  margin: 0;
  color: var(--muted);
}

.searchbar {
  display: grid;
  grid-template-columns: 140px minmax(260px, 460px);
  gap: 10px;
}

.metrics {
  display: grid;
  grid-template-columns: repeat(3, minmax(160px, 1fr));
  gap: 14px;
  margin-bottom: 16px;
}

.metrics article, .panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.metrics article {
  padding: 18px;
}

.metrics span {
  display: block;
  font-size: 32px;
  font-weight: 800;
}

.metrics small { color: var(--muted); }

.panel {
  min-width: 0;
  overflow: hidden;
}

.panel-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
}

.panel h3 {
  margin: 0;
  font-size: 16px;
}

.table-wrap {
  overflow: auto;
  max-height: calc(100vh - 210px);
}

.split {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 360px;
  gap: 16px;
  align-items: start;
}

.product-main {
  display: grid;
  gap: 16px;
  min-width: 0;
}

.product-side {
  display: grid;
  gap: 16px;
  align-content: start;
}

.product-table-wrap table {
  min-width: 560px;
}

.product-version-wrap table {
  min-width: 980px;
}

.selected-row td {
  background: #edf7f5;
}

.panel-subtitle {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.action-cell {
  display: flex;
  gap: 8px;
  white-space: nowrap;
}

.category-list {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  padding: 14px 16px 16px;
}

.category-item {
  display: inline-flex;
  align-items: center;
  min-height: 32px;
  padding: 0 12px;
  border-radius: 6px;
  background: #edf4ef;
  color: var(--accent);
  border: 1px solid #cfe0db;
  font-weight: 700;
}

.category-item:hover,
.category-item.active {
  background: #dfeee9;
  color: var(--accent-strong);
  border-color: #9bc7bd;
}

.inline-form,
.category-manage-form {
  display: grid;
  grid-template-columns: minmax(180px, 1fr) auto auto;
  gap: 10px;
  padding: 12px 16px 16px;
}

.category-manage-form {
  grid-template-columns: 220px minmax(220px, 1fr) auto;
  align-items: end;
}

.product-side .category-manage-form {
  grid-template-columns: 1fr;
}

.category-actions {
  grid-template-columns: auto auto auto;
}

.product-side .category-actions {
  grid-template-columns: 1fr 1fr;
}

.product-edit-actions {
  grid-template-columns: 1fr auto;
}

button.danger {
  color: var(--danger);
}

.form-message {
  min-height: 20px;
  margin: -4px 16px 12px;
  color: var(--accent);
  font-size: 13px;
  font-weight: 700;
}

.form-panel .form-message {
  margin: 0;
}

.error-text {
  color: var(--danger);
}

.detail-topline {
  margin-bottom: 12px;
}

.product-detail-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 16px;
  align-items: start;
}

.product-detail-main {
  min-width: 0;
}

.detail-main-forms {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 16px;
  margin-top: 16px;
}

.selected-version-row {
  background: #f0f8f6;
  box-shadow: inset 4px 0 0 var(--accent);
}

.version-group-row td {
  background: #f8fafb;
  border-top: 2px solid var(--line);
  border-bottom: 1px solid var(--line);
  color: var(--text);
  padding: 14px 20px;
}

.version-group-row span {
  display: inline-block;
  font-size: 16px;
  font-weight: 800;
  margin-right: 10px;
}

.version-group-row small {
  color: var(--muted);
  font-weight: 700;
}

.version-pick {
  min-height: auto;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--accent);
  font: inherit;
  font-weight: 700;
  text-align: left;
}

.version-pick:hover {
  text-decoration: underline;
}

.product-files-section {
  border-top: 1px solid var(--border);
  margin-top: 16px;
  padding-top: 14px;
}

.inline-head {
  padding: 0 0 10px;
}

.product-file-groups {
  display: grid;
  gap: 12px;
}

.product-file-group {
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  background: #fff;
}

.file-group-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 12px;
  background: #edf4ef;
  color: var(--text);
}

.file-group-head h4 {
  margin: 0;
  font-size: 16px;
}

.file-group-head span,
.empty-file-group {
  color: var(--muted);
}

.empty-file-group {
  padding: 12px;
}

.detail-side {
  display: grid;
  gap: 16px;
  align-content: start;
}

.compact-form textarea {
  min-height: 64px;
}

.wide-main {
  grid-template-columns: minmax(0, 1fr) 420px;
}

.form-panel {
  display: grid;
  gap: 12px;
  padding: 16px;
}

.grid-3 {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}

.grid-2 {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.button-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  align-items: center;
}

.audit-filters {
  display: grid;
  grid-template-columns: minmax(260px, 1fr) minmax(140px, 180px) minmax(140px, 170px) minmax(140px, 170px);
  gap: 10px;
  padding: 0 0 12px;
}

.attachment-mode-row {
  grid-template-columns: 1fr 1fr;
}

.small {
  min-height: 32px;
  padding: 0 10px;
  background: #52616b;
}

.pill {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 0 8px;
  border-radius: 999px;
  background: #edf4ef;
  color: #256f6c;
  font-weight: 700;
  font-size: 12px;
}

.file-cell {
  min-width: 180px;
}

.attachment-item {
  display: grid;
  gap: 4px;
  margin-bottom: 6px;
}

.attachment-actions {
  display: flex;
  gap: 8px;
}

.mini-action {
  min-height: 24px;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--accent);
  font-size: 12px;
  font-weight: 700;
}

.danger-text {
  color: var(--danger);
}

.file-link {
  display: block;
  color: var(--accent);
  text-decoration: none;
  line-height: 1.5;
  max-width: 260px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.file-link:hover {
  text-decoration: underline;
}

.muted-cell {
  color: var(--muted);
}

fieldset {
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 10px;
}

legend {
  color: var(--muted);
  font-size: 13px;
}

.check {
  display: inline-flex;
  grid-template-columns: auto 1fr;
  align-items: center;
  gap: 6px;
  margin: 6px 12px 6px 0;
}

.check input {
  width: auto;
}

.toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  background: #182326;
  color: white;
  border-radius: 8px;
  padding: 12px 14px;
  box-shadow: 0 12px 30px rgba(0,0,0,0.22);
}

@media (max-width: 980px) {
  .app-shell { grid-template-columns: 1fr; }
  .sidebar { position: static; }
  .topbar, .login-panel { grid-template-columns: 1fr; }
  .split {
    display: flex;
    flex-direction: column;
  }
  .form-panel {
    order: -1;
  }
  .topbar { align-items: stretch; }
  .searchbar { grid-template-columns: 1fr; }
  .metrics { grid-template-columns: 1fr; }
  .table-wrap { max-height: 420px; }
  .inline-form,
  .category-manage-form,
  .category-actions,
  .grid-2,
  .detail-main-forms { grid-template-columns: 1fr; }
  .audit-filters { grid-template-columns: 1fr; }
  .product-detail-layout { grid-template-columns: 1fr; }
}
