/* =========================================
   WWWD Editor — Dedicated Stylesheet
   Responsive: Mobile / Tablet / Desktop
   ========================================= */

/* ---- CSS Variables ---- */
:root {
  --bg-deep:    #020617;
  --bg-surface: #0f172a;
  --bg-panel:   #1e293b;
  --bg-hover:   #334155;

  --primary:    #38bdf8;
  --primary-glow: rgba(56,189,248,0.25);
  --secondary:  #818cf8;
  --danger:     #f87171;

  --text-main:  #f1f5f9;
  --text-dim:   #94a3b8;
  --text-muted: #475569;

  --border:     rgba(255,255,255,0.07);
  --border-strong: rgba(255,255,255,0.12);

  --font-sans:  'Inter', system-ui, -apple-system, sans-serif;
  --font-heading: 'Outfit', sans-serif;
  --font-mono:  'JetBrains Mono', 'Courier New', monospace;

  --header-h:  60px;
  --sidebar-w: 64px;
  --status-h:  36px;
  --mobile-tabs-h: 56px;

  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;

  --transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

[data-theme="light"] {
  --bg-deep:    #f8fafc;
  --bg-surface: #ffffff;
  --bg-panel:   #f1f5f9;
  --bg-hover:   #e2e8f0;
  --text-main:  #0f172a;
  --text-dim:   #334155;
  --text-muted: #64748b;
  --border:     rgba(0,0,0,0.07);
  --border-strong: rgba(0,0,0,0.12);
}

/* ---- Reset ---- */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-font-smoothing: antialiased;
}

html, body {
  height: 100%;
  overflow: hidden;
}

body {
  font-family: var(--font-sans);
  background: var(--bg-deep);
  color: var(--text-main);
  display: flex;
  flex-direction: column;
  font-size: 14px;
}

.hidden { display: none !important; }

/* ---- Scrollbar ---- */
::-webkit-scrollbar { width: 4px; height: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 10px; }
::-webkit-scrollbar-thumb:hover { background: var(--primary); }

/* ========================================
   HEADER
   ======================================== */
.app-header {
  height: var(--header-h);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border);
  z-index: 200;
  flex-shrink: 0;
  gap: 12px;
}

.logo {
  display: flex;
  align-items: center;
  gap: 10px;
  font-family: var(--font-heading);
  font-weight: 800;
  font-size: 20px;
  background: linear-gradient(135deg, #38bdf8, #818cf8);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  text-decoration: none;
  flex-shrink: 0;
}

.logo img {
  flex-shrink: 0;
  border-radius: var(--radius-sm);
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: nowrap;
}

/* ---- Buttons ---- */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 14px;
  border-radius: var(--radius-md);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  border: 1px solid var(--border-strong);
  background: var(--bg-panel);
  color: var(--text-main);
  transition: var(--transition);
  white-space: nowrap;
  font-family: var(--font-sans);
}

.btn:hover {
  background: var(--bg-hover);
  border-color: var(--primary);
  color: var(--primary);
}

.btn.icon-only { padding: 7px 10px; }

.btn-primary {
  background: linear-gradient(135deg, #38bdf8, #818cf8);
  border: none;
  color: white;
  font-weight: 600;
}

.btn-primary:hover {
  opacity: 0.9;
  color: white;
  transform: translateY(-1px);
  box-shadow: 0 4px 15px rgba(56,189,248,0.3);
}

/* ---- Dropdown ---- */
.dropdown { position: relative; }

.dropdown-menu {
  display: none;
  position: absolute;
  right: 0;
  top: calc(100% + 8px);
  min-width: 200px;
  background: var(--bg-panel);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-lg);
  box-shadow: 0 20px 40px rgba(0,0,0,0.4);
  z-index: 9999;
  padding: 6px;
  animation: dropIn 0.15s ease-out;
}

.dropdown-menu.show { display: block; }

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

.dropdown-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  border-radius: var(--radius-md);
  font-size: 13px;
  color: var(--text-dim);
  cursor: pointer;
  transition: var(--transition);
}

.dropdown-item:hover {
  background: var(--bg-hover);
  color: var(--primary);
}

.dropdown-item i {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
}

/* ========================================
   MAIN LAYOUT
   ======================================== */
.app-main {
  flex: 1;
  display: flex;
  overflow: hidden;
  min-height: 0;
}

/* ---- Sidebar ---- */
.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: var(--bg-surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 16px 0;
  gap: 4px;
  z-index: 100;
}

.sidebar-spacer { flex: 1; }

.sidebar-item {
  width: 44px;
  height: 44px;
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  cursor: pointer;
  transition: var(--transition);
  position: relative;
}

.sidebar-item:hover {
  background: var(--bg-panel);
  color: var(--text-main);
}

.sidebar-item.active {
  background: rgba(56,189,248,0.1);
  color: var(--primary);
}

.sidebar-item.active::before {
  content: '';
  position: absolute;
  left: -1px;
  top: 50%;
  transform: translateY(-50%);
  width: 3px;
  height: 22px;
  background: var(--primary);
  border-radius: 0 4px 4px 0;
  box-shadow: 0 0 12px var(--primary-glow);
}

/* ========================================
   WORKSPACE (Panels + Panes)
   ======================================== */
.workspace {
  flex: 1;
  display: flex;
  position: relative;
  overflow: hidden;
  min-width: 0;
}

/* ---- Side Panels (overlay) ---- */
.side-panel {
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 300px;
  background: var(--bg-panel);
  border-right: 1px solid var(--border);
  z-index: 500;
  display: flex;
  flex-direction: column;
  box-shadow: 8px 0 30px rgba(0,0,0,0.3);
  transform: translateX(0);
  transition: transform 0.3s cubic-bezier(0.4,0,0.2,1);
}

.side-panel.hidden {
  transform: translateX(-110%);
  pointer-events: none;
}

.panel-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.panel-header h3 {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-main);
}

.icon-btn {
  width: 30px;
  height: 30px;
  border-radius: var(--radius-sm);
  border: none;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: var(--transition);
}

.icon-btn:hover { background: var(--bg-hover); color: var(--text-main); }

.panel-content {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
}

.panel-footer {
  padding: 16px 20px;
  border-top: 1px solid var(--border);
  display: flex;
  flex-shrink: 0;
}

/* Settings */
.setting-group {
  margin-bottom: 24px;
}

.setting-group label {
  display: block;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-bottom: 10px;
}

.setting-row {
  display: flex;
  align-items: center;
  gap: 12px;
}

.setting-group input[type="range"] {
  flex: 1;
  accent-color: var(--primary);
}

.setting-group select {
  width: 100%;
  padding: 8px 12px;
  background: var(--bg-hover);
  color: var(--text-main);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-family: var(--font-sans);
  outline: none;
}

.setting-group select:focus { border-color: var(--primary); }

/* Guide items */
.guide-item {
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
  color: var(--text-dim);
}

.guide-item code {
  background: rgba(56,189,248,0.08);
  color: var(--primary);
  padding: 2px 6px;
  border-radius: 4px;
  font-family: var(--font-mono);
  font-size: 12px;
}

/* Doc items */
.doc-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px;
  border-radius: var(--radius-md);
  cursor: pointer;
  border: 1px solid var(--border);
  margin-bottom: 8px;
  background: var(--bg-surface);
  transition: var(--transition);
}

.doc-item:hover { border-color: var(--primary); background: var(--bg-hover); }
.doc-name { font-size: 13px; font-weight: 500; }
.doc-date { font-size: 10px; color: var(--text-muted); margin-top: 2px; }

/* ========================================
   EDITOR & PREVIEW PANES
   ======================================== */
.pane {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-width: 0;
}

#editor-pane {
  border-right: 1px solid var(--border);
  background: #020617;
}

#preview-pane {
  background: #0a1628;
}

/* Pane Header */
.pane-header {
  height: 44px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.12em;
  color: var(--text-muted);
}

.save-badge {
  font-size: 10px;
  padding: 2px 8px;
  border-radius: 100px;
  background: rgba(34,197,94,0.1);
  color: #22c55e;
  border: 1px solid rgba(34,197,94,0.2);
  font-weight: 600;
  letter-spacing: 0;
}

/* Toolbar */
.toolbar {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: 2px;
  padding: 6px 12px;
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}

.toolbar-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 6px 8px;
  min-width: 30px;
  height: 30px;
  border: none;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 12px;
  font-weight: 600;
  font-family: var(--font-sans);
  transition: var(--transition);
}

.toolbar-btn:hover {
  background: var(--bg-panel);
  color: var(--primary);
}

.toolbar-btn.compact {
  height: 26px;
  padding: 0 8px;
  font-size: 10px;
}

.toolbar-sep {
  width: 1px;
  height: 18px;
  background: var(--border-strong);
  margin: 0 4px;
  flex-shrink: 0;
}

/* Editor Textarea */
textarea#editor {
  flex: 1;
  width: 100%;
  resize: none;
  border: none;
  outline: none;
  background: transparent;
  color: var(--text-main);
  font-family: var(--font-mono);
  font-size: 15px;
  line-height: 1.8;
  padding: 32px 40px;
  caret-color: var(--primary);
  tab-size: 2;
}

textarea#editor::placeholder { color: var(--text-muted); }

/* Preview Area */
.preview-area {
  flex: 1;
  overflow-y: auto;
  padding: 40px 48px;
}

/* ---- Prose (Preview Content) ---- */
.prose {
  max-width: 720px;
  margin: 0 auto;
  color: var(--text-dim);
  font-family: var(--font-sans);
  font-size: 16px;
  line-height: 1.8;
}

.prose h1 {
  font-family: var(--font-heading);
  font-size: 2.5rem;
  font-weight: 800;
  color: var(--text-main);
  letter-spacing: -0.03em;
  margin: 0 0 1.5rem;
  padding-bottom: 1rem;
  border-bottom: 1px solid var(--border);
}

.prose h2 {
  font-family: var(--font-heading);
  font-size: 1.75rem;
  font-weight: 700;
  color: var(--text-main);
  margin: 2.5rem 0 1rem;
  padding-bottom: 0.5rem;
  border-bottom: 1px solid var(--border);
}

.prose h3 {
  font-size: 1.25rem;
  font-weight: 600;
  color: var(--text-main);
  margin: 2rem 0 0.75rem;
}

.prose p { margin-bottom: 1.25rem; }

.prose ul, .prose ol { padding-left: 1.5rem; margin-bottom: 1.25rem; }
.prose li { margin-bottom: 0.4rem; }

.prose blockquote {
  border-left: 4px solid var(--primary);
  background: rgba(56,189,248,0.05);
  padding: 16px 24px;
  margin: 24px 0;
  border-radius: 0 var(--radius-md) var(--radius-md) 0;
  font-style: italic;
}

.prose code:not(pre code) {
  background: rgba(56,189,248,0.08);
  color: var(--primary);
  padding: 2px 6px;
  border-radius: 4px;
  font-family: var(--font-mono);
  font-size: 0.88em;
}

.prose pre {
  background: #0f172a !important;
  border: 1px solid var(--border) !important;
  border-radius: var(--radius-lg) !important;
  padding: 20px 24px !important;
  margin: 24px 0 !important;
  overflow-x: auto;
}

.prose pre code { background: none !important; color: inherit; }

.prose table { width: 100%; border-collapse: collapse; margin: 24px 0; }
.prose th, .prose td { padding: 10px 14px; border: 1px solid var(--border); text-align: left; }
.prose th { background: var(--bg-panel); font-weight: 600; color: var(--text-main); }

.prose a { color: var(--primary); text-decoration: none; }
.prose a:hover { text-decoration: underline; }

.prose hr { border: none; border-top: 1px solid var(--border); margin: 2rem 0; }

.prose img { max-width: 100%; border-radius: var(--radius-md); margin: 16px 0; }

/* ========================================
   STATUS BAR
   ======================================== */
.status-bar {
  height: var(--status-h);
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  background: var(--bg-surface);
  border-top: 1px solid var(--border);
  font-size: 11px;
  color: var(--text-muted);
  z-index: 100;
}

.status-items { display: flex; align-items: center; gap: 16px; }
.status-item { display: flex; align-items: center; gap: 5px; }

/* ========================================
   MOBILE TABS
   ======================================== */
.mobile-tabs {
  display: none;
  height: var(--mobile-tabs-h);
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  z-index: 300;
}

.mobile-tab {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-size: 10px;
  font-weight: 600;
  font-family: var(--font-sans);
  cursor: pointer;
  transition: var(--transition);
  border-bottom: 2px solid transparent;
}

.mobile-tab.active {
  color: var(--primary);
  border-bottom-color: var(--primary);
}

/* ========================================
   ANIMATIONS
   ======================================== */
.fade-in { animation: fadeIn 0.3s ease-out; }
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(4px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ========================================
   PRINT / PDF
   ======================================== */
@media print {
  .app-header, .sidebar, .mobile-tabs, #editor-pane, .status-bar, .pane-header, .toolbar { display: none !important; }
  body { overflow: visible !important; height: auto !important; background: white !important; }
  .app-main, .workspace, #preview-pane, .preview-area { display: block !important; height: auto !important; overflow: visible !important; }
  .preview-area { padding: 0 !important; }
  .prose { max-width: 100% !important; color: black !important; }
}

/* ========================================
   RESPONSIVE — TABLET (768px – 1024px)
   ======================================== */
@media (max-width: 1024px) {
  .sidebar { width: 56px; }

  textarea#editor { padding: 24px 28px; }
  .preview-area { padding: 28px 32px; }

  .btn-label { display: none; }
  .btn { padding: 7px 10px; }
}

/* ========================================
   RESPONSIVE — MOBILE (< 768px)
   ======================================== */
@media (max-width: 767px) {
  :root {
    --header-h: 56px;
    --sidebar-w: 0px;
  }

  .mobile-tabs { display: flex; }

  .sidebar { display: none; }

  .workspace {
    flex-direction: column;
  }

  .pane {
    flex: 0 0 100%;
    max-height: calc(100vh - var(--header-h) - var(--mobile-tabs-h) - var(--status-h));
  }

  .pane.mobile-hidden { display: none; }

  #editor-pane { border-right: none; }

  .toolbar { overflow-x: auto; flex-wrap: nowrap; padding: 6px 8px; }
  .toolbar-sep { flex-shrink: 0; }

  textarea#editor { padding: 20px 16px; font-size: 14px; }
  .preview-area { padding: 20px 16px; }

  .side-panel { width: 100%; }

  .prose h1 { font-size: 1.8rem; }
  .prose h2 { font-size: 1.4rem; }

  .hide-mobile { display: none !important; }

  .header-actions .btn:not(.btn-primary) { display: none; }

  .logo span { font-size: 18px; }
}
