/* ═══════════════════════════════════════════════════════════════════════════════
   CICLO BROCAS — INDUSTRIAL INVENTORY & TOOLING LIFECYCLE WEB APP
   Optimized for iPhone 17 Pro Max • Responsive • Dark & Light Themes
   ═══════════════════════════════════════════════════════════════════════════════ */

:root {
  /* Default Dark Mode (Refined Slate & Wine Accents) */
  --bg-primary: #0A0D14;
  --bg-secondary: #101522;
  --card-bg: rgba(22, 28, 42, 0.75);
  --card-border: rgba(255, 255, 255, 0.07);
  --card-hover: rgba(30, 38, 56, 0.85);
  
  --text-primary: #F1F5F9;
  --text-secondary: #94A3B8;
  --text-muted: #64748B;
  
  --wine-primary: #8B1E3F;
  --wine-secondary: #A32448;
  --wine-glow: rgba(163, 36, 72, 0.4);
  --wine-badge: rgba(139, 30, 63, 0.2);
  --wine-border: rgba(163, 36, 72, 0.35);

  --emerald-success: #10B981;
  --emerald-bg: rgba(16, 185, 129, 0.15);
  --amber-warning: #F59E0B;
  --amber-bg: rgba(245, 158, 11, 0.15);
  --blue-info: #3B82F6;

  --nav-bg: rgba(15, 20, 31, 0.88);
  --nav-border: rgba(255, 255, 255, 0.08);

  --font-sans: -apple-system, BlinkMacSystemFont, "SF Pro Display", "Segoe UI", Roboto, Helvetica, sans-serif;
  --radius-sm: 8px;
  --radius-md: 14px;
  --radius-lg: 20px;
  --radius-full: 9999px;
  --shadow-card: 0 4px 20px rgba(0, 0, 0, 0.4);
}

[data-theme="light"] {
  --bg-primary: #F8FAFC;
  --bg-secondary: #EEF2F6;
  --card-bg: rgba(255, 255, 255, 0.95);
  --card-border: rgba(0, 0, 0, 0.08);
  --card-hover: rgba(255, 255, 255, 1);

  --text-primary: #0F172A;
  --text-secondary: #475569;
  --text-muted: #94A3B8;

  --wine-primary: #7A1631;
  --wine-secondary: #941B3C;
  --wine-glow: rgba(122, 22, 49, 0.25);
  --wine-badge: rgba(122, 22, 49, 0.08);
  --wine-border: rgba(122, 22, 49, 0.25);

  --nav-bg: rgba(255, 255, 255, 0.92);
  --nav-border: rgba(0, 0, 0, 0.08);
  --shadow-card: 0 4px 18px rgba(0, 0, 0, 0.06);
}

* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }

body {
  font-family: var(--font-sans);
  background-color: var(--bg-primary);
  color: var(--text-primary);
  min-height: 100vh;
  display: flex;
  justify-content: center;
  overflow-x: hidden;
  transition: background-color 0.25s ease, color 0.25s ease;
}

#app-shell {
  width: 100%;
  max-width: 480px;
  min-height: 100vh;
  background-color: var(--bg-primary);
  position: relative;
  display: flex;
  flex-direction: column;
  padding-bottom: calc(85px + env(safe-area-inset-bottom));
  box-shadow: 0 0 50px rgba(0, 0, 0, 0.5);
}

.top-bar {
  position: sticky;
  top: 0;
  z-index: 50;
  padding: calc(14px + env(safe-area-inset-top)) 18px 12px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  background: var(--nav-bg);
  border-bottom: 1px solid var(--card-border);
}

.brand-wrapper { display: flex; align-items: center; gap: 10px; }
.brand-icon {
  width: 32px; height: 32px; border-radius: var(--radius-sm);
  background: linear-gradient(135deg, var(--wine-primary), var(--wine-secondary));
  display: flex; align-items: center; justify-content: center;
  color: #FFF; font-weight: 800; font-size: 16px;
  box-shadow: 0 2px 10px var(--wine-glow);
}

.brand-title { font-size: 1.15rem; font-weight: 700; letter-spacing: -0.3px; color: var(--text-primary); }
.brand-title span { color: var(--wine-secondary); }
.top-actions { display: flex; align-items: center; gap: 8px; }

.sync-badge {
  display: flex; align-items: center; gap: 6px;
  font-size: 0.72rem; font-weight: 600; padding: 4px 10px;
  border-radius: var(--radius-full); background: var(--emerald-bg);
  color: var(--emerald-success); border: 1px solid rgba(16, 185, 129, 0.3);
}

.sync-dot {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--emerald-success);
  animation: pulse-dot 2s infinite ease-in-out;
}

@keyframes pulse-dot {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.4; transform: scale(0.8); }
}

.view-section {
  display: none;
  flex-direction: column;
  padding: 16px 18px;
  animation: fadeIn 0.2s ease-out;
}
.view-section.active { display: flex; }

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: translateY(0); }
}

/* Dashboard */
.dashboard-kpi-grid {
  display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; margin-bottom: 18px;
}

.kpi-card {
  background: var(--card-bg); border: 1px solid var(--card-border);
  border-radius: var(--radius-md); padding: 14px; display: flex;
  flex-direction: column; box-shadow: var(--shadow-card);
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
}
.kpi-card .kpi-label { font-size: 0.72rem; font-weight: 600; color: var(--text-muted); text-transform: uppercase; margin-bottom: 6px; }
.kpi-card .kpi-value { font-size: 1.55rem; font-weight: 800; color: var(--text-primary); line-height: 1.1; }
.kpi-card .kpi-sub { font-size: 0.72rem; color: var(--text-secondary); margin-top: 4px; }

.section-heading {
  font-size: 0.95rem; font-weight: 700; letter-spacing: -0.2px; margin-bottom: 12px;
  display: flex; justify-content: space-between; align-items: center;
}

.quick-actions-row {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-bottom: 20px;
}
.quick-btn {
  background: var(--card-bg); border: 1px solid var(--card-border);
  border-radius: var(--radius-md); padding: 14px 8px; display: flex;
  flex-direction: column; align-items: center; text-align: center; gap: 8px;
  cursor: pointer; transition: transform 0.15s, border-color 0.15s;
}
.quick-btn:active { transform: scale(0.96); }
.quick-btn-icon {
  width: 38px; height: 38px; border-radius: var(--radius-sm);
  background: var(--wine-badge); border: 1px solid var(--wine-border);
  color: var(--wine-secondary); display: flex; align-items: center;
  justify-content: center; font-size: 18px;
}
.quick-btn-label { font-size: 0.74rem; font-weight: 600; color: var(--text-secondary); }

/* Search & Filters */
.search-container { position: relative; margin-bottom: 12px; }
.search-input {
  width: 100%; padding: 12px 42px 12px 38px; background: var(--card-bg);
  border: 1px solid var(--card-border); border-radius: var(--radius-full);
  color: var(--text-primary); font-size: 0.88rem; outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
}
.search-input:focus { border-color: var(--wine-secondary); box-shadow: 0 0 0 3px var(--wine-glow); }
.search-icon-left { position: absolute; left: 14px; top: 50%; transform: translateY(-50%); color: var(--text-muted); pointer-events: none; }
.search-barcode-btn {
  position: absolute; right: 10px; top: 50%; transform: translateY(-50%);
  background: var(--wine-badge); border: 1px solid var(--wine-border);
  color: var(--wine-secondary); border-radius: 50%; width: 28px; height: 28px;
  display: flex; align-items: center; justify-content: center; cursor: pointer;
}

.filter-chips-row { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 8px; margin-bottom: 14px; scrollbar-width: none; }
.filter-chips-row::-webkit-scrollbar { display: none; }
.filter-chip {
  padding: 6px 14px; border-radius: var(--radius-full); font-size: 0.78rem;
  font-weight: 600; white-space: nowrap; background: var(--card-bg);
  border: 1px solid var(--card-border); color: var(--text-secondary);
  cursor: pointer; transition: all 0.2s;
}
.filter-chip.active { background: var(--wine-primary); border-color: var(--wine-secondary); color: #FFF; box-shadow: 0 2px 8px var(--wine-glow); }

/* Product Cards */
.product-card-list { display: flex; flex-direction: column; gap: 10px; }
.product-card {
  background: var(--card-bg); border: 1px solid var(--card-border);
  border-radius: var(--radius-md); padding: 12px; display: flex;
  align-items: center; gap: 12px; cursor: pointer;
  transition: transform 0.15s, border-color 0.15s, background-color 0.15s;
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
}
.product-card:hover { border-color: var(--wine-border); background: var(--card-hover); }
.product-card:active { transform: scale(0.98); }

.product-thumb {
  width: 60px; height: 60px; border-radius: var(--radius-sm);
  background: rgba(0, 0, 0, 0.25); border: 1px solid var(--card-border);
  object-fit: cover; flex-shrink: 0; display: flex; align-items: center;
  justify-content: center; overflow: hidden;
}
.product-thumb img { width: 100%; height: 100%; object-fit: cover; }
.product-thumb-fallback { color: var(--text-muted); font-size: 24px; }

.product-info { flex: 1; min-width: 0; }
.product-title {
  font-size: 0.86rem; font-weight: 700; color: var(--text-primary);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-bottom: 3px;
}
.product-meta { display: flex; align-items: center; gap: 8px; font-size: 0.72rem; color: var(--text-secondary); margin-bottom: 4px; }
.product-badge-group { display: flex; align-items: center; gap: 6px; margin-top: 4px; flex-wrap: wrap; }
.badge-pill { padding: 2px 8px; border-radius: var(--radius-full); font-size: 0.66rem; font-weight: 700; text-transform: uppercase; }
.badge-disponivel { background: var(--emerald-bg); color: var(--emerald-success); border: 1px solid rgba(16, 185, 129, 0.3); }
.badge-vendida { background: rgba(148, 163, 184, 0.15); color: var(--text-muted); border: 1px solid rgba(148, 163, 184, 0.25); }
.badge-wear { background: var(--wine-badge); color: var(--wine-secondary); border: 1px solid var(--wine-border); }

/* Bottom Navigation */
.bottom-nav {
  position: fixed; bottom: 0; left: 50%; transform: translateX(-50%);
  width: 100%; max-width: 480px; height: calc(64px + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom); background: var(--nav-bg);
  backdrop-filter: blur(20px); -webkit-backdrop-filter: blur(20px);
  border-top: 1px solid var(--nav-border); display: flex;
  align-items: center; justify-content: space-around; z-index: 100;
}

.nav-item {
  display: flex; flex-direction: column; align-items: center; gap: 3px;
  color: var(--text-muted); font-size: 0.68rem; font-weight: 600;
  cursor: pointer; background: none; border: none; flex: 1; transition: color 0.15s;
}
.nav-item svg { width: 22px; height: 22px; stroke: currentColor; stroke-width: 2; fill: none; }
.nav-item.active { color: var(--wine-secondary); }

.nav-scanner-btn-wrapper { position: relative; top: -16px; flex: 1; display: flex; justify-content: center; }
.nav-scanner-btn {
  width: 58px; height: 58px; border-radius: 50%;
  background: linear-gradient(135deg, var(--wine-secondary), var(--wine-primary));
  border: 4px solid var(--bg-primary); color: #FFF; display: flex;
  align-items: center; justify-content: center; box-shadow: 0 4px 18px var(--wine-glow);
  cursor: pointer; transition: transform 0.2s cubic-bezier(0.34, 1.56, 0.64, 1);
}
.nav-scanner-btn:active { transform: scale(0.92); }
.nav-scanner-btn svg { width: 26px; height: 26px; stroke: #FFF; stroke-width: 2; fill: none; }

/* Modal */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(0, 0, 0, 0.75);
  backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
  z-index: 200; display: none; align-items: flex-end; justify-content: center;
}
.modal-overlay.active { display: flex; }

.modal-sheet {
  width: 100%; max-width: 480px; max-height: 90vh;
  background: var(--bg-primary); border-top-left-radius: var(--radius-lg);
  border-top-right-radius: var(--radius-lg); border: 1px solid var(--card-border);
  border-bottom: none; overflow-y: auto;
  padding: 16px 20px calc(24px + env(safe-area-inset-bottom));
  animation: slideUp 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}
@keyframes slideUp { from { transform: translateY(100%); } to { transform: translateY(0); } }

.modal-drag-pill { width: 40px; height: 4px; background: var(--text-muted); border-radius: var(--radius-full); margin: 0 auto 16px; opacity: 0.5; }
.modal-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; }
.modal-close-btn {
  background: var(--card-bg); border: 1px solid var(--card-border);
  color: var(--text-secondary); border-radius: 50%; width: 32px; height: 32px;
  display: flex; align-items: center; justify-content: center; cursor: pointer;
}

.detail-hero-img-wrap {
  width: 100%; height: 220px; border-radius: var(--radius-md);
  overflow: hidden; background: rgba(0, 0, 0, 0.3); margin-bottom: 16px;
  display: flex; align-items: center; justify-content: center;
}
.detail-hero-img-wrap img { width: 100%; height: 100%; object-fit: cover; }

.detail-lifecycle-gauge {
  background: var(--card-bg); border: 1px solid var(--card-border);
  border-radius: var(--radius-md); padding: 14px; display: flex;
  align-items: center; gap: 16px; margin-bottom: 16px;
}
.gauge-circle {
  width: 52px; height: 52px; border-radius: 50%;
  border: 4px solid var(--wine-secondary); border-top-color: transparent;
  display: flex; align-items: center; justify-content: center;
  font-size: 0.82rem; font-weight: 800; color: var(--text-primary);
  flex-shrink: 0; transform: rotate(-45deg);
}
.gauge-circle span { transform: rotate(45deg); }

.detail-spec-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; margin-bottom: 20px; }
.spec-cell { background: var(--card-bg); border: 1px solid var(--card-border); border-radius: var(--radius-sm); padding: 10px; }
.spec-cell-label { font-size: 0.68rem; color: var(--text-muted); text-transform: uppercase; margin-bottom: 4px; }
.spec-cell-value { font-size: 0.86rem; font-weight: 700; color: var(--text-primary); }

.detail-action-buttons { display: flex; gap: 10px; }
.btn-primary {
  flex: 1; background: linear-gradient(135deg, var(--wine-secondary), var(--wine-primary));
  border: none; color: #FFF; font-weight: 700; font-size: 0.86rem;
  padding: 14px; border-radius: var(--radius-sm); cursor: pointer; box-shadow: 0 4px 12px var(--wine-glow);
}
.btn-secondary {
  background: var(--card-bg); border: 1px solid var(--card-border);
  color: var(--text-primary); font-weight: 700; font-size: 0.86rem;
  padding: 14px; border-radius: var(--radius-sm); cursor: pointer;
}

/* Profile / Settings */
.profile-card {
  background: var(--card-bg); border: 1px solid var(--card-border);
  border-radius: var(--radius-md); padding: 16px; display: flex;
  align-items: center; gap: 14px; margin-bottom: 20px;
}
.profile-avatar {
  width: 52px; height: 52px; border-radius: 50%;
  background: linear-gradient(135deg, var(--wine-secondary), #3B82F6);
  display: flex; align-items: center; justify-content: center;
  font-size: 20px; font-weight: 800; color: #FFF;
}
.settings-group-title { font-size: 0.8rem; font-weight: 700; text-transform: uppercase; color: var(--text-muted); margin-bottom: 10px; }
.settings-box { background: var(--card-bg); border: 1px solid var(--card-border); border-radius: var(--radius-md); padding: 14px; margin-bottom: 20px; }

.theme-switch-segment {
  display: flex; background: rgba(0, 0, 0, 0.25); border: 1px solid var(--card-border);
  border-radius: var(--radius-full); padding: 4px; gap: 4px;
}
.theme-opt-btn {
  flex: 1; padding: 10px; border-radius: var(--radius-full); border: none;
  background: transparent; color: var(--text-secondary); font-size: 0.82rem;
  font-weight: 600; display: flex; align-items: center; justify-content: center;
  gap: 6px; cursor: pointer; transition: all 0.2s;
}
.theme-opt-btn.active {
  background: var(--card-hover); color: var(--wine-secondary);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2); border: 1px solid var(--wine-border);
}

.setting-toggle-row { display: flex; align-items: center; justify-content: space-between; padding: 10px 0; border-bottom: 1px solid var(--card-border); }
.setting-toggle-row:last-child { border-bottom: none; }
.toggle-switch {
  width: 44px; height: 24px; background: var(--card-border);
  border-radius: var(--radius-full); position: relative; cursor: pointer; transition: background 0.2s;
}
.toggle-switch.active { background: var(--wine-secondary); }
.toggle-thumb {
  width: 18px; height: 18px; background: #FFF; border-radius: 50%;
  position: absolute; top: 3px; left: 3px; transition: transform 0.2s;
}
.toggle-switch.active .toggle-thumb { transform: translateX(20px); }

/* Scanner view */
#scanner-camera-box {
  width: 100%; height: 260px; background: #000; border-radius: var(--radius-md);
  overflow: hidden; position: relative; margin-bottom: 16px; display: flex;
  align-items: center; justify-content: center;
}
.scanner-reticle {
  width: 200px; height: 140px; border: 2px dashed var(--wine-secondary);
  border-radius: var(--radius-sm); position: relative;
}
.scanner-laser {
  position: absolute; width: 100%; height: 2px;
  background: var(--wine-secondary); box-shadow: 0 0 10px var(--wine-secondary);
  animation: laser-scan 2s infinite ease-in-out;
}
@keyframes laser-scan { 0%, 100% { top: 10%; } 50% { top: 90%; } }
