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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: #1a1a1a;
  color: #e0e0e0;
  overflow: hidden;
  height: 100vh;
}

/* Header */
.header {
  background: #2a2a2a;
  padding: 1rem 2rem;
  border-bottom: 1px solid #3a3a3a;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.header h1 {
  font-size: 1.5rem;
  font-weight: 600;
  color: #fff;
}

.header-actions {
  display: flex;
  gap: 0.5rem;
  align-items: center;
}

#ai-indicator {
  font-size: 0.9rem;
  color: #9a9a9a;
  margin-right: 0.5rem;
}

/* Buttons */
.btn {
  padding: 0.5rem 1rem;
  background: #4a4a4a;
  border: none;
  border-radius: 6px;
  color: #fff;
  cursor: pointer;
  font-size: 0.9rem;
  transition: background 0.2s;
}

.btn:hover {
  background: #5a5a5a;
}

.btn-primary {
  background: #667eea;
}

.btn-primary:hover {
  background: #5568d3;
}

.btn-ai {
  background: #667eea;
}

.btn-ai:hover {
  background: #5568d3;
}

/* Modal */
.modal {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.8);
  align-items: center;
  justify-content: center;
  z-index: 1000;
}

.modal.open {
  display: flex;
}

.modal-content {
  background: #2a2a2a;
  padding: 2rem;
  border-radius: 12px;
  width: 500px;
  max-width: 90vw;
}

.modal-content h2 {
  margin-bottom: 1.5rem;
}

.setting-group {
  margin-bottom: 1.5rem;
}

.setting-group label {
  display: block;
  margin-bottom: 0.5rem;
  color: #9a9a9a;
  font-size: 0.9rem;
}

.setting-group input {
  width: 100%;
  padding: 0.75rem;
  background: #3a3a3a;
  border: 1px solid #4a4a4a;
  border-radius: 6px;
  color: #fff;
  font-size: 0.9rem;
}

.setting-group input:focus {
  outline: none;
  border-color: #667eea;
}

.hint {
  font-size: 0.8rem;
  color: #9a9a9a;
  margin-top: 0.5rem;
}

.hint a {
  color: #667eea;
  text-decoration: none;
}

.hint a:hover {
  text-decoration: underline;
}

.modal-actions {
  display: flex;
  gap: 0.5rem;
  justify-content: flex-end;
}

/* Container */
.container {
  display: flex;
  height: calc(100vh - 65px);
}

/* Sidebar */
.sidebar {
  width: 250px;
  background: #2a2a2a;
  border-right: 1px solid #3a3a3a;
  overflow-y: auto;
  padding: 1rem;
}

.sidebar h3 {
  font-size: 0.9rem;
  font-weight: 600;
  color: #9a9a9a;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 1rem;
}

.example {
  padding: 0.75rem;
  background: #3a3a3a;
  border-radius: 6px;
  margin-bottom: 0.5rem;
  cursor: pointer;
  transition: background 0.2s;
}

.example:hover {
  background: #4a4a4a;
}

.example.active {
  background: #667eea;
}

/* Main */
.main {
  flex: 1;
  display: flex;
  flex-direction: column;
}

/* Editor Container */
.editor-container {
  flex: 1;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1px;
  background: #3a3a3a;
}

.editor-panel {
  background: #1e1e1e;
  display: flex;
  flex-direction: column;
  position: relative;
}

.panel-header {
  background: #2a2a2a;
  padding: 0.5rem 1rem;
  font-size: 0.9rem;
  border-bottom: 1px solid #3a3a3a;
  flex-shrink: 0;
}

#editor-wrapper {
  flex: 1;
  overflow: hidden;
  position: relative;
}

.CodeMirror {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  height: 100% !important;
  font-size: 14px;
}

#preview {
  flex: 1;
  border: none;
  background: #0f1419;
}

.preview-error {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  background: rgba(255, 107, 107, 0.95);
  color: white;
  padding: 1rem;
  font-family: 'SF Mono', Monaco, 'Cascadia Code', 'Roboto Mono', Consolas, 'Courier New', monospace;
  font-size: 12px;
  max-height: 40vh;
  overflow-y: auto;
  display: none;
  z-index: 1000;
  border-top: 3px solid #ff0000;
}

.preview-error pre {
  margin: 0.5rem 0 0 0;
  white-space: pre-wrap;
  word-break: break-word;
  font-family: inherit;
  font-size: inherit;
}

/* AI Panel */
.ai-panel {
  background: #2a2a2a;
  border-top: 1px solid #3a3a3a;
  padding: 1rem;
  flex-shrink: 0;
}

.ai-input-container {
  display: flex;
  gap: 0.5rem;
}

.ai-meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
  min-height: 1.5em;
  margin-top: 0.5rem;
  margin-bottom: 0.5rem;
}

.ai-input {
  flex: 1;
  padding: 0.75rem;
  background: #3a3a3a;
  border: 1px solid #4a4a4a;
  border-radius: 6px;
  color: #fff;
  font-size: 0.9rem;
}

.ai-input:focus {
  outline: none;
  border-color: #667eea;
}

.ai-status {
  font-size: 0.8rem;
  color: #9a9a9a;
  flex: 1;
}

.ai-status.error {
  color: #ff6b6b;
}

.ai-status.success {
  color: #51cf66;
}

.ai-disclaimer {
  font-size: 0.75rem;
  color: #ffd43b;
  margin-top: 0.5rem;
  padding: 0.5rem;
  background: rgba(255, 212, 59, 0.1);
  border-radius: 4px;
  border-left: 3px solid #ffd43b;
}

.ai-disclaimer.hidden {
  display: none;
}

.ai-input:disabled,
.btn-ai:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn-ai.loading {
  position: relative;
  color: transparent;
}

.btn-ai.loading::after {
  content: "Generating...";
  position: absolute;
  left: 0;
  right: 0;
  color: #fff;
  animation: pulse 1.5s ease-in-out infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}

.btn-text {
  background: none;
  border: none;
  color: #9a9a9a;
  font-size: 0.75rem;
  cursor: pointer;
  padding: 0.25rem 0.5rem;
  border-radius: 4px;
  transition: all 0.2s;
}

.btn-text:hover {
  color: #fff;
  background: rgba(255, 255, 255, 0.1);
}

.btn-text:disabled {
  opacity: 0.3;
  cursor: not-allowed;
}
