:root {
  color-scheme: light;
  --bg-top: #fbf4eb;
  --bg-bottom: #f1e1d3;
  --bg-soft: #fffaf4;
  --panel: rgba(255, 251, 245, 0.94);
  --panel-strong: #fffdf9;
  --panel-tint: #f6ebe1;
  --panel-accent: #f2ded1;
  --line: #e6d5c6;
  --line-strong: #c79d86;
  --text: #3c241a;
  --text-strong: #25140f;
  --muted: #71574d;
  --muted-strong: #5a4036;
  --accent: #7a3136;
  --accent-strong: #9d4a4d;
  --accent-deep: #5f2327;
  --accent-soft: #f6e3df;
  --accent-gold: #bf8d56;
  --accent-gold-soft: #f4e3c8;
  --success: #126850;
  --success-bg: #eaf8f2;
  --danger: #b33a3a;
  --danger-bg: #fff1f1;
  --shadow-lg: 0 24px 60px rgba(108, 65, 43, 0.14);
  --shadow-md: 0 14px 34px rgba(108, 65, 43, 0.1);
  --radius-xl: 30px;
  --radius-lg: 22px;
  --radius-md: 16px;
  --radius-sm: 12px;
  --font-body: "Segoe UI", Aptos, Calibri, sans-serif;
  --font-display: "Segoe UI", Aptos, Calibri, sans-serif;
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--font-body);
  color: var(--text);
  background:
    radial-gradient(circle at top left, rgba(191, 141, 86, 0.16), transparent 26%),
    radial-gradient(circle at 90% 12%, rgba(122, 49, 54, 0.11), transparent 22%),
    linear-gradient(180deg, var(--bg-top), var(--bg-bottom));
  overflow-x: hidden;
  position: relative;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  background:
    linear-gradient(rgba(122, 49, 54, 0.025) 1px, transparent 1px),
    linear-gradient(90deg, rgba(122, 49, 54, 0.025) 1px, transparent 1px);
  background-size: 120px 120px;
  mask-image: linear-gradient(to bottom, rgba(0, 0, 0, 0.32), transparent 90%);
  pointer-events: none;
}

.backdrop-orb,
.backdrop-grid {
  position: fixed;
  inset: auto;
  pointer-events: none;
  z-index: 0;
}

.backdrop-orb {
  width: 380px;
  height: 380px;
  border-radius: 50%;
  filter: blur(32px);
  opacity: 0.42;
}

.orb-one {
  top: -120px;
  left: -120px;
  background: radial-gradient(circle, rgba(191, 141, 86, 0.34), transparent 68%);
}

.orb-two {
  right: -140px;
  bottom: 10%;
  background: radial-gradient(circle, rgba(122, 49, 54, 0.22), transparent 68%);
}

.backdrop-grid {
  inset: 0;
  background:
    linear-gradient(135deg, rgba(255, 255, 255, 0.36), transparent 34%),
    linear-gradient(300deg, rgba(122, 49, 54, 0.045), transparent 30%);
}

.shell {
  position: relative;
  z-index: 1;
  width: min(1380px, calc(100vw - 32px));
  margin: 28px auto 54px;
}

.hidden {
  display: none !important;
}

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

h1,
h2,
h3 {
  font-family: var(--font-display);
  color: var(--text-strong);
  letter-spacing: -0.02em;
}

h1 {
  font-size: clamp(34px, 4vw, 48px);
  line-height: 1.08;
  font-weight: 800;
  margin-bottom: 12px;
}

h2 {
  font-size: clamp(24px, 2.4vw, 34px);
  line-height: 1.14;
  font-weight: 750;
  margin-bottom: 8px;
}

h3 {
  font-size: 20px;
  line-height: 1.25;
  font-weight: 700;
  margin-bottom: 8px;
}

.eyebrow {
  margin-bottom: 10px;
  color: var(--accent);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.18em;
  text-transform: uppercase;
}

.lead,
.section-note {
  color: var(--muted);
  line-height: 1.65;
}

.section-note {
  margin-bottom: 0;
}

.mini-label {
  color: rgba(255, 244, 235, 0.84);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.18em;
  text-transform: uppercase;
}

.login-panel,
.panel,
.brand-panel,
.spotlight-card,
.metric-card,
.subcard,
.identity-card {
  border: 1px solid rgba(154, 112, 90, 0.14);
  box-shadow: var(--shadow-lg);
}

.login-panel,
.panel,
.brand-panel,
.spotlight-card,
.insight-panel,
.nav-ribbon,
.identity-card,
.subcard {
  backdrop-filter: blur(14px);
}

.login-panel,
.panel,
.spotlight-card,
.metric-card,
.subcard {
  background: linear-gradient(180deg, rgba(255, 253, 249, 0.96), rgba(250, 242, 234, 0.92));
  border-radius: var(--radius-xl);
}

/* FIX: insight-panel needs border-radius to match sibling card */
.insight-panel {
  border-radius: var(--radius-xl);
}

/* FIX: metric-card border-radius should be smaller, not inherited from shared rule */
.metric-card {
  border-radius: var(--radius-lg) !important;
}

.login-panel {
  width: min(1120px, 100%);
  margin: 58px auto 0;
  padding: 28px;
  display: grid;
  grid-template-columns: minmax(280px, 1.08fr) minmax(320px, 0.92fr);
  gap: 24px;
}

.login-showcase {
  padding: 36px;
  border-radius: calc(var(--radius-xl) - 6px);
  background:
    radial-gradient(circle at top right, rgba(255, 255, 255, 0.1), transparent 28%),
    linear-gradient(135deg, var(--accent-deep), var(--accent-strong));
  color: #fff8f2;
  overflow: hidden;
  position: relative;
}

.login-showcase::after {
  content: "";
  position: absolute;
  inset: auto -30% -20% auto;
  width: 280px;
  height: 280px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(255, 255, 255, 0.18), transparent 68%);
  animation: pulse-float 9s ease-in-out infinite;
}

.login-showcase .eyebrow,
.login-showcase .lead {
  color: rgba(255, 245, 236, 0.92);
}

.login-showcase h1 {
  color: #fffdf9;
}

.auth-form {
  padding: 34px;
  border-radius: calc(var(--radius-xl) - 6px);
  background: rgba(255, 252, 248, 0.88);
}

.form-intro {
  margin-bottom: 8px;
}

.topbar {
  display: grid;
  gap: 16px;
  margin-bottom: 18px;
}

.brand-panel {
  display: flex;
  justify-content: space-between;
  gap: 24px;
  align-items: stretch;
  padding: 30px;
  border-radius: var(--radius-xl);
  background:
    radial-gradient(circle at top right, rgba(255, 255, 255, 0.16), transparent 24%),
    linear-gradient(135deg, #6b2228, #9a4746 55%, #b56b59);
  color: #fffaf6;
  overflow: hidden;
  position: relative;
}

.brand-panel::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(120deg, transparent 25%, rgba(255, 255, 255, 0.12) 40%, transparent 55%);
  transform: translateX(-120%);
  animation: shimmer 8s ease-in-out infinite;
  pointer-events: none;
}

.brand-copy,
.brand-side {
  position: relative;
  z-index: 1;
}

.brand-copy {
  flex: 1;
}

.brand-copy .eyebrow,
.brand-copy .lead,
.brand-copy h1 {
  color: #fffaf6;
}

.brand-side {
  width: min(360px, 100%);
  display: grid;
  gap: 14px;
  align-content: center;
}

.identity-card {
  padding: 18px 20px;
  border-radius: var(--radius-lg);
  background: rgba(255, 250, 246, 0.14);
  border-color: rgba(255, 255, 255, 0.16);
}

.identity-card strong {
  display: block;
  margin: 8px 0 12px;
  font-size: 18px;
  line-height: 1.4;
  color: #fffaf6;
}

/* FIX: nav-ribbon should stretch full width */
.nav-ribbon {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  padding: 10px;
  border-radius: 999px;
  background: rgba(255, 250, 245, 0.84);
  border: 1px solid rgba(154, 112, 90, 0.14);
  box-shadow: var(--shadow-md);
  width: 100%;
  align-items: center;
}

.overview-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.55fr) minmax(310px, 0.9fr);
  gap: 18px;
  margin-bottom: 18px;
}

.spotlight-card {
  padding: 28px;
  position: relative;
  overflow: hidden;
}

.spotlight-card::before,
.panel::before {
  content: "";
  position: absolute;
  left: 0;
  top: 0;
  width: 100%;
  height: 5px;
  background: linear-gradient(90deg, var(--accent), #b56b59, var(--accent-gold));
}

.workflow-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
  margin-top: 20px;
}

.workflow-step {
  padding: 18px;
  border-radius: var(--radius-md);
  background: linear-gradient(180deg, #fffdfa, #f8eee6);
  border: 1px solid rgba(154, 112, 90, 0.12);
  transition: transform 180ms ease, box-shadow 180ms ease, border-color 180ms ease;
}

.workflow-step:hover {
  transform: translateY(-4px);
  border-color: rgba(154, 112, 90, 0.28);
  box-shadow: var(--shadow-md);
}

.workflow-step p {
  color: var(--muted);
  margin-bottom: 0;
}

.step-number {
  display: inline-flex;
  width: 44px;
  height: 44px;
  border-radius: 14px;
  align-items: center;
  justify-content: center;
  margin-bottom: 14px;
  background: linear-gradient(135deg, var(--accent-soft), var(--accent-gold-soft));
  color: var(--accent);
  font-size: 14px;
  font-weight: 800;
}

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

.metric-card {
  padding: 20px;
  background: linear-gradient(180deg, rgba(255, 251, 246, 0.96), rgba(249, 241, 233, 0.96));
}

.metric-card span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.metric-card strong {
  display: block;
  margin: 10px 0 8px;
  font-size: 34px;
  font-weight: 800;
  color: var(--accent);
}

.metric-card small {
  color: var(--muted);
  font-size: 13px;
}

.panel {
  position: relative;
  overflow: hidden;
  margin-bottom: 18px;
  padding: 26px;
}

.deluxe-panel {
  background: linear-gradient(180deg, rgba(255, 252, 248, 0.97), rgba(248, 240, 231, 0.94));
}

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

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

.toolbar-actions {
  margin-top: 18px;
}

.stack {
  display: grid;
  gap: 14px;
}

/* FIX: calc form should use 3 cols but file upload on a new row spanning full */
.grid-form {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
  align-items: end;
}

.calc-form {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

/* FIX: Item upload spans full row to be prominent */
.grid-form .upload-label {
  grid-column: 1 / -1;
}

.calc-form .upload-label {
  grid-column: auto;
}

.framed-form {
  margin-bottom: 18px;
  padding: 18px;
  border-radius: var(--radius-lg);
  background: linear-gradient(180deg, rgba(255, 249, 243, 0.94), rgba(249, 241, 233, 0.88));
  border: 1px solid rgba(154, 112, 90, 0.12);
}

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

.admin-split {
  margin-bottom: 20px;
}

.subcard {
  padding: 20px;
  background: linear-gradient(180deg, rgba(255, 252, 248, 0.98), rgba(248, 239, 230, 0.94));
}

label {
  display: grid;
  gap: 8px;
  color: var(--muted-strong);
  font-size: 13px;
  font-weight: 700;
}

input,
select {
  width: 100%;
  min-height: 46px;
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 11px 14px;
  font: inherit;
  color: var(--text-strong);
  background: #fffdf9;
  outline: none;
  transition: border-color 160ms ease, box-shadow 160ms ease, transform 160ms ease, background 160ms ease;
}

input::placeholder {
  color: #9f8479;
}

input:focus,
select:focus {
  border-color: var(--accent-strong);
  box-shadow: 0 0 0 4px rgba(122, 49, 54, 0.1);
  background: #ffffff;
}

input[type="file"] {
  padding: 10px 12px;
  cursor: pointer;
}

button,
.button {
  min-height: 46px;
  border: 1px solid transparent;
  border-radius: 999px;
  padding: 11px 20px;
  background: linear-gradient(135deg, var(--accent), var(--accent-strong));
  color: #fff9f4;
  font: inherit;
  font-weight: 700;
  letter-spacing: 0.01em;
  text-decoration: none;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: transform 160ms ease, box-shadow 160ms ease, filter 160ms ease, background 160ms ease;
  box-shadow: 0 14px 24px rgba(122, 49, 54, 0.18);
}

button:hover,
.button:hover {
  transform: translateY(-2px);
  filter: brightness(1.03);
  box-shadow: 0 18px 26px rgba(122, 49, 54, 0.22);
}

button:disabled,
.button:disabled {
  cursor: wait;
  opacity: 0.72;
  transform: none;
  box-shadow: none;
}

button.secondary,
.button.secondary,
.ghost-button,
.nav-pill {
  background: linear-gradient(180deg, #fffaf5, #f5eadf);
  color: var(--accent);
  border-color: rgba(154, 112, 90, 0.18);
  box-shadow: none;
}

button.secondary:hover,
.button.secondary:hover,
.ghost-button:hover,
.nav-pill:hover {
  background: linear-gradient(180deg, #fffdf9, #f8efe7);
}

/* FIX: danger button style for delete actions */
button.danger,
.button.danger {
  background: linear-gradient(135deg, #b33a3a, #cc4d4d);
  color: #fff;
  border-color: transparent;
  box-shadow: 0 8px 18px rgba(179, 58, 58, 0.22);
}

button.danger:hover,
.button.danger:hover {
  filter: brightness(1.06);
  box-shadow: 0 12px 22px rgba(179, 58, 58, 0.28);
}

.ghost-button {
  width: 100%;
  color: #fffaf6;
  background: rgba(255, 248, 242, 0.14);
  border-color: rgba(255, 255, 255, 0.2);
}

.ghost-button:hover {
  background: rgba(255, 248, 242, 0.22);
}

.nav-pill {
  min-height: 44px;
  padding-inline: 18px;
  border-radius: 999px;
  font-size: 14px;
  font-weight: 700;
}

.nav-pill.is-active {
  color: #fffaf6;
  background: linear-gradient(135deg, var(--accent), var(--accent-strong));
  border-color: transparent;
  box-shadow: 0 10px 18px rgba(122, 49, 54, 0.2);
}

.chip-row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.info-chip {
  display: inline-flex;
  align-items: center;
  min-height: 32px;
  padding: 6px 12px;
  border-radius: 999px;
  background: rgba(255, 250, 246, 0.14);
  border: 1px solid rgba(255, 249, 244, 0.2);
  color: inherit;
  font-size: 13px;
  font-weight: 700;
}

#categoryChips .info-chip {
  color: #fffaf6;
}

.table-shell {
  overflow-x: auto;
  border: 1px solid rgba(154, 112, 90, 0.14);
  border-radius: var(--radius-lg);
  background: linear-gradient(180deg, rgba(255, 253, 249, 0.98), rgba(249, 241, 233, 0.96));
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.72);
}

.table-headline {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 12px;
  margin: 6px 0 12px;
}

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

#itemsTable {
  table-layout: fixed;
  min-width: 980px;
}

#itemsTable th:nth-child(1),
#itemsTable td:nth-child(1) {
  width: 24%;
}

#itemsTable th:nth-child(2),
#itemsTable td:nth-child(2),
#itemsTable th:nth-child(3),
#itemsTable td:nth-child(3),
#itemsTable th:nth-child(4),
#itemsTable td:nth-child(4) {
  width: 12%;
}

#itemsTable th:nth-child(5),
#itemsTable td:nth-child(5) {
  width: 10%;
}

#itemsTable th:nth-child(6),
#itemsTable td:nth-child(6) {
  width: 18%;
}

#itemsTable th:nth-child(7),
#itemsTable td:nth-child(7) {
  width: 12%;
}

th,
td {
  padding: 14px 14px;
  border-bottom: 1px solid rgba(154, 112, 90, 0.12);
  text-align: left;
  vertical-align: middle;
}

th {
  position: sticky;
  top: 0;
  background: linear-gradient(135deg, #7a3136, #a05553);
  color: #fff8f3;
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

td {
  color: var(--muted-strong);
  background: rgba(255, 253, 249, 0.92);
}

tbody tr:nth-child(even) td {
  background: rgba(248, 239, 230, 0.88);
}

tbody tr:hover td {
  background: rgba(244, 228, 218, 0.72);
}

#itemsTable td {
  padding: 10px;
}

td input {
  width: 100%;
  min-width: 0;
  min-height: 42px;
  border-radius: 12px;
  padding: 10px 12px;
}

tr:last-child td {
  border-bottom: 0;
}

/* FIX: Summary grid — grouped into key metrics and weight section */
.summary-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 14px;
  margin-bottom: 18px;
}

/* FIX: Summary divider between groups */
.summary-divider {
  grid-column: 1 / -1;
  height: 1px;
  background: linear-gradient(90deg, transparent, rgba(154, 112, 90, 0.24), transparent);
  margin: 2px 0;
}

.summary-card {
  padding: 18px 20px;
  border-radius: var(--radius-lg);
  background: linear-gradient(180deg, #fffdf9, #f7ebe2);
  border: 1px solid rgba(154, 112, 90, 0.12);
  transition: transform 180ms ease, box-shadow 180ms ease;
}

.summary-card:hover {
  transform: translateY(-3px);
  box-shadow: var(--shadow-md);
}

.summary-card span {
  display: block;
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  margin-bottom: 8px;
}

/* FIX: summary-card value — tighter, less likely to overflow */
.summary-card strong {
  display: block;
  font-size: clamp(20px, 1.8vw, 28px);
  line-height: 1.2;
  font-weight: 800;
  color: var(--text-strong);
  word-break: break-word;
}

/* FIX: highlight key metric cards (reference, category) differently */
.summary-card.highlight {
  background: linear-gradient(135deg, rgba(122, 49, 54, 0.06), rgba(191, 141, 86, 0.08));
  border-color: rgba(122, 49, 54, 0.14);
}

.summary-card.highlight strong {
  color: var(--accent);
}

/* FIX: unit label for summary cards */
.summary-card .unit {
  display: inline;
  font-size: 14px;
  font-weight: 600;
  color: var(--muted);
  margin-left: 4px;
}

.message {
  margin-bottom: 18px;
  padding: 15px 18px;
  border-radius: 18px;
  background: var(--success-bg);
  border: 1px solid #bfe8d8;
  color: var(--success);
  box-shadow: var(--shadow-md);
}

.message.error,
.error {
  color: var(--danger);
}

.message.error {
  background: var(--danger-bg);
  border-color: #f0c7c7;
}

/* FIX: row-action buttons uniform sizing */
.row-action {
  min-height: 38px;
  padding: 7px 14px;
  font-size: 13px;
  white-space: nowrap;
}

/* FIX: delete row action */
.row-action.danger {
  min-height: 38px;
  padding: 7px 14px;
  font-size: 13px;
}

.empty-state td {
  color: var(--muted);
  text-align: center;
  padding: 28px 16px;
  font-style: italic;
}

/* FIX: action buttons in saved table — flex pair */
.saved-actions {
  display: flex;
  gap: 8px;
  align-items: center;
  justify-content: flex-end;
}

.login-panel,
.brand-panel,
.panel,
.spotlight-card,
.metric-card,
.subcard {
  animation: rise-in 420ms ease;
}

@keyframes rise-in {
  from {
    opacity: 0;
    transform: translateY(16px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes shimmer {
  0%,
  70%,
  100% {
    transform: translateX(-120%);
  }

  30% {
    transform: translateX(120%);
  }
}

@keyframes pulse-float {
  0%,
  100% {
    transform: translateY(0);
  }

  50% {
    transform: translateY(-12px);
  }
}

@media (max-width: 1180px) {
  .login-panel,
  .overview-grid {
    grid-template-columns: 1fr;
  }

  .brand-panel {
    flex-direction: column;
  }

  .brand-side {
    width: 100%;
  }
}

@media (max-width: 900px) {
  .shell {
    width: min(100vw - 18px, 1380px);
    margin-top: 12px;
  }

  .panel,
  .login-panel,
  .spotlight-card,
  .brand-panel {
    padding: 18px;
    border-radius: 24px;
  }

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

  /* On small screens, upload label loses its spanning since grid becomes 1-col */
  .grid-form .upload-label {
    grid-column: 1;
  }

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

  .panel-head,
  .table-headline {
    align-items: stretch;
    flex-direction: column;
  }

  .nav-ribbon {
    border-radius: 24px;
  }
}

@media (max-width: 640px) {
  h1 {
    font-size: 30px;
  }

  .login-panel {
    margin-top: 26px;
  }

  .auth-form,
  .login-showcase {
    padding: 20px;
  }

  .metric-card strong {
    font-size: 30px;
  }

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

  button,
  .button,
  .nav-pill {
    width: 100%;
  }

  .actions,
  .chip-row {
    width: 100%;
  }

  .saved-actions {
    flex-direction: column;
    gap: 6px;
  }

  .saved-actions .button,
  .saved-actions button {
    width: 100%;
  }
}
