/* ===== Reset & Base ===== */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --color-bg: #f8f9fa;
  --color-surface: #ffffff;
  --color-primary: #2563eb;
  --color-primary-hover: #1d4ed8;
  --color-text: #1e293b;
  --color-text-muted: #64748b;
  --color-border: #e2e8f0;
  --color-highlight: #fef3c7;
  --color-electronic: #3b82f6;
  --color-mechanical: #f97316;
  --color-tools: #8b5cf6;
  --color-fasteners: #10b981;
  --color-connectors: #ec4899;
  --radius: 8px;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
  --shadow-lg: 0 4px 12px rgba(0, 0, 0, 0.1);
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--color-bg);
  color: var(--color-text);
  line-height: 1.5;
  min-height: 100vh;
}

.hidden {
  display: none !important;
}

/* ===== Auth Overlay ===== */
#auth-overlay {
  position: fixed;
  inset: 0;
  background: var(--color-bg);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}

.auth-box {
  background: var(--color-surface);
  padding: 3rem 2.5rem;
  border-radius: 12px;
  box-shadow: var(--shadow-lg);
  text-align: center;
  max-width: 400px;
  width: 90%;
}

.auth-icon {
  font-size: 3rem;
  margin-bottom: 0.5rem;
}

.auth-box h1 {
  font-size: 1.5rem;
  margin-bottom: 0.5rem;
}

.auth-box p {
  color: var(--color-text-muted);
  margin-bottom: 1.5rem;
  font-size: 0.9rem;
}

#auth-form {
  display: flex;
  gap: 0.5rem;
}

#auth-form input {
  flex: 1;
  padding: 0.7rem 1rem;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  font-size: 1rem;
  outline: none;
  transition: border-color 0.2s;
}

#auth-form input:focus {
  border-color: var(--color-primary);
}

#auth-form button {
  padding: 0.7rem 1.5rem;
  background: var(--color-primary);
  color: white;
  border: none;
  border-radius: var(--radius);
  font-size: 1rem;
  cursor: pointer;
  transition: background 0.2s;
}

#auth-form button:hover {
  background: var(--color-primary-hover);
}

.error {
  color: #dc2626;
  font-size: 0.85rem;
  margin-top: 1rem;
}

/* ===== Header ===== */
header {
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
  padding: 1rem 2rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 100;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 1rem;
}

header h1 {
  font-size: 1.25rem;
  font-weight: 600;
}

.item-count {
  font-size: 0.8rem;
  color: var(--color-text-muted);
  background: var(--color-bg);
  padding: 0.2rem 0.6rem;
  border-radius: 20px;
}

.header-right {
  display: flex;
  gap: 0.5rem;
  align-items: center;
}

#edit-toggle, #settings-btn, #logout-btn {
  background: none;
  border: 1px solid var(--color-border);
  padding: 0.4rem 1rem;
  border-radius: var(--radius);
  color: var(--color-text-muted);
  cursor: pointer;
  font-size: 0.85rem;
  transition: all 0.2s;
}

#edit-toggle:hover, #settings-btn:hover {
  border-color: var(--color-primary);
  color: var(--color-primary);
}

#edit-toggle.active {
  background: var(--color-primary);
  color: white;
  border-color: var(--color-primary);
}

#logout-btn:hover {
  border-color: #dc2626;
  color: #dc2626;
}

/* ===== Search ===== */
.search-container {
  padding: 1.5rem 2rem 0.5rem;
  position: relative;
}

#search {
  width: 100%;
  padding: 0.9rem 1.2rem;
  font-size: 1.1rem;
  border: 2px solid var(--color-border);
  border-radius: var(--radius);
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
  background: var(--color-surface);
}

#search:focus {
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

.search-hint {
  display: block;
  font-size: 0.75rem;
  color: var(--color-text-muted);
  margin-top: 0.3rem;
  padding-left: 0.2rem;
}

/* ===== Filters ===== */
#filters {
  padding: 0.75rem 2rem;
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.filter-btn {
  padding: 0.35rem 0.9rem;
  border: 1px solid var(--color-border);
  border-radius: 20px;
  background: var(--color-surface);
  color: var(--color-text-muted);
  cursor: pointer;
  font-size: 0.8rem;
  transition: all 0.2s;
  white-space: nowrap;
}

.filter-btn:hover {
  border-color: var(--color-primary);
  color: var(--color-primary);
}

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

.filter-btn .count {
  font-size: 0.7rem;
  opacity: 0.7;
  margin-left: 0.3rem;
}

/* ===== Room Map ===== */
#room-map {
  padding: 1rem 2rem;
}

#room-map > h2 {
  font-size: 0.9rem;
  color: var(--color-text-muted);
  font-weight: 500;
  margin-bottom: 0.75rem;
}

.room-layout {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.walls-container {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
}

.wall {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 0.75rem;
  box-shadow: var(--shadow);
}

.wall h3 {
  font-size: 0.8rem;
  color: var(--color-text-muted);
  margin-bottom: 0.5rem;
  text-align: center;
}

.shelves {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.shelf-row {
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.shelf-label {
  font-size: 0.65rem;
  color: var(--color-text-muted);
  width: 2rem;
  text-align: right;
  flex-shrink: 0;
}

.shelf-boxes {
  display: flex;
  gap: 0.3rem;
  flex-wrap: wrap;
  flex: 1;
}

.box-tag {
  padding: 0.2rem 0.5rem;
  border-radius: 4px;
  font-size: 0.7rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
  border: 2px solid transparent;
  white-space: nowrap;
}

.box-tag:hover {
  transform: scale(1.05);
}

.box-tag.active {
  border-color: var(--color-text);
  box-shadow: var(--shadow);
}

.box-tag.highlight {
  animation: pulse 0.6s ease-in-out;
  border-color: var(--color-primary);
  box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.2);
}

.box-tag.dimmed {
  opacity: 0.3;
}

@keyframes pulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.08); }
}

/* Category colours for box tags */
.box-tag[data-category="Electronic"] { background: #dbeafe; color: #1e40af; }
.box-tag[data-category="Mechanical"] { background: #ffedd5; color: #c2410c; }
.box-tag[data-category="Tools"] { background: #ede9fe; color: #6d28d9; }
.box-tag[data-category="Fasteners"] { background: #d1fae5; color: #065f46; }
.box-tag[data-category="Connectors"] { background: #fce7f3; color: #9d174d; }

/* Screw shelves */
.screw-shelves-container {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
}

.screw-shelf {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 0.75rem;
  box-shadow: var(--shadow);
}

.screw-shelf h3 {
  font-size: 0.8rem;
  color: var(--color-text-muted);
  margin-bottom: 0.5rem;
  text-align: center;
}

.drawers {
  display: flex;
  gap: 0.25rem;
  flex-wrap: wrap;
}

.drawer-tag {
  padding: 0.15rem 0.35rem;
  border-radius: 3px;
  font-size: 0.6rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
  border: 2px solid transparent;
}

.drawer-tag:hover {
  transform: scale(1.1);
}

.drawer-tag.active {
  border-color: var(--color-text);
}

.drawer-tag.highlight {
  border-color: var(--color-primary);
  box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.2);
}

.drawer-tag.dimmed {
  opacity: 0.3;
}

/* ===== Results Table ===== */
#results {
  padding: 0.5rem 2rem 2rem;
}

#items-table {
  width: 100%;
  border-collapse: collapse;
  background: var(--color-surface);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
}

#items-table thead {
  background: var(--color-bg);
}

#items-table th {
  padding: 0.6rem 1rem;
  text-align: left;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--color-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.03em;
  border-bottom: 1px solid var(--color-border);
}

#items-table td {
  padding: 0.6rem 1rem;
  font-size: 0.85rem;
  border-bottom: 1px solid var(--color-border);
  vertical-align: top;
}

#items-table tbody tr {
  transition: background 0.15s;
}

#items-table tbody tr:hover {
  background: #f1f5f9;
}

#items-table tbody tr:last-child td {
  border-bottom: none;
}

#items-table tbody tr.highlight-row {
  background: var(--color-highlight);
}

.location-badge {
  display: inline-block;
  padding: 0.15rem 0.45rem;
  border-radius: 4px;
  font-size: 0.75rem;
  font-weight: 600;
  cursor: pointer;
}

.location-badge[data-category="Electronic"] { background: #dbeafe; color: #1e40af; }
.location-badge[data-category="Mechanical"] { background: #ffedd5; color: #c2410c; }
.location-badge[data-category="Tools"] { background: #ede9fe; color: #6d28d9; }
.location-badge[data-category="Fasteners"] { background: #d1fae5; color: #065f46; }
.location-badge[data-category="Connectors"] { background: #fce7f3; color: #9d174d; }

.category-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  margin-right: 0.4rem;
  vertical-align: middle;
}

.category-dot[data-category="Electronic"] { background: var(--color-electronic); }
.category-dot[data-category="Mechanical"] { background: var(--color-mechanical); }
.category-dot[data-category="Tools"] { background: var(--color-tools); }
.category-dot[data-category="Fasteners"] { background: var(--color-fasteners); }
.category-dot[data-category="Connectors"] { background: var(--color-connectors); }

#no-results {
  text-align: center;
  padding: 3rem;
  color: var(--color-text-muted);
  font-size: 1rem;
}

/* ===== Inline Editing ===== */
td.editable {
  cursor: pointer;
  position: relative;
}

td.editable:hover {
  background: #eff6ff;
  outline: 2px solid var(--color-primary);
  outline-offset: -2px;
  border-radius: 2px;
}

.inline-edit {
  width: 100%;
  padding: 0.3rem 0.4rem;
  border: 2px solid var(--color-primary);
  border-radius: 4px;
  font-size: 0.85rem;
  font-family: inherit;
  outline: none;
  background: white;
}

.delete-cell {
  width: 2rem;
  text-align: center;
}

.delete-btn {
  background: none;
  border: none;
  color: #94a3b8;
  cursor: pointer;
  font-size: 1rem;
  padding: 0.2rem 0.4rem;
  border-radius: 4px;
  transition: all 0.15s;
}

.delete-btn:hover {
  background: #fef2f2;
  color: #dc2626;
}

/* ===== Add Item Bar ===== */
#add-item-bar {
  padding: 0.5rem 2rem;
  display: flex;
  gap: 0.5rem;
  align-items: center;
  flex-wrap: wrap;
}

#add-item-bar input {
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  font-size: 0.85rem;
  outline: none;
  transition: border-color 0.2s;
}

#add-item-bar input:focus {
  border-color: var(--color-primary);
}

#add-item-bar input:nth-child(1) { flex: 2; min-width: 150px; }
#add-item-bar input:nth-child(2) { flex: 0.7; min-width: 80px; }
#add-item-bar input:nth-child(3) { flex: 0.5; min-width: 60px; }
#add-item-bar input:nth-child(4) { flex: 2; min-width: 120px; }

#add-item-btn {
  padding: 0.5rem 1rem;
  background: var(--color-primary);
  color: white;
  border: none;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 0.85rem;
  font-weight: 500;
  white-space: nowrap;
  transition: background 0.2s;
}

#add-item-btn:hover {
  background: var(--color-primary-hover);
}

/* ===== Save Bar ===== */
#save-bar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: var(--color-surface);
  border-top: 1px solid var(--color-border);
  box-shadow: 0 -4px 12px rgba(0, 0, 0, 0.1);
  padding: 0.75rem 2rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  z-index: 200;
  animation: slideUp 0.3s ease-out;
}

@keyframes slideUp {
  from { transform: translateY(100%); }
  to { transform: translateY(0); }
}

#save-bar #change-count {
  font-size: 0.85rem;
  color: var(--color-text-muted);
  font-weight: 500;
}

.save-actions {
  display: flex;
  gap: 0.5rem;
}

.btn-primary {
  padding: 0.5rem 1.2rem;
  background: var(--color-primary);
  color: white;
  border: none;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 0.85rem;
  font-weight: 500;
  transition: background 0.2s;
}

.btn-primary:hover { background: var(--color-primary-hover); }
.btn-primary:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-secondary {
  padding: 0.5rem 1.2rem;
  background: none;
  color: var(--color-text-muted);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 0.85rem;
  transition: all 0.2s;
}

.btn-secondary:hover {
  border-color: var(--color-text-muted);
  color: var(--color-text);
}

/* ===== Settings Modal ===== */
#settings-modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 500;
}

.modal-box {
  background: var(--color-surface);
  padding: 2rem;
  border-radius: 12px;
  box-shadow: var(--shadow-lg);
  max-width: 480px;
  width: 90%;
}

.modal-box h2 {
  font-size: 1.2rem;
  margin-bottom: 0.75rem;
}

.modal-box p {
  font-size: 0.85rem;
  color: var(--color-text-muted);
  margin-bottom: 0.75rem;
  line-height: 1.5;
}

.settings-help {
  font-size: 0.8rem !important;
  margin-bottom: 1rem !important;
}

.settings-help a {
  color: var(--color-primary);
  text-decoration: none;
}

.modal-box input {
  width: 100%;
  padding: 0.7rem 1rem;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  font-size: 0.9rem;
  font-family: monospace;
  outline: none;
  margin-bottom: 1rem;
}

.modal-box input:focus {
  border-color: var(--color-primary);
}

.modal-box code {
  background: var(--color-bg);
  padding: 0.15rem 0.4rem;
  border-radius: 3px;
  font-size: 0.8rem;
}

.modal-actions {
  display: flex;
  gap: 0.5rem;
  justify-content: flex-end;
}

/* ===== Toast ===== */
#toast {
  position: fixed;
  bottom: 5rem;
  left: 50%;
  transform: translateX(-50%);
  background: #065f46;
  color: white;
  padding: 0.6rem 1.5rem;
  border-radius: 20px;
  font-size: 0.85rem;
  font-weight: 500;
  box-shadow: var(--shadow-lg);
  z-index: 600;
  animation: fadeIn 0.3s ease-out;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateX(-50%) translateY(10px); }
  to { opacity: 1; transform: translateX(-50%) translateY(0); }
}

/* ===== Footer ===== */
footer {
  text-align: center;
  padding: 1.5rem 2rem;
  color: var(--color-text-muted);
  font-size: 0.8rem;
}

footer a {
  color: var(--color-primary);
  text-decoration: none;
}

footer a:hover {
  text-decoration: underline;
}

/* ===== Responsive ===== */
@media (max-width: 768px) {
  header {
    padding: 0.75rem 1rem;
  }

  header h1 {
    font-size: 1rem;
  }

  .search-container {
    padding: 1rem 1rem 0.5rem;
  }

  #search {
    font-size: 1rem;
    padding: 0.75rem 1rem;
  }

  #filters {
    padding: 0.5rem 1rem;
  }

  #room-map {
    padding: 0.75rem 1rem;
  }

  .walls-container {
    grid-template-columns: 1fr;
  }

  .screw-shelves-container {
    grid-template-columns: 1fr;
  }

  #results {
    padding: 0.5rem 1rem 2rem;
    overflow-x: auto;
  }

  /* Card layout on mobile */
  #items-table thead {
    display: none;
  }

  #items-table, #items-table tbody, #items-table tr, #items-table td {
    display: block;
  }

  #items-table tr {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    padding: 0.75rem;
    margin-bottom: 0.5rem;
    box-shadow: var(--shadow);
  }

  #items-table td {
    padding: 0.15rem 0;
    border: none;
  }

  #items-table td:first-child {
    font-weight: 600;
    font-size: 0.9rem;
  }

  #items-table td:nth-child(3) {
    display: none;
  }

  #items-table td::before {
    content: attr(data-label);
    font-size: 0.65rem;
    color: var(--color-text-muted);
    text-transform: uppercase;
    display: block;
    margin-top: 0.2rem;
  }

  #items-table td:first-child::before {
    display: none;
  }
}
