/* Expiry Checker PWA - App Styles */
:root {
  --primary: #e94560;
  --primary-dark: #c81d45;
  --bg: #1a1a2e;
  --bg-card: #16213e;
  --bg-input: #0f3460;
  --text: #eaeaea;
  --text-dim: #8899aa;
  --safe: #27ae60;
  --warning: #f39c12;
  --critical: #e67e22;
  --expired: #e74c3c;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 4px 20px rgba(0,0,0,0.3);
  --nav-height: 64px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
  touch-action: manipulation;
}

/* Safe area padding */
body { padding-top: var(--safe-top); padding-bottom: var(--safe-bottom); }

/* Auth screens */
.auth-wrap {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 24px;
}

.auth-card {
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 32px 24px;
  width: 100%;
  max-width: 400px;
  box-shadow: var(--shadow);
}

.auth-card h1 {
  text-align: center;
  font-size: 24px;
  margin-bottom: 8px;
}

.auth-card .subtitle {
  text-align: center;
  color: var(--text-dim);
  font-size: 14px;
  margin-bottom: 24px;
}

.auth-card .logo-icon {
  text-align: center;
  font-size: 48px;
  margin-bottom: 16px;
}

/* Forms */
.form-group {
  margin-bottom: 16px;
}

.form-group label {
  display: block;
  font-size: 13px;
  color: var(--text-dim);
  margin-bottom: 6px;
  font-weight: 500;
}

.form-group input,
.form-group select,
.form-group textarea {
  width: 100%;
  padding: 12px 16px;
  background: var(--bg-input);
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 16px;
  transition: border-color 0.2s;
  outline: none;
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
  border-color: var(--primary);
}

.form-group textarea {
  resize: vertical;
  min-height: 80px;
}

.form-group input[type="date"]::-webkit-calendar-picker-indicator {
  filter: invert(1);
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px 24px;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
  text-decoration: none;
}

.btn-primary {
  background: var(--primary);
  color: white;
  width: 100%;
}

.btn-primary:hover { background: var(--primary-dark); }
.btn-primary:active { transform: scale(0.98); }

.btn-secondary {
  background: var(--bg-input);
  color: var(--text);
  width: 100%;
}

.btn-sm {
  padding: 8px 16px;
  font-size: 14px;
}

.btn-danger {
  background: var(--expired);
  color: white;
}

.btn-icon {
  width: 40px;
  height: 40px;
  padding: 0;
  border-radius: 50%;
  font-size: 20px;
}

/* Auth toggle link */
.auth-toggle {
  text-align: center;
  margin-top: 16px;
  font-size: 14px;
  color: var(--text-dim);
}

.auth-toggle a {
  color: var(--primary);
  cursor: pointer;
  text-decoration: none;
}

/* Main layout with bottom nav */
.app-wrap {
  display: none;
  flex-direction: column;
  min-height: 100vh;
}

.app-wrap.active { display: flex; }
.auth-wrap.active { display: flex; }
.auth-wrap:not(.active) { display: none; }

/* Top bar */
.top-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  background: var(--bg-card);
  border-bottom: 1px solid rgba(255,255,255,0.05);
  position: sticky;
  top: 0;
  z-index: 100;
}

.top-bar h2 {
  font-size: 18px;
  font-weight: 600;
}

.top-bar-actions {
  display: flex;
  gap: 8px;
}

/* Page content */
.page-content {
  flex: 1;
  padding: 16px;
  padding-bottom: calc(var(--nav-height) + var(--safe-bottom) + 16px);
  overflow-y: auto;
}

/* Bottom nav */
.bottom-nav {
  display: flex;
  align-items: center;
  justify-content: space-around;
  background: var(--bg-card);
  border-top: 1px solid rgba(255,255,255,0.05);
  height: var(--nav-height);
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 100;
  padding-bottom: var(--safe-bottom);
}

.nav-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 8px;
  color: var(--text-dim);
  text-decoration: none;
  cursor: pointer;
  font-size: 11px;
  transition: color 0.2s;
  border: none;
  background: none;
  min-width: 64px;
}

.nav-item .nav-icon { font-size: 24px; }
.nav-item.active { color: var(--primary); }

/* Dashboard stats */
.stats-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-bottom: 20px;
}

.stat-card {
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 16px;
  text-align: center;
}

.stat-card .stat-num {
  font-size: 32px;
  font-weight: 700;
  line-height: 1.2;
}

.stat-card .stat-label {
  font-size: 12px;
  color: var(--text-dim);
  margin-top: 4px;
}

.stat-card.expired .stat-num { color: var(--expired); }
.stat-card.critical .stat-num { color: var(--critical); }
.stat-card.warning .stat-num { color: var(--warning); }
.stat-card.safe .stat-num { color: var(--safe); }

/* Alert cards */
.alert-section { margin-bottom: 20px; }
.alert-section h3 {
  font-size: 16px;
  margin-bottom: 12px;
  color: var(--text-dim);
}

.alert-card {
  background: var(--bg-card);
  border-radius: var(--radius-sm);
  padding: 12px 16px;
  margin-bottom: 8px;
  display: flex;
  align-items: center;
  gap: 12px;
  border-left: 4px solid var(--critical);
}

.alert-card.expired-alert { border-left-color: var(--expired); }
.alert-card .alert-info { flex: 1; }
.alert-card .alert-name { font-weight: 600; font-size: 15px; }
.alert-card .alert-days { font-size: 13px; color: var(--text-dim); }
.alert-card .alert-cat { font-size: 12px; color: var(--text-dim); }

/* Item cards */
.items-list { display: flex; flex-direction: column; gap: 10px; }

.item-card {
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 14px;
  display: flex;
  gap: 12px;
  cursor: pointer;
  transition: transform 0.15s;
  border-left: 4px solid var(--safe);
  touch-action: manipulation;
  -webkit-user-select: none;
  user-select: none;
}

.item-card:active { transform: scale(0.98); }

.item-card.status-expired { border-left-color: var(--expired); }
.item-card.status-critical { border-left-color: var(--critical); }
.item-card.status-warning { border-left-color: var(--warning); }
.item-card.status-safe { border-left-color: var(--safe); }

.item-thumb {
  width: 56px;
  height: 56px;
  border-radius: var(--radius-sm);
  object-fit: cover;
  background: var(--bg-input);
  flex-shrink: 0;
}

.item-thumb-placeholder {
  width: 56px;
  height: 56px;
  border-radius: var(--radius-sm);
  background: var(--bg-input);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
  flex-shrink: 0;
}

.item-info { flex: 1; min-width: 0; }
.item-name {
  font-weight: 600;
  font-size: 15px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.item-meta {
  font-size: 13px;
  color: var(--text-dim);
  margin-top: 2px;
  display: flex;
  gap: 8px;
}
.item-expiry {
  font-size: 12px;
  margin-top: 4px;
  font-weight: 600;
}
.item-expiry.expired { color: var(--expired); }
.item-expiry.critical { color: var(--critical); }
.item-expiry.warning { color: var(--warning); }
.item-expiry.safe { color: var(--safe); }

/* Filter bar */
.filter-bar {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
  overflow-x: auto;
  padding-bottom: 4px;
  -webkit-overflow-scrolling: touch;
}

.filter-chip {
  padding: 6px 14px;
  border-radius: 20px;
  font-size: 13px;
  white-space: nowrap;
  background: var(--bg-card);
  color: var(--text-dim);
  border: 1px solid rgba(255,255,255,0.1);
  cursor: pointer;
  transition: all 0.2s;
}

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

/* Add item form */
.add-form {
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 20px;
}

.photo-capture {
  width: 100%;
  height: 200px;
  background: var(--bg-input);
  border-radius: var(--radius-sm);
  border: 2px dashed rgba(255,255,255,0.2);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 8px;
  cursor: pointer;
  margin-bottom: 16px;
  overflow: hidden;
  position: relative;
}

.photo-capture.has-photo {
  border-style: solid;
  border-color: var(--primary);
}

.photo-capture img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  position: absolute;
  top: 0;
  left: 0;
}

.photo-capture .photo-icon { font-size: 40px; }
.photo-capture .photo-text { font-size: 14px; color: var(--text-dim); }

.photo-capture input[type="file"] { display: none; }

/* Category pills */
.category-pills {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 16px;
}

.category-pill {
  padding: 8px 14px;
  border-radius: 20px;
  font-size: 13px;
  background: var(--bg-input);
  color: var(--text);
  border: 1px solid rgba(255,255,255,0.1);
  cursor: pointer;
  transition: all 0.2s;
  display: flex;
  align-items: center;
  gap: 6px;
}

.category-pill.active {
  border-color: var(--primary);
  background: rgba(233, 69, 96, 0.15);
}

/* Detail modal */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  z-index: 200;
  align-items: flex-end;
  justify-content: center;
}

.modal-overlay.active { display: flex; }

.modal-content {
  background: var(--bg-card);
  border-radius: var(--radius) var(--radius) 0 0;
  width: 100%;
  max-width: 500px;
  max-height: 85vh;
  overflow-y: auto;
  padding: 20px;
  padding-bottom: calc(20px + var(--safe-bottom));
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}

.modal-header h3 { font-size: 18px; }
.modal-close {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: none;
  background: var(--bg-input);
  color: var(--text);
  font-size: 18px;
  cursor: pointer;
}

.detail-photo {
  width: 100%;
  height: 200px;
  object-fit: cover;
  border-radius: var(--radius-sm);
  margin-bottom: 16px;
  background: var(--bg-input);
}

.detail-field {
  margin-bottom: 12px;
}

.detail-field .detail-label {
  font-size: 12px;
  color: var(--text-dim);
  margin-bottom: 2px;
}

.detail-field .detail-value {
  font-size: 15px;
}

.detail-actions {
  display: flex;
  gap: 10px;
  margin-top: 20px;
}

.detail-actions .btn { flex: 1; }

/* Toast */
.toast {
  position: fixed;
  top: calc(var(--safe-top) + 12px);
  left: 50%;
  transform: translateX(-50%) translateY(-100px);
  background: var(--bg-card);
  color: var(--text);
  padding: 12px 24px;
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow);
  z-index: 300;
  font-size: 14px;
  transition: transform 0.3s ease;
  border-left: 4px solid var(--primary);
}

.toast.show { transform: translateX(-50%) translateY(0); }
.toast.success { border-left-color: var(--safe); }
.toast.error { border-left-color: var(--expired); }

/* Pull to refresh indicator */
.pull-indicator {
  text-align: center;
  padding: 12px;
  color: var(--text-dim);
  font-size: 13px;
  display: none;
}

.pull-indicator.active { display: block; }

/* Empty state */
.empty-state {
  text-align: center;
  padding: 40px 20px;
  color: var(--text-dim);
}

.empty-state .empty-icon { font-size: 48px; margin-bottom: 12px; }
.empty-state p { font-size: 14px; }

/* Search bar */
.search-bar {
  margin-bottom: 12px;
}

.search-bar input {
  width: 100%;
  padding: 10px 16px 10px 40px;
  background: var(--bg-card);
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 20px;
  color: var(--text);
  font-size: 14px;
  outline: none;
}

.search-bar input:focus { border-color: var(--primary); }

.search-bar {
  position: relative;
}

.search-bar::before {
  content: "🔍";
  position: absolute;
  left: 14px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 14px;
}

/* Install banner */
.install-banner {
  background: var(--bg-card);
  padding: 12px 16px;
  display: flex;
  align-items: center;
  gap: 12px;
  border-bottom: 1px solid rgba(255,255,255,0.05);
}

.install-banner p { flex: 1; font-size: 14px; }
.install-banner .btn-sm { white-space: nowrap; }

/* Category breakdown */
.cat-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
}

.cat-bar .cat-icon { font-size: 20px; }
.cat-bar .cat-name { font-size: 14px; flex: 1; }
.cat-bar .cat-count { font-size: 14px; font-weight: 600; }

/* Scrollbar */
::-webkit-scrollbar { width: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.1); border-radius: 2px; }

/* Loading */
.spinner {
  display: inline-block;
  width: 20px;
  height: 20px;
  border: 2px solid rgba(255,255,255,0.3);
  border-radius: 50%;
  border-top-color: var(--primary);
  animation: spin 0.6s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

.loading-center {
  display: flex;
  justify-content: center;
  padding: 40px;
}
