:root {
  color-scheme: light;
  --bg: #f3f8fa;
  --surface: #ffffff;
  --surface-strong: #eef8fb;
  --ink: #14313a;
  --muted: #6b7d83;
  --line: #d7e7ec;
  --brand: #0f91b3;
  --brand-dark: #0c6577;
  --brand-deep: #064757;
  --aqua: #22b8cf;
  --amber: #c87917;
  --red: #b33b35;
  --blue: #246da8;
  --shadow: 0 18px 42px rgba(6, 71, 87, 0.1);
  --shadow-soft: 0 10px 24px rgba(6, 71, 87, 0.07);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    linear-gradient(180deg, rgba(15, 145, 179, 0.1), transparent 270px),
    var(--bg);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

[hidden] {
  display: none !important;
}

.brand-strip {
  height: 8px;
  background: linear-gradient(90deg, #0b7794, #28b7cf 44%, #0b6f83);
}

.auth-view {
  min-height: calc(100vh - 8px);
  display: grid;
  place-items: center;
  padding: 24px;
}

.auth-card {
  width: min(440px, 100%);
  display: grid;
  gap: 16px;
  padding: 24px;
  background: rgba(255, 255, 255, 0.92);
  border: 1px solid rgba(215, 231, 236, 0.95);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.auth-card img {
  width: min(100%, 310px);
  height: auto;
}

.auth-card h1 {
  font-size: clamp(1.8rem, 5vw, 2.8rem);
}

.auth-actions {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
  align-items: center;
}

.auth-status {
  min-height: 20px;
  margin: 0;
  color: var(--muted);
  font-size: 0.88rem;
  line-height: 1.4;
}

.app-shell {
  width: min(1480px, calc(100% - 32px));
  margin: 0 auto;
  padding: 22px 0 40px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 18px;
  padding: 18px;
  background: rgba(255, 255, 255, 0.88);
  border: 1px solid rgba(215, 231, 236, 0.95);
  border-radius: 8px;
  box-shadow: var(--shadow);
  backdrop-filter: blur(10px);
}

.brand-lockup {
  display: flex;
  align-items: center;
  gap: 22px;
  min-width: 0;
}

.brand-lockup img {
  width: clamp(210px, 24vw, 330px);
  height: auto;
  flex: 0 0 auto;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--brand-dark);
  font-size: 0.82rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0;
}

h1,
h2,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-size: clamp(1.75rem, 3.5vw, 3.1rem);
  line-height: 1;
  letter-spacing: 0;
  color: var(--brand-deep);
}

h2 {
  margin-bottom: 0;
  font-size: 1.05rem;
}

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

.session-pill {
  max-width: 220px;
  overflow: hidden;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #f4fbfd;
  color: var(--brand-dark);
  font-size: 0.82rem;
  font-weight: 800;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.icon-button,
.primary-button,
.ghost-button,
.small-button {
  border: 1px solid transparent;
  border-radius: 8px;
  transition: transform 0.15s ease, background 0.15s ease, border-color 0.15s ease;
}

.icon-button {
  display: grid;
  width: 44px;
  height: 44px;
  place-items: center;
  background: #f8fdff;
  border-color: #cae4eb;
  color: var(--brand-deep);
  box-shadow: var(--shadow-soft);
}

.icon-button:hover,
.primary-button:hover,
.ghost-button:hover,
.small-button:hover {
  transform: translateY(-1px);
}

.file-button input {
  position: absolute;
  inline-size: 1px;
  block-size: 1px;
  opacity: 0;
  pointer-events: none;
}

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

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

.metric {
  min-height: 98px;
  padding: 18px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  position: relative;
  overflow: hidden;
}

.metric::before {
  content: "";
  position: absolute;
  inset: 0 auto 0 0;
  width: 5px;
  background: linear-gradient(180deg, var(--aqua), var(--brand-dark));
}

.metric span {
  color: var(--muted);
  font-size: 0.86rem;
  font-weight: 700;
}

.metric strong {
  font-size: 2rem;
  line-height: 1;
  color: var(--brand-deep);
}

.metric.warning strong {
  color: var(--amber);
}

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

.panel {
  padding: 18px;
  box-shadow: var(--shadow-soft);
}

.panel-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 16px;
}

.panel-heading.compact {
  margin-bottom: 14px;
}

.search-field {
  flex: 0 1 440px;
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 220px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-strong);
  color: var(--brand-dark);
}

.search-field input {
  width: 100%;
  min-height: 42px;
  border: 0;
  outline: 0;
  background: transparent;
}

.table-wrap {
  width: 100%;
  overflow-x: auto;
}

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

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

th {
  color: var(--brand-dark);
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0;
  background: #f4fbfd;
}

td strong {
  display: block;
}

.stock-badge {
  display: inline-flex;
  align-items: center;
  min-width: 58px;
  justify-content: center;
  padding: 5px 9px;
  border-radius: 999px;
  background: #def6f8;
  color: var(--brand-dark);
  font-weight: 800;
}

.stock-badge.low {
  background: #fff1d7;
  color: var(--amber);
}

.stock-badge.empty {
  background: #ffe5e2;
  color: var(--red);
}

.stock-row.low td {
  background: #fffaf0;
}

.stock-row.critical td {
  background: #fff3f1;
}

.alert-pill {
  display: inline-grid;
  min-width: 74px;
  min-height: 28px;
  place-items: center;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 850;
}

.alert-pill.ok {
  background: #e8f8f6;
  color: var(--brand-dark);
}

.alert-pill.low {
  background: #fff1d7;
  color: var(--amber);
}

.alert-pill.critical {
  background: #ffe5e2;
  color: var(--red);
}

.side-stack {
  display: grid;
  gap: 16px;
}

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

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

input,
select {
  width: 100%;
  min-height: 42px;
  padding: 9px 11px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  outline: 0;
}

input:focus,
select:focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(15, 145, 179, 0.14);
}

.two-cols {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.primary-button {
  min-height: 44px;
  background: linear-gradient(135deg, var(--brand), var(--brand-dark));
  color: #fff;
  font-weight: 850;
  box-shadow: 0 10px 22px rgba(15, 145, 179, 0.18);
}

.ghost-button,
.small-button {
  min-height: 34px;
  padding: 7px 10px;
  background: #f4fbfd;
  border-color: var(--line);
  color: var(--ink);
  font-weight: 750;
}

.ghost-button.danger,
.small-button.remove {
  color: var(--red);
}

.small-button.add-stock {
  color: var(--brand-dark);
}

.small-button.edit {
  color: var(--blue);
}

.small-button.destock {
  color: var(--amber);
}

.history-panel {
  margin-top: 16px;
}

.history-list {
  display: grid;
  gap: 8px;
  max-height: 320px;
  overflow: auto;
}

.history-item {
  display: grid;
  grid-template-columns: 82px 1fr auto;
  gap: 12px;
  align-items: center;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfeff;
}

.history-type {
  display: inline-grid;
  min-height: 28px;
  place-items: center;
  border-radius: 999px;
  color: #fff;
  font-weight: 850;
  font-size: 0.78rem;
}

.history-type.in {
  background: var(--brand);
}

.history-type.out {
  background: var(--amber);
}

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

.history-main strong,
.history-main span {
  display: block;
}

.history-main span,
.history-date,
.empty-state {
  color: var(--muted);
  font-size: 0.86rem;
}

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

.empty-state.visible {
  display: block;
}

@media (max-width: 1040px) {
  .workspace-grid {
    grid-template-columns: 1fr;
  }

  .side-stack {
    grid-template-columns: 1fr 1fr;
  }
}

@media (max-width: 760px) {
  .app-shell {
    width: min(100% - 20px, 1480px);
    padding-top: 12px;
  }

  .topbar,
  .panel-heading {
    align-items: stretch;
    flex-direction: column;
  }

  .brand-lockup {
    align-items: flex-start;
    flex-direction: column;
    gap: 12px;
  }

  .brand-lockup img {
    width: min(100%, 300px);
  }

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

  .metrics-grid,
  .side-stack,
  .two-cols {
    grid-template-columns: 1fr;
  }

  .metrics-grid {
    gap: 10px;
  }

  .metric {
    min-height: 78px;
    padding: 14px 16px;
  }

  .metric strong {
    font-size: 1.65rem;
  }

  .panel {
    padding: 14px;
  }

  .panel-heading {
    gap: 10px;
    margin-bottom: 12px;
  }

  .search-field {
    flex: none;
    width: 100%;
    min-width: 0;
    height: 44px;
    padding: 0 10px;
  }

  .search-field input {
    min-height: 40px;
    font-size: 1rem;
  }

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

  table {
    min-width: 0;
  }

  thead {
    display: none;
  }

  tbody,
  tr,
  td {
    display: block;
    width: 100%;
  }

  tr.stock-row {
    margin-bottom: 12px;
    padding: 14px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fff;
  }

  .stock-row.low,
  .stock-row.critical {
    background: #fffaf0;
    border-color: #f0d8b8;
  }

  .stock-row.critical {
    background: #fff3f1;
    border-color: #efc4bf;
  }

  th,
  td {
    padding: 0;
    border-bottom: 0;
  }

  td {
    display: flex;
    align-items: center;
    background: transparent !important;
    justify-content: space-between;
    gap: 14px;
    min-height: 34px;
    padding: 7px 0;
  }

  td::before {
    color: var(--muted);
    content: "";
    flex: 0 0 96px;
    font-size: 0.78rem;
    font-weight: 850;
    text-transform: uppercase;
  }

  td:nth-child(1) {
    align-items: flex-start;
    display: block;
    padding-top: 0;
  }

  td:nth-child(1)::before {
    display: none;
  }

  td:nth-child(1) strong {
    font-size: 1.05rem;
    line-height: 1.25;
  }

  td:nth-child(2)::before {
    content: "Famille";
  }

  td:nth-child(3)::before {
    content: "Quantité";
  }

  td:nth-child(4)::before {
    content: "Alerte";
  }

  td:nth-child(5) {
    display: block;
    padding-bottom: 0;
  }

  td:nth-child(5)::before {
    display: none;
  }

  .row-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    margin-top: 8px;
  }

  .small-button {
    min-height: 38px;
    padding: 8px;
  }

  .history-item {
    grid-template-columns: 1fr;
  }

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