/**
 * File: public/css/style.css
 * Purpose: Main stylesheet for the Notak3 application.
 *          Defines CSS custom properties (design tokens) for light and dark themes,
 *          base resets, the app-shell layout (sidebar + main content), header,
 *          glass-panel cards, buttons, the dual-pane editor, AI score meter,
 *          copy-gate overlay, auth pages, and the premium footer.
 *          Theme switching is achieved by setting [data-theme="dark"] on <html>.
 *
 * Future Improvements:
 * - Add CSS custom property for accent colour so the user's chosen colour applies globally.
 * - Extract component styles into separate files and bundle with a build step.
 * - Add @layer declarations to improve specificity management.
 * - Add print media query so the /editor page prints cleanly.
 * - Animate sidebar collapse with overflow:hidden + max-width for smoother transition.
 */

:root {
  /* Colors - Light Theme */
  --bg-main: #F8F7F4;
  --bg-surface: #FFFFFF;
  --bg-surface-glass: rgba(255, 255, 255, 0.6);
  --text-main: #1E293B;
  --text-muted: #64748B;
  --border-color: #E2E8F0;
  
  /* Primary Accent - Indigo */
  --accent-light: #EEF2FF;
  --accent-main: #6366F1;
  --accent-hover: #4F46E5;
  
  /* Status Colors */
  --success: #10B981;
  --warning: #F59E0B;
  --danger: #EF4444;
  
  /* Shadows */
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.06);
  --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.08);
  --shadow-lg: 0 12px 40px rgba(0, 0, 0, 0.12);
  --shadow-paper: 0 2px 8px rgba(0,0,0,0.06), 0 0 0 1px rgba(0,0,0,0.04);
  
  /* Typography */
  --font-sans: 'Inter', system-ui, -apple-system, sans-serif;
  
  /* Border Radius */
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-xl: 24px;
  --radius-pill: 9999px;
}

[data-theme="dark"] {
  --bg-main: #0B0F1A;
  --bg-surface: #131928;
  --bg-surface-glass: rgba(19, 25, 40, 0.75);
  --text-main: #F1F5F9;
  --text-muted: #94A3B8;
  --border-color: #1E2D45;
  --shadow-paper: 0 2px 12px rgba(0,0,0,0.3), 0 0 0 1px rgba(255,255,255,0.04);
}

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

body {
  font-family: var(--font-sans);
  background-color: var(--bg-main);
  color: var(--text-main);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  transition: background-color 0.3s, color 0.3s;
}

a {
  color: var(--accent-main);
  text-decoration: none;
  transition: color 0.2s;
}

a:hover {
  color: var(--accent-hover);
}

/* One-time Splash Screen */
.notak3-splash {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: var(--bg-main);
  z-index: 100000;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  transition: opacity 0.6s cubic-bezier(0.65, 0, 0.35, 1);
}

html.splash-done .notak3-splash {
  display: none !important;
}

.notak3-splash.fade-out {
  opacity: 0;
  pointer-events: none;
}

.splash-svg {
  width: 80px;
  height: 80px;
  margin-bottom: 24px;
}

.splash-svg path {
  stroke-dasharray: 250;
  stroke-dashoffset: 250;
  animation: drawPath 1.2s cubic-bezier(0.65, 0, 0.35, 1) forwards;
}

@keyframes drawPath {
  to { stroke-dashoffset: 0; }
}

.splash-text {
  font-family: var(--font-sans);
  font-size: 1.8rem;
  font-weight: 700;
  letter-spacing: 0.25em;
  color: var(--text-main);
  opacity: 0;
  transform: translateY(10px);
  animation: splashFadeInUp 0.8s ease 0.6s forwards;
  margin-left: 0.25em; /* offset for letter-spacing */
}

@keyframes splashFadeInUp {
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* App Shell (Sidebar + Main) */
.app-shell {
  display: flex;
  min-height: 100vh;
  position: relative;
}

/* Background depth orbs — dark mode only */
[data-theme="dark"] .app-shell::before,
[data-theme="dark"] .app-shell::after {
  content: '';
  position: fixed;
  border-radius: 50%;
  pointer-events: none;
  z-index: 0;
  filter: blur(120px);
}
[data-theme="dark"] .app-shell::before {
  width: 600px;
  height: 600px;
  background: rgba(99, 102, 241, 0.07);
  top: -200px;
  right: 10%;
}
[data-theme="dark"] .app-shell::after {
  width: 400px;
  height: 400px;
  background: rgba(16, 185, 129, 0.04);
  bottom: 0;
  left: 15%;
}

/* Sidebar — icon-only rail, always compact */
.sidebar {
  width: 72px;
  background-color: var(--bg-surface);
  border-right: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  z-index: 100;
  flex-shrink: 0;
  position: relative;
}

.sidebar-header {
  padding: 22px 0;
  display: flex;
  align-items: center;
  justify-content: center;
  border-bottom: 1px solid var(--border-color);
}

.sidebar-brand {
  color: var(--accent-main);
  display: flex;
  align-items: center;
  justify-content: center;
}

.brand-icon {
  width: 24px;
  height: 24px;
  stroke-width: 2;
}

.sidebar-nav {
  padding: 16px 10px;
  flex-grow: 1;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.nav-item {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 11px;
  border-radius: 12px;
  color: var(--text-muted);
  transition: all 0.18s ease;
  position: relative;
}

/* Thin Lucide SVGs — Apple SF style */
.nav-item svg {
  width: 21px;
  height: 21px;
  stroke-width: 1.75;
  flex-shrink: 0;
}

.nav-item:hover {
  background-color: var(--accent-light);
  color: var(--accent-main);
  transform: scale(1.05);
}

.nav-item.active {
  background-color: var(--accent-light);
  color: var(--accent-main);
}

.nav-logout:hover {
  background-color: rgba(239, 68, 68, 0.08);
  color: var(--danger);
}

.nav-new-btn {
  background-color: var(--accent-main);
  color: white;
  margin: 4px 0 8px 0;
  box-shadow: 0 4px 12px rgba(99, 102, 241, 0.25);
}

.nav-new-btn:hover {
  background-color: var(--accent-hover);
  color: white;
  transform: scale(1.08) translateY(-1px);
  box-shadow: 0 6px 16px rgba(99, 102, 241, 0.4);
}

.nav-new-btn svg {
  stroke-width: 2.5;
}

/* Tooltip that appears to the right of each icon */
.nav-item[data-label]::after {
  content: attr(data-label);
  position: absolute;
  left: calc(100% + 14px);
  top: 50%;
  transform: translateY(-50%);
  background: var(--bg-surface);
  color: var(--text-main);
  padding: 6px 12px;
  border-radius: 8px;
  font-size: 0.78rem;
  font-weight: 500;
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.15s;
  box-shadow: var(--shadow-lg);
  border: 1px solid var(--border-color);
  z-index: 300;
  letter-spacing: 0.01em;
}

.nav-item[data-label]:hover::after {
  opacity: 1;
}

/* Main Content Area */
.main-content {
  flex-grow: 1;
  display: flex;
  flex-direction: column;
  width: calc(100% - 72px);
  min-width: 0;
}

/* Header — floating, borderless, glass */
.app-header {
  background: var(--bg-surface-glass);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-bottom: 1px solid rgba(255,255,255,0.06);
  padding: 12px 28px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  position: sticky;
  top: 0;
  z-index: 50;
  transition: box-shadow 0.3s ease;
}

/* Session title — looks like a heading, not a form input */
#session-title {
  letter-spacing: -0.02em;
}
#session-title:focus, #session-subject:focus {
  outline: none;
  opacity: 1;
}
#session-title::placeholder, #session-subject::placeholder {
  color: var(--border-color);
}

/* AI Score badge — glassmorphic pill */
.ai-score-badge {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--bg-surface-glass);
  backdrop-filter: blur(8px);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-pill);
  padding: 5px 14px;
  font-size: 0.82rem;
  color: var(--text-muted);
}

/* Glass Panel */
.glass-panel {
  background: var(--bg-surface-glass);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
  padding: 24px;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 9px 20px;
  border-radius: var(--radius-pill);
  font-weight: 600;
  font-size: 0.9rem;
  border: none;
  cursor: pointer;
  transition: all 0.18s ease;
}

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

.btn-primary {
  background-color: var(--accent-main);
  color: white;
  box-shadow: 0 2px 8px rgba(99,102,241,0.25);
}

.btn-primary:hover {
  background-color: var(--accent-hover);
  transform: translateY(-1px);
  box-shadow: 0 4px 16px rgba(99,102,241,0.35);
}

.btn-outline {
  background-color: transparent;
  border: 1px solid var(--border-color);
  color: var(--text-muted);
}

.btn-outline:hover {
  background-color: var(--bg-surface);
  border-color: var(--accent-main);
  color: var(--accent-main);
}

/* Dual Pane Editor */
.editor-container {
  display: flex;
  height: calc(100vh - 61px);
  overflow: hidden;
  position: relative;
}

.pane {
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  position: relative;
}

.pane-left {
  flex: 0 0 42%;
  padding: 28px 28px;
  background-color: var(--bg-main);
  min-width: 280px;
}

/* Resizable Gutter Divider */
.pane-divider {
  width: 5px;
  background: transparent;
  cursor: col-resize;
  flex-shrink: 0;
  position: relative;
  transition: background 0.15s;
  z-index: 10;
}
.pane-divider:hover, .pane-divider.dragging {
  background: var(--accent-main);
  opacity: 0.5;
}
.pane-divider::after {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 2px;
  height: 32px;
  border-radius: 2px;
  background: var(--border-color);
}

.pane-right {
  flex: 1;
  padding: 28px 0;
  background-color: var(--bg-main);
  display: flex;
  flex-direction: column;
  align-items: center;
  min-width: 0;
}

/* Chat Messages — editorial style, not chat bubbles */
.chat-message {
  margin-bottom: 24px;
  display: flex;
  flex-direction: column;
}

.message-user {
  align-items: flex-end;
}

.message-ai {
  align-items: flex-start;
  width: 100%;
}

.message-bubble {
  max-width: 85%;
  line-height: 1.7;
}

/* User message — pill/bubble */
.message-user .message-bubble {
  background-color: var(--accent-main);
  color: white;
  padding: 10px 16px;
  border-radius: var(--radius-pill);
  border-bottom-right-radius: 6px;
  font-size: 0.95rem;
}

/* AI message — clean document block */
.message-ai .message-bubble {
  width: 100%;
  max-width: 100%;
  background: transparent;
  border: none;
  padding: 0;
  color: var(--text-main);
}

/* AI paragraph blocks — editorial card style */
.ai-paragraph {
  margin-bottom: 16px;
  padding: 14px 16px;
  border-radius: var(--radius-md);
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-left: 3px solid var(--accent-main);
  box-shadow: var(--shadow-sm);
  transition: box-shadow 0.15s;
}

.ai-paragraph:hover {
  box-shadow: var(--shadow-md);
}

.ai-paragraph:last-child {
  margin-bottom: 0;
}

/* Floating Selection Bubble Toolbar */
.selection-bubble {
  position: fixed;
  z-index: 9999;
  background: #1E293B;
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: var(--radius-pill);
  padding: 5px 8px;
  display: flex;
  align-items: center;
  gap: 2px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.25), 0 2px 8px rgba(0,0,0,0.15);
  transform: translateY(-4px);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.15s ease, transform 0.15s ease;
}

.selection-bubble.visible {
  opacity: 1;
  transform: translateY(0);
  pointer-events: all;
}

/* Downward arrow caret */
.selection-bubble::after {
  content: '';
  position: absolute;
  bottom: -5px;
  left: 50%;
  transform: translateX(-50%);
  width: 10px;
  height: 5px;
  background: #1E293B;
  clip-path: polygon(0 0, 100% 0, 50% 100%);
}

.bubble-btn {
  background: transparent;
  border: none;
  color: #94A3B8;
  padding: 5px 8px;
  border-radius: 20px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s, color 0.15s;
}

.bubble-btn:hover {
  background: rgba(255,255,255,0.1);
  color: #FFFFFF;
}

.bubble-btn svg {
  width: 15px;
  height: 15px;
  stroke-width: 2;
}

/* Spinning state for bubble buttons */
.bubble-btn.loading svg {
  animation: lucideSpin 0.8s linear infinite;
}

.bubble-divider {
  width: 1px;
  height: 16px;
  background: rgba(255,255,255,0.12);
  margin: 0 2px;
}

/* Chat Input */
.chat-input-container {
  margin-top: auto;
  position: relative;
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 8px;
  display: flex;
  align-items: flex-end;
  box-shadow: var(--shadow-sm);
}

.chat-input {
  flex-grow: 1;
  border: none;
  background: transparent;
  padding: 12px;
  resize: none;
  max-height: 150px;
  font-family: inherit;
  font-size: 1rem;
  color: var(--text-main);
}

.chat-input:focus {
  outline: none;
}

.chat-submit {
  background: var(--accent-main);
  color: white;
  border: none;
  width: 40px;
  height: 40px;
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  margin-left: 8px;
  transition: background-color 0.2s;
}

.chat-submit:hover {
  background: var(--accent-hover);
}

/* Document Editor — paper floating on desk */
.doc-editor-wrapper {
  width: 100%;
  max-width: 720px;
  flex: 1;
  display: flex;
  flex-direction: column;
  padding: 0 32px;
  position: relative;
}

.doc-editor {
  width: 100%;
  flex: 1;
  border: none;
  resize: none;
  font-family: inherit;
  font-size: 1.05rem;
  line-height: 1.85;
  color: var(--text-main);
  background: transparent;
  caret-color: var(--accent-main);
}

.doc-editor:empty::before {
  content: attr(data-placeholder);
  color: var(--border-color);
  font-size: 1.1rem;
  position: absolute;
  top: 0;
  left: 32px;
  pointer-events: none;
  user-select: none;
}

.doc-editor:focus {
  outline: none;
}

/* Floating word count */
.doc-wordcount {
  position: sticky;
  bottom: 0;
  padding: 10px 0 6px;
  font-size: 0.78rem;
  color: var(--text-muted);
  text-align: right;
  user-select: none;
  background: transparent;
  letter-spacing: 0.01em;
}

/* Pane right header toolbar */
.pane-right-header {
  width: 100%;
  max-width: 720px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0 32px 16px;
  border-bottom: 1px solid var(--border-color);
  margin-bottom: 24px;
}

/* AI Score Meter */
.score-meter {
  width: 150px;
  height: 8px;
  background: var(--border-color);
  border-radius: 4px;
  overflow: hidden;
  margin-left: 16px;
}

.score-fill {
  height: 100%;
  width: 0%;
  transition: width 0.3s ease, background-color 0.3s ease;
}

.score-safe { background-color: var(--success); }
.score-warn { background-color: var(--warning); }
.score-danger { background-color: var(--danger); }

/* Copy Gate Cooldown Overlay */
.copy-overlay {
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(255,255,255,0.8);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10;
  border-radius: var(--radius-lg);
  font-weight: bold;
  color: var(--accent-main);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s;
}

.copy-overlay.active {
  opacity: 1;
  pointer-events: all;
}

/* Auth Pages */
.auth-container {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, var(--bg-main) 0%, var(--accent-light) 100%);
  padding: 24px;
}

.auth-card {
  width: 100%;
  max-width: 400px;
}

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

.form-label {
  display: block;
  margin-bottom: 8px;
  font-weight: 500;
  color: var(--text-main);
}

.form-control {
  width: 100%;
  padding: 12px 16px;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  background-color: var(--bg-surface);
  color: var(--text-main);
  font-family: inherit;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.form-control:focus {
  outline: none;
  border-color: var(--accent-main);
  box-shadow: 0 0 0 3px var(--accent-light);
}

/* Mobile Adjustments */
@media (max-width: 768px) {
  .app-shell {
    flex-direction: column;
  }
  
  .sidebar {
    width: 100%;
    height: auto;
    flex-direction: row;
    overflow-x: auto;
    border-right: none;
    border-bottom: 1px solid var(--border-color);
    position: fixed;
    bottom: 0;
    z-index: 100;
    padding: 8px;
  }
  
  .sidebar-header, .sidebar-brand {
    display: none;
  }

  /* Disable tooltips on mobile */
  .nav-item[data-label]::after { display: none; }

  .sidebar-nav {
    flex-direction: row;
    padding: 0;
    justify-content: space-around;
    width: 100%;
    gap: 0;
  }
  
  .nav-item {
    flex-direction: column;
    padding: 10px 8px;
    border-radius: 10px;
    transform: none !important;
  }

  .nav-item svg {
    width: 22px;
    height: 22px;
  }
  
  .main-content {
    width: 100%;
    padding-bottom: 70px; /* Space for bottom nav */
  }
  
  .editor-container {
    flex-direction: column;
    /* Use WhatsApp style tabs for mobile */
  }
  
  .pane {
    display: none; /* Hide panes by default, manage via JS */
    padding: 20px;
  }
  
  .pane.active {
    display: flex;
  }

  .mobile-tabs {
    display: flex;
    background: var(--bg-surface);
    border-bottom: 1px solid var(--border-color);
  }

  .mobile-tab {
    flex: 1;
    text-align: center;
    padding: 12px;
    font-weight: 600;
    color: var(--text-muted);
    border-bottom: 2px solid transparent;
  }

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

/* Premium Footer */
.premium-footer {
  background-color: #0B0F19; /* Very dark rich blue */
  color: #8B949E;
  margin-top: auto;
  border-top: 1px solid rgba(255, 255, 255, 0.05);
  padding: 48px 48px 24px 48px;
  font-family: var(--font-sans);
}

.footer-content {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 64px;
  flex-wrap: wrap;
  gap: 32px;
}

.footer-left {
  max-width: 400px;
}

.footer-brand {
  color: #4F46E5; /* Deep Indigo */
  font-size: 1.25rem;
  font-weight: 700;
  margin-bottom: 16px;
  letter-spacing: -0.02em;
}

.footer-desc {
  font-size: 0.95rem;
  line-height: 1.6;
  margin-bottom: 24px;
  color: #64748B;
}

.footer-launch a {
  color: #3B82F6;
  font-size: 0.95rem;
  font-weight: 600;
  letter-spacing: 0.02em;
}

.footer-launch a:hover {
  text-decoration: underline;
}

.footer-right {
  display: flex;
  flex-direction: column;
}

.footer-links {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.footer-links li {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 0.9rem;
  color: #64748B;
  transition: color 0.2s;
}

.footer-links li:hover {
  color: #94A3B8;
}

.footer-links i {
  color: #475569;
  width: 16px;
  text-align: center;
}

.footer-bottom {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding-top: 24px;
  border-top: 1px solid rgba(255, 255, 255, 0.05);
  font-size: 0.8rem;
  color: #475569;
}

.system-status {
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-weight: 600;
}

/* Animations */
@keyframes lucideSpin {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}

.lucide-spin {
  animation: lucideSpin 1s linear infinite;
}

@keyframes bounceUp {
  0%, 100% { transform: translateY(0); opacity: 0.5; }
  50% { transform: translateY(-4px); opacity: 1; }
}

.bouncing-dots span {
  display: inline-block;
  animation: bounceUp 0.8s infinite ease-in-out;
}
.bouncing-dots span:nth-child(2) { animation-delay: 0.15s; }
.bouncing-dots span:nth-child(3) { animation-delay: 0.3s; }

@keyframes shimmerEffect {
  0% { background-position: -400px 0; }
  100% { background-position: 400px 0; }
}

.skeleton-shimmer {
  background: var(--bg-surface);
  background-image: linear-gradient(90deg, rgba(255,255,255,0) 0, rgba(255,255,255,0.06) 20%, rgba(255,255,255,0) 40%, rgba(255,255,255,0));
  background-size: 800px 100%;
  background-repeat: no-repeat;
  animation: shimmerEffect 1.5s linear infinite forwards;
  opacity: 0.7;
}

[data-theme="light"] .skeleton-shimmer {
  background-image: linear-gradient(90deg, rgba(0,0,0,0) 0, rgba(0,0,0,0.04) 20%, rgba(0,0,0,0) 40%, rgba(0,0,0,0));
}

@media (max-width: 768px) {
  .footer-content {
    flex-direction: column;
    margin-bottom: 40px;
  }
  .premium-footer {
    padding: 32px 24px 24px 24px;
  }
  .footer-bottom {
    flex-direction: column;
    gap: 12px;
    align-items: flex-start;
  }
}
