:root {
  --bg: #f4f6f8;
  --panel: #ffffff;
  --text: #122033;
  --muted: #64748b;
  --line: #d9e1ea;
  --accent: #111827;
  --accent-soft: #e8edf3;
  --positive: #18803d;
  --positive-soft: #e8f5ec;
  --negative: #b42318;
  --negative-soft: #fdeceb;
  --warning: #b45309;
  --warning-soft: #fff4e5;
  --shadow: 0 10px 30px rgba(15, 23, 42, 0.08);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
}

.app-shell {
  min-height: 100vh;
}

a {
  color: inherit;
  text-decoration: none;
}

button,
input,
select {
  font: inherit;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 18px 20px 10px;
  gap: 16px;
}

.brand {
  font-size: 22px;
  font-weight: 800;
  letter-spacing: 0;
}

.status {
  margin-top: 2px;
  color: var(--positive);
  font-size: 12px;
  font-weight: 700;
}

.nav {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 8px;
  padding: 10px 20px calc(12px + env(safe-area-inset-bottom));
}

.bottom-nav {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 50;
  background: var(--bg);
  border-top: 1px solid var(--line);
  box-shadow: 0 -10px 30px rgba(15, 23, 42, 0.08);
}

.nav-link {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 72px;
  padding: 10px 8px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  font-size: 12px;
  font-weight: 700;
  box-shadow: var(--shadow);
}

.nav-link svg {
  width: 18px;
  height: 18px;
}

.icon-success {
  color: var(--positive);
}

.icon-danger,
.danger {
  color: var(--negative);
}

.page {
  padding: 0 20px calc(132px + env(safe-area-inset-bottom));
}

.section-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
  margin: 18px 0 16px;
}

.section-head h1,
.modal-head h2,
.login-title {
  margin: 0;
  font-size: 22px;
  line-height: 1.2;
}

.section-head p,
.login-subtitle,
.timeline-main p,
.product-meta .code {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.btn,
.icon-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: 0;
  border-radius: 10px;
  cursor: pointer;
  transition: transform 0.12s ease, opacity 0.12s ease;
}

.btn:hover,
.icon-link:hover {
  transform: translateY(-1px);
}

.btn {
  min-height: 44px;
  padding: 0 16px;
  font-weight: 700;
}

.btn svg,
.icon-link svg {
  width: 18px;
  height: 18px;
}

.btn-block {
  width: 100%;
}

.btn-primary {
  background: var(--accent);
  color: #fff;
}

.btn-dark {
  background: var(--accent);
  color: #fff;
}

.btn-positive {
  background: var(--positive);
  color: #fff;
}

.btn-negative {
  background: var(--negative);
  color: #fff;
}

.icon-link {
  width: 42px;
  height: 42px;
  background: var(--panel);
  border: 1px solid var(--line);
}

.alert {
  margin: 0 0 14px;
  padding: 12px 14px;
  border-radius: 10px;
  font-size: 14px;
  font-weight: 600;
}

.alert-error {
  background: var(--negative-soft);
  color: var(--negative);
}

.alert-success {
  background: var(--positive-soft);
  color: var(--positive);
}

.container {
  width: 100%;
}

.page-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 15px;
}

.page-head h3,
.card-form h3 {
  margin: 0;
  font-size: 20px;
  line-height: 1.2;
}

.btn-add-small,
.btn-black,
.btn-cancel {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 0;
  border-radius: 8px;
  cursor: pointer;
  font-weight: 700;
  transition: transform 0.12s ease, opacity 0.12s ease;
}

.btn-add-small:hover,
.btn-black:hover,
.btn-cancel:hover {
  transform: translateY(-1px);
}

.btn-add-small {
  min-height: 36px;
  padding: 0 14px;
  background: var(--accent);
  color: #fff;
}

.card-list {
  display: grid;
  gap: 10px;
}

.card {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.card-body {
  min-width: 0;
  flex: 1;
}

.card-actions {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: 6px;
}

.inline-form {
  margin: 0;
}

.card-icon-button {
  width: 38px;
  height: 38px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--accent-soft);
  color: var(--text);
  cursor: pointer;
  transition: transform 0.12s ease, opacity 0.12s ease;
}

.card-icon-button:hover {
  transform: translateY(-1px);
}

.card-icon-button svg {
  width: 17px;
  height: 17px;
}

.card-icon-button.danger-action {
  background: var(--negative-soft);
  color: var(--negative);
}

.prod-img {
  width: 60px;
  height: 60px;
  border-radius: 8px;
  object-fit: cover;
  display: block;
  background: var(--accent-soft);
}

.product-name {
  font-size: 14px;
  font-weight: 600;
  line-height: 1.35;
}

.stock-val {
  margin-top: 4px;
  font-size: 14px;
  font-weight: 700;
}

.low-stock {
  color: var(--negative);
}

.product-code {
  margin-top: 2px;
  color: var(--muted);
  font-size: 9px;
}

.list-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.modal-full {
  position: fixed;
  inset: 0;
  z-index: 1000;
  padding: 20px;
  background: rgba(15, 23, 42, 0.56);
  overflow-y: auto;
}

.card-form {
  width: min(100%, 420px);
  margin: 48px auto;
  padding: 16px;
  display: grid;
  gap: 12px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.input-group {
  display: grid;
  gap: 6px;
}

.input-group label {
  font-size: 13px;
  font-weight: 700;
}

.input-group input,
.input-group select {
  width: 100%;
  min-height: 44px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--text);
}

.btn-black,
.btn-cancel {
  min-height: 44px;
  padding: 0 16px;
  width: 100%;
}

.btn-black {
  background: var(--accent);
  color: #fff;
}

.btn-cancel {
  background: #fff;
  color: var(--text);
  border: 1px solid var(--line);
}

.product-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 14px;
}

.product-card {
  display: grid;
  grid-template-columns: 64px minmax(0, 1fr);
  gap: 12px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 12px;
  box-shadow: var(--shadow);
}

.product-card.is-low {
  border-color: var(--warning);
  background: linear-gradient(0deg, var(--warning-soft), var(--warning-soft)), var(--panel);
}

.product-image {
  width: 64px;
  height: 64px;
  border-radius: 10px;
  overflow: hidden;
  background: var(--accent-soft);
}

.product-image img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.product-placeholder {
  width: 100%;
  height: 100%;
  display: grid;
  place-items: center;
  color: var(--muted);
}

.product-meta {
  min-width: 0;
}

.product-meta h2 {
  margin: 0;
  font-size: 15px;
  line-height: 1.35;
}

.quantity {
  margin-top: 6px;
  font-size: 18px;
  font-weight: 800;
}

.list-panel,
.form-card,
.timeline {
  display: grid;
  gap: 12px;
}

.list-panel,
.form-card {
  padding: 18px;
  align-content: start;
}

.list-row,
.timeline-row,
.form-card,
.login-card,
.modal-panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  box-shadow: var(--shadow);
}

.list-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 14px;
  font-size: 14px;
}

.timeline-row {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  padding: 14px;
}

.timeline-in {
  border-left: 4px solid var(--positive);
}

.timeline-out {
  border-left: 4px solid var(--negative);
}

.timeline-main {
  min-width: 0;
}

.timeline-main h2 {
  margin: 6px 0 0;
  font-size: 15px;
}

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 0 10px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--text);
  font-size: 12px;
  font-weight: 700;
}

.remarks {
  margin-top: 8px;
}

.timeline-value {
  flex-shrink: 0;
  font-size: 18px;
  font-weight: 800;
}

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

.admin-grid .list-panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  box-shadow: var(--shadow);
}

.admin-grid .list-row {
  min-height: 54px;
  background: #f8fafc;
  box-shadow: none;
}

.permission-panel {
  display: grid;
  gap: 14px;
  padding: 18px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  box-shadow: var(--shadow);
}

.permission-table {
  display: grid;
  gap: 8px;
}

.permission-row {
  display: grid;
  grid-template-columns: minmax(160px, 1fr) repeat(2, minmax(96px, 140px));
  gap: 12px;
  align-items: center;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fafc;
}

.permission-header {
  background: var(--accent-soft);
  color: var(--text);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

.permission-row strong,
.permission-row span {
  display: block;
}

.permission-row strong {
  font-size: 14px;
}

.permission-row span {
  margin-top: 2px;
  color: var(--muted);
  font-size: 12px;
}

.permission-check {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 38px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  cursor: pointer;
}

.permission-check input {
  width: 16px;
  height: 16px;
  accent-color: var(--accent);
}

.permission-check span {
  margin: 0;
  color: var(--text);
  font-size: 12px;
  font-weight: 700;
}

.panel-title {
  margin: 0 0 6px;
  font-size: 16px;
  line-height: 1.3;
}

.role-pill {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 0 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0;
}

.role-admin {
  background: var(--positive-soft);
  color: var(--positive);
}

.role-user {
  background: var(--accent-soft);
  color: var(--text);
}

.admin-user-row {
  align-items: center;
}

.admin-user-main {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  min-width: 150px;
  font-weight: 700;
}

.role-active {
  background: var(--positive-soft);
  color: var(--positive);
}

.role-inactive {
  background: var(--negative-soft);
  color: var(--negative);
}

.role-form {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0;
}

.role-form select {
  min-height: 38px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--text);
}

.role-form .btn {
  min-height: 38px;
  padding: 0 12px;
  font-size: 12px;
}

.field {
  display: grid;
  gap: 8px;
}

.field span {
  font-size: 13px;
  font-weight: 700;
}

.field input,
.field select {
  width: 100%;
  min-height: 44px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
  color: var(--text);
}

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

.login-body {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background: var(--bg);
}

.login-card {
  display: grid;
  gap: 14px;
  width: min(100%, 360px);
  padding: 28px;
  align-content: start;
}

.login-card .alert {
  margin: 0;
}

.login-card .btn-block {
  margin-top: 8px;
  min-height: 48px;
}

.login-subtitle {
  margin: -8px 0 4px;
}

.modal {
  border: 0;
  padding: 0;
  background: transparent;
  width: min(100%, 520px);
}

.modal::backdrop {
  background: rgba(15, 23, 42, 0.45);
}

.modal-panel {
  width: 100%;
  padding: 18px;
}

.modal-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 14px;
}

@media (max-width: 720px) {
  .topbar,
  .page,
  .nav {
    padding-left: 14px;
    padding-right: 14px;
  }

  .nav {
    grid-template-columns: repeat(5, minmax(0, 1fr));
    gap: 6px;
  }

  .nav-link {
    min-height: 64px;
    padding: 8px 4px;
    font-size: 11px;
  }

  .section-head,
  .timeline-row,
  .list-row {
    flex-direction: column;
    align-items: stretch;
  }

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

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

  .role-form {
    width: 100%;
  }

  .role-form select {
    flex: 1;
  }

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