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

:root {
    --bg-primary: #ffffff;
    --bg-secondary: #f5f5f7;
    --bg-tertiary: #e8e8ed;
    --text-primary: #1d1d1f;
    --text-secondary: #6e6e73;
    --accent: #007aff;
    --accent-hover: #0056b3;
    --border: #d2d2d7;
    --sidebar-width: 220px;
    --notelist-width: 280px;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    min-height: 100vh;
}

.screen {
    min-height: 100vh;
}

.hidden {
    display: none !important;
}

/* ===== Auth Screen ===== */
#auth-screen {
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-secondary);
}

.auth-container {
    text-align: center;
    padding: 3rem;
    background: var(--bg-primary);
    border-radius: 16px;
    box-shadow: 0 4px 24px rgba(0, 0, 0, 0.1);
}

.auth-container h1 {
    font-size: 2.5rem;
    margin-bottom: 0.5rem;
    background: linear-gradient(135deg, #007aff, #5856d6);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.auth-container p {
    color: var(--text-secondary);
    margin-bottom: 2rem;
}

#apple-sign-in-button {
    display: inline-block;
}

/* ===== App Layout ===== */
#app-screen {
    display: grid;
    grid-template-columns: var(--sidebar-width) var(--notelist-width) 1fr;
    min-height: 100vh;
}

/* ===== Sidebar ===== */
#sidebar {
    background: var(--bg-secondary);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
}

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

.sidebar-header h2 {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.icon-btn {
    width: 28px;
    height: 28px;
    border: none;
    border-radius: 6px;
    background: var(--accent);
    color: white;
    font-size: 1.2rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
}

.icon-btn:hover {
    background: var(--accent-hover);
}

#folder-list {
    list-style: none;
    flex: 1;
    overflow-y: auto;
    padding: 0.5rem 0;
}

#folder-list li {
    padding: 0.6rem 1rem;
    cursor: pointer;
    transition: background 0.2s;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.95rem;
}

#folder-list li:hover {
    background: var(--bg-tertiary);
}

#folder-list li.active {
    background: var(--accent);
    color: white;
}

#folder-list li .folder-icon {
    opacity: 0.8;
}

#folder-list li .note-count {
    margin-left: auto;
    font-size: 0.75rem;
    color: var(--text-secondary);
    background: var(--bg-primary);
    padding: 0.15rem 0.5rem;
    border-radius: 10px;
}

#folder-list li.active .note-count {
    background: rgba(255, 255, 255, 0.25);
    color: white;
}

.sidebar-footer {
    padding: 1rem;
    border-top: 1px solid var(--border);
}

#sign-out-btn {
    width: 100%;
    padding: 0.5rem;
    background: transparent;
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all 0.2s;
    font-size: 0.9rem;
}

#sign-out-btn:hover {
    background: var(--bg-tertiary);
    color: var(--text-primary);
}

/* ===== Note List Panel ===== */
#note-list-panel {
    background: var(--bg-primary);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
}

.panel-header {
    padding: 1rem;
    border-bottom: 1px solid var(--border);
}

.panel-header h2 {
    font-size: 1.1rem;
    margin-bottom: 0.75rem;
    font-weight: 600;
}

#search-input {
    width: 100%;
    padding: 0.5rem 0.75rem;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text-primary);
    font-size: 0.9rem;
}

#search-input:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(0, 122, 255, 0.15);
}

#search-input::placeholder {
    color: var(--text-secondary);
}

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

#note-list li {
    padding: 0.875rem 1rem;
    border-bottom: 1px solid var(--border);
    cursor: pointer;
    transition: background 0.2s;
}

#note-list li:hover {
    background: var(--bg-secondary);
}

#note-list li.active {
    background: var(--accent);
    color: white;
}

#note-list li .note-item-title {
    font-weight: 500;
    margin-bottom: 0.2rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

#note-list li .note-item-preview {
    font-size: 0.85rem;
    color: var(--text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

#note-list li.active .note-item-preview {
    color: rgba(255, 255, 255, 0.85);
}

#note-list li .note-item-date {
    font-size: 0.75rem;
    color: var(--text-secondary);
    margin-top: 0.2rem;
}

#note-list li.active .note-item-date {
    color: rgba(255, 255, 255, 0.7);
}

#note-list .pinned-indicator {
    color: #ff9500;
    margin-right: 0.25rem;
}

/* ===== Note Viewer ===== */
#note-viewer {
    background: var(--bg-primary);
    overflow-y: auto;
}

#note-placeholder {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100%;
    color: var(--text-secondary);
}

#note-content {
    max-width: 800px;
    margin: 0 auto;
    padding: 2rem;
}

#note-content header {
    margin-bottom: 2rem;
    padding-bottom: 1rem;
    border-bottom: 1px solid var(--border);
}

#note-title {
    font-size: 2rem;
    font-weight: 600;
    margin-bottom: 0.5rem;
    color: var(--text-primary);
}

#note-meta {
    font-size: 0.85rem;
    color: var(--text-secondary);
}

#note-body {
    position: relative;
}

#note-text {
    font-size: 1rem;
    line-height: 1.7;
    white-space: pre-wrap;
    color: var(--text-primary);
}

#note-text p {
    margin-bottom: 1rem;
}

#note-drawing {
    max-width: 100%;
    margin-top: 1rem;
    border-radius: 8px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

#note-drawing[src=""] {
    display: none;
}

/* ===== Modal ===== */
.modal {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.4);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
}

.modal-content {
    background: var(--bg-primary);
    border-radius: 12px;
    padding: 1.5rem;
    width: 90%;
    max-width: 500px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.2);
}

.modal-content h2 {
    margin-bottom: 1.5rem;
    font-weight: 600;
}

.modal-content label {
    display: block;
    font-size: 0.9rem;
    color: var(--text-secondary);
    margin-bottom: 0.5rem;
}

.modal-content input,
.modal-content textarea,
.modal-content select {
    width: 100%;
    padding: 0.75rem;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text-primary);
    font-size: 1rem;
    margin-bottom: 1rem;
    font-family: inherit;
}

.modal-content input:focus,
.modal-content textarea:focus,
.modal-content select:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(0, 122, 255, 0.15);
}

.modal-content textarea {
    resize: vertical;
}

.modal-actions {
    display: flex;
    gap: 0.75rem;
    justify-content: flex-end;
    margin-top: 0.5rem;
}

.modal-actions button {
    padding: 0.6rem 1.25rem;
    border-radius: 8px;
    font-size: 0.95rem;
    cursor: pointer;
    transition: all 0.2s;
}

.modal-actions button[type="button"] {
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text-primary);
}

.modal-actions button[type="button"]:hover {
    background: var(--bg-secondary);
}

.modal-actions button[type="submit"] {
    background: var(--accent);
    border: none;
    color: white;
}

.modal-actions button[type="submit"]:hover {
    background: var(--accent-hover);
}

/* ===== Loading States ===== */
.loading {
    text-align: center;
    padding: 2rem;
    color: var(--text-secondary);
}

.loading::after {
    content: '';
    display: inline-block;
    width: 1rem;
    height: 1rem;
    border: 2px solid var(--border);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    margin-left: 0.5rem;
    vertical-align: middle;
}

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

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

/* ===== Responsive ===== */
@media (max-width: 900px) {
    #app-screen {
        grid-template-columns: 1fr;
    }
    
    #sidebar {
        position: fixed;
        left: -100%;
        top: 0;
        bottom: 0;
        width: var(--sidebar-width);
        z-index: 50;
        transition: left 0.3s;
    }
    
    #sidebar.open {
        left: 0;
    }
    
    #note-list-panel {
        display: none;
    }
    
    #note-viewer {
        padding: 1rem;
    }
}
