/* Premium Design System & CSS Container Queries for Unified Writer & Audit Suite */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&family=Outfit:wght@400;500;600;700&family=Source+Serif+4:ital,opsz,wght@0,8..60,300;0,8..60,400;0,8..60,600;1,8..60,400&display=swap');

:root {
  --bg-primary: #0b0f17;
  --bg-surface: #141b27;
  --bg-surface-hover: #1c2638;
  --bg-card: rgba(20, 27, 39, 0.85);
  
  --border-color: rgba(255, 255, 255, 0.08);
  --border-focus: #10b981;
  
  --text-primary: #f1f5f9;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;
  
  --accent-emerald: #10b981;
  --accent-emerald-dark: #059669;
  --accent-amber: #f59e0b;
  --accent-rose: #f43f5e;
  --accent-indigo: #6366f1;
  
  --font-ui: 'Inter', system-ui, -apple-system, sans-serif;
  --font-display: 'Outfit', sans-serif;
  --font-editor: 'Source Serif 4', Georgia, serif;
  
  --header-height: 56px;
  --bottom-nav-height: 56px;
  --sidebar-width: 280px;
  --panel-width: 360px;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: var(--font-ui);
  background-color: var(--bg-primary);
  color: var(--text-primary);
  height: 100vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

/* Header & Top Bar */
.app-header {
  height: var(--header-height);
  background-color: var(--bg-surface);
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  z-index: 50;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 1.1rem;
  color: var(--text-primary);
}

.brand-icon {
  background: linear-gradient(135deg, var(--accent-emerald), var(--accent-indigo));
  width: 32px;
  height: 32px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1rem;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}

.badge {
  background: rgba(16, 185, 129, 0.15);
  color: var(--accent-emerald);
  border: 1px solid rgba(16, 185, 129, 0.3);
  padding: 4px 10px;
  border-radius: 12px;
  font-size: 0.8rem;
  font-weight: 600;
}

.btn {
  background-color: var(--bg-surface-hover);
  color: var(--text-primary);
  border: 1px solid var(--border-color);
  padding: 8px 14px;
  border-radius: 8px;
  font-family: var(--font-ui);
  font-size: 0.85rem;
  font-weight: 500;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: all 0.2s ease;
}

.btn:hover {
  background-color: var(--border-color);
  border-color: rgba(255, 255, 255, 0.2);
}

.btn-primary {
  background: linear-gradient(135deg, var(--accent-emerald), var(--accent-emerald-dark));
  color: #fff;
  border: none;
}

.btn-primary:hover {
  opacity: 0.9;
}

.btn-loading {
  opacity: 0.65;
  cursor: wait !important;
  pointer-events: none;
}

/* App Main Layout Container */
.app-container {
  flex: 1;
  display: flex;
  height: calc(100vh - var(--header-height));
  position: relative;
  overflow: hidden;
}

/* Sidebar (Left Panel: Chapter Tree) */
.sidebar {
  width: var(--sidebar-width);
  background-color: var(--bg-surface);
  border-right: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  transition: transform 0.3s ease;
  z-index: 40;
}

.sidebar-header {
  padding: 14px 16px;
  border-bottom: 1px solid var(--border-color);
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 0.9rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.chapter-list {
  flex: 1;
  overflow-y: auto;
  padding: 8px;
  list-style: none;
}

.chapter-item {
  padding: 10px 12px;
  border-radius: 8px;
  cursor: pointer;
  margin-bottom: 4px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  transition: background 0.15s ease;
}

.chapter-item:hover {
  background-color: var(--bg-surface-hover);
}

.chapter-item.active {
  background-color: rgba(16, 185, 129, 0.15);
  border-left: 3px solid var(--accent-emerald);
  color: var(--accent-emerald);
}

.chapter-title {
  font-size: 0.9rem;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chapter-meta {
  font-size: 0.75rem;
  color: var(--text-muted);
}

/* Main Editor Area */
.editor-container {
  flex: 1;
  display: flex;
  flex-direction: column;
  background-color: var(--bg-primary);
  overflow: hidden;
  position: relative;
}

.editor-toolbar {
  height: 48px;
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  background-color: rgba(20, 27, 39, 0.5);
}

.ai-loading-banner {
  background: linear-gradient(135deg, rgba(16, 185, 129, 0.2), rgba(99, 102, 241, 0.2));
  border-bottom: 1px solid var(--accent-emerald);
  color: var(--accent-emerald);
  padding: 10px 20px;
  font-size: 0.9rem;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 12px;
  animation: pulseBanner 1.8s infinite ease-in-out;
  z-index: 10;
}

@keyframes pulseBanner {
  0% { background: linear-gradient(135deg, rgba(16, 185, 129, 0.2), rgba(99, 102, 241, 0.2)); }
  50% { background: linear-gradient(135deg, rgba(16, 185, 129, 0.4), rgba(99, 102, 241, 0.4)); }
  100% { background: linear-gradient(135deg, rgba(16, 185, 129, 0.2), rgba(99, 102, 241, 0.2)); }
}

.spinner {
  display: inline-block;
  animation: spin 2s linear infinite;
}

@keyframes spin {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}

.beat-controls {
  display: flex;
  align-items: center;
  gap: 8px;
}

.editor-textarea {
  flex: 1;
  width: 100%;
  padding: 24px 32px;
  background: transparent;
  border: none;
  color: var(--text-primary);
  font-family: var(--font-editor);
  font-size: 1.15rem;
  line-height: 1.7;
  resize: none;
  outline: none;
}

.editor-footer {
  height: 36px;
  border-top: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  font-size: 0.8rem;
  color: var(--text-muted);
  background-color: var(--bg-surface);
}

/* Inspector / Right Panel (Audit & State) */
.inspector-panel {
  width: var(--panel-width);
  background-color: var(--bg-surface);
  border-left: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.inspector-tabs {
  display: flex;
  border-bottom: 1px solid var(--border-color);
}

.tab-btn {
  flex: 1;
  padding: 12px;
  background: none;
  border: none;
  color: var(--text-muted);
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 0.85rem;
  cursor: pointer;
  border-bottom: 2px solid transparent;
}

.tab-btn.active {
  color: var(--accent-emerald);
  border-bottom-color: var(--accent-emerald);
  background-color: rgba(16, 185, 129, 0.05);
}

.tab-content {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
}

.audit-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: 10px;
  padding: 14px;
  margin-bottom: 12px;
}

.audit-score {
  font-size: 1.8rem;
  font-weight: 700;
  color: var(--accent-emerald);
  font-family: var(--font-display);
}

.issue-item {
  background: rgba(244, 63, 94, 0.1);
  border: 1px solid rgba(244, 63, 94, 0.2);
  border-radius: 6px;
  padding: 8px 10px;
  font-size: 0.82rem;
  margin-top: 6px;
}

/* Bottom Nav Bar (Mobile / iPhone) */
.bottom-nav {
  display: none;
  height: var(--bottom-nav-height);
  background-color: var(--bg-surface);
  border-top: 1px solid var(--border-color);
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 100;
}

.nav-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  font-size: 0.75rem;
  text-decoration: none;
  background: none;
  border: none;
  cursor: pointer;
}

.nav-item.active {
  color: var(--accent-emerald);
}

/* Login Modal Overlay */
.auth-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: rgba(11, 15, 23, 0.92);
  backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}

.auth-card {
  background-color: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: 16px;
  padding: 32px;
  width: 100%;
  max-width: 380px;
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.5);
}

.auth-title {
  font-family: var(--font-display);
  font-size: 1.4rem;
  font-weight: 700;
  margin-bottom: 8px;
  text-align: center;
}

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

.form-label {
  display: block;
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-bottom: 6px;
}

.form-input {
  width: 100%;
  padding: 10px 14px;
  background-color: var(--bg-primary);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  color: var(--text-primary);
  font-family: var(--font-ui);
  font-size: 0.95rem;
  outline: none;
}

.form-input:focus {
  border-color: var(--border-focus);
}

/* RESPONSIVE LAYOUT QUERIES */

/* Tablet / iPad (641px - 1023px) */
@media (max-width: 1023px) {
  .inspector-panel {
    position: absolute;
    right: 0;
    top: 0;
    bottom: 0;
    transform: translateX(100%);
    transition: transform 0.3s ease;
    z-index: 60;
    box-shadow: -10px 0 30px rgba(0, 0, 0, 0.5);
  }
  .inspector-panel.open {
    transform: translateX(0);
  }
}

/* Smartphone / iPhone (max-width: 640px) */
@media (max-width: 640px) {
  .app-container {
    height: calc(100vh - var(--header-height) - var(--bottom-nav-height));
  }
  .sidebar {
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    transform: translateX(-100%);
    width: 80%;
  }
  .sidebar.open {
    transform: translateX(0);
  }
  .inspector-panel {
    width: 100%;
  }
  .bottom-nav {
    display: flex;
  }
  .editor-textarea {
    padding: 16px;
    font-size: 1rem;
  }
}
