html {
  height: 100vh; /* Fallback for browsers that do not support custom properties */
  height: calc(var(--vh, 1vh) * 100);
}

body {
  margin: 0;
  font-family: sans-serif;
  height: 100%;
  display: flex;
  flex-direction: column;
  overflow: hidden; /* Prevent body from scrolling */
}

header {
  background-color: #f8f9fa;
  padding: 10px 20px;
  border-bottom: 1px solid #dee2e6;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

header h1 {
  margin: 0;
  font-size: 24px;
  color: #3f51b5;
}

.header-buttons {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-grow: 1;
  flex-wrap: wrap;
  gap: 10px;
}

.header-right-controls {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 5px;
}

.header-right-controls span {
  font-size: 14px;
  color: #555555;
}

#toggle-image-size {
  padding: 4px 8px;
  border-radius: 4px;
  border: none;
  background-color: #eeeeee;
  color: #444746;
  cursor: pointer;
  height: 32px;
  box-sizing: border-box;
  transition: background-color 0.2s, color 0.2s;
  font-size: 14px;
  min-width: 100px;
}

#toggle-image-size.active {
  background-color: #3f51b5;
  color: #ffffff;
}

.view-controls {
  display: inline-block;
}

.view-controls img {
  padding: 4px;
  border-radius: 4px;
  cursor: pointer;
  transition: background-color 0.2s;
}

.view-controls img:hover {
  background-color: rgba(0, 0, 0, 0.1);
}

.view-controls img.active {
  background-color: rgba(0, 0, 0, 0.15);
}

#preview-inner.limit-image-width img {
  max-width: 100%;
  height: auto;
}

#open-file,
#save-md,
#save-pdf {
  padding: 4px 8px;
  border-radius: 4px;
  border: none;
  background-color: #3f51b5;
  color: #ffffff;
  cursor: pointer;
  height: 32px;
  box-sizing: border-box;
  transition: background-color 0.2s, color 0.2s;
  font-size: 14px;
}

#open-file {
  background-color: tomato;
}

#open-file:hover,
#save-md:hover,
#save-pdf:hover {
  background-color: #303f9f;
}

.container {
  display: flex;
  flex-grow: 1;
  overflow: hidden;
}

.split {
  height: 100%;
  padding: 10px;
  box-sizing: border-box;
  overflow-y: auto;
}

.left {
  width: 50%;
  border-right: 2px solid #adb5bd;
}

.right {
  width: 50%;
}

.container.show-left .right,
.container.show-right .left {
  display: none;
}

.container.show-left .left,
.container.show-right .right {
  width: 100%;
  border: none;
}

textarea {
  width: 100%;
  height: 100%;
  border: none;
  resize: none;
}

@media (max-width: 768px) {
  /* Default to left view on small screens */
  .container:not(.show-right) .right {
    display: none;
  }

  .container:not(.show-right) .left {
    width: 100%;
    border-right: none;
  }

  /* "Both" view on small screens */
  .container:not(.show-left):not(.show-right) .right {
    display: block;
    width: 50%;
  }

  .container:not(.show-left):not(.show-right) .left {
    width: 50%;
    border-right: 2px solid #adb5bd;
  }
}

@media print {
  html,
  body {
    height: auto !important;
    overflow: visible !important;
    display: block !important;
  }
  body > *:not(.container) {
    display: none;
  }
  .container,
  .right {
    display: block !important;
    width: 100% !important;
    height: auto !important;
    overflow: visible !important;
  }
  .left {
    display: none !important;
  }
}

/* Handle overflow for wide elements */
#preview-inner pre {
  overflow-x: auto;
}

#preview-inner table {
  display: block;
  max-width: 100%;
  overflow-x: auto;
}

#preview-inner th,
#preview-inner td {
  word-break: break-all;
}

/* Print-specific styles */
@media print {
  #preview-inner pre,
  #preview-inner code {
    white-space: pre-wrap;
    word-wrap: break-word;
  }

  #preview-inner table {
    table-layout: fixed;
    width: 100%;
  }

  #preview-inner th,
  #preview-inner td {
    word-wrap: break-word;
  }
}
