@import url('themes.css');

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

html, body {
    height: 100%;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    font-size: 15px;
    line-height: 1.5;
    color: var(--text-primary);
    background: var(--bg-primary);
    -webkit-font-smoothing: antialiased;
}

/* ── Scrollbars ───────────────────────────────────────────────────────────── */
::-webkit-scrollbar         { width: 6px; height: 6px; }
::-webkit-scrollbar-track   { background: var(--scrollbar-track); }
::-webkit-scrollbar-thumb   { background: var(--scrollbar-thumb); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--scrollbar-hover); }

/* ── Auth pages ───────────────────────────────────────────────────────────── */
.auth-page {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100dvh;
    background: var(--bg-secondary);
}

.auth-container { width: 100%; max-width: 380px; padding: 1rem; }

.auth-card {
    background: var(--bg-primary);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 2.5rem 2rem;
    box-shadow: var(--shadow-md);
}

.auth-logo {
    display: flex;
    justify-content: center;
    margin-bottom: 1rem;
}

.auth-title {
    text-align: center;
    font-size: 1.6rem;
    font-weight: 700;
    color: var(--text-title);
    margin-bottom: 0.25rem;
}

.auth-subtitle {
    text-align: center;
    color: var(--text-muted);
    font-size: 0.9rem;
    margin-bottom: 1.75rem;
}

.auth-error {
    background: #fde8e8;
    color: var(--danger);
    border: 1px solid #f9c7c7;
    border-radius: 6px;
    padding: 0.6rem 0.9rem;
    font-size: 0.875rem;
    margin-bottom: 1rem;
}

:root[data-theme="dark"] .auth-error {
    background: #3a1a1a;
    border-color: #5a2a2a;
}

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

.auth-form label {
    display: block;
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--text-secondary);
    margin-bottom: 0.4rem;
}

.auth-form input[type="email"],
.auth-form input[type="password"],
.auth-form input[type="text"] {
    width: 100%;
    padding: 0.6rem 0.8rem;
    border: 1px solid var(--input-border);
    border-radius: 6px;
    background: var(--input-bg);
    color: var(--text-primary);
    font-size: 0.95rem;
    transition: border-color .15s;
    outline: none;
}

.auth-form input:focus { border-color: var(--input-focus); box-shadow: 0 0 0 3px rgba(74,158,255,.15); }

/* ── Buttons ──────────────────────────────────────────────────────────────── */
.btn-primary {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.4rem;
    padding: 0.6rem 1.2rem;
    background: var(--accent);
    color: var(--accent-text);
    border: none;
    border-radius: 6px;
    font-size: 0.9rem;
    font-weight: 500;
    cursor: pointer;
    transition: background .15s;
    text-decoration: none;
}
.btn-primary:hover  { background: var(--accent-hover); }
.btn-full           { width: 100%; margin-top: 0.5rem; }

.btn-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 32px; height: 32px;
    background: transparent;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    color: var(--text-secondary);
    transition: background .15s, color .15s;
    flex-shrink: 0;
}
.btn-icon:hover { background: var(--bg-list-hover); color: var(--text-primary); }
.btn-icon.active { color: var(--accent); }

.btn-danger {
    background: transparent;
    border: none;
    color: var(--danger);
    cursor: pointer;
    font-size: 0.85rem;
    padding: 0.3rem 0.5rem;
    border-radius: 4px;
    transition: background .15s;
}
.btn-danger:hover { background: rgba(217,48,37,.08); }

/* ── App shell ────────────────────────────────────────────────────────────── */
.app-shell {
    display: grid;
    grid-template-rows: 48px 1fr;
    grid-template-columns: 280px 1fr;
    height: 100dvh;
    overflow: hidden;
}

/* ── Toolbar ──────────────────────────────────────────────────────────────── */
.toolbar {
    grid-column: 1 / -1;
    grid-row: 1;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0 0.75rem;
    background: var(--bg-toolbar);
    border-bottom: 1px solid var(--border);
    height: 48px;
}

.toolbar-brand {
    font-size: 1.05rem;
    font-weight: 700;
    color: var(--text-title);
    margin-right: 0.5rem;
    user-select: none;
    white-space: nowrap;
}

.toolbar-search {
    flex: 1;
    min-width: 0;
    max-width: 320px;
    position: relative;
}

.toolbar-search input {
    width: 100%;
    padding: 0.35rem 0.7rem 0.35rem 2rem;
    border: 1px solid var(--input-border);
    border-radius: 6px;
    background: var(--input-bg);
    color: var(--text-primary);
    font-size: 0.875rem;
    outline: none;
    transition: border-color .15s;
}
.toolbar-search input:focus { border-color: var(--input-focus); }
.toolbar-search input::placeholder { color: var(--text-muted); }

.toolbar-search .search-icon {
    position: absolute;
    left: 0.5rem;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-muted);
    pointer-events: none;
}

.toolbar-search .search-clear {
    position: absolute;
    right: 0.4rem;
    top: 50%;
    transform: translateY(-50%);
    display: none;
    background: none;
    border: none;
    cursor: pointer;
    color: var(--text-muted);
    padding: 2px;
    line-height: 1;
}
.toolbar-search.has-query .search-clear { display: block; }

.toolbar-right {
    display: flex;
    align-items: center;
    gap: 0.25rem;
    margin-left: auto;
}

.sync-indicator {
    width: 8px; height: 8px;
    border-radius: 50%;
    background: var(--sync-dot);
    flex-shrink: 0;
    transition: background .3s;
}
.sync-indicator.pending  { background: var(--sync-pending); }
.sync-indicator.offline  { background: var(--sync-offline); }
.sync-indicator.syncing  { animation: pulse 1s infinite; }

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50%       { opacity: 0.3; }
}

/* ── Note list pane ───────────────────────────────────────────────────────── */
.note-list-pane {
    grid-column: 1;
    grid-row: 2;
    display: flex;
    flex-direction: column;
    background: var(--bg-list);
    border-right: 1px solid var(--border);
    overflow: hidden;
}

.note-list-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.6rem 0.75rem;
    border-bottom: 1px solid var(--border-light);
    flex-shrink: 0;
}

.note-count {
    font-size: 0.75rem;
    color: var(--text-muted);
}

.note-list {
    flex: 1;
    overflow-y: auto;
    list-style: none;
}

.note-item {
    padding: 0.75rem 0.9rem;
    cursor: pointer;
    border-bottom: 1px solid var(--border-light);
    transition: background .1s;
    position: relative;
}
.note-item:hover    { background: var(--bg-list-hover); }
.note-item.selected { background: var(--bg-selected); }

.note-item-title {
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--text-note-title);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-bottom: 0.2rem;
}

.note-item-preview {
    font-size: 0.8rem;
    color: var(--text-preview);
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    line-height: 1.4;
}

.note-item-meta {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-top: 0.3rem;
}

.note-item-date {
    font-size: 0.73rem;
    color: var(--text-muted);
}

.note-item-badges { display: flex; gap: 0.25rem; margin-left: auto; }

.badge {
    font-size: 0.65rem;
    padding: 1px 5px;
    border-radius: 4px;
    background: var(--tag-bg);
    color: var(--tag-text);
    font-weight: 500;
    letter-spacing: 0.02em;
}

mark { background: var(--mark-bg); color: var(--mark-text); border-radius: 2px; padding: 0 1px; }

.note-list-header.trash-mode { background: rgba(234,67,53,.07); }
.note-item.trashed .note-item-title { opacity: .6; }
.trash-mode-label {
    font-size: .7rem; font-weight: 600; text-transform: uppercase;
    letter-spacing: .06em; color: var(--danger); padding: .35rem .75rem;
    border-bottom: 1px solid var(--border-light); background: rgba(234,67,53,.05);
    flex-shrink: 0;
}

.note-list-empty {
    padding: 3rem 1rem;
    text-align: center;
    color: var(--text-muted);
    font-size: 0.875rem;
}

/* ── Editor pane ──────────────────────────────────────────────────────────── */
.editor-pane {
    grid-column: 2;
    grid-row: 2;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    background: var(--bg-editor);
}

.editor-toolbar {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0 0.75rem;
    height: 40px;
    border-bottom: 1px solid var(--border-light);
    flex-shrink: 0;
    background: var(--bg-toolbar);
}

.editor-toolbar-right { margin-left: auto; display: flex; align-items: center; gap: 0.4rem; }

.note-word-count {
    font-size: 0.75rem;
    color: var(--text-muted);
}

.editor-inner {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    position: relative;
}

/* Title area */
.note-title-input {
    padding: 1.25rem 1.5rem 0;
    flex-shrink: 0;
}

.note-title-input input {
    width: 100%;
    border: none;
    outline: none;
    background: transparent;
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--text-title);
    line-height: 1.3;
    padding: 0;
}
.note-title-input input::placeholder { color: var(--text-muted); font-weight: 400; }

.title-divider {
    height: 1px;
    background: var(--border-light);
    margin: 0.6rem 1.5rem 0;
    flex-shrink: 0;
}

/* Body area - normal mode */
.editor-body {
    flex: 1;
    display: flex;
    overflow: hidden;
    min-height: 0;
}

#note-body {
    flex: 1;
    resize: none;
    border: none;
    outline: none;
    background: var(--bg-editor);
    color: var(--text-primary);
    font-family: 'SF Mono', 'Fira Code', 'Cascadia Code', 'Consolas', 'Courier New', monospace;
    font-size: 0.925rem;
    line-height: 1.7;
    padding: 0.75rem 1.5rem 1.5rem;
    tab-size: 2;
    overflow-y: auto;
    word-wrap: break-word;
    white-space: pre-wrap;
}

/* Markdown split view */
.editor-body.split-view {
    flex-direction: row;
}
.editor-body.split-view #note-body {
    flex: 1;
    border-right: 1px solid var(--border);
}
.markdown-preview {
    flex: 1;
    padding: 0.75rem 1.5rem 1.5rem;
    overflow-y: auto;
    background: var(--bg-preview);
    display: none;
}
.editor-body.split-view .markdown-preview { display: block; }

/* Markdown preview typography */
.markdown-preview h1 { font-size: 1.6rem; margin: 0 0 0.75rem; }
.markdown-preview h2 { font-size: 1.3rem; margin: 1.25rem 0 0.5rem; }
.markdown-preview h3 { font-size: 1.1rem; margin: 1rem 0 0.4rem; }
.markdown-preview p  { margin: 0 0 0.9rem; }
.markdown-preview ul,
.markdown-preview ol { margin: 0 0 0.9rem; padding-left: 1.5rem; }
.markdown-preview li { margin-bottom: 0.25rem; }
.markdown-preview blockquote {
    border-left: 3px solid var(--accent);
    margin: 0 0 0.9rem;
    padding: 0.4rem 0.9rem;
    color: var(--text-secondary);
    background: var(--bg-secondary);
    border-radius: 0 4px 4px 0;
}
.markdown-preview code {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: 3px;
    padding: 1px 4px;
    font-family: 'SF Mono', 'Fira Code', monospace;
    font-size: 0.875em;
}
.markdown-preview pre {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 0.9rem 1rem;
    overflow-x: auto;
    margin-bottom: 0.9rem;
}
.markdown-preview pre code { background: none; border: none; padding: 0; }
.markdown-preview a { color: var(--accent); }
.markdown-preview hr { border: none; border-top: 1px solid var(--border); margin: 1.25rem 0; }
.markdown-preview table { border-collapse: collapse; width: 100%; margin-bottom: 0.9rem; }
.markdown-preview th,
.markdown-preview td { border: 1px solid var(--border); padding: 0.4rem 0.7rem; }
.markdown-preview th { background: var(--bg-secondary); font-weight: 600; }

/* ── Empty state ──────────────────────────────────────────────────────────── */
.editor-empty {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: var(--text-muted);
    gap: 1rem;
    padding: 2rem;
}
.editor-empty svg { opacity: 0.3; }
.editor-empty p   { font-size: 0.9rem; }

/* ── Toast notifications ──────────────────────────────────────────────────── */
.toast-container {
    position: fixed;
    bottom: 1.5rem;
    right: 1.5rem;
    z-index: 1000;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    max-width: 360px;
}

.toast {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 0.75rem 1rem;
    box-shadow: var(--shadow-md);
    font-size: 0.875rem;
    display: flex;
    align-items: flex-start;
    gap: 0.6rem;
    animation: slideIn .2s ease-out;
}
.toast.success { border-left: 3px solid var(--sync-dot); }
.toast.warning { border-left: 3px solid var(--sync-pending); }
.toast.error   { border-left: 3px solid var(--sync-offline); }

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

/* ── Share URL bar ────────────────────────────────────────────────────────── */
.share-bar {
    display: none;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 1rem;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border);
    font-size: 0.8rem;
    color: var(--text-secondary);
    flex-shrink: 0;
}
.share-bar.visible { display: flex; }
.share-bar input {
    flex: 1;
    border: 1px solid var(--border);
    border-radius: 4px;
    padding: 0.25rem 0.5rem;
    font-size: 0.8rem;
    background: var(--input-bg);
    color: var(--text-primary);
    outline: none;
}

/* ── Delete confirmation modal ────────────────────────────────────────────── */
.modal-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.4);
    z-index: 500;
    align-items: center;
    justify-content: center;
}
.modal-overlay.visible { display: flex; }
.modal {
    background: var(--bg-primary);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 1.75rem;
    max-width: 380px;
    width: 90%;
    box-shadow: var(--shadow-md);
}
.modal h2  { font-size: 1.1rem; margin-bottom: 0.6rem; }
.modal p   { color: var(--text-secondary); font-size: 0.9rem; margin-bottom: 1.25rem; }
.modal-actions { display: flex; gap: 0.5rem; justify-content: flex-end; }

/* ── Mobile ───────────────────────────────────────────────────────────────── */
@media (max-width: 768px) {
    .app-shell {
        grid-template-columns: 1fr;
    }

    .note-list-pane {
        grid-column: 1;
    }

    .editor-pane {
        grid-column: 1;
        grid-row: 2;
        display: none;
    }

    /* When a note is open on mobile */
    .app-shell[data-view="editor"] .note-list-pane  { display: none; }
    .app-shell[data-view="editor"] .editor-pane     { display: flex; }

    .toolbar-search { max-width: none; }

    .note-title-input { padding: 1rem 1rem 0; }
    .title-divider    { margin: 0.5rem 1rem 0; }
    #note-body        { padding: 0.6rem 1rem 1rem; }

    .editor-body.split-view { flex-direction: column; }
    .editor-body.split-view #note-body { flex: none; height: 45%; }
    .editor-body.split-view .markdown-preview { flex: none; height: 55%; }

    /* Mobile back button */
    .mobile-back { display: flex; }
    .desktop-only { display: none; }
}

@media (min-width: 769px) {
    .mobile-back { display: none; }
}

/* ── Loading spinner ──────────────────────────────────────────────────────── */
.spinner {
    display: inline-block;
    width: 16px; height: 16px;
    border: 2px solid var(--border);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Share page ───────────────────────────────────────────────────────────── */
.share-page {
    max-width: 720px;
    margin: 0 auto;
    padding: 2rem 1.5rem;
}
.share-page-header {
    border-bottom: 1px solid var(--border);
    padding-bottom: 1rem;
    margin-bottom: 1.5rem;
}
.share-page-header h1 {
    font-size: 1.75rem;
    font-weight: 700;
    color: var(--text-title);
}
.share-page-meta {
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-top: 0.4rem;
}
.share-page-body {
    color: var(--text-primary);
    line-height: 1.7;
    font-size: 0.95rem;
    white-space: pre-wrap;
    word-wrap: break-word;
}
