* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    line-height: 1.6;
    color: #333;
    background: #fafafa;
}

header {
    background: white;
    padding: 1rem;
    border-bottom: 1px solid #e1e5e9;
    position: sticky;
    top: 0;
    z-index: 100;
}

header h1 {
    margin-bottom: 0.5rem;
    font-size: 1.5rem;
    font-weight: 600;
}

.header-controls {
    display: flex;
    justify-content: space-between;
    align-items: center;
    width: 100%;
}

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

nav a {
    color: #0066cc;
    text-decoration: none;
    padding: 0.25rem 0.5rem;
    border-radius: 4px;
    transition: background-color 0.2s;
}

nav a:hover {
    background-color: #f0f8ff;
}

.btn {
    background: #0066cc;
    color: white;
    border: none;
    padding: 0.5rem 1rem;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.9rem;
    transition: background-color 0.2s;
}

.btn:hover {
    background: #0052a3;
}

.btn-primary {
    background: #0066cc;
}

.btn:not(.btn-primary) {
    background: #6c757d;
}

#notes-container {
    height: calc(100vh - 100px);
    overflow: hidden;
}

.note-stack {
    display: flex;
    height: 100%;
    overflow-x: auto;
    scroll-behavior: smooth;
    gap: 1px;
    background: #e1e5e9;
}

.note-panel {
    min-width: 350px;
    max-width: 400px;
    height: 100%;
    background: white;
    display: flex;
    flex-direction: column;
    border-right: 1px solid #e1e5e9;
    flex-shrink: 0;
    opacity: 1;
}

.note-panel.new-note {
    opacity: 0;
    animation: fadeIn 0.4s ease-out forwards;
}

@keyframes fadeIn {
    to {
        opacity: 1;
    }
}

.note-header {
    padding: 1rem;
    border-bottom: 1px solid #e1e5e9;
    background: #f8f9fa;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.note-title {
    font-size: 1.1rem;
    font-weight: 600;
    margin: 0;
}

.close-note {
    background: none;
    border: none;
    font-size: 1.2rem;
    cursor: pointer;
    padding: 0.25rem;
    border-radius: 4px;
    color: #666;
}

.close-note:hover {
    background: #e9ecef;
    color: #333;
}

.note-content {
    flex: 1;
    padding: 1rem;
    overflow-y: auto;
    font-size: 0.95rem;
}

.note-content h1,
.note-content h2,
.note-content h3 {
    margin-top: 1.5rem;
    margin-bottom: 0.5rem;
    color: #2c3e50;
}

.note-content h1 {
    font-size: 1.4rem;
}

.note-content h2 {
    font-size: 1.2rem;
}

.note-content h3 {
    font-size: 1.1rem;
}

.note-content p {
    margin-bottom: 1rem;
}

.note-content ul,
.note-content ol {
    margin-left: 1.5rem;
    margin-bottom: 1rem;
}

.note-content li {
    margin-bottom: 0.25rem;
}

.note-content a {
    color: #0066cc;
    text-decoration: none;
}

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

.note-link {
    cursor: pointer;
}

.note-link:hover {
    background-color: rgba(0, 102, 204, 0.1);
}

.note-link-missing {
    color: #dc3545 !important;
    text-decoration: none;
    border-bottom: 1px dashed #dc3545;
}

.note-link-missing:hover {
    background-color: rgba(220, 53, 69, 0.1) !important;
}

.loading {
    display: flex;
    justify-content: center;
    align-items: center;
    height: 200px;
    font-style: italic;
    color: #666;
}

@media (max-width: 800px) {
    .note-panel {
        min-width: 280px;
        max-width: 320px;
    }
    
    nav {
        font-size: 0.9rem;
    }
    
    header h1 {
        font-size: 1.3rem;
    }
}

@media (max-width: 600px) {
    .note-panel {
        min-width: calc(100vw - 20px);
        max-width: calc(100vw - 20px);
    }
    
    #notes-container {
        height: calc(100vh - 120px);
    }
}

/* Modal Styles */
.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    z-index: 1000;
    justify-content: center;
    align-items: center;
}

.modal.show {
    display: flex;
}

.modal-content {
    background: white;
    border-radius: 8px;
    width: 90%;
    max-width: 900px;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
}

.modal-header {
    padding: 1rem;
    border-bottom: 1px solid #e1e5e9;
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: #f8f9fa;
    border-radius: 8px 8px 0 0;
}

.modal-header h3 {
    margin: 0;
    font-size: 1.2rem;
}

.close-modal {
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    padding: 0.25rem;
    border-radius: 4px;
    color: #666;
}

.close-modal:hover {
    background: #e9ecef;
    color: #333;
}

.modal-body {
    padding: 1.5rem;
}

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

.form-group label {
    display: block;
    margin-bottom: 0.5rem;
    font-weight: 600;
    color: #2c3e50;
}

.form-group input,
.form-group textarea {
    width: 100%;
    padding: 0.75rem;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 0.95rem;
    font-family: inherit;
}

.form-group input:focus,
.form-group textarea:focus {
    outline: none;
    border-color: #0066cc;
    box-shadow: 0 0 0 2px rgba(0, 102, 204, 0.1);
}

.form-group textarea {
    resize: vertical;
    min-height: 200px;
    font-family: 'Monaco', 'Menlo', monospace;
}

.form-group small {
    display: block;
    margin-top: 0.25rem;
    color: #666;
    font-size: 0.8rem;
}

.form-actions {
    display: flex;
    gap: 1rem;
    justify-content: flex-end;
    margin-top: 2rem;
}

/* Search Styles */
#search-input {
    width: 100%;
    padding: 0.75rem;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 1rem;
    margin-bottom: 1rem;
}

#search-results {
    max-height: 300px;
    overflow-y: auto;
}

.search-result {
    padding: 0.75rem;
    border-bottom: 1px solid #e1e5e9;
    cursor: pointer;
    transition: background-color 0.2s;
}

.search-result:hover {
    background: #f8f9fa;
}

.search-result:last-child {
    border-bottom: none;
}

.search-result-title {
    font-weight: 600;
    color: #2c3e50;
    margin-bottom: 0.25rem;
}

.search-result-preview {
    color: #666;
    font-size: 0.9rem;
    line-height: 1.4;
}

.note-actions {
    display: flex;
    gap: 0.5rem;
    margin-left: auto;
}

.note-actions button {
    background: none;
    border: none;
    padding: 0.25rem 0.5rem;
    border-radius: 4px;
    cursor: pointer;
    color: #666;
    font-size: 0.8rem;
}

.note-actions button:hover {
    background: #e9ecef;
    color: #333;
}

/* Editor with Live Preview Styles */
.editor-container {
    display: flex;
    gap: 1rem;
    border: 1px solid #ddd;
    border-radius: 4px;
    overflow: hidden;
    height: 400px;
}

.editor-pane,
.preview-pane {
    flex: 1;
    display: flex;
    flex-direction: column;
}

.editor-header {
    background: #f8f9fa;
    padding: 0.5rem 0.75rem;
    border-bottom: 1px solid #e1e5e9;
    font-size: 0.9rem;
    font-weight: 600;
    color: #666;
}

.textarea-container {
    position: relative;
    flex: 1;
    display: flex;
    flex-direction: column;
}

.editor-pane textarea {
    flex: 1;
    border: none;
    resize: none;
    padding: 1rem;
    font-family: 'Monaco', 'Menlo', 'Consolas', monospace;
    font-size: 0.9rem;
    line-height: 1.5;
    outline: none;
}

.editor-pane textarea:focus {
    box-shadow: none;
}

.preview-pane {
    border-left: 1px solid #e1e5e9;
    background: #fafafa;
}

.preview-content {
    flex: 1;
    padding: 1rem;
    overflow-y: auto;
    font-size: 0.9rem;
    line-height: 1.6;
}

.preview-content h1,
.preview-content h2,
.preview-content h3 {
    margin-top: 1rem;
    margin-bottom: 0.5rem;
    color: #2c3e50;
}

.preview-content h1:first-child,
.preview-content h2:first-child,
.preview-content h3:first-child {
    margin-top: 0;
}

.preview-content h1 {
    font-size: 1.3rem;
    border-bottom: 2px solid #e1e5e9;
    padding-bottom: 0.25rem;
}

.preview-content h2 {
    font-size: 1.1rem;
}

.preview-content h3 {
    font-size: 1rem;
}

.preview-content p {
    margin-bottom: 1rem;
}

.preview-content ul,
.preview-content ol {
    margin-left: 1.5rem;
    margin-bottom: 1rem;
}

.preview-content li {
    margin-bottom: 0.25rem;
}

.preview-content a {
    color: #0066cc;
    text-decoration: none;
}

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

.preview-content code {
    background: #f1f3f4;
    padding: 0.125rem 0.25rem;
    border-radius: 3px;
    font-family: 'Monaco', 'Menlo', monospace;
    font-size: 0.85em;
}

.preview-content pre {
    background: #f8f9fa;
    padding: 1rem;
    border-radius: 4px;
    overflow-x: auto;
    margin-bottom: 1rem;
    border-left: 4px solid #0066cc;
}

.preview-content pre code {
    background: none;
    padding: 0;
}

.preview-content blockquote {
    margin: 1rem 0;
    padding: 0.5rem 1rem;
    border-left: 4px solid #ddd;
    background: #f9f9f9;
    color: #666;
}

.preview-placeholder {
    color: #999;
    font-style: italic;
    text-align: center;
    margin-top: 2rem;
}

@media (max-width: 768px) {
    .editor-container {
        flex-direction: column;
        height: 600px;
    }
    
    .preview-pane {
        border-left: none;
        border-top: 1px solid #e1e5e9;
    }
}

/* Formatting Toolbar Styles */
.formatting-toolbar {
    display: flex;
    gap: 1rem;
    padding: 0.5rem 0.75rem;
    background: #f8f9fa;
    border-bottom: 1px solid #e1e5e9;
    flex-wrap: wrap;
    align-items: center;
}

.toolbar-group {
    display: flex;
    gap: 0.25rem;
    align-items: center;
}

.toolbar-btn {
    background: white;
    border: 1px solid #ddd;
    border-radius: 3px;
    padding: 0.25rem 0.5rem;
    cursor: pointer;
    font-size: 0.8rem;
    transition: all 0.2s;
    min-width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.toolbar-btn:hover {
    background: #e9ecef;
    border-color: #aaa;
}

.toolbar-btn:active {
    background: #dee2e6;
    transform: translateY(1px);
}

.toolbar-btn strong,
.toolbar-btn em,
.toolbar-btn u {
    font-size: 0.8rem;
    line-height: 1;
}

.color-picker-group {
    display: flex;
    align-items: center;
    gap: 0.25rem;
}

.color-label {
    font-size: 0.75rem;
    color: #666;
    margin: 0;
}

.color-picker {
    width: 32px;
    height: 28px;
    border: 1px solid #ddd;
    border-radius: 3px;
    cursor: pointer;
    padding: 0;
    background: none;
}

.color-picker::-webkit-color-swatch-wrapper {
    padding: 2px;
}

.color-picker::-webkit-color-swatch {
    border: none;
    border-radius: 2px;
}

.color-picker::-moz-color-swatch {
    border: none;
    border-radius: 2px;
}

/* Responsive toolbar */
@media (max-width: 768px) {
    .formatting-toolbar {
        gap: 0.5rem;
    }
    
    .toolbar-group {
        gap: 0.125rem;
    }
    
    .toolbar-btn {
        min-width: 26px;
        height: 26px;
        font-size: 0.75rem;
    }
    
    .color-picker {
        width: 28px;
        height: 26px;
    }
    
    .color-label {
        font-size: 0.7rem;
    }
}

/* Note Autocomplete Styles */
.note-autocomplete-dropdown {
    position: absolute;
    background: white;
    border: 1px solid #ddd;
    border-radius: 4px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    max-height: 200px;
    overflow-y: auto;
    z-index: 1000;
    display: none;
    min-width: 250px;
}

.note-autocomplete-dropdown.show {
    display: block;
}

.autocomplete-item {
    padding: 0.5rem 0.75rem;
    cursor: pointer;
    border-bottom: 1px solid #f0f0f0;
    transition: background-color 0.2s;
}

.autocomplete-item:last-child {
    border-bottom: none;
}

.autocomplete-item:hover,
.autocomplete-item.selected {
    background: #f8f9fa;
}

.autocomplete-item.selected {
    background: #e3f2fd;
}

.autocomplete-title {
    font-weight: 600;
    color: #2c3e50;
    font-size: 0.9rem;
}

.autocomplete-id {
    font-size: 0.8rem;
    color: #666;
    font-family: 'Monaco', 'Menlo', 'Consolas', monospace;
}

.autocomplete-preview {
    font-size: 0.8rem;
    color: #888;
    margin-top: 0.25rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.no-notes-found {
    padding: 0.75rem;
    text-align: center;
    color: #999;
    font-style: italic;
    font-size: 0.9rem;
}

/* Note Hover Preview Styles */
.note-preview {
    position: absolute;
    background: white;
    border: 1px solid #e1e5e9;
    border-radius: 8px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.15);
    padding: 1rem;
    max-width: 400px;
    max-height: 300px;
    overflow-y: auto;
    z-index: 1000;
    display: none;
    font-size: 0.9rem;
    line-height: 1.5;
}

.note-preview.show {
    display: block;
}

.note-preview h1,
.note-preview h2,
.note-preview h3 {
    margin-top: 0;
    margin-bottom: 0.5rem;
    color: #2c3e50;
}

.note-preview h1 {
    font-size: 1.1rem;
}

.note-preview h2 {
    font-size: 1rem;
}

.note-preview h3 {
    font-size: 0.95rem;
}

.note-preview p {
    margin-bottom: 0.75rem;
}

.note-preview ul,
.note-preview ol {
    margin-left: 1rem;
    margin-bottom: 0.75rem;
}

.note-preview .preview-title {
    font-weight: 600;
    color: #0066cc;
    margin-bottom: 0.5rem;
    padding-bottom: 0.5rem;
    border-bottom: 1px solid #f0f0f0;
}

.note-preview .preview-content {
    color: #555;
}

.note-link {
    position: relative;
}

/* Sync Status Styles */
.sync-status {
    display: flex;
    align-items: center;
    gap: 0.25rem;
    font-size: 0.8rem;
    color: #666;
    margin-left: 1rem;
}

/* Note Count Styles */
.note-count {
    display: flex;
    align-items: center;
    font-size: 0.8rem;
    color: #666;
    margin-left: 0.5rem;
}

#sync-indicator {
    font-size: 0.9rem;
}

.sync-status.syncing #sync-indicator {
    animation: spin 1s linear infinite;
}

.sync-status.success {
    color: #28a745;
}

.sync-status.error {
    color: #dc3545;
}

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

/* Settings Modal Styles */
.settings-section {
    margin-bottom: 2rem;
    padding-bottom: 1.5rem;
    border-bottom: 1px solid #e1e5e9;
}

.settings-section:last-of-type {
    border-bottom: none;
    margin-bottom: 0;
}

.settings-section h4 {
    margin-bottom: 1rem;
    color: #2c3e50;
    font-size: 1rem;
}

.setup-instructions {
    background: #f8f9fa;
    padding: 1rem;
    border-radius: 4px;
    border-left: 4px solid #0066cc;
    font-size: 0.9rem;
    line-height: 1.5;
}

.setup-instructions li {
    margin-bottom: 0.5rem;
}

.setup-instructions code {
    background: #e9ecef;
    padding: 0.125rem 0.25rem;
    border-radius: 3px;
    font-family: 'Monaco', 'Menlo', monospace;
    font-size: 0.85em;
}

.setup-instructions a {
    color: #0066cc;
    text-decoration: none;
}

.setup-instructions a:hover {
    text-decoration: underline;
}

.form-group label input[type="checkbox"] {
    width: auto;
    margin-right: 0.5rem;
}

.form-group select {
    width: 100%;
    padding: 0.75rem;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 0.95rem;
    font-family: inherit;
}

.form-group select:focus {
    outline: none;
    border-color: #0066cc;
    box-shadow: 0 0 0 2px rgba(0, 102, 204, 0.1);
}

#sync-status-display {
    background: #f8f9fa;
    padding: 1rem;
    border-radius: 4px;
}

#last-sync,
#sync-info {
    font-size: 0.9rem;
    color: #666;
    margin-bottom: 0.5rem;
}

#last-sync {
    font-weight: 600;
}

/* Authentication Styles */
.auth-container {
    min-height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    padding: 2rem;
}

.auth-card {
    background: white;
    border-radius: 12px;
    padding: 3rem;
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.1);
    max-width: 400px;
    width: 100%;
    text-align: center;
}

.auth-card h1 {
    margin-bottom: 0.5rem;
    color: #2c3e50;
    font-size: 2rem;
}

.auth-card p {
    color: #666;
    margin-bottom: 2rem;
    line-height: 1.5;
}

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

.auth-header h2 {
    margin: 0;
    color: #2c3e50;
    font-size: 1.5rem;
    font-weight: 500;
}

.auth-form .form-group {
    text-align: left;
    margin-bottom: 1.5rem;
}

.auth-form label {
    display: block;
    margin-bottom: 0.5rem;
    font-weight: 600;
    color: #2c3e50;
}

.auth-form input {
    width: 100%;
    padding: 0.875rem;
    border: 2px solid #e1e5e9;
    border-radius: 8px;
    font-size: 1rem;
    transition: border-color 0.2s;
}

.auth-form input:focus {
    outline: none;
    border-color: #0066cc;
    box-shadow: 0 0 0 3px rgba(0, 102, 204, 0.1);
}

.auth-btn {
    width: 100%;
    padding: 0.875rem;
    font-size: 1rem;
    font-weight: 600;
    border-radius: 8px;
    margin-top: 1rem;
}

.auth-loading {
    text-align: center;
    padding: 2rem 0;
}

.loading-spinner {
    width: 32px;
    height: 32px;
    border: 3px solid #f3f3f3;
    border-top: 3px solid #0066cc;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin: 0 auto 1rem;
}

.auth-error {
    background: #fee;
    border: 1px solid #fcc;
    color: #c33;
    padding: 1rem;
    border-radius: 8px;
    margin-top: 1rem;
    font-size: 0.9rem;
}

.auth-note {
    text-align: center;
    margin-top: 1.5rem;
    color: #666;
    font-size: 0.9rem;
    font-style: italic;
}

.logout-btn {
    background: #dc3545 !important;
    margin-left: 1rem;
}

.logout-btn:hover {
    background: #c82333 !important;
}

.notes-app {
    min-height: 100vh;
}

@media (max-width: 480px) {
    .auth-container {
        padding: 1rem;
    }
    
    .auth-card {
        padding: 2rem 1.5rem;
    }
}}