/* ===== CSS Custom Properties ===== */
:root {
    --accent: #6366f1;
    --accent-light: #eef2ff;
    --accent-hover: #eff6ff;
    --gray-header: #e8e8ed;
    --gray-border: #e5e7eb;
    --gray-mid: #6b7280;
    --text: #111827;
    --bg: #f8f9fa;
}

/* ===== Base ===== */
*, *::before, *::after { box-sizing: border-box; }

body {
    background-color: var(--bg);
    font-family: 'Inter', system-ui, sans-serif;
    font-size: 16px;
    color: var(--text);
    margin: 0;
}

ul { list-style-type: none; margin: 0; padding: 0; }

/* ===== Header ===== */
.jana-header {
    background: #fff;
    border-bottom: 1px solid var(--gray-border);
    padding: 8px 16px;
    display: flex;
    align-items: center;
    gap: 8px;
    position: sticky;
    top: 0;
    z-index: 100;
    min-height: 48px;
}
.jana-logo {
    font-size: 16px;
    font-weight: 800;
    color: var(--accent);
    letter-spacing: 0.02em;
    white-space: nowrap;
}
.jana-version {
    font-size: 12px;
    font-weight: 400;
    color: var(--text-muted, #9ca3af);
    letter-spacing: 0;
    vertical-align: middle;
}
.jana-toolbar {
    display: flex;
    align-items: center;
    gap: 4px;
}
.jana-btn {
    background: #f3f4f6;
    border: none;
    border-radius: 6px;
    padding: 8px 12px;
    cursor: pointer;
    color: #374151;
    font-size: 16px;
    line-height: 1;
    transition: background 0.15s;
    font-family: inherit;
}
.jana-btn:hover { background: var(--gray-border); }
.jana-user {
    margin-left: auto;
    display: flex;
    align-items: center;
    gap: 6px;
    color: var(--gray-mid);
    font-size: 15px;
    white-space: nowrap;
}
#errorsPanel {
    font-size: 12px;
    color: #ef4444;
    padding: 4px 16px;
}

/* ===== Sidebar ===== */
.jana-sidebar-header {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 10px 12px 4px;
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.07em;
    font-weight: 600;
    color: var(--gray-mid);
}
#lista { padding: 0 8px 16px; }
#lista ul, #lista ol { padding-left: 0; }

/* Folder li */
li[data-id] {
    margin: 2px 0;
    padding: 0 !important;
}
.folder-row {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 8px 10px;
    border-radius: 8px;
    cursor: pointer;
    color: var(--text);
    transition: background 0.1s;
    user-select: none;
}
.folder-row:hover { background: var(--accent-hover); }
.folder-row.open {
    background: var(--accent-hover);
    color: #1d4ed8;
}
.folder-row.open .folder-name { font-weight: 600; }
.folder-chevron {
    color: #9ca3af;
    font-size: 10px;
    width: 12px;
    flex-shrink: 0;
    transition: transform 0.15s ease;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}
.folder-chevron.open {
    color: var(--accent);
    transform: rotate(90deg);
}
.folder-name { flex: 1; font-size: 15px; }
.folder-count {
    font-size: 13px;
    color: #9ca3af;
    margin-left: auto;
}

/* Note items */
.noteItem {
    display: flex;
    flex-direction: column;
    padding: 8px 10px 8px 28px;
    border-radius: 6px;
    cursor: pointer;
    list-style: none;
    transition: background 0.1s;
    margin: 2px 0;
}
.noteItem:hover { background: #f9fafb; }
.noteItem.active {
    background: var(--accent-light);
    border-left: 2px solid var(--accent);
    padding-left: 26px;
}
.note-title {
    font-weight: 500;
    font-size: 15px;
    color: var(--text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.note-snippet {
    font-size: 13px;
    color: #9ca3af;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-top: 2px;
}

/* ===== Editor Nota ===== */
#notaspace {
    display: none;
    flex-direction: column;
}
.nota-header {
    background: var(--gray-header);
    border-bottom: 1px solid #d1d5db;
    padding: 12px 16px;
}
#notadirectory, .nota-breadcrumb {
    font-size: 11px;
    color: var(--accent);
    text-transform: uppercase;
    letter-spacing: 0.06em;
    font-weight: 600;
    margin-bottom: 4px;
    display: block;
}
#notatitle {
    font-size: 20px;
    font-weight: 700;
    color: var(--text);
    border: none;
    background: transparent;
    width: 100%;
    outline: none;
    font-family: inherit;
    padding: 0;
}
.nota-body {
    background: #fff;
    padding: 16px;
    flex: 1;
    display: flex;
    flex-direction: column;
}
#notatext {
    font-size: 17px;
    line-height: 1.7;
    color: #374151;
    min-height: 10em;
    outline: none;
    width: 100%;
    flex: 1;
}
.nota-actions {
    display: flex;
    gap: 8px;
    padding-top: 12px;
    border-top: 1px solid var(--gray-border);
    margin-top: 12px;
}
#notasave {
    background: var(--accent);
    color: #fff;
    border: none;
    border-radius: 6px;
    padding: 10px 24px;
    font-weight: 600;
    font-size: 16px;
    cursor: pointer;
    font-family: inherit;
    transition: background 0.15s;
}
#notasave:hover { background: #4f46e5; }
#notadelete {
    background: transparent;
    color: #ef4444;
    border: 1px solid #fca5a5;
    border-radius: 6px;
    padding: 10px 24px;
    font-size: 16px;
    cursor: pointer;
    font-family: inherit;
    transition: border-color 0.15s;
}
#notadelete:hover { border-color: #ef4444; }

/* ===== Mobile Back Button ===== */
#mobileBack {
    display: none;
    align-items: center;
    gap: 6px;
    padding: 8px 16px;
    background: var(--bg);
    border: none;
    border-bottom: 1px solid var(--gray-border);
    cursor: pointer;
    color: var(--accent);
    font-weight: 600;
    font-size: 13px;
    font-family: inherit;
    width: 100%;
    text-align: left;
}

/* ===== Log Panel ===== */
#logs {
    background-color: #f1f1f1;
    border-top: 1px solid var(--gray-border);
    font-size: 11px;
    color: var(--gray-mid);
    white-space: pre-line;
    line-height: 1.4;
    max-height: calc(1.4em + 8px);
    overflow: hidden;
    padding: 4px 8px;
    cursor: pointer;
    transition: max-height 0.2s ease;
    font-family: monospace;
}
#logs.logs-expanded {
    max-height: 120px;
    overflow-y: auto;
}

/* ===== Ricerca ===== */
#searchSpace { padding: 12px 8px; }
#searchInput {
    border: 1px solid var(--gray-border);
    border-radius: 8px;
    padding: 8px 12px;
    font-size: 14px;
    width: 100%;
    outline: none;
    font-family: inherit;
    transition: border-color 0.15s;
    background: #fff;
}
#searchInput:focus { border-color: var(--accent); }
#searchResults {
    max-height: 400px;
    overflow-y: auto;
    margin-top: 8px;
    border: none;
    border-radius: 0;
    padding: 0 12px;
}
.search-result-item {
    padding: 8px 12px;
    border-radius: 6px;
    cursor: pointer;
    border-bottom: 1px solid var(--gray-border);
}
.search-result-item:hover { background: var(--accent-hover); }
.search-result-folder {
    font-size: 11px;
    color: var(--gray-mid);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    margin-bottom: 2px;
}
.search-result-title {
    font-weight: 600;
    color: var(--text);
    font-size: 13px;
}
.search-result-snippet {
    font-size: 11px;
    color: #9ca3af;
    margin-top: 1px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* ===== Desktop ===== */
@media (min-width: 768px) {
    #notaspace {
        position: sticky;
        top: 48px;
        align-self: flex-start;
        height: calc(100vh - 48px);
        overflow-y: auto;
        background: var(--bg);
    }
    .nota-body { min-height: calc(100vh - 200px); }
}

/* ===== Mobile ===== */
@media (max-width: 767px) {
    .jana-logo { font-size: 18px; }
    .jana-btn { padding: 8px 10px; font-size: 18px; }
    #userData { display: none; }
    .folder-name { font-size: 17px; }
    .folder-row { padding: 10px 12px; }
    .note-title { font-size: 16px; }
    .note-snippet { font-size: 14px; }
    .noteItem { padding: 10px 12px 10px 32px; }
    #notatitle { font-size: 22px; }
    #notatext { font-size: 18px; }
    #notasave, #notadelete { padding: 12px 28px; font-size: 17px; }
    #mobileBack { font-size: 17px; padding: 12px 16px; }
    #searchInput { font-size: 17px; padding: 12px 14px; }
    .search-result-title { font-size: 16px; }
    .search-result-snippet { font-size: 14px; }
    .jana-sidebar-header { font-size: 13px; }
    #logs { font-size: 13px; }
    #errorsPanel { font-size: 14px; }
}
