/* Base styles */
html, body {
  width: 100%; 
  height: 100%; 
  margin: 0; 
  padding: 0;
  background: var(--bg-color);
  overflow: hidden;
  font-family: monospace;
}

/* Theme variables */
:root {
  --text-color: #0EFC63;
  --bg-color: #000;
  --border-color: #0EFC63;
  --hover-color: #0cd752;
  --menu-bg: #001201;
}

/* Amber theme */
body.theme-amber {
  --text-color: #FFB000;
  --bg-color: #000;
  --border-color: #FFB000;
  --hover-color: #FFC740;
  --menu-bg: #120F01;
}

/* Green theme (default) */
body.theme-green {
  --text-color: #0EFC63;
  --bg-color: #000;
  --border-color: #0EFC63;
  --hover-color: #0cd752;
  --menu-bg: #001201;
}

/* Blue theme */
body.theme-blue {
  --text-color: #4A9DFF;
  --bg-color: #000;
  --border-color: #4A9DFF;
  --hover-color: #82BEFF;
  --menu-bg: #010E1A;
}

/* White theme (DOS style) */
body.theme-white {
  --text-color: #FFFFFF;
  --bg-color: #0000AA;
  --border-color: #FFFFFF;
  --hover-color: #CCCCCC;
  --menu-bg: #000088;
}

/* CRT scanline effect */
body.crt-effect:before {
  content: "";
  display: block;
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  background: linear-gradient(rgba(18, 16, 16, 0) 50%, rgba(0, 0, 0, 0.25) 50%);
  background-size: 100% 2px;
  z-index: 100;
}

/* Add a subtle screen flicker animation for CRT effect */
body.crt-effect {
  animation: flicker 0.15s infinite;
}

@keyframes flicker {
  0% { opacity: 1.0; }
  49% { opacity: 1.0; }
  50% { opacity: 0.95; }
  51% { opacity: 1.0; }
  99% { opacity: 1.0; }
  100% { opacity: 0.98; }
}

/* Theme selectors */
.theme-selectors {
  display: flex;
  gap: 5px;
  position: absolute;
  left: -125px; /* Hide all but 2px of the first element */
  top: 10px;
  z-index: 20;
  transition: left 0.3s ease; /* Smooth transition */
  background: transparent;
  padding: 5px;
  padding-left: 0; /* No extra padding */
  border-right: 1px solid var(--border-color); /* Visible 2px border when collapsed */
}

/* When hovered or has 'expanded' class */
.theme-selectors:hover, 
.theme-selectors.expanded {
  left: 15px; /* Fully visible when hovered */
  border-right: none; /* Remove border when expanded */
}

/* Add subtle animation to hint at interactivity when collapsed */
.theme-selectors:not(:hover):not(.expanded) {
  animation: pulse 2s infinite;
}

/* Adjust tooltip position for collapsed state */
.theme-selectors:not(:hover):not(.expanded) .tooltip {
  display: none;
}

/* Ensure first theme square touches the border */
.theme-selectors .theme-item:first-child {
  margin-left: 0;
}

@keyframes pulse {
  0% { border-color: var(--border-color); }
  50% { border-color: var(--hover-color); }
  100% { border-color: var(--border-color); }
}

.theme-square {
  width: 15px;
  height: 15px;
  border: 1px solid #000000;
  cursor: pointer;
  transition: transform 0.2s, border-color 0.2s;
}

.theme-square:hover {
  transform: scale(1.2);
  border-color: #fff;
}

.theme-square.active {
  border-color: #000000;
  border-width: 1px;
}

/* Theme colors */
.theme-square.amber {
  background-color: #FFB000;
}

.theme-square.green {
  background-color: #0EFC63;
}

.theme-square.blue {
  background-color: #4A9DFF;
}

.theme-square.white {
  background-color: #FFFFFF;
}

.theme-square.crt {
  background-color: #333;
  color: #fff;
  font-size: 11px;
  display: flex;
  justify-content: center;
  align-items: center;
}

/* Adjust app-title position to make room for theme squares */
.app-title {
  left: 130px;
}

/* Custom Scrollbar Styling */
::-webkit-scrollbar {
  width: 12px;
  height: 12px;
}

::-webkit-scrollbar-track {
  background: var(--bg-color);
  border-left: 1px solid var(--border-color);
}

::-webkit-scrollbar-thumb {
  background: var(--border-color);
  border: 2px solid var(--bg-color);
}

::-webkit-scrollbar-thumb:hover {
  background: var(--hover-color);
}

* {
  scrollbar-color: var(--border-color) var(--bg-color);
}

/* Default text selection (green theme) */
::selection {
  background-color: rgba(14, 252, 99, 0.4);
  color: #FFFFFF;
}

::-moz-selection {
  background-color: rgba(14, 252, 99, 0.4);
  color: #FFFFFF;
}

/* Amber theme selection */
body.theme-amber ::selection {
  background-color: rgba(255, 176, 0, 0.4);
  color: #FFFFFF;
}

body.theme-amber ::-moz-selection {
  background-color: rgba(255, 176, 0, 0.4);
  color: #FFFFFF;
}

/* Blue theme selection */
body.theme-blue ::selection {
  background-color: rgba(74, 157, 255, 0.4);
  color: #FFFFFF;
}

body.theme-blue ::-moz-selection {
  background-color: rgba(74, 157, 255, 0.4);
  color: #FFFFFF;
}

/* DOS style white theme selection */
body.theme-white ::selection {
  background-color: rgba(255, 255, 255, 0.5);
  color: #0000AA;
}

body.theme-white ::-moz-selection {
  background-color: rgba(255, 255, 255, 0.5);
  color: #0000AA;
}

/* Rest */

#loading-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: var(--bg-color);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 999;
  color: var(--text-color);
  font-family: monospace;
}

#app-container {
  display: flex;
  flex-direction: column;
  height: 100vh;
}

/* Menu bar with vertical buttons */
#menu-bar {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  min-height: 40px;
  background: var(--menu-bg);
  border-bottom: 1px solid var(--border-color);
  padding: 0 15px;
  position: relative;
}

.app-title {
  color: var(--text-color);
  font-size: 18px;
  font-weight: bold;
  position: absolute;
  left: 15px;
  top: 10px;
}

.document-title-display {
  color: var(--text-color);
  font-size: 16px;
  text-align: center;
  position: absolute;
  width: 70%;
  left: 15%;
  top: 10px;
}

.menu-buttons {
  display: flex;
  flex-direction: column;
  gap: 6px;
  position: absolute;
  right: -26px; /* Hide most of the buttons, leaving 2px visible */
  top: 60px; /* Position as requested */
  z-index: 100;
  transition: right 0.3s ease; /* Smooth transition */
  width: 28px; /* Same as button width */
  padding: 5px;
  padding-right: 2px; /* This creates the 2px visible edge */
  background: transparent;
}

/* When hovered or has 'expanded' class */
.menu-buttons:hover, 
.menu-buttons.expanded {
  right: 15px; /* Fully visible when hovered */
}

/* Adjust tooltip position for collapsed state */
.menu-buttons:not(:hover):not(.expanded) .tooltip {
  display: none;
}

.menu-item {
  position: relative;
  display: flex;
  align-items: center;
}

.menu-btn {
  width: 28px;
  height: 28px;
  background: #111;
  color: var(--text-color);
  border: 1px solid var(--border-color);
  border-radius: 3px;
  font-family: monospace;
  font-weight: bold;
  cursor: pointer;
  display: flex;
  justify-content: center;
  align-items: center;
  transition: background 0.2s;
  padding: 0;
  margin: 0;
}

.menu-btn:hover {
  background: #222;
}

.menu-btn:active {
  background: var(--border-color);
  color: var(--bg-color);
}

/* Width adjuster strip */
#width-adjuster {
  height: 20px;
  background: var(--menu-bg);
  border-top: 1px solid var(--border-color);
  cursor: col-resize;
  position: relative;
  display: flex;
  justify-content: center;
  align-items: center;
}

.adjuster-handle {
  width: 30px;
  height: 10px;
  background: var(--text-color);
  border-radius: 2px;
  position: relative;
}

.adjuster-handle::before,
.adjuster-handle::after {
  content: '';
  position: absolute;
  height: 100%;
  width: 1px;
  background: #000;
  top: 0;
}

.adjuster-handle::before {
  left: 10px;
}

.adjuster-handle::after {
  right: 10px;
}

/* Terminal screen */
#screen {
  flex-grow: 1;
  box-sizing: border-box;
  padding: 8px 16px;
  font-size: 18px;
  line-height: 1.2;
  color: var(--text-color);
  background: var(--bg-color);
  overflow-y: auto;
  white-space: pre-wrap; /* Changed from pre to pre-wrap */
  word-wrap: break-word; /* Add word wrapping */
  scroll-behavior: smooth;
  width: 90%; /* Default width */
  margin: 0 auto; /* Center the text area */
  transition: width 0.2s ease; /* Smooth width changes */
}

.cursor {
  display: inline-block;
  width: 0.6em; 
  height: 1.2em;
  background: var(--text-color);
  animation: blink 1s steps(1) infinite;
  vertical-align: bottom;
}

@keyframes blink {
  50% { opacity: 0; }
}

/* Editable line styles */
.line {
  min-height: 1.2em;
  cursor: default;
}

.editable-line {
  background: none;
  border: none;
  color: var(--text-color);
  font-family: monospace;
  font-size: 18px;
  width: 100%;
  outline: none;
  padding: 0;
}

/* Panels */
.panel {
  position: absolute;
  top: 41px;
  right: -280px; /* Start off-screen */
  width: 250px;
  height: calc(100vh - 41px);
  background: var(--menu-bg);
  /*border-left: 1px solid var(--border-color);*/
  padding: 15px;
  color: var(--text-color);
  overflow-y: auto;
  transition: right 0.3s ease; /* Add sliding transition */
  z-index: 50; /* Ensure panels appear above other content */
}

/* Panel visible state */
.panel.visible {
  right: 0; /* Slide in */
}

.panel h3 {
  margin-top: 0;
  border-bottom: 1px solid var(--border-color);
  padding-bottom: 8px;
}

.panel button {
  background: var(--bg-color);
  color: var(--text-color);
  border: 1px solid var(--border-color);
  border-radius: 3px;
  padding: 8px 12px;
  margin: 5px 0;
  width: 100%;
  cursor: pointer;
  font-family: monospace;
}

.panel button:hover {
  background: var(--menu-bg);
}

.panel button:active {
  background: var(--border-color);
  color: var(--bg-color);
}

#new-note {
  width: 100%;
  background: var(--bg-color);
  color: var(--text-color);
  border: 1px solid var(--border-color);
  font-family: monospace;
  padding: 8px;
  margin: 10px 0;
  height: 80px;
  resize: vertical;
  box-sizing: border-box;
}

.note-item {
  margin: 10px 0;
  padding: 8px;
  border: 1px solid var(--border-color);
  background: var(--bg-color);
  position: relative;
  box-sizing: border-box;
}
.note-content {
  min-height: 30px;
  word-wrap: break-word;
}

.note-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 5px;
  font-size: 12px;
}

.note-timestamp {
  color: #888;
}

.note-delete-btn {
  background: transparent;
  border: none;
  outline: none;
  cursor: pointer;
  color: var(--text-color);
  padding: 2px;
  display: flex;
  align-items: center;
  width: auto;
  height: auto;
  margin: 0;
  min-width: unset;
}

.note-delete-btn:hover {
  color: #ff3333;
  background: transparent;
  border: none;
}

/* Override any panel button styles for note delete button */
.panel .note-delete-btn {
  background: transparent;
  border: none;
  width: auto;
  margin: 0;
  padding: 2px;
}

.panel .note-delete-btn:hover {
  background: transparent;
  border: none;
}

.note-edit-textarea {
  width: 100%;
  min-height: 60px;
  background: #111;
  color: var(--text-color);
  border: 1px solid var(--border-color);
  font-family: monospace;
  padding: 5px;
  resize: vertical;
}

.hidden {
  display: none;
}

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

.file-item:hover {
  background: var(--hover-color);
  color: var(--menu-bg);
}

.file-title {
  flex-grow: 1;
  cursor: pointer;
}

.file-actions {
  display: flex;
  gap: 5px;
}

/* Delete button */
.panel .delete-btn {
  background: transparent;
  color: var(--text-color);
  border: none;
  width: 24px;
  height: 24px;
  border-radius: 0;
  cursor: pointer;
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 0;
  margin: 0;
}

.panel .delete-btn:hover {
  background: transparent;
  color: #FF3333;
  border: none;
  width: auto;
}

.panel .delete-btn svg {
  width: 18px;
  height: 18px;
  fill: currentColor; /* This makes SVG follow parent color */
}

/* Custom Alert */
#custom-alert {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.7);
  display: none; /* Explicitly hidden by default */
  justify-content: center;
  align-items: center;
  z-index: 100;
}

#custom-alert.visible {
  display: flex; /* Only show when the visible class is added */
}

.alert-content {
  background: var(--bg-color);
  border: 2px solid var(--border-color);
  padding: 20px;
  width: 300px;
}

.alert-message {
  color: var(--text-color);
  font-family: monospace;
  font-size: 16px;
  margin-bottom: 20px;
  min-height: 50px;
}

.alert-buttons {
  display: flex;
  justify-content: center;
  gap: 15px;
}

.alert-buttons button {
  background: var(--menu-bg);
  color: var(--text-color);
  border: 1px solid var(--border-color);
  padding: 8px 20px;
  cursor: pointer;
  font-family: monospace;
  transition: background 0.2s;
}

.alert-buttons button:hover {
  background: var(--bg-color);
}

.alert-buttons button:active {
  background: var(--border-color);
  color: var(--bg-color);
}

/* Custom Tooltips */

.tooltip {
  position: absolute;
  right: 38px; /* Position to the left of the button */
  background: var(--menu-bg);
  color: var(--text-color);
  border: 1px solid var(--border-color);
  padding: 5px 10px;
  font-family: monospace;
  font-size: 14px;
  white-space: nowrap;
  display: none;
  z-index: 20;
}

.menu-item:hover .tooltip {
  display: block;
}

/* Theme tooltip styling */
.theme-item {
  position: relative;
  display: inline-block;
  margin: 0 2px; /* Add some spacing between items */
}

.theme-item .tooltip {
  position: absolute;
  left: 50%;
  transform: translateX(-50%); /* Center tooltip under square */
  top: 34px; /* Position below the square */
  background: #111;
  color: var(--text-color);
  border: 1px solid var(--border-color);
  padding: 6px 10px;
  font-family: monospace;
  font-size: 14px;
  white-space: nowrap;
  display: none;
  z-index: 25; /* Higher z-index to appear above other elements */
  min-width: 30px; /* Ensure enough width for text */
  text-align: center; /* Center the text */
}

.theme-item:hover .tooltip {
  display: block;
}

/* Add a small arrow pointer to the tooltip */
.theme-item .tooltip:before {
  content: '';
  position: absolute;
  bottom: 100%;
  left: 50%;
  margin-left: -5px;
  border-width: 5px;
  border-style: solid;
  border-color: transparent transparent var(--border-color) transparent;
}

/* Status Bar Styles */
#status-bar {
  display: flex;
  justify-content: space-between;
  background: var(--menu-bg);
  border-top: 1px solid var(--border-color);
  color: var(--text-color);
  font-size: 12px;
  padding: 2px 10px;
  height: 18px;
}

.status-item {
  padding: 0 10px;
}

.status-modified {
  color: #ff6b6b;
}

/* Line Number Styles */
.line-number {
  color: rgba(255, 255, 255, 0.5);
  user-select: none;
  display: inline-block;
  width: 40px;
  text-align: right;
  margin-right: 10px;
  opacity: 0.7;
}

.line-content {
  display: inline;
}

/* Update colors based on theme */
body.theme-amber .line-number {
  color: rgba(255, 176, 0, 0.6);
}

body.theme-green .line-number {
  color: rgba(14, 252, 99, 0.6);
}

body.theme-blue .line-number {
  color: rgba(74, 157, 255, 0.6);
}

body.theme-white .line-number {
  color: rgba(255, 255, 255, 0.6);
}

/* Notification System */
#notification-container {
  position: fixed;
  bottom: 60px;
  right: 20px;
  z-index: 200;
  display: flex;
  flex-direction: column;
  gap: 10px;
  pointer-events: none; /* Allow clicking through notifications */
}

.notification {
  background: var(--menu-bg);
  color: var(--text-color);
  padding: 12px 20px;
  font-family: monospace;
  max-width: 300px;
  opacity: 0;
  transform: translateX(50px);
  transition: opacity 0.3s, transform 0.3s;
  pointer-events: none; /* Allow clicking through notifications */
}

.notification.visible {
  opacity: 1;
  transform: translateX(0);
}

.notification.success {
}

.notification.error {
}

.notification.info {
}


/* Code block styles */
pre code.hljs {
  font-family: monospace;
  background: rgba(30, 30, 30, 0.8);
  border: 1px solid var(--border-color);
  margin: 10px 0;
  padding: 10px;
  border-radius: 4px;
  overflow-x: auto;
  font-size: 16px;
  line-height: 1.4;
}

/* Adjust theme colors to match terminal themes */
body.theme-green pre code.hljs {
  border-color: #0EFC63;
  box-shadow: 0 0 5px rgba(14, 252, 99, 0.3);
}

body.theme-amber pre code.hljs {
  border-color: #FFB000;
  box-shadow: 0 0 5px rgba(255, 176, 0, 0.3);
}

body.theme-blue pre code.hljs {
  border-color: #4A9DFF;
  box-shadow: 0 0 5px rgba(74, 157, 255, 0.3);
}

body.theme-white pre code.hljs {
  border-color: #FFFFFF;
  box-shadow: 0 0 5px rgba(255, 255, 255, 0.3);
}

/* Language indicator in top-right corner */
.code-block-container {
  position: relative;
}

.code-block-delete {
  position: absolute;
  top: 0px;
  right: 64px;
  background: rgba(255, 50, 50, 0.7);
  color: white;
  border: none;
  border-radius: 3px;
  padding: 2px 6px;
  font-size: 12px;
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.2s;
  z-index: 10;
}

.code-block-container:hover .code-block-delete {
  opacity: 1;
}

.code-block-delete:hover {
  background: rgba(255, 50, 50, 0.9);
  box-shadow: 0 0 5px rgba(255, 255, 255, 0.3);
}

.language-indicator {
  position: absolute;
  top: 0;
  right: 0;
  background: var(--border-color);
  color: var(--bg-color);
  padding: 2px 6px;
  border-radius: 0 4px 0 4px;
  font-size: 12px;
  font-weight: bold;
  text-transform: uppercase;
}