/* Base reset and CSS variables */
html,
body {
  margin: 0;
  padding: 0;
  overflow-x: hidden;
}

:root {
  --header-height: 72px;
  --sidebar-width: 16rem;
}

/* Fixed header bar */
header {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: var(--header-height);
  background: #2f855a;
  z-index: 1000;
  display: flex;
  align-items: center;
  padding: 0 16px;
}

#appSection {
  padding-top: var(--header-height);
}

/* Fixed sidebar nav */
aside {
  position: fixed;
  top: var(--header-height);
  left: 0;
  width: var(--sidebar-width);
  height: calc(100vh - var(--header-height));
  overflow-y: auto;
  background: #ffffff;
  padding: 1.5rem;
  box-shadow: 2px 0 6px rgba(0, 0, 0, 0.1);
  z-index: 900;
}

main {
  margin-left: var(--sidebar-width);
  padding-bottom: 140px;
}

/* Table overflow - allows absolute-positioned dropdowns to escape table cells */
table,
thead,
tbody,
tr,
td,
th {
  overflow: visible;
}

/* Options dropdown positioning */
.options-cell {
  position: relative;
}

.options-menu {
  position: absolute;
  top: 50%;
  right: 100%;
  transform: translateY(-50%);
  margin-right: 8px;
  min-width: 140px;
  background: #ffffff;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  box-shadow: 0 12px 24px rgba(0, 0, 0, 0.15);
  z-index: 9999;
}

.options-menu.drop-up {
  top: auto;
  bottom: 50%;
}

/* Mobile layout - sidebar slides in, main goes full width */
@media (max-width: 640px) {
  aside {
    top: 0;
    height: 100vh;
    width: 75vw;
    transform: translateX(-100%);
    transition: transform 0.3s ease;
    z-index: 1100;
  }

  aside.show {
    transform: translateX(0);
  }

  main {
    margin-left: 0;
    margin-top: 0;
    padding-bottom: 200px;
    padding-right: 0;
    padding-left: 0;
  }

  .inventory-table-wrap {
    margin: 0 -8px;
  }

  main .p-6 {
    padding: 8px;
  }

  #inventoryTable th,
  #inventoryTable td {
    padding: 6px 8px;
    font-size: 14px;
  }

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

  #inventoryTable th:nth-child(2),
  #inventoryTable td:nth-child(2) {
    width: 20%;
    font-size: 14px;
  }

  #inventoryTable th:nth-child(3),
  #inventoryTable td:nth-child(3) {
    width: 20%;
  }

  #inventoryTable th:nth-child(4),
  #inventoryTable td:nth-child(4) {
    width: 20%;
  }

  /* MOBILE HEADER GRID */
  header {
    display: grid !important;
    grid-template-columns: 40px 1fr;
    grid-template-rows: auto auto;
    align-items: center;
    gap: 8px;
    padding: 10px;
    width: 100%;
    box-sizing: border-box;
    height: auto;
    position: sticky;
    top: 0;
  }

  #menuToggle {
    grid-column: 1;
    grid-row: 1;
    justify-self: start;
  }

  header h1 {
    grid-column: 2;
    grid-row: 1;
    font-size: 18px;
    text-align: center;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  header button {
    grid-column: 1 / span 2;
    grid-row: 2;
    width: 100%;
    padding: 10px;
    font-size: 16px;
    border-radius: 0;
    margin: 0;
  }

  #appSection {
    padding-top: 0;
  }
}

/* Desktop layout */
@media (min-width: 641px) {
  header {
    position: fixed;
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: var(--header-height);
    padding: 0 24px;
  }

  header h1 {
    font-size: 26px;
    text-align: left;
    white-space: nowrap;
  }

  #addItemBtn {
    width: auto;
    padding: 10px 20px;
    font-size: 16px;
    border-radius: 8px;
    margin: 0;
  }
}

/* Report section shared styles */
.report-value {
  min-width: 90px;
  text-align: right;
  font-weight: 600;
}

.report-row,
#reportsSection .flex.justify-between {
  border-bottom: 2px solid #d1d5db;
}

.reports-flat > div > div:nth-child(even),
.page-break div:nth-child(even) {
  background: #f9fafb;
}

.report-category-title {
  font-weight: 700;
  color: #111827;
}

/* Print styles - removes chrome, resets layout for report printing */
@media print {
  #appSection {
    padding-top: 0 !important;
  }

  main {
    margin-left: 0 !important;
    margin: 0 !important;
    padding: 0 !important;
  }

  #reportsSection,
  #reportsContainer {
    max-width: none !important;
    width: 100% !important;
    margin: 0 !important;
    padding: 0 !important;
  }

  body {
    background: #fff !important;
  }

  @page {
    size: auto;
    margin: 10mm;
  }
}

/* Hide nav/sidebar/controls during print */
@media print {
  header,
  aside,
  nav,
  .sidebar,
  .top-bar,
  .app-header,
  .app-toolbar,
  .print-controls,
  .report-controls,
  .reports-toolbar,
  #addItemBtn,
  #menuToggle,
  #sidebarClose,
  #printReportsBtn,
  #reportFlatToggle,
  label[for="reportFlatToggle"] {
    display: none !important;
  }
}

html,
body {
  width: 100%;
  margin: 0;
}

#reportsSection,
#reportsContainer,
.page-break,
.report-block {
  width: 100%;
  max-width: none;
  margin: 0;
  padding: 0;
}

/* Report row borders for print clarity */
#reportsSection .flex.justify-between {
  padding: 6px 0;
  border-bottom: 2px solid #4b5563;
}

.flex.justify-between span:first-child {
  color: #374151;
}

.report-value {
  font-weight: 700;
  color: #000;
}

.report-category-title {
  color: #000;
}

/* Prevents report cards from splitting across page breaks when printing */
.report-block,
.page-break {
  break-inside: avoid;
  page-break-inside: avoid;
  margin-bottom: 12px;
}

.report-head,
.page-break h3 {
  break-after: avoid;
  page-break-after: avoid;
}

/* Purchase order print styles */
@media print {
  header,
  aside,
  #menuToggle,
  #addItemBtn {
    display: none !important;
  }

  body {
    background: #fff;
  }

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

  th,
  td {
    border: 1px solid #000;
    padding: 6px;
  }
}

/* Forecast table - alternating row shading */
#forecastSection #forecastTable tr:nth-child(even) {
  background-color: #f9fafb;
}