/* ==========================================================================
   VM Power Management Portal — Responsive CSS with Light/Dark Theme Support
   ==========================================================================
   Uses CSS custom properties (data-theme attribute) for theming.
   Default: light theme. Dark theme applied via data-theme="dark" on <html>.
   Automatic dark mode via prefers-color-scheme: dark media query.
   Primary accent: #2a9d8f
   ========================================================================== */

/* --- CSS Custom Properties (Light Theme - Default) --- */
:root {
  --color-primary: #2a9d8f;
  --color-primary-hover: #24887d;
  --color-danger: #e63946;
  --color-danger-hover: #c5303c;

  /* Light theme defaults */
  --bg-body: #f5f7fa;
  --bg-card: #ffffff;
  --text-primary: #333333;
  --text-secondary: #4d4d4d;
  --text-muted: #6c757d;
  --border-light: #e5e7eb;
  --shadow-card: 0 4px 24px rgba(0, 0, 0, 0.08);
  --shadow-logo: 0 1px 4px rgba(0, 0, 0, 0.12);

  /* VM state colors */
  --state-running: #28a745;
  --state-starting: #007bff;
  --state-stopping: #fd7e14;
  --state-stopped: #6c757d;
  --state-deallocated: #6c757d;

  /* Health status colors */
  --health-good: #28a745;
  --health-warning: #ffc107;
  --health-error: #dc3545;

  /* Progress bar */
  --progress-bg: #e9ecef;
  --progress-fill: var(--color-primary);
}

/* --- Dark Theme via data-theme attribute --- */
[data-theme="dark"] {
  --bg-body: #1e1e1e;
  --bg-card: #252525;
  --text-primary: #f0f0f0;
  --text-secondary: #b3b3b3;
  --text-muted: #9ca3af;
  --border-light: #3a3a3a;
  --shadow-card: 0 4px 24px rgba(0, 0, 0, 0.3);
  --shadow-logo: 0 1px 4px rgba(0, 0, 0, 0.3);
  --progress-bg: #3a3a3a;
}

/* --- Auto dark mode via prefers-color-scheme --- */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg-body: #1e1e1e;
    --bg-card: #252525;
    --text-primary: #f0f0f0;
    --text-secondary: #b3b3b3;
    --text-muted: #9ca3af;
    --border-light: #3a3a3a;
    --shadow-card: 0 4px 24px rgba(0, 0, 0, 0.3);
    --shadow-logo: 0 1px 4px rgba(0, 0, 0, 0.3);
    --progress-bg: #3a3a3a;
  }
}

/* --- Base Reset & Body --- */
*,
*::before,
*::after {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  font-size: 15px;
  line-height: 1.5;
  color: var(--text-primary);
  background-color: var(--bg-body);
  background-image: url('assets/login-bg-agriculture-lesotho.svg');
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
  background-attachment: fixed;
  min-height: 100vh;
}

/* --- Main Layout --- */
.standby-container,
.page-container {
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 100vh;
  padding: 16px;
}

/* --- Card Component --- */
.standby-card,
.card {
  width: 100%;
  max-width: 400px;
  border-radius: 16px;
  padding: 24px;
  background-color: var(--bg-card);
  box-shadow: var(--shadow-card);
  margin: 0 auto;
  display: flex;
  flex-direction: column;
}

/* --- Logos Row --- */
.logos-row {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 20px;
  margin-bottom: 12px;
}

.logo-container {
  display: flex;
  justify-content: center;
  align-items: center;
  width: 60px;
  height: 60px;
  border-radius: 10px;
  overflow: hidden;
  box-shadow: var(--shadow-logo);
  background: #ffffff;
}

.logo-container img {
  width: auto;
  height: 50px;
  object-fit: contain;
}

.logo-container.app-icon {
  background-color: var(--color-primary);
}

.logo-container.app-icon-container {
  background-color: transparent;
  box-shadow: none;
}

.logo-container.app-icon img,
.logo-container.app-icon-container img {
  height: 50px;
}

/* --- Typography --- */
.app-tagline {
  font-size: 16px;
  font-weight: 600;
  text-align: center;
  margin: 0 0 12px 0;
  color: var(--text-primary);
}

.project-reference {
  font-size: 12px;
  text-align: center;
  line-height: 1.4;
  margin: 0 0 8px 0;
  color: var(--text-secondary);
}

.project-reference a {
  color: var(--color-primary);
  text-decoration: none;
}

.project-reference a:hover {
  text-decoration: underline;
}

.partner-credit {
  font-size: 12px;
  text-align: center;
  margin: 0 0 8px 0;
  color: var(--text-secondary);
}

.partner-credit a {
  color: var(--color-primary);
  font-weight: 600;
  text-decoration: none;
}

.partner-credit a:hover {
  text-decoration: underline;
}

/* --- Offline Status Message --- */
.offline-status,
.status-message {
  text-align: center;
  margin: 16px 0;
}

.offline-status h2,
.status-heading {
  font-size: 18px;
  font-weight: 600;
  margin: 0 0 8px 0;
  color: var(--text-primary);
}

.offline-status p,
.status-secondary {
  font-size: 14px;
  margin: 0;
  color: var(--text-secondary);
}

/* --- Admin Login Button --- */
.admin-login-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  padding: 10px 16px;
  margin-top: 16px;
  font-size: 15px;
  font-weight: 600;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  transition: background-color 0.2s, opacity 0.2s;
  background-color: var(--color-primary);
  color: #ffffff;
}

.admin-login-button:hover:not(:disabled) {
  background-color: var(--color-primary-hover);
}

[data-theme="dark"] .admin-login-button {
  border: 1px solid rgba(255, 255, 255, 0.15);
}

/* --- Buttons --- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 10px 16px;
  font-size: 15px;
  font-weight: 600;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  transition: background-color 0.2s, opacity 0.2s;
  text-align: center;
  width: 100%;
}

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

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

.btn-primary:hover:not(:disabled) {
  background-color: var(--color-primary-hover);
}

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

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

[data-theme="dark"] .btn-primary,
[data-theme="dark"] .btn-danger {
  border: 1px solid rgba(255, 255, 255, 0.15);
}

/* --- VM State Indicators --- */
.vm-state {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  font-weight: 500;
}

.vm-state-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
}

.vm-state-dot.running {
  background-color: var(--state-running);
}

.vm-state-dot.starting {
  background-color: var(--state-starting);
}

.vm-state-dot.stopping {
  background-color: var(--state-stopping);
}

.vm-state-dot.stopped,
.vm-state-dot.deallocated {
  background-color: var(--state-stopped);
}

.vm-state-label {
  color: var(--text-primary);
}

/* --- Admin Panel Sections --- */
.admin-panel {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.panel-section {
  padding: 16px;
  border-radius: 12px;
  border: 1px solid var(--border-light);
}

.panel-section h3 {
  font-size: 14px;
  font-weight: 600;
  margin: 0 0 12px 0;
  color: var(--text-primary);
}

/* --- Loading Spinner --- */
.spinner {
  display: inline-block;
  width: 20px;
  height: 20px;
  border: 2px solid var(--border-light);
  border-top-color: var(--color-primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

.loading-indicator {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-size: 14px;
  color: var(--text-secondary);
  padding: 12px 0;
}

/* --- Progress Bars (Resource Usage) --- */
.progress-bar-container {
  margin-bottom: 10px;
}

.progress-bar-label {
  display: flex;
  justify-content: space-between;
  font-size: 12px;
  margin-bottom: 4px;
  color: var(--text-secondary);
}

.progress-bar {
  width: 100%;
  height: 8px;
  background-color: var(--progress-bg);
  border-radius: 4px;
  overflow: hidden;
}

.progress-bar-fill {
  height: 100%;
  border-radius: 4px;
  background-color: var(--color-primary);
  transition: width 0.3s ease;
}

/* --- Health Status Indicators --- */
.health-services {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.health-service {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
}

.health-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}

.health-dot.good {
  background-color: var(--health-good);
}

.health-dot.warning {
  background-color: var(--health-warning);
}

.health-dot.error {
  background-color: var(--health-error);
}

.health-service-name {
  font-weight: 500;
  color: var(--text-primary);
}

.health-service-message {
  font-size: 12px;
  color: var(--text-muted);
}

/* --- Confirmation Dialog --- */
.dialog-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(0, 0, 0, 0.5);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 1000;
}

.dialog {
  width: 90%;
  max-width: 360px;
  background-color: var(--bg-card);
  border-radius: 12px;
  padding: 24px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.2);
}

.dialog h3 {
  margin: 0 0 12px 0;
  font-size: 16px;
  font-weight: 600;
  color: var(--text-primary);
}

.dialog p {
  margin: 0 0 20px 0;
  font-size: 14px;
  color: var(--text-secondary);
}

.dialog-actions {
  display: flex;
  gap: 12px;
}

.dialog-actions .btn {
  flex: 1;
  padding: 8px 12px;
  font-size: 14px;
}

.btn-cancel {
  background-color: transparent;
  border: 1px solid var(--border-light);
  color: var(--text-primary);
}

.btn-cancel:hover {
  background-color: var(--progress-bg);
}

/* --- Schedule Picker --- */
.schedule-section {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.schedule-display {
  font-size: 14px;
  color: var(--text-primary);
  font-weight: 500;
}

.schedule-picker select {
  width: 100%;
  padding: 8px 12px;
  font-size: 14px;
  border-radius: 8px;
  border: 1px solid var(--border-light);
  background-color: var(--bg-card);
  color: var(--text-primary);
  cursor: pointer;
  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='none' stroke='%23999' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3e%3cpolyline points='6 9 12 15 18 9'%3e%3c/polyline%3e%3c/svg%3e");
  background-repeat: no-repeat;
  background-position: right 8px center;
  background-size: 14px;
  padding-right: 28px;
}

.schedule-picker select:focus {
  outline: none;
  border-color: var(--color-primary);
}

/* --- Warning Badge & Last Updated --- */
.warning-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 8px;
  font-size: 12px;
  border-radius: 4px;
  background-color: rgba(253, 126, 20, 0.15);
  color: var(--state-stopping);
}

.last-updated {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 4px;
}

/* --- Success / Error Messages --- */
.message {
  padding: 10px 12px;
  border-radius: 8px;
  font-size: 13px;
  margin-top: 8px;
}

.message-success {
  background-color: rgba(40, 167, 69, 0.12);
  border: 1px solid rgba(40, 167, 69, 0.3);
  color: var(--health-good);
}

.message-error {
  background-color: rgba(220, 53, 69, 0.12);
  border: 1px solid rgba(220, 53, 69, 0.3);
  color: var(--health-error);
}

.message-info {
  background-color: rgba(42, 157, 143, 0.12);
  border: 1px solid rgba(42, 157, 143, 0.3);
  color: var(--color-primary);
}

/* --- Rate Limit Countdown --- */
.rate-limit-message {
  text-align: center;
  font-size: 13px;
  color: var(--state-stopping);
  padding: 8px;
}

/* --- Admin Header --- */
.admin-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
}

.admin-name {
  font-size: 14px;
  font-weight: 500;
  color: var(--text-primary);
}

.btn-signout {
  padding: 6px 12px;
  font-size: 12px;
  background-color: transparent;
  border: 1px solid var(--border-light);
  color: var(--text-secondary);
  border-radius: 6px;
  cursor: pointer;
  transition: background-color 0.2s;
}

.btn-signout:hover {
  background-color: var(--progress-bg);
}

/* --- Estimated Time Notice --- */
.boot-time-notice {
  font-size: 12px;
  color: var(--text-muted);
  text-align: center;
  margin-top: 8px;
}

/* --- Auth Error Area --- */
.auth-error-area {
  margin-top: 12px;
  padding: 12px;
  border-radius: 8px;
  background-color: rgba(220, 53, 69, 0.08);
  border: 1px solid rgba(220, 53, 69, 0.25);
}

.auth-error-message {
  margin: 0 0 10px 0;
  font-size: 13px;
  color: var(--health-error);
  text-align: center;
}

.auth-error-actions {
  display: flex;
  gap: 8px;
  justify-content: center;
  flex-wrap: wrap;
}

.auth-error-btn {
  padding: 6px 12px;
  font-size: 12px;
  font-weight: 500;
  border-radius: 6px;
  border: none;
  cursor: pointer;
  transition: background-color 0.2s, opacity 0.2s;
}

.auth-error-btn-retry {
  background-color: var(--color-primary);
  color: #ffffff;
}

.auth-error-btn-retry:hover {
  background-color: var(--color-primary-hover);
}

.auth-error-btn-signout {
  background-color: transparent;
  border: 1px solid var(--border-light);
  color: var(--text-secondary);
}

.auth-error-btn-signout:hover {
  background-color: var(--progress-bg);
}

.auth-error-btn-dismiss {
  background-color: transparent;
  border: 1px solid var(--border-light);
  color: var(--text-muted);
}

.auth-error-btn-dismiss:hover {
  background-color: var(--progress-bg);
}

/* --- Admin Panel Header --- */
.admin-panel-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border-light);
}

.admin-welcome {
  font-size: 13px;
  color: var(--text-secondary);
}

.admin-signout-button {
  padding: 6px 12px;
  font-size: 12px;
  font-weight: 500;
  border-radius: 6px;
  border: 1px solid var(--border-light);
  background-color: transparent;
  color: var(--text-secondary);
  cursor: pointer;
  transition: background-color 0.2s;
}

.admin-signout-button:hover {
  background-color: var(--progress-bg);
}

/* --- Admin Panel Section Containers --- */
.admin-section {
  min-height: 40px;
}

/* --- Hidden utility --- */
.hidden {
  display: none !important;
}

/* The `hidden` HTML attribute must actually hide elements. Several controls
   (the admin login button, admin panel, recovery/error sections) are toggled
   via `el.hidden = true/false` in JS, but they also carry a `display`-setting
   class (e.g. .admin-login-button { display: inline-flex }). An author
   `display` rule beats the UA `[hidden] { display: none }`, so without this
   the element stays visible even when hidden=true - which is why the
   "Sign in as Admin" button lingered after logging in. Force it. */
[hidden] {
  display: none !important;
}

/* ==========================================================================
   Mobile Breakpoint — 480px and below
   ========================================================================== */
@media (max-width: 480px) {
  .standby-container,
  .page-container {
    padding: 10px;
  }

  .standby-card,
  .card {
    padding: 16px;
    border-radius: 12px;
  }

  .logos-row {
    gap: 12px;
  }

  .logo-container {
    width: 48px;
    height: 48px;
    border-radius: 8px;
  }

  .logo-container img {
    height: 38px;
  }

  .app-tagline {
    font-size: 14px;
  }

  .project-reference {
    font-size: 11px;
  }

  .offline-status h2,
  .status-heading {
    font-size: 16px;
  }

  .offline-status p,
  .status-secondary {
    font-size: 13px;
  }

  .btn,
  .admin-login-button {
    font-size: 14px;
    padding: 9px 14px;
  }

  /* Secondary sign-out buttons are visually small (12px text); on touch they
     still need a >=44px tap target. Bump min-height and give them room without
     changing their compact desktop look. */
  .btn-signout,
  .admin-signout-button {
    min-height: 44px;
    padding: 10px 14px;
  }

  /* Dialog action buttons should also clear the 44px touch guideline. */
  .dialog-actions .btn {
    min-height: 44px;
  }

  .panel-section {
    padding: 12px;
  }

  .dialog {
    padding: 16px;
  }
}

/* --- Service Recovery Banner --- */
.recovery-section {
  margin: 16px 0;
}

.recovery-banner {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  padding: 16px;
  border-radius: 12px;
  background-color: rgba(42, 157, 143, 0.12);
  border: 1px solid rgba(42, 157, 143, 0.3);
  text-align: center;
}

.recovery-message {
  margin: 0;
  font-size: 14px;
  font-weight: 600;
  color: var(--color-primary);
}

.recovery-button {
  min-width: 180px;
}
