/* --- Reset & Base --- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
[hidden] { display: none !important; }

:root {
    --bg: #faf8f5;
    --bg-card: #ffffff;
    --bg-hover: #f3f0eb;
    --bg-input: #f7f5f2;
    --border: #e5e0d8;
    --border-focus: #c4a882;
    --text: #3a3530;
    --text-muted: #8a8078;
    --text-light: #b0a89e;
    --accent: #c4884a;
    --accent-hover: #b07a40;
    --accent-bg: #fdf3e8;
    --danger: #c0564a;
    --danger-hover: #a84a3f;
    --pin-color: #d4a54a;
    --tag-bg: #ede8e1;
    --tag-text: #6b6158;
    --radius: 8px;
    --radius-lg: 12px;
    --shadow: 0 1px 3px rgba(60,50,40,0.06), 0 1px 2px rgba(60,50,40,0.04);
    --shadow-lg: 0 4px 16px rgba(60,50,40,0.10);
    --font: 'Georgia', 'Times New Roman', serif;
    --font-mono: 'SF Mono', 'Consolas', 'Monaco', monospace;
    --font-sans: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
}

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

/* --- Login --- */
.screen { min-height: 100vh; }
#login-screen {
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(145deg, #faf8f5, #f0ebe3);
}
.login-box {
    text-align: center;
    padding: 3rem 2.5rem;
    background: var(--bg-card);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    width: 100%;
    max-width: 360px;
}
.login-box h1 {
    font-family: var(--font);
    font-size: 2rem;
    font-weight: 400;
    letter-spacing: -0.02em;
    margin-bottom: 0.25rem;
    color: var(--text);
}
.login-sub {
    color: var(--text-muted);
    font-size: 0.85rem;
    margin-bottom: 2rem;
    font-style: italic;
}
#login-form { display: flex; flex-direction: column; gap: 0.75rem; }
#login-form input {
    padding: 0.7rem 1rem;
    border: 1.5px solid var(--border);
    border-radius: var(--radius);
    font-size: 0.95rem;
    background: var(--bg-input);
    color: var(--text);
    outline: none;
    transition: border-color 0.2s;
    text-align: center;
}
#login-form input:focus { border-color: var(--border-focus); }
#login-form button {
    padding: 0.7rem;
    background: var(--accent);
    color: #fff;
    border: none;
    border-radius: var(--radius);
    font-size: 0.95rem;
    cursor: pointer;
    transition: background 0.2s;
}
#login-form button:hover { background: var(--accent-hover); }
.error { color: var(--danger); font-size: 0.85rem; margin-top: 0.5rem; }

/* --- Header --- */
header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1rem 1.5rem;
    border-bottom: 1px solid var(--border);
    background: var(--bg-card);
    position: sticky;
    top: 0;
    z-index: 10;
}
#header-title {
    font-family: var(--font);
    font-size: 1.3rem;
    font-weight: 400;
    letter-spacing: -0.01em;
}
.header-right { display: flex; gap: 0.5rem; align-items: center; }

/* --- Buttons --- */
.btn-primary {
    padding: 0.45rem 1rem;
    background: var(--accent);
    color: #fff;
    border: none;
    border-radius: var(--radius);
    font-size: 0.85rem;
    cursor: pointer;
    transition: background 0.2s;
    white-space: nowrap;
}
.btn-primary:hover { background: var(--accent-hover); }
.btn-ghost {
    padding: 0.45rem 0.75rem;
    background: none;
    color: var(--text-muted);
    border: 1px solid transparent;
    border-radius: var(--radius);
    font-size: 0.85rem;
    cursor: pointer;
    transition: all 0.2s;
}
.btn-ghost:hover { background: var(--bg-hover); color: var(--text); }
.btn-icon {
    padding: 0.35rem 0.65rem;
    background: none;
    color: var(--text-muted);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 0.8rem;
    cursor: pointer;
    transition: all 0.2s;
}
.btn-icon:hover { background: var(--bg-hover); color: var(--text); }
.btn-danger { color: var(--danger); }
.btn-danger:hover { background: #fdf0ee; color: var(--danger-hover); }

/* --- Toolbar --- */
.toolbar {
    padding: 0.75rem 1.5rem;
    display: flex;
    gap: 0.75rem;
    align-items: center;
    flex-wrap: wrap;
    border-bottom: 1px solid var(--border);
    background: var(--bg-card);
}
#search-input {
    padding: 0.5rem 0.85rem;
    border: 1.5px solid var(--border);
    border-radius: var(--radius);
    font-size: 0.85rem;
    background: var(--bg-input);
    color: var(--text);
    outline: none;
    width: 260px;
    max-width: 100%;
    transition: border-color 0.2s;
}
#search-input:focus { border-color: var(--border-focus); }
.tag-filters { display: flex; gap: 0.4rem; flex-wrap: wrap; }
.tag-chip {
    display: inline-block;
    padding: 0.2rem 0.6rem;
    background: var(--tag-bg);
    color: var(--tag-text);
    border-radius: 20px;
    font-size: 0.75rem;
    cursor: pointer;
    transition: all 0.2s;
    border: 1.5px solid transparent;
    user-select: none;
}
.tag-chip:hover { background: var(--border); }
.tag-chip.active { border-color: var(--accent); background: var(--accent-bg); color: var(--accent); }

/* --- Notes List --- */
main { padding: 1rem 1.5rem; max-width: 900px; margin: 0 auto; }
.notes-list { display: flex; flex-direction: column; gap: 0.6rem; }
.note-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 0.9rem 1.1rem;
    cursor: pointer;
    transition: all 0.15s;
    position: relative;
}
.note-card:hover {
    box-shadow: var(--shadow);
    border-color: var(--border-focus);
}
.note-card.pinned { border-left: 3px solid var(--pin-color); }
.note-card-title {
    font-weight: 600;
    font-size: 0.95rem;
    margin-bottom: 0.2rem;
    display: flex;
    align-items: center;
    gap: 0.4rem;
}
.pin-indicator {
    color: var(--pin-color);
    font-size: 0.75rem;
    font-weight: normal;
}
.note-card-snippet {
    color: var(--text-muted);
    font-size: 0.82rem;
    line-height: 1.5;
    overflow: hidden;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
}
.note-card-meta {
    display: flex;
    gap: 0.5rem;
    align-items: center;
    margin-top: 0.5rem;
    flex-wrap: wrap;
}
.note-card-date {
    font-size: 0.72rem;
    color: var(--text-light);
}
.note-card-tags { display: flex; gap: 0.3rem; flex-wrap: wrap; }
.note-card-tag {
    font-size: 0.68rem;
    padding: 0.1rem 0.45rem;
    background: var(--tag-bg);
    color: var(--tag-text);
    border-radius: 10px;
}
.empty-state {
    text-align: center;
    padding: 4rem 1rem;
    color: var(--text-muted);
    font-size: 0.95rem;
}
.empty-state strong { color: var(--accent); }

/* --- Modal --- */
.modal {
    position: fixed;
    inset: 0;
    z-index: 100;
    display: flex;
    align-items: center;
    justify-content: center;
}
.modal-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(50,45,40,0.35);
    backdrop-filter: blur(2px);
}
.modal-content {
    position: relative;
    background: var(--bg-card);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    width: 95%;
    max-width: 860px;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* --- Editor --- */
.editor-header {
    display: flex;
    align-items: center;
    padding: 0.85rem 1.2rem;
    gap: 0.75rem;
    border-bottom: 1px solid var(--border);
}
.editor-title-input {
    flex: 1;
    border: none;
    outline: none;
    font-size: 1.1rem;
    font-weight: 600;
    background: transparent;
    color: var(--text);
}
.editor-title-input::placeholder { color: var(--text-light); font-weight: 400; }
.editor-actions { display: flex; gap: 0.4rem; }
.editor-tags {
    padding: 0.5rem 1.2rem;
    border-bottom: 1px solid var(--border);
}
#editor-tags-input {
    width: 100%;
    border: none;
    outline: none;
    font-size: 0.82rem;
    color: var(--text-muted);
    background: transparent;
}
#editor-tags-input::placeholder { color: var(--text-light); }
.editor-body { flex: 1; overflow: hidden; min-height: 0; }
.editor-panes {
    display: flex;
    height: 55vh;
}
#editor-content {
    flex: 1;
    border: none;
    outline: none;
    resize: none;
    padding: 1rem 1.2rem;
    font-family: var(--font-mono);
    font-size: 0.85rem;
    line-height: 1.7;
    color: var(--text);
    background: var(--bg-input);
}
#editor-content::placeholder { color: var(--text-light); }
.preview {
    flex: 1;
    padding: 1rem 1.2rem;
    overflow-y: auto;
    border-left: 1px solid var(--border);
    font-size: 0.9rem;
    line-height: 1.7;
}
.preview h1, .preview h2, .preview h3 { margin: 1rem 0 0.5rem; font-family: var(--font); font-weight: 600; }
.preview h1 { font-size: 1.4rem; }
.preview h2 { font-size: 1.2rem; }
.preview h3 { font-size: 1.05rem; }
.preview p { margin-bottom: 0.75rem; }
.preview code {
    font-family: var(--font-mono);
    background: var(--bg-hover);
    padding: 0.15rem 0.35rem;
    border-radius: 4px;
    font-size: 0.85em;
}
.preview pre {
    background: #2d2a26;
    color: #e8dfd4;
    padding: 0.85rem 1rem;
    border-radius: var(--radius);
    overflow-x: auto;
    margin-bottom: 0.75rem;
}
.preview pre code { background: none; padding: 0; color: inherit; }
.preview ul, .preview ol { padding-left: 1.5rem; margin-bottom: 0.75rem; }
.preview blockquote {
    border-left: 3px solid var(--border-focus);
    padding-left: 1rem;
    color: var(--text-muted);
    margin-bottom: 0.75rem;
    font-style: italic;
}
.preview a { color: var(--accent); }
.preview img { max-width: 100%; border-radius: var(--radius); }

/* Editor footer */
.editor-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.5rem 1.2rem;
    border-top: 1px solid var(--border);
    background: var(--bg);
}
.editor-status { font-size: 0.75rem; color: var(--text-light); }
.editor-tabs { display: flex; gap: 0.25rem; }
.tab {
    padding: 0.25rem 0.6rem;
    border: none;
    background: none;
    color: var(--text-muted);
    font-size: 0.75rem;
    cursor: pointer;
    border-radius: var(--radius);
    transition: all 0.15s;
}
.tab:hover { background: var(--bg-hover); }
.tab.active { background: var(--accent-bg); color: var(--accent); }

/* View modes */
.editor-panes.write-only .preview { display: none; }
.editor-panes.write-only #editor-content { flex: 1; }
.editor-panes.preview-only #editor-content { display: none; }
.editor-panes.preview-only .preview { flex: 1; border-left: none; }

/* --- Settings Modal --- */
.settings-content {
    padding: 2rem;
    max-width: 400px;
}
.settings-content h2 {
    font-family: var(--font);
    font-weight: 400;
    margin-bottom: 1.5rem;
}
.settings-content label {
    display: block;
    font-size: 0.82rem;
    color: var(--text-muted);
    margin-bottom: 0.3rem;
}
.settings-content input {
    width: 100%;
    padding: 0.55rem 0.75rem;
    border: 1.5px solid var(--border);
    border-radius: var(--radius);
    font-size: 0.9rem;
    background: var(--bg-input);
    color: var(--text);
    outline: none;
    margin-bottom: 0.75rem;
    transition: border-color 0.2s;
}
.settings-content input:focus { border-color: var(--border-focus); }
.settings-msg { font-size: 0.85rem; margin-top: 0.5rem; }
.settings-msg.ok { color: #5a8a50; }
.settings-msg.err { color: var(--danger); }

/* --- Responsive --- */
@media (max-width: 640px) {
    header { padding: 0.75rem 1rem; }
    .toolbar { padding: 0.6rem 1rem; }
    #search-input { width: 100%; }
    main { padding: 0.75rem 1rem; }
    .modal-content { width: 100%; max-width: 100%; max-height: 100vh; border-radius: 0; }
    .editor-panes { height: 50vh; }
    .editor-panes { flex-direction: column; }
    .preview { border-left: none; border-top: 1px solid var(--border); }
    .editor-header { flex-wrap: wrap; }
    .header-right { gap: 0.3rem; }
    .btn-primary, .btn-ghost { font-size: 0.8rem; padding: 0.4rem 0.65rem; }
}
