:root {
  --bg: #0f1115;
  --card: #1a1d24;
  --border: #2a2e37;
  --text: #f2f3f5;
  --muted: #9ca3af;
  --accent: #22c55e;
  --danger: #ef4444;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
}

.topbar {
  padding: env(safe-area-inset-top, 16px) 16px 12px;
  background: var(--card);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: baseline;
  justify-content: space-between;
}

.topbar h1 {
  margin: 0;
  font-size: 1.25rem;
}

.app-version {
  font-size: 0.7rem;
  color: var(--muted);
  font-family: monospace;
}

main {
  padding: 16px;
  max-width: 720px;
  margin: 0 auto;
  padding-bottom: 96px;
}

.view[hidden] { display: none; }

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  margin-bottom: 20px;
}

.photo-strip {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 2px;
}

.photo-thumb-wrap {
  position: relative;
  width: 84px;
  height: 84px;
  flex-shrink: 0;
  border-radius: 10px;
  overflow: hidden;
  background: #12141a;
}

.photo-thumb-wrap img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.photo-remove-btn {
  position: absolute;
  top: 2px;
  right: 2px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: none;
  background: rgba(0, 0, 0, 0.6);
  color: #fff;
  font-size: 0.8rem;
  line-height: 1;
  cursor: pointer;
}

.photo-add-tile {
  width: 84px;
  height: 84px;
  flex-shrink: 0;
  border: 2px dashed var(--border);
  border-radius: 10px;
  background: transparent;
  color: var(--muted);
  font-size: 1.6rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.camera-modal {
  position: fixed;
  inset: 0;
  background: #000;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
}

.camera-video {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.camera-close {
  position: absolute;
  top: calc(16px + env(safe-area-inset-top, 0px));
  right: 16px;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: none;
  background: rgba(0, 0, 0, 0.5);
  color: #fff;
  font-size: 1.1rem;
  cursor: pointer;
}

.camera-shutter {
  position: absolute;
  bottom: calc(28px + env(safe-area-inset-bottom, 0px));
  left: 50%;
  transform: translateX(-50%);
  width: 72px;
  height: 72px;
  border-radius: 50%;
  border: 4px solid #fff;
  background: rgba(255, 255, 255, 0.25);
  cursor: pointer;
}

.camera-shutter:active { background: rgba(255, 255, 255, 0.5); }

.form-title {
  margin: 0 0 12px;
  font-size: 1.1rem;
}

.form-actions {
  display: flex;
  gap: 10px;
  margin-top: 4px;
}

.form-actions .save-btn { flex: 1; margin-top: 0; }

.cancel-btn {
  flex: 1;
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 10px;
  padding: 13px;
  font-size: 1rem;
  cursor: pointer;
}

.delete-item-btn {
  background: transparent;
  border: 1px solid var(--danger);
  color: var(--danger);
  border-radius: 10px;
  padding: 12px;
  font-size: 0.95rem;
  cursor: pointer;
  margin-top: 4px;
}

.fab {
  position: fixed;
  right: 20px;
  bottom: calc(20px + env(safe-area-inset-bottom, 0px));
  width: 60px;
  height: 60px;
  border-radius: 50%;
  border: none;
  background: var(--accent);
  color: #08210f;
  font-size: 1.6rem;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.4);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 20;
}

.fab:active { transform: scale(0.95); }

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.field label {
  font-size: 0.85rem;
  color: var(--muted);
}

.opt { font-weight: 400; opacity: 0.7; }

input[type="text"],
input[type="number"],
textarea {
  background: #12141a;
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 1rem;
  width: 100%;
}

textarea { resize: vertical; font-family: inherit; }

.input-with-clear {
  position: relative;
  display: flex;
  align-items: center;
}

.input-with-clear input { padding-right: 36px; }

.clear-btn {
  position: absolute;
  right: 6px;
  background: transparent;
  border: none;
  color: var(--muted);
  font-size: 1rem;
  cursor: pointer;
  padding: 6px;
  line-height: 1;
}

.clear-btn:active { color: var(--danger); }

.save-btn {
  background: var(--accent);
  color: #08210f;
  border: none;
  border-radius: 10px;
  padding: 13px;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  margin-top: 4px;
}

.save-btn:active { opacity: 0.85; }

.list-header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 12px;
}

.list-header h2 { margin: 0; font-size: 1.05rem; }
.total { color: var(--muted); font-size: 0.9rem; }

.item-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 12px;
}

.item-card {
  position: relative;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 14px;
  overflow: hidden;
  aspect-ratio: 3 / 4;
  display: flex;
  flex-direction: column;
  cursor: pointer;
}

.item-card .item-thumb {
  width: 100%;
  flex: 1;
  border-radius: 0;
  object-fit: cover;
}

.item-card .item-thumb.placeholder {
  font-size: 2rem;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
}

.item-card-info {
  padding: 8px 10px;
  background: linear-gradient(to top, rgba(0,0,0,0.55), transparent 100%);
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
}

.item-card-amount {
  font-weight: 700;
  color: #ffffff;
  font-size: 1rem;
  text-shadow: 0 1px 3px rgba(0,0,0,0.6);
}

.item-card-name {
  font-size: 0.75rem;
  color: #e5e7eb;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  text-shadow: 0 1px 3px rgba(0,0,0,0.6);
}

.item-card .delete-btn {
  position: absolute;
  top: 4px;
  right: 4px;
  background: rgba(0,0,0,0.5);
  border-radius: 50%;
  width: 28px;
  height: 28px;
  color: #fff;
}

.item-card-photo-count {
  position: absolute;
  top: 4px;
  left: 4px;
  background: rgba(0, 0, 0, 0.6);
  color: #fff;
  font-size: 0.7rem;
  padding: 2px 7px;
  border-radius: 10px;
}

.delete-btn {
  background: transparent;
  border: none;
  color: var(--muted);
  font-size: 1.1rem;
  cursor: pointer;
  padding: 4px 6px;
  flex-shrink: 0;
}

.delete-btn:active { color: var(--danger); }

.empty-state {
  color: var(--muted);
  text-align: center;
  padding: 24px 0;
}
