/* ---------------------------------
   Simple, mobile‑first skin
---------------------------------- */

/* CSS variables – tweak these to change the look */
:root {
  --primary: #2c3e50;
  --secondary: #34495e;
  --accent: #e67e22;
  --bg: #f5f8fa;
  --text: #333;
  --border: #ddd;
  --radius: 4px;
}

/* Reset */
*, *::before, *::after {
  box-sizing: border-box;
}
body, h1, h2, h3, h4, h5, h6, p,
ul, ol, li, dl, dt, dd,
figure, figcaption, blockquote,
pre, code, fieldset, legend {
  margin: 0;
  padding: 0;
}

body {
  font-family: system-ui, -apple-system, BlinkMacSystemFont,
               "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  line-height: 1.6;
  color: var(--text);
  background: var(--bg);
  min-width: 320px; /* prevent layout break on very narrow screens */
}

a {
  color: var(--accent);
  text-decoration: none;
}
a:hover { text-decoration: underline; }

/* Header ------------------------------------------------- */
.app-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: var(--primary);
  color: #fff;
  padding: 0.75rem 1rem;
}
.app-header h1 {
  font-size: 1.25rem;
}
.app-header nav a { color: #fff; }

/* Main --------------------------------------------------- */
main {
  padding: 1rem;
}

/* Filters ------------------------------------------------- */
.filters {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-bottom: 1rem;
}
.filters select,
.filters input[type="text"] {
  flex: 1 1 auto;
  min-width: 150px;
  padding: 0.5rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
#add-item-btn {
  background: var(--accent);
  color: #fff;
  border: none;
  padding: 0.55rem 1rem;
  border-radius: var(--radius);
  cursor: pointer;
}
#add-item-btn:hover { opacity: 0.9; }

/* Items grid ------------------------------------------- */
.grid {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
}
.item-card {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.5rem;
  width: calc(50% - 0.375rem); /* two columns on mobile */
  cursor: pointer;
  display: flex;
  align-items: center;
  transition: background-color .2s ease;
  position: relative;
}
/* Quantity‑based tint – subtle */
.item-card.qty-low {   /* qty between 1–4 */
  background-color: rgba(0,122,255,0.08);   /* light blue */
}
.item-card.qty-zero {  /* qty == 0 */
  background-color: rgba(255,0,0,0.08);     /* light red */
}

.item-card img {
  width: 48px; height: 48px;
  object-fit: cover;
  border-radius: var(--radius);
  margin-right: 0.75rem;
  background: #eee;
}
.item-details {
  flex: 1;
}
.item-name { font-weight: bold; }
.item-meta { color: #777; font-size: 0.85em; }

/* Two columns on tablets */
@media (min-width: 600px) {
  .item-card { width: calc(33.333% - 0.5rem); }
}

/* Modal ------------------------------------------------- */
.modal.hidden { display: none; }
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}
/* lock body scrolling when modal is open (see JS below) */
body.modal-open {
  overflow: hidden;
}
.modal-content {
  background: #fff;
  padding: 1rem;
  border-radius: var(--radius);
  width: 90%;
  max-width: 500px;
  position: relative;
  max-height: calc(100vh - 2rem); /* 2 rem = padding on both sides */
  overflow-y: auto;              /* ← this is what allows internal scrolling */
  -webkit-overflow-scrolling: touch;   /* smooth scrolling on iOS */
}
.close {
  position: absolute;
  top: 0.5rem; right: 0.75rem;
  background: none;
  border: none;
  font-size: 1.5rem;
  cursor: pointer;
}

/* Form ----------------------------------------------- */
label { display: block; margin-bottom: 0.5rem; }
input[type="text"],
input[type="number"],
input[type="date"],
select,
textarea {
  width: 100%;
  padding: 0.4rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
textarea { resize: vertical; min-height: 60px; }
.form-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
  margin-top: 1rem;
}
button[type="submit"],
#delete-item-btn {
  background: var(--accent);
  color: #fff;
  border: none;
  padding: 0.55rem 1rem;
  border-radius: var(--radius);
  cursor: pointer;
}
#delete-item-btn { background: #c0392b; }
button[type="submit"]:hover,
#delete-item-btn:hover { opacity: 0.9; }

/* Locations table ------------------------------------- */
table {
  width: 100%;
  border-collapse: collapse;
  margin-bottom: 1rem;
}
th, td {
  padding: 0.5rem;
  text-align: left;
  border-bottom: 1px solid var(--border);
}
input[type="text"]#new-location-name {
  flex: 1;
  padding: 0.4rem;
  margin-right: 0.5rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
button#add-location-btn {
  background: var(--accent);
  color: #fff;
  border: none;
  padding: 0.55rem 1rem;
  border-radius: var(--radius);
  cursor: pointer;
}
button#add-location-btn:hover { opacity: 0.9; }

/* Photo preview inside modal */
.photo-preview img {
  display: none;          /* hidden until we set a src */
  max-width: 100%;
  height: auto;
  border-radius: var(--radius);
}

/* -------------------------------------------------- */
/*  Decrement button on item cards                    */
/* -------------------------------------------------- */
.decrement-btn {
  background: #e67e22;          /* same accent colour as Add button */
  color: #fff;
  border: none;
  padding: .2rem .4rem;
  font-size: .8rem;
  cursor: pointer;
  margin-left: auto;            /* push it to the right of the card */
  border-radius: var(--radius);
  position: absolute;
  top: .4rem;                 /* distance from the top edge */
  right: .4rem;                /* distance from the right edge */
  z-index: 2;                  /* stay above other content */
}
.decrement-btn:hover { opacity: .9; }

/* ---------- Loading overlay ---------- */
#loading-overlay {
  position: fixed;
  inset: 0;                     /* top right bottom left = 0 */
  background: rgba(0, 0, 0, .4);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 2000;                /* above modal (z‑index 1000) */
}
#loading-overlay.hidden { display:none; }

.spinner {
  width: 50px; height: 50px;
  border: 5px solid #f3f3f3;
  border-top: 5px solid var(--accent);
  border-radius: 50%;
  animation: spin .8s linear infinite;
}
@keyframes spin { to{transform:rotate(360deg);} }

.multi-select{ position:relative; }
.combo-menu{
  position:absolute;
  top:100%; left:0;
  right:0;
  max-height:200px;
  overflow-y:auto;
  background:#fff;
  border:1px solid var(--border);
  z-index:5;
}
.combo-menu label{ display:block; padding:.3rem .5rem; }
.combo-menu input[type=checkbox]{ margin-right:.4rem; }

.combo-menu.hidden { display: none; }

/* 1️⃣ Make the combo a flex container */
#filter-category-combo {
    display: flex;
    align-items: center;          /* vertically centre the two items   */
}

/* 2️⃣ Push the arrow to the far right of the wrapper */
#filter-category-combo .dropdown-arrow {
    margin-left: auto;            /* takes all remaining space        */
    cursor: pointer;              /* keep it clickable                */
}

/* 3️⃣ Give the text input a little breathing room on the right
   so that the arrow doesn’t overlap the placeholder text. */
#filter-category-combo input[type="text"] {
    padding-right: 1.5rem;        /* adjust as needed – 1.5rem ≈ 24px */
}

/* 1️⃣ Keep flex‑wrap on the main container */
.filters {
    display: flex;
    flex-wrap: wrap;            /* allow wrapping for the rest   */
    gap: 0.5rem;
}

/* --------------------------------------------------
   1️⃣ Allow .filter-group to take up remaining space
   -------------------------------------------------- */
.filter-group {
    display:flex;
    gap:.5rem;
    flex:1 1 auto;          /* <‑‑ key change – lets it grow           */
}

/* --------------------------------------------------
   2️⃣ Let the wrapper itself also grow (optional)
   -------------------------------------------------- */
#filter-category-combo {
    flex:1 1 auto;           /* optional but keeps the combo in sync */
}

input[readonly] {
  background-color: var(--border);   /* light grey – same as border colour */
  color: #666;                       /* dark‑grey text for contrast */
  cursor: not-allowed;               /* visual cue that it’s not editable */
}
/* ------------------------------------------------------------------
   1️⃣ Camera modal – small screen tweaks
------------------------------------------------------------------- */
@media (max-width: 480px) {          /* tweak breakpoint as needed */

  /* 1. Keep the modal centered but limit its height to 90% of viewport */
  #camera-modal .modal-content {
    width: 95%;                      /* a bit smaller than full screen */
    max-height: 90vh;                /* 90 % of the visible window */
    overflow-y: auto;                /* allow scrolling inside if absolutely necessary */
    padding: 0.5rem;                 /* some breathing room around edges */
    box-sizing: border-box;
  }

  /* 2. Video should fill the modal’s width but never exceed its height minus controls */
  #camera-modal video {
    width: 100%;                     /* full width of modal-content */
    max-height: calc(90vh - 120px);   /* leave space for buttons + padding */
    object-fit: cover;               /* keep aspect ratio, crop if needed */
    border-radius: var(--radius);
  }

  /* 3. Buttons stack under the video (flex column) */
  #camera-modal .modal-content > div {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.5rem;                     /* space between video and button row */
  }

  /* 4. Button row – make them stretch to full width so they’re easy to tap */
  #camera-modal .modal-content > div > div {
    display: flex;
    justify-content: space-between;
    width: 100%;
    padding: 0 0.5rem;
  }

  /* 5. Style the Cancel / Capture buttons for touch‑friendly size */
  #cancel-camera-upc,
  #capture-photo,
  #cancel-camera-photo {
    font-size: 1.2rem;               /* larger text */
    padding: 0.6rem 1rem;            /* bigger tap area */
    flex: 1;                         /* equal width in the button row */
  }
}
@media (max-width: 480px) {
  #camera-modal {
    background: rgba(0,0,0,.6);      /* keep dim background */
  }
}

/* Small, gray “used‑by” date inside the card meta */
.used-by-date {
  font-size: .85rem;
  color: #777;          /* same as other meta text */
  margin-left: .5rem;   /* space from the rest of the meta line */
}

/* Pagination + page‑size selector spacing */
#pagination .page-size-select-wrapper {
  display: inline-block;
  vertical-align: middle;
  margin-left: 1rem;   /* space from pagination buttons */
}

/* ------------------------------------------------------------------
   Pagination layout – selector to the right of the page controls
------------------------------------------------------------------- */
#pagination {
  display: flex;                /* lay out children horizontally */
  align-items: center;          /* vertically centre everything */
  gap: 0.5rem;                  /* space between buttons and text */
}

/* Push the selector block to the far right */
#pagination .page-size-select-wrapper {
  margin-left: auto;            /* pushes it as far right as possible */
}

.page-input {
  width: 3rem;          /* matches inline style above */
  text-align: center;
}
