:root {
  --bg-color: #121212;
  --glass-bg: rgba(255, 255, 255, 0.1);
  --glass-border: rgba(255, 255, 255, 0.2);
  --primary-color: #4caf50;
  --danger-color: #f44336;
  --text-color: #ffffff;
  --text-secondary: #aaaaaa;
}

body {
  margin: 0;
  font-family: 'Inter', sans-serif;
  background-color: var(--bg-color);
  color: var(--text-color);
  min-height: 100vh;
  overflow-y: auto;
  /* Window Scroll */
}

#app {
  display: flex;
  flex-direction: column;
  padding: 20px;
  /* Safe Area padding for Notches / StatusBar on mobile */
  padding-top: calc(20px + env(safe-area-inset-top, 20px));
  padding-bottom: calc(20px + env(safe-area-inset-bottom, 0px));
  /* Overflow handled by body */
}

/* Hide Scrollbar Globally */
html::-webkit-scrollbar,
body::-webkit-scrollbar {
  display: none;
}

html,
body {
  scrollbar-width: none;
}

/* Visibility Helpers */
.desktop-only {
  display: block;
}

.mobile-only {
  display: none;
}

@media (max-width: 768px) {
  .desktop-only {
    display: none !important;
  }

  .mobile-only {
    display: block !important;
  }
}

/* Glassmorphism Cards */
/* Glassmorphism Cards */
.glass-card {
  background: var(--glass-bg);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border: 1px solid var(--glass-border);
  border-radius: 16px;
  padding: 20px;
  margin-bottom: 20px;
  box-shadow: 0 4px 30px rgba(0, 0, 0, 0.1);
  position: relative;
  z-index: 1;
}

/* Auth Form */
.auth-container {
  display: flex;
  flex-direction: column;
  justify-content: center;
  height: 100%;
}

input {
  width: 100%;
  padding: 12px;
  margin: 10px 0;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--glass-border);
  border-radius: 8px;
  color: white;
  font-size: 16px;
  box-sizing: border-box;
}

button {
  width: 100%;
  padding: 14px;
  margin-top: 10px;
  background: var(--primary-color);
  color: white;
  border: none;
  border-radius: 8px;
  font-size: 16px;
  font-weight: bold;
  cursor: pointer;
  transition: transform 0.1s;
}

button:active {
  transform: scale(0.98);
}

button.secondary {
  background: transparent;
  border: 1px solid var(--glass-border);
}

/* Main Dashboard */
.status-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
  position: relative;
  z-index: 100 !important;
}

.status-indicator {
  display: flex;
  align-items: center;
  font-size: 14px;
  color: var(--text-secondary);
}

.status-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background-color: var(--danger-color);
  margin-right: 8px;
}

.status-dot.online {
  background-color: var(--primary-color);
}

.gate-control {
  text-align: center;
  margin: 40px 0;
}

.big-button {
  width: 150px;
  height: 150px;
  border-radius: 50%;
  background: linear-gradient(145deg, #1e1e1e, #2a2a2a);
  border: 4px solid var(--primary-color);
  box-shadow: 0 0 20px rgba(76, 175, 80, 0.3);
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto;
  cursor: pointer;
  transition: all 0.3s;
}

.big-button:active {
  transform: scale(0.95);
  box-shadow: 0 0 10px rgba(76, 175, 80, 0.5);
}

.big-button svg {
  width: 60px;
  height: 60px;
  fill: var(--primary-color);
}

.big-button.danger {
  border-color: var(--danger-color);
  box-shadow: 0 0 20px rgba(244, 67, 54, 0.3);
  position: relative;
}

.big-button.danger:active {
  box-shadow: 0 0 10px rgba(244, 67, 54, 0.5);
}

.big-button.danger svg {
  fill: var(--danger-color);
}

.big-button.danger::after {
  content: '';
  position: absolute;
  top: -8px;
  left: -8px;
  right: -8px;
  bottom: -8px;
  border-radius: 50%;
  border: 4px solid transparent;
  border-top-color: var(--danger-color);
  border-bottom-color: var(--danger-color);
  animation: spin 2s linear infinite;
  opacity: 0.8;
  pointer-events: none;
}

/* Logs List */
.logs-list {
  list-style: none;
  padding: 0;
  margin: 0;
}

.log-item {
  display: flex;
  justify-content: space-between;
  padding: 12px 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
  font-size: 14px;
}

.log-time {
  color: var(--text-secondary);
}

/* Toast */
.toast-container {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 1000;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.toast {
  background: #333;
  color: white;
  padding: 12px 24px;
  border-radius: 20px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
  opacity: 0;
  transform: translateY(20px);
  animation: slideIn 0.3s forwards;
}

@keyframes slideIn {
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* Utility */
.hidden {
  display: none !important;
}

.text-center {
  text-align: center;
}

.mt-20 {
  margin-top: 20px;
}

.w-100 {
  width: 100%;
}

.mb-10 {
  margin-bottom: 10px;
}

/* Admin Panel Styles */
.admin-tabs {
  display: flex;
  gap: 10px;
  margin-bottom: 20px;
}

.tab-btn {
  flex: 1;
  padding: 10px;
  background: transparent;
  border: 1px solid var(--glass-border);
  color: var(--text-secondary);
  border-radius: 8px;
}

.tab-btn.active {
  background: var(--primary-color);
  color: white;
  border-color: var(--primary-color);
}

.tab-content {
  display: none;
}

.tab-content.active {
  display: block;
  animation: fadeIn 0.3s;
}

.stats-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 15px;
}

.stat-card {
  text-align: center;
  padding: 15px;
}

.stat-card h4 {
  margin: 0 0 10px 0;
  color: var(--text-secondary);
  font-size: 0.9rem;
}

.stat-card span {
  font-size: 1.5rem;
  font-weight: bold;
}

.btn-danger {
  background-color: var(--danger-color);
}

/* Desktop Responsive Layout (PC Interface) */
/* Desktop overrides for Tabs removed to allow Tab Navigation on PC */
@media (min-width: 1024px) {
  #app {
    max-width: 1200px;
    margin: 0 auto;
    width: 100%;
  }
}

@media (max-width: 480px) {
  .big-button {
    width: 120px;
    height: 120px;
  }
}

/* Full Registration Form */
.form-section {
  margin-bottom: 20px;
  padding-bottom: 20px;
  border-bottom: 1px solid var(--glass-border);
}

.form-section h4 {
  color: var(--primary-color);
  margin-bottom: 15px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.form-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 15px;
}

.form-group {
  display: flex;
  flex-direction: column;
}

.form-group label {
  font-size: 0.85rem;
  color: var(--text-secondary);
  margin-bottom: 5px;
}

.file-upload-box {
  border: 1px dashed var(--glass-border);
  padding: 10px;
  border-radius: 8px;
  text-align: center;
  cursor: pointer;
  background: rgba(255, 255, 255, 0.02);
}

.file-upload-box:hover {
  background: rgba(255, 255, 255, 0.05);
}

.tag-reader-box {
  background: #000;
  padding: 15px;
  border-radius: 8px;
  border: 1px solid #333;
  margin-top: 10px;
}

.tag-display {
  display: flex;
  gap: 10px;
  margin-top: 10px;
}

/* Desktop Form Grid */
/* Input Select Fix */
select {
  appearance: none;
  -webkit-appearance: none;
  -moz-appearance: none;
  background-image: url("data:image/svg+xml;charset=UTF-8,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='white'%3e%3cpath d='M7 10l5 5 5-5z'/%3e%3c/svg%3e");
  background-repeat: no-repeat;
  background-position: right 10px center;
  background-size: 12px;
}

select option {
  background-color: #1e1e1e;
  color: white;
}

/* Modal Overlay Fix */
.modal {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(0, 0, 0, 0.8);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 2000;
  backdrop-filter: blur(5px);
}

.modal.hidden {
  display: none !important;
}

@media (min-width: 768px) {
  .form-grid {
    grid-template-columns: 1fr 1fr;
  }

  .form-grid.three-col {
    grid-template-columns: 1fr 1fr 1fr;
  }
}

@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(10px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* Table & Badges */
.glass-card-hover {
  transition: background 0.2s;
}

.glass-card-hover:hover {
  background: rgba(255, 255, 255, 0.15);
  cursor: pointer;
}

.badge {
  padding: 4px 8px;
  border-radius: 4px;
  font-size: 0.75rem;
  background: #333;
  color: #ccc;
  display: inline-block;
}

.badge.verified {
  background: var(--primary-color);
  color: white;
}

.badge.pending {
  background: #ff9800;
  color: black;
}

.users-table-header div {
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

/* --- Modal Tabs Redesign --- */
.modal-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 20px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
  padding-bottom: 15px;
}

.modal-tab-btn {
  flex: 1 1 auto;
  width: auto !important;
  /* Override button width: 100% */
  margin-top: 0 !important;
  min-width: 100px;
  padding: 10px 15px;
  background: rgba(255, 255, 255, 0.05) !important;
  border: 1px solid rgba(255, 255, 255, 0.1) !important;
  border-radius: 8px;
  color: #ccc !important;
  font-size: 0.9rem;
  cursor: pointer;
  font-weight: 500;
  text-align: center;
  transition: all 0.2s;
}

.modal-tab-btn:hover {
  background: rgba(255, 255, 255, 0.1) !important;
  color: white !important;
}

.modal-tab-btn.active {
  background: var(--primary-color) !important;
  color: white !important;
  border-color: var(--primary-color) !important;
  font-weight: bold;
}

/* Hide inactive content */
.modal-tab-content {
  display: none !important;
}

.modal-tab-content.active {
  display: block !important;
  animation: fadeIn 0.3s ease !important;
  /* Reset animation override */
}

/* Edit Button Style */
#btn-toggle-edit {
  width: auto !important;
  padding: 6px 14px;
  font-size: 0.9rem;
  margin: 0 !important;
  cursor: pointer !important;
}

/* Mobile Grid for Tabs */
@media (max-width: 600px) {
  .modal-tabs {
    display: grid;
    grid-template-columns: 1fr 1fr;
  }
}

/* PC Tabs - Mobile Like Style */
.admin-tabs {
  display: flex !important;
  justify-content: space-between !important;
  gap: 0 !important;
  margin-bottom: 20px !important;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1) !important;
  background: transparent !important;
  padding: 0 !important;
}

.admin-tabs .tab-btn {
  flex: 1 !important;
  background: transparent !important;
  border: none !important;
  border-bottom: 3px solid transparent !important;
  color: #888 !important;
  padding: 15px !important;
  font-size: 1rem !important;
  font-weight: 500 !important;
  cursor: pointer !important;
  transition: all 0.3s ease !important;
  border-radius: 0 !important;
  display: flex !important;
  align-items: center !important;
  justify-content: center !important;
  gap: 8px !important;
  box-shadow: none !important;
}

.admin-tabs .tab-btn:hover {
  background: rgba(255, 255, 255, 0.02) !important;
  color: #ccc !important;
}

.admin-tabs .tab-btn.active {
  background: transparent !important;
  border-bottom: 3px solid #ff9800 !important;
  /* Orange highlight */
  color: white !important;
}

/* Modal Tab Btn (Inside Task Manager) */
.modal-tabs {
  display: flex;
  gap: 10px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
  margin-bottom: 10px;
}

.modal-tab-btn {
  background: transparent;
  border: none;
  padding: 10px 15px;
  color: #aaa;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  transition: all 0.3s;
}

.modal-tab-btn.active {
  color: #2196f3;
  border-bottom: 2px solid #2196f3;
  font-weight: bold;
}

/* Override Inline Styles for Task Button to match Tabs */
#btn-open-tasks-manager {
  background-color: transparent !important;
  color: #888 !important;
  border-bottom: 3px solid transparent !important;
  border-radius: 0 !important;
  margin: 0 !important;
}

#btn-open-tasks-manager:hover {
  color: #ff9800 !important;
  border-bottom-color: #ff9800 !important;
}

/* Toast High Z-Index Override */
#toast-container {
  z-index: 10000 !important;
}

/* Small Buttons Override */
.btn-sm {
  width: auto !important;
  display: inline-flex !important;
  margin: 0 !important;
  min-width: 0 !important;
}

/* User List Responsive Styles */
.users-grid-header {
  display: grid;
  grid-template-columns: 2fr 100px 100px auto;
  gap: 10px;
  padding: 10px;
  font-weight: bold;
  color: #aaa;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

/* --- GATE STATUS ANIMATIONS (INJECTED) --- */
@keyframes spin {
  0% {
    transform: rotate(0deg);
  }

  100% {
    transform: rotate(360deg);
  }
}

.big-button.status-online {
  border-color: #4caf50 !important;
  box-shadow: 0 0 30px rgba(76, 175, 80, 0.5);
  position: relative;
}

.big-button.status-online::after {
  content: '';
  position: absolute;
  top: -8px;
  left: -8px;
  right: -8px;
  bottom: -8px;
  border-radius: 50%;
  border: 4px solid transparent;
  border-top-color: #4caf50;
  border-bottom-color: #4caf50;
  animation: spin 2s linear infinite;
  opacity: 0.8;
  pointer-events: none;
}

.big-button.status-offline {
  border-color: #f44336 !important;
  box-shadow: none;
  opacity: 0.6;
  filter: grayscale(100%);
  cursor: not-allowed !important;
  pointer-events: none;
}

.big-button.status-offline svg {
  fill: #f44336 !important;
}

/* Notification Dropdown Responsive Fix */
#notification-center {
  position: absolute;
  top: 40px;
  right: 0;
  width: 300px;
  max-height: 400px;
  overflow-y: auto;
  z-index: 3000;
  padding: 0;
}

@media (max-width: 768px) {
  #notification-center {
    position: fixed !important;
    top: 80px !important;
    /* Below the header */
    left: 50% !important;
    transform: translateX(-50%) !important;
    /* Center horizontally only */
    width: 90% !important;
    max-width: 350px !important;
    right: auto !important;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5);
    border: 1px solid rgba(255, 255, 255, 0.2);
    background: rgba(0, 0, 0, 0.7) !important;
    backdrop-filter: blur(15px);
    /* Keep blur */
  }
}

.big-button.status-error {
  border-color: #ff9800 !important;
  box-shadow: 0 0 10px rgba(255, 152, 0, 0.3);
  cursor: not-allowed !important;
  pointer-events: none;
}

.big-button.status-error svg {
  fill: #ff9800 !important;
}

/* ----------------------------------------- */

.user-row {
  display: grid;
  grid-template-columns: 2fr 100px 100px auto;
  gap: 10px;
  padding: 15px 10px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
  align-items: center;
}

.user-row:hover {
  background: rgba(255, 255, 255, 0.03);
}

.user-info-group {
  display: contents;
  /* On Desktop, just be part of grid */
}

@media (max-width: 768px) {
  .users-grid-header {
    display: none;
  }

  .user-row {
    display: flex !important;
    flex-wrap: wrap !important;
    padding: 10px !important;
    gap: 8px !important;
    grid-template-columns: none !important;
  }

  /* On Mobile, group becomes a flex line */
  .user-info-group {
    display: flex !important;
    align-items: center;
    gap: 8px;
    flex: 1 1 100%;
    /* Full width row */
    overflow: hidden;
  }

  .user-name-col {
    flex: 0 1 auto;
    font-size: 0.95rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .user-role-col {
    flex: 0 0 auto;
  }

  .user-date-col {
    flex: 0 0 auto;
    font-size: 0.75rem;
    color: #888;
    margin-left: auto;
  }

  .user-actions {
    flex: 1 1 100%;
    /* Force new line */
    margin-top: 5px;
    justify-content: flex-end !important;
    /* Right align buttons? Or space-between? User said "cabe um do lado do outro". */
    /* If full width, justify-end puts them to the right. */
    /* To put them left/center: justify-content: flex-start; */
    /* Screenshot Image 8 shows them full width stacked. */
    /* I want them inline. justify-content: flex-start or flex-end. */
    display: flex;
    gap: 8px;
  }
}

/* Compact Scrollbar for Task List */
.task-list::-webkit-scrollbar {
  width: 6px;
}

.task-list::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.2);
  border-radius: 3px;
}

/* Sub-Tabs Navigation (Resident Profile) */
.sub-tabs-nav {
  display: flex;
  gap: 10px;
  margin-bottom: 15px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
  padding-bottom: 10px;
}

.sub-tab-btn {
  background: transparent !important;
  border: none !important;
  padding: 8px 12px !important;
  color: #888 !important;
  cursor: pointer;
  font-size: 0.9rem !important;
  border-radius: 6px !important;
  width: auto !important;
  margin-top: 0 !important;
  transition: all 0.2s;
}

.sub-tab-btn:hover {
  background: rgba(255, 255, 255, 0.05) !important;
  color: #ccc !important;
}

.sub-tab-btn.active {
  background: rgba(76, 175, 80, 0.1) !important;
  color: var(--primary-color) !important;
  font-weight: 500 !important;
}

/* History Task Date Grouping */
.task-date-group {
  margin-bottom: 10px;
}

.task-date-group>div:first-child:hover {
  background: rgba(255, 255, 255, 0.1) !important;
}

.date-group-content {
  animation: fadeIn 0.2s ease;
}

.date-group-content>div:last-child {
  border-bottom: none !important;
}

/* Modal Close Button Redesign */
.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
}

.close-btn {
  width: 32px !important;
  height: 32px !important;
  padding: 0 !important;
  margin: 0 !important;
  background: var(--danger-color) !important;
  color: white !important;
  border-radius: 50%;
  font-size: 1.2rem;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2);
}

.close-btn:hover {
  background: #d32f2f !important;
  transform: scale(1.1);
}


/* Notification Dropdown Desktop Fix */
#notification-center {
  background: #1e1e1e !important;
  border: 1px solid #333;
  box-shadow: 0 5px 15px rgba(0, 0, 0, 0.5);
}

/* Animacoes do Music Spinner Injection */
@keyframes rotate {
  100% {
    transform: rotate(360deg);
  }
}

@keyframes dash {
  0% {
    stroke-dasharray: 1, 200;
    stroke-dashoffset: 0;
  }

  50% {
    stroke-dasharray: 89, 200;
    stroke-dashoffset: -35px;
  }

  100% {
    stroke-dasharray: 89, 200;
    stroke-dashoffset: -124px;
  }
}