:root {
  color-scheme: light;
  font-family: Inter, system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: #f7f8fb;
  color: #1f2937;
  --sidebar-width: 280px;
  --primary-color: #2563eb;
  --border-color: #e2e8f0;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* Auth Pages (Login/Register) */
.auth-shell {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 2rem;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
}

.auth-shell h1 {
  font-size: 2.5rem;
  color: white;
  margin: 0 0 2rem;
  text-align: center;
}

.auth-form {
  background: white;
  border-radius: 1rem;
  padding: 2.5rem;
  width: 100%;
  max-width: 400px;
  box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1);
}

.auth-form label {
  display: flex;
  flex-direction: column;
  margin-bottom: 1.5rem;
  gap: 0.5rem;
  font-weight: 600;
  color: #1f2937;
}

.auth-form label:last-of-type {
  margin-bottom: 2rem;
}

.auth-form input {
  padding: 0.75rem;
  border: 1px solid var(--border-color);
  border-radius: 0.5rem;
  font-size: 0.95rem;
  font-family: inherit;
  transition: border-color 0.2s;
}

.auth-form input:focus {
  outline: none;
  border-color: #667eea;
  box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}

.auth-form button {
  width: 100%;
  padding: 0.75rem;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
  border: none;
  border-radius: 0.5rem;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.2s, box-shadow 0.2s;
}

.auth-form button:hover {
  transform: translateY(-2px);
  box-shadow: 0 10px 15px -3px rgba(102, 126, 234, 0.3);
}

.auth-shell > p {
  color: white;
  margin-top: 1.5rem;
  font-size: 0.95rem;
}

.auth-shell > p a {
  color: #fff;
  font-weight: 600;
  text-decoration: none;
}

.auth-shell > p a:hover {
  text-decoration: underline;
}

.app-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1rem 1.5rem;
  background: #0f172a;
  color: #fff;
  gap: 1rem;
  border-bottom: 1px solid #1e293b;
  flex-shrink: 0;
}

.brand a {
  color: #f8fafc;
  text-decoration: none;
  font-size: 1.25rem;
  font-weight: 700;
}

nav {
  display: flex;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
}

nav a,
.link-button {
  color: #e2e8f0;
  text-decoration: none;
  border: none;
  background: transparent;
  cursor: pointer;
  font: inherit;
  padding: 0.5rem 1rem;
  border-radius: 0.5rem;
  transition: background 0.2s;
}

nav a:hover,
.link-button:hover {
  background: rgba(255, 255, 255, 0.1);
}

.inline-form {
  display: inline;
}

.app-container {
  display: flex;
  flex: 1;
  overflow: hidden;
}

/* Sidebar */
.sidebar {
  width: var(--sidebar-width);
  background: #f5f5f7;
  border-right: 1px solid var(--border-color);
  overflow-y: auto;
  flex-shrink: 0;
  padding: 1rem 0;
}

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

.sidebar-header h2 {
  margin: 0;
  font-size: 0.95rem;
  text-transform: uppercase;
  color: #64748b;
  font-weight: 600;
  letter-spacing: 0.5px;
}

.add-folder-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--primary-color);
  color: white;
  text-decoration: none;
  font-weight: bold;
  cursor: pointer;
  transition: background 0.2s;
}

.add-folder-btn:hover {
  background: #1d4ed8;
}

.folder-nav {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  padding: 0.5rem 0.5rem;
}

/* A-Z alphabetical index (sidebar) */
.az-index {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 0.15rem;
  padding: 0.5rem 0.75rem;
}

.az-item {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  width: 100%;
  gap: 0.65rem;
  padding: 0.55rem 0.75rem;
  color: #1f2937;
  text-decoration: none;
  text-align: left;
  border-radius: 0.6rem;
  font-size: 0.95rem;
  font-weight: 500;
  transition: background 0.15s;
  box-sizing: border-box;
}

.az-item:hover {
  background: rgba(37, 99, 235, 0.08);
}

.az-item:active {
  background: rgba(37, 99, 235, 0.15);
}

.az-icon {
  font-size: 1rem;
  flex-shrink: 0;
}

.az-title {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.az-empty {
  padding: 0.75rem 1rem;
  color: #94a3b8;
  font-size: 0.9rem;
}

.folder-item-wrapper {
  display: flex;
  align-items: center;
  gap: 0.25rem;
  padding: 0.5rem;
  border-radius: 0.5rem;
  transition: background 0.2s;
}

.folder-item-wrapper:hover {
  background: #f1f5f9;
}

.folder-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem 1rem;
  color: #475569;
  text-decoration: none;
  border-radius: 0.5rem;
  transition: all 0.2s;
  font-size: 0.95rem;
}

.folder-item:hover {
  background: #f1f5f9;
  color: #1f2937;
}

.folder-item.active {
  background: #eff6ff;
  color: var(--primary-color);
  font-weight: 600;
  border-left: 3px solid var(--primary-color);
  padding-left: calc(1rem - 3px);
}

.folder-icon {
  font-size: 1.2rem;
  flex-shrink: 0;
}

.folder-name {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.file-count {
  font-size: 0.85rem;
  background: #e2e8f0;
  color: #64748b;
  padding: 0.2rem 0.5rem;
  border-radius: 999px;
  flex-shrink: 0;
}

.folder-item.active .file-count {
  background: var(--primary-color);
  color: white;
}

/* Content Area */
.content {
  flex: 1;
  overflow-y: auto;
  padding: 2rem;
}

.content-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 2rem;
  gap: 1rem;
}

.content-header h1 {
  margin: 0;
  font-size: 2rem;
  color: #1f2937;
}

.content > h1 {
  margin: 0 0 2rem;
  font-size: 2rem;
  color: #1f2937;
}

/* Search Bar */
.search-bar {
  margin-bottom: 2rem;
}

.search-form {
  display: flex;
  gap: 0.75rem;
  align-items: center;
}

.search-form input {
  flex: 1;
  max-width: 500px;
  padding: 0.75rem 1rem;
  border: 1px solid var(--border-color);
  border-radius: 0.5rem;
  font-size: 0.95rem;
  font-family: inherit;
  transition: border-color 0.2s, box-shadow 0.2s;
}

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

.btn-search,
.btn-clear {
  padding: 0.75rem 1.25rem;
  border-radius: 0.5rem;
  border: none;
  cursor: pointer;
  font-size: 0.95rem;
  font-weight: 500;
  transition: all 0.2s;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
}

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

.btn-search:hover {
  background: #1d4ed8;
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(37, 99, 235, 0.3);
}

.btn-clear {
  background: #f1f5f9;
  color: #64748b;
}

.btn-clear:hover {
  background: #e2e8f0;
}

.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.75rem 1.25rem;
  border-radius: 0.5rem;
  border: none;
  cursor: pointer;
  font-size: 0.95rem;
  font-weight: 500;
  transition: all 0.2s;
  text-decoration: none;
}

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

.btn-primary:hover {
  background: #1d4ed8;
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(37, 99, 235, 0.3);
}

.flash {
  padding: 1rem;
  border-radius: 0.75rem;
  background: #d1fae5;
  color: #065f46;
  margin-bottom: 1.5rem;
  border-left: 4px solid #10b981;
}

.auth-shell .flash {
  width: 100%;
  max-width: 400px;
  background: #fee2e2;
  color: #991b1b;
  border-left-color: #ef4444;
  margin-bottom: 1.5rem;
}

.empty-state {
  padding: 4rem 2rem;
  text-align: center;
  background: #f8fafc;
  border-radius: 1rem;
  border: 2px dashed var(--border-color);
}

.empty-icon {
  font-size: 3rem;
  margin-bottom: 1rem;
}

.empty-state p {
  font-size: 1.1rem;
  color: #64748b;
  margin: 0 0 1.5rem;
}

.notes-list {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.note-item {
  background: white;
  border: 1px solid var(--border-color);
  border-radius: 0.75rem;
  padding: 1.5rem;
  transition: all 0.2s;
  hover-effect: shadow;
}

.note-item:hover {
  border-color: var(--primary-color);
  box-shadow: 0 4px 12px rgba(37, 99, 235, 0.1);
  transform: translateY(-1px);
}

.note-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1rem;
  margin-bottom: 0.75rem;
}

.note-header h3 {
  margin: 0;
  font-size: 1.15rem;
  color: #1f2937;
}

.note-header h3 a {
  color: var(--primary-color);
  text-decoration: none;
}

.note-header h3 a:hover {
  text-decoration: underline;
}

.note-actions {
  display: flex;
  gap: 0.5rem;
  flex-shrink: 0;
}

.btn-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: 0.5rem;
  background: #f1f5f9;
  border: none;
  cursor: pointer;
  font-size: 1rem;
  transition: all 0.2s;
  text-decoration: none;
}

.btn-icon:hover {
  background: #e2e8f0;
  transform: scale(1.1);
}

.note-folder {
  display: inline-block;
  padding: 0.3rem 0.65rem;
  background: #e0f2fe;
  color: #0c4a6e;
  border-radius: 999px;
  font-size: 0.85rem;
  margin: 0 0 0.75rem;
}

.note-preview {
  color: #64748b;
  margin: 0.75rem 0;
  line-height: 1.5;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.note-date {
  margin: 0;
  font-size: 0.85rem;
  color: #94a3b8;
}

/* Scrollbars */
::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: #cbd5e1;
  border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
  background: #94a3b8;
}

/* Responsive */
@media (max-width: 768px) {
  .app-container {
    flex-direction: column;
  }

  .sidebar {
    width: 100%;
    border-right: none;
    border-bottom: 1px solid var(--border-color);
    max-height: 200px;
  }

  .folder-nav {
    flex-direction: row;
    overflow-x: auto;
    padding: 0.5rem;
  }

  .folder-item {
    flex-shrink: 0;
  }

  .content {
    padding: 1.5rem;
  }

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

  .content-header h1 {
    font-size: 1.5rem;
  }

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

  .note-header {
    flex-direction: column;
  }

  .note-actions {
    width: 100%;
    justify-content: flex-start;
  }
}

/* Form Styles */
.app-main {
  max-width: 900px;
  margin: 0 auto;
  padding: 2rem;
}

.app-main h1 {
  margin: 0 0 2rem;
  font-size: 2rem;
  color: #1f2937;
}

.note-form,
.folder-form {
  background: white;
  border: 1px solid var(--border-color);
  border-radius: 0.75rem;
  padding: 2rem;
  margin-bottom: 2rem;
  max-width: 700px;
}

.note-form label,
.folder-form label {
  display: flex;
  flex-direction: column;
  margin-bottom: 1.5rem;
  gap: 0.5rem;
}

.note-form label:last-of-type,
.folder-form label:last-of-type {
  margin-bottom: 0;
}

.note-form label > span,
.folder-form label > span {
  font-weight: 600;
  color: #1f2937;
}

.note-form input,
.note-form textarea,
.note-form select,
.folder-form input {
  padding: 0.75rem;
  border: 1px solid var(--border-color);
  border-radius: 0.5rem;
  font-family: inherit;
  font-size: 0.95rem;
  color: #1f2937;
  transition: border-color 0.2s;
}

.note-form input:focus,
.note-form textarea:focus,
.note-form select:focus,
.folder-form input:focus {
  outline: none;
  border-color: var(--primary-color);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

.note-form textarea {
  resize: vertical;
  min-height: 300px;
  font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', monospace;
}

.note-form button,
.folder-form button {
  background: var(--primary-color);
  color: white;
  padding: 0.75rem 1.5rem;
  border: none;
  border-radius: 0.5rem;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s;
  margin-top: 1rem;
}

.note-form button:hover,
.folder-form button:hover {
  background: #1d4ed8;
}

.content > p {
  margin-top: 1rem;
}

.content > p a {
  color: var(--primary-color);
  text-decoration: none;
}

.content > p a:hover {
  text-decoration: underline;
}

/* Note View Styles */
.note-meta {
  display: flex;
  gap: 2rem;
  padding: 1rem;
  background: #f8fafc;
  border-radius: 0.5rem;
  margin: 1.5rem 0;
  font-size: 0.95rem;
  color: #475569;
  max-width: 700px;
}

.note-content {
  background: #f8fafc;
  border: 1px solid var(--border-color);
  border-radius: 0.5rem;
  padding: 1.5rem;
  margin: 2rem 0;
  font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', monospace;
  font-size: 0.9rem;
  line-height: 1.6;
  color: #1f2937;
  white-space: pre-wrap;
  word-wrap: break-word;
  max-width: 700px;
}

.note-actions {
  display: flex;
  gap: 1rem;
  margin-top: 2rem;
  max-width: 700px;
}

.note-actions a,
.note-actions button {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.75rem 1.25rem;
  border-radius: 0.5rem;
  border: none;
  cursor: pointer;
  font-size: 0.95rem;
  font-weight: 500;
  text-decoration: none;
  transition: all 0.2s;
  background: var(--primary-color);
  color: white;
}

.note-actions a:hover,
.note-actions button:hover {
  background: #1d4ed8;
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(37, 99, 235, 0.3);
}

.note-actions button.danger {
  background: #ef4444;
}

.note-actions button.danger:hover {
  background: #dc2626;
}

/* Folder Delete Button */
.folder-delete-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  border-radius: 0.25rem;
  background: transparent;
  color: #ef4444;
  border: none;
  cursor: pointer;
  font-size: 0.9rem;
  opacity: 0;
  transition: all 0.2s;
  padding: 0;
  flex-shrink: 0;
}

.folder-item-wrapper:hover .folder-delete-btn {
  opacity: 1;
}

.folder-delete-btn:hover {
  background: #fee2e2;
}

/* Responsive form layout */
@media (max-width: 768px) {
  .app-main {
    padding: 1rem;
  }

  .note-form,
  .folder-form {
    padding: 1rem;
  }

  .note-meta {
    flex-direction: column;
    gap: 0.75rem;
  }

  .note-content {
    font-size: 0.85rem;
    padding: 1rem;
  }
}
