/* ═══════════════════════════════════════════
   MAGISH DOCS v2 — Refined Dark Industrial
   ═══════════════════════════════════════════ */

@import url('https://fonts.googleapis.com/css2?family=JetBrains+Mono:wght@400;500;600&family=Outfit:wght@300;400;500;600;700;800&display=swap');

:root {
  --bg-deep: #060a12;
  --bg-primary: #0b1018;
  --bg-secondary: #10161f;
  --bg-elevated: #151d2a;
  --bg-hover: #1a2435;
  --bg-active: #1f2b40;

  --surface-100: #0d1319;
  --surface-200: #131b26;
  --surface-300: #1a2433;
  --surface-400: #222f42;
  --surface-500: #2c3b52;
  --surface-600: #3a4d68;

  --text-primary: #e4eaf3;
  --text-secondary: #8594ad;
  --text-muted: #556478;
  --text-faint: #3d4e63;
  --text-inverse: #060a12;

  --accent-green: #34d28a;
  --accent-green-dim: #28a36c;
  --accent-green-soft: rgba(52, 210, 138, 0.12);
  --accent-green-glow: rgba(52, 210, 138, 0.2);
  --accent-blue: #4b8ff5;
  --accent-blue-dim: #3570cc;
  --accent-blue-soft: rgba(75, 143, 245, 0.1);
  --accent-blue-glow: rgba(75, 143, 245, 0.15);
  --accent-red: #f55464;
  --accent-red-soft: rgba(245, 84, 100, 0.1);
  --accent-yellow: #e8b930;
  --accent-yellow-soft: rgba(232, 185, 48, 0.1);
  --accent-purple: #a578f0;
  --accent-purple-soft: rgba(165, 120, 240, 0.1);
  --accent-off-white: #cdd6e4;

  --border-subtle: rgba(255, 255, 255, 0.05);
  --border-medium: rgba(255, 255, 255, 0.08);
  --border-strong: rgba(255, 255, 255, 0.12);

  --shadow-sm: 0 1px 3px rgba(0,0,0,0.5);
  --shadow-md: 0 4px 20px rgba(0,0,0,0.6);
  --shadow-lg: 0 12px 40px rgba(0,0,0,0.7);
  --shadow-glow-green: 0 0 24px rgba(52,210,138,0.12);
  --shadow-glow-blue: 0 0 20px rgba(75,143,245,0.08);
  --shadow-inset: inset 0 1px 0 rgba(255,255,255,0.03);

  --radius-xs: 4px;
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;

  --font-display: 'Outfit', -apple-system, sans-serif;
  --font-mono: 'JetBrains Mono', 'Fira Code', monospace;

  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
  --ease-spring: cubic-bezier(0.34, 1.56, 0.64, 1);
  --t-fast: 120ms;
  --t-med: 220ms;
  --t-slow: 400ms;
}

*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }
html, body { height: 100%; overflow: hidden; }

body {
  font-family: var(--font-display);
  background: var(--bg-deep);
  color: var(--text-primary);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

#app { height: 100%; }

.screen { display: none; height: 100%; }
.screen.active { display: flex; }

/* ═══════════════════════════════════════════
   AUTH SCREEN
   ═══════════════════════════════════════════ */
#auth-screen {
  align-items: center;
  justify-content: center;
  background: var(--bg-deep);
  position: relative;
}

.auth-container {
  position: relative;
  z-index: 1;
}

.auth-glow {
  position: fixed;
  inset: 0;
  background:
    radial-gradient(ellipse 60% 50% at 40% 20%, rgba(75,143,245,0.07) 0%, transparent 60%),
    radial-gradient(ellipse 50% 40% at 70% 80%, rgba(52,210,138,0.05) 0%, transparent 50%);
  pointer-events: none;
}

.auth-card {
  text-align: center;
  padding: 3.5rem 3rem;
  background: var(--bg-primary);
  border: 1px solid var(--border-medium);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  animation: authIn 0.7s var(--ease-out);
  position: relative;
  overflow: hidden;
}

.auth-card::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 2px;
  background: linear-gradient(90deg, var(--accent-green), var(--accent-blue), var(--accent-green));
  background-size: 200% 100%;
  animation: shimmer 3s linear infinite;
}

@keyframes shimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

@keyframes authIn {
  from { opacity: 0; transform: translateY(24px) scale(0.96); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

.auth-logo {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  margin-bottom: 2rem;
}

.auth-logo h1 {
  font-size: 2rem;
  font-weight: 800;
  letter-spacing: -0.03em;
  line-height: 1;
}
.auth-logo h1 span { color: var(--accent-green); }
.auth-tagline {
  font-size: 0.82rem;
  color: var(--text-muted);
  font-weight: 300;
  margin-top: 0.25rem;
}

.btn-login {
  display: inline-flex;
  align-items: center;
  gap: 0.7rem;
  padding: 0.8rem 2rem;
  background: var(--bg-elevated);
  color: var(--text-primary);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-md);
  font-family: var(--font-display);
  font-size: 0.95rem;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--t-med) var(--ease-out);
  box-shadow: var(--shadow-sm), var(--shadow-inset);
}
.btn-login:hover {
  background: var(--bg-hover);
  border-color: var(--accent-green-dim);
  box-shadow: var(--shadow-glow-green);
  transform: translateY(-2px);
}

.auth-footer-text {
  margin-top: 1.5rem;
  font-size: 0.72rem;
  color: var(--text-faint);
}

/* ═══════════════════════════════════════════
   SIDEBAR
   ═══════════════════════════════════════════ */
.sidebar {
  width: 280px;
  min-width: 280px;
  background: var(--bg-primary);
  border-right: 1px solid var(--border-subtle);
  display: flex;
  flex-direction: column;
  position: relative;
}

.sidebar-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1rem 0.75rem;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-weight: 700;
  font-size: 0.88rem;
  color: var(--text-primary);
  letter-spacing: -0.01em;
}

.btn-new {
  width: 30px;
  height: 30px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--accent-green);
  color: var(--text-inverse);
  border: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all var(--t-fast) var(--ease-out);
}
.btn-new:hover {
  background: var(--accent-green-dim);
  box-shadow: var(--shadow-glow-green);
  transform: scale(1.08);
}

.sidebar-search {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  margin: 0.4rem 0.75rem;
  padding: 0.45rem 0.7rem;
  background: var(--bg-secondary);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  transition: all var(--t-fast);
}
.sidebar-search:focus-within {
  border-color: var(--accent-blue-dim);
  background: var(--bg-elevated);
}

.sidebar-search input {
  flex: 1;
  background: none;
  border: none;
  outline: none;
  color: var(--text-primary);
  font-family: var(--font-display);
  font-size: 0.8rem;
}
.sidebar-search input::placeholder { color: var(--text-faint); }

.sidebar-filters {
  display: flex;
  gap: 0.25rem;
  padding: 0.4rem 0.75rem;
  flex-wrap: wrap;
}

.filter-chip {
  padding: 0.18rem 0.55rem;
  font-size: 0.65rem;
  font-family: var(--font-display);
  font-weight: 600;
  background: transparent;
  border: 1px solid var(--border-subtle);
  border-radius: 100px;
  color: var(--text-muted);
  cursor: pointer;
  transition: all var(--t-fast);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.filter-chip:hover { color: var(--text-secondary); border-color: var(--border-medium); }
.filter-chip.active {
  background: var(--accent-blue-soft);
  border-color: var(--accent-blue-dim);
  color: var(--accent-blue);
}

.doc-list {
  flex: 1;
  overflow-y: auto;
  padding: 0.35rem 0.5rem;
}
.doc-list::-webkit-scrollbar { width: 3px; }
.doc-list::-webkit-scrollbar-thumb { background: var(--surface-400); border-radius: 3px; }

.doc-item {
  padding: 0.6rem 0.7rem;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all var(--t-fast);
  border-left: 2px solid transparent;
  margin-bottom: 1px;
}
.doc-item:hover { background: var(--bg-hover); }
.doc-item.active {
  background: var(--bg-elevated);
  border-left-color: var(--accent-green);
}
.doc-item-title {
  font-size: 0.82rem;
  font-weight: 500;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.doc-item-meta {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  margin-top: 0.15rem;
  font-size: 0.65rem;
  color: var(--text-faint);
}
.doc-item-cat {
  padding: 0.08rem 0.35rem;
  border-radius: 3px;
  font-size: 0.6rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.doc-item-cat[data-cat="server"] { color: var(--accent-green); background: var(--accent-green-soft); }
.doc-item-cat[data-cat="network"] { color: var(--accent-blue); background: var(--accent-blue-soft); }
.doc-item-cat[data-cat="service"] { color: var(--accent-yellow); background: var(--accent-yellow-soft); }
.doc-item-cat[data-cat="guide"] { color: var(--accent-purple); background: var(--accent-purple-soft); }

.sidebar-user {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.65rem 0.85rem;
  border-top: 1px solid var(--border-subtle);
  background: var(--bg-secondary);
}
.user-profile {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.78rem;
  color: var(--text-secondary);
}
.user-profile img {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  border: 1.5px solid var(--surface-400);
}
.btn-icon-sm {
  background: none;
  border: none;
  color: var(--text-faint);
  cursor: pointer;
  padding: 0.3rem;
  border-radius: var(--radius-xs);
  transition: all var(--t-fast);
}
.btn-icon-sm:hover { color: var(--text-primary); background: var(--bg-hover); }

/* ═══════════════════════════════════════════
   EDITOR AREA
   ═══════════════════════════════════════════ */
.editor-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--bg-deep);
}

.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  gap: 0.8rem;
  animation: fadeIn 0.4s var(--ease-out);
}
.empty-state h2 {
  font-size: 1.15rem;
  font-weight: 500;
  color: var(--text-muted);
}
.empty-state p { font-size: 0.82rem; color: var(--text-faint); }

@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

.editor-view {
  display: flex;
  flex-direction: column;
  height: 100%;
  animation: editorIn 0.25s var(--ease-out);
}
@keyframes editorIn {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

/* Top bar */
.editor-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.5rem 1.5rem;
  background: var(--bg-primary);
  border-bottom: 1px solid var(--border-subtle);
}
.topbar-left, .topbar-right { display: flex; align-items: center; gap: 0.75rem; }

.category-select {
  background: var(--bg-secondary);
  border: 1px solid var(--border-subtle);
  color: var(--text-secondary);
  font-family: var(--font-display);
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 0.25rem 0.5rem;
  border-radius: var(--radius-xs);
  cursor: pointer;
  outline: none;
}
.category-select option { background: var(--bg-elevated); }

.save-indicator {
  display: flex;
  align-items: center;
  gap: 0.3rem;
  font-size: 0.7rem;
  font-weight: 500;
  color: var(--accent-green-dim);
}
.save-dot {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--accent-green);
}
.save-indicator.saving .save-dot {
  background: var(--accent-blue);
  animation: pulse 0.8s infinite;
}
.save-indicator.saving { color: var(--accent-blue-dim); }
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: 0.3; } }

.btn-topbar {
  background: none;
  border: none;
  color: var(--text-faint);
  cursor: pointer;
  padding: 0.35rem;
  border-radius: var(--radius-xs);
  transition: all var(--t-fast);
}
.btn-topbar:hover { color: var(--text-secondary); background: var(--bg-hover); }
.btn-delete:hover { color: var(--accent-red); background: var(--accent-red-soft); }

/* Title */
.doc-title-input {
  font-family: var(--font-display);
  font-size: 1.6rem;
  font-weight: 700;
  letter-spacing: -0.025em;
  background: none;
  border: none;
  outline: none;
  color: var(--text-primary);
  padding: 1.25rem 2rem 0.4rem;
  width: 100%;
}
.doc-title-input::placeholder { color: var(--text-faint); }

/* ═══════════════════════════════════════════
   FORMAT TOOLBAR
   ═══════════════════════════════════════════ */
.format-toolbar {
  display: flex;
  align-items: center;
  gap: 0.15rem;
  padding: 0.4rem 1.75rem;
  border-bottom: 1px solid var(--border-subtle);
  background: var(--bg-primary);
  flex-wrap: wrap;
}

.toolbar-group {
  display: flex;
  gap: 1px;
}

.toolbar-sep {
  width: 1px;
  height: 20px;
  background: var(--border-subtle);
  margin: 0 0.35rem;
}

.tb-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 28px;
  background: none;
  border: 1px solid transparent;
  border-radius: var(--radius-xs);
  color: var(--text-muted);
  cursor: pointer;
  font-family: var(--font-display);
  font-size: 0.7rem;
  font-weight: 700;
  transition: all var(--t-fast);
}
.tb-btn:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
  border-color: var(--border-subtle);
}
.tb-btn.active {
  background: var(--accent-blue-soft);
  color: var(--accent-blue);
  border-color: var(--accent-blue-dim);
}

/* ═══════════════════════════════════════════
   EDITOR CONTENT (contenteditable)
   ═══════════════════════════════════════════ */
.editor-body {
  flex: 1;
  overflow-y: auto;
  background: var(--bg-deep);
}
.editor-body::-webkit-scrollbar { width: 5px; }
.editor-body::-webkit-scrollbar-thumb { background: var(--surface-400); border-radius: 3px; }

.editor-content {
  max-width: 780px;
  margin: 0 auto;
  padding: 1.5rem 2.5rem 6rem;
  min-height: 100%;
  outline: none;
  font-size: 0.92rem;
  line-height: 1.75;
  color: var(--text-secondary);
  caret-color: var(--accent-green);
}

.editor-content:empty::before {
  content: 'Börja skriva...';
  color: var(--text-faint);
  pointer-events: none;
}

/* Rich text styles */
.editor-content h1 {
  font-family: var(--font-display);
  font-size: 1.7rem;
  font-weight: 700;
  color: var(--text-primary);
  margin: 2rem 0 0.75rem;
  letter-spacing: -0.02em;
  padding-bottom: 0.5rem;
  border-bottom: 1px solid var(--border-subtle);
}
.editor-content h2 {
  font-family: var(--font-display);
  font-size: 1.3rem;
  font-weight: 600;
  color: var(--accent-blue);
  margin: 1.75rem 0 0.5rem;
}
.editor-content h3 {
  font-family: var(--font-display);
  font-size: 1.05rem;
  font-weight: 600;
  color: var(--text-primary);
  margin: 1.25rem 0 0.4rem;
}

.editor-content p { margin: 0.4rem 0; }

.editor-content strong { color: var(--text-primary); font-weight: 600; }
.editor-content em { font-style: italic; }
.editor-content u { text-decoration: underline; text-underline-offset: 3px; }
.editor-content s { text-decoration: line-through; color: var(--text-muted); }

.editor-content a {
  color: var(--accent-blue);
  text-decoration: underline;
  text-underline-offset: 2px;
}

.editor-content ul, .editor-content ol {
  padding-left: 1.5rem;
  margin: 0.5rem 0;
}
.editor-content li { margin: 0.25rem 0; }

.editor-content code {
  font-family: var(--font-mono);
  font-size: 0.82rem;
  background: var(--bg-elevated);
  padding: 0.15rem 0.4rem;
  border-radius: 4px;
  color: var(--accent-green);
  border: 1px solid var(--border-subtle);
}

.editor-content pre {
  background: var(--bg-elevated);
  border: 1px solid var(--border-medium);
  border-radius: var(--radius-md);
  padding: 1rem 1.25rem;
  margin: 1rem 0;
  overflow-x: auto;
  position: relative;
}
.editor-content pre::before {
  content: 'CODE';
  position: absolute;
  top: 0.4rem;
  right: 0.6rem;
  font-family: var(--font-mono);
  font-size: 0.55rem;
  font-weight: 600;
  color: var(--text-faint);
  letter-spacing: 0.1em;
}
.editor-content pre code {
  background: none;
  border: none;
  padding: 0;
  color: var(--text-primary);
  font-size: 0.8rem;
  line-height: 1.6;
}

.editor-content blockquote {
  border-left: 3px solid var(--accent-blue-dim);
  padding: 0.5rem 1rem;
  margin: 0.75rem 0;
  background: var(--accent-blue-soft);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  color: var(--text-secondary);
  font-style: italic;
}

.editor-content hr {
  border: none;
  height: 1px;
  background: var(--border-medium);
  margin: 1.5rem 0;
}

.editor-content table {
  width: 100%;
  border-collapse: collapse;
  margin: 1rem 0;
  font-size: 0.85rem;
}
.editor-content th, .editor-content td {
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--border-medium);
  text-align: left;
}
.editor-content th {
  background: var(--bg-elevated);
  font-weight: 600;
  color: var(--text-primary);
}

.editor-content img {
  max-width: 100%;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-subtle);
  margin: 0.75rem 0;
}

.editor-content .file-attachment {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.4rem 0.8rem;
  background: var(--bg-elevated);
  border: 1px solid var(--border-medium);
  border-radius: var(--radius-sm);
  color: var(--accent-blue);
  font-size: 0.8rem;
  font-weight: 500;
  text-decoration: none;
  margin: 0.3rem 0;
}
.editor-content .file-attachment:hover {
  background: var(--bg-hover);
  border-color: var(--accent-blue-dim);
}

/* Checklist */
.editor-content .checklist-item {
  display: flex;
  align-items: flex-start;
  gap: 0.5rem;
  margin: 0.3rem 0;
  list-style: none;
}
.editor-content .checklist-item input[type="checkbox"] {
  margin-top: 0.35rem;
  accent-color: var(--accent-green);
}

/* ═══════════════════════════════════════════
   RESPONSIVE
   ═══════════════════════════════════════════ */
@media (max-width: 768px) {
  #main-screen { flex-direction: column; }
  .sidebar {
    width: 100%;
    min-width: unset;
    max-height: 45vh;
    border-right: none;
    border-bottom: 1px solid var(--border-subtle);
  }
  .doc-title-input { font-size: 1.2rem; padding: 0.75rem 1rem 0.3rem; }
  .editor-content { padding: 1rem 1rem 4rem; }
  .format-toolbar { padding: 0.3rem 0.5rem; overflow-x: auto; flex-wrap: nowrap; }
  .editor-topbar { padding: 0.4rem 0.75rem; }
}
