/**
 * ===================================================================
 * HomeToDo - Mobile-First Responsive Stylesheet
 * ===================================================================
 */

:root {
  --primary: #10b981;
  --primary-hover: #059669;
  --primary-light: rgba(16, 185, 129, 0.12);
  --primary-text: #ffffff;
  
  --bg: #f8fafc;
  --surface: #ffffff;
  --surface-alt: #f1f5f9;
  --surface-border: #e2e8f0;
  
  --text-main: #0f172a;
  --text-muted: #64748b;
  --text-subtle: #94a3b8;
  
  --danger: #ef4444;
  --danger-light: rgba(239, 68, 68, 0.12);
  --warning: #f59e0b;
  --warning-light: rgba(245, 158, 11, 0.12);
  --success: #10b981;
  
  --radius-sm: 8px;
  --radius-md: 14px;
  --radius-lg: 20px;
  --radius-full: 9999px;
  
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.06), 0 1px 2px rgba(0, 0, 0, 0.04);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.08), 0 2px 4px -1px rgba(0, 0, 0, 0.04);
  --shadow-lg: 0 12px 24px -4px rgba(0, 0, 0, 0.12);
  
  --touch-target: 48px;
  --font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #090d16;
    --surface: #131b2e;
    --surface-alt: #1c2740;
    --surface-border: #233152;
    
    --text-main: #f8fafc;
    --text-muted: #94a3b8;
    --text-subtle: #64748b;
    
    --primary-light: rgba(16, 185, 129, 0.18);
    --shadow-md: 0 4px 10px rgba(0, 0, 0, 0.35);
  }
}

/* Reset & Box Sizing */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  height: 100%;
  font-family: var(--font-family);
  background-color: var(--bg);
  color: var(--text-main);
  user-select: none;
  -webkit-user-select: none;
  overflow: hidden;
}

/* App Layout: Mobile-first container capped on tablets/desktop */
.app-layout {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  max-width: 640px;
  margin: 0 auto;
  position: relative;
  background-color: var(--bg);
  box-shadow: 0 0 50px rgba(0, 0, 0, 0.15);
}

/* ========================================================= */
/* HEADER & NAVIGATION */
/* ========================================================= */

.app-header {
  flex-shrink: 0;
  background-color: var(--surface);
  border-bottom: 1px solid var(--surface-border);
  padding-top: max(12px, env(safe-area-inset-top));
  padding-left: 16px;
  padding-right: 16px;
  padding-bottom: 10px;
  z-index: 10;
}

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

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
}

.brand-icon {
  width: 40px;
  height: 40px;
  background: linear-gradient(135deg, var(--primary), var(--primary-hover));
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #ffffff;
  box-shadow: 0 4px 10px rgba(16, 185, 129, 0.3);
}

.brand-icon svg {
  width: 22px;
  height: 22px;
}

.brand-text h1 {
  font-size: 1.25rem;
  font-weight: 700;
  line-height: 1.2;
}

/* Sync status badge */
.sync-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.72rem;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: var(--radius-full);
  margin-top: 2px;
  transition: all 0.25s ease;
}

.sync-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
}

.status-online {
  background-color: var(--primary-light);
  color: var(--primary);
}
.status-online .sync-dot {
  background-color: var(--primary);
}

.status-syncing {
  background-color: rgba(59, 130, 246, 0.15);
  color: #3b82f6;
}
.status-syncing .sync-dot {
  background-color: #3b82f6;
  animation: pulse-dot 1s infinite alternate;
}

.status-offline {
  background-color: var(--warning-light);
  color: var(--warning);
}
.status-offline .sync-dot {
  background-color: var(--warning);
}

@keyframes pulse-dot {
  from { opacity: 0.3; transform: scale(0.8); }
  to { opacity: 1; transform: scale(1.2); }
}

/* Header Action Buttons (Min 48px) */
.header-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

.icon-btn {
  width: var(--touch-target);
  height: var(--touch-target);
  display: flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: none;
  border-radius: var(--radius-full);
  color: var(--text-muted);
  cursor: pointer;
  transition: background-color 0.15s ease, color 0.15s ease, transform 0.1s ease;
}

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

.icon-btn:active {
  transform: scale(0.92);
}

.icon-btn svg {
  width: 22px;
  height: 22px;
}

/* Filter Pills Carousel */
.filter-bar {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
  padding-bottom: 2px;
}

.filter-bar::-webkit-scrollbar {
  display: none;
}

.filter-pill {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: 6px;
  height: 36px;
  padding: 0 14px;
  background-color: var(--surface-alt);
  border: 1px solid transparent;
  border-radius: var(--radius-full);
  color: var(--text-muted);
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
}

.filter-pill.active {
  background-color: var(--primary);
  color: #ffffff;
  border-color: var(--primary);
  box-shadow: 0 2px 8px rgba(16, 185, 129, 0.3);
}

.filter-pill .badge {
  font-size: 0.72rem;
  background: rgba(0, 0, 0, 0.12);
  padding: 1px 6px;
  border-radius: var(--radius-full);
}

.filter-pill.active .badge {
  background: rgba(255, 255, 255, 0.28);
  color: #ffffff;
}

/* ========================================================= */
/* MAIN CONTENT LIST */
/* ========================================================= */

.app-content {
  flex: 1;
  overflow-y: auto;
  padding: 14px 16px 140px 16px; /* Bottom padding so items are not covered by quick add bar */
  -webkit-overflow-scrolling: touch;
}

/* Warning Banner */
.banner-card {
  display: flex;
  gap: 12px;
  background: linear-gradient(135deg, rgba(16, 185, 129, 0.1), rgba(16, 185, 129, 0.04));
  border: 1px solid var(--primary);
  border-radius: var(--radius-md);
  padding: 14px;
  margin-bottom: 16px;
}

.banner-icon {
  font-size: 1.6rem;
}

.banner-body h3 {
  font-size: 0.95rem;
  font-weight: 700;
  margin-bottom: 4px;
}

.banner-body p {
  font-size: 0.82rem;
  color: var(--text-muted);
  margin-bottom: 10px;
  line-height: 1.35;
}

/* Stats row */
.stats-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.78rem;
  color: var(--text-muted);
  font-weight: 500;
  margin-bottom: 12px;
  padding: 0 4px;
}

.btn-link {
  background: none;
  border: none;
  color: var(--primary);
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 4px 6px;
  border-radius: var(--radius-sm);
}

.btn-link:hover {
  background-color: var(--primary-light);
}

/* Category Sections & Item Cards */
.category-group {
  margin-bottom: 18px;
}

.category-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 8px;
  padding-left: 4px;
}

.category-badge-count {
  font-size: 0.72rem;
  background-color: var(--surface-alt);
  padding: 2px 7px;
  border-radius: var(--radius-full);
}

.items-group-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

/* Product Item Card */
.item-card {
  display: flex;
  align-items: center;
  gap: 10px;
  background-color: var(--surface);
  border: 1px solid var(--surface-border);
  border-radius: var(--radius-md);
  padding: 8px 10px 8px 6px;
  min-height: 56px;
  box-shadow: var(--shadow-sm);
  transition: transform 0.15s ease, opacity 0.2s ease, border-color 0.2s ease;
  user-select: none;
}

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

/* Checkbox touch area: minimum 48px */
.checkbox-touch {
  width: var(--touch-target);
  height: var(--touch-target);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  background: none;
  border: none;
  flex-shrink: 0;
}

.custom-checkbox {
  width: 24px;
  height: 24px;
  border: 2px solid var(--text-subtle);
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  color: transparent;
}

.item-card.is-checked .custom-checkbox {
  background-color: var(--primary);
  border-color: var(--primary);
  color: #ffffff;
  transform: scale(1.05);
}

.custom-checkbox svg {
  width: 16px;
  height: 16px;
  stroke-dasharray: 24;
  stroke-dashoffset: 0;
  transition: stroke-dashoffset 0.2s ease;
}

/* Item details text */
.item-details {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  justify-content: center;
  cursor: pointer;
}

.item-title-row {
  display: flex;
  align-items: baseline;
  gap: 8px;
  flex-wrap: wrap;
}

.item-name {
  font-size: 0.96rem;
  font-weight: 600;
  color: var(--text-main);
  word-break: break-word;
  transition: color 0.2s ease, text-decoration 0.2s ease;
}

.item-qty {
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--primary);
  background-color: var(--primary-light);
  padding: 2px 7px;
  border-radius: var(--radius-full);
}

.item-meta {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 2px;
}

.item-cat-tag {
  font-size: 0.72rem;
  color: var(--text-muted);
}

/* Checked state styling */
.item-card.is-checked {
  opacity: 0.55;
  background-color: var(--surface-alt);
  border-color: transparent;
}

.item-card.is-checked .item-name {
  text-decoration: line-through;
  color: var(--text-muted);
}

.item-card.is-checked .item-qty {
  background-color: var(--surface-alt);
  color: var(--text-subtle);
}

/* Item actions */
.item-actions {
  display: flex;
  align-items: center;
  gap: 2px;
  flex-shrink: 0;
}

.item-action-btn {
  width: 38px;
  height: 38px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: none;
  border: none;
  border-radius: var(--radius-full);
  color: var(--text-subtle);
  cursor: pointer;
  transition: all 0.15s ease;
}

.item-action-btn:hover {
  color: var(--text-main);
  background-color: var(--surface-alt);
}

.item-action-btn.btn-delete:hover {
  color: var(--danger);
  background-color: var(--danger-light);
}

.item-action-btn svg {
  width: 17px;
  height: 17px;
}

/* Empty State */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 48px 24px;
  color: var(--text-muted);
}

.empty-icon {
  font-size: 3.5rem;
  margin-bottom: 12px;
}

.empty-state h3 {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--text-main);
  margin-bottom: 6px;
}

.empty-state p {
  font-size: 0.88rem;
  max-width: 260px;
}

/* ========================================================= */
/* QUICK ADD FLOATING BAR (BOTTOM ERGONOMIC) */
/* ========================================================= */

.quick-add-bar {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  background-color: var(--surface);
  border-top: 1px solid var(--surface-border);
  padding: 10px 14px max(14px, env(safe-area-inset-bottom)) 14px;
  box-shadow: 0 -8px 24px rgba(0, 0, 0, 0.08);
  backdrop-filter: blur(12px);
  z-index: 20;
}

.add-form {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.form-row.main-row {
  display: flex;
  gap: 8px;
}

.input-text {
  flex: 1;
  height: var(--touch-target);
  background-color: var(--surface-alt);
  border: 1px solid var(--surface-border);
  border-radius: var(--radius-md);
  padding: 0 14px;
  font-size: 0.95rem;
  color: var(--text-main);
  outline: none;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
  user-select: text;
  -webkit-user-select: text;
}

.input-text:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-light);
}

.btn-add {
  width: var(--touch-target);
  height: var(--touch-target);
  flex-shrink: 0;
  background: linear-gradient(135deg, var(--primary), var(--primary-hover));
  border: none;
  border-radius: var(--radius-md);
  color: #ffffff;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: 0 4px 12px rgba(16, 185, 129, 0.35);
  transition: transform 0.1s ease, box-shadow 0.2s ease;
}

.btn-add:active {
  transform: scale(0.92);
}

.btn-add svg {
  width: 24px;
  height: 24px;
}

.form-row.detail-row {
  display: flex;
  gap: 8px;
}

.select-wrapper {
  flex: 1.3;
}

.input-select {
  width: 100%;
  height: 38px;
  background-color: var(--surface-alt);
  border: 1px solid var(--surface-border);
  border-radius: var(--radius-sm);
  padding: 0 10px;
  font-size: 0.85rem;
  color: var(--text-main);
  outline: none;
  cursor: pointer;
}

.input-qty {
  flex: 1;
  height: 38px;
  background-color: var(--surface-alt);
  border: 1px solid var(--surface-border);
  border-radius: var(--radius-sm);
  padding: 0 10px;
  font-size: 0.85rem;
  color: var(--text-main);
  outline: none;
  user-select: text;
  -webkit-user-select: text;
}

/* ========================================================= */
/* MODALS */
/* ========================================================= */

.modal-overlay {
  position: fixed;
  inset: 0;
  background-color: rgba(0, 0, 0, 0.65);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 50;
  animation: fadeIn 0.2s ease;
}

@media (min-width: 640px) {
  .modal-overlay {
    align-items: center;
    padding: 20px;
  }
}

.modal-card {
  width: 100%;
  max-width: 520px;
  max-height: 90dvh;
  overflow-y: auto;
  background-color: var(--surface);
  border-top-left-radius: var(--radius-lg);
  border-top-right-radius: var(--radius-lg);
  padding: 20px 20px max(24px, env(safe-area-inset-bottom)) 20px;
  box-shadow: var(--shadow-lg);
  animation: slideUp 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}

@media (min-width: 640px) {
  .modal-card {
    border-radius: var(--radius-lg);
  }
}

.modal-card.modal-sm {
  max-width: 400px;
}

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

.modal-header h2, .modal-header h3 {
  font-size: 1.15rem;
  font-weight: 700;
}

.modal-close {
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--surface-alt);
  border: none;
  border-radius: var(--radius-full);
  font-size: 1.5rem;
  color: var(--text-muted);
  cursor: pointer;
}

.field-group {
  margin-bottom: 14px;
}

.field-group label {
  display: block;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text-main);
  margin-bottom: 6px;
}

.field-help {
  display: block;
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 4px;
  line-height: 1.3;
}

.field-help code {
  background: var(--surface-alt);
  padding: 1px 4px;
  border-radius: 4px;
  font-size: 0.72rem;
}

.input-secret-wrapper {
  display: flex;
  gap: 6px;
}

.btn-toggle-eye {
  width: var(--touch-target);
  height: var(--touch-target);
  background: var(--surface-alt);
  border: 1px solid var(--surface-border);
  border-radius: var(--radius-md);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.1rem;
}

.btn-row {
  display: flex;
  gap: 10px;
  margin-top: 18px;
}

.btn {
  flex: 1;
  height: var(--touch-target);
  border: none;
  border-radius: var(--radius-md);
  font-size: 0.92rem;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.15s ease;
}

.btn-sm {
  height: 38px;
  font-size: 0.82rem;
  padding: 0 14px;
  flex: initial;
}

.btn-primary {
  background: var(--primary);
  color: #ffffff;
}
.btn-primary:hover {
  background: var(--primary-hover);
}

.btn-secondary {
  background: var(--surface-alt);
  color: var(--text-main);
  border: 1px solid var(--surface-border);
}
.btn-secondary:hover {
  background: var(--surface-border);
}

.btn-danger {
  background: var(--danger);
  color: #ffffff;
}

.modal-divider {
  border: none;
  height: 1px;
  background-color: var(--surface-border);
  margin: 20px 0;
}

/* Test Connection Result Alert */
.test-result {
  margin-top: 12px;
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  font-size: 0.82rem;
  font-weight: 500;
  line-height: 1.4;
}

.test-result.success {
  background-color: var(--primary-light);
  color: var(--primary);
  border: 1px solid var(--primary);
}

.test-result.error {
  background-color: var(--danger-light);
  color: var(--danger);
  border: 1px solid var(--danger);
}

/* Pairing Section */
.pairing-section h3 {
  font-size: 0.95rem;
  font-weight: 700;
  margin-bottom: 4px;
}

.share-box {
  display: flex;
  gap: 8px;
  margin-top: 10px;
}

.share-box input {
  font-size: 0.78rem;
}

.qr-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  margin-top: 16px;
  padding: 16px;
  background-color: var(--surface-alt);
  border-radius: var(--radius-md);
}

#qr-canvas {
  background-color: #ffffff;
  border-radius: 8px;
  padding: 8px;
  box-shadow: var(--shadow-sm);
}

.qr-caption {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 8px;
}

.danger-zone {
  display: flex;
  justify-content: flex-end;
}

/* ========================================================= */
/* TOAST NOTIFICATIONS */
/* ========================================================= */

.toast-container {
  position: fixed;
  top: max(16px, env(safe-area-inset-top));
  left: 50%;
  transform: translateX(-50%);
  width: 90%;
  max-width: 420px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 100;
  pointer-events: none;
}

.toast {
  padding: 10px 16px;
  background-color: var(--text-main);
  color: var(--bg);
  border-radius: var(--radius-full);
  font-size: 0.85rem;
  font-weight: 600;
  box-shadow: var(--shadow-lg);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  animation: toastIn 0.25s cubic-bezier(0.16, 1, 0.3, 1), toastOut 0.25s ease 2.75s forwards;
  pointer-events: auto;
}

/* Utility classes */
.hidden {
  display: none !important;
}

/* Animations */
@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

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

@keyframes toastIn {
  from { opacity: 0; transform: translateY(-12px) scale(0.95); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

@keyframes toastOut {
  from { opacity: 1; transform: translateY(0) scale(1); }
  to { opacity: 0; transform: translateY(-8px) scale(0.95); }
}
