@import url('https://fonts.googleapis.com/css2?family=Outfit:wght@300;400;500;600;700&display=swap');

:root {
  --font-sans: 'Outfit', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  
  /* Color Palette (Deep dark theme with vibrant accents) */
  --bg-app: hsl(222, 47%, 7%);
  --bg-card: hsla(222, 47%, 11%, 0.75);
  --bg-card-hover: hsla(222, 47%, 15%, 0.85);
  --bg-input: hsla(222, 47%, 4%, 0.5);
  
  --border-color: hsla(217, 24%, 32%, 0.25);
  --border-color-focus: hsla(250, 100%, 65%, 0.5);
  
  --text-primary: hsl(210, 40%, 98%);
  --text-secondary: hsl(215, 20%, 75%);
  --text-muted: hsl(215, 15%, 55%);
  
  --primary: hsl(250, 100%, 65%);
  --primary-hover: hsl(250, 100%, 70%);
  --primary-glow: hsla(250, 100%, 65%, 0.35);
  
  --success: hsl(142, 70%, 45%);
  --success-glow: hsla(142, 70%, 45%, 0.25);
  
  --warning: hsl(38, 92%, 50%);
  --danger: hsl(350, 80%, 50%);
  
  --gradient-primary: linear-gradient(135deg, hsl(250, 100%, 65%) 0%, hsl(280, 85%, 55%) 100%);
  --gradient-accent: linear-gradient(135deg, hsl(180, 100%, 40%) 0%, hsl(210, 100%, 50%) 100%);
  --gradient-success: linear-gradient(135deg, hsl(142, 70%, 45%) 0%, hsl(160, 80%, 40%) 100%);
  
  --shadow-sm: 0 2px 8px -2px rgba(0, 0, 0, 0.5);
  --shadow-md: 0 8px 30px -4px rgba(0, 0, 0, 0.6);
  --shadow-lg: 0 16px 40px -6px rgba(0, 0, 0, 0.8);
  
  --radius-sm: 8px;
  --radius-md: 16px;
  --radius-lg: 24px;
  
  --transition-fast: 0.15s ease;
  --transition-normal: 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

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

body {
  font-family: var(--font-sans);
  background-color: var(--bg-app);
  color: var(--text-primary);
  min-height: 100vh;
  min-height: -webkit-fill-available; /* mobile viewport height fix */
  display: flex;
  flex-direction: column;
  overflow-x: hidden;
  background-image: 
    radial-gradient(at 0% 0%, hsla(253, 62%, 18%, 0.35) 0px, transparent 50%),
    radial-gradient(at 100% 100%, hsla(210, 100%, 12%, 0.3) 0px, transparent 50%);
  background-attachment: fixed;
}

/* Typography */
h1, h2, h3, h4 {
  font-weight: 600;
  letter-spacing: -0.02em;
  line-height: 1.25;
}

p {
  color: var(--text-secondary);
  line-height: 1.6;
}

/* Header / Navigation */
header {
  background: hsla(222, 47%, 5%, 0.8);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border-color);
  padding: 1.25rem 1rem;
  position: sticky;
  top: 0;
  z-index: 100;
}

.header-container {
  max-width: 600px;
  margin: 0 auto;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.logo {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-weight: 700;
  font-size: 1.25rem;
  background: var(--gradient-primary);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.nav-links {
  display: flex;
  gap: 1rem;
}

.nav-link {
  color: var(--text-secondary);
  text-decoration: none;
  font-size: 0.9rem;
  font-weight: 500;
  padding: 0.5rem 0.75rem;
  border-radius: var(--radius-sm);
  transition: var(--transition-fast);
}

.nav-link:hover, .nav-link.active {
  color: var(--text-primary);
  background-color: hsla(222, 47%, 15%, 0.6);
}

/* Layout container */
main {
  flex: 1;
  width: 100%;
  max-width: 600px;
  margin: 0 auto;
  padding: 1.5rem 1rem 3rem 1rem;
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

/* Cards (Glassmorphism) */
.card {
  background: var(--bg-card);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 1.5rem;
  box-shadow: var(--shadow-md);
  transition: transform var(--transition-normal), border-color var(--transition-normal);
}

.card:hover {
  border-color: hsla(217, 24%, 32%, 0.4);
}

/* Segmented Control / Tabs */
.tabs-container {
  background: hsla(222, 47%, 4%, 0.6);
  border: 1px solid var(--border-color);
  border-radius: 12px;
  padding: 0.25rem;
  display: flex;
  gap: 0.25rem;
}

.tab-btn {
  flex: 1;
  background: transparent;
  border: none;
  color: var(--text-secondary);
  padding: 0.75rem 1rem;
  font-size: 0.95rem;
  font-weight: 600;
  font-family: var(--font-sans);
  border-radius: 10px;
  cursor: pointer;
  transition: var(--transition-normal);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
}

.tab-btn:hover {
  color: var(--text-primary);
}

.tab-btn.active {
  background: var(--primary);
  color: var(--text-primary);
  box-shadow: 0 4px 12px var(--primary-glow);
}

/* Form Styles */
.form-group {
  margin-bottom: 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.form-group label {
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
}

select, input[type="text"], input[type="tel"], input[type="email"], input[type="password"] {
  background-color: var(--bg-input);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-family: var(--font-sans);
  font-size: 1rem;
  padding: 0.85rem 1rem;
  outline: none;
  transition: var(--transition-fast);
  width: 100%;
}

select:focus, input[type="text"]:focus, input[type="tel"]:focus, input[type="email"]:focus, input[type="password"]:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-glow);
}

select {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 24 24' stroke='white'%3E%3Cpath stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='M19 9l-7 7-7-7'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 1rem center;
  background-size: 1.2rem;
  padding-right: 2.5rem;
}

/* Camera Component */
.camera-container {
  background-color: var(--bg-input);
  border: 2px dashed var(--border-color);
  border-radius: var(--radius-md);
  position: relative;
  overflow: hidden;
  aspect-ratio: 4 / 3;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.75rem;
  margin-bottom: 1.5rem;
  transition: var(--transition-normal);
}

.camera-container.has-preview {
  border-style: solid;
  border-color: var(--border-color);
}

.camera-container.has-preview .camera-placeholder {
  display: none !important;
}

.camera-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: 1rem;
  z-index: 2;
  pointer-events: none;
}

.camera-shutter-flash {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: white;
  opacity: 0;
  z-index: 5;
  pointer-events: none;
}

.camera-shutter-flash.flash-active {
  animation: flash-anim 0.3s ease-out;
}

@keyframes flash-anim {
  0% { opacity: 0.8; }
  100% { opacity: 0; }
}

#camera-video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  z-index: 1;
}

#camera-preview {
  width: 100%;
  height: 100%;
  object-fit: cover;
  z-index: 1;
}

.camera-placeholder {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  text-align: center;
  padding: 2rem;
  cursor: pointer;
  width: 100%;
  height: 100%;
  z-index: 2;
}

.camera-placeholder svg {
  width: 3rem;
  height: 3rem;
  margin-bottom: 0.5rem;
  color: var(--text-secondary);
}

.camera-actions-floating {
  position: absolute;
  bottom: 1rem;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 0.75rem;
  z-index: 10;
}

/* Buttons */
.btn {
  border: none;
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-family: var(--font-sans);
  font-size: 1rem;
  font-weight: 600;
  padding: 0.85rem 1.5rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  transition: var(--transition-normal);
  width: 100%;
  box-shadow: var(--shadow-sm);
}

.btn:active {
  transform: scale(0.98);
}

.btn-primary {
  background: var(--gradient-primary);
}

.btn-primary:hover:not(:disabled) {
  opacity: 0.95;
  box-shadow: 0 6px 20px var(--primary-glow);
}

.btn-success {
  background: var(--gradient-success);
}

.btn-success:hover:not(:disabled) {
  opacity: 0.95;
  box-shadow: 0 6px 20px var(--success-glow);
}

.btn-secondary {
  background-color: hsla(222, 47%, 18%, 0.6);
  border: 1px solid var(--border-color);
}

.btn-secondary:hover:not(:disabled) {
  background-color: hsla(222, 47%, 22%, 0.8);
  color: var(--text-primary);
}

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

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn-circle {
  border-radius: 50%;
  width: 3rem;
  height: 3rem;
  padding: 0;
}

.btn-camera-trigger {
  background: white;
  border: 4px solid rgba(0, 0, 0, 0.2);
  width: 3.5rem;
  height: 3.5rem;
  border-radius: 50%;
}

.btn-camera-trigger:active {
  transform: scale(0.9) translateX(-50%); /* scale tweak to keep layout correct with translate */
}

/* Resident List / Search Items */
.search-container {
  margin-bottom: 1.25rem;
}

.delivery-list {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.delivery-item {
  background: hsla(222, 47%, 6%, 0.4);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  padding: 0.85rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  transition: var(--transition-fast);
}

.delivery-item:hover {
  border-color: hsla(217, 24%, 32%, 0.5);
  background: hsla(222, 47%, 10%, 0.5);
}

.delivery-info {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex: 1;
}

.delivery-thumb {
  width: 3.5rem;
  height: 3.5rem;
  border-radius: var(--radius-sm);
  object-fit: cover;
  background-color: var(--bg-input);
  border: 1px solid var(--border-color);
  cursor: zoom-in;
}

.delivery-details h4 {
  font-size: 0.95rem;
  color: var(--text-primary);
}

.delivery-details p {
  font-size: 0.8rem;
  color: var(--text-muted);
}

.badge {
  display: inline-block;
  padding: 0.2rem 0.5rem;
  border-radius: 4px;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
}

.badge-pending {
  background-color: hsla(38, 92%, 50%, 0.15);
  color: var(--warning);
}

.badge-delivered {
  background-color: hsla(142, 70%, 45%, 0.15);
  color: var(--success);
}

/* Resident dynamic list for registration phone numbers */
.phone-list {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.phone-input-row {
  display: flex;
  gap: 0.5rem;
}

/* Status Notifications / Alerts */
.toast {
  position: fixed;
  top: 2rem;
  left: 50%;
  transform: translateX(-50%) translateY(-100px);
  padding: 1rem 1.5rem;
  border-radius: var(--radius-sm);
  color: white;
  font-weight: 500;
  box-shadow: var(--shadow-lg);
  z-index: 1000;
  transition: transform var(--transition-normal);
  display: flex;
  align-items: center;
  gap: 0.5rem;
  width: 90%;
  max-width: 400px;
}

.toast.show {
  transform: translateX(-50%) translateY(0);
}

.toast-success {
  background: var(--gradient-success);
}

.toast-error {
  background: var(--danger);
}

.toast-info {
  background: var(--primary);
}

/* Spinner / Loading */
.spinner {
  width: 1.25rem;
  height: 1.25rem;
  border: 2px solid rgba(255, 255, 255, 0.3);
  border-radius: 50%;
  border-top-color: white;
  animation: spin 0.8s linear infinite;
}

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

/* Native/fallback modal for full image view */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(0, 0, 0, 0.95);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 1rem;
}

.modal-content {
  max-width: 100%;
  max-height: 80vh;
  object-fit: contain;
  border-radius: var(--radius-sm);
}

.modal-close {
  position: absolute;
  top: 1.5rem;
  right: 1.5rem;
  background: none;
  border: none;
  color: white;
  cursor: pointer;
}

.modal-close svg {
  width: 2rem;
  height: 2rem;
}

/* Views switcher configuration */
.view-panel {
  display: none;
}

.view-panel.active {
  display: block;
}

/* Empty state styling */
.empty-state {
  text-align: center;
  padding: 3rem 1.5rem;
  color: var(--text-muted);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.75rem;
}

.empty-state svg {
  width: 3rem;
  height: 3rem;
  color: var(--text-secondary);
  opacity: 0.5;
}

/* Config status bar */
.config-status-bar {
  background-color: hsla(38, 92%, 50%, 0.1);
  border: 1px solid hsla(38, 92%, 50%, 0.2);
  color: var(--warning);
  padding: 0.75rem;
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 1rem;
}

.config-status-bar.configured {
  background-color: hsla(142, 70%, 45%, 0.1);
  border: 1px solid hsla(142, 70%, 45%, 0.2);
  color: var(--success);
}

/* Auth / Login Page Styles */
.login-body {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
}

.auth-card {
  width: 100%;
  animation: card-appear 0.4s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes card-appear {
  from {
    opacity: 0;
    transform: translateY(20px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* User Info Bar */
.user-info-bar {
  background: hsla(222, 47%, 9%, 0.95);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border-color);
  padding: 0.65rem 1rem;
  z-index: 90;
}

.user-info-container {
  max-width: 600px;
  margin: 0 auto;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
}

.user-details-wrapper {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.user-avatar {
  width: 2.2rem;
  height: 2.2rem;
  border-radius: 50%;
  background: var(--gradient-primary);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 0.9rem;
  color: white;
  box-shadow: 0 2px 8px var(--primary-glow);
}

.user-text-info {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
}

.user-name {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text-primary);
}

.user-role-badge {
  font-size: 0.65rem;
  padding: 0.1rem 0.35rem;
  width: max-content;
  border-radius: 4px;
}

.user-role-badge.admin {
  background-color: hsla(250, 100%, 65%, 0.2);
  color: hsl(250, 100%, 75%);
}

.user-role-badge.master {
  background: linear-gradient(135deg, hsla(38, 92%, 50%, 0.2), hsla(320, 80%, 50%, 0.2));
  color: hsl(38, 95%, 65%);
  border: 1px solid hsla(38, 92%, 50%, 0.35);
}

.user-role-badge.porteiro, .user-role-badge.operacao {
  background-color: hsla(142, 70%, 45%, 0.2);
  color: hsl(142, 70%, 65%);
}

.btn-logout {
  width: auto;
  padding: 0.45rem 0.85rem;
  font-size: 0.8rem;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  gap: 0.35rem;
}

/* Dashboard Analytics Styles */
.dashboard-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 1rem;
}

.metric-card {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 1.25rem;
  transition: transform var(--transition-normal);
}

.metric-card:hover {
  transform: translateY(-4px);
}

.metric-icon {
  width: 3.25rem;
  height: 3.25rem;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.metric-data {
  display: flex;
  flex-direction: column;
}

.metric-label {
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.metric-value {
  font-size: 1.8rem;
  font-weight: 700;
  color: var(--text-primary);
  margin-top: 0.15rem;
}

/* Custom Chart progress layouts */
.chart-bar-container {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.chart-bar-labels {
  display: flex;
  justify-content: space-between;
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--text-secondary);
}

.chart-progress-track {
  height: 12px;
  background-color: var(--bg-input);
  border-radius: 6px;
  overflow: hidden;
  border: 1px solid var(--border-color);
  position: relative;
}

.chart-progress-fill {
  height: 100%;
  background: var(--gradient-primary);
  border-radius: 6px;
  transition: width 0.6s cubic-bezier(0.16, 1, 0.3, 1);
}

.chart-bar-footer {
  display: flex;
  justify-content: space-between;
  font-size: 0.75rem;
  font-weight: 500;
  margin-top: 0.25rem;
}

/* Hourly distribution rows */
.hourly-chart {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.hourly-row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.hourly-time {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-secondary);
  width: 3.5rem;
  flex-shrink: 0;
}

.hourly-track {
  flex: 1;
  height: 8px;
  background-color: var(--bg-input);
  border-radius: 4px;
  overflow: hidden;
  position: relative;
}

.hourly-fill {
  height: 100%;
  background: var(--gradient-accent);
  border-radius: 4px;
  transition: width 0.5s ease;
}

.hourly-count {
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--text-primary);
  background: hsla(222, 47%, 15%, 0.8);
  padding: 0.15rem 0.5rem;
  border-radius: 10px;
  min-width: 1.8rem;
  text-align: center;
  border: 1px solid var(--border-color);
}

/* Resident List Actions styling */
.resident-actions {
  display: flex;
  gap: 0.5rem;
}

.btn-small-icon {
  width: 2.2rem;
  height: 2.2rem;
  padding: 0;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
}

.btn-small-icon svg {
  width: 1.1rem;
  height: 1.1rem;
}

