/* HomeKeeper - Styles */
:root {
  --bg: #f8f9fa;
  --surface: #ffffff;
  --surface-2: #f1f3f5;
  --text: #1a1b1e;
  --text-2: #6b7280;
  --border: #e5e7eb;
  --primary: #3b82f6;
  --primary-hover: #2563eb;
  --danger: #ef4444;
  --success: #22c55e;
  --warning: #f59e0b;
  --shadow: 0 1px 3px rgba(0,0,0,0.08), 0 1px 2px rgba(0,0,0,0.06);
  --shadow-lg: 0 10px 25px rgba(0,0,0,0.12);
  --radius: 10px;
  --radius-sm: 6px;
  --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --nav-h: 56px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1117;
    --surface: #1a1b23;
    --surface-2: #25262e;
    --text: #e4e5e7;
    --text-2: #909296;
    --border: #2c2e33;
    --shadow: 0 1px 3px rgba(0,0,0,0.3), 0 1px 2px rgba(0,0,0,0.2);
    --shadow-lg: 0 10px 25px rgba(0,0,0,0.4);
  }
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 16px; -webkit-text-size-adjust: 100%; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  min-height: 100dvh;
  overflow-x: hidden;
}

/* Layout */
.app-header {
  position: fixed; top: 0; left: 0; right: 0; z-index: 100;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  height: var(--nav-h);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 16px;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}
.app-header h1 {
  font-size: 1.1rem; font-weight: 700;
  display: flex; align-items: center; gap: 8px;
}
.app-header h1 span { font-size: 1.3rem; }
.header-actions { display: flex; gap: 8px; align-items: center; }

.app-nav {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 100;
  background: var(--surface);
  border-top: 1px solid var(--border);
  height: var(--nav-h);
  display: flex;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}
.app-nav button {
  flex: 1; background: none; border: none; color: var(--text-2);
  font-size: 0.7rem; font-weight: 500;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 2px; cursor: pointer; transition: color 0.15s; padding: 4px 0;
  -webkit-tap-highlight-color: transparent;
}
.app-nav button .nav-icon { font-size: 1.3rem; }
.app-nav button.active { color: var(--primary); }
.app-nav button.active .nav-icon { transform: scale(1.1); }

.app-content {
  padding-top: calc(var(--nav-h) + 8px);
  padding-bottom: calc(var(--nav-h) + 8px);
  padding-left: 12px; padding-right: 12px;
  max-width: 800px; margin: 0 auto;
}

/* Cards */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
}
.card + .card { margin-top: 12px; }

/* Affiliate card */
.affiliate-card {
  transition: border-color 0.2s, box-shadow 0.2s;
}
.affiliate-card:hover {
  border-color: var(--primary) !important;
  box-shadow: 0 0 0 1px var(--primary);
}

/* Stats grid */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 10px;
  margin-bottom: 16px;
}
.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  text-align: center;
  box-shadow: var(--shadow);
}
.stat-card .stat-value { font-size: 1.5rem; font-weight: 700; }
.stat-card .stat-label { font-size: 0.75rem; color: var(--text-2); margin-top: 2px; }
.stat-card.warning .stat-value { color: var(--warning); }
.stat-card.danger .stat-value { color: var(--danger); }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 16px; border-radius: var(--radius-sm);
  font-size: 0.875rem; font-weight: 500; cursor: pointer;
  border: 1px solid var(--border); background: var(--surface);
  color: var(--text); transition: all 0.15s;
  -webkit-tap-highlight-color: transparent;
  white-space: nowrap;
}
.btn:hover { background: var(--surface-2); }
.btn:active { transform: scale(0.97); }
.btn-primary { background: var(--primary); color: white; border-color: var(--primary); }
.btn-primary:hover { background: var(--primary-hover); }
.btn-danger { background: var(--danger); color: white; border-color: var(--danger); }
.btn-sm { padding: 4px 10px; font-size: 0.8rem; }
.btn-icon { padding: 6px; border: none; background: none; color: var(--text-2); font-size: 1.2rem; cursor: pointer; border-radius: 50%; }
.btn-icon:hover { background: var(--surface-2); }

/* Room grid */
.room-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 10px;
  margin-bottom: 16px;
}
.room-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  cursor: pointer;
  transition: all 0.15s;
  box-shadow: var(--shadow);
  text-align: center;
  -webkit-tap-highlight-color: transparent;
}
.room-card:hover { border-color: var(--primary); transform: translateY(-1px); }
.room-card:active { transform: scale(0.97); }
.room-card .room-icon { font-size: 1.8rem; display: block; margin-bottom: 4px; }
.room-card .room-name { font-size: 0.85rem; font-weight: 600; }
.room-card .room-count { font-size: 0.7rem; color: var(--text-2); }

/* Section headers */
.section-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 10px;
}
.section-header h2 { font-size: 1rem; font-weight: 600; }
.section-header .badge {
  background: var(--primary); color: white; font-size: 0.7rem;
  padding: 2px 8px; border-radius: 10px; font-weight: 600;
}

/* Item list */
.item-list { list-style: none; }
.item-list li {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 0; border-bottom: 1px solid var(--border);
  cursor: pointer; transition: background 0.1s;
}
.item-list li:last-child { border-bottom: none; }
.item-list li:hover { background: var(--surface-2); margin: 0 -12px; padding: 12px 12px; border-radius: var(--radius-sm); }
.item-icon { font-size: 1.5rem; width: 36px; text-align: center; flex-shrink: 0; }
.item-info { flex: 1; min-width: 0; }
.item-info .item-name { font-weight: 600; font-size: 0.9rem; }
.item-info .item-meta { font-size: 0.75rem; color: var(--text-2); }
.item-actions { display: flex; gap: 4px; flex-shrink: 0; }

/* Maintenance list */
.maint-item {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 0; border-bottom: 1px solid var(--border);
}
.maint-item:last-child { border-bottom: none; }
.maint-status {
  width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0;
}
.maint-status.overdue { background: var(--danger); }
.maint-status.due-soon { background: var(--warning); }
.maint-status.ok { background: var(--success); }

/* Modal overlay */
.modal-overlay {
  position: fixed; inset: 0; z-index: 200;
  background: rgba(0,0,0,0.5);
  display: flex; align-items: flex-end; justify-content: center;
  animation: fadeIn 0.15s ease;
}
.modal-overlay.center {
  align-items: center;
}
.modal {
  background: var(--surface);
  border-radius: var(--radius) var(--radius) 0 0;
  width: 100%; max-width: 500px;
  max-height: 85dvh; overflow-y: auto;
  padding: 20px; padding-bottom: calc(20px + env(safe-area-inset-bottom));
  animation: slideUp 0.2s ease;
}
.modal-overlay.center .modal {
  border-radius: var(--radius);
  max-height: 90dvh;
}
.modal h2 { font-size: 1.1rem; margin-bottom: 16px; display: flex; align-items: center; gap: 8px; }
.modal-close {
  float: right; background: none; border: none; font-size: 1.5rem;
  color: var(--text-2); cursor: pointer; padding: 4px;
}

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

/* Form fields */
.form-group { margin-bottom: 14px; }
.form-group label { display: block; font-size: 0.8rem; font-weight: 600; margin-bottom: 4px; color: var(--text-2); }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.form-control {
  width: 100%; padding: 10px 12px; border-radius: var(--radius-sm);
  border: 1px solid var(--border); background: var(--bg);
  font-size: 0.9rem; color: var(--text); font-family: var(--font);
  transition: border-color 0.15s;
}
.form-control:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 2px rgba(59,130,246,0.2); }
textarea.form-control { resize: vertical; min-height: 60px; }
select.form-control { appearance: auto; }

/* Photo */
.photo-thumb {
  width: 48px; height: 48px; border-radius: var(--radius-sm);
  object-fit: cover; border: 1px solid var(--border);
  flex-shrink: 0; cursor: pointer;
}
.photo-upload-btn { display: inline-flex; align-items: center; gap: 6px; }

/* Toast */
.toast {
  position: fixed; bottom: calc(var(--nav-h) + 16px); left: 50%; transform: translateX(-50%);
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 10px 16px;
  box-shadow: var(--shadow-lg); z-index: 300;
  font-size: 0.85rem; animation: slideUp 0.2s ease;
  max-width: 90vw; text-align: center;
}

/* Empty state */
.empty-state {
  text-align: center; padding: 40px 20px; color: var(--text-2);
}
.empty-state .empty-icon { font-size: 3rem; margin-bottom: 12px; }
.empty-state p { font-size: 0.9rem; }

/* Detail view */
.detail-header {
  display: flex; align-items: center; gap: 12px; margin-bottom: 16px;
}
.detail-header .back-btn {
  background: none; border: none; font-size: 1.3rem;
  color: var(--primary); cursor: pointer; padding: 4px;
}
.detail-header h2 { margin: 0; font-size: 1.1rem; }

/* Photo view modal */
.photo-view {
  max-width: 90vw; max-height: 80vh; border-radius: var(--radius-sm);
}

/* Responsive */
@media (min-width: 640px) {
  .room-grid { grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); }
  .stats-grid { grid-template-columns: repeat(4, 1fr); }
}

/* Scrollbar */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

/* ─── Photo Gallery Styles ─── */
.gallery-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 10px;
  margin-bottom: 16px;
}
.gallery-item {
  position: relative;
  border-radius: var(--radius-sm);
  overflow: hidden;
  background: var(--surface-2);
  aspect-ratio: 1;
  cursor: pointer;
  transition: transform 0.15s, box-shadow 0.15s;
  border: 1px solid var(--border);
}
.gallery-item:hover {
  transform: scale(1.03);
  box-shadow: var(--shadow-lg);
  z-index: 2;
}
.gallery-item img {
  width: 100%; height: 100%;
  object-fit: cover;
  display: block;
}
.gallery-item-overlay {
  position: absolute;
  bottom: 0; left: 0; right: 0;
  background: linear-gradient(transparent, rgba(0,0,0,0.7));
  padding: 24px 8px 6px;
  color: #fff;
  font-size: 0.72rem;
  line-height: 1.3;
  pointer-events: none;
}
.gallery-item-overlay .gal-name {
  font-weight: 600;
  text-shadow: 0 1px 2px rgba(0,0,0,0.5);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.gallery-item-overlay .gal-category {
  font-size: 0.6rem;
  opacity: 0.85;
  text-shadow: 0 1px 2px rgba(0,0,0,0.3);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.gallery-empty {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-2);
}
.gallery-empty .gal-empty-icon { font-size: 3.5rem; margin-bottom: 12px; }
.gallery-empty h3 { font-size: 1.1rem; font-weight: 600; color: var(--text); margin-bottom: 4px; }
.gallery-empty p { font-size: 0.85rem; }
.gallery-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 12px;
}
.gallery-header h2 { font-size: 1rem; font-weight: 600; }
.gallery-count {
  font-size: 0.75rem;
  color: var(--text-2);
  background: var(--surface-2);
  padding: 2px 10px;
  border-radius: 10px;
  font-weight: 500;
}

/* ─── Budget Styles ─── */
.budget-grid {
  display: flex; flex-direction: column; gap: 8px;
  margin-bottom: 16px;
}
.budget-card {
  background: var(--surface);
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  padding: 12px;
  transition: border-color 0.15s;
}
.budget-card.over { border-left: 3px solid var(--danger); }
.budget-card.warning { border-left: 3px solid var(--warning); }
.budget-card.ok { border-left: 3px solid var(--success); }
.budget-card.no-budget { border-left: 3px solid var(--text-2); opacity: 0.85; }
.budget-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 6px;
}
.budget-cat { font-weight: 600; font-size: 0.85rem; }
.budget-amount { font-size: 0.8rem; color: var(--text-2); }
.budget-bar-wrap {
  height: 8px; background: var(--surface-2);
  border-radius: 4px; overflow: hidden;
  margin-bottom: 4px;
}
.budget-bar {
  height: 100%; border-radius: 4px;
  transition: width 0.5s ease;
  min-width: 2px;
}
.budget-meta { font-size: 0.7rem; color: var(--text-2); }
.budget-alert {
  background: rgba(239,68,68,0.08);
  border: 1px solid rgba(239,68,68,0.2);
  border-radius: var(--radius-sm);
  padding: 8px 12px;
  font-size: 0.8rem;
  margin-bottom: 6px;
}
.budget-alert.warn {
  background: rgba(245,158,11,0.08);
  border-color: rgba(245,158,11,0.25);
}
.budget-edit-row {
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
}
.budget-edit-row:last-of-type { border-bottom: none; }
.budget-edit-info {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 6px;
}
.budget-edit-cat { font-weight: 600; font-size: 0.85rem; display: flex; align-items: center; gap: 4px; }
.budget-edit-spend { font-size: 0.75rem; color: var(--text-2); }
.budget-edit-form {
  display: flex; gap: 6px; align-items: center;
  flex-wrap: wrap;
}
.budget-preview-bar-wrap {
  height: 4px; background: var(--surface-2);
  border-radius: 2px; overflow: hidden;
  margin-top: 6px;
}
.budget-preview-bar {
  height: 100%; border-radius: 2px;
  transition: width 0.4s ease;
  min-width: 2px;
}
