/* styles.css - Classy minimal design with monospace fonts and warm tone */

/* Reset & Base */
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html,
body {
  height: 100%;
  font-family: 'SF Mono', 'Monaco', 'Inconsolata', 'Fira Code', 'Droid Sans Mono', 'Source Code Pro', ui-monospace, monospace;
  font-size: 14px;
  line-height: 1.6;
  background: #f5f1eb;
  color: #3d3d3d;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* Auth Screen */
.auth-screen {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 20px;
  background: linear-gradient(135deg, #f5f1eb 0%, #eae4db 100%);
}

.auth-card {
  text-align: center;
  width: 100%;
  max-width: 380px;
  padding: 48px 32px;
  background: #fefdfb;
  border: 1px solid #e8ddd2;
  border-radius: 12px;
  box-shadow: 0 8px 32px rgba(139, 90, 43, 0.08);
}

.auth-card h1 {
  font-size: 32px;
  font-weight: 600;
  letter-spacing: -0.5px;
  margin-bottom: 8px;
  color: #3d3d3d;
}

.auth-card p {
  color: #8b7355;
  margin-bottom: 32px;
  font-size: 15px;
}

.auth-form {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.auth-form input {
  width: 100%;
  padding: 12px 16px;
  background: #faf8f5;
  color: #3d3d3d;
  border: 1px solid #e0d5ca;
  border-radius: 6px;
  font-family: inherit;
  font-size: 14px;
}

.auth-form input:focus {
  outline: none;
  border-color: #c9a871;
  background: #fcfaf7;
}

.code-sent-msg {
  color: #4ade80;
  font-size: 13px;
  margin: 0 0 8px 0;
}

.btn-secondary {
  background: transparent;
  color: #8b7355;
  border: 1px solid #e0d5ca;
  padding: 10px 20px;
  font-size: 13px;
}

.btn-secondary:hover {
  background: #faf8f5;
  color: #3d3d3d;
}

/* Caution Box */
.caution-box {
  background: white;
  border: 1px solid rgba(139, 115, 85, 0.2);
  border-radius: 8px;
  padding: 12px 16px;
  margin-bottom: 16px;
  text-align: center;
  max-width: 380px;
  width: 100%;
}

.caution-title {
  font-size: 16px;
  font-weight: 600;
  color: #000000;
  margin-bottom: 8px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.caution-text {
  font-size: 12px;
  line-height: 1.5;
  color: #000000;
  margin: 0;
}

.caution-text strong {
  color: #3d3d3d;
}

.caution-text:last-child {
  margin-bottom: 0;
}

/* Buttons */
button {
  font-family: inherit;
  font-size: 13px;
  padding: 8px 16px;
  background: #eae4db;
  color: #3d3d3d;
  border: 1px solid #d9cdc2;
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.15s ease;
}

button:hover {
  background: #ddd1c6;
  border-color: #c9a871;
}

button:active {
  transform: translateY(1px);
}

.btn-primary {
  background: #8b7355;
  color: #ffffff;
  border: none;
  padding: 12px 24px;
  font-size: 14px;
  font-weight: 500;
}

.btn-primary:hover {
  background: #6f5a47;
}

.btn-logout {
  background: transparent;
  border: 1px solid #d9cdc2;
  padding: 6px 12px;
  font-size: 12px;
  color: #8b7355;
}

/* App Layout */
.app {
  display: flex;
  flex-direction: column;
  height: 100vh;
}

/* Top Bar */
.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 16px;
  background: #fefdfb;
  border-bottom: 1px solid #e8ddd2;
  flex-shrink: 0;
}

.logo {
  font-size: 16px;
  font-weight: 600;
  color: #3d3d3d;
  letter-spacing: -0.5px;
}

.actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

/* Save Indicator */
.save-indicator {
  font-size: 12px;
  padding: 4px 10px;
  border-radius: 4px;
  font-weight: 500;
  transition: all 0.2s ease;
  white-space: nowrap;
}

.save-indicator.saving {
  color: #8b7355;
  background: #f5f1eb;
  animation: pulse 1.5s ease-in-out infinite;
}

.save-indicator.saved {
  color: #4ade80;
  background: rgba(74, 222, 128, 0.1);
}

.save-indicator.offline {
  color: #f59e0b;
  background: rgba(245, 158, 11, 0.1);
}

.save-indicator.error {
  color: #ef4444;
  background: rgba(239, 68, 68, 0.1);
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}

.icon-btn {
  background: transparent;
  border: none;
  font-size: 18px;
  padding: 6px 8px;
  cursor: pointer;
  transition: all 0.15s ease;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #3d3d3d;
}

.icon-btn svg,
.icon-btn i {
  stroke: currentColor;
}

.icon-btn:hover {
  background: #eae4db;
}

/* Profile Menu */
.profile-menu {
  position: relative;
}

.dropdown {
  position: absolute;
  top: 100%;
  right: 0;
  background: #fefdfb;
  border: 1px solid #e8ddd2;
  border-radius: 6px;
  margin-top: 8px;
  z-index: 50;
  display: none;
  flex-direction: column;
  min-width: 140px;
  box-shadow: 0 8px 24px rgba(139, 90, 43, 0.12);
}

.dropdown[aria-hidden="false"] {
  display: flex;
}

.dropdown button {
  padding: 10px 16px;
  background: transparent;
  border: none;
  color: #3d3d3d;
  text-align: left;
  font-family: inherit;
  font-size: 13px;
  cursor: pointer;
  transition: background 0.1s ease;
}

.dropdown button:last-child {
  /* ... existing code ... */
}

.dropdown button:hover {
  background: #f5f1eb;
}

.user-email {
  padding: 10px 16px;
  font-size: 12px;
  color: #8b7355;
  border-bottom: 1px solid #e8ddd2;
  word-break: break-all;
  font-weight: 500;
}

/* Container */
.container {
  display: flex;
  flex-direction: column;
  gap: 0;
  padding: 0;
  flex: 1;
  overflow: hidden;
  align-items: center;
}

/* Centered content wrapper */
.content {
  width: 100%;
  max-width: 860px;
  padding: 32px 20px 0 20px;
  display: flex;
  flex-direction: column;
  flex: 1;
  overflow: hidden;
}

/* Editor */
#editor {
  flex: 1;
  width: 100%;
  resize: none;
  background: #fffbf7;
  color: #3d3d3d;
  border: none;
  border-radius: 12px;
  padding: 24px;
  font-family: inherit;
  font-size: 14px;
  line-height: 1.8;
  letter-spacing: 0.2px;
  overflow-y: auto;
}

#editor:focus {
  outline: none;
}

#editor::placeholder {
  color: #c9a871;
}

/* Search Results */
.search-results {
  max-height: 30vh;
  overflow-y: auto;
  background: #fffbf7;
  border-top: 1px solid #e8ddd2;
}

.search-results:empty {
  display: none;
}

.search-results .result {
  padding: 10px 24px;
  border-bottom: 1px solid #f0e9e0;
  cursor: pointer;
  transition: background 0.1s ease;
  font-size: 13px;
}

.search-results .result:hover {
  background: #f5f1eb;
}

.search-results .line-num {
  color: #999;
  margin-right: 12px;
  font-size: 12px;
}

.search-results .no-results {
  padding: 16px 24px;
  color: #999;
  text-align: center;
}

/* Search modal input */
#search-input {
  width: 100%;
  padding: 10px 12px;
  background: #faf8f5;
  color: #3d3d3d;
  border: 1px solid #e0d5ca;
  border-radius: 6px;
  font-family: inherit;
  font-size: 13px;
  margin-bottom: 12px;
}

#search-input:focus {
  outline: none;
  border-color: #c9a871;
  background: #fcfaf7;
}

.modal {
  position: fixed;
  inset: 0;
  background: rgba(139, 90, 43, 0.3);
  backdrop-filter: blur(4px);
  display: none;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 100;
}

.modal[aria-hidden="false"] {
  display: flex;
}

.modal-content {
  position: relative;
  width: 100%;
  max-width: 600px;
  max-height: 80vh;
  background: #fefdfb;
  border: 1px solid #e8ddd2;
  border-radius: 12px;
  padding: 24px;
  overflow-y: auto;
  box-shadow: 0 16px 64px rgba(139, 90, 43, 0.15);
}

.modal-content h2 {
  font-size: 18px;
  font-weight: 600;
  margin-bottom: 20px;
  color: #3d3d3d;
}

/* Mobile-friendly Close Icon (44x44) */
.modal-close {
  position: absolute;
  top: 12px;
  right: 12px;
  width: 44px;
  height: 44px;
  font-size: 24px;
  line-height: 44px;
  text-align: center;
  background: transparent;
  color: #8b7355;
  border: none;
  cursor: pointer;
  border-radius: 6px;
}

.modal-close:hover {
  background: #f5f1eb;
  color: #3d3d3d;
}

/* Snapshot list */
.snapshot-list {
  list-style: none;
}

.snapshot-list li {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 0;
  border-bottom: 1px solid #e8ddd2;
}

.snapshot-list li:last-child {
  border-bottom: none;
}

.snapshot-list .time {
  color: #8b7355;
  font-size: 13px;
}

.snapshot-list .actions {
  display: flex;
  gap: 8px;
}

.snapshot-list button {
  font-size: 12px;
  padding: 6px 8px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.snapshot-group-header {
  padding: 12px 0 8px 0 !important;
  font-weight: 600;
  color: #3d3d3d;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  border-bottom: none !important;
  margin-top: 8px;
}

.snapshot-group-header:first-child {
  margin-top: 0;
}

.pin-btn {
  background: #f0e9e0;
  color: #8b7355;
  border: 1px solid #d9cdc2;
}

.pin-btn:hover {
  background: #e8ddd2;
  border-color: #c9a871;
}

.pin-btn.pinned {
  background: #c9a871;
  color: #ffffff;
  border: 1px solid #b8954a;
}

.pin-btn.pinned:hover {
  background: #b8954a;
  border-color: #a0823f;
}

/* Mobile Responsive */
@media (max-width: 640px) {
  .topbar {
    flex-wrap: wrap;
    gap: 8px;
    padding: 12px;
  }

  .topbar .left {
    order: 1;
    flex: 1;
  }

  .topbar .right {
    order: 2;
    width: 100%;
    justify-content: space-between;
  }

  .topbar input[type="search"] {
    flex: 1;
  }

  .content {
    padding: 0;
    max-width: 100%;
  }

  #editor {
    font-size: 16px;
    padding: 20px;
    border-radius: 0;
    background: #f5f1eb; /* Match body background for seamless look */
    
    /* Hide scrollbar */
    -ms-overflow-style: none;
    scrollbar-width: none;
  }
  
  #editor::-webkit-scrollbar {
    display: none;
  }

  .auth-card {
    padding: 40px 24px;
    border: none;
    box-shadow: none;
    background: transparent;
  }
}

/* Scrollbar */
::-webkit-scrollbar {
  width: 10px;
  height: 10px;
}

::-webkit-scrollbar-track {
  background: #f5f1eb;
}

::-webkit-scrollbar-thumb {
  background: #d9cdc2;
  border-radius: 5px;
}

::-webkit-scrollbar-thumb:hover {
  background: #c9a871;
}

/* Text Format Modal Styles */
.format-section {
  margin-bottom: 20px;
}

.format-section label {
  display: block;
  margin-bottom: 8px;
  color: #3d3d3d;
  font-size: 13px;
  font-weight: 500;
}

.font-size-controls {
  display: flex;
  align-items: center;
  gap: 12px;
  justify-content: center;
}

.size-btn {
  width: 40px;
  height: 40px;
  font-size: 18px;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #eae4db;
  border: 1px solid #d9cdc2;
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.15s ease;
}

.size-btn:hover {
  background: #ddd1c6;
  border-color: #c9a871;
}

#font-size-display {
  min-width: 50px;
  text-align: center;
  font-weight: 600;
  color: #3d3d3d;
}

#font-family-select {
  width: 100%;
  padding: 10px 12px;
  background: #faf8f5;
  color: #3d3d3d;
  border: 1px solid #e0d5ca;
  border-radius: 6px;
  font-family: inherit;
  font-size: 13px;
  cursor: pointer;
}

#font-family-select:focus {
  outline: none;
  border-color: #c9a871;
  background: #fcfaf7;
}

.format-actions {
  display: flex;
  gap: 12px;
  margin-top: 24px;
}

.format-actions button {
  flex: 1;
}

/* Snippets Modal Styles */
.snippets-container {
  width: 100%;
}

.snippets-actions {
  margin-bottom: 16px;
}

.snippet-list {
  list-style: none;
}

.snippet-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 0;
  border-bottom: 1px solid #e8ddd2;
}

.snippet-item:last-child {
  border-bottom: none;
}

.snippet-name {
  color: #3d3d3d;
  font-size: 14px;
  font-weight: 500;
  font-family: 'SF Mono', 'Monaco', 'Inconsolata', 'Fira Code', monospace;
}

.snippet-list .empty-msg {
  color: #8b7355;
  font-size: 13px;
  display: block;
  padding: 16px 0;
  text-align: center;
}

.snippet-list .actions {
  display: flex;
  gap: 8px;
}

.snippet-list button {
  font-size: 12px;
  padding: 6px 12px;
}

/* Snippet Form */
.form-group {
  margin-bottom: 16px;
}

.form-group label {
  display: block;
  margin-bottom: 8px;
  color: #3d3d3d;
  font-size: 13px;
  font-weight: 500;
}

.form-group input,
.form-group textarea {
  width: 100%;
  padding: 10px 12px;
  background: #faf8f5;
  color: #3d3d3d;
  border: 1px solid #e0d5ca;
  border-radius: 6px;
  font-family: inherit;
  font-size: 13px;
}

.form-group input:focus,
.form-group textarea:focus {
  outline: none;
  border-color: #c9a871;
  background: #fcfaf7;
}

.form-group textarea {
  resize: vertical;
  min-height: 120px;
  font-family: 'SF Mono', 'Monaco', 'Inconsolata', 'Fira Code', monospace;
}

.form-actions {
  display: flex;
  gap: 12px;
  margin-top: 20px;
}

.form-actions button {
  flex: 1;
}

/* AI Chat Modal Styles */
.ai-chat-content {
  max-width: 700px;
  height: 80vh;
  max-height: 600px;
  display: flex;
  flex-direction: column;
}

.ai-chat-container {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
}

.ai-chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px 0;
  margin-bottom: 16px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.ai-message {
  display: flex;
  gap: 12px;
  animation: fadeIn 0.2s ease;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

.ai-message.user {
  flex-direction: row-reverse;
}

.ai-message-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: #8b7355;
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  font-weight: 600;
  flex-shrink: 0;
}

.ai-message.user .ai-message-avatar {
  background: #c9a871;
}

.ai-message-content {
  background: #faf8f5;
  padding: 12px 16px;
  border-radius: 12px;
  max-width: 70%;
  word-wrap: break-word;
  color: #3d3d3d;
  font-size: 14px;
  line-height: 1.5;
  border: 1px solid #e8ddd2;
}

.ai-message.user .ai-message-content {
  background: #eae4db;
  border-color: #d9cdc2;
}

.ai-message.assistant .ai-message-content {
  background: #fefdfb;
}

.ai-message.loading .ai-message-content {
  font-style: italic;
  color: #8b7355;
}

.ai-message-content strong {
  font-weight: 600;
  color: #3d3d3d;
}

.ai-message-content em {
  font-style: italic;
}

.ai-list-item {
  margin: 6px 0;
  line-height: 1.6;
}

.ai-message-content br + br {
  display: block;
  content: '';
  margin-top: 8px;
}

.ai-chat-input-container {
  display: flex;
  gap: 8px;
  padding-top: 16px;
  border-top: 1px solid #e8ddd2;
}

#ai-chat-input {
  flex: 1;
  padding: 10px 12px;
  background: #faf8f5;
  color: #3d3d3d;
  border: 1px solid #e0d5ca;
  border-radius: 6px;
  font-family: inherit;
  font-size: 14px;
}

#ai-chat-input:focus {
  outline: none;
  border-color: #c9a871;
  background: #fcfaf7;
}

#btn-ai-send {
  padding: 10px 20px;
  white-space: nowrap;
}

.ai-chat-empty {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #8b7355;
  font-size: 14px;
  text-align: center;
  padding: 32px 16px;
}

/* Settings Modal Styles */
.settings-container {
  max-width: 600px;
}

.settings-section {
  margin-bottom: 24px;
}

.settings-section h3 {
  font-size: 16px;
  font-weight: 600;
  color: #3d3d3d;
  margin-bottom: 8px;
}

.settings-description {
  color: #8b7355;
  font-size: 13px;
  margin-bottom: 20px;
}

.api-key-input-group {
  display: flex;
  align-items: center;
  gap: 8px;
}

.api-key-input-group input {
  flex: 1;
}

.api-key-status {
  font-size: 12px;
  color: #4ade80;
  white-space: nowrap;
}

.api-key-status.error {
  color: #ef4444;
}

.form-group small {
  display: block;
  margin-top: 6px;
  color: #8b7355;
  font-size: 12px;
  line-height: 1.4;
}

.form-group small a {
  color: #8b7355;
  text-decoration: underline;
}

.form-group small a:hover {
  color: #6f5a47;
}

.form-group select {
  width: 100%;
  padding: 10px 12px;
  background: #faf8f5;
  color: #3d3d3d;
  border: 1px solid #e0d5ca;
  border-radius: 6px;
  font-family: inherit;
  font-size: 13px;
  cursor: pointer;
}

.form-group select:focus {
  outline: none;
  border-color: #c9a871;
  background: #fcfaf7;
}

.settings-actions {
  display: flex;
  gap: 12px;
  margin-top: 24px;
  padding-top: 24px;
  border-top: 1px solid #e8ddd2;
}

/* AI Actions Modal Styles */
.ai-actions-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
  margin-bottom: 20px;
}

/* Hide dropdown on desktop */
.ai-actions-dropdown {
  display: none;
}

.action-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 20px 16px;
  background: #faf8f5;
  color: #3d3d3d;
  border: 1px solid #e0d5ca;
  border-radius: 12px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s ease;
}

.action-btn:hover {
  background: #f0e9e0;
  border-color: #c9a871;
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(139, 90, 43, 0.1);
}

.action-btn:active {
  transform: translateY(0);
}

.action-btn svg,
.action-btn i {
  flex-shrink: 0;
  color: #8b7355;
  stroke: currentColor;
}

.action-btn span {
  text-align: center;
  line-height: 1.3;
}

.ai-actions-result {
  background: #fefdfb;
  border: 1px solid #e8ddd2;
  border-radius: 12px;
  padding: 20px;
  min-height: 80px;
  max-height: 400px;
  overflow-y: auto;
  font-size: 14px;
  line-height: 1.6;
}

.ai-actions-result:empty {
  display: none;
}

.ai-actions-result .ai-message-content {
  background: transparent;
  border: none;
  padding: 0;
  max-width: 100%;
}

/* Mobile Responsiveness for AI Actions */
@media (max-width: 768px) {
  /* Hide grid on mobile */
  .ai-actions-grid {
    display: none;
  }
  
  /* Show dropdown on mobile */
  .ai-actions-dropdown {
    display: flex;
    flex-direction: column;
    gap: 12px;
    margin-bottom: 20px;
  }
  
  .ai-actions-dropdown label {
    font-size: 13px;
    font-weight: 500;
    color: #3d3d3d;
  }
  
  .ai-actions-dropdown select {
    width: 100%;
    padding: 12px;
    background: #faf8f5;
    color: #3d3d3d;
    border: 1px solid #e0d5ca;
    border-radius: 8px;
    font-family: inherit;
    font-size: 14px;
    cursor: pointer;
  }
  
  .ai-actions-dropdown select:focus {
    outline: none;
    border-color: #c9a871;
    background: #fcfaf7;
  }
  
  .ai-actions-dropdown button {
    width: 100%;
    padding: 12px 24px;
  }
  
  .ai-actions-result {
    max-height: 300px;
  }
}

/* AI Usage Display */
.ai-usage-display {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 16px;
  background: #faf8f5;
  border: 1px solid #e8ddd2;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 500;
  margin-bottom: 16px;
  color: #8b7355;
}

.ai-usage-display svg {
  flex-shrink: 0;
  opacity: 0.8;
}

.ai-usage-display span {
  line-height: 1.4;
}

/* Mobile Responsiveness for AI Chat */
@media (max-width: 768px) {
  .ai-chat-content {
    max-width: 100%;
    height: 90vh;
    max-height: none;
  }
  
  .ai-message-content {
    max-width: 80%;
  }
  
  .settings-container {
    max-width: 100%;
  }
}

/* Line Counter */
.line-counter {
  position: fixed;
  bottom: 20px;
  left: 20px;
  background: rgba(254, 253, 251, 0.95);
  color: #8b7355;
  padding: 8px 16px;
  border-radius: 8px;
  font-size: 12px;
  font-weight: 500;
  border: 1px solid #e8ddd2;
  box-shadow: 0 4px 12px rgba(139, 90, 43, 0.1);
  pointer-events: none;
  z-index: 10;
  backdrop-filter: blur(8px);
  transition: opacity 0.2s ease;
}

.line-counter #line-count {
  font-weight: 600;
  color: #3d3d3d;
}

.line-counter #word-count {
  font-weight: 600;
  color: #3d3d3d;
}

/* Hide line counter on mobile */
@media (max-width: 640px) {
  .line-counter {
    display: none;
  }
}

/* Hide InstantDB badge */
iframe[src*="instantdb"],
iframe[title*="instant"],
[class*="instant-badge"],
[id*="instant-badge"],
div[style*="z-index: 2147483647"] {
  display: none !important;
  visibility: hidden !important;
}
