/* ==========================================================================
   PWA CODETUTOR AI - STYLING WORKSPACE (2-KOLOM & GLASSMORPHISM)
   ========================================================================== */

:root {
  --bg-deep: #080c14;
  --bg-card: #141e33;
  --border-glow: rgba(99, 102, 241, 0.25);
  --border-subtle: #1e293b;
  --primary-indigo: #6366f1;
  --accent-cyan: #06b6d4;
  --accent-pink: #ec4899;
  --text-main: #f8fafc;
  --text-muted: #94a3b8;
  --text-sub: #cbd5e1;
  --editor-bg: #0b0f19;
  --ai-bubble-bg: #1e1b4e;
  --user-bubble-bg: #2563eb;
}

* { box-sizing: border-box; margin: 0; padding: 0; font-family: 'Plus Jakarta Sans', sans-serif; }

html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }

body {
  background-color: var(--bg-deep);
  color: var(--text-main);
  height: 100vh;
  height: 100dvh; /* tinggi layar yang benar di HP (menyesuaikan bilah alamat) */
  display: flex;
  flex-direction: column;
  overflow: hidden;
  overscroll-behavior: none; /* cegah tarik-untuk-muat-ulang saat menggulir panel */
  /* aman dari poni/notch saat dipasang sebagai PWA */
  padding: env(safe-area-inset-top) env(safe-area-inset-right) 0 env(safe-area-inset-left);
}

button, select, input, textarea { touch-action: manipulation; }
button:focus-visible, select:focus-visible, input:focus-visible, textarea:focus-visible {
  outline: 2px solid var(--accent-cyan); outline-offset: 2px;
}

/* MODAL OVERLAY */
.login-overlay {
  position: fixed; inset: 0;
  background: rgba(8, 12, 20, 0.92);
  backdrop-filter: blur(20px);
  z-index: 9999;
  display: flex; align-items: flex-start; justify-content: center;
  padding: 20px; overflow-y: auto; /* kartu tetap bisa digulir di layar pendek */
}

.login-card {
  background: var(--bg-card);
  border: 1px solid var(--border-glow);
  border-radius: 20px; margin: auto;
  padding: 32px; width: 100%; max-width: 420px;
  text-align: center;
  box-shadow: 0 25px 60px -15px rgba(0, 0, 0, 0.7);
}

.login-icon-glow {
  background: linear-gradient(135deg, var(--primary-indigo), var(--accent-pink));
  width: 50px; height: 50px; border-radius: 14px;
  display: flex; align-items: center; justify-content: center;
  font-size: 24px; margin: 0 auto 16px auto;
}

.login-header h2 { font-size: 20px; font-weight: 800; margin-bottom: 6px; }
.badge-ai-glow { background: linear-gradient(90deg, #6366f1, #ec4899); -webkit-background-clip: text; -webkit-text-fill-color: transparent; }
.login-sub { font-size: 11px; color: var(--text-muted); margin-bottom: 22px; }

.form-group { text-align: left; margin-bottom: 16px; }
.form-group label { display: block; font-size: 11px; font-weight: 700; color: var(--text-sub); margin-bottom: 6px; text-transform: uppercase; }
.form-group input, .form-group select {
  width: 100%; padding: 12px; background: var(--editor-bg);
  border: 1px solid var(--border-subtle); border-radius: 8px; color: var(--text-main); font-size: 13px; outline: none;
}
.form-group input:focus, .form-group select:focus { border-color: var(--primary-indigo); }

.btn-login-futuristic {
  margin-top: 8px; background: linear-gradient(135deg, var(--primary-indigo), var(--accent-cyan));
  padding: 12px; font-size: 13px; width: 100%; border: none; border-radius: 8px; color: white; font-weight: 700; cursor: pointer;
}

/* NAVBAR */
.navbar {
  background: #0f172a;
  border-bottom: 1px solid var(--border-subtle); padding: 12px 24px;
  display: flex; justify-content: space-between; align-items: center; min-height: 64px; flex-shrink: 0;
}
.brand { display: flex; align-items: center; gap: 12px; }
.logo-box { background: linear-gradient(135deg, var(--primary-indigo), var(--accent-cyan)); width: 36px; height: 36px; border-radius: 8px; display: flex; align-items: center; justify-content: center; font-size: 18px; }
.brand-text h1 { font-size: 16px; font-weight: 800; display: flex; align-items: center; gap: 6px; }
.version-tag { font-size: 10px; background: rgba(255, 255, 255, 0.1); padding: 2px 6px; border-radius: 4px; color: var(--accent-cyan); font-family: 'JetBrains Mono', monospace; }
.subtitle { font-size: 11px; color: var(--text-muted); }

.nav-actions { display: flex; align-items: center; gap: 14px; }
.user-profile-badge { background: rgba(99, 102, 241, 0.12); border: 1px solid rgba(99, 102, 241, 0.3); padding: 6px 12px; border-radius: 10px; display: flex; align-items: center; gap: 8px; }
.user-name { font-size: 12px; font-weight: 700; color: #a5b4fc; }
.user-class { font-size: 10px; color: var(--text-muted); }
.btn-logout { background: rgba(239, 68, 68, 0.2); border: 1px solid rgba(239, 68, 68, 0.4); color: #fca5a5; border-radius: 6px; padding: 4px 8px; cursor: pointer; font-size: 11px; font-weight: 600; }
.btn-logout:hover { background: #ef4444; color: white; }

.status-badge { background: rgba(34, 197, 94, 0.1); color: #4ade80; border: 1px solid rgba(34, 197, 94, 0.25); padding: 6px 12px; border-radius: 20px; font-size: 11px; font-weight: 600; display: flex; align-items: center; gap: 6px; }
.pulse-dot { width: 8px; height: 8px; background-color: #22c55e; border-radius: 50%; box-shadow: 0 0 10px #22c55e; }

/* WORKSPACE LAYOUT (2 KOLOM) */
.workspace {
  display: grid;
  grid-template-columns: minmax(0, 1fr) clamp(300px, 30vw, 400px);
  grid-template-rows: minmax(0, 1.1fr) minmax(0, 0.9fr);
  gap: 16px; padding: 16px; flex: 1; min-height: 0; overflow: hidden;
}

.card { background: var(--bg-card); border: 1px solid var(--border-subtle); border-radius: 14px; display: flex; flex-direction: column; overflow: hidden; min-height: 0; }
.editor-card { grid-column: 1 / 2; grid-row: 1 / 2; }
.preview-card { grid-column: 1 / 2; grid-row: 2 / 3; }
.ai-card { grid-column: 2 / 3; grid-row: 1 / 3; }

.card-header { background: rgba(15, 23, 42, 0.6); padding: 10px 14px; border-bottom: 1px solid var(--border-subtle); display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-shrink: 0; }
.card-body { flex: 1; position: relative; display: flex; flex-direction: column; overflow: hidden; min-height: 0; }

.tab-group { display: flex; gap: 6px; }
.tab-btn { background: transparent; border: none; color: var(--text-muted); padding: 6px 12px; font-size: 11px; font-weight: 700; border-radius: 6px; cursor: pointer; }
.tab-btn.active { background: var(--primary-indigo); color: #ffffff; }

.tab-content { display: none !important; }
.tab-content.active { display: flex !important; }

.editor-actions { display: flex; align-items: center; gap: 6px; }
.preset-dropdown { background: var(--editor-bg); border: 1px solid var(--border-glow); color: #a5b4fc; padding: 5px 10px; border-radius: 6px; font-size: 11px; outline: none; cursor: pointer; }
.btn-action { background: rgba(255, 255, 255, 0.06); border: 1px solid var(--border-subtle); color: var(--text-main); padding: 5px 10px; border-radius: 6px; font-size: 11px; cursor: pointer; }
.btn-reset:hover { background: #ef4444; border-color: #ef4444; }

textarea { width: 100%; height: 100%; background-color: var(--editor-bg); color: #e2e8f0; font-family: 'JetBrains Mono', monospace; font-size: 13px; line-height: 1.6; padding: 14px; border: none; outline: none; resize: none; }

.materi-container { padding: 16px; overflow-y: auto; height: 100%; display: flex; flex-direction: column; gap: 14px; }
.materi-card { background: var(--editor-bg); border: 1px solid var(--border-subtle); border-radius: 10px; padding: 14px; }
.modul-badge { display: inline-block; background: rgba(99, 102, 241, 0.15); color: var(--accent-cyan); font-family: 'JetBrains Mono', monospace; font-size: 10px; font-weight: 700; padding: 2px 6px; border-radius: 4px; margin-bottom: 8px; }
.materi-card h3 { font-size: 14px; color: var(--text-main); margin-bottom: 6px; }
.materi-card p { font-size: 12px; color: var(--text-sub); line-height: 1.5; }

.browser-bar { gap: 10px; }
.window-dots { display: flex; gap: 5px; }
.dot-win { width: 9px; height: 9px; border-radius: 50%; }
.red { background-color: #ef4444; } .yellow { background-color: #f59e0b; } .green { background-color: #10b981; }
.browser-url { background: var(--editor-bg); color: var(--text-muted); font-size: 11px; padding: 4px 10px; border-radius: 6px; flex: 1; border: 1px solid var(--border-subtle); }
.preview-tag { font-size: 9px; font-family: 'JetBrains Mono', monospace; background: rgba(6, 182, 212, 0.15); color: var(--accent-cyan); padding: 2px 6px; border-radius: 4px; }

iframe { width: 100%; height: 100%; border: none; background-color: #ffffff; }

.ai-title { display: flex; align-items: center; gap: 8px; }
.ai-avatar-glow { font-size: 18px; background: rgba(99, 102, 241, 0.2); width: 32px; height: 32px; border-radius: 8px; display: flex; align-items: center; justify-content: center; }
.ai-title h3 { font-size: 13px; font-weight: 700; }
.ai-status { font-size: 10px; color: var(--text-muted); }

.chat-container { padding: 14px; gap: 10px; overflow-y: auto; background: rgba(8, 12, 20, 0.3); display: flex; flex-direction: column; flex: 1; }
.chat-bubble { padding: 10px 12px; border-radius: 10px; font-size: 12px; line-height: 1.5; max-width: 90%; }
.ai-bubble { background: var(--ai-bubble-bg); border: 1px solid rgba(99, 102, 241, 0.3); color: #e0e7ff; align-self: flex-start; }
.user-bubble { background: var(--user-bubble-bg); color: #ffffff; align-self: flex-end; }
.bubble-sender { font-size: 10px; font-weight: 700; margin-bottom: 4px; opacity: 0.8; }

.ai-footer-layout { padding: 10px; border-top: 1px solid var(--border-subtle); background: rgba(15, 23, 42, 0.6); display: flex; flex-direction: column; gap: 8px; flex-shrink: 0; }
.btn-quick-hint { width: 100%; background: linear-gradient(135deg, var(--primary-indigo), var(--accent-cyan)); color: white; border: none; padding: 10px; border-radius: 8px; font-weight: 700; font-size: 11px; cursor: pointer; }
.chat-input-group { display: flex; gap: 6px; width: 100%; }
.chat-input-group input { flex: 1; background: var(--editor-bg); border: 1px solid var(--border-subtle); border-radius: 8px; padding: 8px 12px; color: var(--text-main); font-size: 12px; outline: none; }
.btn-send-chat { width: 38px; background: var(--primary-indigo); border: none; border-radius: 8px; color: white; font-size: 13px; cursor: pointer; }

::-webkit-scrollbar { width: 5px; }
::-webkit-scrollbar-track { background: var(--editor-bg); }
::-webkit-scrollbar-thumb { background: var(--border-subtle); border-radius: 3px; }
/* STATUS KONEKSI / PWA (ditambahkan pada versi 3) */
.status-badge.is-offline { background: rgba(245, 158, 11, 0.12); color: #fbbf24; border-color: rgba(245, 158, 11, 0.3); }
.status-badge.is-off { background: rgba(239, 68, 68, 0.1); color: #fca5a5; border-color: rgba(239, 68, 68, 0.3); }
.status-badge.is-offline .pulse-dot { background-color: #f59e0b; box-shadow: 0 0 10px #f59e0b; }
.status-badge.is-off .pulse-dot { background-color: #ef4444; box-shadow: 0 0 10px #ef4444; }
.materi-card h4 { font-size: 12px; color: var(--accent-cyan); margin: 10px 0 4px 0; }
.materi-card ul { margin: 4px 0 6px 18px; font-size: 12px; color: var(--text-sub); line-height: 1.6; }
.code-box { background: #060a12; border: 1px solid var(--border-subtle); border-radius: 8px; padding: 10px; margin: 6px 0; overflow-x: auto; font-family: 'JetBrains Mono', monospace; font-size: 11px; color: #e2e8f0; line-height: 1.5; }
.materi-card code { font-family: 'JetBrains Mono', monospace; font-size: 11px; color: #a5b4fc; }

/* ==========================================================================
   RESPONSIF
   - di atas 1100px : tata letak desktop (editor + pratinjau | Tutor AI)
   - 901-1100px     : desktop ringkas
   - 900px ke bawah : satu panel penuh layar + navigasi bawah (HP & tablet tegak)
   ========================================================================== */

.mobile-nav { display: none; }

/* ---------- Laptop kecil / tablet mendatar ---------- */
@media (max-width: 1100px) {
  .subtitle { display: none; }
  .navbar { padding: 10px 16px; }
  .workspace { gap: 12px; padding: 12px; }
  .editor-header { flex-wrap: wrap; }
  .editor-actions { flex-wrap: wrap; }
}

/* ---------- HP dan tablet tegak ---------- */
@media (max-width: 900px) {

  /* Navbar ringkas */
  .navbar { padding: 8px 12px; min-height: 52px; gap: 8px; }
  .brand { gap: 8px; min-width: 0; }
  .logo-box { width: 30px; height: 30px; font-size: 15px; flex-shrink: 0; }
  .brand-text h1 { font-size: 14px; white-space: nowrap; }
  .version-tag { display: none; }
  .nav-actions { gap: 8px; min-width: 0; }
  .user-profile-badge { padding: 4px 8px; gap: 6px; }
  .user-avatar { display: none; }
  .user-info { display: flex; flex-direction: column; line-height: 1.25; min-width: 0; }
  .user-name { max-width: 72px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .btn-logout { min-height: 32px; padding: 6px 9px; }
  .status-badge { position: relative; padding: 5px 10px; font-size: 10px; }

  /* Satu panel per layar */
  .workspace {
    display: flex; flex-direction: column;
    padding: 8px; gap: 0;
  }
  .workspace > .card { display: none; flex: 1 1 auto; min-height: 0; }
  body[data-panel="editor"]  .workspace > .editor-card,
  body[data-panel="preview"] .workspace > .preview-card,
  body[data-panel="ai"]      .workspace > .ai-card { display: flex; }

  /* Navigasi panel di bawah */
  .mobile-nav {
    display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px;
    flex-shrink: 0;
    padding: 6px 8px calc(6px + env(safe-area-inset-bottom));
    background: rgba(15, 23, 42, 0.96);
    border-top: 1px solid var(--border-subtle);
  }
  .mobile-nav-btn {
    display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
    min-height: 48px; padding: 6px 4px;
    background: transparent; border: none; border-radius: 10px;
    color: var(--text-muted); font-size: 11px; font-weight: 700; cursor: pointer;
  }
  .mobile-nav-btn.active { background: rgba(99, 102, 241, 0.18); color: #c7d2fe; }
  .mobile-nav-icon { font-size: 18px; line-height: 1; }
  .mobile-nav-btn:focus-visible { outline-offset: -2px; }

  /* Header editor: baris 1 = tab, baris 2 = pilihan modul + tombol ikon */
  .card-header { padding: 8px 10px; }
  .editor-header { flex-direction: column; align-items: stretch; gap: 8px; }
  .tab-group { width: 100%; }
  .tab-btn { flex: 1; min-height: 38px; font-size: 12px; }
  .editor-actions { flex-wrap: nowrap; gap: 6px; }
  .preset-dropdown { flex: 1 1 auto; min-width: 0; min-height: 40px; font-size: 16px; text-overflow: ellipsis; }
  .btn-action { min-height: 40px; min-width: 40px; padding: 8px 10px; font-size: 13px; flex-shrink: 0; }

  /* Editor: 16px mencegah iPhone memperbesar layar otomatis saat mengetik */
  textarea { font-size: 16px; line-height: 1.5; padding: 12px; tab-size: 2; }

  /* Materi */
  .materi-container { padding: 12px; gap: 12px; }
  .materi-card { padding: 12px; }
  .materi-card h3 { font-size: 15px; }
  .materi-card p, .materi-card ul { font-size: 13px; }
  .materi-card code { overflow-wrap: anywhere; }
  .code-box { font-size: 12px; }

  /* Pratinjau */
  .browser-url { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

  /* Tutor AI */
  .chat-container { padding: 12px; }
  .chat-bubble { font-size: 13px; max-width: 94%; }
  .ai-footer-layout { padding: 8px; }
  .btn-quick-hint { min-height: 44px; font-size: 12px; }
  .chat-input-group input { min-height: 44px; font-size: 16px; }
  .btn-send-chat { width: 48px; min-height: 44px; font-size: 15px; }

  /* Modal masuk */
  .login-card { padding: 24px 20px; }
  .form-group input, .form-group select { font-size: 16px; min-height: 44px; }
  .btn-login-futuristic { min-height: 46px; font-size: 14px; }
}

/* ---------- HP kecil: status koneksi jadi titik berwarna ---------- */
@media (max-width: 560px) {
  .btn-logout-label, .btn-label { display: none; }
  .status-badge { padding: 6px 9px; }
  /* teks tetap terbaca pembaca layar, hanya disembunyikan secara visual */
  #status-text {
    position: absolute; width: 1px; height: 1px; overflow: hidden;
    clip: rect(0 0 0 0); clip-path: inset(50%); white-space: nowrap;
  }
}

/* ---------- HP mendatar (layar pendek) ---------- */
@media (max-width: 900px) and (max-height: 480px) {
  .navbar { min-height: 40px; padding-top: 4px; padding-bottom: 4px; }
  .logo-box { width: 26px; height: 26px; font-size: 13px; }
  .mobile-nav { padding-top: 3px; }
  .mobile-nav-btn { flex-direction: row; gap: 6px; min-height: 36px; }
  .editor-header { flex-direction: row; align-items: center; }
  .tab-group { width: auto; }
  .tab-btn { flex: none; }
  .editor-actions { flex: 1; }
}
