:root {
    --bg-primary: #1e1e1e;
    --bg-secondary: #252526;
    --bg-tertiary: #2d2d30;
    --text-primary: #cccccc;
    --text-secondary: #858585;
    --accent: #0e639c;
    --accent-hover: #1177bb;
    --border: #3e3e42;
    --error: #f48771;
    --success: #89d185;

    /* Month colors for calendar */
    --month-color-0: #f97316;
    /* January: Orange */
    --month-color-1: #2563eb;
    /* February: Blue */
    --month-color-2: #dc2626;
    /* March: Red */
    --month-color-3: #10b981;
    /* April: Green */
    --month-color-4: #ec4899;
    /* May: Pink */
    --month-color-5: #3b82f6;
    /* June: Sky Blue */
    --month-color-6: #fbbf24;
    /* July: Yellow */
    --month-color-7: #4338ca;
    /* August: Indigo */
    --month-color-8: #fb923c;
    /* September: Peach */
    --month-color-9: #84cc16;
    /* October: Lime */
    --month-color-10: #e11d48;
    /* November: Rose */
    --month-color-11: #06b6d4;
    /* December: Cyan */
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

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

#app {
    display: grid;
    grid-template-areas:
        "header header header"
        "sidebar handle content";
    grid-template-columns: var(--sidebar-width, 250px) 6px 1fr;
    grid-template-rows: 60px 1fr;
    height: 100vh;
    width: 100vw;
    overflow: hidden;
}

/* Header */
#header {
    grid-area: header;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border);
    padding: 0 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.header-left {
    display: flex;
    align-items: center;
    gap: 15px;
}

.header-left h1 {
    font-size: 1.5rem;
}

.version {
    font-size: 0.7rem;
    color: var(--text-secondary);
    font-weight: normal;
    margin-left: 8px;
}

.status-indicator {
    font-size: 1rem;
    color: var(--text-secondary);
}

.status-indicator.synced {
    color: var(--success);
}

.status-indicator.syncing {
    color: #ffa500;
    animation: pulse 1s infinite;
}

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

.status-indicator.conflict {
    color: #ffa500;
    animation: pulse 0.5s infinite;
}

@keyframes pulse {

    0%,
    100% {
        opacity: 1;
    }

    50% {
        opacity: 0.3;
    }
}

.header-right {
    display: flex;
    gap: 10px;
    align-items: center;
}

button {
    background: var(--bg-tertiary);
    color: var(--text-primary);
    border: 1px solid var(--border);
    padding: 8px 16px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 1rem;
}

button:hover {
    background: var(--accent);
}

/* Sidebar */
#sidebar {
    grid-area: sidebar;
    background: var(--bg-secondary);
    padding: 20px;
    overflow: hidden;
    min-width: 200px;
    max-width: 600px;
    display: flex;
    flex-direction: column;
}

#sidebar nav ul {
    list-style: none;
}

#sidebar nav li {
    margin-bottom: 10px;
}

#sidebar nav a {
    display: block;
    padding: 10px;
    color: var(--text-primary);
    text-decoration: none;
    border-radius: 4px;
}

#sidebar nav a:hover,
#sidebar nav a.active {
    background: var(--accent);
}

#recent-pages {
    margin-top: 30px;
}

#recent-pages.hidden {
    display: none;
}

#recent-pages h3 {
    font-size: 0.9rem;
    color: var(--text-secondary);
    margin-bottom: 10px;
}

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

#recent-list li {
    padding: 5px 0;
}

#recent-list a {
    color: var(--text-primary);
    text-decoration: none;
    font-size: 0.9rem;
}

#recent-list a:hover {
    color: var(--accent);
}

/* Resize Handles */
.resize-handle {
    background: var(--border);
    position: relative;
    z-index: 10;
}

.resize-handle-vertical {
    grid-area: handle;
    cursor: col-resize;
    transition: background 0.2s;
    min-height: 100%;
}

.resize-handle-vertical:hover,
.resize-handle-vertical.resizing {
    background: var(--accent);
}

.resize-handle-vertical::before {
    content: '⋮';
    position: absolute;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
    color: var(--text-secondary);
    font-size: 14px;
    line-height: 1;
    opacity: 0.3;
    transition: opacity 0.2s;
}

.resize-handle-vertical:hover::before,
.resize-handle-vertical.resizing::before {
    opacity: 0.8;
}

/* Main Content */
#content {
    grid-area: content;
    background: var(--bg-primary);
    padding: 20px;
    overflow-y: auto;
    min-width: 0;
}

.view {
    display: none;
}

.view.active {
    display: block;
}

/* Journal View */
.journal-header {
    display: flex;
    align-items: center;
    gap: 15px;
    margin-bottom: 20px;
}

.journal-header h2 {
    flex: 1;
    font-size: 1.8rem;
}

#journal-content {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: 4px;
    padding: 20px;
    min-height: 500px;
}

/* Editor */
.editor {
    font-family: 'Courier New', monospace;
    font-size: 1rem;
    line-height: 1.6;
    white-space: pre-wrap;
    outline: none;
}

.editor[contenteditable="true"] {
    cursor: text;
}

/* Pages View */
.pages-header {
    display: flex;
    gap: 15px;
    margin-bottom: 20px;
}

#page-search {
    flex: 1;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    color: var(--text-primary);
    padding: 10px;
    border-radius: 4px;
    font-size: 1rem;
}

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

#pages-list li {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    padding: 15px;
    margin-bottom: 10px;
    border-radius: 4px;
    cursor: pointer;
}

#pages-list li:hover {
    border-color: var(--accent);
}

/* Graph View */
#graph-canvas {
    width: 100%;
    height: 100%;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: 4px;
}

/* Search View */
#search-input {
    width: 100%;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    color: var(--text-primary);
    padding: 15px;
    border-radius: 4px;
    font-size: 1.2rem;
    margin-bottom: 20px;
}

#search-results {
    display: flex;
    flex-direction: column;
    gap: 15px;
}

.search-result {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    padding: 15px;
    border-radius: 4px;
    cursor: pointer;
}

.search-result:hover {
    border-color: var(--accent);
}

/* Modal */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.8);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.modal.hidden {
    display: none;
}

.modal-content {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 30px;
    max-width: 500px;
    width: 90%;
}

.modal-content h2 {
    margin-bottom: 20px;
}

.modal-content label {
    display: block;
    margin-bottom: 15px;
    color: var(--text-primary);
}

.modal-content input[type="text"],
.modal-content input[type="password"] {
    width: 100%;
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    color: var(--text-primary);
    padding: 10px;
    border-radius: 4px;
    margin-top: 5px;
    font-size: 1rem;
}

.modal-content input[type="checkbox"] {
    margin-right: 10px;
}

.modal-actions {
    display: flex;
    gap: 10px;
    margin-top: 20px;
}

.modal-actions button {
    flex: 1;
}

.btn-danger {
    background: #f48771 !important;
    color: white !important;
}

.btn-danger:hover {
    background: #e25c47 !important;
}

/* Utility Classes */
.hidden {
    display: none !important;
}

.loading {
    text-align: center;
    padding: 50px;
    color: var(--text-secondary);
}

.error {
    background: var(--error);
    color: white;
    padding: 15px;
    border-radius: 4px;
    margin-bottom: 20px;
}

/* Remote Change Notification Banner */
.notification-banner {
    background: linear-gradient(135deg, #ffa500 0%, #ff8c00 100%);
    color: #1e1e1e;
    padding: 12px 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 2px solid #ff8c00;
    font-weight: 500;
    animation: slideDown 0.3s ease-out;
}

@keyframes slideDown {
    from {
        transform: translateY(-100%);
        opacity: 0;
    }

    to {
        transform: translateY(0);
        opacity: 1;
    }
}

.notification-banner span {
    display: flex;
    align-items: center;
    gap: 8px;
}

.banner-actions {
    display: flex;
    gap: 10px;
}

.btn-reload,
.btn-ignore {
    padding: 6px 16px;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-weight: 500;
    font-size: 0.9rem;
    transition: all 0.2s;
}

.btn-reload {
    background: #1e1e1e;
    color: #ffa500;
}

.btn-reload:hover {
    background: #2d2d30;
    transform: scale(1.05);
}

.btn-ignore {
    background: rgba(0, 0, 0, 0.2);
    color: #1e1e1e;
}

.btn-ignore:hover {
    background: rgba(0, 0, 0, 0.3);
}

/* History Sidebar */
#history-sidebar {
    position: fixed;
    top: 60px;
    right: 0;
    bottom: 0;
    width: 300px;
    background: var(--bg-secondary);
    border-left: 2px solid var(--border);
    padding: 12px 8px;
    overflow-y: auto;
    overflow-x: hidden;
    display: flex;
    flex-direction: column;
    transform: translateX(100%);
    transition: transform 0.3s ease-in-out;
    z-index: 100;
    box-shadow: -4px 0 8px rgba(0, 0, 0, 0.3);
}

#history-sidebar.open {
    transform: translateX(0);
}

#history-sidebar h3 {
    margin-bottom: 10px;
    color: var(--text-primary);
    font-size: 0.85rem;
    padding: 0 8px;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

#toggle-history {
    background: transparent;
    border: 1px solid var(--border);
    padding: 4px 8px;
    font-size: 0.9rem;
    cursor: pointer;
    border-radius: 3px;
}

#toggle-history:hover {
    background: var(--accent);
}

#history-list {
    list-style: none;
    padding: 0;
    margin: 0;
    overflow-y: auto;
    flex: 1;
}

.history-date-header {
    font-size: 0.7rem;
    color: var(--text-secondary);
    font-weight: bold;
    padding: 8px 8px 4px 8px;
    margin-top: 8px;
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    background: var(--bg-secondary);
    z-index: 1;
}

.history-date-header:first-child {
    margin-top: 0;
}

.history-item {
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    border-radius: 3px;
    padding: 4px 6px;
    margin: 4px 4px;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    gap: 4px;
    font-size: 0.75rem;
}

.history-item:hover {
    background: var(--bg-primary);
    border-color: var(--accent);
}

.history-time {
    font-size: 0.7rem;
    color: var(--text-secondary);
    font-family: monospace;
    flex-shrink: 0;
    width: 40px;
    white-space: nowrap;
}

.history-actions {
    display: flex;
    align-items: center;
    gap: 3px;
    flex: 1;
    min-width: 0;
}

.history-view,
.history-restore {
    background: transparent;
    border: 1px solid var(--border);
    padding: 2px 4px;
    font-size: 0.75rem;
    border-radius: 3px;
    cursor: pointer;
    min-width: 20px;
    width: 22px;
    height: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.history-view:hover {
    background: var(--accent);
    border-color: var(--accent);
}

.history-restore:hover {
    background: var(--success);
    border-color: var(--success);
}

.history-sha {
    margin-left: auto;
    font-family: monospace;
    font-size: 0.65rem;
    color: var(--text-secondary);
    flex-shrink: 0;
}

.history-size {
    font-family: monospace;
    font-size: 0.6rem;
    color: #555;
    margin-left: 4px;
    flex-shrink: 0;
}

.history-empty,
.history-error {
    padding: 20px 8px;
    text-align: center;
    color: var(--text-secondary);
    font-style: italic;
    font-size: 0.75rem;
}

/* History Modal */
.history-modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.8);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.history-modal-content {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: 8px;
    max-width: 80%;
    max-height: 80%;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

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

.history-modal-header h3 {
    margin: 0;
    font-size: 1.1rem;
}

.close-modal {
    background: transparent;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    padding: 0;
    width: 30px;
    height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.close-modal:hover {
    background: var(--error);
    border-radius: 4px;
}

.history-content {
    padding: 20px;
    overflow: auto;
    font-family: 'Courier New', monospace;
    font-size: 0.9rem;
    white-space: pre-wrap;
    color: var(--text-primary);
}

#clear-settings {
    background: var(--error);
}

#clear-settings:hover {
    background: #d66a55;
}

/* Calendar Config Panel */
.config-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.7);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10000;
}

.config-panel {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: 8px;
    width: 500px;
    max-width: 90%;
    max-height: 80vh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.config-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 15px 20px;
    border-bottom: 1px solid var(--border);
    background: var(--bg-tertiary);
}

.config-header h3 {
    margin: 0;
    font-size: 1.1rem;
    color: var(--text-primary);
}

.config-header .close-btn {
    background: transparent;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    color: var(--text-secondary);
    padding: 0;
    width: 30px;
    height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
}

.config-header .close-btn:hover {
    background: var(--error);
    color: var(--text-primary);
}

.config-content {
    padding: 20px;
    overflow-y: auto;
    flex: 1;
}

.config-section {
    margin-bottom: 20px;
}

.config-section label {
    display: flex;
    flex-direction: column;
    gap: 8px;
    color: var(--text-primary);
    font-size: 0.9rem;
}

.config-section select,
.config-section input[type="number"] {
    padding: 8px 12px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    border-radius: 4px;
    color: var(--text-primary);
    font-size: 0.9rem;
}

.config-section select:focus,
.config-section input[type="number"]:focus {
    outline: none;
    border-color: var(--accent);
}

.config-section input[type="checkbox"] {
    margin-right: 8px;
}

.config-section label:has(input[type="checkbox"]) {
    flex-direction: row;
    align-items: center;
}

.config-footer {
    display: flex;
    gap: 10px;
    justify-content: flex-end;
    padding: 15px 20px;
    border-top: 1px solid var(--border);
    background: var(--bg-tertiary);
}

.config-footer button {
    padding: 8px 16px;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.9rem;
}

.config-footer .btn-primary {
    background: var(--accent);
    color: var(--text-primary);
}

.config-footer .btn-primary:hover {
    background: var(--accent-hover);
}

.config-footer .btn-secondary {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    color: var(--text-primary);
}

.config-footer .btn-secondary:hover {
    background: var(--bg-tertiary);
}
