:root {
  --bg-main: #f2ede3;
  --bg-secondary: #efe6d5;
  --ink: #142231;
  --muted: #556678;
  --card: #fffaf1;
  --line: #d8cdb9;
  --primary: #146c74;
  --primary-dark: #0c4d53;
  --accent: #d9822b;
  --critical: #be2f2f;
  --warning: #c77812;
  --ok: #1f8155;
  --radius-lg: 22px;
  --radius-md: 14px;
  --shadow-soft: 0 18px 40px rgba(16, 35, 50, 0.08);
  --shadow-hard: 0 6px 18px rgba(15, 35, 48, 0.18);
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
}

body {
  font-family: "Manrope", sans-serif;
  color: var(--ink);
  background: linear-gradient(140deg, var(--bg-main) 0%, #f7f4ec 55%, #e5efe8 100%);
}

.bg-grid {
  position: fixed;
  inset: 0;
  background-image:
    radial-gradient(circle at 1px 1px, rgba(20, 34, 49, 0.04) 1px, transparent 0),
    linear-gradient(130deg, rgba(20, 108, 116, 0.04), rgba(217, 130, 43, 0.04));
  background-size:
    24px 24px,
    100% 100%;
  pointer-events: none;
  z-index: -1;
}

.app-shell {
  display: grid;
  grid-template-columns: 280px 1fr;
  min-height: 100vh;
  max-width: 1600px;
  margin: 0 auto;
  padding: 24px;
  gap: 18px;
}

.sidebar {
  background: linear-gradient(180deg, #193349 0%, #0f283d 100%);
  color: #e8f0f8;
  border-radius: var(--radius-lg);
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 22px;
  box-shadow: var(--shadow-hard);
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-badge {
  width: 44px;
  height: 44px;
  border-radius: 12px;
  background: linear-gradient(140deg, #2aa3ac, #f0a558);
  display: grid;
  place-items: center;
  font-weight: 800;
  color: #0f2232;
  font-family: "Sora", sans-serif;
}

.brand strong {
  display: block;
  font-family: "Sora", sans-serif;
  font-size: 1.02rem;
}

.brand span {
  opacity: 0.78;
  font-size: 0.82rem;
}

.menu {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.menu-item {
  border: 0;
  border-radius: 10px;
  padding: 12px 14px;
  background: transparent;
  color: #d9e4ef;
  font-size: 0.94rem;
  text-align: left;
  cursor: pointer;
  transition: background 0.2s ease, transform 0.2s ease;
}

.menu-item:hover,
.menu-item:focus-visible {
  outline: none;
  background: rgba(255, 255, 255, 0.1);
  transform: translateX(2px);
}

.menu-item.is-active {
  background: linear-gradient(130deg, rgba(42, 163, 172, 0.55), rgba(240, 165, 88, 0.6));
  color: #07202d;
  font-weight: 700;
}

.sidebar-footer {
  margin-top: auto;
  border-top: 1px solid rgba(255, 255, 255, 0.17);
  padding-top: 14px;
}

.sidebar-footer p {
  margin: 0;
  font-size: 0.88rem;
}

.sidebar-footer small {
  color: #adc1d7;
}

.main-content {
  display: grid;
  align-content: start;
  gap: 14px;
}

.main-header {
  background: rgba(255, 250, 241, 0.86);
  border: 1px solid rgba(216, 205, 185, 0.7);
  border-radius: var(--radius-lg);
  padding: 18px 22px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  box-shadow: var(--shadow-soft);
}

.header-main {
  display: flex;
  align-items: flex-start;
  gap: 12px;
}

.mobile-only {
  display: none;
}

.nav-toggle-btn,
.nav-close-btn {
  white-space: nowrap;
}

.main-header h1 {
  margin: 0;
  font-family: "Sora", sans-serif;
  font-size: 1.35rem;
  letter-spacing: -0.01em;
}

.main-header p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 0.93rem;
}

.header-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.view {
  display: none;
  gap: 14px;
}

.view.is-active {
  display: grid;
}

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

.kpi-grid.mini {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.kpi-card {
  background: var(--card);
  border-radius: var(--radius-md);
  padding: 16px;
  border: 1px solid var(--line);
  box-shadow: var(--shadow-soft);
  overflow: hidden;
  position: relative;
}

.kpi-card::after {
  content: "";
  position: absolute;
  right: -18px;
  top: -26px;
  width: 74px;
  height: 74px;
  border-radius: 18px;
  background: linear-gradient(140deg, rgba(20, 108, 116, 0.14), rgba(217, 130, 43, 0.16));
}

.kpi-title {
  color: var(--muted);
  font-size: 0.82rem;
  letter-spacing: 0.03em;
  text-transform: uppercase;
}

.kpi-value {
  margin-top: 8px;
  font-family: "Sora", sans-serif;
  font-size: 1.64rem;
  font-weight: 700;
}

.kpi-meta {
  margin-top: 6px;
  color: var(--muted);
  font-size: 0.84rem;
}

.dashboard-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr);
  gap: 12px;
}

.dual-grid {
  display: grid;
  grid-template-columns: minmax(340px, 0.95fr) minmax(0, 1.25fr);
  gap: 12px;
}

.card {
  background: var(--card);
  border-radius: var(--radius-md);
  padding: 16px;
  border: 1px solid var(--line);
  box-shadow: var(--shadow-soft);
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
}

.card-header h2 {
  margin: 0;
  font-family: "Sora", sans-serif;
  font-size: 1rem;
  font-weight: 650;
}

.toolbar {
  display: flex;
  justify-content: space-between;
  align-items: end;
  gap: 12px;
  margin-bottom: 12px;
  flex-wrap: wrap;
}

.toolbar.compact {
  margin-bottom: 10px;
}

.toolbar-group {
  display: flex;
  align-items: end;
  flex-wrap: wrap;
  gap: 10px;
}

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

label span {
  font-weight: 650;
  font-size: 0.8rem;
  color: #485767;
}

input,
select,
textarea {
  width: 100%;
  border-radius: 10px;
  border: 1px solid #cdbfa7;
  background: #fffdf8;
  color: var(--ink);
  padding: 10px 12px;
  font: inherit;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

input:focus,
select:focus,
textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(20, 108, 116, 0.16);
}

textarea {
  resize: vertical;
}

.btn {
  border: 0;
  border-radius: 11px;
  cursor: pointer;
  font-weight: 700;
  padding: 10px 14px;
  transition: transform 0.2s ease, filter 0.2s ease, box-shadow 0.2s ease;
  font-family: "Sora", sans-serif;
}

.btn:hover {
  transform: translateY(-1px);
  filter: brightness(1.03);
}

.btn.small {
  padding: 8px 11px;
  font-size: 0.82rem;
}

.btn-primary {
  background: linear-gradient(130deg, #1d7a82, #0f6167);
  color: #f4fbff;
  box-shadow: 0 8px 16px rgba(15, 97, 103, 0.25);
}

.btn-muted {
  background: #ede2cf;
  color: #344354;
}

.inline-input {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  align-items: center;
}

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

.full-width {
  grid-column: 1 / -1;
}

.hidden {
  display: none;
}

.table-wrapper {
  border: 1px solid #d7caaf;
  border-radius: 12px;
  overflow: auto;
  background: #fffdf8;
}

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

th,
td {
  padding: 10px 12px;
  border-bottom: 1px solid #ebdfca;
  text-align: left;
  font-size: 0.9rem;
}

th {
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: #516070;
  background: #f3ead8;
  position: sticky;
  top: 0;
}

tbody tr:hover {
  background: #faf3e5;
}

.placeholder-cell {
  text-align: center;
  color: #7e8c9b;
  padding: 18px;
}

.pill {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 4px 10px;
  font-size: 0.78rem;
  font-weight: 700;
}

.pill.low {
  background: #fde8d3;
  color: #9a5409;
}

.pill.out {
  background: #f7d9d9;
  color: #8f2626;
}

.pill.attention {
  background: #f9efcf;
  color: #88610b;
}

.pill.healthy {
  background: #d8f3e4;
  color: #126341;
}

.pill.in {
  background: #d9f2e5;
  color: #1b6947;
}

.pill.out-movement {
  background: #fae2d9;
  color: #94412b;
}

.pill.priority-critical {
  background: #f7d8d8;
  color: #941f1f;
}

.pill.priority-high {
  background: #fde7cc;
  color: #9d550a;
}

.pill.priority-medium {
  background: #f7f0d5;
  color: #8a680c;
}

.pill.priority-planned {
  background: #d9edf6;
  color: #205f80;
}

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

.product-title strong {
  font-size: 0.92rem;
}

.product-title small {
  font-size: 0.78rem;
  color: #718191;
}

.table-actions {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.table-actions button {
  border: 1px solid #c9bda4;
  background: #fef7eb;
  border-radius: 8px;
  padding: 6px 10px;
  cursor: pointer;
  font-size: 0.8rem;
}

.table-actions button:hover {
  background: #f0e1c8;
}

.ranking-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 8px;
}

.ranking-list li {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  border: 1px dashed #d2c4ab;
  border-radius: 10px;
  background: #fffdf8;
}

dialog {
  border: 1px solid #cfbea0;
  border-radius: 16px;
  padding: 0;
  width: min(900px, 96vw);
  box-shadow: 0 20px 60px rgba(20, 34, 49, 0.3);
  background: #fffaf1;
}

dialog::backdrop {
  background: rgba(6, 17, 26, 0.44);
}

#product-form {
  display: grid;
  gap: 12px;
  padding: 16px;
}

#product-form header,
#product-form footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
}

#product-form h3 {
  margin: 0;
  font-family: "Sora", sans-serif;
}

.icon-btn {
  border: 1px solid #cfbea0;
  background: #f4e7d0;
  border-radius: 10px;
  cursor: pointer;
  padding: 8px 10px;
  font-size: 0.8rem;
}

#system-dialog,
#scanner-modal {
  width: min(560px, 96vw);
  padding: 16px;
}

.dialog-message {
  margin: 0 0 12px;
  color: var(--text-soft);
  line-height: 1.5;
}

#system-dialog-form {
  display: grid;
  gap: 12px;
}

#system-dialog-fields:empty {
  display: none;
}

button:disabled,
.btn:disabled {
  opacity: 0.55;
  cursor: wait;
}

.scanner-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
}

.scanner-tip {
  margin: 0 0 10px;
  color: var(--muted);
  font-size: 0.92rem;
}

#scanner-reader {
  min-height: 300px;
  border: 1px dashed #c7b796;
  border-radius: 12px;
  overflow: hidden;
  background: #f4ead8;
}

#toast-container {
  position: fixed;
  bottom: 20px;
  right: 20px;
  display: grid;
  gap: 8px;
  z-index: 20;
}

.toast {
  border-radius: 12px;
  padding: 12px 14px;
  color: #f8fbff;
  box-shadow: var(--shadow-hard);
  animation: slide-up 0.18s ease;
  min-width: 240px;
}

.toast.success {
  background: linear-gradient(130deg, #248458, #14673f);
}

.toast.error {
  background: linear-gradient(130deg, #c23a3a, #982626);
}

.toast.info {
  background: linear-gradient(130deg, #2e6f93, #1c4b66);
}

.skeleton {
  min-height: 112px;
  background:
    linear-gradient(100deg, rgba(255, 255, 255, 0) 40%, rgba(255, 255, 255, 0.58) 50%, rgba(255, 255, 255, 0) 60%)
      #f0e4d1;
  background-size: 200% 100%;
  animation: loading 1.3s infinite;
}

@keyframes loading {
  0% {
    background-position: 200% 0;
  }
  100% {
    background-position: -200% 0;
  }
}

@keyframes slide-up {
  from {
    opacity: 0;
    transform: translateY(12px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@media (max-width: 1220px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    display: grid;
    grid-template-columns: 1fr;
    gap: 12px;
  }

  .menu {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }

  .scrollable-menu {
    max-height: none;
    overflow: visible;
    padding-right: 0;
  }

  .menu-item {
    text-align: center;
  }

  .sidebar-footer {
    margin-top: 0;
  }

  .dashboard-grid,
  .dual-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 860px) {
  body.mobile-nav-open {
    overflow: hidden;
  }

  .app-shell {
    padding: 10px;
    gap: 12px;
  }

  .mobile-only {
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }

  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: min(82vw, 320px);
    max-width: 320px;
    z-index: 50;
    border-radius: 0 22px 22px 0;
    transform: translateX(-108%);
    transition: transform 0.25s ease;
    overflow-y: auto;
  }

  .sidebar.is-open {
    transform: translateX(0);
  }

  .sidebar-backdrop {
    position: fixed;
    inset: 0;
    border: 0;
    padding: 0;
    background: rgba(7, 20, 31, 0.38);
    z-index: 45;
  }

  .brand {
    justify-content: space-between;
    align-items: center;
  }

  .brand > div:last-of-type {
    min-width: 0;
  }

  .scrollable-menu,
  .menu {
    display: flex;
    flex-direction: column;
    gap: 8px;
    overflow: visible;
    max-height: none;
  }

  .menu-item {
    text-align: left;
    font-size: 0.92rem;
  }

  .main-header {
    flex-direction: column;
    align-items: stretch;
    padding: 14px;
  }

  .header-main {
    width: 100%;
    align-items: center;
  }

  .header-main > div:last-child {
    min-width: 0;
  }

  .main-header h1 {
    font-size: 1.12rem;
  }

  .main-header p {
    font-size: 0.86rem;
  }

  .header-actions {
    width: 100%;
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .header-actions .btn,
  .header-actions .user-chip {
    width: 100%;
    text-align: center;
  }

  .kpi-grid,
  .kpi-grid.mini,
  .dashboard-grid,
  .dual-grid,
  .card-grid.two-col {
    grid-template-columns: 1fr;
  }

  .toolbar,
  .toolbar-group {
    width: 100%;
  }

  .toolbar-group {
    display: grid;
    grid-template-columns: 1fr;
  }

  .toolbar-group label,
  .toolbar > label,
  .toolbar > button,
  .toolbar .btn {
    width: 100%;
  }

  .form-grid {
    grid-template-columns: 1fr;
  }

  .inline-input {
    grid-template-columns: 1fr;
  }

  .inline-actions,
  .card-header,
  .ranking-list li,
  #product-form header,
  #product-form footer,
  .scanner-header {
    flex-direction: column;
    align-items: stretch;
  }

  .inline-actions > *,
  .card-header > *,
  .scanner-header > *,
  #product-form header > *,
  #product-form footer > * {
    width: 100%;
  }

  .table-wrapper {
    margin: 0 -6px;
  }

  table {
    min-width: 520px;
  }

  #toast-container {
    left: 12px;
    right: 12px;
    bottom: 12px;
  }

  .toast {
    min-width: 0;
  }
}

@media (max-width: 520px) {
  .app-shell {
    padding: 8px;
    gap: 10px;
  }

  .sidebar {
    width: min(88vw, 300px);
    padding: 14px;
    gap: 14px;
  }

  .main-header {
    padding: 12px;
  }

  .header-main {
    align-items: flex-start;
  }

  .nav-toggle-btn,
  .nav-close-btn {
    font-size: 0.78rem;
  }

  .header-actions {
    grid-template-columns: 1fr;
  }

  .kpi-card,
  .card,
  .login-card,
  dialog,
  #system-dialog,
  #scanner-modal {
    border-radius: 14px;
  }

  .menu-item {
    padding: 10px 10px;
    font-size: 0.84rem;
  }

  table {
    min-width: 460px;
  }

  th,
  td {
    padding: 8px 9px;
    font-size: 0.82rem;
  }
}

@media (max-width: 380px) {
  .sidebar {
    width: 92vw;
  }

  .header-main {
    gap: 8px;
  }

  .main-header h1 {
    font-size: 1rem;
  }

  .login-card {
    padding: 16px;
  }
}


.hidden {
  display: none !important;
}

.login-layer {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  background: linear-gradient(160deg, rgba(8, 24, 38, 0.85), rgba(17, 47, 56, 0.85));
  z-index: 40;
  padding: 18px;
}

.login-card {
  width: min(430px, 96vw);
  background: #fffaf1;
  border: 1px solid #d3c3a6;
  border-radius: 18px;
  padding: 20px;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.25);
  display: grid;
  gap: 12px;
}

.login-card h1 {
  margin: 0;
  font-family: "Sora", sans-serif;
  font-size: 1.2rem;
}

.login-card p {
  margin: 0;
  color: var(--muted);
  font-size: 0.92rem;
}

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

.scrollable-menu {
  max-height: min(52vh, 560px);
  overflow-y: auto;
  overflow-x: hidden;
  padding-right: 4px;
}

.user-chip {
  border: 1px solid #d8cdb9;
  border-radius: 999px;
  padding: 8px 12px;
  background: #f6eddc;
  font-size: 0.82rem;
  font-weight: 700;
}

.card-grid {
  display: grid;
  gap: 12px;
}

.card-grid.two-col {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.inline-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.helper-text {
  margin: 0;
  font-size: 0.84rem;
  color: var(--muted);
}

.compact-table table {
  min-width: 420px;
}

.simple-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 8px;
}

.simple-list li {
  border: 1px solid #d8cdb9;
  border-radius: 10px;
  padding: 8px 10px;
  background: #fffdf8;
  display: grid;
  gap: 3px;
}

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

.kpi-card.clickable {
  cursor: pointer;
  transition: transform 0.2s ease, border-color 0.2s ease, box-shadow 0.2s ease;
}

.kpi-card.clickable:hover {
  transform: translateY(-2px);
  border-color: #b9aa8f;
  box-shadow: 0 14px 34px rgba(20, 34, 49, 0.13);
}

.kpi-card.warn-card {
  border-color: rgba(190, 47, 47, 0.3);
}

.po-detail-head {
  margin-bottom: 10px;
  display: grid;
  gap: 4px;
}

.po-detail-head p {
  margin: 0;
  font-size: 0.9rem;
}

.receive-row {
  border: 1px solid #d5c8ad;
  border-radius: 11px;
  padding: 10px;
  display: grid;
  gap: 6px;
  margin-bottom: 8px;
}

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

.text-danger {
  color: #a12e2e;
}

.text-success {
  color: #177b4e;
}

@media (max-width: 1220px) {
  .card-grid.two-col {
    grid-template-columns: 1fr;
  }

  .scrollable-menu {
    max-height: none;
    overflow: visible;
    padding-right: 0;
  }
}

@media (max-width: 860px) {
  .scrollable-menu {
    max-height: none;
    overflow: visible;
    padding-right: 0;
  }

  .user-chip {
    width: 100%;
    text-align: center;
  }
}
