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

body {
  font-family: system-ui, -apple-system, sans-serif;
  background: #0d1117;
  color: #c9d1d9;
  overflow: hidden;
}

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

/* Header */
header {
  background: #161b22;
  border-bottom: 1px solid #30363d;
  padding: 12px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 56px;
}

.logo {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 18px;
  font-weight: 600;
  color: #58a6ff;
}

.logo-icon {
  width: 32px;
  height: 32px;
  background: linear-gradient(135deg, #58a6ff, #1f6feb);
  border-radius: 8px;
  padding: 4px;
  flex-shrink: 0;
}

.logo-sub {
  color: #8b949e;
  font-weight: 400;
}

.header-actions {
  display: flex;
  gap: 10px;
}

.btn {
  padding: 8px 16px;
  border-radius: 6px;
  border: 1px solid #30363d;
  background: #21262d;
  color: #c9d1d9;
  cursor: pointer;
  font-size: 14px;
  font-weight: 500;
  transition: all 0.2s;
}

.btn:hover {
  background: #30363d;
  border-color: #484f58;
}

.btn-primary {
  background: #238636;
  border-color: #238636;
  color: white;
}

.btn-primary:hover {
  background: #2ea043;
  border-color: #2ea043;
}

/* Main Layout */
.main-layout {
  display: flex;
  height: calc(100vh - 56px);
  overflow: hidden;
}

/* Editor Panel */
.editor-panel {
  background: #0d1117;
  border-right: none;
  display: flex;
  flex-direction: column;
  width: 33.33vw;
  min-width: 300px;
  max-width: 70vw;
  flex-shrink: 0;
}

/* Resize Handle */
.resize-handle {
  width: 5px;
  cursor: col-resize;
  background: #30363d;
  flex-shrink: 0;
  position: relative;
  z-index: 10;
  transition: background 0.15s;
}

.resize-handle:hover,
.resize-handle.active {
  background: #58a6ff;
}

.tabs {
  display: flex;
  background: #161b22;
  border-bottom: 1px solid #30363d;
  padding: 0 16px;
}

.tab {
  padding: 12px 16px;
  border: none;
  background: transparent;
  color: #8b949e;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  font-size: 14px;
  font-weight: 500;
  transition: all 0.2s;
}

.tab:hover {
  color: #c9d1d9;
}

.tab.active {
  color: #58a6ff;
  border-bottom-color: #58a6ff;
}

.tab-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* Code Editor (CodeMirror wrapper) */
.editor-wrapper {
  flex: 1;
  overflow: hidden;
}

.editor-wrapper .CodeMirror {
  height: 100%;
  font-family: "Monaco", "Menlo", "Consolas", monospace;
  font-size: 13px;
  line-height: 1.6;
}

/* CodeMirror dark theme matching our UI */
.cm-s-sketchdown-dark.CodeMirror {
  background: #0d1117;
  color: #c9d1d9;
}

.cm-s-sketchdown-dark .CodeMirror-gutters {
  background: #0d1117;
  border-right: 1px solid #21262d;
}

.cm-s-sketchdown-dark .CodeMirror-linenumber {
  color: #484f58;
}

.cm-s-sketchdown-dark .CodeMirror-cursor {
  border-left: 1.5px solid #c9d1d9;
}

.cm-s-sketchdown-dark div.CodeMirror-selected {
  background: rgba(31, 111, 235, 0.4);
}

.cm-s-sketchdown-dark .CodeMirror-focused div.CodeMirror-selected {
  background: rgba(31, 111, 235, 0.4);
}

.cm-s-sketchdown-dark .CodeMirror-activeline-background {
  background: #161b22;
}

.cm-s-sketchdown-dark .CodeMirror-matchingbracket {
  color: #c9d1d9 !important;
  border-bottom: 1px solid #58a6ff;
}

/* Syntax colors */
.cm-s-sketchdown-dark .cm-keyword {
  color: #ff7b72;
}

.cm-s-sketchdown-dark .cm-string {
  color: #a5d6ff;
}

.cm-s-sketchdown-dark .cm-attribute {
  color: #d2a8ff;
}

.cm-s-sketchdown-dark .cm-number {
  color: #ffa657;
}

.cm-s-sketchdown-dark .cm-operator {
  color: #ffa657;
  font-weight: bold;
}

.cm-s-sketchdown-dark .cm-comment {
  color: #484f58;
  font-style: italic;
}

/* Search dialog styling */
.cm-s-sketchdown-dark .CodeMirror-dialog {
  background: #1c2128;
  border-bottom: 1px solid #444c56;
  color: #c9d1d9;
  padding: 4px 8px;
}

.cm-s-sketchdown-dark .CodeMirror-dialog input {
  background: #0d1117;
  border: 1px solid #30363d;
  border-radius: 4px;
  color: #c9d1d9;
  padding: 2px 6px;
  font-family: "Monaco", "Menlo", "Consolas", monospace;
  font-size: 13px;
  outline: none;
}

.cm-s-sketchdown-dark .CodeMirror-dialog input:focus {
  border-color: #58a6ff;
}

.cm-s-sketchdown-dark .CodeMirror-dialog button {
  background: #21262d;
  border: 1px solid #30363d;
  border-radius: 4px;
  color: #c9d1d9;
  padding: 2px 8px;
  cursor: pointer;
  font-size: 12px;
}

.cm-s-sketchdown-dark .CodeMirror-dialog button:hover {
  background: #30363d;
}

/* Search match highlighting */
.cm-s-sketchdown-dark .cm-searching {
  background: rgba(229, 192, 56, 0.3);
  outline: 1px solid rgba(229, 192, 56, 0.5);
}

/* Examples */
.examples {
  background: #161b22;
  border-bottom: 1px solid #30363d;
  padding: 12px 16px;
}

.examples-buttons {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.example-btn {
  padding: 6px 12px;
  border-radius: 6px;
  border: 1px solid #30363d;
  background: #21262d;
  color: #8b949e;
  cursor: pointer;
  font-size: 12px;
  transition: all 0.2s;
}

.example-btn:hover {
  background: #30363d;
  color: #c9d1d9;
  border-color: #484f58;
}

/* Export Dropdown */
.tab-export-wrapper {
  position: relative;
  margin-left: auto;
  display: flex;
  align-items: center;
}

.btn-export {
  font-size: 12px;
  padding: 5px 12px;
}

.export-dropdown {
  display: none;
  position: absolute;
  top: 100%;
  left: 0;
  background: #1c2128;
  border: 1px solid #30363d;
  border-radius: 8px;
  padding: 4px;
  z-index: 20;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
  min-width: 180px;
}

.export-dropdown.visible {
  display: flex;
  flex-direction: column;
}

.export-option {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  border: none;
  background: transparent;
  color: #c9d1d9;
  cursor: pointer;
  border-radius: 6px;
  font-size: 13px;
  transition: background 0.15s;
}

.export-option:hover {
  background: #30363d;
}

.export-icon {
  background: #30363d;
  color: #58a6ff;
  font-size: 10px;
  font-weight: 700;
  padding: 3px 6px;
  border-radius: 3px;
  font-family: monospace;
}

.export-option:hover .export-icon {
  background: #484f58;
}

.export-text {
  font-size: 13px;
}

/* Error Display */
.error {
  background: #da3633;
  color: white;
  padding: 12px 16px;
  font-size: 12px;
  font-family: monospace;
  white-space: pre-wrap;
  border-top: 1px solid #f85149;
  display: none;
}

.error.visible {
  display: block;
}

/* Preview Panel */
.preview-panel {
  background: #0d1117;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  flex: 1;
  min-width: 200px;
}

.preview-toolbar {
  background: #161b22;
  border-bottom: 1px solid #30363d;
  padding: 8px 16px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.preview-title {
  font-size: 14px;
  font-weight: 600;
  color: #c9d1d9;
}

.preview-actions {
  display: flex;
  gap: 8px;
}

.viewport-btn {
  padding: 4px 12px;
  border-radius: 6px;
  border: 1px solid #30363d;
  background: #21262d;
  color: #8b949e;
  cursor: pointer;
  font-size: 12px;
  font-weight: 500;
  transition: all 0.2s;
}

.viewport-btn:hover {
  background: #30363d;
  color: #c9d1d9;
}

.viewport-btn.active {
  background: #1f6feb;
  border-color: #1f6feb;
  color: #fff;
}

#preview {
  flex: 1;
  overflow: auto;
  padding: 16px;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  background: #0d1117;
}

#preview svg {
  max-width: 100%;
  height: auto;
  filter: drop-shadow(0 4px 12px rgba(0, 0, 0, 0.3));
  transform-origin: top center;
}

#preview:empty::before {
  content: "Enter Sketchdown code to see preview";
  color: #484f58;
  font-size: 14px;
}

/* Scrollbars */
::-webkit-scrollbar {
  width: 12px;
  height: 12px;
}

::-webkit-scrollbar-track {
  background: #161b22;
}

::-webkit-scrollbar-thumb {
  background: #30363d;
  border-radius: 6px;
  border: 2px solid #161b22;
}

::-webkit-scrollbar-thumb:hover {
  background: #484f58;
}

/* Responsive */
@media (max-width: 768px) {
  .main-layout {
    flex-direction: column;
  }

  .editor-panel {
    width: 100% !important;
    max-width: 100vw;
    height: 400px;
    min-width: 0;
  }

  .resize-handle {
    display: none;
  }
}
