* {
  box-sizing: border-box;
}

:root {
  --bg: #f4f6f8;
  --surface: #ffffff;
  --text: #1f2937;
  --muted: #6b7280;
  --border: #d1d5db;
  --primary: #1f2937;
  --primary-hover: #111827;
  --danger: #b91c1c;
  --danger-light: #fee2e2;
  --success: #166534;
  --shadow: 0 8px 24px rgba(0, 0, 0, 0.08);
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  font-family: Arial, Helvetica, sans-serif;
  background: var(--bg);
  color: var(--text);
}

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

button {
  cursor: pointer;
}

button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}


/* =========================
   HEADER
========================= */

.topbar {
  background: #111827;
  color: white;
  padding: 20px 28px;

  display: flex;
  justify-content: space-between;
  align-items: center;

  gap: 20px;

  box-shadow: var(--shadow);
}

.brand h1 {
  margin: 0;
  font-size: 2rem;
  letter-spacing: 3px;
}

.brand p {
  margin: 5px 0 0;
  color: #d1d5db;
}

.big-button {
  font-size: 1rem;
  padding: 12px 18px;
}


/* =========================
   MAIN CONTAINER
========================= */

.container {
  width: min(1200px, calc(100% - 30px));
  margin: 0 auto;
  padding: 24px 0 50px;
}


/* =========================
   CARDS
========================= */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: var(--shadow);
}


/* =========================
   BUTTONS
========================= */

button {
  border: 1px solid var(--border);
  background: white;
  color: var(--text);

  border-radius: 10px;

  padding: 10px 14px;

  transition:
    background 0.2s ease,
    transform 0.1s ease,
    border-color 0.2s ease;
}

button:hover {
  background: #f3f4f6;
}

button:active {
  transform: scale(0.98);
}

.primary {
  background: var(--primary);
  color: white;
  border-color: var(--primary);
}

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

.danger {
  color: var(--danger);
}

button.danger:hover {
  background: var(--danger-light);
  border-color: #fecaca;
}


/* =========================
   SEARCH / FILTER TOOLBAR
========================= */

.toolbar {
  padding: 14px;

  display: grid;

  grid-template-columns:
    minmax(250px, 2fr)
    minmax(160px, 1fr)
    minmax(160px, 1fr)
    auto
    auto
    auto;

  gap: 10px;

  align-items: center;
}

.toolbar input,
.toolbar select {
  width: 100%;
}


/* =========================
   INPUTS
========================= */

input,
select,
textarea {
  border: 1px solid var(--border);
  border-radius: 10px;

  padding: 11px 12px;

  background: white;
  color: var(--text);

  outline: none;

  transition:
    border-color 0.2s ease,
    box-shadow 0.2s ease;
}

input:focus,
select:focus,
textarea:focus {
  border-color: #6b7280;
  box-shadow: 0 0 0 3px rgba(107, 114, 128, 0.15);
}

textarea {
  resize: vertical;
}


/* =========================
   STATS
========================= */

.stats {
  display: grid;

  grid-template-columns: repeat(4, 1fr);

  gap: 14px;

  margin: 18px 0;
}

.stat {
  padding: 20px;
}

.stat span {
  display: block;

  font-size: 1.8rem;
  font-weight: bold;

  margin-bottom: 4px;
}

.stat small {
  color: var(--muted);
}


/* =========================
   BACKUP AREA
========================= */

.backup-toolbar {
  margin-bottom: 18px;

  padding: 16px 18px;

  display: flex;
  justify-content: space-between;
  align-items: center;

  gap: 16px;
}

.backup-toolbar strong {
  font-size: 1rem;
}

.backup-toolbar p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 0.9rem;
}

.backup-buttons {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}


/* =========================
   INVENTORY GRID
========================= */

.inventory-grid {
  display: grid;

  grid-template-columns:
    repeat(auto-fill, minmax(285px, 1fr));

  gap: 18px;
}


/* =========================
   ITEM CARD
========================= */

.item-card {
  overflow: hidden;

  display: flex;
  flex-direction: column;

  min-height: 100%;
}

.item-image-wrap {
  height: 220px;

  position: relative;

  background: #e5e7eb;

  overflow: hidden;
}

.item-image {
  width: 100%;
  height: 100%;

  object-fit: cover;

  display: none;
}

.image-placeholder {
  height: 100%;

  display: flex;
  flex-direction: column;

  justify-content: center;
  align-items: center;

  color: var(--muted);
}

.image-placeholder span {
  font-size: 2rem;
}

.image-placeholder p {
  margin: 6px 0 0;
}

.item-body {
  padding: 16px;

  display: flex;
  flex-direction: column;

  flex: 1;
}

.item-heading {
  display: flex;

  justify-content: space-between;
  align-items: flex-start;

  gap: 10px;
}

.item-heading h3 {
  margin: 0;

  font-size: 1.15rem;
}

.item-qty {
  color: var(--muted);

  font-size: 0.9rem;

  white-space: nowrap;
}

.badges {
  display: flex;
  flex-wrap: wrap;

  gap: 6px;

  margin: 10px 0;
}

.badge {
  display: inline-block;

  padding: 5px 9px;

  background: #f3f4f6;

  border: 1px solid #e5e7eb;

  border-radius: 999px;

  font-size: 0.8rem;
}

.item-location {
  margin: 4px 0;

  font-size: 0.9rem;

  color: var(--muted);
}

.item-notes {
  color: var(--muted);

  font-size: 0.9rem;

  white-space: pre-wrap;

  overflow-wrap: anywhere;
}

.item-footer {
  margin-top: auto;
  padding-top: 14px;

  display: flex;

  justify-content: space-between;
  align-items: center;

  gap: 10px;
}

.item-value {
  font-size: 1.05rem;
}

.item-actions {
  display: flex;

  gap: 6px;
}


/* =========================
   EMPTY STATE
========================= */

.empty {
  text-align: center;

  padding: 50px 20px;

  color: var(--muted);
}

.empty h2 {
  color: var(--text);

  margin-top: 0;
}


/* =========================
   DIALOG WINDOWS
========================= */

dialog {
  width: min(700px, calc(100% - 24px));

  border: none;
  border-radius: 18px;

  padding: 0;

  background: white;

  color: var(--text);

  box-shadow:
    0 24px 70px rgba(0, 0, 0, 0.28);

  max-height: 92vh;
}

dialog::backdrop {
  background: rgba(0, 0, 0, 0.6);
}

.dialog-form {
  padding: 22px;

  max-height: 92vh;

  overflow-y: auto;
}

.dialog-header {
  display: flex;

  justify-content: space-between;
  align-items: flex-start;

  gap: 14px;

  margin-bottom: 18px;
}

.dialog-header h2 {
  margin: 0;
}

.dialog-header p {
  margin: 5px 0 0;

  color: var(--muted);
}

.icon-btn {
  background: transparent;
  border: none;

  font-size: 1.2rem;

  padding: 5px 8px;
}


/* =========================
   FORM LAYOUT
========================= */

.dialog-form label {
  display: block;

  margin-bottom: 15px;

  font-weight: bold;
}

.dialog-form label input,
.dialog-form label select,
.dialog-form label textarea {
  display: block;

  width: 100%;

  margin-top: 6px;

  font-weight: normal;
}

.two-col {
  display: grid;

  grid-template-columns: 1fr 1fr;

  gap: 12px;
}

.help-text {
  margin-top: -5px;

  font-size: 0.85rem;

  color: var(--muted);
}


/* =========================
   MONEY INPUT
========================= */

.money-input {
  display: flex;

  align-items: center;

  margin-top: 6px;

  border: 1px solid var(--border);

  border-radius: 10px;

  overflow: hidden;

  background: white;
}

.money-input span {
  padding-left: 12px;

  color: var(--muted);
}

.money-input input {
  border: none;

  box-shadow: none;

  margin: 0;
}

.money-input input:focus {
  box-shadow: none;
}


/* =========================
   PHOTO PREVIEW
========================= */

.photo-preview-wrap {
  margin-top: 10px;

  padding: 12px;

  border: 1px solid var(--border);

  border-radius: 12px;

  background: #f9fafb;
}

.photo-preview-wrap img {
  display: block;

  width: 100%;

  max-height: 320px;

  object-fit: contain;

  border-radius: 10px;

  margin-bottom: 10px;
}


/* =========================
   CATEGORY / AREA LISTS
========================= */

.inline-add {
  display: grid;

  grid-template-columns: 1fr auto;

  gap: 8px;

  margin-bottom: 15px;
}

.manage-list {
  display: grid;

  gap: 8px;

  max-height: 350px;

  overflow-y: auto;

  padding-right: 2px;
}

.manage-row {
  display: grid;

  grid-template-columns: 1fr auto auto;

  gap: 8px;

  align-items: center;

  padding: 8px;

  border: 1px solid var(--border);

  border-radius: 10px;
}

.manage-row input {
  width: 100%;
}


/* =========================
   LOCATION SECTION
========================= */

.location-example {
  margin-top: 16px;

  padding: 12px;

  background: #f3f4f6;

  border-radius: 10px;
}

.location-example p {
  margin: 4px 0 0;

  color: var(--muted);
}


/* =========================
   DIALOG ACTIONS
========================= */

.dialog-actions {
  display: flex;

  justify-content: flex-end;

  gap: 10px;

  margin-top: 20px;
}


/* =========================
   UTILITY
========================= */

.hidden {
  display: none !important;
}


/* =========================
   TABLET
========================= */

@media (max-width: 950px) {

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

  .toolbar #searchInput {
    grid-column: 1 / -1;
  }

}


/* =========================
   MOBILE
========================= */

@media (max-width: 650px) {

  .topbar {
    flex-direction: column;

    align-items: stretch;
  }

  .brand {
    text-align: center;
  }

  .big-button {
    width: 100%;
  }


  .container {
    width: min(100% - 20px, 1200px);

    padding-top: 14px;
  }


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

  .toolbar #searchInput {
    grid-column: auto;
  }


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


  .backup-toolbar {
    flex-direction: column;

    align-items: stretch;
  }

  .backup-buttons {
    width: 100%;
  }

  .backup-buttons button {
    flex: 1;
  }


  .two-col {
    grid-template-columns: 1fr;
  }


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


  .item-image-wrap {
    height: 250px;
  }


  .manage-row {
    grid-template-columns: 1fr;
  }


  .manage-row button {
    width: 100%;
  }


  .dialog-actions {
    flex-direction: column-reverse;
  }

  .dialog-actions button {
    width: 100%;
  }

}


/* =========================
   SMALL PHONE
========================= */

@media (max-width: 400px) {

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

  .brand h1 {
    font-size: 1.6rem;
  }

}
