/* =========================================
   GLOBAL RESET & CORE LAYOUT
   ========================================= */
* { box-sizing: border-box; transition: all 0.2s ease-out; }

html, body {
  margin: 0; padding: 0; width: 100%;
  height: 100vh; 
  height: calc(var(--vh, 1vh) * 100);
  background: linear-gradient(to bottom, #000000 0%, #330B0D 50%, #000000 100%);
  color: #e0e0e0;
  font-family: "Inter", sans-serif;
  display: flex; justify-content: center; align-items: center;
  overflow: hidden; 
}

/* =========================================
   ACCESSIBILITY & UTILITIES
   ========================================= */
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border-width: 0;
}

/* Button Reset for converted divs */
button {
  font-family: inherit;
}

/* =========================================
   BACKGROUND ANIMATION
   ========================================= */
.liquid-background {
  position: fixed; top: 0; left: 0; width: 100%; height: 100%;
  z-index: 1; overflow: hidden;
}

.liquid-shape {
  position: absolute; border-radius: 50%;
  filter: blur(100px); opacity: 0.7;
}

.shape1 {
  width: 350px; height: 350px; background: #9A2126;
  top: -100px; left: -150px; animation: move1 25s infinite alternate;
}

.shape2 {
  width: 250px; height: 250px; background: #4a148c;
  bottom: -50px; right: -80px; animation: move2 30s infinite alternate;
}

@keyframes move1 { from { transform: translate(0, 0) rotate(0deg); } to { transform: translate(200px, 300px) rotate(180deg); } }
@keyframes move2 { from { transform: translate(0, 0) rotate(0deg); } to { transform: translate(-250px, -200px) rotate(-180deg); } }

/* =========================================
   MAIN APP CONTAINER (GLASSMORPHISM)
   ========================================= */

.glass-container {
  background: rgba(25, 25, 25, 0.4);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 20px; /* Slightly reduced radius */
  box-shadow: 0 16px 64px 0 rgba(0, 0, 0, 0.5);
  padding: 0.8rem; margin: 0.5rem; /* Very tight margins */
  width: 100%; /* Changed from 95% to work better with margin */
  max-width: 450px;
  display: flex; flex-direction: column; align-items: center;
  /* Removed max-height to allow content to grow */
  position: relative; z-index: 2;
}

/* =========================================
   TYPOGRAPHY
   ========================================= */
h1 { margin: 0 0 0.4rem 0; font-size: 0.9rem; color: #fff; font-family: 'Cinzel', serif; font-weight: 500; }
h2 { 
  margin: 0; font-size: 0.7rem; color: #888; text-align: center; font-weight: 400; 
  font-family: 'Cinzel', serif;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  padding: 0 1rem;
}

/* =========================================
   ANIMATIONS & TRANSITIONS
   ========================================= */
@keyframes fadeInUp { from { opacity: 0; transform: translateY(20px); } to { opacity: 1; transform: translateY(0); } }

/* Staggered animation is now on scanner-ui children */
#scanner-ui > * {
  animation: fadeInUp 0.6s ease-out forwards;
}
#scanner-ui > .header-container { animation-delay: 0.1s; }
#scanner-ui > #topic-trigger { animation-delay: 0.2s; }
#scanner-ui > #reader-container { animation-delay: 0.3s; }
#scanner-ui > #status { animation-delay: 0.4s; }
#scanner-ui > .app-footer { animation-delay: 0.5s; }


@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes fadeOutDown { from { opacity: 1; transform: translateY(0); } to { opacity: 0; transform: translateY(20px); } }
@keyframes shake {
  10%, 90% { transform: translateX(-1px); } 20%, 80% { transform: translateX(2px); }
  30%, 50%, 70% { transform: translateX(-4px); } 40%, 60% { transform: translateX(4px); }
}

/* =========================================
   HEADER & LOGOS
   ========================================= */
/* Header inside the scanner view */
.header-container {
  display: flex;
  align-items: center;
  justify-content: center; /* REVERTED: Centered layout */
  width: 100%;
}

.header-logo {
  height: 36px; /* Default height */
  width: auto;
  margin-right: 12px;
}
/* Override for the scanner view logo specifically - REVERTED */
#scanner-ui .header-logo {
  height: 72px; /* Reverted to 72px */
  width: auto;
}

.header-text {
  display: flex;
  flex-direction: column;
}
/* Reverted text styles */
.header-text h1 { text-align: left; margin: 0 0 4px 0; font-size: 1rem; line-height: normal; }
.header-text h2 { text-align: left; padding: 0; margin: 0; font-size: 0.6rem; line-height: normal; }


/* New Header Dashboard Button */
.header-dashboard-btn {
  display: flex; align-items: center; justify-content: center;
  background: #1b5e20; /* GREEN FILL */
  color: #e8f5e9;
  width: 36px; height: 36px;
  border-radius: 50%;
  text-decoration: none;
  border: 1px solid #2e7d32;
  transition: all 0.2s ease;
  box-shadow: 0 4px 6px rgba(0,0,0,0.3);
}
.header-dashboard-btn:hover {
  background: #2e7d32;
  transform: translateY(-1px) scale(1.05);
  box-shadow: 0 6px 8px rgba(0,0,0,0.4);
}
.header-dashboard-btn .material-icons-outlined {
  font-size: 1.2rem;
}

/* Fixed logo at the top for login screen (currently commented out in HTML) */
#login-header {
  position: fixed; top: 20px; left: 0;
  width: 100%; display: flex; align-items: center; justify-content: center;
  z-index: 1; pointer-events: none;
}
#login-header img { height: 80px; width: auto; }

/* =========================================
   LOGIN SCREEN
   ========================================= */
#login-loader {
  display: none; flex-direction: column; align-items: center; justify-content: center;
  position: fixed; inset: 0; background: rgba(0,0,0,0.8); z-index: 1000;
}

#login-container {
  display: flex; flex-direction: column; align-items: center;
  width: 100%;
  animation: fadeInUp 0.5s ease-out forwards;
}
.login-header-title {
  margin-bottom: 0.5rem; margin-top: 0rem;
  text-align: center;
  font-size: 1.4rem;
}

.input-wrapper {
  position: relative; width: 100%; max-width: 350px; text-align: center;
}

#login-input {
  width: 100%; padding: 0.8rem 3rem; font-size: 1rem;
  background: #333; border: 1px solid #444; border-radius: 8px;
  color: #eee; text-align: center; margin-bottom: 0.2rem;
}

.password-toggle-icon {
  position: absolute; top: 50%; right: 1rem; transform: translateY(-50%);
  cursor: pointer; color: #888;
}

#login-success-icon {
  right: 3rem; color: #4CAF50; animation: fadeIn 0.3s;
  position: absolute; top: 50%; transform: translateY(-50%);
}

#login-btn {
  width: 100%; max-width: 100px; margin-top: 1rem; margin-bottom: 0.4rem;
  padding: 0.4rem; background: #9A2126; color: white;
  border: 1px solid rgba(255, 255, 255, 0.3); border-radius: 8px;
  cursor: pointer; text-align: center; font-weight: 250;
}

.login-error-message {
  position: absolute; top: 50%; left: 0; right: 0;
  margin: 0 auto; transform: translate(0, -50%);
  width: 70%; z-index: 1001; padding: 0.8rem 1.5rem;
  background: rgba(78, 9, 9, 0.5); backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  color: #ffebee; border: 1px solid #661818; border-radius: 8px;
  animation: fadeInUp 0.3s ease-out forwards; text-align: center;
}

#login-footer {
  display: block; padding: 0.5rem;
}
#login-footer div { font-size: 0.9rem; text-align: center; }
#login-footer a { color: #9A2126; text-decoration: none; }

/* =========================================
   SCANNER UI
   ========================================= */
#scanner-ui {
  display: none;
  width: 100%;
  height: 100%; /* Take full height of glass-container */
  flex-direction: column;
  align-items: center;
  justify-content: center; /* Vertically center content */
  padding: 0 1rem; /* Horizontal padding */
  overflow-y: auto; /* Allow scrolling ONLY if content overflows */
}

/* This container will hold the main content that might need to scroll */
.scanner-content-body {
    display: flex;
    flex-direction: column;
    align-items: center;
    width: 100%;
    /* Let this grow and shrink, but center the whole block */
    flex-grow: 1;
    justify-content: center;
    gap: 0.8rem;
}

/* Topic selector dropdown trigger */
.topic-selector-btn {
  width: 100%;
  background: #222; color: #ddd;
  font-size: .9rem; /* Smaller font */
  text-align: left;
  padding: 0.6rem 0.8rem; /* Smaller padding */
  border-radius: 8px; border: 1px solid #333;
  display: flex; justify-content: space-between; align-items: center;
  cursor: pointer;
}
.topic-selector-btn:after { content: '▼'; font-size: 0.7rem; color: #666; }

/* Camera viewport container */
#reader-container {
  position: relative; width: 100%; aspect-ratio: 1 / 1;
  border-radius: 12px;
  overflow: hidden; background: #000;
  border: 1px solid #333;
}
#reader {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

/* Camera loading spinner overlay */
#camera-loader {
  position: absolute; top: 0; left: 0; width: 100%; height: 100%;
  background: #111; display: flex; justify-content: center; align-items: center;
  color: #888; font-size: 0.9rem; z-index: 10;
  flex-direction: column; gap: 15px;
}
#camera-loader span { margin-top: 10px; }

/* General Spinner Animation */
.spinner {
  border: 3px solid rgba(255, 255, 255, 0.1);
  border-top: 3px solid #9A2126;
  border-radius: 50%; width: 30px; height: 30px;
  animation: spin 1s linear infinite;
}
@keyframes spin { 0% { transform: rotate(0deg); } 100% { transform: rotate(360deg); } }

/* =========================================
   STATUS INDICATORS
   ========================================= */
#status {
  width: 100%;
  padding: 0.8rem; border-radius: 8px; min-height: 48px;
  display: flex; align-items: center; gap: 12px; text-align: left;    
  font-weight: 400;
  flex-shrink: 0;
}

/* Status variants */
.idle { background: #111; color: #aaa; border: 1px dashed #333; justify-content: center; }
.success { background: #1b5e20; color: #e8f5e9; border: 1px solid #2e7d32; }
.error { background: #b71c1c; color: #ffebee; border: 1px solid #d32f2f; }
.processing { background: #332222; color: #E57373; border: 1px solid #9A2126; justify-content: center; }

.status-text-container { display: flex; flex-direction: column; }
.main-text { font-size: 0.8rem; font-weight: 400; }
.sub-text { font-size: 0.6rem; opacity: 0.8; font-weight: 300; }

/* =========================================
   APP FOOTER
   ========================================= */
/* Main footer in scanner view */
.app-footer {
  width: 100%; max-width: 600px;
  box-sizing: border-box; padding: 5px 10px;
  display: flex; flex-direction: column; /* Reverted to column */
  align-items: center;
  font-size: 0.65rem; color: #555;
  gap: 5px;
}

.footer-text { text-align: center; }
.footer-link { color: #9A2126; text-decoration: none; }

/* Dashboard Pill Button */
#dashboard-pill {
  display: flex;
  align-items: center;
  justify-content: center;
  background: #1b5e20;
  color: #e8f5e9;
  height: 40px;
  border-radius: 20px; /* Fully rounded for pill shape */
  cursor: pointer;
  border: 1px solid #2e7d32;
  box-shadow: 0 4px 6px rgba(0,0,0,0.3);
  transition: all 0.2s ease; /* Simple transition */
  padding: 0 20px; /* Generous padding for pill shape */
  text-decoration: none; /* Remove underline if it's an anchor */
}

#dashboard-pill:hover {
  background: #2e7d32;
  transform: translateY(-1px); /* Subtle hover effect */
  box-shadow: 0 6px 8px rgba(0,0,0,0.4);
}

/* Text inside the pill */
.pill-text {
  white-space: nowrap;
  font-size: 0.85rem;
  font-weight: 500;
  margin-left: 8px; /* Space between icon and text */
}

/* =========================================
   TOPIC MODAL
   ========================================= */
#topic-modal {
  display: none; position: fixed; bottom: 0; left: 0; width: 100%; height: 100%;
  background: rgba(0,0,0,0.9); z-index: 999;
  flex-direction: column; justify-content: flex-end;
}

.modal-content {
  background: #1a1a1a;
  border-top-left-radius: 16px; border-top-right-radius: 16px;
  padding: 1rem; max-height: 70vh;
  display: flex; flex-direction: column;
  border-top: 1px solid #333;
}
.modal-content > h3 { margin: 0 0 10px 0; text-align: center; color: #fff; font-weight:400; }

#topic-list-container {
  overflow-y: auto; display: flex; flex-direction: column; gap: 10px;
}
.topic-loading-placeholder { text-align: center; padding: 20px; color: #666; }

#topic-search-input {
  width: 100%; position: sticky; top: 0; z-index: 1;
  padding: 0.8rem 1rem; margin-bottom: 10px;
  background: #333; border: 1px solid #444; border-radius: 8px;
  color: #eee; font-size: 0.9rem;
}

.topic-option {
  padding: 1rem; background: #2a2a2a; border-radius: 8px;
  text-align: left; font-size: 0.9rem; color: #ccc;
  border: 1px solid #333; cursor: pointer;
}

.topic-option.topic-p {
  background: #FFC107;
  color: #000;
  border-color: #FFA000;
}

.topic-option.topic-ki {
  background: #1565C0;
  color: #fff;
  border-color: #0D47A1;
}

.topic-option.active { border-color: #9A2126; background: #332222; color: #E57373; }

.topic-option.topic-p.active {
  background: #FFC107;
  color: #000;
  border: 2px solid #D32F2F; /* Red border to indicate selection, matching the theme */
}

.topic-option.topic-ki.active {
  background: #1565C0;
  color: #fff;
  border: 2px solid #D32F2F; /* Red border to indicate selection */
}

.topic-option.topic-rekoleksi {
  background: #ffffff;
  color: #111111;
  border: 1px solid #ffffff;
  font-weight: 600;
}

.topic-option.topic-rekoleksi.active {
  background: #e0e0e0;
  color: #9A2126;
  border: 2px solid #D32F2F;
}

.modal-close-btn {
  margin-top: 15px; padding: 1rem; background: #d32f2f; color: white;
  text-align: center; border-radius: 8px; cursor: pointer;
  position: sticky; bottom: 0;
}

/* =========================================
   PROFILE MODAL & CARD
   ========================================= */
#profile-modal {
  display: none; position: fixed; top: 0; left: 0; width: 100%; height: 100%;
  background: rgba(0, 0, 0, 0.85); z-index: 2000;
  justify-content: center; align-items: center;
  backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
}

.profile-card {
  position: relative; background: #1b5e20; border: 1px solid #2e7d32;
  border-radius: 24px; padding: 2.5rem 2rem;
  width: 85%; max-width: 340px;
  display: flex; flex-direction: column; align-items: center;
  box-shadow: 0 25px 50px -12px rgba(27, 94, 32, 0.5);
  animation: popIn 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes popIn { from { opacity: 0; transform: scale(0.9) translateY(20px); } to { opacity: 1; transform: scale(1) translateY(0); } }
@keyframes fadeOut { from { opacity: 1; transform: scale(1) translateY(0); } to { opacity: 0; transform: scale(0.9) translateY(20px); } }

.timeout-spinner {
  position: absolute; top: 16px; right: 16px;
  width: 24px; height: 24px; pointer-events: none;
}
.timeout-spinner svg { width: 100%; height: 100%; transform: rotate(0deg); }

.circle-bg { fill: none; stroke: rgba(255, 255, 255, 0.2); stroke-width: 4; }
.circle-progress {
  fill: none; stroke: #fff; stroke-width: 4;
  stroke-dasharray: 100, 100; stroke-dashoffset: 0;
  animation: countdown 4s linear forwards;
}
@keyframes countdown { to { stroke-dashoffset: 100; } }

.profile-img-wrapper {
  width: 120px; height: 120px; border-radius: 50%; padding: 4px;
  background: linear-gradient(135deg, #2e7d32, #1b5e20);
  margin-bottom: 1.2rem; box-shadow: 0 8px 24px rgba(0,0,0,0.4);
}
.profile-img-wrapper img {
  width: 100%; height: 100%; border-radius: 50%; object-fit: cover;
  border: 3px solid #1a1a1a; background-color: #000;
}

.profile-name {
  font-family: 'Cinzel', serif; font-size: 1.4rem; color: #fff;
  text-align: center; margin-bottom: 0.4rem;
  text-shadow: 0 2px 4px rgba(0,0,0,0.5);
}
.profile-id {
  font-family: "Inter", sans-serif; font-size: 0.9rem; color: #aaa;
  margin-bottom: 2rem; letter-spacing: 0.05em;
}

.profile-close-btn {
  background: #2e7d32; color: #fff; border: 1px solid rgba(255,255,255,0.2);
  padding: 0.8rem 2.5rem; border-radius: 50px;
  font-size: 0.9rem; cursor: pointer; font-weight: 500;
  transition: all 0.2s ease; box-shadow: 0 4px 12px rgba(46, 125, 50, 0.3);
}
.profile-close-btn:hover {
  background: #388e3c; transform: translateY(-2px);
  box-shadow: 0 6px 16px rgba(46, 125, 50, 0.4);
}

.fixed-bottom-branding {
  position: fixed; bottom: 20px; left: 0; width: 100%; display: flex; justify-content: center; align-items: center; z-index: 1;
}