/* Reset and base styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --primary: #4b5563;
    --primary-hover: #374151;
    --danger: #dc2626;
    --danger-hover: #b91c1c;
    --bg: #f8fafc;
    --bg-card: #ffffff;
    --text: #1e293b;
    --text-muted: #64748b;
    --border: #e2e8f0;
    --sidebar-bg: #f1f5f9;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.6;
}

.hidden {
    display: none !important;
}

/* Login Screen */
.login-container {
    max-width: 400px;
    margin: 100px auto;
    padding: 40px;
    background: var(--bg-card);
    border-radius: 12px;
    box-shadow: 0 4px 6px -1px rgb(0 0 0 / 0.1);
}

.login-container h1 {
    text-align: center;
    margin-bottom: 8px;
}

.subtitle {
    text-align: center;
    color: var(--text-muted);
    margin-bottom: 32px;
}

.form-group {
    margin-bottom: 20px;
}

.form-group label {
    display: block;
    margin-bottom: 6px;
    font-weight: 500;
}

.form-group input,
.form-group textarea {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 16px;
}

.form-group input:focus,
.form-group textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgb(75 85 99 / 0.1);
}

button {
    padding: 10px 20px;
    border: none;
    border-radius: 6px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.2s;
}

button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

#login-btn {
    width: 100%;
    background: var(--primary);
    color: white;
}

#login-btn:hover:not(:disabled) {
    background: var(--primary-hover);
}

.status {
    margin-top: 16px;
    text-align: center;
    font-size: 14px;
}

.status.error {
    color: var(--danger);
}

.status.info {
    color: var(--text-muted);
}

/* Main Screen */
#main-screen {
    display: flex;
    flex-direction: column;
    height: 100vh;
}

header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 24px;
    background: var(--bg-card);
    border-bottom: 1px solid var(--border);
}

header h1 {
    font-size: 20px;
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 16px;
}

#current-user {
    color: var(--text-muted);
}

#logout-btn {
    background: none;
    color: var(--text-muted);
    padding: 6px 12px;
}

#logout-btn:hover {
    color: var(--text);
    background: var(--bg);
}

main {
    display: flex;
    flex: 1;
    overflow: hidden;
}

/* Sidebar */
#sidebar {
    width: 200px;
    background: var(--sidebar-bg);
    padding: 20px;
    border-right: 1px solid var(--border);
    overflow-y: auto;
}

#sidebar h2 {
    font-size: 14px;
    text-transform: uppercase;
    color: var(--text-muted);
    margin-bottom: 12px;
}

#tag-list {
    list-style: none;
}

.tag-item {
    padding: 8px 12px;
    border-radius: 6px;
    cursor: pointer;
    margin-bottom: 4px;
}

.tag-item:hover {
    background: var(--border);
}

.tag-item.active {
    background: var(--primary);
    color: white;
}

/* Content */
#content {
    flex: 1;
    padding: 24px;
    overflow-y: auto;
}

.list-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
}

#new-note-btn {
    background: var(--primary);
    color: white;
}

#new-note-btn:hover {
    background: var(--primary-hover);
}

/* Note Card */
.note-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 16px;
    margin-bottom: 12px;
    cursor: pointer;
    transition: border-color 0.2s;
}

.note-card:hover {
    border-color: var(--primary);
}

.note-card h3 {
    margin-bottom: 8px;
}

.note-card .preview {
    color: var(--text-muted);
    font-size: 14px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.note-card .meta {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 12px;
    font-size: 12px;
    color: var(--text-muted);
}

/* Tag badge */
.tag {
    display: inline-block;
    padding: 2px 8px;
    background: var(--sidebar-bg);
    border-radius: 4px;
    font-size: 12px;
}

/* Note Detail */
.detail-header,
.edit-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 24px;
}

.detail-actions {
    display: flex;
    gap: 8px;
}

#back-btn,
#cancel-edit-btn {
    background: none;
    color: var(--text-muted);
}

#back-btn:hover,
#cancel-edit-btn:hover {
    color: var(--text);
}

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

#edit-btn:hover {
    background: var(--primary-hover);
}

#save-note-btn {
    background: var(--primary);
    color: white;
}

#save-note-btn:hover {
    background: var(--primary-hover);
}

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

.danger:hover {
    background: var(--danger-hover);
}

#note-content {
    background: var(--bg-card);
    padding: 24px;
    border-radius: 8px;
    border: 1px solid var(--border);
}

#note-title {
    margin-bottom: 8px;
}

#note-tag {
    margin-bottom: 20px;
}

#note-body {
    line-height: 1.8;
}

#note-body h1,
#note-body h2,
#note-body h3 {
    margin-top: 24px;
    margin-bottom: 12px;
}

#note-body p {
    margin-bottom: 16px;
}

#note-body code {
    background: var(--sidebar-bg);
    padding: 2px 6px;
    border-radius: 4px;
    font-family: 'Monaco', 'Menlo', monospace;
}

#note-body pre {
    background: var(--sidebar-bg);
    padding: 16px;
    border-radius: 6px;
    overflow-x: auto;
    margin-bottom: 16px;
}

#note-body pre code {
    background: none;
    padding: 0;
}

/* Attachments */
#attachments-section {
    margin-top: 24px;
    padding: 20px;
    background: var(--bg-card);
    border-radius: 8px;
    border: 1px solid var(--border);
}

#attachments-section h3 {
    margin-bottom: 16px;
}

#attachments-list {
    list-style: none;
    margin-bottom: 16px;
}

#attachments-list li {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 0;
    border-bottom: 1px solid var(--border);
}

.upload-area {
    display: flex;
    gap: 12px;
    align-items: center;
}

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

/* Edit View */
#edit-content {
    font-family: 'Monaco', 'Menlo', monospace;
    resize: vertical;
    min-height: 300px;
}

/* Loading Overlay */
#loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(255, 255, 255, 0.9);
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    z-index: 1000;
}

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

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

#loading-message {
    margin-top: 16px;
    color: var(--text-muted);
}

/* Empty state */
.empty-state {
    text-align: center;
    padding: 60px 20px;
    color: var(--text-muted);
}

/* Responsive */
@media (max-width: 768px) {
    main {
        flex-direction: column;
    }

    #sidebar {
        width: 100%;
        border-right: none;
        border-bottom: 1px solid var(--border);
    }

    #tag-list {
        display: flex;
        flex-wrap: wrap;
        gap: 8px;
    }

    .tag-item {
        margin-bottom: 0;
    }
}
