/* Reset and base */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --font-family: 'EB Garamond', serif;
  --font-size: 20px;
  --line-height: 1.7;
  --paragraph-spacing: 1.5em;
  --column-width: 70%;
  --transition: 0.3s ease;
}

/* Light theme (default) */
.light-theme {
  --bg-color: #f8f6f1;
  --text-color: #2c2c2c;
  --header-bg: #f0ede6;
  --panel-bg: #ffffff;
  --border-color: #e0ddd6;
  --accent-color: #6b5b4f;
  --accent-hover: #4a3f36;
  --placeholder-color: #999;
  --save-status-color: #888;
  --menu-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
  --grammar-bg: #fff3cd;
  --spelling-bg: #f8d7da;
}

/* Dark theme */
.dark-theme {
  --bg-color: #1a1a1a;
  --text-color: #e8e4df;
  --header-bg: #242424;
  --panel-bg: #2a2a2a;
  --border-color: #3a3a3a;
  --accent-color: #c4a77d;
  --accent-hover: #d4bc9a;
  --placeholder-color: #666;
  --save-status-color: #777;
  --menu-shadow: 0 4px 20px rgba(0, 0, 0, 0.4);
  --grammar-bg: #5c4b1f;
  --spelling-bg: #5c2936;
}

html, body {
  height: 100%;
}

body {
  font-family: var(--font-family);
  font-size: var(--font-size);
  line-height: var(--line-height);
  background-color: var(--bg-color);
  color: var(--text-color);
  transition: background-color var(--transition), color var(--transition);
}

/* ==================== */
/* LOGIN SCREEN */
/* ==================== */
.login-screen {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: var(--bg-color);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 2000;
}

.login-box {
  text-align: center;
  padding: 40px;
}

.login-box h1 {
  font-size: 2.5em;
  font-weight: 500;
  margin-bottom: 10px;
  color: var(--text-color);
}

.login-box > p {
  font-size: 1.1em;
  color: var(--save-status-color);
  margin-bottom: 30px;
}

.pin-input-container {
  margin-bottom: 20px;
}

#pinInput {
  width: 160px;
  padding: 16px;
  font-family: var(--font-family);
  font-size: 28px;
  text-align: center;
  letter-spacing: 12px;
  border: 2px solid var(--border-color);
  border-radius: 8px;
  background: var(--panel-bg);
  color: var(--text-color);
  outline: none;
  transition: border-color var(--transition);
}

#pinInput:focus {
  border-color: var(--accent-color);
}

#pinInput::placeholder {
  letter-spacing: 8px;
  color: var(--placeholder-color);
}

.login-btn {
  padding: 14px 40px;
  font-family: var(--font-family);
  font-size: 18px;
  background: var(--accent-color);
  color: white;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  transition: background var(--transition);
}

.login-btn:hover {
  background: var(--accent-hover);
}

.login-error {
  margin-top: 16px;
  color: #c44;
  font-size: 15px;
  min-height: 20px;
}

.login-screen.hidden {
  display: none;
}

/* ==================== */
/* HEADER */
/* ==================== */
.header {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: 50px;
  background-color: var(--header-bg);
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  z-index: 100;
  transition: background-color var(--transition), border-color var(--transition);
}

.header-title {
  font-size: 16px;
  font-weight: 500;
  color: var(--text-color);
}

/* Hamburger button */
.hamburger {
  background: none;
  border: none;
  cursor: pointer;
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.hamburger span {
  display: block;
  width: 24px;
  height: 2px;
  background-color: var(--text-color);
  transition: background-color var(--transition), transform var(--transition);
}

.hamburger.active span:nth-child(1) {
  transform: rotate(45deg) translate(5px, 5px);
}

.hamburger.active span:nth-child(2) {
  opacity: 0;
}

.hamburger.active span:nth-child(3) {
  transform: rotate(-45deg) translate(5px, -5px);
}

/* Save status */
.save-status {
  font-size: 14px;
  color: var(--save-status-color);
  font-style: italic;
}

.save-status.saving {
  color: var(--accent-color);
}

/* ==================== */
/* SIDE PANEL */
/* ==================== */
.side-panel {
  position: fixed;
  top: 50px;
  left: 0;
  bottom: 0;
  width: 300px;
  background-color: var(--panel-bg);
  border-right: 1px solid var(--border-color);
  transform: translateX(-100%);
  transition: transform var(--transition), background-color var(--transition);
  z-index: 90;
  overflow-y: auto;
}

.side-panel.open {
  transform: translateX(0);
}

.panel-content {
  padding: 30px 25px;
}

.panel-content h2 {
  font-size: 22px;
  font-weight: 500;
  margin-bottom: 30px;
  color: var(--text-color);
}

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

.setting-group label {
  display: block;
  font-size: 15px;
  margin-bottom: 12px;
  color: var(--text-color);
}

/* Range slider */
input[type="range"] {
  width: 100%;
  height: 6px;
  border-radius: 3px;
  background: var(--border-color);
  outline: none;
  -webkit-appearance: none;
}

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--accent-color);
  cursor: pointer;
  transition: background var(--transition);
}

input[type="range"]::-webkit-slider-thumb:hover {
  background: var(--accent-hover);
}

/* Theme buttons */
.theme-buttons {
  display: flex;
  gap: 10px;
}

.theme-btn {
  flex: 1;
  padding: 12px;
  border: 1px solid var(--border-color);
  background: transparent;
  color: var(--text-color);
  font-family: var(--font-family);
  font-size: 15px;
  cursor: pointer;
  border-radius: 6px;
  transition: all var(--transition);
}

.theme-btn:hover {
  border-color: var(--accent-color);
}

.theme-btn.active {
  background: var(--accent-color);
  border-color: var(--accent-color);
  color: white;
}

/* Submit button */
.submit-btn {
  width: 100%;
  padding: 14px;
  background: var(--accent-color);
  border: none;
  color: white;
  font-family: var(--font-family);
  font-size: 16px;
  cursor: pointer;
  border-radius: 6px;
  transition: background var(--transition);
}

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

.submit-btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.submit-info {
  font-size: 13px;
  color: var(--save-status-color);
  margin-top: 10px;
  font-style: italic;
}

/* Status badge */
.status-badge {
  display: inline-block;
  padding: 6px 14px;
  border-radius: 20px;
  font-size: 13px;
}

.status-badge.status-draft,
.status-badge.not-ready {
  background: #f0e6d3;
  color: #8b7355;
}

.dark-theme .status-badge.status-draft,
.dark-theme .status-badge.not-ready {
  background: #3d3529;
  color: #c4a77d;
}

.status-badge.status-submitted {
  background: #cce5ff;
  color: #004085;
}

.dark-theme .status-badge.status-submitted {
  background: #1a3a5c;
  color: #87ceeb;
}

.status-badge.status-reviewed,
.status-badge.ready {
  background: #d4edda;
  color: #2d6a3d;
}

.dark-theme .status-badge.status-reviewed,
.dark-theme .status-badge.ready {
  background: #1e3d24;
  color: #7bc47f;
}

/* Archive list */
.archive-list {
  max-height: 200px;
  overflow-y: auto;
  border: 1px solid var(--border-color);
  border-radius: 6px;
  padding: 10px;
}

.archive-empty,
.doc-empty {
  color: var(--placeholder-color);
  font-size: 14px;
  font-style: italic;
  text-align: center;
  padding: 10px;
}

.archive-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 0;
  border-bottom: 1px solid var(--border-color);
}

.archive-item:last-child {
  border-bottom: none;
}

.archive-title {
  font-size: 14px;
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  margin-right: 10px;
}

.archive-status {
  font-size: 11px;
  padding: 3px 8px;
  border-radius: 10px;
}

/* Overlay */
.overlay {
  position: fixed;
  top: 50px;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.3);
  opacity: 0;
  visibility: hidden;
  transition: opacity var(--transition), visibility var(--transition);
  z-index: 80;
}

.overlay.visible {
  opacity: 1;
  visibility: visible;
}

/* ==================== */
/* EDITOR */
/* ==================== */
.editor-container {
  min-height: 100vh;
  padding: 80px 30px 60px;
  display: flex;
  justify-content: center;
}

.editor {
  width: var(--column-width);
  max-width: 1200px;
  font-family: var(--font-family);
  font-size: var(--font-size);
  line-height: var(--line-height);
  color: var(--text-color);
  outline: none;
  min-height: calc(100vh - 140px);
}

.editor:empty::before {
  content: attr(data-placeholder);
  color: var(--placeholder-color);
  pointer-events: none;
}

/* Editor typography - only allow basic formatting */
.editor p,
.editor div {
  margin-bottom: var(--paragraph-spacing);
}

.editor h1,
.editor h2,
.editor h3 {
  font-size: 1.5em;
  font-weight: 600;
  margin-bottom: 0.7em;
  margin-top: 1em;
}

.editor b, .editor strong {
  font-weight: 600;
}

.editor i, .editor em {
  font-style: italic;
}

/* Prevent unwanted formatting - force font family and color */
.editor * {
  font-family: var(--font-family) !important;
  color: var(--text-color) !important;
}

/* ==================== */
/* CONTEXT MENU */
/* ==================== */
.context-menu {
  position: fixed;
  background: var(--panel-bg);
  border: 1px solid var(--border-color);
  border-radius: 6px;
  box-shadow: var(--menu-shadow);
  padding: 4px;
  display: flex;
  gap: 2px;
  opacity: 0;
  visibility: hidden;
  transform: scale(0.95);
  transition: opacity 0.15s, visibility 0.15s, transform 0.15s;
  z-index: 1000;
}

.context-menu.visible {
  opacity: 1;
  visibility: visible;
  transform: scale(1);
}

.context-menu button {
  padding: 8px 14px;
  background: none;
  border: none;
  font-family: var(--font-family);
  font-size: 14px;
  color: var(--text-color);
  cursor: pointer;
  border-radius: 4px;
  transition: background var(--transition);
  white-space: nowrap;
}

.context-menu button:hover {
  background: var(--border-color);
}

.context-menu button[data-format="bold"] {
  font-weight: 600;
}

.context-menu button[data-format="italic"] {
  font-style: italic;
}

.context-menu button[data-format="heading"] {
  font-weight: 600;
}

/* ==================== */
/* HENRIK'S VIEW */
/* ==================== */
.henrik-main {
  display: flex;
  min-height: calc(100vh - 50px);
  margin-top: 50px;
}

.doc-list-container {
  width: 300px;
  background: var(--panel-bg);
  border-right: 1px solid var(--border-color);
  overflow-y: auto;
  flex-shrink: 0;
}

.doc-list {
  padding: 20px;
}

.doc-item {
  padding: 15px;
  border: 1px solid var(--border-color);
  border-radius: 8px;
  margin-bottom: 10px;
  cursor: pointer;
  transition: all var(--transition);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.doc-item:hover {
  border-color: var(--accent-color);
}

.doc-item.active {
  background: var(--accent-color);
  border-color: var(--accent-color);
}

.doc-item.active .doc-title,
.doc-item.active .doc-status {
  color: white !important;
}

.doc-item.unread {
  border-left: 4px solid var(--accent-color);
}

.doc-title {
  font-size: 15px;
  font-weight: 500;
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  margin-right: 10px;
}

.doc-status {
  font-size: 11px;
  padding: 3px 8px;
  border-radius: 10px;
}

.doc-panel {
  flex: 1;
  display: flex;
  flex-direction: column;
  opacity: 0.5;
  transition: opacity var(--transition);
}

.doc-panel.open {
  opacity: 1;
}

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

.doc-panel-header h2 {
  font-size: 20px;
  font-weight: 500;
}

.close-btn {
  background: none;
  border: none;
  font-size: 28px;
  color: var(--text-color);
  cursor: pointer;
  padding: 0 10px;
  opacity: 0.6;
  transition: opacity var(--transition);
}

.close-btn:hover {
  opacity: 1;
}

.doc-panel-actions {
  padding: 15px 30px;
  display: flex;
  gap: 10px;
  border-bottom: 1px solid var(--border-color);
}

.action-btn {
  padding: 10px 20px;
  background: var(--accent-color);
  border: none;
  color: white;
  font-family: var(--font-family);
  font-size: 14px;
  cursor: pointer;
  border-radius: 6px;
  transition: background var(--transition);
}

.action-btn:hover {
  background: var(--accent-hover);
}

.action-btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.action-btn.success {
  background: #4a8f4a;
}

.action-btn.success:hover {
  background: #3d7a3d;
}

.doc-viewer {
  flex: 1;
  padding: 30px;
  overflow-y: auto;
  font-family: var(--font-family);
  font-size: var(--font-size);
  line-height: var(--line-height);
}

.doc-viewer .empty-doc {
  color: var(--placeholder-color);
  text-align: center;
  padding: 40px;
}

/* Grammar and spelling highlights */
.grammar-error {
  background-color: var(--grammar-bg);
  padding: 2px 4px;
  border-radius: 3px;
  cursor: help;
}

.spelling-error {
  background-color: var(--spelling-bg);
  padding: 2px 4px;
  border-radius: 3px;
  cursor: help;
}

/* ==================== */
/* RESPONSIVE */
/* ==================== */
@media (max-width: 900px) {
  .henrik-main {
    flex-direction: column;
  }

  .doc-list-container {
    width: 100%;
    max-height: 40vh;
    border-right: none;
    border-bottom: 1px solid var(--border-color);
  }

  .doc-panel {
    min-height: 60vh;
  }
}

@media (max-width: 600px) {
  .side-panel {
    width: 280px;
  }

  .editor-container {
    padding: 70px 16px 40px;
  }

  .editor {
    width: 100% !important;
  }

  .doc-panel-header {
    padding: 15px 20px;
  }

  .doc-panel-actions {
    padding: 10px 20px;
    flex-wrap: wrap;
  }

  .doc-viewer {
    padding: 20px;
  }
}
