/* ==========================================================================
   AI4Kids Portal CSS - Modern Responsive UI (Mobile / iPad / PC Optimized)
   ========================================================================== */

:root {
  /* Color Palette */
  --bg-page: #0b0f19;
  --bg-surface: #111827;
  --bg-surface-elevated: #1a2336;
  --bg-surface-glass: rgba(17, 24, 39, 0.85);
  --bg-input: #0e1524;
  --border: #1f293d;
  --border-hover: #334155;
  --border-focus: #38bdf8;
  
  --text-main: #f8fafc;
  --text-muted: #94a3b8;
  --text-dim: #64748b;
  
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --primary-light: rgba(37, 99, 235, 0.18);
  --accent-sky: #38bdf8;
  --accent-sky-light: rgba(56, 189, 248, 0.12);
  
  --danger: #ef4444;
  --danger-hover: #dc2626;
  --danger-bg: rgba(239, 68, 68, 0.12);
  --danger-border: rgba(239, 68, 68, 0.28);
  
  --success: #10b981;
  --success-bg: rgba(16, 185, 129, 0.12);
  --success-border: rgba(16, 185, 129, 0.28);
  
  --warning: #f59e0b;
  --warning-bg: rgba(245, 158, 11, 0.12);
  --warning-border: rgba(245, 158, 11, 0.28);
  
  --radius-sm: 8px;
  --radius: 12px;
  --radius-lg: 16px;
  --radius-xl: 20px;
  
  --font-family: -apple-system, BlinkMacSystemFont, "SF Pro Display", "Inter", "Segoe UI", Roboto, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;

  /* Safe Area Insets for iOS Notch / Dynamic Island / Home Indicator */
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
}

/* Standalone / PWA Fullscreen Mode (Added to iOS Home Screen) */
@media all and (display-mode: standalone) {
  :root {
    --safe-top: max(env(safe-area-inset-top, 0px), 48px);
    --safe-bottom: max(env(safe-area-inset-bottom, 0px), 20px);
  }
}

@supports (-webkit-touch-callout: none) {
  @media all and (display-mode: standalone) {
    :root {
      --safe-top: max(env(safe-area-inset-top, 0px), 50px);
    }
  }
}

/* ==========================================================================
   Reset & Base Styles
   ========================================================================== */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  scroll-behavior: smooth;
  height: 100%;
}

body {
  background-color: var(--bg-page);
  color: var(--text-main);
  font-family: var(--font-family);
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  overflow-x: hidden;
  position: relative;
  line-height: 1.5;
}

/* ==========================================================================
   Typography & SVGs
   ========================================================================== */
h1, h2, h3, h4, h5, h6 {
  color: var(--text-main);
  font-weight: 700;
  line-height: 1.3;
}

.icon {
  width: 18px;
  height: 18px;
  stroke-width: 2;
  stroke: currentColor;
  fill: none;
  stroke-linecap: round;
  stroke-linejoin: round;
  vertical-align: middle;
  flex-shrink: 0;
}
.icon-sm {
  width: 15px;
  height: 15px;
}
.icon-lg {
  width: 22px;
  height: 22px;
}

/* ==========================================================================
   Responsive Navigation Bar (iOS / Mobile / iPad / Desktop)
   ========================================================================== */
.portal-nav {
  background: rgba(13, 20, 36, 0.92);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 100;
  width: 100%;
  padding-top: max(var(--safe-top), env(safe-area-inset-top, 0px));
}

.portal-nav-inner {
  max-width: 1240px;
  width: 100%;
  margin: 0 auto;
  padding: 10px 20px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  min-height: 56px;
}

.portal-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
  font-size: 1.15rem;
  letter-spacing: -0.01em;
  color: var(--text-main);
  text-decoration: none;
  flex-shrink: 0;
}

.portal-brand-badge {
  background: var(--primary-light);
  color: var(--accent-sky);
  border: 1px solid rgba(56, 189, 248, 0.35);
  font-size: 0.72rem;
  font-weight: 700;
  padding: 3px 8px;
  border-radius: 6px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  white-space: nowrap;
}

/* Desktop Actions Container */
.portal-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

/* Mobile Hamburger Toggle */
.nav-toggle-btn {
  display: none;
  width: 42px;
  height: 42px;
  min-height: 42px;
  padding: 0;
  background: var(--bg-surface-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-main);
  cursor: pointer;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 5px;
  transition: all 0.2s ease;
  touch-action: manipulation;
  z-index: 110;
}

.nav-toggle-btn:active {
  transform: scale(0.95);
  background: #243048;
}

.hamburger-line {
  width: 20px;
  height: 2px;
  background: var(--text-main);
  border-radius: 2px;
  transition: all 0.25s ease-in-out;
}

.nav-toggle-btn.active .hamburger-line:nth-child(1) {
  transform: translateY(7px) rotate(45deg);
}
.nav-toggle-btn.active .hamburger-line:nth-child(2) {
  opacity: 0;
}
.nav-toggle-btn.active .hamburger-line:nth-child(3) {
  transform: translateY(-7px) rotate(-45deg);
}

.portal-nav-backdrop {
  display: none;
}

/* ==========================================================================
   Buttons & Interactive Elements
   ========================================================================== */
.btn {
  padding: 9px 16px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--bg-surface-elevated);
  color: var(--text-main);
  font-weight: 600;
  font-size: 0.88rem;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: all 0.15s ease-in-out;
  text-decoration: none;
  line-height: 1.2;
  white-space: nowrap;
  touch-action: manipulation;
  min-height: 38px;
}

.btn:hover {
  background: #243048;
  border-color: var(--border-hover);
  color: #ffffff;
}

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

.btn-sm {
  padding: 7px 12px;
  font-size: 0.82rem;
  min-height: 34px;
  border-radius: var(--radius-sm);
}

.btn-primary {
  background: var(--primary);
  border-color: rgba(37, 99, 235, 0.7);
  color: #ffffff;
}
.btn-primary:hover {
  background: var(--primary-hover);
  border-color: var(--primary-hover);
  box-shadow: 0 0 16px rgba(37, 99, 235, 0.4);
}

.btn-secondary {
  background: var(--bg-surface-elevated);
  border-color: var(--border);
  color: var(--text-muted);
}
.btn-secondary:hover {
  color: var(--text-main);
  border-color: var(--border-hover);
  background: #232d42;
}

.btn-danger {
  background: var(--danger-bg);
  color: #fca5a5;
  border-color: var(--danger-border);
}
.btn-danger:hover {
  background: var(--danger);
  color: #ffffff;
  border-color: var(--danger);
  box-shadow: 0 0 14px rgba(239, 68, 68, 0.35);
}

.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  pointer-events: none;
  transform: none !important;
}

/* ==========================================================================
   Container Layout
   ========================================================================== */
.portal-container {
  max-width: 1240px;
  width: 100%;
  margin: 0 auto;
  padding: 20px 24px calc(24px + var(--safe-bottom)) 24px;
  flex: 1;
  min-width: 0;
}

/* Status Indicator Pill */
.status-indicator {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font-size: 0.8rem;
  color: var(--text-muted);
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--border);
  padding: 5px 12px;
  border-radius: 20px;
  white-space: nowrap;
}
.status-indicator-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--success);
  box-shadow: 0 0 8px var(--success);
  flex-shrink: 0;
}

/* Section Header */
.section-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
  gap: 16px;
  flex-wrap: wrap;
}

.section-title {
  font-size: 1.2rem;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.section-subtitle {
  color: var(--text-muted);
  font-size: 0.86rem;
  margin-top: 4px;
  line-height: 1.4;
}

/* ==========================================================================
   Segmented Tabs Navigation (Smooth Horizontal Scroll on Touch)
   ========================================================================== */
.tabs-header {
  display: flex;
  gap: 6px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 22px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
  padding-bottom: 2px;
}
.tabs-header::-webkit-scrollbar {
  display: none;
}

.tab-btn {
  padding: 10px 18px;
  background: transparent;
  border: none;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  font-weight: 600;
  font-size: 0.88rem;
  color: var(--text-muted);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  transition: all 0.15s ease-in-out;
  white-space: nowrap;
  flex-shrink: 0;
  touch-action: manipulation;
  min-height: 42px;
  border-radius: var(--radius-sm) var(--radius-sm) 0 0;
}

.tab-btn:hover {
  color: var(--text-main);
  background: rgba(255, 255, 255, 0.03);
}

.tab-btn.active {
  color: var(--accent-sky);
  border-bottom-color: var(--accent-sky);
  background: rgba(56, 189, 248, 0.05);
}

.tab-pane {
  display: none;
}
.tab-pane.active {
  display: block;
}

/* ==========================================================================
   Stats Cards (Modern Grid)
   ========================================================================== */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
  margin-bottom: 24px;
}

.stat-card {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px;
  transition: border-color 0.2s, box-shadow 0.2s;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.15);
  min-width: 0;
}

.stat-card:hover {
  border-color: var(--border-hover);
}

.stat-card .label {
  font-size: 0.76rem;
  color: var(--text-muted);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 10px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.stat-card .value {
  font-size: clamp(1.6rem, 3.2vw, 2.2rem);
  font-weight: 800;
  color: var(--text-main);
  letter-spacing: -0.02em;
  line-height: 1.1;
}

/* ==========================================================================
   Filter Bars & Search Controls
   ========================================================================== */
.filter-bar {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 18px;
  margin-bottom: 20px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.15);
}

.filter-group {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  min-width: 0;
}

.filter-inputs-row {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  flex: 1;
  min-width: 0;
}

.filter-item {
  min-width: 0;
}

.filter-item.search-filter-item {
  flex: 1 1 220px;
}

.filter-actions-row {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.filter-checkbox-label {
  font-size: 0.85rem;
  display: flex;
  align-items: center;
  gap: 7px;
  cursor: pointer;
  color: var(--text-muted);
  user-select: none;
  white-space: nowrap;
}

.filter-checkbox-label input[type="checkbox"] {
  width: 16px;
  height: 16px;
  accent-color: var(--primary);
  cursor: pointer;
}

/* ==========================================================================
   Form Controls (iOS Safari 16px Auto-Zoom Safe)
   ========================================================================== */
.form-control {
  background: var(--bg-input);
  color: var(--text-main);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 9px 14px;
  font-size: 0.92rem;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
  width: 100%;
  box-sizing: border-box;
  -webkit-appearance: none;
  appearance: none;
}

.form-control:focus {
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px rgba(56, 189, 248, 0.2);
}

select.form-control {
  cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%2394a3b8' 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 12px center;
  background-size: 16px;
  padding-right: 36px;
}

textarea.form-control {
  min-height: 80px;
  resize: vertical;
  line-height: 1.5;
}

.form-group {
  margin-bottom: 16px;
  min-width: 0;
}

.form-group label {
  display: block;
  font-weight: 600;
  font-size: 0.85rem;
  margin-bottom: 6px;
  color: var(--text-main);
}

.form-group small {
  display: block;
  font-size: 0.78rem;
  color: var(--text-muted);
  margin-top: 4px;
  line-height: 1.4;
}

/* Flexible Form Grids */
.form-grid {
  display: grid;
  gap: 14px;
  margin-bottom: 14px;
}
.form-grid-4 {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}
.form-grid-3 {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}
.form-grid-2 {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.form-row {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}
.form-row .form-group {
  flex: 1 1 200px;
}

/* ==========================================================================
   Tables & Card Transformation (Mobile Responsive)
   ========================================================================== */
.table-responsive {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.15);
  margin-bottom: 16px;
}

table.portal-table {
  width: 100%;
  border-collapse: collapse;
  text-align: left;
  font-size: 0.88rem;
  min-width: 600px;
}

.portal-table th, 
.portal-table td {
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}

.portal-table th {
  background: rgba(14, 21, 36, 0.9);
  font-weight: 600;
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  position: sticky;
  top: 0;
  z-index: 2;
}

.portal-table tr:last-child td {
  border-bottom: none;
}

.portal-table tr:hover td {
  background: rgba(255, 255, 255, 0.02);
}

.log-question-prefix,
.log-response-prefix {
  display: none;
}

/* Pagination Bar */
.pagination-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 16px;
  gap: 12px;
  flex-wrap: wrap;
}

.pagination-info {
  font-size: 0.84rem;
  color: var(--text-muted);
}

.pagination-controls {
  display: flex;
  gap: 8px;
}

/* ==========================================================================
   Badges & Tags
   ========================================================================== */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 4px 10px;
  border-radius: 6px;
  font-size: 0.75rem;
  font-weight: 600;
  line-height: 1.2;
  white-space: nowrap;
}

.badge-safe {
  background: var(--success-bg);
  color: #34d399;
  border: 1px solid var(--success-border);
}
.badge-blocked {
  background: var(--danger-bg);
  color: #f87171;
  border: 1px solid var(--danger-border);
}
.badge-warning {
  background: var(--warning-bg);
  color: #fbbf24;
  border: 1px solid var(--warning-border);
}
.badge-neutral {
  background: rgba(148, 163, 184, 0.12);
  color: #cbd5e1;
  border: 1px solid rgba(148, 163, 184, 0.25);
}

.topic-tag {
  background: rgba(56, 189, 248, 0.12);
  color: #7dd3fc;
  border: 1px solid rgba(56, 189, 248, 0.25);
  padding: 4px 10px;
  border-radius: 12px;
  font-size: 0.78rem;
  font-weight: 600;
  display: inline-block;
  margin-right: 6px;
  margin-top: 4px;
}

/* ==========================================================================
   Summaries List
   ========================================================================== */
.summary-card {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 16px;
  transition: border-color 0.2s, box-shadow 0.2s;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.15);
}

.summary-card:hover {
  border-color: var(--border-hover);
}

.summary-card-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 14px;
  border-bottom: 1px solid var(--border);
  padding-bottom: 12px;
  gap: 12px;
}

/* ==========================================================================
   Admin Children Cards Grid
   ========================================================================== */
.children-cards-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 340px), 1fr));
  gap: 16px;
}

.child-card {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  transition: all 0.2s ease;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.15);
  min-width: 0;
}

.child-card:hover {
  border-color: var(--border-hover);
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.3);
}

.child-card-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 14px;
  gap: 10px;
}

.child-card-avatar {
  width: 48px;
  height: 48px;
  border-radius: var(--radius);
  background: var(--bg-surface-elevated);
  border: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.6rem;
  flex-shrink: 0;
}

.child-card-meta {
  font-size: 0.84rem;
  color: var(--text-muted);
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 16px;
  min-width: 0;
}

.child-card-meta-row {
  display: flex;
  align-items: baseline;
  gap: 8px;
  min-width: 0;
}

.child-card-meta-key {
  color: var(--text-dim);
  min-width: 95px;
  flex-shrink: 0;
}

.child-card-meta-val {
  color: var(--text-main);
  font-weight: 500;
  min-width: 0;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.child-card-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  border-top: 1px solid var(--border);
  padding-top: 14px;
}

.child-card-actions .btn {
  flex: 1 1 80px;
  justify-content: center;
  min-height: 38px;
}

/* ==========================================================================
   Modals (iOS Dynamic Height & Sticky Controls)
   ========================================================================== */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(5, 8, 15, 0.78);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  padding: 16px;
  padding-top: max(16px, var(--safe-top));
  padding-bottom: max(16px, var(--safe-bottom));
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.modal-content {
  background: var(--bg-surface);
  border: 1px solid var(--border-hover);
  border-radius: var(--radius-lg);
  padding: 24px;
  max-width: 520px;
  width: 100%;
  box-shadow: 0 24px 48px rgba(0, 0, 0, 0.7);
  color: var(--text-main);
  position: relative;
  max-height: calc(100dvh - 32px);
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.modal-content.modal-content-wide,
.modal-content.wide {
  max-width: 820px;
  width: 100%;
  padding: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  max-height: min(92vh, 92dvh);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 22px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-surface);
  flex-shrink: 0;
  gap: 12px;
}

.modal-title,
.modal-header h2 {
  font-size: 1.18rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0;
  min-width: 0;
}

.btn-icon-close {
  width: 34px;
  height: 34px;
  min-height: 34px;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-sm);
  font-size: 1rem;
}

.modal-body {
  padding: 22px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  flex: 1;
  min-height: 0;
}

.modal-footer {
  padding: 16px 22px;
  border-top: 1px solid var(--border);
  background: var(--bg-surface-elevated);
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  flex-shrink: 0;
  padding-bottom: max(16px, var(--safe-bottom));
}

/* ==========================================================================
   PLEX-STYLE PIN AUTH MODAL
   ========================================================================== */
.plex-pin-modal {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(5, 8, 15, 0.88);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1200;
  padding: calc(20px + max(var(--safe-top), env(safe-area-inset-top, 0px))) 20px calc(20px + max(var(--safe-bottom), env(safe-area-inset-bottom, 0px))) 20px;
}

.plex-pin-box {
  background: #111827;
  border: 1px solid #243048;
  border-radius: 20px;
  padding: 32px 28px;
  max-width: 380px;
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  box-shadow: 0 25px 50px rgba(0, 0, 0, 0.6);
  position: relative;
  animation: fadeInModal 0.25s ease;
}

@keyframes fadeInModal {
  from { opacity: 0; transform: scale(0.96); }
  to { opacity: 1; transform: scale(1); }
}

.plex-pin-box.shake {
  animation: shake 0.4s ease-in-out;
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20%, 60% { transform: translateX(-10px); }
  40%, 80% { transform: translateX(10px); }
}

.plex-pin-avatar {
  width: 72px;
  height: 72px;
  border-radius: 16px;
  background: #1a2336;
  border: 2px solid #334155;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 36px;
  margin-bottom: 12px;
}

.plex-pin-name {
  font-size: 1.25rem;
  font-weight: 700;
  color: #f8fafc;
}

.plex-pin-prompt {
  font-size: 0.85rem;
  color: #94a3b8;
  margin-top: 4px;
  margin-bottom: 22px;
  text-align: center;
  line-height: 1.4;
}

.plex-dots-container {
  display: flex;
  gap: 14px;
  margin-bottom: 20px;
  justify-content: center;
  flex-wrap: wrap;
}

.plex-pin-dot {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  border: 2px solid #475569;
  background: transparent;
  transition: all 0.2s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.plex-pin-dot.filled {
  background: #f59e0b;
  border-color: #f59e0b;
  box-shadow: 0 0 12px rgba(245, 158, 11, 0.6);
  transform: scale(1.15);
}

.plex-pin-dot.error {
  background: #ef4444;
  border-color: #ef4444;
  box-shadow: 0 0 12px rgba(239, 68, 68, 0.6);
}

.plex-numpad {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  width: 100%;
  max-width: 270px;
  margin-bottom: 16px;
}

.numpad-btn {
  height: 54px;
  border-radius: 14px;
  background: #1a2336;
  border: 1px solid #243048;
  color: #f8fafc;
  font-size: 1.35rem;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s ease-in-out;
  outline: none;
  user-select: none;
}

.numpad-btn:hover {
  background: #28354f;
  border-color: #3b4d70;
  transform: translateY(-2px);
}

.numpad-btn:active {
  transform: translateY(1px);
  background: #141b2b;
}

.numpad-btn.action-btn {
  font-size: 0.95rem;
  color: #94a3b8;
}

.plex-pin-error {
  font-size: 0.82rem;
  color: #ef4444;
  min-height: 20px;
  margin-bottom: 8px;
  text-align: center;
}

.plex-submit-btn {
  width: 100%;
  max-width: 270px;
  height: 46px;
  margin-bottom: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-weight: 600;
  font-size: 0.95rem;
}

.plex-pin-back-btn {
  background: none;
  border: none;
  color: #94a3b8;
  font-size: 0.86rem;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  border-radius: 8px;
  text-decoration: none;
  transition: all 0.15s ease;
}

.plex-pin-back-btn:hover {
  color: #f8fafc;
  background: rgba(255, 255, 255, 0.06);
}

/* Auth Cards / PIN Login Modals */
.modal-auth-card {
  max-width: 440px;
  text-align: center;
  padding: 30px 24px;
}

.modal-auth-card .modal-header {
  border-bottom: none;
  padding: 0 0 16px 0;
  justify-content: center;
}

.modal-auth-card .form-control {
  text-align: center;
  font-size: 1.4rem;
  letter-spacing: 0.25em;
  font-weight: 700;
  padding: 12px;
}

.auth-modal-actions {
  display: flex;
  gap: 10px;
  margin-top: 24px;
}

.auth-modal-actions .btn {
  flex: 1;
  min-height: 44px;
}

/* Callout Boxes */
.callout {
  border-radius: var(--radius-sm);
  padding: 14px 16px;
  font-size: 0.86rem;
  line-height: 1.5;
  margin-bottom: 16px;
  border: 1px solid transparent;
  min-width: 0;
  word-break: break-word;
}
.callout-info {
  background: rgba(56, 189, 248, 0.08);
  border-color: rgba(56, 189, 248, 0.22);
  color: #7dd3fc;
}
.callout-danger {
  background: var(--danger-bg);
  border-color: var(--danger-border);
  color: #fca5a5;
}

/* Telegram Config Box */
.telegram-config-box {
  background: rgba(255, 255, 255, 0.02);
  border: 1px solid var(--border);
  padding: 16px;
  border-radius: var(--radius);
  margin-bottom: 16px;
}

.telegram-config-title {
  font-weight: 700;
  font-size: 0.9rem;
  color: var(--text-main);
  margin-bottom: 12px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.custom-checkbox-label {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  font-size: 0.88rem;
  font-weight: 500;
  user-select: none;
}

.custom-checkbox-label input[type="checkbox"] {
  width: 18px;
  height: 18px;
  accent-color: var(--primary);
  cursor: pointer;
}

.checkbox-align-group {
  display: flex;
  align-items: flex-end;
  padding-bottom: 6px;
}

.prompt-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
  gap: 8px;
  flex-wrap: wrap;
}

.prompt-textarea {
  min-height: 140px;
  font-family: var(--font-mono);
  font-size: 0.84rem;
}

/* ==========================================================================
   RESPONSIVE BREAKPOINTS (Mobile, iPad, PC)
   ========================================================================== */

/* Tablet & iPad (max-width: 1024px) */
@media (max-width: 1024px) {
  .portal-container {
    padding-left: max(20px, var(--safe-left));
    padding-right: max(20px, var(--safe-right));
  }

  .stats-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

/* Mobile & Tablet Portrait (max-width: 860px) */
@media (max-width: 860px) {
  /* Navigation Drawer Pattern */
  .nav-toggle-btn {
    display: flex;
  }

  .portal-nav-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    top: 56px;
    background: rgba(0, 0, 0, 0.65);
    z-index: 95;
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
  }

  .portal-nav-backdrop.active {
    display: block;
  }

  .portal-actions {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    width: 100%;
    background: rgba(17, 24, 39, 0.98);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-bottom: 1px solid var(--border);
    padding: 18px 20px calc(20px + var(--safe-bottom)) 20px;
    display: none;
    flex-direction: column;
    gap: 12px;
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.6);
    z-index: 100;
  }

  .portal-actions.open {
    display: flex;
    animation: slideDownMenu 0.22s ease-out forwards;
  }

  @keyframes slideDownMenu {
    from {
      opacity: 0;
      transform: translateY(-8px);
    }
    to {
      opacity: 1;
      transform: translateY(0);
    }
  }

  .portal-actions .nav-action-btn {
    width: 100%;
    min-height: 44px;
    font-size: 0.92rem;
    justify-content: center;
  }

  .portal-actions .status-indicator {
    width: 100%;
    justify-content: center;
    padding: 9px;
    font-size: 0.85rem;
    box-sizing: border-box;
  }

  /* Form Grids on Medium/Small */
  .form-grid-4 {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

/* Mobile Phones (max-width: 680px) */
@media (max-width: 680px) {
  /* Prevent iOS Safari auto-zoom on input focus */
  .form-control,
  input,
  select,
  textarea {
    font-size: 16px !important;
  }

  .portal-container {
    padding: 14px max(14px, var(--safe-left)) calc(20px + var(--safe-bottom)) max(14px, var(--safe-right));
  }

  .portal-brand {
    font-size: 1.05rem;
    gap: 6px;
  }

  .portal-brand-badge {
    font-size: 0.68rem;
    padding: 2px 6px;
  }

  /* Section Header on Mobile */
  .section-header {
    flex-direction: column;
    align-items: stretch;
    gap: 12px;
  }

  .btn-add-child {
    width: 100%;
    min-height: 44px;
    font-size: 0.92rem;
  }

  /* Filter Bars on Mobile */
  .filter-bar {
    padding: 14px;
    flex-direction: column;
    align-items: stretch;
    gap: 12px;
  }

  .filter-group,
  .filter-inputs-row {
    flex-direction: column;
    align-items: stretch;
    width: 100%;
    gap: 10px;
  }

  .filter-actions-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    width: 100%;
  }

  .filter-actions-row .btn {
    width: 100%;
    min-height: 42px;
    justify-content: center;
  }

  .filter-item {
    width: 100%;
  }

  .filter-checkbox-label {
    padding: 4px 0;
  }

  /* Stats Grid 2 columns on Mobile */
  .stats-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
    margin-bottom: 18px;
  }

  .stat-card {
    padding: 14px;
  }

  .stat-card .label {
    font-size: 0.72rem;
    margin-bottom: 6px;
  }

  /* Children Cards Grid */
  .children-cards-grid {
    grid-template-columns: 1fr;
    gap: 14px;
  }

  .child-card {
    padding: 16px;
  }

  .child-card-actions {
    flex-direction: row;
    gap: 8px;
  }

  .child-card-actions .btn {
    min-height: 40px;
    font-size: 0.82rem;
  }

  /* Modals on Mobile */
  .modal-overlay {
    padding: 10px;
    padding-top: max(10px, var(--safe-top));
    padding-bottom: max(10px, var(--safe-bottom));
    align-items: flex-end; /* Sheet appearance on mobile */
  }

  .modal-content {
    border-radius: var(--radius-lg) var(--radius-lg) var(--radius-sm) var(--radius-sm);
    padding: 18px;
    max-height: calc(100dvh - 20px);
  }

  .modal-content.modal-content-wide,
  .modal-content.wide {
    max-height: calc(100dvh - 20px);
    border-radius: var(--radius-lg);
  }

  .modal-header {
    padding: 14px 16px;
  }

  .modal-body {
    padding: 16px;
  }

  .modal-footer {
    padding: 14px 16px;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
  }

  .modal-footer .btn {
    width: 100%;
    min-height: 44px;
    justify-content: center;
  }

  /* All Multi-column Form Grids collapse to 1 column on Mobile */
  .form-grid-4,
  .form-grid-3,
  .form-grid-2 {
    grid-template-columns: 1fr;
    gap: 12px;
  }

  /* Pagination Bar on Mobile */
  .pagination-bar {
    flex-direction: column;
    align-items: stretch;
    gap: 12px;
  }

  .pagination-info {
    text-align: center;
  }

  .pagination-controls {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    width: 100%;
  }

  .pagination-controls .btn {
    min-height: 42px;
    justify-content: center;
  }

  /* Responsive Table Card Transformation for Mobile Phones */
  .table-responsive {
    background: transparent;
    border: none;
    box-shadow: none;
    overflow: visible;
  }

  table.portal-table,
  .portal-table thead,
  .portal-table tbody,
  .portal-table tr,
  .portal-table td {
    display: block;
    width: 100%;
    min-width: 0;
  }

  .portal-table thead {
    display: none;
  }

  .portal-table tr {
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 14px 16px;
    margin-bottom: 12px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.2);
    display: grid;
    grid-template-columns: 1fr auto;
    grid-template-areas:
      "time status"
      "question question"
      "response response";
    gap: 10px;
    align-items: center;
  }

  .portal-table tr:hover td {
    background: transparent;
  }

  .portal-table td {
    padding: 0;
    border: none;
  }

  .portal-table td.col-time,
  .portal-table td:nth-child(1) {
    grid-area: time;
    font-size: 0.8rem;
    color: var(--text-muted);
  }

  .portal-table td.col-status,
  .portal-table td:nth-child(4) {
    grid-area: status;
    justify-self: end;
  }

  .portal-table td.col-question,
  .portal-table td:nth-child(2) {
    grid-area: question;
    border-top: 1px solid rgba(255, 255, 255, 0.06);
    padding-top: 8px;
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--text-main);
    line-height: 1.4;
  }

  .portal-table td.col-response,
  .portal-table td:nth-child(3) {
    grid-area: response;
    background: var(--bg-surface-elevated);
    border: 1px solid rgba(255, 255, 255, 0.05);
    border-radius: var(--radius-sm);
    padding: 10px 12px;
    font-size: 0.88rem;
    color: #cbd5e1;
    line-height: 1.5;
  }

  .log-question-prefix {
    color: var(--accent-sky);
    font-weight: 700;
    margin-right: 4px;
  }

  .log-response-prefix {
    color: var(--text-dim);
    font-weight: 600;
    font-size: 0.74rem;
    text-transform: uppercase;
    display: block;
    margin-bottom: 3px;
    letter-spacing: 0.04em;
  }
}
