/* ── Loading Overlay ──────────────────────────────────────────── */
.loading-overlay {
  position: fixed;
  inset: 0;
  z-index: 9999;
  background: rgba(255, 255, 255, 0.85);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  transition: opacity 0.3s ease;
}
.loading-overlay.hidden {
  opacity: 0;
  pointer-events: none;
}
.loading-spinner {
  width: 48px;
  height: 48px;
  border: 5px solid #e0e0e0;
  border-top-color: #1877f2;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin {
  to { transform: rotate(360deg); }
}
.loading-text {
  font-size: 1rem;
  color: #606770;
}

/* ── Reset & Base ────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { font-size: 16px; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: #f0f2f5;
  color: #1c1e21;
  min-height: 100vh;
}

/* ── Login Page ─────────────────────────────────────────────── */
.login-page {
  display: flex; align-items: center; justify-content: center; padding: 1rem;
}
.login-card {
  background: #fff; border-radius: 12px; box-shadow: 0 2px 12px rgba(0,0,0,0.08);
  padding: 2rem 1.5rem; width: 100%; max-width: 360px;
}
.login-card h1 {
  font-size: 1.25rem; text-align: center; margin-bottom: 1.5rem;
  color: #1877f2;
}
.login-card label {
  display: block; font-size: 0.875rem; margin-bottom: 0.25rem; color: #606770;
}
.login-card input {
  width: 100%; padding: 0.625rem 0.75rem; border: 1px solid #ccd0d5;
  border-radius: 6px; font-size: 1rem; margin-bottom: 1rem; outline: none;
}
.login-card input:focus { border-color: #1877f2; box-shadow: 0 0 0 2px rgba(24,119,242,0.2); }
.login-card button {
  width: 100%; padding: 0.7rem; background: #1877f2; color: #fff; border: none;
  border-radius: 6px; font-size: 1rem; font-weight: 600; cursor: pointer;
}
.login-card button:hover { background: #166fe5; }
.error-msg { color: #e53935; font-size: 0.875rem; margin-bottom: 0.75rem; text-align: center; }

/* Google SSO button */
.google-btn {
  display: flex; align-items: center; justify-content: center; gap: 0.5rem;
  width: 100%; padding: 0.7rem; background: #fff; color: #333;
  border: 1px solid #dadce0; border-radius: 6px; font-size: 1rem;
  cursor: pointer; text-decoration: none; transition: background 0.2s;
}
.google-btn:hover { background: #f8f9fa; border-color: #c6c9cc; }
.google-icon {
  font-weight: 700; font-size: 1.2rem; color: #4285f4;
}
.google-domain-note {
  font-size: 0.75rem; color: #90949c; text-align: center; margin: 0.4rem 0 0.75rem;
}

/* Admin password login button */
.admin-btn {
  display: flex; align-items: center; justify-content: center; gap: 0.5rem;
  width: 100%; padding: 0.7rem; background: #fff; color: #333;
  border: 1px solid #dadce0; border-radius: 6px; font-size: 1rem;
  cursor: pointer; text-decoration: none; transition: background 0.2s;
}
.admin-btn:hover { background: #f8f9fa; border-color: #c6c9cc; }

/* Back link */
.back-link {
  display: block; text-align: center; margin-top: 1rem;
  font-size: 0.875rem; color: #1877f2; text-decoration: none;
}
.back-link:hover { text-decoration: underline; }

/* Divider */
.divider {
  display: flex; align-items: center; gap: 0.75rem; margin: 0.75rem 0;
}
.divider::before, .divider::after {
  content: ""; flex: 1; height: 1px; background: #e0e0e0;
}
.divider-text {
  font-size: 0.8rem; color: #90949c; white-space: nowrap;
}

/* ── Top Bar ────────────────────────────────────────────────── */
.top-bar {
  background: #1877f2; color: #fff; padding: 0.75rem 1rem;
  display: flex; align-items: center; justify-content: space-between;
}
.top-title { font-size: 1.1rem; font-weight: 600; }
.logout-btn {
  color: #fff; text-decoration: none; font-size: 0.875rem; opacity: 0.85;
}
.logout-btn:hover { opacity: inherit; }
.log-btn {
  color: #fff; text-decoration: none; font-size: 0.875rem; padding: 0.25rem 0.5rem;
  background: rgba(255,255,255,0.15); border-radius: 6px; border: 1px solid rgba(255,255,255,0.3);
}
.log-btn:hover { background: rgba(255,255,255,0.25); }
.top-actions { display: flex; align-items: center; gap: 0.75rem; }
.user-name { font-size: 0.85rem; opacity: 0.9; white-space: nowrap; }

/* ── Language Toggle ─────────────────────────────────────────── */
.lang-toggle {
  background: rgba(255,255,255,0.15); color: #fff; border: 1px solid rgba(255,255,255,0.3);
  border-radius: 6px; padding: 0.25rem 0.6rem; font-size: 0.8rem; cursor: pointer;
}
.lang-toggle:hover { background: rgba(255,255,255,0.25); }
.login-card .lang-toggle {
  display: block; margin: 1rem auto 0; background: #e4e6eb; color: #1c1e21;
  border: 1px solid #ccd0d5;
}
.login-card .lang-toggle:hover { background: #d8dadf; }

/* ── Dashboard ──────────────────────────────────────────────── */
.dashboard { max-width: 680px; margin: 1.5rem auto; padding: 0 1rem; }

/* Status card */
.status-card {
  background: #fff; border-radius: 12px; box-shadow: 0 1px 6px rgba(0,0,0,0.06);
  padding: 1.5rem; margin-bottom: 1rem;
}
.status-card h2 { font-size: 1.1rem; margin-bottom: 0.25rem; }
.group-label { font-size: 0.875rem; color: #606770; margin-bottom: 1rem; }
.status-row {
  display: flex; align-items: center; justify-content: space-between;
}
.status-badge {
  display: inline-block; padding: 0.35rem 0.9rem; border-radius: 20px;
  font-size: 0.875rem; font-weight: 600;
}
.status-badge.locked { background: #e8f5e9; color: #2e7d32; }
.status-badge.unlocked { background: #fce4ec; color: #c62828; }
.status-badge.partial { background: #fff3e0; color: #e65100; }
.status-badge.loading { background: #e3f2fd; color: #1565c0; }
.device-count { font-size: 0.875rem; color: #606770; }

/* Action buttons */
.actions { display: flex; gap: 0.75rem; margin-bottom: 1rem; }
.btn {
  flex: 1; padding: 0.85rem 0.5rem; border: none; border-radius: 10px;
  font-size: 1rem; font-weight: 600; cursor: pointer; transition: opacity 0.2s;
}
.btn:disabled { opacity: 0.4; cursor: not-allowed; }
.btn-lock { background: #43a047; color: #fff; }
.btn-lock:hover:not(:disabled) { background: #388e3c; }
.btn-unlock { background: #e53935; color: #fff; }
.btn-unlock:hover:not(:disabled) { background: #c62828; }

/* Info note */
.info-note {
  background: #fff8e1; border: 1px solid #ffe082; border-radius: 10px;
  padding: 0.7rem 1rem; margin-bottom: 1rem; font-size: 0.85rem;
  color: #e65100; text-align: center; line-height: 1.4;
}

/* ── Lock status table ──────────────────────────────────────────── */
.lock-status-table {
  background: #fff; border-radius: 12px; box-shadow: 0 1px 6px rgba(0,0,0,0.06);
  padding: 0.75rem 1.25rem; margin-bottom: 1rem; font-size: 0.85rem;
}
.lock-status-header {
  font-weight: 600; color: #606770; margin-bottom: 0.5rem; text-align: center;
}
.lock-status-row {
  display: flex; justify-content: center; gap: 1.5rem; padding: 0.2rem 0;
}
.lock-status-row:first-of-type {
  font-weight: 600; color: #606770; border-bottom: 1px solid #e0e0e0; padding-bottom: 0.4rem; margin-bottom: 0.2rem;
}
.lock-status-row span { min-width: 4rem; text-align: center; }
.lock-status-row .locked { color: #c62828; font-weight: 600; }
.lock-status-row .unlocked { color: #2e7d32; font-weight: 600; }

/* ── Group List ─────────────────────────────────────────────── */
.group-list {
  background: #fff; border-radius: 12px; box-shadow: 0 1px 6px rgba(0,0,0,0.06);
  padding: 0.5rem 1.5rem 1rem; margin-bottom: 1rem;
}
.group-list-header {
  display: flex; align-items: center;
  padding: 0.5rem 0; border-bottom: 1px solid #e0e0e0; margin-bottom: 0.25rem;
  font-size: 0.8rem; font-weight: 600; color: #606770;
}
.col-class { flex: 1; }
.col-count { width: 3rem; text-align: center; margin-right: 0.5rem; }
.col-status { flex: 1; text-align: center; }
.col-actions { width: 10rem; text-align: center; }

/* Column background tints */
.col-count-bg { padding: 0.2rem 0.4rem; }
.col-status-bg { padding: 0.2rem 0.4rem; }
.col-actions-bg { padding: 0.2rem 0.3rem; }
.checkbox-label { display: flex; align-items: center; gap: 0.4rem; cursor: pointer; }
.checkbox-label input[type="checkbox"] { width: 1rem; height: 1rem; cursor: pointer; }
.select-all { font-size: 0.85rem; font-weight: 500; color: #606770; }
.group-item {
  display: flex; align-items: center; gap: 0.5rem;
  padding: 0.75rem 0; border-bottom: 1px solid #f0f0f0;
}
.group-item:last-child { border-bottom: none; }
.group-list .group-item:nth-child(even) { background: #f9f9f9; }
.group-item .checkbox-label { flex-shrink: 0; }
.group-item .checkbox-label input[type="checkbox"] {
  width: 1.3rem; height: 1.3rem;
}
.group-name { font-size: 1rem; font-weight: 500; flex: 1; min-width: 0; }
.group-count { font-size: 0.85rem; color: #90949c; white-space: nowrap; }
.group-badge {
  font-size: 0.8rem; padding: 0.3rem 0.7rem; border-radius: 14px;
  white-space: nowrap; font-weight: 600;
}
.group-badge.locked { background: #e8f5e9; color: #2e7d32; }
.group-badge.unlocked { background: #fce4ec; color: #c62828; }

/* Per-row actions */
.group-actions { display: flex; align-items: center; gap: 0.4rem; flex-shrink: 0; }
.row-unlock-btn, .row-lock-btn {
  border: none; border-radius: 8px; padding: 0.4rem 0.6rem;
  font-size: 1.1rem; cursor: pointer; font-weight: 600; line-height: 1;
  min-width: 2.4rem; min-height: 2.4rem;
  transition: opacity 0.15s;
}
.row-unlock-btn:disabled, .row-lock-btn:disabled { opacity: 0.35; cursor: not-allowed; }
.row-unlock-btn.hidden, .row-lock-btn.hidden, .row-profile-select.hidden { display: none; }
.row-unlock-btn { background: #ffcdd2; color: #c62828; }
.row-unlock-btn:hover:not(:disabled) { background: #ef9a9a; }
.row-lock-btn { background: #c8e6c9; color: #2e7d32; }
.row-lock-btn:hover:not(:disabled) { background: #a5d6a7; }
.row-profile-select {
  font-size: 0.8rem; padding: 0.35rem 0.3rem; border: 1px solid #ccc;
  border-radius: 6px; max-width: 6rem; min-height: 2.2rem; cursor: pointer;
}

/* ── Log page ────────────────────────────────────────────────── */
.log-content {
  background: #1e1e1e; color: #d4d4d4; padding: 1.25rem; border-radius: 10px;
  font-family: "Cascadia Code", "Fira Code", "Consolas", monospace;
  font-size: 0.8rem; line-height: 1.6; overflow-x: auto; white-space: pre-wrap;
  min-height: 60vh; max-height: 70vh; overflow-y: auto;
}

/* ── Toast ──────────────────────────────────────────────────── */
.toast {
  position: fixed; top: 4.5rem; left: 50%; transform: translateX(-50%);
  padding: 0.75rem 1.25rem; border-radius: 8px; font-size: 0.9rem;
  max-width: 90vw; text-align: center; z-index: 999;
  opacity: 0; transition: opacity 0.3s ease;
  pointer-events: none;
}
.toast.show { opacity: 1; pointer-events: auto; }
.toast.success { background: #e8f5e9; color: #2e7d32; border: 1px solid #a5d6a7; }
.toast.error { background: #fce4ec; color: #c62828; border: 1px solid #ef9a9a; }
.toast.info { background: #e3f2fd; color: #1565c0; border: 1px solid #90caf9; }

/* ── Mobile fine-tune ───────────────────────────────────────── */
@media (max-width: 480px) {
  html { font-size: 14px; }
  .dashboard { margin: 0.75rem auto; padding: 0 0.5rem; }
  .top-bar { flex-wrap: wrap; gap: 0.4rem; padding: 0.5rem 0.75rem; }
  .top-actions { flex-wrap: wrap; gap: 0.4rem; }
  .top-title { font-size: 1rem; width: 100%; }
  .status-card { padding: 1rem; }
  .status-row { flex-direction: column; gap: 0.4rem; align-items: flex-start; }

  /* Group list: card-style per row */
  .group-list-header { display: none; }
  .group-item {
    flex-wrap: wrap; gap: 0.3rem; padding: 0.6rem 0;
  }
  .group-item .group-name {
    width: 100%; font-size: 0.95rem; margin-bottom: 0.2rem;
  }
  .group-item .col-count-bg,
  .group-item .col-status-bg {
    width: auto; font-size: 0.8rem;
  }
  .group-actions { width: 100%; margin-top: 0.3rem; justify-content: flex-start; }
  .row-profile-select { max-width: 5rem; font-size: 0.75rem; min-height: 1.8rem; }
  .row-unlock-btn, .row-lock-btn { min-width: 2rem; min-height: 2rem; padding: 0.3rem 0.4rem; font-size: 0.95rem; }

  /* Lock status table */
  .lock-status-table { padding: 0.5rem 0.75rem; }
  .lock-status-row { gap: 0.75rem; }
  .lock-status-row span { min-width: 3rem; font-size: 0.8rem; }

  /* Info note */
  .info-note { font-size: 0.8rem; padding: 0.5rem 0.75rem; }
}

@media (max-width: 360px) {
  .top-bar { flex-direction: column; align-items: stretch; }
  .top-actions { justify-content: center; }
  .group-actions { flex-wrap: wrap; }
  .row-profile-select { max-width: 4rem; }
}
