/* === Root Variables === */
:root {
  --primary-color: #667eea;
  --secondary-color: #764ba2;
  --text-dark: #1a1a1a;
  --text-light: #666;
  --bg-light: #f8f9fa;
  --border-color: #e1e5e9;
  --white: #fff;
  --danger-color: #ef4444;
  --success-color: #22c55e;

  --font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --border-radius-sm: 4px;
  --border-radius-md: 8px;
  --border-radius-lg: 16px;
  --shadow-sm: 0 4px 15px rgba(0, 0, 0, 0.05);
  --shadow-md: 0 8px 32px rgba(0, 0, 0, 0.1);
}

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

body {
  font-family: var(--font-family);
  background: linear-gradient(135deg, var(--primary-color) 0%, var(--secondary-color) 100%);
  min-height: 100vh;
  overflow: hidden;
  color: var(--text-dark);
}

/* === TinyMCE Dialog Z-Index Fix === */
.tox-dialog-wrap {
  z-index: 2002 !important;
}

.tox-tinymce-aux {
  z-index: 2003 !important;
}

.tox-dialog__backdrop {
  z-index: 2001 !important;
}

/* === App Layout === */
.app-container {
  position: relative;
  width: 100vw;
  height: 100vh;
}

#map {
  width: 100%;
  height: 100%;
  z-index: 1;
}

/* === Header === */
.header {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  z-index: 1000;
  background: rgba(255, 255, 255, 0.9);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border-color);
  padding: 0.75rem 1.5rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.logo {
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--text-dark);
}

.auth-buttons {
  display: flex;
  gap: 0.75rem;
}

/* === Buttons === */
.btn {
  padding: 0.5rem 1rem;
  border: none;
  border-radius: var(--border-radius-md);
  font-weight: 500;
  font-size: 0.85rem;
  cursor: pointer;
  transition: all 0.2s ease;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
}

.btn-primary {
  background: linear-gradient(135deg, var(--primary-color) 0%, var(--secondary-color) 100%);
  color: var(--white);
}

.btn-primary:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}

.btn-secondary {
  background: var(--bg-light);
  color: var(--text-dark);
  border: 1px solid var(--border-color);
}

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

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

/* === Modals (General) === */
.auth-modal, .create-note-modal, .note-modal {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.6);
  z-index: 2000;
  display: none;
  align-items: center;
  justify-content: center;
}

.auth-modal.show, .create-note-modal.show, .note-modal.show {
  display: flex;
}

.auth-card, .create-note-card, .note-modal-content {
  background: var(--white);
  border-radius: var(--border-radius-lg);
  padding: 2rem;
  width: 90%;
  max-width: 450px;
  box-shadow: var(--shadow-md);
  animation: slideUp 0.3s ease;
  position: relative;
}

.close-modal, .create-note-close, .note-modal-close {
  position: absolute;
  top: 0.75rem;
  right: 0.75rem;
  background: none;
  border: none;
  font-size: 1.5rem;
  color: var(--text-light);
  cursor: pointer;
  padding: 0.25rem;
  border-radius: 50%;
  transition: all 0.2s ease;
}

.close-modal:hover, .create-note-close:hover, .note-modal-close:hover {
  background: var(--bg-light);
  color: var(--text-dark);
}

@keyframes slideUp {
  from { opacity: 0; transform: translateY(20px); }
  to { opacity: 1; transform: translateY(0); }
}

/* === Auth & Create Note Modals === */
.auth-header, .create-note-header {
  text-align: center;
  margin-bottom: 1.5rem;
}

/* === TinyMCE Integration === */
.create-note-card {
  max-width: 700px;
  width: 95%;
}

.tox-tinymce {
  border-radius: var(--border-radius-md) !important;
}

.tox .tox-toolbar {
  background: var(--bg-light) !important;
  border-bottom: 1px solid var(--border-color) !important;
}

.tox .tox-edit-area {
  background: var(--white) !important;
}

.tox .tox-statusbar {
  display: none !important;
}

.auth-header h2, .create-note-header h2 {
  font-size: 1.5rem;
  margin-bottom: 0.25rem;
}

.auth-header p, .create-note-header p {
  color: var(--text-light);
  font-size: 0.9rem;
}

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

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

.form-group input, .form-field input,
.form-group textarea, .form-field textarea {
  width: 100%;
  padding: 0.6rem 0.8rem;
  border: 1px solid var(--border-color);
  border-radius: var(--border-radius-md);
  font-size: 0.9rem;
  transition: all 0.2s ease;
  background: var(--bg-light);
  font-family: inherit;
}

.form-group input:focus, .form-field input:focus,
.form-group textarea:focus, .form-field textarea:focus {
  outline: none;
  border-color: var(--primary-color);
  background: var(--white);
  box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}

.form-field textarea {
  min-height: 120px;
  resize: vertical;
}

.auth-actions, .create-note-actions {
  display: flex;
  gap: 1rem;
  margin-top: 1.5rem;
}

.auth-actions .btn, .create-note-actions .btn {
  flex: 1;
}

/* === Note Viewing Modal === */
.note-modal-content {
  padding: 1.5rem;
  max-height: 85vh;
  overflow-y: auto;
}

.note-modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1rem;
  padding-bottom: 0.75rem;
  border-bottom: 1px solid var(--border-color);
}

.note-modal-header h3 {
  font-size: 1.1rem;
  font-weight: 600;
}

.note-modal-author {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--primary-color);
  margin-bottom: 0.5rem;
}

.note-modal-body {
  font-size: 0.9rem;
  line-height: 1.6;
  white-space: pre-wrap;
  word-wrap: break-word;
}

/* === COMPACT REPLY STYLES === */
.replies-section {
  margin-top: 1rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border-color);
}

.replies-header {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-light);
  margin-bottom: 0.75rem;
}

.replies-list {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.reply-item {
  background: var(--bg-light);
  border-radius: var(--border-radius-sm);
  padding: 0.35rem 0.6rem;
  border-left: 3px solid var(--primary-color);
}

.reply-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.25rem;
}

.reply-author {
  font-size: 0.7rem;
  font-weight: 600;
  color: var(--primary-color);
}

.reply-text {
  font-size: 0.8rem;
  line-height: 1.4;
  word-wrap: break-word;
}

.reply-to-reply-btn {
  background: none;
  border: none;
  color: var(--text-light);
  font-size: 0.7rem;
  cursor: pointer;
  padding: 0.1rem 0.3rem;
  border-radius: var(--border-radius-sm);
}

.reply-to-reply-btn:hover {
  background: #e0e0e0;
}

/* Thread Indentation */
.reply-indent-1 { margin-left: 1rem; border-left-color: #a7b5f4; }
.reply-indent-2 { margin-left: 2rem; border-left-color: #c4d0f7; }
.reply-indent-3 { margin-left: 3rem; border-left-color: #e2e8f0; }

/* === COMPACT REPLY FORM === */
.reply-form-section {
  margin-top: 1rem;
}

.reply-form {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.reply-form.nested {
  margin-top: 0.5rem;
  padding: 0.5rem;
  background: #f0f2f5;
  border-radius: var(--border-radius-md);
}

.reply-form textarea {
  width: 100%;
  padding: 0.4rem;
  font-size: 0.75rem;
  border: 1px solid var(--border-color);
  border-radius: var(--border-radius-sm);
  resize: vertical;
  min-height: 32px; /* Compact height */
  font-family: inherit;
  transition: all 0.2s ease;
}

.reply-form textarea:focus {
  outline: none;
  border-color: var(--primary-color);
  box-shadow: 0 0 0 2px rgba(102, 126, 234, 0.1);
}

.reply-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.4rem;
}

.reply-actions .btn {
  font-size: 0.7rem;
  padding: 0.25rem 0.6rem;
}

/* === Instructions Panel === */
.instructions {
  position: absolute;
  bottom: 1.5rem;
  left: 1.5rem;
  background: rgba(255, 255, 255, 0.95);
  backdrop-filter: blur(8px);
  border-radius: var(--border-radius-md);
  padding: 1rem;
  max-width: 280px;
  box-shadow: var(--shadow-md);
  z-index: 1000;
  transition: all 0.3s ease;
}

.instructions.hidden {
  transform: translateX(-120%);
  opacity: 0;
}

.instructions h3 {
  font-size: 0.9rem;
  margin-bottom: 0.5rem;
}

.instructions p {
  font-size: 0.8rem;
  color: var(--text-light);
  line-height: 1.4;
}

/* === Email Verification Styles === */
.verification-hint {
  display: block;
  font-size: 0.75rem;
  color: var(--text-light);
  margin-top: 0.25rem;
  font-style: italic;
}

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

.btn-success:hover {
  background: #16a34a;
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}

/* === Helper Classes === */
.message {
  position: fixed;
  top: 1.5rem;
  right: 1.5rem;
  padding: 0.75rem 1.25rem;
  border-radius: var(--border-radius-md);
  color: var(--white);
  font-weight: 500;
  z-index: 3000;
  animation: slideIn 0.3s ease;
}

.message.success { background: var(--success-color); }
.message.error { background: var(--danger-color); }

@keyframes slideIn {
  from { opacity: 0; transform: translateX(100%); }
  to { opacity: 1; transform: translateX(0); }
}

/* === Responsive Design === */
@media (max-width: 768px) {
  .header { padding: 0.75rem 1rem; }
  .logo { font-size: 1.1rem; }
  .instructions { display: none; } /* Hide on mobile for simplicity */
  .auth-card, .create-note-card, .note-modal-content { padding: 1.5rem; }
  .reply-form textarea { font-size: 16px; } /* Prevents iOS zoom */
}
