:root {
  color-scheme: light;
  --ink: #22201d;
  --muted: #706b63;
  --line: #ddd6ca;
  --paper: #fffdfa;
  --soft: #f4efe7;
  --accent: #246a63;
  --accent-dark: #174b46;
  --warn: #b54708;
  --bad: #b42318;
  --good: #217a4a;
  --shadow: 0 18px 50px rgba(45, 36, 24, 0.12);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

body {
  min-height: 100vh;
  margin: 0;
  background:
    linear-gradient(180deg, rgba(36, 106, 99, 0.11), transparent 320px),
    var(--soft);
  color: var(--ink);
}

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

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

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

.login-logo {
  display: block;
  width: 100%;
  max-height: 160px;
  object-fit: contain;
  border-radius: 6px;
}

.login-panel h1 {
  margin-bottom: 8px;
  font-size: 2rem;
}

.login-error {
  min-height: 20px;
  margin: 0;
  color: var(--bad);
  font-size: 0.9rem;
  font-weight: 800;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 28px clamp(18px, 4vw, 48px) 18px;
}

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

.app-logo {
  width: 92px;
  height: 92px;
  flex: 0 0 92px;
  border-radius: 8px;
  object-fit: cover;
}

.topbar-account {
  display: grid;
  justify-items: end;
  gap: 10px;
}

.session-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
}

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

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

h1 {
  margin-bottom: 0;
  font-size: clamp(1.85rem, 3vw, 3rem);
}

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

h3 {
  margin-bottom: 8px;
  font-size: 1rem;
}

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

.summary span,
.status {
  display: inline-flex;
  min-height: 32px;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.72);
  color: var(--muted);
  font-size: 0.88rem;
  font-weight: 700;
  padding: 6px 12px;
}

.tabs {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 0 clamp(18px, 4vw, 48px) 18px;
}

.tab-button {
  min-width: max-content;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.7);
  color: var(--muted);
  padding: 10px 14px;
}

.tab-button.active {
  background: var(--accent);
  color: white;
}

main {
  padding: 0 clamp(18px, 4vw, 48px) 42px;
}

.tab-panel {
  display: none;
}

.tab-panel.active {
  display: block;
}

.factory-grid,
.branch-grid {
  display: grid;
  grid-template-columns: minmax(320px, 0.9fr) minmax(360px, 1.4fr);
  align-items: start;
  gap: 18px;
}

.dashboard-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  align-items: start;
  gap: 18px;
}

.dashboard-panel,
.branch-header-panel {
  margin-top: 18px;
}

.panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--paper);
  box-shadow: var(--shadow);
  padding: 18px;
}

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

form,
.product-list,
.shipment-list,
.receipt-grid {
  display: grid;
  gap: 12px;
}

.compact-list {
  gap: 8px;
}

.product-group-title {
  position: sticky;
  top: 0;
  z-index: 1;
  margin: 6px 0 -2px;
  border-bottom: 1px solid var(--line);
  background: var(--paper);
  color: var(--accent-dark);
  font-size: 0.92rem;
  padding: 9px 0 7px;
}

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

input,
select,
textarea {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: white;
  color: var(--ink);
  padding: 9px 11px;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--accent);
  outline: 3px solid rgba(36, 106, 99, 0.16);
}

input:disabled,
textarea:disabled,
select:disabled {
  background: #f0ece5;
  color: var(--muted);
  cursor: not-allowed;
}

textarea {
  resize: vertical;
}

.product-row,
.receipt-row,
.sent-row {
  display: grid;
  grid-template-columns: minmax(120px, 1fr) 108px;
  align-items: center;
  gap: 10px;
}

.product-row span,
.sent-row span:first-child,
.receipt-row span:first-child {
  font-weight: 700;
}

.product-row input,
.receipt-row input {
  text-align: right;
}

button {
  min-height: 42px;
  border: 0;
  border-radius: 7px;
  cursor: pointer;
  font-weight: 800;
}

.primary {
  background: var(--accent);
  color: white;
  padding: 10px 16px;
}

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

.secondary {
  border: 1px solid var(--line);
  background: white;
  color: var(--ink);
  padding: 9px 13px;
}

.icon-button {
  width: 42px;
  min-width: 42px;
  padding: 0;
  border: 1px solid var(--line);
  background: white;
  color: var(--accent);
  font-size: 1.2rem;
}

.shipment-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
  padding: 15px;
}

.folder {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
  overflow: hidden;
}

.folder summary {
  display: flex;
  min-height: 48px;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  cursor: pointer;
  color: var(--accent-dark);
  font-weight: 900;
  padding: 12px 14px;
}

.folder summary span {
  color: var(--muted);
  font-size: 0.86rem;
  font-weight: 800;
}

.folder-content {
  display: grid;
  gap: 10px;
  border-top: 1px solid var(--line);
  background: rgba(244, 239, 231, 0.55);
  padding: 12px;
}

.folder-content .shipment-card {
  box-shadow: none;
}

.shipment-title {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.shipment-title p,
.shipment-title p + p,
.note,
.alert-text,
.empty {
  color: var(--muted);
}

.note {
  margin: 4px 0 14px;
  font-size: 0.92rem;
}

.alert-text {
  margin-bottom: 12px;
  color: var(--bad);
  font-size: 0.9rem;
  font-weight: 800;
}

.locked-message {
  margin: 14px 0 0;
  border-radius: 7px;
  background: rgba(33, 122, 74, 0.1);
  color: var(--good);
  font-size: 0.9rem;
  font-weight: 800;
  padding: 10px 12px;
}

.sent-list {
  display: grid;
  gap: 7px;
  margin: 0 0 14px;
}

.sent-row,
.receipt-row {
  min-height: 38px;
  border-radius: 7px;
  background: var(--soft);
  padding: 6px 9px;
}

.mismatch-row {
  background: rgba(180, 35, 24, 0.1);
}

.return-total-row {
  border: 1px solid rgba(33, 122, 74, 0.2);
  background: rgba(33, 122, 74, 0.1);
}

.sent-row span:last-child {
  font-weight: 800;
  text-align: right;
}

.receipt-row.match {
  background: rgba(33, 122, 74, 0.1);
}

.receipt-row.mismatch {
  background: rgba(180, 35, 24, 0.1);
}

.difference {
  color: var(--bad);
  font-size: 0.82rem;
  font-weight: 800;
  text-align: right;
}

.status.pending {
  color: var(--warn);
}

.status.issue {
  color: var(--bad);
}

.status.ok {
  color: var(--good);
}

.card-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 14px;
}

.empty {
  border: 1px dashed var(--line);
  border-radius: 8px;
  padding: 22px;
  text-align: center;
}

@media (max-width: 820px) {
  .topbar,
  .tabs,
  main {
    padding-left: 14px;
    padding-right: 14px;
  }

  .topbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .app-logo {
    width: 72px;
    height: 72px;
    flex-basis: 72px;
  }

  .topbar-account {
    justify-items: start;
  }

  .session-actions {
    justify-content: flex-start;
  }

  .summary {
    justify-content: flex-start;
  }

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

@media (max-width: 460px) {
  .product-row,
  .receipt-row,
  .sent-row {
    grid-template-columns: 1fr;
  }

  .difference {
    text-align: left;
  }
}
