/* Reset y variables */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

:root {
  --bg-primary: #ffffff;
  --bg-secondary: #f5f5f5;
  --bg-tertiary: #e8e8e8;
  --text-primary: #1a1a1a;
  --text-secondary: #666666;
  --border-color: #e0e0e0;
  --accent-color: #2563eb;
  --accent-hover: #1d4ed8;
  --danger-color: #dc2626;
  --success-color: #16a34a;
  --shadow: 0 1px 3px rgba(0,0,0,0.1);
  --radius: 6px;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg-secondary);
  color: var(--text-primary);
  line-height: 1.6;
}

/* Login Page */
.login-page {
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 100vh;
}

.login-container {
  background: var(--bg-primary);
  padding: 3rem;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  width: 100%;
  max-width: 400px;
  text-align: center;
}

.login-container h1 {
  font-size: 1.75rem;
  margin-bottom: 0.5rem;
}

.subtitle {
  color: var(--text-secondary);
  margin-bottom: 2rem;
}

.login-form {
  text-align: left;
}

/* Forms */
.form-group {
  margin-bottom: 1rem;
}

.form-group.inline {
  display: inline-block;
  margin-right: 1rem;
}

.form-group label {
  display: block;
  margin-bottom: 0.5rem;
  font-weight: 500;
  font-size: 0.875rem;
}

input[type="text"],
input[type="password"],
input[type="search"],
textarea,
select {
  width: 100%;
  padding: 0.75rem;
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
  font-size: 1rem;
  font-family: inherit;
  transition: border-color 0.2s;
}

input:focus,
textarea:focus,
select:focus {
  outline: none;
  border-color: var(--accent-color);
}

textarea {
  resize: vertical;
}

/* Buttons */
.btn {
  padding: 0.75rem 1.5rem;
  border: none;
  border-radius: var(--radius);
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  transition: background-color 0.2s;
}

.btn-primary {
  background: var(--accent-color);
  color: white;
}

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

.btn-secondary {
  background: var(--bg-tertiary);
  color: var(--text-primary);
}

.btn-secondary:hover {
  background: var(--border-color);
}

.btn-danger {
  background: var(--danger-color);
  color: white;
}

.btn-danger:hover {
  background: #b91c1c;
}

.error-msg {
  color: var(--danger-color);
  margin-top: 1rem;
  font-size: 0.875rem;
}

/* App Layout */
.app-container {
  display: flex;
  flex-direction: column;
  height: 100vh;
}

.header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1rem 2rem;
  background: var(--bg-primary);
  border-bottom: 1px solid var(--border-color);
}

.header h1 {
  font-size: 1.25rem;
}

.header nav {
  display: flex;
  gap: 0.5rem;
}

.main-content {
  display: flex;
  flex: 1;
  overflow: hidden;
}

/* Sidebar */
.sidebar {
  width: 300px;
  background: var(--bg-primary);
  border-right: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
}

.sidebar-header {
  padding: 1rem;
  border-bottom: 1px solid var(--border-color);
}

.sidebar-header h2 {
  font-size: 1rem;
  margin-bottom: 0.75rem;
}

.search-input {
  padding: 0.5rem;
  font-size: 0.875rem;
}

.filters {
  padding: 0.75rem 1rem;
  display: flex;
  gap: 0.5rem;
  border-bottom: 1px solid var(--border-color);
}

.filter-select {
  flex: 1;
  padding: 0.5rem;
  font-size: 0.8rem;
}

.articles-list {
  flex: 1;
  overflow-y: auto;
  list-style: none;
}

.article-item {
  padding: 1rem;
  border-bottom: 1px solid var(--border-color);
  cursor: pointer;
  transition: background-color 0.2s;
}

.article-item:hover {
  background: var(--bg-secondary);
}

.article-item.active {
  background: var(--bg-secondary);
  border-left: 3px solid var(--accent-color);
}

.article-item h3 {
  font-size: 0.9rem;
  margin-bottom: 0.25rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.article-item p {
  font-size: 0.75rem;
  color: var(--text-secondary);
}

.article-item .meta {
  display: flex;
  gap: 0.5rem;
  margin-top: 0.5rem;
}

.article-item .tag {
  font-size: 0.7rem;
  background: var(--bg-tertiary);
  padding: 0.15rem 0.5rem;
  border-radius: 3px;
}

/* Editor Panel */
.editor-panel {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.view {
  display: none;
  flex-direction: column;
  height: 100%;
  padding: 1.5rem;
  overflow-y: auto;
}

.view.active {
  display: flex;
}

.welcome-message {
  text-align: center;
  margin-top: 15%;
  color: var(--text-secondary);
}

.welcome-message h2 {
  margin-bottom: 0.5rem;
}

/* Editor Header */
.editor-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1rem;
  gap: 1rem;
}

.title-input {
  flex: 1;
  font-size: 1.5rem;
  font-weight: 600;
  padding: 0.5rem;
  border: 1px solid transparent;
}

.title-input:focus {
  border-color: var(--border-color);
}

.editor-actions {
  display: flex;
  gap: 0.5rem;
}

.editor-meta {
  display: flex;
  gap: 1rem;
  margin-bottom: 1rem;
  flex-wrap: wrap;
}

.editor-meta .form-group {
  margin-bottom: 0;
}

.editor-meta input,
.editor-meta select {
  padding: 0.5rem;
  font-size: 0.875rem;
  width: auto;
  min-width: 150px;
}

/* Editor Body */
.editor-body {
  display: flex;
  gap: 1rem;
  flex: 1;
  min-height: 0;
}

.article-content {
  flex: 2;
  display: flex;
  flex-direction: column;
  background: var(--bg-primary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
  overflow: hidden;
}

.tabs {
  display: flex;
  border-bottom: 1px solid var(--border-color);
}

.tab {
  padding: 0.75rem 1.5rem;
  background: none;
  border: none;
  cursor: pointer;
  font-size: 0.875rem;
  color: var(--text-secondary);
  border-bottom: 2px solid transparent;
}

.tab.active {
  color: var(--accent-color);
  border-bottom-color: var(--accent-color);
}

.tab-content {
  display: none;
  flex: 1;
  overflow: auto;
}

.tab-content.active {
  display: block;
}

.content-preview {
  padding: 1.5rem;
  line-height: 1.8;
}

.content-preview h1 { font-size: 2rem; margin: 1rem 0; }
.content-preview h2 { font-size: 1.5rem; margin: 1rem 0; }
.content-preview h3 { font-size: 1.25rem; margin: 1rem 0; }
.content-preview p { margin: 1rem 0; }
.content-preview ul, .content-preview ol { margin: 1rem 0; padding-left: 2rem; }
.content-preview li { margin: 0.5rem 0; }

.content-html {
  width: 100%;
  height: 100%;
  border: none;
  padding: 1rem;
  font-family: 'Monaco', 'Menlo', monospace;
  font-size: 0.875rem;
  resize: none;
}

/* Chat Panel */
.chat-panel {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: var(--bg-primary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
  min-width: 300px;
}

.chat-panel h3 {
  padding: 1rem;
  font-size: 0.9rem;
  border-bottom: 1px solid var(--border-color);
}

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 1rem;
}

.chat-message {
  margin-bottom: 1rem;
  padding: 0.75rem;
  border-radius: var(--radius);
  font-size: 0.875rem;
}

.chat-message.user {
  background: var(--accent-color);
  color: white;
  margin-left: 2rem;
}

.chat-message.assistant {
  background: var(--bg-secondary);
  margin-right: 2rem;
}

.chat-form {
  display: flex;
  gap: 0.5rem;
  padding: 1rem;
  border-top: 1px solid var(--border-color);
}

.chat-form input {
  flex: 1;
  padding: 0.5rem;
}

.chat-form button {
  padding: 0.5rem 1rem;
}

/* Metadata View */
.metadata-section {
  background: var(--bg-primary);
  padding: 1.5rem;
  border-radius: var(--radius);
  margin-bottom: 1rem;
  border: 1px solid var(--border-color);
}

.metadata-section h3 {
  font-size: 1rem;
  margin-bottom: 1rem;
}

.copy-section {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.copy-section textarea {
  font-family: 'Monaco', 'Menlo', monospace;
  font-size: 0.8rem;
}

.metadata-actions {
  display: flex;
  gap: 1rem;
  justify-content: flex-end;
}

.image-suggestion {
  background: var(--bg-secondary);
  padding: 1rem;
  border-radius: var(--radius);
  margin-bottom: 0.5rem;
}

.image-suggestion strong {
  display: block;
  margin-bottom: 0.5rem;
}

.image-suggestion p {
  font-size: 0.875rem;
  margin: 0.25rem 0;
}

.image-suggestion .prompt {
  font-style: italic;
  color: var(--text-secondary);
}

/* Loading Overlay */
.loading-overlay {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(255,255,255,0.9);
  justify-content: center;
  align-items: center;
  flex-direction: column;
  z-index: 1000;
}

.loading-overlay.active {
  display: flex;
}

.spinner {
  width: 40px;
  height: 40px;
  border: 3px solid var(--border-color);
  border-top-color: var(--accent-color);
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

#loadingText {
  margin-top: 1rem;
  color: var(--text-secondary);
}

/* Responsive */
@media (max-width: 1024px) {
  .editor-body {
    flex-direction: column;
  }

  .chat-panel {
    min-width: 100%;
    max-height: 300px;
  }
}

@media (max-width: 768px) {
  .main-content {
    flex-direction: column;
  }

  .sidebar {
    width: 100%;
    max-height: 200px;
  }

  .header {
    padding: 1rem;
  }

  .editor-header {
    flex-direction: column;
    align-items: stretch;
  }

  .editor-actions {
    justify-content: flex-end;
  }
}
