/* ============================================================
   style.css — Automation Tutorial Platform Stylesheet
   Supports light/dark mode, responsive layout, code highlighting
   ============================================================ */

/* ---------- CSS Custom Properties ---------- */
:root {
  --bg:             #f1f5f9;
  --bg-alt:         #e2e8f0;
  --panel:          #ffffff;
  --panel-hover:    #f8fafc;
  --border:         #e2e8f0;
  --text:           #1e293b;
  --text-muted:     #64748b;
  --primary:        #2563eb;
  --primary-light:  #dbeafe;
  --primary-dark:   #1d4ed8;
  --accent:         #0ea5e9;
  --danger:         #ef4444;
  --danger-light:   #fee2e2;
  --success:        #22c55e;
  --success-light:  #dcfce7;
  --warning:        #f59e0b;
  --warning-light:  #fef3c7;
  --code-bg:        #1e293b;
  --code-text:      #e2e8f0;
  --sidebar-w:      280px;
  --header-h:       auto;
  --radius:         8px;
  --radius-lg:      12px;
  --shadow:         0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.06);
  --shadow-lg:      0 10px 25px rgba(0,0,0,.1);
  --font:           'Segoe UI', system-ui, -apple-system, sans-serif;
  --font-mono:      'Cascadia Code', 'Fira Code', 'Consolas', monospace;
  --transition:     180ms ease;
}

/* ---------- Dark Mode ---------- */
[data-theme="dark"] {
  --bg:            #0f172a;
  --bg-alt:        #1e293b;
  --panel:         #1e293b;
  --panel-hover:   #334155;
  --border:        #334155;
  --text:          #e2e8f0;
  --text-muted:    #94a3b8;
  --primary:       #3b82f6;
  --primary-light: #1e3a5f;
  --primary-dark:  #60a5fa;
  --danger-light:  #451a1a;
  --success-light: #14532d;
  --warning-light: #451a03;
  --code-bg:       #0f172a;
  --code-text:     #e2e8f0;
  --shadow:        0 1px 3px rgba(0,0,0,.3);
  --shadow-lg:     0 10px 25px rgba(0,0,0,.4);
}

/* ---------- Reset & Base ---------- */
*, *::before, *::after { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.6;
  color: var(--text);
  background: var(--bg);
  transition: background var(--transition), color var(--transition);
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

img { max-width: 100%; }

/* ---------- Utility ---------- */
.hidden  { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0,0,0,0); }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--panel);
  color: var(--text);
  font: inherit;
  font-size: 0.875rem;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition);
  white-space: nowrap;
}
.btn:hover { background: var(--panel-hover); box-shadow: var(--shadow); }
.btn-primary { background: var(--primary); color: #fff; border-color: var(--primary); }
.btn-primary:hover { background: var(--primary-dark); }
.btn-danger  { background: var(--danger); color: #fff; border-color: var(--danger); }
.btn-danger:hover  { opacity: .9; }
.btn-success { background: var(--success); color: #fff; border-color: var(--success); }
.btn-sm { padding: 4px 10px; font-size: 0.8rem; }

.compiler-dropdown {
  display: flex;
  align-items: center;
  gap: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
  transition: box-shadow var(--transition), border-color var(--transition);
}
.compiler-dropdown:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.15);
}
.compiler-label {
  padding: 6px 10px;
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--text-muted);
  white-space: nowrap;
  border-right: 1px solid var(--border);
  background: var(--surface-muted);
  user-select: none;
}
.compiler-select {
  padding: 6px 12px;
  border: none;
  background: transparent;
  color: var(--text);
  font: inherit;
  font-size: 0.82rem;
  cursor: pointer;
  outline: none;
  min-width: 120px;
}
.compiler-select option {
  background: var(--bg);
  color: var(--text);
}
.compiler-go-btn {
  padding: 6px 14px;
  font-size: 0.8rem;
  font-weight: 600;
  border: none;
  border-left: 1px solid var(--border);
  border-radius: 0;
  background: var(--primary);
  color: #fff;
  cursor: pointer;
  white-space: nowrap;
  transition: background var(--transition);
}
.compiler-go-btn:hover {
  background: var(--primary-dark);
}
.btn-full { width: 100%; justify-content: center; }
.btn-icon {
  padding: 6px;
  border: none;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  border-radius: var(--radius);
  font-size: 1.1rem;
  line-height: 1;
}
.btn-icon:hover { background: var(--bg-alt); color: var(--text); }

.admin-return-fab {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 110;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  padding: 0 16px;
  border-radius: 999px;
  background: var(--primary);
  color: #fff;
  box-shadow: var(--shadow-lg);
  font-size: 0.9rem;
  font-weight: 700;
}

.admin-return-fab:hover {
  background: var(--primary-dark);
  text-decoration: none;
}

/* ---------- Form elements ---------- */
.form-group { margin-bottom: 16px; }
.form-group label {
  display: block;
  margin-bottom: 4px;
  font-weight: 600;
  font-size: 0.875rem;
  color: var(--text-muted);
}
.form-group input,
.form-group textarea,
.form-group select {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--panel);
  color: var(--text);
  font: inherit;
  transition: border-color var(--transition);
}
.form-group input:focus,
.form-group textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37,99,235,.15);
}
.form-group textarea {
  min-height: 300px;
  resize: vertical;
  font-family: var(--font-mono);
  font-size: 0.875rem;
  line-height: 1.5;
}

.error-text {
  color: var(--danger);
  font-size: 0.85rem;
  margin: 4px 0 12px;
}

/* ---------- Login Page ---------- */
.login-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  background: var(--bg);
}
.login-card {
  width: 100%;
  max-width: 400px;
  padding: 40px 32px;
  background: var(--panel);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  text-align: center;
}
.login-card h1 { margin: 0 0 4px; font-size: 1.6rem; }
.login-subtitle { color: var(--text-muted); margin: 0 0 24px; font-size: .9rem; }
.login-card form { text-align: left; }
.login-footer { margin-top: 20px; font-size: .85rem; }

/* ========================================
   MAIN TUTORIAL LAYOUT (index.html)
   ======================================== */

/* --- Header --- */
.site-header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  box-shadow: var(--shadow);
  transition: background var(--transition);
}
.header-inner {
  max-width: 1440px;
  margin: 0 auto;
  padding: 0 20px;
}
.header-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 0;
  flex-wrap: wrap;
  gap: 10px;
}
.header-top h1 {
  margin: 0;
  font-size: 1.3rem;
  white-space: nowrap;
}
.header-top h1 span { color: var(--primary); }
.header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

/* Search */
.search-box {
  position: relative;
}
.search-box input {
  width: 240px;
  padding: 8px 12px 8px 34px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--bg);
  color: var(--text);
  font: inherit;
  font-size: .875rem;
  transition: border-color var(--transition), width var(--transition);
}
.search-box input:focus {
  outline: none;
  border-color: var(--primary);
  width: 300px;
}
.search-box::before {
  content: "🔍";
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  font-size: .8rem;
  pointer-events: none;
}
.search-results {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  right: 0;
  max-height: 360px;
  overflow-y: auto;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  z-index: 200;
}
.search-results.hidden { display: none; }
.search-result-item {
  padding: 10px 14px;
  cursor: pointer;
  border-bottom: 1px solid var(--border);
  font-size: .875rem;
  transition: background var(--transition);
}
.search-result-item:hover { background: var(--primary-light); }
.search-result-item:last-child { border-bottom: none; }
.search-result-item .sr-tech {
  font-size: .75rem;
  color: var(--text-muted);
}

/* Theme toggle */
.theme-toggle {
  font-size: 1.2rem;
  background: none;
  border: 1px solid var(--border);
  border-radius: 999px;
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background var(--transition);
  color: var(--text);
}
.theme-toggle:hover { background: var(--bg-alt); }

/* Technology tabs */
.tech-nav {
  display: flex;
  gap: 2px;
  overflow-x: auto;
  padding-bottom: 0;
  scrollbar-width: thin;
}
.tech-tab {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 10px 18px;
  background: transparent;
  border: none;
  border-bottom: 3px solid transparent;
  color: var(--text-muted);
  font: inherit;
  font-size: .875rem;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: all var(--transition);
}
.tech-tab:hover {
  color: var(--text);
  background: var(--bg-alt);
}
.tech-tab.active {
  color: var(--primary);
  border-bottom-color: var(--primary);
}
.tech-tab .tech-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 26px;
  border-radius: 6px;
  font-size: .7rem;
  font-weight: 800;
  background: var(--primary-light);
  color: var(--primary);
}

/* --- Main Layout --- */
.main-layout {
  display: flex;
  max-width: 1440px;
  margin: 0 auto;
  min-height: calc(100vh - 120px);
}

/* --- Sidebar --- */
.sidebar {
  width: var(--sidebar-w);
  min-width: var(--sidebar-w);
  border-right: 1px solid var(--border);
  background: var(--panel);
  overflow-y: auto;
  max-height: calc(100vh - 120px);
  position: sticky;
  top: 106px;
  transition: background var(--transition);
}
.sidebar-inner { padding: 12px 0; }
.sidebar-section {
  border-bottom: 1px solid var(--border);
  padding-bottom: 4px;
  margin-bottom: 4px;
}
.sidebar-section:last-child { border: none; }

.sidebar-title {
  display: flex;
  align-items: center;
  width: 100%;
  gap: 8px;
  padding: 10px 16px;
  border: none;
  background: transparent;
  color: var(--text);
  font: inherit;
  font-size: .875rem;
  font-weight: 700;
  cursor: pointer;
  text-align: left;
  transition: background var(--transition);
}
.sidebar-title:hover { background: var(--bg-alt); }
.sidebar-title.active {
  color: var(--primary);
  background: var(--primary-light);
}
.sidebar-title .arrow {
  font-size: .65rem;
  transition: transform var(--transition);
  margin-left: auto;
  color: var(--text-muted);
}
.sidebar-title.expanded .arrow { transform: rotate(90deg); }

.sub-list {
  list-style: none;
  margin: 0;
  padding: 0 0 4px 0;
  overflow: hidden;
  max-height: 0;
  transition: max-height 300ms ease;
}
.sub-list.open { max-height: 600px; }
.sub-item {
  padding: 6px 16px 6px 36px;
  font-size: .8rem;
  color: var(--text-muted);
  cursor: pointer;
  border-left: 3px solid transparent;
  margin-left: 16px;
}
.sub-item:hover {
  color: var(--text);
  background: var(--bg-alt);
}
.sub-item.active {
  color: var(--primary);
  border-left-color: var(--primary);
  background: var(--primary-light);
}

/* --- Content Panel --- */
.content-panel {
  flex: 1;
  min-width: 0;
  padding: 30px 40px 60px;
  background: var(--panel);
  transition: background var(--transition);
}

/* Rendered markdown-like content */
.content-panel h1 { font-size: 1.8rem; margin: 0 0 6px; border-bottom: 2px solid var(--border); padding-bottom: 10px; }
.content-panel h2 { font-size: 1.3rem; margin: 32px 0 12px; color: var(--primary); }
.content-panel h3 { font-size: 1.1rem; margin: 24px 0 8px; }
.content-panel p  { margin: 0 0 14px; line-height: 1.75; }
.content-panel ul, .content-panel ol { margin: 0 0 16px; padding-left: 22px; }
.content-panel li { margin-bottom: 6px; line-height: 1.65; }
.content-panel blockquote {
  margin: 16px 0;
  padding: 12px 16px;
  border-left: 4px solid var(--warning);
  background: var(--warning-light);
  border-radius: 0 var(--radius) var(--radius) 0;
  font-size: .9rem;
}
.content-panel hr { border: none; border-top: 1px solid var(--border); margin: 24px 0; }

/* Inline code */
.content-panel code:not(pre code) {
  padding: 2px 6px;
  border-radius: 4px;
  background: var(--bg-alt);
  font-family: var(--font-mono);
  font-size: .85em;
  color: var(--primary-dark);
}

/* Code blocks */
.code-block-wrapper {
  position: relative;
  margin: 12px 0 20px;
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--code-bg);
  box-shadow: var(--shadow);
}
.code-block-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 6px 14px;
  background: rgba(0,0,0,.2);
  border-bottom: 1px solid rgba(255,255,255,.06);
}
.code-lang {
  font-size: .75rem;
  font-weight: 700;
  text-transform: uppercase;
  color: var(--accent);
  letter-spacing: .04em;
}
.copy-btn {
  padding: 3px 10px;
  border: 1px solid rgba(255,255,255,.15);
  border-radius: 4px;
  background: transparent;
  color: #cbd5e1;
  font-size: .75rem;
  cursor: pointer;
  transition: all var(--transition);
}
.copy-btn:hover { background: rgba(255,255,255,.1); color: #fff; }
.copy-btn.copied { color: var(--success); border-color: var(--success); }

.code-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.code-block-wrapper pre {
  margin: 0;
  padding: 16px;
  overflow-x: auto;
  background: transparent;
  color: var(--code-text);
  font-family: var(--font-mono);
  font-size: .85rem;
  line-height: 1.6;
}
.code-block-wrapper code {
  font-family: var(--font-mono);
  background: none;
  padding: 0;
}

/* Topic chips shown at the top of each section */
.topic-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 12px 0 20px;
  padding: 0;
  list-style: none;
}
.topic-chips li {
  padding: 4px 12px;
  border-radius: 999px;
  background: var(--primary-light);
  color: var(--primary);
  font-size: .8rem;
  font-weight: 600;
  margin: 0;
}

/* Welcome / empty state */
.welcome-state {
  text-align: center;
  padding: 80px 20px;
  color: var(--text-muted);
}
.welcome-state h2 { color: var(--text); font-size: 1.5rem; }

/* Sidebar toggle for mobile */
.sidebar-toggle {
  display: none;
  position: fixed;
  bottom: 20px;
  left: 20px;
  z-index: 300;
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: var(--primary);
  color: #fff;
  font-size: 1.4rem;
  border: none;
  cursor: pointer;
  box-shadow: var(--shadow-lg);
  align-items: center;
  justify-content: center;
}

/* ========================================
   ADMIN PANEL (admin.html)
   ======================================== */
.admin-layout {
  display: flex;
  min-height: 100vh;
}
.admin-sidebar {
  width: 280px;
  min-width: 280px;
  background: var(--code-bg);
  color: #e2e8f0;
  padding: 20px 0;
  overflow-y: auto;
}
.admin-sidebar h2 {
  padding: 0 20px;
  font-size: 1rem;
  margin: 0 0 16px;
  color: #94a3b8;
  text-transform: uppercase;
  letter-spacing: .08em;
  font-weight: 700;
}
.admin-sidebar .admin-logo {
  padding: 0 20px 20px;
  border-bottom: 1px solid #334155;
  margin-bottom: 16px;
}
.admin-sidebar .admin-logo h1 {
  margin: 0;
  font-size: 1.2rem;
  color: #fff;
}
.admin-sidebar .admin-logo p {
  margin: 2px 0 0;
  font-size: .8rem;
  color: #64748b;
}

.admin-nav-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 20px;
  cursor: pointer;
  transition: background var(--transition);
  font-size: .875rem;
  border: none;
  background: transparent;
  color: #e2e8f0;
  width: 100%;
  text-align: left;
  font-family: inherit;
}
.admin-nav-item:hover { background: #334155; }
.admin-nav-item.active { background: var(--primary); color: #fff; }
.admin-nav-actions {
  display: flex;
  gap: 4px;
}
.admin-nav-actions button {
  padding: 2px 6px;
  font-size: .75rem;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  background: rgba(255,255,255,.1);
  color: #cbd5e1;
  transition: all var(--transition);
}
.admin-nav-actions button:hover { background: rgba(255,255,255,.2); color: #fff; }
.admin-nav-actions .del-btn:hover { background: var(--danger); color: #fff; }

.admin-section-list {
  margin-top: 8px;
  border-top: 1px solid #334155;
  padding-top: 8px;
}
.admin-section-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 20px 8px 30px;
  font-size: .8rem;
  color: #94a3b8;
  cursor: pointer;
  transition: background var(--transition);
}
.admin-section-item:hover { background: #334155; color: #e2e8f0; }
.admin-section-item.active { background: #1e3a5f; color: #93c5fd; }
.admin-section-item.dragging { opacity: .5; }

/* Admin main content */
.admin-main {
  flex: 1;
  padding: 30px 40px;
  overflow-y: auto;
  background: var(--bg);
}
.admin-main h2 {
  margin: 0 0 20px;
  font-size: 1.4rem;
}

/* Editor */
.editor-toolbar {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}
.preview-panel {
  min-height: 200px;
  padding: 20px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--panel);
  margin-top: 16px;
}

/* Modal */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.5);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
}
.modal-overlay.hidden { display: none; }
.modal-box {
  background: var(--panel);
  border-radius: var(--radius-lg);
  padding: 28px;
  width: 90%;
  max-width: 460px;
  box-shadow: var(--shadow-lg);
}
.modal-box h3 { margin: 0 0 16px; }
.modal-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  margin-top: 20px;
}

/* ========================================
   YOUTUBE EMBED & IMAGE SUPPORT
   ======================================== */
.youtube-embed {
  position: relative;
  width: 100%;
  max-width: 720px;
  padding-bottom: min(56.25%, 405px);
  margin: 16px auto;
  border-radius: var(--radius);
  overflow: hidden;
  background: #000;
  display: block;
}

.youtube-embed iframe {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  border: none;
}

.content-image {
  display: block;
  max-width: 100%;
  width: auto;
  height: auto;
  border-radius: var(--radius);
  margin: 16px auto 4px;
  box-shadow: var(--shadow);
}
/* Caption: a paragraph whose only content is italic text, right after an image */
.content-panel p > em:only-child {
  display: block;
  text-align: center;
  font-size: 0.8rem;
  color: var(--text-muted);
  font-style: italic;
  margin-bottom: 18px;
}

/* ========================================
   RESPONSIVE
   ======================================== */
@media (max-width: 1024px) {
  .sidebar { width: 240px; min-width: 240px; }
  .content-panel { padding: 24px; }
  .admin-main { padding: 24px; }
}

@media (max-width: 768px) {
  /* Mobile: hide sidebar, show toggle */
  .sidebar {
    position: fixed;
    left: -300px;
    top: 0;
    bottom: 0;
    z-index: 200;
    width: 280px;
    max-height: 100vh;
    top: 0;
    box-shadow: var(--shadow-lg);
    transition: left 300ms ease;
  }
  .sidebar.mobile-open {
    left: 0;
  }
  .sidebar-toggle { display: flex; }
  .content-panel { padding: 18px 16px 60px; }

  .header-top { padding: 10px 0; }
  .search-box input { width: 160px; }
  .search-box input:focus { width: 200px; }
  .admin-return-fab { right: 14px; bottom: 14px; }

  .tech-nav { padding: 0 10px 10px; }

  .admin-layout { flex-direction: column; }
  .admin-sidebar { width: 100%; min-width: 100%; max-height: 40vh; }
  .admin-main { padding: 20px 16px; }
}

@media (max-width: 480px) {
  .header-top h1 { font-size: 1rem; }
  .content-panel h1 { font-size: 1.3rem; }
  .login-card { padding: 28px 20px; }
}
