:root {
  --bg: #f4f7ef;
  --ink: #0f1f1b;
  --card: #ffffff;
  --line: #d8e1d6;
  --accent: #1d6f5c;
  --accent2: #ff8a3d;
}
* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: 'Space Grotesk', sans-serif;
  color: var(--ink);
  background:
    radial-gradient(circle at 0 0, #ddeac8 0, transparent 35%),
    radial-gradient(circle at 100% 0, #e7d9c7 0, transparent 25%),
    var(--bg);
}
.shell { display: grid; grid-template-columns: 260px 1fr; min-height: 100vh; }
.sidebar {
  background: linear-gradient(180deg, #13231f, #1d352f);
  color: #e8f2ef;
  padding: 20px;
}
.brand {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 28px;
  font-weight: 600;
  margin-bottom: 24px;
  letter-spacing: 1px;
}
.brand-mark,
.brand-text {
  display: block;
}
.sidebar nav { display: grid; gap: 6px; }
.sidebar a {
  color: #e8f2ef;
  text-decoration: none;
  padding: 9px 10px;
  border-radius: 8px;
}
.nav-group { display: grid; gap: 4px; }
.nav-group > summary {
  list-style: none;
}
.nav-group > summary::-webkit-details-marker {
  display: none;
}
.nav-toggle {
  width: 100%;
  text-align: left;
  border-radius: 8px;
  padding: 9px 10px;
  font: inherit;
  color: #e8f2ef;
  background: transparent;
  cursor: pointer;
}
.nav-toggle:hover,
.nav-toggle:focus-visible {
  background: rgba(255,255,255,0.12);
}
.submenu {
  display: grid;
  margin-left: 10px;
  border-left: 1px solid rgba(232, 242, 239, 0.22);
  padding-left: 8px;
}
.nav-group:not([open]) .submenu { display: none; }
.submenu.open { gap: 4px; }
.submenu a {
  font-size: 13px;
  opacity: 0.95;
}
.sidebar a:hover { background: rgba(255,255,255,0.12); }
.content { padding: 26px; }
.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 14px;
}
.topbar h1 { margin: 0; font-size: 30px; }
.meta { text-align: right; }
.meta small { color: #5e6f6a; }
.panel, .card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 16px;
  margin-bottom: 16px;
  box-shadow: 0 10px 22px rgba(24, 43, 35, 0.05);
}
.grid.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; }
.card h3 { margin: 0 0 8px; color: #4f6a62; font-size: 14px; }
.card p { margin: 0; font-size: 24px; font-weight: 700; }
h2 { margin-top: 0; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 9px 8px; border-bottom: 1px solid var(--line); font-size: 14px; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 8px; margin-bottom: 12px; }
.form-grid.three { grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); }
.form-grid.four { grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); }
input, select, button {
  border: 1px solid #c7d3c8;
  border-radius: 8px;
  padding: 9px 10px;
  font-family: inherit;
}
button {
  background: linear-gradient(90deg, var(--accent), #2d9e83);
  color: white;
  border: 0;
  font-weight: 600;
  cursor: pointer;
}
button.remove-line {
  background: #ffe1d1;
  color: #7d2a00;
}
.alert {
  padding: 10px 12px;
  border-radius: 10px;
  margin-bottom: 12px;
  border: 1px solid;
}
.alert.success { background: #e5f8ef; border-color: #9fdfbf; }
.alert.danger { background: #ffecec; border-color: #efb7b7; }
.status-pill {
  display: inline-block;
  padding: 4px 8px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
}
.wf-draft { background: #e8ece9; color: #31443e; }
.wf-pending { background: #ffe7b8; color: #6b4b00; }
.wf-checked { background: #d8f0dd; color: #1a5b2d; }
.wf-noted { background: #dce9ff; color: #1c3f74; }
.wf-rejected { background: #ffd7d7; color: #7a1b1b; }
.login-page {
  min-height: 100vh;
  display: grid;
  place-items: center;
}
.login-card {
  width: min(92vw, 460px);
  background: white;
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 26px;
  box-shadow: 0 18px 35px rgba(0, 0, 0, 0.08);
}
.login-card h1 { margin-top: 0; }
.login-card p { margin-top: 0; color: #5b6f68; }
.login-card form { display: grid; gap: 8px; }

.prod-page .panel {
  background: transparent;
  box-shadow: none;
  border: 0;
  border-radius: 10px;
  padding: 0;
  margin-bottom: 10px;
}
.prod-page .panel h2 {
  margin: 0;
  font-size: 13px;
  font-weight: 700;
}
.prod-page .panel > h2 {
  padding: 7px 10px;
  border: 1px solid var(--line);
  border-bottom: 0;
  border-radius: 10px 10px 0 0;
}
.prod-page .panel > h2 + form {
  border: 1px solid var(--line);
  border-top: 0;
  border-radius: 0 0 10px 10px;
  padding: 8px;
}
.prod-page .form-grid {
  gap: 6px;
  margin-bottom: 8px;
}
.prod-page .form-grid.three {
  grid-template-columns: repeat(3, minmax(170px, 1fr));
}
.prod-page input,
.prod-page select,
.prod-page button {
  padding: 4px 6px;
  min-height: 30px;
  font-size: 12px;
}
.prod-page table {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
}
.prod-page table th,
.prod-page table td {
  padding: 6px;
  font-size: 12px;
  border: 1px solid var(--line);
}
.prod-page table th {
  background: transparent;
}
.prod-page .status-pill {
  font-size: 11px;
  padding: 3px 7px;
}
.prod-page td form {
  display: inline-flex;
  margin-right: 4px;
}
.prod-page .prod-shell {
  display: grid;
  grid-template-columns: 240px minmax(0, 1fr);
  gap: 10px;
  margin-bottom: 10px;
}
.prod-page .prod-recent-list {
  display: grid;
  gap: 6px;
  border: 1px solid var(--line);
  border-top: 0;
  border-radius: 0 0 10px 10px;
  padding: 8px;
  max-height: 580px;
  overflow: auto;
}
.prod-page .prod-recent-item {
  display: grid;
  gap: 2px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 6px;
  text-decoration: none;
  color: inherit;
  background: transparent;
}
.prod-page .prod-recent-item:hover {
  background: rgba(0, 0, 0, 0.04);
}
.prod-page .prod-recent-item small {
  color: #4d5f59;
}
.prod-page .prod-title-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  margin: 0;
  padding: 7px 10px;
  border: 1px solid var(--line);
  border-bottom: 0;
  border-radius: 10px 10px 0 0;
}
.prod-page .prod-title-row h2 {
  margin: 0;
}
.prod-page .prod-title-row a {
  color: var(--ink);
  text-decoration: none;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 2px 8px;
  font-size: 12px;
  background: transparent;
}
.prod-page .prod-title-row a:hover {
  background: rgba(0, 0, 0, 0.04);
}
@media (max-width: 1200px) {
  .prod-page .prod-shell {
    grid-template-columns: 1fr;
  }
  .prod-page .form-grid.three {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 960px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar { position: sticky; top: 0; z-index: 20; }
  .sidebar nav { grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); }
}

/* Unified app chrome */
body {
  color: #1f2b24;
  background: #f5f7f2;
}
.shell {
  grid-template-columns: 286px minmax(0, 1fr);
  background: #f5f7f2;
}
.sidebar {
  background: #fff;
  color: #1d3324;
  border-right: 1px solid #e2e8dc;
  padding: 18px 14px;
}
.brand {
  font-family: 'Space Grotesk', sans-serif;
  font-size: 24px;
  line-height: 1.12;
  letter-spacing: 0;
  color: #164b20;
  display: flex;
  align-items: center;
  gap: 14px;
  margin: 0 0 26px;
  min-height: 88px;
  padding: 8px 4px;
}
.brand-mark {
  width: 74px;
  height: 74px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  border: 2px solid #74b843;
  background: #f8fcf5;
  color: #125719;
  font-size: 18px;
  font-weight: 800;
  letter-spacing: .02em;
  flex: 0 0 74px;
}
.brand-text {
  display: grid;
  gap: 3px;
  min-width: 0;
}
.brand-text strong {
  display: block;
  font-size: 24px;
  line-height: 1.08;
  font-weight: 800;
  color: #164b20;
}
.sidebar nav {
  gap: 8px;
}
.sidebar a,
.nav-toggle {
  color: #26362e;
  border-radius: 8px;
  padding: 10px 12px;
}
.sidebar a:hover,
.nav-toggle:hover,
.nav-toggle:focus-visible {
  background: #eef5e9;
}
.sidebar a.active,
.nav-toggle.active {
  background: #14561d !important;
  color: #fff;
  box-shadow: none !important;
}
.submenu {
  border-left-color: #dbe5d5;
}
.submenu a {
  color: #26362e;
}
.content {
  padding: 0;
  min-width: 0;
}
.topbar {
  height: 82px;
  margin: 0;
  padding: 0 28px;
  border-bottom: 1px solid #e2e8dc;
  background: #fff;
}
.topbar h1 {
  font-size: 26px;
}
.meta span {
  font-weight: 700;
}
.meta small {
  color: #4b584f;
}
.alert {
  margin: 16px 24px 0;
}
.content > .panel,
.content > .card,
.prod-page,
.content > form,
.content > table {
  margin-left: 24px;
  margin-right: 24px;
}
.content > .panel:first-of-type,
.content > .card:first-of-type,
.prod-page:first-child {
  margin-top: 18px;
}
@media (max-width: 960px) {
  .shell {
    grid-template-columns: 1fr;
  }
  .sidebar {
    position: sticky;
    top: 0;
    z-index: 20;
  }
  .sidebar nav {
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  }
  .topbar {
    height: auto;
    padding: 16px;
  }
  .content > .panel,
  .content > .card,
  .prod-page,
  .content > form,
  .content > table {
    margin-left: 14px;
    margin-right: 14px;
  }
}

/* Responsive GUI layer */
:root {
  --sidebar-width: 286px;
  --page-pad: clamp(12px, 2.4vw, 28px);
  --control-height: 40px;
  --radius: 8px;
}

html {
  min-width: 320px;
}

body {
  overflow-x: hidden;
}

.shell {
  grid-template-columns: var(--sidebar-width) minmax(0, 1fr);
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
  overscroll-behavior: contain;
}

.sidebar nav {
  align-content: start;
}

.nav-menu-button {
  display: none;
  width: 100%;
  min-height: var(--control-height);
  align-items: center;
  gap: 8px;
  justify-content: flex-start;
  background: #eef5e9;
  color: #26362e;
  border: 1px solid #dbe5d5;
  border-radius: var(--radius);
  box-shadow: none;
}

.nav-menu-button span {
  display: block;
  width: 16px;
  height: 2px;
  background: currentColor;
  border-radius: 999px;
}

.nav-menu-button strong {
  margin-left: 2px;
  font-size: 13px;
}

.content {
  min-width: 0;
  width: 100%;
}

.topbar {
  gap: 16px;
}

.topbar h1 {
  min-width: 0;
  overflow-wrap: anywhere;
}

.meta {
  flex: 0 0 auto;
}

.content > .panel,
.content > .card,
.content > section,
.content > form,
.content > table,
.content > .prod-page {
  margin-left: var(--page-pad);
  margin-right: var(--page-pad);
}

.panel,
.card,
[class$="-section"],
[class*="-section "] {
  border-radius: var(--radius) !important;
  max-width: 100%;
}

.panel,
.card {
  padding: clamp(12px, 1.6vw, 16px);
}

table {
  max-width: 100%;
}

th,
td {
  overflow-wrap: anywhere;
}

input,
select,
textarea,
button {
  width: 100%;
  min-width: 0;
  min-height: var(--control-height);
  max-width: 100%;
  font-size: 14px;
}

textarea {
  resize: vertical;
}

button,
.prm-link-btn,
.rir-link-btn,
.recipe-button,
.stock-card-link {
  min-height: var(--control-height);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  white-space: normal;
  text-align: center;
}

button {
  width: auto;
}

.form-grid,
.form-grid.three,
.form-grid.four,
[class$="-header-grid"],
[class*="-header-grid "],
.sign-grid,
.catalog-split,
.grid.cards {
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 220px), 1fr)) !important;
}

.form-grid button,
.form-grid .button,
.form-grid a[class*="btn"],
.form-grid a[class*="link"] {
  width: 100%;
}

[class$="-field"],
[class*="-field "] {
  min-width: 0;
}

[class$="-actions"],
[class*="-actions "],
.prm-actions,
.rir-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

[class$="-actions"] > *,
[class*="-actions "] > *,
.prm-actions > *,
.rir-actions > * {
  flex: 0 1 auto;
}

.status-pill {
  border-radius: 999px;
  line-height: 1.2;
  white-space: nowrap;
}

@media (max-width: 1180px) {
  .shell {
    grid-template-columns: 232px minmax(0, 1fr);
  }

  .brand-text strong {
    font-size: 20px;
  }

  .sidebar a,
  .nav-toggle {
    padding: 9px 10px;
    font-size: 14px;
  }
}

@media (max-width: 980px) {
  .shell {
    display: block;
  }

  .sidebar {
    position: sticky;
    height: auto;
    max-height: 100vh;
    padding: 12px var(--page-pad);
    border-right: 0;
    border-bottom: 1px solid #e2e8dc;
  }

  .brand {
    min-height: 0;
    margin: 0 0 10px;
    padding: 0;
  }

  .brand-text {
    grid-template-columns: auto auto;
    gap: 6px;
  }

  .brand-text strong {
    font-size: 18px;
  }

  .nav-menu-button {
    display: flex;
  }

  .sidebar nav {
    display: none;
    grid-template-columns: repeat(auto-fit, minmax(min(100%, 190px), 1fr));
    gap: 6px;
    margin-top: 10px;
    max-height: calc(100vh - 96px);
    overflow-y: auto;
  }

  .sidebar.nav-open nav {
    display: grid;
  }

  .submenu {
    margin-left: 0;
    padding-left: 0;
    border-left: 0;
  }

  .topbar {
    align-items: flex-start;
    flex-direction: column;
    padding: 14px var(--page-pad);
  }

  .topbar h1 {
    font-size: 22px;
  }

  .meta {
    text-align: left;
  }
}

@media (max-width: 760px) {
  .content > .panel,
  .content > .card,
  .content > section,
  .content > form,
  .content > table,
  .content > .prod-page {
    margin-left: var(--page-pad);
    margin-right: var(--page-pad);
  }

  .alert {
    margin-left: var(--page-pad);
    margin-right: var(--page-pad);
  }

  table,
  .prod-page table,
  .prm-simple-table,
  .rir-simple-table,
  .lcf-simple-table,
  .fgr-simple-table,
  .physical-table,
  .warehouse-table {
    display: block;
    width: 100%;
    overflow-x: auto;
    table-layout: auto !important;
    white-space: nowrap;
    -webkit-overflow-scrolling: touch;
  }

  th,
  td,
  .prod-page table th,
  .prod-page table td {
    padding: 8px;
    font-size: 13px;
  }

  .form-grid,
  .form-grid.three,
  .form-grid.four,
  [class$="-header-grid"],
  [class*="-header-grid "],
  .sign-grid,
  .catalog-split,
  .grid.cards {
    grid-template-columns: 1fr !important;
  }

  [class$="-field"],
  [class*="-field "] {
    align-items: stretch !important;
    flex-direction: column;
    gap: 4px;
  }

  [class$="-field"] label,
  [class*="-field "] label {
    min-width: 0 !important;
  }

  [class$="-actions"] > *,
  [class*="-actions "] > *,
  .prm-actions > *,
  .rir-actions > *,
  button,
  .prm-link-btn,
  .rir-link-btn,
  .recipe-button,
  .stock-card-link {
    flex: 1 1 180px;
  }
}

@media (max-width: 480px) {
  :root {
    --page-pad: 10px;
    --control-height: 38px;
  }

  .topbar h1 {
    font-size: 20px;
  }

  .brand-text {
    grid-template-columns: 1fr;
  }

  .panel,
  .card {
    padding-left: 10px !important;
    padding-right: 10px !important;
  }

  input,
  select,
  textarea,
  button {
    font-size: 13px;
    padding: 8px;
  }
}

/* Desktop sidebar matching compact admin-menu layout */
:root {
  --sidebar-width: 238px;
  --sidebar-collapsed-width: 64px;
  --sidebar-bg: #0d0d1b;
  --sidebar-bg-2: #141329;
  --sidebar-ink: #f4f2ff;
  --sidebar-muted: #a7a3bd;
  --sidebar-active: #ffffff;
}

.sidebar a,
.nav-toggle {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 38px;
}

.nav-icon {
  width: 24px;
  height: 24px;
  border-radius: 7px;
  display: inline-grid;
  place-items: center;
  flex: 0 0 24px;
  font-family: 'IBM Plex Mono', monospace;
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0;
  background: rgba(255,255,255,0.08);
  color: currentColor;
}

.nav-label {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sidebar-search {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0 0 12px;
  padding: 0 8px;
  min-height: 40px;
  border-radius: 8px;
  background: rgba(255,255,255,0.06);
  color: var(--sidebar-muted);
}

.sidebar-search input {
  min-height: 34px;
  padding: 0;
  border: 0;
  border-radius: 0;
  background: transparent;
  color: var(--sidebar-ink);
  outline: none;
}

.sidebar-search input::placeholder {
  color: var(--sidebar-muted);
}

.sidebar-collapse-button {
  width: 32px;
  min-width: 32px;
  min-height: 32px;
  padding: 0;
  border: 0;
  border-radius: 8px;
  background: rgba(255,255,255,0.08);
  color: var(--sidebar-ink);
  display: inline-grid;
  place-items: center;
  gap: 0;
  box-shadow: none;
}

.sidebar-collapse-button span {
  width: 14px;
  height: 2px;
  background: currentColor;
  border-radius: 999px;
}

@media (min-width: 981px) {
  body {
    background: #eef2fb;
  }

  .shell {
    grid-template-columns: var(--sidebar-width) minmax(0, 1fr);
    transition: grid-template-columns .18s ease;
  }

  .shell.sidebar-collapsed {
    grid-template-columns: var(--sidebar-collapsed-width) minmax(0, 1fr);
  }

  .sidebar {
    background: var(--sidebar-bg);
    color: var(--sidebar-ink);
    border-right: 0;
    padding: 12px;
    transition: width .18s ease, padding .18s ease;
  }

  .brand {
    min-height: 32px;
    margin: 0 0 14px;
    padding: 0 2px;
    color: var(--sidebar-ink);
    justify-content: space-between;
  }

  .brand-text strong {
    color: var(--sidebar-ink);
    font-size: 15px;
    line-height: 1.1;
    font-weight: 700;
  }

  .sidebar nav {
    gap: 6px;
  }

  .sidebar a,
  .nav-toggle {
    color: var(--sidebar-ink);
    border-radius: 8px;
    padding: 7px 8px;
  }

  .sidebar a:hover,
  .nav-toggle:hover,
  .nav-toggle:focus-visible {
    background: rgba(255,255,255,0.08);
  }

  .sidebar a.active,
  .nav-toggle.active {
    background: var(--sidebar-active) !important;
    color: #171625;
  }

  .submenu {
    margin-left: 12px;
    border-left: 1px solid rgba(255,255,255,0.11);
    padding-left: 8px;
  }

  .submenu a {
    color: var(--sidebar-muted);
    font-size: 12px;
  }

  .submenu a.active {
    color: #171625;
  }

  .topbar {
    background: #eef2fb;
    border-bottom: 0;
  }

  .content {
    background: #eef2fb;
  }

  .shell.sidebar-collapsed .sidebar {
    padding-left: 8px;
    padding-right: 8px;
  }

  .shell.sidebar-collapsed .brand {
    justify-content: center;
  }

  .shell.sidebar-collapsed .brand-text,
  .shell.sidebar-collapsed .nav-label,
  .shell.sidebar-collapsed .sidebar-search input {
    display: none;
  }

  .shell.sidebar-collapsed .sidebar-search {
    justify-content: center;
    padding: 0;
  }

  .shell.sidebar-collapsed .sidebar a,
  .shell.sidebar-collapsed .nav-toggle {
    justify-content: center;
    padding-left: 0;
    padding-right: 0;
  }

  .shell.sidebar-collapsed .submenu {
    display: none;
  }

  .shell.sidebar-collapsed .sidebar-collapse-button {
    transform: rotate(180deg);
  }
}

@media (max-width: 980px) {
  .sidebar-collapse-button,
  .sidebar-search {
    display: none;
  }

  .sidebar a,
  .nav-toggle {
    justify-content: flex-start;
  }
}
