:root {
  color-scheme: dark;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --bg: #0d0f12;
  --panel: #15181d;
  --panel-soft: #1b2027;
  --ink: #f4f7fb;
  --muted: #a2abb8;
  --line: #29313a;
  --primary: #2f9e8f;
  --primary-dark: #258476;
  --danger: #ef6f6c;
  --warn: #e6b450;
  --warn-bg: #2a251a;
  --warn-line: #5b4a24;
  --ok-bg: #142922;
  --input-bg: #101317;
  --input-line: #333b46;
  --button-soft: #20252c;
  --button-soft-ink: #edf3f7;
  --shadow: 0 18px 45px rgba(0, 0, 0, 0.2);
}

html[data-theme="light"] {
  color-scheme: light;
  --bg: #f7f8fa;
  --panel: #ffffff;
  --panel-soft: #ffffff;
  --ink: #192027;
  --muted: #66727f;
  --line: #e1e6eb;
  --primary: #227c70;
  --primary-dark: #1b665d;
  --danger: #b42318;
  --warn: #9a6700;
  --warn-bg: #fff8e6;
  --warn-line: #f2d184;
  --ok-bg: #eaf7f3;
  --input-bg: #ffffff;
  --input-line: #ccd5de;
  --button-soft: #eef2f5;
  --button-soft-ink: #26323d;
  --shadow: 0 18px 45px rgba(25, 32, 39, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  overflow-x: hidden;
  transition: background 160ms ease, color 160ms ease;
}

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

.is-hidden {
  display: none !important;
}

.login-screen {
  display: grid;
  min-height: 100vh;
  place-items: center;
  padding: 24px;
}

.login-panel {
  width: min(420px, 100%);
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
  padding: 28px;
}

.brand-logo {
  display: block;
  width: 176px;
  max-width: 100%;
  height: auto;
}

.login-logo {
  margin-bottom: 18px;
}

.user-line {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 700;
}

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 28px clamp(16px, 4vw, 44px);
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}

.app-header > div:first-child {
  min-width: 0;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--primary);
  font-size: 0.78rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.header-logo {
  width: 130px;
  margin-bottom: 6px;
  cursor: pointer;
}

#sidebar-logo {
  cursor: pointer;
}
h1,
h2,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-size: clamp(1.75rem, 4vw, 2.7rem);
}

h2 {
  margin-bottom: 6px;
  font-size: 1.15rem;
}

.app-shell {
  display: grid;
  grid-template-columns: 260px minmax(0, 1fr);
  gap: 24px;
  align-items: start;
  padding: 24px clamp(16px, 4vw, 44px) 44px;
  max-width: 100%;
}

.panel,
.stat-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.panel {
  padding: 22px;
}

.app-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  border-top: 1px solid var(--line);
  padding: 14px clamp(16px, 4vw, 44px) 18px;
  color: var(--muted);
  font-size: 0.8rem;
}

.footer-col {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.footer-col-center {
  text-align: center;
}

.footer-col-end {
  text-align: right;
}

.footer-brand {
  font-size: 0.85rem;
  color: var(--ink);
}

.footer-tagline {
  font-size: 0.75rem;
}

.footer-version {
  font-size: 0.72rem;
  opacity: 0.65;
}

.footer-link {
  color: inherit;
  text-decoration: none;
  font-weight: 700;
}

.footer-link:hover {
  color: var(--primary);
  text-decoration: underline;
}

.sidebar {
  align-self: start;
  position: sticky;
  top: 18px;
  display: grid;
  gap: 16px;
  min-width: 0;
  max-width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
  padding: 16px;
  overflow: hidden;
}

.sidebar-brand {
  border-bottom: 1px solid var(--line);
  padding: 0 0 16px;
}

.sidebar-nav {
  display: grid;
  gap: 8px;
  min-width: 0;
}

.sidebar-button {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 10px;
  width: 100%;
  min-width: 0;
  min-height: 42px;
  border: 1px solid var(--line);
  background: var(--button-soft);
  color: var(--button-soft-ink);
  padding: 9px 10px;
  text-align: left;
}

.sidebar-button span {
  display: inline-grid;
  place-items: center;
  width: 24px;
  height: 24px;
  border-radius: 999px;
  background: color-mix(in srgb, var(--primary) 18%, transparent);
  color: var(--primary);
  flex: 0 0 auto;
}

.sidebar-button strong {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  font-size: 0.86rem;
  white-space: nowrap;
}

.primary-sidebar-action {
  border-color: var(--line);
  background: var(--button-soft);
  color: var(--button-soft-ink);
}

.sidebar-button.is-active {
  border-color: color-mix(in srgb, var(--primary) 55%, var(--line));
  background: color-mix(in srgb, var(--primary) 18%, var(--button-soft));
  color: var(--ink);
}

.admin-users {
  border-top: 1px solid var(--line);
  padding-top: 14px;
}

.sidebar-section {
  border-top: 1px solid var(--line);
  padding-top: 14px;
}

.sidebar-section .section-title {
  margin-bottom: 10px;
}

.sidebar-section .section-title h2 {
  margin-bottom: 2px;
  font-size: 1rem;
}

.sidebar-section .section-title p {
  margin-bottom: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.action-button:disabled {
  cursor: not-allowed;
  opacity: 0.38;
}

.user-list {
  display: grid;
  gap: 6px;
  margin-top: 10px;
}

.supplier-list {
  display: grid;
  gap: 8px;
  margin-top: 18px;
  max-height: 240px;
  overflow: auto;
  padding-right: 4px;
}

.user-item {
  display: grid;
  align-items: center;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: color-mix(in srgb, var(--panel-soft) 72%, transparent);
  padding: 9px 10px;
}

.user-item strong,
.user-item span {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.user-item span {
  grid-column: 1;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 800;
}

.user-item .mini-button {
  grid-column: 2;
  grid-row: 1 / span 2;
}

.supplier-item {
  display: grid;
  align-items: center;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: color-mix(in srgb, var(--panel-soft) 72%, transparent);
  padding: 10px 12px;
}

.supplier-info {
  display: grid;
  gap: 4px;
  min-width: 0;
}

.supplier-info strong,
.supplier-info span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.supplier-info span,
.field-hint {
  color: var(--muted);
  font-size: 0.84rem;
}

.supplier-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.field-hint {
  margin: -6px 0 0;
}

.mini-button {
  min-height: 30px;
  border: 1px solid var(--line);
  background: var(--button-soft);
  color: var(--button-soft-ink);
  padding: 4px 8px;
  font-size: 0.78rem;
}

.mini-button:disabled,
.compact-button:disabled {
  cursor: not-allowed;
  opacity: 0.42;
}

.danger-mini-button {
  border-color: color-mix(in srgb, var(--danger) 34%, var(--line));
  color: var(--danger);
}

.section-title p,
.form-message,
.empty-state {
  color: var(--muted);
  font-size: 0.92rem;
}

form,
label {
  display: grid;
  gap: 8px;
}

form {
  gap: 16px;
}

label {
  color: var(--ink);
  font-size: 0.9rem;
  font-weight: 700;
}

.checkbox-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

.checkbox-row input {
  width: auto;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--input-line);
  border-radius: 8px;
  background: var(--input-bg);
  color: var(--ink);
  padding: 12px 13px;
  outline: none;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary) 22%, transparent);
}

.password-field {
  position: relative;
  display: block;
}

.password-field input {
  padding-right: 44px;
}

.password-toggle {
  position: absolute;
  top: 50%;
  right: 8px;
  transform: translateY(-50%);
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  padding: 4px;
  border: none;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
}

.password-toggle:hover {
  color: var(--ink);
  background: color-mix(in srgb, var(--line) 40%, transparent);
}

.password-toggle svg {
  width: 20px;
  height: 20px;
}

.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}

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

.form-actions,
.header-actions,
.row-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.form-actions {
  justify-content: flex-end;
}

button {
  min-height: 42px;
  border: 0;
  border-radius: 8px;
  padding: 10px 14px;
  font-weight: 800;
  cursor: pointer;
}

.primary-button {
  background: var(--primary);
  color: white;
}

.primary-button:hover {
  background: var(--primary-dark);
}

.ghost-button {
  background: var(--button-soft);
  color: var(--button-soft-ink);
}

.compact-button {
  min-height: 42px;
  padding-inline: 16px;
  white-space: nowrap;
}

.icon-button {
  display: inline-grid;
  place-items: center;
  width: 42px;
  min-width: 42px;
  padding: 0;
  background: var(--button-soft);
  color: var(--button-soft-ink);
}

.icon-button:hover {
  background: color-mix(in srgb, var(--button-soft) 82%, var(--primary));
}

.theme-icon {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2;
}

.theme-icon-moon {
  display: none;
}

html[data-theme="light"] .theme-icon-sun {
  display: none;
}

html[data-theme="light"] .theme-icon-moon {
  display: block;
}

.danger-button {
  background: color-mix(in srgb, var(--danger) 16%, transparent);
  color: var(--danger);
}

.action-button {
  display: inline-grid;
  place-items: center;
  width: 36px;
  min-width: 36px;
  min-height: 36px;
  padding: 0;
  border: 1px solid var(--line);
  background: var(--button-soft);
  color: var(--button-soft-ink);
}

.action-button svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2;
}

.icon-button svg {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2;
}

.entry-action {
  border-color: color-mix(in srgb, var(--primary) 45%, var(--line));
  color: var(--primary);
}

.exit-action {
  color: var(--warn);
}

.history-action {
  color: #6fa8ff;
}

.delete-action {
  border-color: color-mix(in srgb, var(--danger) 35%, var(--line));
  color: var(--danger);
}

.content-area {
  display: grid;
  gap: 18px;
  align-content: start;
  min-width: 0;
}

.app-page {
  display: grid;
  gap: 18px;
  align-content: start;
  min-width: 0;
}

.app-page.is-hidden {
  display: none;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(150px, 1fr));
  gap: 14px;
}

.stat-card {
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-height: 168px;
  padding: 18px;
}

.stat-card span {
  color: var(--muted);
  font-size: 0.88rem;
  font-weight: 700;
}

.stat-card strong {
  display: block;
  font-size: 2rem;
}

.stat-actions,
.panel-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  align-self: end;
  gap: 8px;
  margin-top: auto;
}

.stat-card.warning {
  background: var(--panel);
  border-color: var(--warn-line);
}

.stat-card.warning strong {
  color: var(--warn);
}

.stat-card.orders {
  background: var(--panel);
  border-color: color-mix(in srgb, #6fa8ff 36%, var(--line));
}

.stat-card.orders strong {
  color: #6fa8ff;
}

.low-stock-list,
.ordered-list {
  display: grid;
  gap: 6px;
}

.low-stock-list > span,
.ordered-list > span {
  color: var(--muted);
  font-size: 0.82rem;
}

.low-stock-alert,
.ordered-alert {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 32px;
  border: 1px solid var(--warn-line);
  border-radius: 8px;
  background: var(--warn-bg);
  color: var(--warn);
  padding: 7px 9px;
  text-align: left;
  font-size: 0.82rem;
  font-weight: 800;
}

.ordered-alert {
  border-color: color-mix(in srgb, #6fa8ff 38%, var(--line));
  background: color-mix(in srgb, #6fa8ff 10%, var(--panel-soft));
  color: #6fa8ff;
}

.dashboard-grid {
  display: grid;
  grid-template-columns: minmax(260px, 0.9fr) minmax(280px, 1fr) minmax(280px, 1fr);
  gap: 14px;
}

.dashboard-panel {
  display: flex;
  flex-direction: column;
  gap: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
  padding: 18px;
}

.dashboard-breakdown,
.dashboard-list {
  display: grid;
  gap: 8px;
  flex: 1 1 auto;
}

.breakdown-item,
.dashboard-list-item {
  width: 100%;
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: color-mix(in srgb, var(--panel-soft) 76%, transparent);
  color: var(--ink);
  text-align: left;
}

.breakdown-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 40px;
  padding: 8px 10px;
}

.breakdown-item span,
.dashboard-list-item span,
.dashboard-empty {
  color: var(--muted);
  font-size: 0.84rem;
}

.breakdown-item strong {
  font-size: 1rem;
}

.dashboard-list-item {
  display: grid;
  gap: 4px;
  padding: 10px 12px;
}

.dashboard-list-item strong,
.dashboard-list-item span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.dashboard-list-item.movement-out {
  border-left: 4px solid var(--warn);
}

.dashboard-list-item.movement-in {
  border-left: 4px solid var(--primary);
}

.dashboard-empty {
  display: block;
  padding: 10px 0;
  color: var(--muted);
  font-size: 0.92rem;
}

.replenishment-list,
.backup-actions {
  display: grid;
  gap: 10px;
}

.replenishment-toolbar {
  display: grid;
  grid-template-columns: minmax(220px, 1fr) minmax(160px, 0.7fr) minmax(150px, 0.55fr);
  gap: 12px;
  margin-bottom: 12px;
}

.replenishment-summary {
  margin: -2px 0 14px;
  color: var(--muted);
  font-size: 0.84rem;
  font-weight: 800;
}

.replenishment-group {
  display: grid;
  gap: 10px;
}

.replenishment-group + .replenishment-group {
  margin-top: 6px;
}

.replenishment-group-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 900;
  text-transform: uppercase;
}

.replenishment-group-title span {
  color: var(--muted);
  font-size: 0.78rem;
  text-transform: none;
}

.replenishment-item {
  display: grid;
  gap: 12px;
  border: 1px solid var(--line);
  border-left: 4px solid var(--warn);
  border-radius: 8px;
  background: var(--panel-soft);
  color: var(--ink);
  padding: 12px 14px;
  text-align: left;
}

.replenishment-item.has-order {
  border-left-color: var(--primary);
}

.replenishment-item-header,
.dialog-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.replenishment-title {
  display: grid;
  gap: 3px;
  min-width: 0;
}

.replenishment-title strong,
.replenishment-title small,
.replenishment-meta {
  overflow: hidden;
  text-overflow: ellipsis;
}

.replenishment-title small,
.replenishment-meta,
.replenishment-order-detail {
  color: var(--muted);
  font-size: 0.84rem;
}

.replenishment-title small,
.replenishment-meta {
  white-space: nowrap;
}

.replenishment-meta {
  margin-bottom: 0;
}

.replenishment-controls {
  display: grid;
  grid-template-columns: auto minmax(72px, 0.35fr) minmax(150px, 1fr) auto auto auto;
  gap: 8px;
  align-items: center;
}

.replenishment-controls input {
  min-height: 38px;
  padding: 9px 10px;
}

.replenishment-order-detail {
  align-self: center;
  grid-column: span 2;
  font-weight: 800;
}

.replenishment-item .badge.warn {
  color: var(--warn);
  font-weight: 900;
}

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

.filter-grid {
  display: grid;
  grid-template-columns: minmax(220px, 1fr) 150px 150px 140px 160px;
  gap: 12px;
  min-width: min(920px, 100%);
}

.search-box {
  min-width: 0;
}

.table-wrap {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
}

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

td {
  font-size: 0.78rem;
}

td small {
  display: block;
  margin-top: 4px;
  color: var(--muted);
  font-size: 0.72rem;
}

th {
  color: var(--muted);
  font-size: 0.78rem;
  text-transform: uppercase;
}

.numeric-column {
  text-align: center;
}

.action-column {
  width: 158px;
  text-align: right;
}

.table-row-actions {
  display: inline-flex;
  justify-content: flex-end;
  gap: 6px;
  opacity: 0;
  transition: opacity 150ms ease;
}

tr:hover .table-row-actions,
tr:focus-within .table-row-actions,
.selected-row .table-row-actions {
  opacity: 1;
}

.quick-action-button {
  width: 32px;
  min-width: 32px;
  min-height: 32px;
}

.quick-action-button svg {
  width: 16px;
  height: 16px;
}

.badge {
  display: inline-flex;
  border-radius: 999px;
  padding: 5px 9px;
  font-size: 0.78rem;
  font-weight: 800;
}

.badge.ok {
  background: var(--ok-bg);
  color: var(--primary);
}

.badge.warn {
  background: var(--warn-bg);
  color: var(--warn);
}

.badge.info {
  background: color-mix(in srgb, #6fa8ff 16%, transparent);
  color: #6fa8ff;
}

.empty-state {
  display: none;
  margin: 18px 0 0;
}

.confirm-overlay {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: grid;
  place-items: center;
  background: color-mix(in srgb, #000 45%, transparent);
  padding: 24px;
}

.confirm-modal {
  width: min(420px, 100%);
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow), 0 8px 32px rgba(0,0,0,0.3);
  padding: 24px;
}

.confirm-message {
  margin: 0 0 18px;
  color: var(--muted);
  line-height: 1.5;
  font-size: 0.92rem;
}

.app-dialog {
  width: 100%;
  max-height: none;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--ink);
  box-shadow: var(--shadow);
  padding: 24px;
}

.material-dialog {
  width: 100%;
}

.user-dialog {
  width: 100%;
}

.supplier-dialog {
  width: 100%;
}

.material-details-dialog {
  width: 100%;
}

.dialog-header,
.movement-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
}

.dialog-header {
  margin-bottom: 22px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--line);
}

.dialog-header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 0 0 auto;
}

.dialog-header h2 {
  max-width: 460px;
  margin-bottom: 0;
  overflow-wrap: anywhere;
}

.dialog-subtitle {
  margin: 6px 0 0;
  color: var(--muted);
  font-weight: 800;
  overflow-wrap: anywhere;
}

.material-summary-grid,
.material-detail-grid {
  display: grid;
  gap: 12px;
}

.material-summary-grid {
  grid-template-columns: repeat(4, minmax(0, 1fr));
  margin-bottom: 18px;
}

.material-summary-grid article,
.material-detail-grid > div {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: color-mix(in srgb, var(--panel-soft) 72%, transparent);
  padding: 13px 14px;
}

.material-summary-grid span,
.material-detail-grid span {
  display: block;
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 800;
}

.material-summary-grid strong,
.material-detail-grid strong {
  display: block;
  overflow-wrap: anywhere;
}

.material-summary-grid strong {
  font-size: 1.35rem;
}

.material-detail-grid {
  grid-template-columns: repeat(2, minmax(0, 1fr));
  margin-bottom: 18px;
}

.material-detail-context {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
  margin-bottom: 18px;
}

.detail-context-panel {
  display: grid;
  align-content: start;
  gap: 10px;
  min-width: 0;
  border: 1px solid var(--line);
  border-left: 4px solid var(--line);
  border-radius: 8px;
  background: color-mix(in srgb, var(--panel-soft) 82%, transparent);
  padding: 13px 14px;
}

.detail-context-panel.has-order {
  border-left-color: var(--primary);
}

.detail-context-panel.needs-order {
  border-left-color: var(--warn);
}

.detail-context-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  min-width: 0;
}

.detail-context-header > div {
  min-width: 0;
}

.detail-context-header span,
.detail-context-panel p {
  color: var(--muted);
  font-size: 0.82rem;
}

.detail-context-header span {
  display: block;
  margin-bottom: 4px;
  font-weight: 800;
}

.detail-context-header strong,
.detail-context-panel p {
  overflow-wrap: anywhere;
}

.detail-context-panel p {
  margin: 0;
  line-height: 1.5;
}

.wide-detail {
  grid-column: 1 / -1;
}

.ok-detail {
  color: var(--primary);
}

.warn-detail {
  color: var(--warn);
}

.info-detail {
  color: #6fa8ff;
}

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

.detail-action-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-width: 0;
  border: 1px solid var(--line);
  background: var(--button-soft);
  color: var(--button-soft-ink);
  white-space: nowrap;
}

.detail-action-button:disabled {
  cursor: not-allowed;
  opacity: 0.38;
}

.detail-action-button svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2;
  flex: 0 0 auto;
}

.history-list {
  display: grid;
  gap: 12px;
  max-height: 440px;
  overflow: auto;
  padding-right: 6px;
}

.history-filters {
  display: grid;
  grid-template-columns: minmax(96px, 0.7fr) minmax(150px, 1fr) minmax(150px, 1fr) auto;
  gap: 12px;
  align-items: end;
  margin-bottom: 16px;
}

.history-filters label {
  min-width: 0;
}

.history-filters button {
  justify-self: end;
}

.global-history-filters {
  grid-template-columns: minmax(96px, 0.65fr) minmax(180px, 1.2fr) minmax(140px, 0.85fr) minmax(140px, 0.85fr) auto;
}

.movement-item {
  display: grid;
  gap: 9px;
  border: 1px solid var(--line);
  border-left: 4px solid var(--primary);
  border-radius: 8px;
  background: color-mix(in srgb, var(--panel-soft) 92%, var(--primary));
  padding: 15px 16px;
  transition: border-color 160ms ease, transform 160ms ease;
}

.movement-item:hover {
  border-color: color-mix(in srgb, var(--line) 68%, var(--primary));
  transform: translateY(-1px);
}

.movement-meta,
.movement-item p {
  color: var(--muted);
  font-size: 0.88rem;
}

.movement-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.movement-meta span {
  max-width: 180px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 3px 8px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.movement-item p {
  margin-bottom: 0;
  line-height: 1.45;
}

.movement-row span {
  border-radius: 999px;
  background: color-mix(in srgb, currentColor 12%, transparent);
  padding: 4px 9px;
  font-weight: 900;
}

.movement-out {
  border-left-color: var(--warn);
  background: color-mix(in srgb, var(--panel-soft) 92%, var(--warn));
}

.movement-out .movement-row span {
  color: var(--warn);
}

.movement-in .movement-row span {
  color: var(--primary);
}

.movement-warning {
  border-left-color: var(--danger);
  color: var(--danger);
  font-weight: 800;
}

tbody tr {
  cursor: pointer;
  transition: background 140ms ease;
}

tbody tr:hover {
  background: color-mix(in srgb, var(--panel-soft) 70%, var(--primary));
}

tbody tr:focus {
  outline: 2px solid color-mix(in srgb, var(--primary) 56%, transparent);
  outline-offset: -2px;
}

.selected-row {
  background: color-mix(in srgb, var(--primary) 9%, transparent);
}

.selected-row td:first-child {
  box-shadow: inset 3px 0 0 var(--primary);
}

@media (max-width: 880px) {
  .app-header,
  .toolbar {
    align-items: stretch;
    flex-direction: column;
  }

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

  .filter-grid,
  .dashboard-grid,
  .history-filters,
  .stats-grid {
    grid-template-columns: 1fr 1fr;
  }

  .sidebar {
    position: static;
    width: 100%;
  }
}

@media (max-width: 640px) {
  .stats-grid,
  .dashboard-grid,
  .form-grid,
  .filter-grid,
  .history-filters,
  .replenishment-toolbar {
    grid-template-columns: 1fr;
  }

  .app-header {
    padding: 20px 16px;
  }

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

  .app-footer {
    flex-direction: column;
    align-items: center;
    gap: 6px;
    text-align: center;
    padding: 12px 16px 16px;
  }

  .footer-col,
  .footer-col-end {
    text-align: center;
  }

  .header-actions {
    display: grid;
    grid-template-columns: 42px 1fr 1fr;
    width: 100%;
  }

  .header-actions .primary-button,
  .header-actions .ghost-button {
    min-width: 0;
    padding-inline: 10px;
  }

  .brand-logo {
    width: 152px;
  }

  table,
  thead,
  tbody,
  tr,
  th,
  td {
    display: block;
  }

  thead {
    display: none;
  }

  tr {
    border: 1px solid var(--line);
    border-radius: 8px;
    margin-bottom: 12px;
    padding: 10px;
    background: #fff;
    background: var(--panel-soft);
  }

  tr:hover {
    background: var(--panel-soft);
  }

  .selected-row {
    border-color: color-mix(in srgb, var(--primary) 65%, var(--line));
  }

  .selected-row td:first-child {
    box-shadow: none;
  }

  td {
    display: grid;
    grid-template-columns: 118px 1fr;
    gap: 10px;
    border-bottom: 0;
    padding: 8px 4px;
  }

  td::before {
    content: attr(data-label);
    color: var(--muted);
    font-weight: 800;
  }

  .row-actions {
    align-items: stretch;
  }

  .action-column {
    width: auto;
    text-align: left;
  }

  .table-row-actions {
    justify-content: flex-start;
    opacity: 1;
  }

  .sidebar {
    gap: 14px;
    padding: 14px;
  }

  .sidebar-brand {
    padding-bottom: 12px;
  }

  .sidebar-section {
    padding-top: 14px;
  }

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

  .material-summary-grid,
  .material-detail-grid,
  .material-detail-context,
  .material-detail-actions {
    grid-template-columns: 1fr;
  }

  .material-summary-grid strong {
    font-size: 1.15rem;
  }

  .replenishment-item-header,
  .dialog-header-actions,
  .dialog-actions {
    align-items: stretch;
  }

  .replenishment-controls {
    grid-template-columns: 1fr;
  }

  .replenishment-order-detail {
    grid-column: auto;
  }

  .replenishment-title small,
  .replenishment-meta {
    white-space: normal;
  }

  .user-list {
    max-height: 160px;
    overflow: auto;
  }

  .app-dialog {
    padding: 16px;
  }
}

@media (max-width: 420px) {
  .detail-action-button {
    justify-content: flex-start;
  }
}

@media print {
  .form-panel,
  .sidebar,
  .header-actions,
  .search-box,
  .dashboard-grid,
  .filter-grid,
  .stats-grid,
  .section-title p,
  .screen-only-column {
    display: none;
  }

  body {
    background: #fff;
    color: #17211b;
  }

  .app-shell {
    display: block;
    padding: 0;
  }

  .panel,
  .stat-card {
    border: 0;
    box-shadow: none;
  }

  .table-wrap {
    overflow: visible;
  }

  table {
    border-collapse: collapse;
  }

  th,
  td {
    border-bottom: 1px solid #cfd6dd;
    color: #17211b;
  }
}
