/* CSS Variables for theming */
:root {
    --color-primary: #2563eb;
    --color-primary-hover: #1d4ed8;
    --color-secondary: #64748b;
    --color-success: #10b981;
    --color-danger: #ef4444;
    --color-warning: #f59e0b;

    --color-bg: #ffffff;
    --color-bg-secondary: #f8fafc;
    --color-bg-tertiary: #f1f5f9;

    --color-text: #1e293b;
    --color-text-secondary: #64748b;
    --color-text-muted: #94a3b8;

    --color-border: #e2e8f0;
    --color-border-hover: #cbd5e1;

    --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
    --shadow: 0 1px 3px 0 rgb(0 0 0 / 0.1), 0 1px 2px -1px rgb(0 0 0 / 0.1);
    --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
    --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);

    --radius-sm: 4px;
    --radius: 8px;
    --radius-lg: 12px;
    --radius-full: 9999px;

    --transition: 150ms ease;
    --font-sans: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    --font-mono: 'SF Mono', 'Fira Code', 'Fira Mono', Menlo, monospace;
}

/* Dark mode */
[data-theme="dark"] {
    --color-bg: #0f172a;
    --color-bg-secondary: #1e293b;
    --color-bg-tertiary: #334155;

    --color-text: #f1f5f9;
    --color-text-secondary: #94a3b8;
    --color-text-muted: #64748b;

    --color-border: #334155;
    --color-border-hover: #475569;
}

/* Reset & Base */
*,
*::before,
*::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html {
    font-size: 16px;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

body {
    font-family: var(--font-sans);
    background-color: var(--color-bg);
    color: var(--color-text);
    line-height: 1.6;
    min-height: 100vh;
}

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

a:hover {
    color: var(--color-primary-hover);
}

img {
    max-width: 100%;
    height: auto;
}

/* Typography */
h1,
h2,
h3,
h4,
h5,
h6 {
    font-weight: 600;
    line-height: 1.3;
    color: var(--color-text);
}

h1 {
    font-size: 2.25rem;
}

h2 {
    font-size: 1.875rem;
}

h3 {
    font-size: 1.5rem;
}

h4 {
    font-size: 1.25rem;
}

h5 {
    font-size: 1.125rem;
}

h6 {
    font-size: 1rem;
}

p {
    margin-bottom: 1rem;
}

/* Layout */
.container {
    width: 100%;
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 1rem;
}

.page {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

.main-content {
    flex: 1;
    padding: 2rem 0;
}

/* Header */
.header {
    background: var(--color-bg);
    border-bottom: 1px solid var(--color-border);
    padding: 1rem 0;
    position: sticky;
    top: 0;
    z-index: 100;
}

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

.logo {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--color-text);
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.logo svg {
    width: 32px;
    height: 32px;
    color: var(--color-primary);
}

.nav {
    display: flex;
    align-items: center;
    gap: 1.5rem;
}

.nav-link {
    color: var(--color-text-secondary);
    font-weight: 500;
    transition: color var(--transition);
}

.nav-link:hover {
    color: var(--color-text);
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.625rem 1.25rem;
    font-size: 0.875rem;
    font-weight: 500;
    border-radius: var(--radius);
    border: none;
    cursor: pointer;
    transition: all var(--transition);
    text-decoration: none;
    line-height: 1.5;
}

.btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

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

.btn-primary:hover:not(:disabled) {
    background: var(--color-primary-hover);
}

.btn-secondary {
    background: var(--color-bg-tertiary);
    color: var(--color-text);
}

.btn-secondary:hover:not(:disabled) {
    background: var(--color-border);
}

.btn-outline {
    background: transparent;
    border: 1px solid var(--color-border);
    color: var(--color-text);
}

.btn-outline:hover:not(:disabled) {
    border-color: var(--color-border-hover);
    background: var(--color-bg-secondary);
}

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

.btn-danger:hover:not(:disabled) {
    background: #dc2626;
}

.btn-sm {
    padding: 0.375rem 0.75rem;
    font-size: 0.8125rem;
}

.btn-lg {
    padding: 0.875rem 1.75rem;
    font-size: 1rem;
}

.btn-icon {
    padding: 0.5rem;
    border-radius: var(--radius);
}

/* Forms */
.form-group {
    margin-bottom: 1.25rem;
}

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

.form-input {
    width: 100%;
    padding: 0.625rem 0.875rem;
    font-size: 0.9375rem;
    font-family: inherit;
    background: var(--color-bg);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    color: var(--color-text);
    transition: border-color var(--transition), box-shadow var(--transition);
}

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

.form-input::placeholder {
    color: var(--color-text-muted);
}

.form-error {
    font-size: 0.8125rem;
    color: var(--color-danger);
    margin-top: 0.375rem;
}

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

/* Cards */
.card {
    background: var(--color-bg);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    overflow: hidden;
}

.card-header {
    padding: 1rem 1.25rem;
    border-bottom: 1px solid var(--color-border);
    background: var(--color-bg-secondary);
}

.card-body {
    padding: 1.25rem;
}

.card-footer {
    padding: 1rem 1.25rem;
    border-top: 1px solid var(--color-border);
    background: var(--color-bg-secondary);
}

/* Notes Grid */
.notes-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 1rem;
}

.note-card {
    background: var(--color-bg);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    padding: 1.25rem;
    transition: box-shadow var(--transition), transform var(--transition);
    cursor: pointer;
    display: flex;
    flex-direction: column;
    min-height: 160px;
}

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

.note-card.pinned {
    border-color: var(--color-warning);
    background: linear-gradient(to bottom right, var(--color-bg), rgb(245 158 11 / 0.05));
}

.note-card-title {
    font-size: 1.0625rem;
    font-weight: 600;
    margin-bottom: 0.5rem;
    color: var(--color-text);
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.note-card-content {
    font-size: 0.875rem;
    color: var(--color-text-secondary);
    flex: 1;
    display: -webkit-box;
    -webkit-line-clamp: 4;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.note-card-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-top: 1rem;
    padding-top: 0.75rem;
    border-top: 1px solid var(--color-border);
    font-size: 0.8125rem;
    color: var(--color-text-muted);
}

.note-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 0.375rem;
}

.note-tag {
    display: inline-block;
    padding: 0.125rem 0.5rem;
    font-size: 0.75rem;
    font-weight: 500;
    background: var(--color-bg-tertiary);
    color: var(--color-text-secondary);
    border-radius: var(--radius-full);
}

/* Editor */
.editor-container {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1.5rem;
    height: calc(100vh - 200px);
    min-height: 500px;
}

.editor-pane {
    display: flex;
    flex-direction: column;
    background: var(--color-bg);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    overflow: hidden;
}

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

.editor-title-input {
    flex: 1;
    font-size: 1.125rem;
    font-weight: 600;
    background: transparent;
    border: none;
    color: var(--color-text);
    padding: 0.25rem;
}

.editor-title-input:focus {
    outline: none;
}

.editor-textarea {
    flex: 1;
    width: 100%;
    padding: 1rem;
    font-family: var(--font-mono);
    font-size: 0.9375rem;
    line-height: 1.6;
    background: var(--color-bg);
    border: none;
    color: var(--color-text);
    resize: none;
}

.editor-textarea:focus {
    outline: none;
}

.editor-preview {
    flex: 1;
    padding: 1rem;
    overflow-y: auto;
    background: var(--color-bg);
}

.editor-preview h1,
.editor-preview h2,
.editor-preview h3 {
    margin-top: 1rem;
    margin-bottom: 0.5rem;
}

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

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

.editor-preview code {
    font-family: var(--font-mono);
    background: var(--color-bg-tertiary);
    padding: 0.125rem 0.375rem;
    border-radius: var(--radius-sm);
    font-size: 0.875em;
}

.editor-preview pre {
    background: var(--color-bg-tertiary);
    padding: 1rem;
    border-radius: var(--radius);
    overflow-x: auto;
    margin-bottom: 1rem;
}

.editor-preview pre code {
    background: transparent;
    padding: 0;
}

.editor-preview ul,
.editor-preview ol {
    margin-bottom: 0.75rem;
    padding-left: 1.5rem;
}

.editor-preview blockquote {
    border-left: 3px solid var(--color-primary);
    padding-left: 1rem;
    color: var(--color-text-secondary);
    margin-bottom: 0.75rem;
}

/* Auth Pages */
.auth-container {
    max-width: 400px;
    margin: 2rem auto;
}

.auth-card {
    background: var(--color-bg);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    padding: 2rem;
}

.auth-title {
    font-size: 1.5rem;
    text-align: center;
    margin-bottom: 0.5rem;
}

.auth-subtitle {
    text-align: center;
    color: var(--color-text-secondary);
    margin-bottom: 2rem;
}

.divider {
    display: flex;
    align-items: center;
    margin: 1.5rem 0;
    color: var(--color-text-muted);
    font-size: 0.875rem;
}

.divider::before,
.divider::after {
    content: '';
    flex: 1;
    height: 1px;
    background: var(--color-border);
}

.divider span {
    padding: 0 1rem;
}

.social-buttons {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.social-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.75rem;
    width: 100%;
    padding: 0.75rem;
    font-size: 0.9375rem;
    font-weight: 500;
    border-radius: var(--radius);
    border: 1px solid var(--color-border);
    background: var(--color-bg);
    color: var(--color-text);
    cursor: pointer;
    transition: all var(--transition);
}

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

.social-btn svg {
    width: 20px;
    height: 20px;
}

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

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

.search-bar {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    background: var(--color-bg);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    padding: 0.5rem 1rem;
    min-width: 300px;
}

.search-input {
    flex: 1;
    background: transparent;
    border: none;
    color: var(--color-text);
    font-size: 0.9375rem;
}

.search-input:focus {
    outline: none;
}

.filter-bar {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-bottom: 1.5rem;
    flex-wrap: wrap;
}

.filter-select {
    padding: 0.5rem 2rem 0.5rem 0.75rem;
    font-size: 0.875rem;
    background: var(--color-bg);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    color: var(--color-text);
    cursor: pointer;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%2364748b' stroke-width='2'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 0.5rem center;
}

.filter-select:focus {
    outline: none;
    border-color: var(--color-primary);
}

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

.empty-state svg {
    width: 64px;
    height: 64px;
    color: var(--color-text-muted);
    margin-bottom: 1rem;
}

.empty-state h3 {
    margin-bottom: 0.5rem;
    color: var(--color-text);
}

.empty-state p {
    margin-bottom: 1.5rem;
}

/* Modal */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgb(0 0 0 / 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    padding: 1rem;
}

.modal {
    background: var(--color-bg);
    border-radius: var(--radius-lg);
    max-width: 500px;
    width: 100%;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: var(--shadow-lg);
}

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

.modal-title {
    font-size: 1.125rem;
    font-weight: 600;
}

.modal-close {
    background: none;
    border: none;
    cursor: pointer;
    color: var(--color-text-muted);
    padding: 0.25rem;
}

.modal-close:hover {
    color: var(--color-text);
}

.modal-body {
    padding: 1.25rem;
}

.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 0.75rem;
    padding: 1.25rem;
    border-top: 1px solid var(--color-border);
}

/* Toast */
.toast-container {
    position: fixed;
    bottom: 1.5rem;
    right: 1.5rem;
    z-index: 1100;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.toast {
    padding: 1rem 1.25rem;
    border-radius: var(--radius);
    background: var(--color-bg);
    border: 1px solid var(--color-border);
    box-shadow: var(--shadow-lg);
    display: flex;
    align-items: center;
    gap: 0.75rem;
    animation: slideIn 0.2s ease;
}

.toast.success {
    border-left: 3px solid var(--color-success);
}

.toast.error {
    border-left: 3px solid var(--color-danger);
}

.toast.warning {
    border-left: 3px solid var(--color-warning);
}

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

    to {
        transform: translateX(0);
        opacity: 1;
    }
}

/* Loading */
.loading {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 2rem;
}

.spinner {
    width: 32px;
    height: 32px;
    border: 3px solid var(--color-border);
    border-top-color: var(--color-primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

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

/* Footer */
.footer {
    background: var(--color-bg-secondary);
    border-top: 1px solid var(--color-border);
    padding: 2rem 0;
    margin-top: auto;
}

.footer-inner {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 1rem;
}

.footer-links {
    display: flex;
    gap: 1.5rem;
}

.footer-link {
    color: var(--color-text-secondary);
    font-size: 0.875rem;
}

.footer-link:hover {
    color: var(--color-text);
}

.footer-copyright {
    color: var(--color-text-muted);
    font-size: 0.875rem;
}

/* Responsive */
@media (max-width: 768px) {
    .editor-container {
        grid-template-columns: 1fr;
        height: auto;
    }

    .editor-pane {
        min-height: 400px;
    }

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

    .search-bar {
        min-width: auto;
    }

    .notes-grid {
        grid-template-columns: 1fr;
    }

    .auth-card {
        padding: 1.5rem;
    }

    .header-inner {
        flex-wrap: wrap;
    }

    .nav {
        width: 100%;
        justify-content: center;
        margin-top: 1rem;
    }
}

/* Markdown Editor specific */
.markdown-toolbar {
    display: flex;
    gap: 0.25rem;
    padding: 0.5rem;
    background: var(--color-bg-secondary);
    border-bottom: 1px solid var(--color-border);
}

.toolbar-btn {
    padding: 0.375rem 0.5rem;
    background: transparent;
    border: none;
    border-radius: var(--radius-sm);
    color: var(--color-text-secondary);
    cursor: pointer;
    transition: all var(--transition);
}

.toolbar-btn:hover {
    background: var(--color-bg-tertiary);
    color: var(--color-text);
}

.toolbar-divider {
    width: 1px;
    background: var(--color-border);
    margin: 0 0.375rem;
}