*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --bg: #f0f4f8;
  --surface: #ffffff;
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --danger: #dc2626;
  --text: #1e293b;
  --text-muted: #64748b;
  --border: #e2e8f0;
  --success: #16a34a;
  --radius: 12px;
  --shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

html {
  -webkit-tap-highlight-color: transparent;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100dvh;
  padding-bottom: calc(72px + var(--safe-bottom));
}

header {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--primary);
  color: white;
  padding: 12px 16px;
  padding-top: calc(12px + env(safe-area-inset-top, 0px));
  box-shadow: var(--shadow);
}

header h1 {
  font-size: 1.25rem;
  font-weight: 700;
}

.house-bar {
  display: flex;
  gap: 8px;
  margin-top: 10px;
  align-items: center;
}

.house-bar select {
  flex: 1;
  padding: 10px 12px;
  border: none;
  border-radius: 8px;
  font-size: 1rem;
  background: rgba(255, 255, 255, 0.95);
  color: var(--text);
}

.btn-icon {
  width: 42px;
  height: 42px;
  border: none;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.2);
  color: white;
  font-size: 1.25rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.btn-icon:active {
  background: rgba(255, 255, 255, 0.35);
}

main {
  padding: 16px;
  max-width: 600px;
  margin: 0 auto;
}

.panel {
  display: none;
}

.panel.active {
  display: block;
}

.filter-bar {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
  overflow-x: auto;
  padding-bottom: 4px;
  -webkit-overflow-scrolling: touch;
}

.filter-chip {
  padding: 8px 14px;
  border: 1px solid var(--border);
  border-radius: 20px;
  background: var(--surface);
  font-size: 0.875rem;
  white-space: nowrap;
  cursor: pointer;
  transition: all 0.15s;
}

.filter-chip.active {
  background: var(--primary);
  color: white;
  border-color: var(--primary);
}

.item-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.item-card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 14px 16px;
  box-shadow: var(--shadow);
  display: flex;
  align-items: center;
  gap: 12px;
}

.item-card.checked {
  opacity: 0.55;
}

.item-card.checked .item-name {
  text-decoration: line-through;
}

.item-checkbox {
  width: 24px;
  height: 24px;
  accent-color: var(--primary);
  flex-shrink: 0;
}

.item-info {
  flex: 1;
  min-width: 0;
}

.item-name {
  font-weight: 600;
  font-size: 1rem;
  word-break: break-word;
}

.item-meta {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-top: 2px;
}

.item-badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 6px;
  font-size: 0.75rem;
  font-weight: 500;
  background: #dbeafe;
  color: #1e40af;
  margin-top: 4px;
}

.item-badge.expired {
  background: #fee2e2;
  color: #991b1b;
}

.item-badge.soon {
  background: #fef3c7;
  color: #92400e;
}

.item-actions {
  display: flex;
  gap: 4px;
  flex-shrink: 0;
}

.item-actions button {
  width: 36px;
  height: 36px;
  border: none;
  border-radius: 8px;
  background: var(--bg);
  font-size: 1rem;
  cursor: pointer;
}

.item-actions button.delete {
  color: var(--danger);
}

.empty-state {
  text-align: center;
  padding: 48px 16px;
  color: var(--text-muted);
}

.empty-state .emoji {
  font-size: 3rem;
  margin-bottom: 12px;
}

.fab {
  position: fixed;
  bottom: calc(80px + var(--safe-bottom));
  right: 20px;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--primary);
  color: white;
  border: none;
  font-size: 1.75rem;
  box-shadow: 0 4px 16px rgba(37, 99, 235, 0.4);
  cursor: pointer;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: center;
}

.fab:active {
  background: var(--primary-dark);
  transform: scale(0.95);
}

nav.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: var(--surface);
  border-top: 1px solid var(--border);
  display: flex;
  padding-bottom: var(--safe-bottom);
  z-index: 10;
}

.nav-btn {
  flex: 1;
  padding: 10px 0;
  border: none;
  background: none;
  color: var(--text-muted);
  font-size: 0.75rem;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}

.nav-btn .icon {
  font-size: 1.4rem;
}

.nav-btn.active {
  color: var(--primary);
  font-weight: 600;
}

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  z-index: 20;
  display: none;
  align-items: flex-end;
  justify-content: center;
}

.modal-overlay.open {
  display: flex;
}

.modal {
  background: var(--surface);
  width: 100%;
  max-width: 600px;
  border-radius: 16px 16px 0 0;
  padding: 20px;
  padding-bottom: calc(20px + var(--safe-bottom));
  animation: slideUp 0.25s ease;
}

@keyframes slideUp {
  from { transform: translateY(100%); }
  to { transform: translateY(0); }
}

.modal h2 {
  font-size: 1.125rem;
  margin-bottom: 16px;
}

.form-group {
  margin-bottom: 14px;
}

.form-group label {
  display: block;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 6px;
}

.form-group input,
.form-group select {
  width: 100%;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 1rem;
}

.form-row {
  display: flex;
  gap: 10px;
}

.form-row .form-group {
  flex: 1;
}

.modal-actions {
  display: flex;
  gap: 10px;
  margin-top: 20px;
}

.btn {
  flex: 1;
  padding: 14px;
  border: none;
  border-radius: 10px;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
}

.btn-primary {
  background: var(--primary);
  color: white;
}

.btn-secondary {
  background: var(--bg);
  color: var(--text);
}

.btn-danger {
  background: var(--danger);
  color: white;
}

.toast {
  position: fixed;
  top: calc(16px + env(safe-area-inset-top, 0px));
  left: 50%;
  transform: translateX(-50%);
  background: #1e293b;
  color: white;
  padding: 10px 20px;
  border-radius: 8px;
  font-size: 0.875rem;
  z-index: 30;
  opacity: 0;
  transition: opacity 0.3s;
  pointer-events: none;
}

.toast.show {
  opacity: 1;
}

.loading {
  text-align: center;
  padding: 32px;
  color: var(--text-muted);
}

body.login-active > header,
body.login-active > main,
body.login-active > .fab,
body.login-active > nav {
  display: none;
}

.login-screen {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 100;
  background: linear-gradient(160deg, #2563eb 0%, #1e40af 100%);
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.login-screen.open {
  display: flex;
}

.login-card {
  background: var(--surface);
  border-radius: 20px;
  padding: 32px 28px;
  width: 100%;
  max-width: 380px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.2);
  text-align: center;
}

.login-logo {
  font-size: 3rem;
  margin-bottom: 8px;
}

.login-card h1 {
  font-size: 1.5rem;
  margin-bottom: 4px;
}

.login-subtitle {
  color: var(--text-muted);
  font-size: 0.9rem;
  margin-bottom: 24px;
}

.login-error {
  color: var(--danger);
  font-size: 0.85rem;
  min-height: 1.2em;
  margin-bottom: 8px;
}

@media (min-width: 600px) {
  .modal-overlay {
    align-items: center;
  }

  .modal {
    border-radius: 16px;
    max-height: 90vh;
    overflow-y: auto;
  }
}
