/*
 * Scriptum - Writing IDE Styles
 */

/* CSS Variables */
:root {
  --primary-color: #007bff;
  --primary-hover: #0056b3;
  --secondary-color: #6c757d;
  --success-color: #28a745;
  --danger-color: #dc3545;
  --warning-color: #ffc107;
  --light-bg: #f8f9fa;
  --border-color: #dee2e6;
  --text-color: #212529;
  --text-muted: #6c757d;
  --font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

/* Reset & Base */
* {
  box-sizing: border-box;
}

body {
  font-family: var(--font-family);
  color: var(--text-color);
  line-height: 1.6;
  margin: 0;
  padding: 0;
  background: var(--light-bg);
}

/* Typography */
h1, h2, h3, h4, h5, h6 {
  margin-top: 0;
  font-weight: 600;
}

a {
  color: var(--primary-color);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

/* Buttons */
.btn, button, input[type="submit"] {
  display: inline-block;
  padding: 0.5rem 1rem;
  font-size: 1rem;
  font-weight: 500;
  text-align: center;
  text-decoration: none;
  border: 1px solid var(--border-color);
  border-radius: 4px;
  background: white;
  color: var(--text-color);
  cursor: pointer;
  transition: all 0.2s;
}

.btn:hover, button:hover, input[type="submit"]:hover {
  background: var(--light-bg);
  text-decoration: none;
}

.btn-primary, input[type="submit"] {
  background: var(--primary-color);
  border-color: var(--primary-color);
  color: white;
}

.btn-primary:hover, input[type="submit"]:hover {
  background: var(--primary-hover);
  border-color: var(--primary-hover);
}

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

/* Forms */
input, textarea, select {
  font-family: inherit;
  font-size: 1rem;
  padding: 0.5rem;
  border: 1px solid var(--border-color);
  border-radius: 4px;
  width: 100%;
}

input:focus, textarea:focus, select:focus {
  outline: none;
  border-color: var(--primary-color);
  box-shadow: 0 0 0 3px rgba(0, 123, 255, 0.1);
}

label {
  display: block;
  margin-bottom: 0.25rem;
  font-weight: 500;
}

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

fieldset {
  border: 1px solid var(--border-color);
  border-radius: 4px;
  padding: 1.5rem;
  margin-bottom: 1.5rem;
}

legend {
  font-weight: 600;
  padding: 0 0.5rem;
}

.form-actions {
  margin-top: 1.5rem;
  display: flex;
  gap: 0.5rem;
}

.help-text {
  font-size: 0.875rem;
  color: var(--text-muted);
  margin-top: 0.5rem;
}

/* Alerts & Notices */
.notice {
  padding: 1rem;
  border-radius: 4px;
  margin-bottom: 1rem;
  background: #d4edda;
  border: 1px solid #c3e6cb;
  color: #155724;
}

.alert, .errors {
  padding: 1rem;
  border-radius: 4px;
  margin-bottom: 1rem;
  background: #f8d7da;
  border: 1px solid #f5c6cb;
  color: #721c24;
}

.errors ul {
  margin: 0;
  padding-left: 1.5rem;
}

/* Auth Pages Container */
.auth-container,
.settings-container {
  max-width: 400px;
  margin: 3rem auto;
  padding: 2rem;
  background: white;
  border-radius: 8px;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
}

.auth-container h1,
.settings-container h1 {
  text-align: center;
  margin-bottom: 1.5rem;
}

.auth-branding {
  text-align: center;
  margin-bottom: 2rem;
}

.auth-logo {
  width: 64px;
  height: 64px;
  margin-bottom: 0.75rem;
}

.auth-app-name {
  font-size: 1.75rem;
  font-weight: 600;
  color: var(--text-color);
  margin: 0;
}

.auth-tagline {
  color: var(--text-muted);
  font-size: 0.9rem;
  margin-top: 0.25rem;
}

.back-link {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 1.5rem;
  color: var(--text-muted);
  font-size: 0.875rem;
  font-weight: 500;
  text-decoration: none;
  transition: color 0.15s;
}

.back-link:hover {
  color: var(--text-color);
  text-decoration: none;
}

.back-icon {
  width: 16px;
  height: 16px;
}

/* Form Page */
.form-page {
  min-height: 100vh;
  background: linear-gradient(135deg, #f8fafc 0%, #f1f5f9 100%);
  padding: 2rem 1rem;
}

.form-container {
  max-width: 480px;
  margin: 0 auto;
  background: white;
  border-radius: 16px;
  padding: 2rem;
  box-shadow: 0 4px 24px rgba(0, 0, 0, 0.06);
}

.form-header {
  text-align: center;
  margin-bottom: 2rem;
}

.form-header-icon {
  width: 56px;
  height: 56px;
  margin: 0 auto 1rem;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #eff6ff 0%, #dbeafe 100%);
  border-radius: 14px;
  color: var(--primary-color);
}

.form-header-icon svg {
  width: 28px;
  height: 28px;
}

.form-header h1 {
  margin: 0 0 0.5rem;
  font-size: 1.5rem;
  font-weight: 600;
}

.form-header-subtitle {
  margin: 0;
  color: var(--text-muted);
  font-size: 0.9375rem;
}

/* Polished Form */
.polished-form .form-group {
  margin-bottom: 1.25rem;
}

.form-label {
  display: block;
  margin-bottom: 0.375rem;
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--text-color);
}

.form-input {
  display: block;
  width: 100%;
  padding: 0.75rem 1rem;
  font-size: 1rem;
  border: 1px solid var(--border-color);
  border-radius: 8px;
  background: white;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.form-input:focus {
  outline: none;
  border-color: var(--primary-color);
  box-shadow: 0 0 0 3px rgba(0, 123, 255, 0.1);
}

.form-input::placeholder {
  color: #94a3b8;
}

.form-hint {
  margin: 0.375rem 0 0;
  font-size: 0.8125rem;
  color: var(--text-muted);
}

.form-errors {
  padding: 1rem;
  margin-bottom: 1.5rem;
  background: #fef2f2;
  border: 1px solid #fecaca;
  border-radius: 8px;
  color: #dc2626;
  font-size: 0.875rem;
}

.form-errors ul {
  margin: 0;
  padding-left: 1.25rem;
}

.polished-form .form-actions {
  margin-top: 1.5rem;
}

.btn-block {
  display: block;
  width: 100%;
  padding: 0.875rem 1.5rem;
  font-size: 1rem;
  font-weight: 500;
  border-radius: 8px;
}

@media (max-width: 768px) {
  .form-page {
    padding: 1rem;
  }

  .form-container {
    padding: 1.5rem;
    border-radius: 12px;
  }

  .form-header-icon {
    width: 48px;
    height: 48px;
  }

  .form-header-icon svg {
    width: 24px;
    height: 24px;
  }

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

/* Form Sections */
.form-container-wide {
  max-width: 560px;
}

.form-section {
  padding: 1.5rem 0;
  border-bottom: 1px solid var(--border-color);
}

.form-section:first-of-type {
  padding-top: 0;
}

.form-section:last-of-type {
  border-bottom: none;
  padding-bottom: 0;
}

.form-section-alt {
  background: #f8fafc;
  margin: 1.5rem -2rem -2rem;
  padding: 1.5rem 2rem;
  border-radius: 0 0 16px 16px;
  border-bottom: none;
}

.form-section-title {
  margin: 0 0 1rem;
  font-size: 1rem;
  font-weight: 600;
  color: var(--text-color);
}

.form-section-description {
  margin: 0 0 1rem;
  font-size: 0.875rem;
  color: var(--text-muted);
}

.form-notice {
  padding: 0.75rem 1rem;
  margin-bottom: 1.5rem;
  background: #dcfce7;
  border: 1px solid #bbf7d0;
  border-radius: 8px;
  color: #166534;
  font-size: 0.875rem;
}

.btn-secondary {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  background: white;
  border: 1px solid var(--border-color);
  color: var(--text-color);
}

.btn-secondary:hover {
  background: var(--light-bg);
  border-color: var(--text-muted);
}

.btn-danger-outline {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  background: white;
  border: 1px solid var(--danger-color);
  color: var(--danger-color);
}

.btn-danger-outline:hover {
  background: #fef2f2;
  border-color: var(--danger-color);
  color: var(--danger-color);
}

.settings-divider {
  height: 1px;
  background: var(--border-color);
  margin: 1.5rem 0;
}

@media (max-width: 768px) {
  .form-section-alt {
    margin: 1.5rem -1.5rem -1.5rem;
    padding: 1.5rem;
    border-radius: 0 0 12px 12px;
  }
}

.auth-links {
  margin-top: 1.5rem;
  text-align: center;
  color: var(--text-muted);
}

.auth-links a {
  color: var(--primary-color);
}

/* Dashboard */
.dashboard {
  min-height: 100vh;
  background: linear-gradient(135deg, #f8fafc 0%, #f1f5f9 100%);
}

.dashboard-notice {
  max-width: 800px;
  margin: 0 auto 1rem;
  padding: 0.75rem 1rem;
  background: #dcfce7;
  border: 1px solid #bbf7d0;
  border-radius: 8px;
  color: #166534;
  font-size: 0.875rem;
}

.dashboard-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  max-width: 800px;
  margin: 0 auto;
  padding: 1.5rem 1.5rem 0;
}

.dashboard-brand {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.dashboard-logo {
  width: 28px;
  height: 28px;
  color: var(--primary-color);
}

.dashboard-brand-name {
  font-size: 1.25rem;
  font-weight: 600;
  color: var(--text-color);
}

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

.btn-icon {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
}

.btn-icon-only {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  padding: 0;
  border-radius: 8px;
  background: white;
  border: 1px solid var(--border-color);
  color: var(--text-muted);
  cursor: pointer;
  transition: all 0.15s;
}

.btn-icon-only:hover {
  background: white;
  border-color: var(--text-muted);
  color: var(--text-color);
}

.btn-icon-only svg {
  width: 18px;
  height: 18px;
}

.dashboard-actions .btn-primary {
  display: inline-flex;
  align-items: center;
  gap: 0.375rem;
  padding: 0.5rem 1rem;
  border-radius: 8px;
  font-weight: 500;
}

/* Dashboard Content */
.dashboard-content {
  max-width: 800px;
  margin: 0 auto;
  padding: 2rem 1.5rem 3rem;
}

.dashboard-title-row {
  display: flex;
  align-items: baseline;
  gap: 0.75rem;
  margin-bottom: 1.5rem;
}

.dashboard-title {
  margin: 0;
  font-size: 1.75rem;
  font-weight: 600;
  color: var(--text-color);
}

.dashboard-count {
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--text-muted);
  background: white;
  border: 1px solid var(--border-color);
  padding: 0.125rem 0.5rem;
  border-radius: 999px;
}

/* Document Cards Grid */
.documents-grid {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.document-card {
  display: flex;
  align-items: center;
  gap: 1rem;
  background: white;
  padding: 1rem 1.25rem;
  border-radius: 12px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.04), 0 1px 2px rgba(0, 0, 0, 0.06);
  border: 1px solid rgba(0, 0, 0, 0.05);
  transition: all 0.15s ease;
  text-decoration: none;
  color: inherit;
}

.document-card:hover {
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08), 0 2px 4px rgba(0, 0, 0, 0.04);
  border-color: rgba(0, 0, 0, 0.08);
  transform: translateY(-1px);
  text-decoration: none;
}

.document-card-icon {
  flex-shrink: 0;
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #eff6ff 0%, #dbeafe 100%);
  border-radius: 10px;
  color: var(--primary-color);
}

.document-card-icon svg {
  width: 22px;
  height: 22px;
}

.document-card-body {
  flex: 1;
  min-width: 0;
}

.document-card-title {
  margin: 0 0 0.25rem;
  font-size: 1rem;
  font-weight: 500;
  color: var(--text-color);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.document-card-meta {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  font-size: 0.8125rem;
  color: var(--text-muted);
}

.document-type-badge {
  background: #f1f5f9;
  color: #475569;
  padding: 0.125rem 0.5rem;
  border-radius: 4px;
  font-size: 0.75rem;
  font-weight: 500;
}

.document-updated {
  color: var(--text-muted);
}

.document-card-arrow {
  flex-shrink: 0;
  color: #cbd5e1;
  transition: color 0.15s, transform 0.15s;
}

.document-card-arrow svg {
  width: 20px;
  height: 20px;
}

.document-card:hover .document-card-arrow {
  color: var(--text-muted);
  transform: translateX(2px);
}

/* Empty State */
.empty-state {
  text-align: center;
  padding: 4rem 2rem;
  background: white;
  border-radius: 16px;
  border: 2px dashed var(--border-color);
}

.empty-state-icon {
  width: 64px;
  height: 64px;
  margin: 0 auto 1.5rem;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #f1f5f9 0%, #e2e8f0 100%);
  border-radius: 16px;
  color: var(--text-muted);
}

.empty-state-icon svg {
  width: 32px;
  height: 32px;
}

.empty-state-title {
  margin: 0 0 0.5rem;
  font-size: 1.25rem;
  font-weight: 600;
  color: var(--text-color);
}

.empty-state-description {
  margin: 0 0 1.5rem;
  color: var(--text-muted);
  font-size: 0.9375rem;
}

.btn-large {
  padding: 0.75rem 1.5rem;
  font-size: 1rem;
}

/* Mobile Dashboard */
@media (max-width: 768px) {
  .dashboard-header {
    padding: 1rem;
  }

  .dashboard-brand-name {
    font-size: 1.125rem;
  }

  .dashboard-logo {
    width: 24px;
    height: 24px;
  }

  .btn-label {
    display: none;
  }

  .dashboard-actions .btn-primary {
    width: 40px;
    height: 40px;
    padding: 0;
    justify-content: center;
  }

  .dashboard-actions .btn-primary .btn-icon {
    width: 20px;
    height: 20px;
    margin: 0;
  }

  .dashboard-content {
    padding: 1.5rem 1rem 2rem;
  }

  .dashboard-title {
    font-size: 1.5rem;
  }

  .document-card {
    padding: 0.875rem 1rem;
    gap: 0.75rem;
    border-radius: 10px;
  }

  .document-card-icon {
    width: 36px;
    height: 36px;
    border-radius: 8px;
  }

  .document-card-icon svg {
    width: 18px;
    height: 18px;
  }

  .document-card-title {
    font-size: 0.9375rem;
  }

  .document-card-meta {
    flex-direction: column;
    align-items: flex-start;
    gap: 0.25rem;
  }

  .document-card-arrow {
    display: none;
  }

  .empty-state {
    padding: 3rem 1.5rem;
  }

  .empty-state-icon {
    width: 56px;
    height: 56px;
  }

  .empty-state-icon svg {
    width: 28px;
    height: 28px;
  }

  .empty-state-title {
    font-size: 1.125rem;
  }

  .btn-large {
    width: 100%;
    justify-content: center;
  }
}

/* Chat Input Area */
.chat-input {
  padding: 1rem;
  border-top: 1px solid var(--border-color);
}

.chat-input textarea {
  margin-bottom: 0.5rem;
  resize: none;
}

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

.chat-header h3 {
  margin: 0;
  padding: 0;
  border: none;
}

.chat-header button {
  padding: 0.25rem 0.5rem;
  font-size: 0.875rem;
}

/* Research Form */
.research-form {
  background: white;
  padding: 1rem;
  border-radius: 4px;
  margin-top: 0.5rem;
}

.research-form .form-group {
  margin-bottom: 0.75rem;
}

.research-form input,
.research-form select {
  padding: 0.375rem 0.5rem;
  font-size: 0.875rem;
}

.research-form .form-actions {
  display: flex;
  gap: 0.5rem;
  margin-top: 1rem;
}

.research-form .form-actions button {
  flex: 1;
  padding: 0.375rem;
  font-size: 0.875rem;
}

.research-item-delete {
  font-size: 0.75rem;
  padding: 0.25rem 0.5rem;
  background: transparent;
  border: 1px solid var(--danger-color);
  color: var(--danger-color);
}

.research-item-delete:hover {
  background: var(--danger-color);
  color: white;
}

/* Message Styling */
.message strong {
  display: block;
  font-size: 0.75rem;
  margin-bottom: 0.25rem;
  opacity: 0.7;
}

.message-content {
  white-space: pre-wrap;
}

.message-content p {
  margin: 0;
}

.message-actions {
  display: flex;
  gap: 0.25rem;
  margin-top: 0.5rem;
  opacity: 0;
  transition: opacity 0.15s;
}

.message:hover .message-actions {
  opacity: 1;
}

.message-actions .action-btn {
  padding: 0.125rem 0.375rem;
  font-size: 0.875rem;
  background: transparent;
  border: 1px solid var(--border-color);
  border-radius: 3px;
  color: var(--text-muted);
  cursor: pointer;
  line-height: 1;
}

.message-actions .action-btn:hover {
  background: var(--light-bg);
  color: var(--text-color);
  border-color: var(--secondary-color);
}

/* Settings Page */
.settings-container {
  max-width: 600px;
}

/* Document Types List */
.document-types-list {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.document-type-card {
  background: var(--light-bg);
  border: 1px solid var(--border-color);
  border-radius: 6px;
  padding: 1rem;
}

.document-type-header {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 0.5rem;
}

.document-type-header h3 {
  margin: 0;
  font-size: 1rem;
}

.slug-badge {
  font-size: 0.75rem;
  font-family: monospace;
  background: var(--border-color);
  padding: 0.125rem 0.5rem;
  border-radius: 3px;
  color: var(--text-muted);
}

.instructions-preview {
  font-size: 0.875rem;
  color: var(--text-muted);
  margin: 0 0 0.75rem 0;
  line-height: 1.4;
}

.instructions-preview.empty {
  font-style: italic;
}

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

.btn-small {
  padding: 0.25rem 0.75rem;
  font-size: 0.875rem;
}

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

.btn-secondary:hover {
  background: #5a6268;
  border-color: #5a6268;
}

/* Empty State */
.empty-state {
  text-align: center;
  padding: 3rem;
  color: var(--text-muted);
}

/* Edit Notification (AI edits in chat) */
.edit-notification {
  background: #f0f7ff;
  border: 1px solid #b8daff;
  border-radius: 4px;
  padding: 0.75rem;
}

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

.edit-icon {
  font-size: 1rem;
}

.edit-description {
  flex: 1;
  font-weight: 500;
}

.expand-btn {
  padding: 0.25rem 0.5rem;
  font-size: 0.75rem;
  background: white;
}

.edit-diff {
  margin-top: 0.75rem;
  background: white;
  border: 1px solid var(--border-color);
  border-radius: 4px;
  padding: 0.5rem;
  overflow-x: auto;
  font-family: monospace;
  font-size: 0.875rem;
}

/* Inline diff styles */
.inline-diff {
  line-height: 1.6;
  white-space: pre-wrap;
  word-wrap: break-word;
}
.diff-removed {
  background: #ffecec;
  color: #a00;
  text-decoration: line-through;
}
.diff-added {
  background: #eaffea;
  color: #080;
}
