/* Base styles and layout for Inventrix. Mobile-first. */

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  height: 100%;
}

body {
  margin: 0;
  min-height: 100%;
  background: var(--color-bg);
  color: var(--color-text);
  font-family: var(--font-body);
  font-size: 1rem;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

img {
  max-width: 100%;
  display: block;
}

h1 {
  font-size: 1.4rem;
  margin: 0 0 var(--space-4);
}

h2 {
  font-size: 1.15rem;
  margin: var(--space-4) 0 var(--space-2);
}

p {
  margin: 0 0 var(--space-3);
}

a {
  color: var(--color-primary);
}

:focus-visible {
  outline: 3px solid var(--color-focus);
  outline-offset: 2px;
}

.app-shell {
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
}

/* Boot status message (removed once the app is running, see boot.js). */
#boot-status {
  padding: var(--space-6) var(--space-4);
  text-align: center;
  color: var(--color-text-muted);
}

#boot-status.boot-error {
  color: var(--color-danger);
}

.app-main {
  flex: 1;
  width: 100%;
  max-width: 44rem;
  margin: 0 auto;
  padding: var(--space-4) var(--space-4) calc(var(--space-6) + 64px);
}

/* Bottom nav on mobile, side nav on desktop. */
.app-nav {
  position: fixed;
  inset: auto 0 0 0;
  display: flex;
  justify-content: space-around;
  background: var(--color-surface);
  border-top: 1px solid var(--color-border);
  padding: var(--space-1) var(--space-2);
  z-index: 20;
}

.app-nav a {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  min-width: var(--tap-target);
  min-height: var(--tap-target);
  justify-content: center;
  padding: var(--space-1) var(--space-2);
  border-radius: var(--radius-1);
  text-decoration: none;
  color: var(--color-text-muted);
  font-size: 0.72rem;
}

.app-nav a.active {
  color: var(--color-primary);
  background: var(--color-primary-soft);
}

.app-nav svg {
  width: 22px;
  height: 22px;
}

@media (min-width: 900px) {
  .app-shell {
    flex-direction: row;
  }

  .app-nav {
    position: sticky;
    top: 0;
    inset: auto;
    flex-direction: column;
    justify-content: flex-start;
    gap: var(--space-2);
    height: 100dvh;
    width: 12rem;
    border-top: none;
    border-right: 1px solid var(--color-border);
    padding: var(--space-4) var(--space-2);
  }

  .app-nav a {
    flex-direction: row;
    justify-content: flex-start;
    gap: var(--space-2);
    width: 100%;
    font-size: 0.95rem;
  }

  /* Desktop: content may use the space; individual fields stay at a
   * comfortable reading width. */
  .app-main {
    max-width: 74rem;
    padding: var(--space-5) var(--space-6) var(--space-6);
  }

  .form-field {
    max-width: 42rem;
  }

  h1 {
    font-size: 1.6rem;
  }

  /* Home screen: the three main actions as tiles side by side. */
  .home-actions {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: var(--space-3);
    margin-bottom: var(--space-2);
  }

  .home-actions .btn-big {
    margin-bottom: 0;
    min-height: 72px;
  }

  /* Item list: a grid of cards instead of a single column. */
  .item-cards {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(20rem, 1fr));
    gap: var(--space-3);
    align-items: stretch;
  }

  .item-cards .card {
    margin: 0;
    height: 100%;
  }

  /* Item detail: photo and gallery on the left (stay in view while
   * scrolling), data on the right. */
  .detail-layout {
    display: grid;
    grid-template-columns: minmax(18rem, 26rem) 1fr;
    gap: var(--space-6);
    align-items: start;
  }

  .detail-media {
    position: sticky;
    top: var(--space-5);
  }
}

/* Forms */
.form-field {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
  margin-bottom: var(--space-4);
}

.form-field label {
  font-weight: 600;
  font-size: 0.9rem;
}

input[type="text"],
input[type="number"],
input[type="search"],
select,
textarea {
  font: inherit;
  color: var(--color-text);
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-1);
  padding: var(--space-2) var(--space-3);
  min-height: var(--tap-target);
  width: 100%;
}

textarea {
  min-height: 5.5rem;
  resize: vertical;
}

/* Masked text field (e.g. the sync key): shows dots without actually
   being type="password", so the browser's password manager doesn't pick
   it up as a login. Works in Chromium/WebKit (the PWA target browsers);
   in Firefox the value shows as plain text. */
.masked-input {
  -webkit-text-security: disc;
}

.field-hint {
  color: var(--color-text-muted);
  font-size: 0.82rem;
}

.field-error {
  color: var(--color-danger);
  font-size: 0.85rem;
}

.field-warn {
  color: var(--color-warning-text);
  background: var(--color-warning-bg);
  border-radius: var(--radius-1);
  padding: 0 var(--space-2);
  font-size: 0.85rem;
  width: fit-content;
}

/* Buttons */
.btn {
  font: inherit;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  min-height: var(--tap-target);
  min-width: var(--tap-target);
  padding: var(--space-2) var(--space-4);
  border-radius: var(--radius-1);
  border: 1px solid var(--color-border);
  background: var(--color-surface);
  color: var(--color-text);
  cursor: pointer;
  text-decoration: none;
}

.btn:hover {
  background: var(--color-surface-alt);
}

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

.btn-primary:hover {
  filter: brightness(1.06);
  background: var(--color-primary);
}

.btn-danger {
  background: var(--color-danger);
  border-color: var(--color-danger);
  color: var(--color-danger-contrast);
}

.btn-danger:hover {
  filter: brightness(1.06);
  background: var(--color-danger);
}

.btn-big {
  width: 100%;
  font-size: 1.1rem;
  min-height: 56px;
  margin-bottom: var(--space-3);
}

.btn-row {
  display: flex;
  gap: var(--space-3);
  flex-wrap: wrap;
  margin-top: var(--space-4);
}

.btn-row-center {
  justify-content: center;
}

/* Home screen, bulk actions: full-width stacked on narrow screens
 * (reachable with one hand); a plain row on wider screens. */
@media (max-width: 640px) {
  .home-bulk-actions {
    flex-direction: column;
  }

  .home-bulk-actions .btn {
    width: 100%;
    min-height: 48px;
    justify-content: center;
  }
}

/* Action bar: sticks to the bottom of the screen so Save etc. are always
   reachable without scrolling (above the bottom nav). */
.action-bar {
  position: sticky;
  bottom: calc(64px + env(safe-area-inset-bottom, 0px) + var(--space-2));
  z-index: 15;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-2);
  box-shadow: var(--shadow-1);
  padding: var(--space-2) var(--space-3);
}

@media (min-width: 900px) {
  .action-bar {
    bottom: var(--space-2);
  }
}

/* Compact field within a filter bar (no bottom margin). */
.form-field-flat {
  margin-bottom: 0;
}

/* Photo as a clickable button (full-screen view). */
.photo-button {
  padding: 0;
  border: none;
  width: 100%;
  background: none;
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* Cards and lists */
.card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-2);
  padding: var(--space-4);
  margin-bottom: var(--space-3);
  box-shadow: var(--shadow-1);
}

.empty-state {
  text-align: center;
  padding: var(--space-6) var(--space-4);
  color: var(--color-text-muted);
}

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

.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  margin-bottom: var(--space-4);
}

.page-header h1 {
  margin: 0;
  min-width: 0;
  overflow-wrap: anywhere;
}

/* Detail screen: action icons on their own line below the code, so the
   (sometimes long) code stays fully readable. */
.page-header:has(.detail-header-actions) {
  flex-wrap: wrap;
}

.muted {
  color: var(--color-text-muted);
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}
