@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap');

:root {
    --bg-surface: #131314;
    --bg-panel: #1f1f20;
    --bg-element: #2a2a2c;
    --bg-element-hover: #3c3c3e;
    --brand-red: #d94242;
    --brand-red-hover: #e15a5a;
    --text-primary: #e8eaed;
    --text-secondary: #9aa0a6;
    --border-color: #3c3c3e;
    --star-color: #fbbc04;
    --speeddial-color: #8ab4f8;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
input:focus, select:focus, textarea:focus, button:focus { outline: none; }
body { font-family: 'Inter', sans-serif; background-color: var(--bg-surface); color: var(--text-primary); font-size: 14px; line-height: 1.5; overflow: hidden; }
.hidden { display: none !important; }
.no-results-message { color: var(--text-secondary); text-align: center; margin-top: 2rem; }
#backdrop { position: fixed; top: 0; left: 0; width: 100%; height: 100%; background-color: rgba(0,0,0,0.5); z-index: 998; }

/* --- Login Page Styles --- */
.login-body { display: flex; justify-content: center; align-items: center; height: 100dvh; padding: 1rem; }
.login-container { width: 100%; max-width: 400px; background-color: var(--bg-panel); border: 1px solid var(--border-color); border-radius: 12px; padding: 2.5rem; text-align: center; }
.login-container .logo { font-size: 2rem; font-weight: 600; color: var(--text-primary); margin-bottom: 0.5rem; }
.login-subtitle { color: var(--text-secondary); margin-bottom: 2rem; }
.login-container .form-group { margin-bottom: 1.5rem; text-align: left; }
.login-container .form-group label { display: block; font-size: 0.9rem; font-weight: 500; color: var(--text-secondary); margin-bottom: 0.5rem; }
.input-wrapper { position: relative; }
.input-wrapper i { position: absolute; left: 15px; top: 50%; transform: translateY(-50%); color: var(--text-secondary); }
.login-container input { width: 100%; background: var(--bg-element); border: 1px solid var(--border-color); border-radius: 8px; padding: 12px 12px 12px 45px; color: var(--text-primary); font-size: 1rem; transition: border-color 0.2s; }
.login-container input:focus { border-color: var(--brand-red); }
.login-container button { width: 100%; padding: 12px; background: var(--brand-red); border: none; border-radius: 8px; color: #fff; font-size: 1rem; font-weight: 500; cursor: pointer; transition: background 0.2s; }
.login-container button:hover { background: var(--brand-red-hover); }
.error-message { color: var(--brand-red); margin-top: 1rem; height: 1em; font-size: 0.9rem; }

/* --- App Layout --- */
.app-container { display: flex; height: 100dvh; position: relative; }
.sidebar-left { width: 340px; background: var(--bg-surface); padding: 1rem; display: flex; flex-direction: column; transition: padding 0.3s ease, transform 0.3s ease, width 0.3s ease; border-right: 1px solid var(--border-color); flex-shrink: 0; z-index: 1000; }
.main-content { flex-grow: 1; display: flex; flex-direction: column; overflow: hidden; }
/* REVERTED: Sidebar is hidden by default using a class, not by default styles */
.sidebar-right { width: var(--editor-width); background: var(--bg-surface); border-left: 1px solid var(--border-color); display: none; flex-direction: column; flex-shrink: 0; z-index: 1001; position: relative; }
.sidebar-right {
    width: var(--editor-width);
    background: var(--bg-surface);
    border-left: 1px solid var(--border-color);
    display: flex; /* REVERTED: The sidebar is now part of the layout by default */
    flex-direction: column;
    flex-shrink: 0;
    z-index: 1001;
    position: relative;
}

/*
    This is the ONLY rule needed for auto-hiding.
    If the setting is enabled, it hides the sidebar ONLY when the placeholder is visible.
    If the setting is disabled, this rule does nothing, and the sidebar remains visible.
*/
.app-container.sidebar-auto-close-enabled:not(.editor-visible) .sidebar-right:has(#edit-panel-placeholder:not(.hidden)) {
    display: none;
}
.app-container.sidebar-auto-close-enabled:not(.editor-visible) .resizer#resizer-right:has(+ .sidebar-right:has(#edit-panel-placeholder:not(.hidden))) {
    display: none;
}


/* Left Sidebar Global Structure */
.sidebar-header { display: flex; justify-content: space-between; align-items: center;}
#sidebar-toggle-btn { background: none; border: none; color: var(--text-secondary); cursor: pointer; font-size: 1rem; padding: 5px; }
.sidebar-footer { padding-top: 1rem; border-top: 1px solid var(--border-color); }

/* App Switcher */
#app-switcher { position: relative; flex-grow: 1; margin-right: 1rem; }
#app-switcher-btn { display: flex; align-items: center; width: 100%; padding: 10px 12px; background-color: transparent; border: 0px; border-radius: 6px; color: var(--text-primary); font-size: 1.1rem; font-weight: 600; cursor: pointer; text-align: left; transition: background-color 0.2s; }
#app-switcher-btn:hover { background-color: var(--bg-element-hover); }
#app-switcher-btn > i:first-child { margin-right: 12px; width: 20px; text-align: center; color: var(--brand-red); }
#app-switcher-btn span { flex-grow: 1; }
#app-switcher-btn .switcher-arrow { font-size: 0.8rem; color: var(--text-secondary); transition: transform 0.2s; }
#app-switcher-list { position: absolute; top: calc(100% + 8px); left: 0; width: 100%; background-color: var(--bg-element); border: 1px solid var(--border-color); border-radius: 6px; z-index: 1001; padding: 6px; box-shadow: 0 8px 16px rgba(0,0,0,0.3); }
#app-switcher-btn.open .switcher-arrow { transform: rotate(180deg); }
.app-switcher-item { display: flex; align-items: center; padding: 10px 12px; color: var(--text-secondary); text-decoration: none; border-radius: 4px; font-weight: 500; cursor: pointer; }
.app-switcher-item:hover { background-color: var(--bg-element-hover); color: var(--text-primary); }
.app-switcher-item i { width: 20px; text-align: center; margin-right: 12px; }
#app-switcher-toggle-view:hover { background-color: var(--bg-element-hover); color: var(--text-primary); }
#app-switcher-toggle-view i { color: var(--brand-red); }

/* App Switcher Divider */
.app-switcher-divider {
    height: 1px;
    background-color: var(--border-color);
    margin: 6px 0;
}

/* Resizers */
.resizer { width: 5px; background-color: var(--bg-surface); cursor: col-resize; flex-shrink: 0; z-index: 999; transition: background-color 0.2s; }
.resizer:hover, .is-resizing .resizer { background-color: var(--brand-red); }
.is-resizing { user-select: none; cursor: col-resize !important; }
.is-resizing * { pointer-events: none; }

/* Main Content Global Structure */
.main-content-header { padding: 1rem 2rem; flex-shrink: 0; display: flex; align-items: center; gap: 1rem; }
.links-grid-container { flex-grow: 1; overflow-y: auto; padding: 0 2rem 2rem 2rem; }

/* Placeholder for empty header */
.main-header-placeholder {
    color: var(--text-secondary);
    font-size: 1.1rem;
    font-weight: 500;
}

/* Global Search Container */
.search-container { position: relative; width: 100%; max-width: 720px; flex-grow: 1; }
.search-container i { position: absolute; left: 15px; top: 50%; transform: translateY(-50%); color: var(--text-secondary); }
.search-container input { width: 100%; padding: 12px 20px 12px 45px; background-color: var(--bg-panel); border: 1px solid var(--border-color); border-radius: 8px; color: var(--text-primary); font-size: 1rem; }

/* Global Header Action Button */
.main-header-actions {
    margin-left: auto;
}
.header-action-btn {
    display: block;
    background: var(--bg-element);
    color: var(--text-secondary);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    padding: 10px 12px;
    cursor: pointer;
    font-size: 1rem;
    transition: all 0.2s;
}
.header-action-btn:hover {
    background-color: var(--bg-element-hover);
    color: var(--text-primary);
}
.header-action-btn i {
    margin-right: 0; /* No margin for icon-only buttons */
}
.header-action-btn span {
    margin-left: 8px;
}
@media (max-width: 768px) {
    .header-action-btn span {
        display: none; /* Hide text on mobile for icon-only buttons */
    }
}


/* Mobile-only Buttons */
.mobile-only-btn { display: none; background: none; border: none; color: var(--text-secondary); font-size: 1.2rem; cursor: pointer; z-index: 2; }

/* Right Sidebar Global Structure */
#close-editor-btn { position: absolute; top: 1rem; right: 1rem; display: none;}
#edit-panel-placeholder { text-align: center; color: var(--text-secondary); margin-top: 4rem; padding: 1.5rem; }
#edit-panel-placeholder i { font-size: 3rem; margin-bottom: 1rem; }

/* Toast Notifications */
#toast-container { position: fixed; bottom: 20px; right: 20px; z-index: 2000; }
.toast { background-color: #323232; color: #fff; padding: 10px 20px; border-radius: 6px; margin-top: 10px; opacity: 0; transform: translateY(20px); transition: opacity 0.3s, transform 0.3s; }
.toast.success { background-color: #2e7d32; }
.toast.error { background-color: #c62828; }
.toast.show { opacity: 1; transform: translateY(0); }

/* --- Modal Styles --- */
.modal-overlay { position: fixed; top: 0; left: 0; width: 100%; height: 100%; background-color: rgba(0,0,0,0.6); display: flex; justify-content: center; align-items: center; z-index: 1002; }
.modal-content { background-color: var(--bg-panel); padding: 2rem; border-radius: 8px; width: 90%; max-width: 450px; border: 1px solid var(--border-color); }
.modal-content h3 { margin-bottom: 1rem; font-size: 1.25rem; }
.modal-content p { color: var(--text-secondary); margin-bottom: 2rem; line-height: 1.6; }
.modal-actions { display: flex; justify-content: flex-end; gap: 1rem; }
.modal-actions button { padding: 10px 20px; border-radius: 6px; border: none; cursor: pointer; font-weight: 500; }
.modal-actions .btn-secondary { background-color: var(--bg-element); color: var(--text-primary); }
.modal-actions .btn-danger { background-color: var(--brand-red); color: white; }

/* --- Global Component Styles (for re-use in apps) --- */
.nav-item { display: flex; align-items: center; padding: 10px 12px; border-radius: 20px; text-decoration: none; color: var(--text-secondary); font-weight: 500; transition: all 0.2s ease; background: none; border: none; width: 100%; font-family: 'Inter'; font-size: 14px; cursor: pointer; }
.nav-item i { margin-right: 16px; font-size: 1rem; width: 20px; text-align: center; }
.nav-item:hover { background-color: var(--bg-element); color: var(--text-primary); }
.nav-item.active { background-color: var(--bg-element-hover); color: var(--text-primary); }
/* New rule for the scrollable container */
#app-sidebar-scroll-container {
    flex-grow: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding-bottom: 1rem; /* Add some space at the bottom of the scroll area */
}

.sidebar-section {
    display: flex; /* REMOVED flex-grow and overflow */
    flex-direction: column;
    margin-top: 20px;
}
.section-inline { flex-grow: 0; }
.section-title { color: var(--text-secondary); font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.5px; margin-bottom: 1rem; display: flex; align-items: center; padding: 0 12px; flex-shrink: 0; }
.sidebar-section { flex-grow: 1; overflow: hidden; display: flex; flex-direction: column; margin-top: 20px;}
.section-inline { flex-grow: 0; }
.section-title { color: var(--text-secondary); font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.5px; margin-bottom: 1rem; display: flex; align-items: center; padding: 0 12px; flex-shrink: 0; }
.section-title i { margin-right: 12px; }

/* Collapsed Sidebar */
.sidebar-left.collapsed { width: 68px !important; padding: 1rem 0.5rem; }
.sidebar-left.collapsed .logo, .sidebar-left.collapsed .section-title span, .sidebar-left.collapsed .nav-item span, .sidebar-left.collapsed .add-tag-input, .sidebar-left.collapsed .tag-filter-item span, .sidebar-left.collapsed .delete-tag-icon { display: none; }
.sidebar-left.collapsed .sidebar-header { justify-content: space-between; flex-direction: column; align-items: center; gap: 1rem; }
.sidebar-left.collapsed #sidebar-toggle-btn i { transform: rotate(180deg); }
.sidebar-left.collapsed .nav-item, .sidebar-left.collapsed .section-title { justify-content: center; padding: 10px; }
.sidebar-left.collapsed .tag-filter-item { justify-content: center; }
.sidebar-left.collapsed .nav-item i, .sidebar-left.collapsed .section-title i { margin-right: 0; }
.sidebar-left.collapsed .add-tag-container { justify-content: center; }
.sidebar-left.collapsed #add-tag-btn { border-radius: 4px; border-left: 1px solid var(--border-color); }
.sidebar-left.collapsed #app-switcher-btn { justify-content: center; }
.sidebar-left.collapsed #app-switcher-btn span, .sidebar-left.collapsed #app-switcher-btn .switcher-arrow { display: none; }
.sidebar-left.collapsed #app-switcher-btn > i:first-child { margin-right: 0; }
.sidebar-left.collapsed #app-switcher-list { width: 240px; left: 8px; }
.sidebar-left.collapsed .app-switcher-item span { display: inline-block !important; }

/* --- Mobile App Drawer --- */
#mobile-app-drawer {
    position: fixed;
    bottom: 0;
    left: 0;
    width: 100%;
    z-index: 1003;
    background-color: var(--bg-element);
    border-top: 1px solid var(--border-color);
    border-top-left-radius: 16px;
    border-top-right-radius: 16px;
    box-shadow: 0 -4px 20px rgba(0,0,0,0.3);
    transform: translateY(100%);
    transition: transform 0.3s ease-out, max-height 0.3s ease-out;
    display: flex;
    flex-direction: column;
    max-height: 35vh; /* Initial height for shortcuts */
}
#mobile-app-drawer.visible {
    transform: translateY(0);
}
#mobile-app-drawer.expanded {
    max-height: 85vh; /* Expanded height for all apps */
}
#mobile-drawer-handle-area {
    padding: 10px;
    flex-shrink: 0;
    text-align: center;
    cursor: grab;
}
.handle-bar {
    width: 40px;
    height: 4px;
    background-color: var(--text-secondary);
    border-radius: 2px;
    margin: 0 auto 5px auto;
}
#mobile-drawer-indicator {
    font-size: 12px;
    color: var(--text-secondary);
    transition: opacity 0.3s;
}
#mobile-app-drawer.expanded #mobile-drawer-indicator {
    opacity: 0;
}
#mobile-app-list-container {
    overflow-y: auto;
    padding: 0 10px 10px 10px;
    padding-bottom: calc(env(safe-area-inset-bottom, 20px) + 10px);
}
.mobile-app-list {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 20px 10px;
    padding: 10px 0;
}
#mobile-other-apps-list {
    border-top: 1px solid var(--border-color);
    margin-top: 10px;
    display: none; /* Hidden by default */
}
#mobile-app-drawer.expanded #mobile-other-apps-list {
    display: grid; /* Show when expanded */
}
.mobile-app-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    text-decoration: none;
    color: var(--text-secondary);
    text-align: center;
}
.mobile-app-item.active {
    color: var(--brand-red);
}
.mobile-app-item i {
    font-size: 24px;
    width: 48px;
    height: 48px;
    line-height: 48px;
    text-align: center;
    background-color: var(--bg-element-hover);
    border-radius: 12px;
}
.mobile-app-item.active i {
    background-color: var(--brand-red);
    color: white;
}
.mobile-app-item span {
    font-size: 12px;
    font-weight: 500;
    word-break: break-word;
}

/* --- Responsive Design --- */
@media (max-width: 1024px) {
    .resizer { display: none !important; }

    .sidebar-left {
        width: 240px;
    }
    .sidebar-right {
        display: flex;
        position: fixed;
        right: 0;
        top: 0;
        height: 100%;
        transform: translateX(100%);
        border-left: 1px solid var(--border-color);
        transition: transform 0.3s ease;
    }
    .app-container.editor-visible .sidebar-right {
        transform: translateX(0);
    }
    .resizer#resizer-right {
        display: none !important;
    }

    .main-content-header, .links-grid-container {
        padding-left: 1.5rem;
        padding-right: 1.5rem;
    }
}


@media (max-width: 768px) {
    .login-container { padding: 2rem 1.5rem; }
    #sidebar-toggle-btn { display: none; }
    .mobile-only-btn { display: block; }
    .main-content-header { padding: 1rem; }
    .sidebar-left { position: fixed; left: 0; top: 0; height: 100%; transform: translateX(-100%); border-right: 1px solid var(--border-color); }
    .app-container.nav-visible .sidebar-left { transform: translateX(0); }
    .sidebar-right { width: 90%; max-width: none; }
    .links-grid-container, #contacts-grid-container, #notes-grid-container { padding: 0 1rem 1rem 1rem; }
}
.tox.tox-edit-focus .tox-edit-area::before {
    opacity: 0 !important;
}
.tox .tox-toolbar-overlord {
    background-color: transparent !important;
}

/* --- Upcoming Events Sidebar Section --- */
.upcoming-events-section {
    padding-top: 1rem;
    border-top: 1px solid var(--border-color);
    margin-top: 1rem;
    margin-bottom: 1rem;
    flex-shrink: 0;
    flex-grow: 0;
}
.sidebar-left.collapsed .upcoming-events-section {
    display: none;
}
#upcoming-events-list {
    display: flex;
    flex-direction: column;
    gap: 2px;
    max-height: 250px;
    overflow-y: auto;
    font-size: 12px;
}
.upcoming-event-item {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 2px;
    border-radius: 6px;
    text-decoration: none;
    color: var(--text-secondary);
    transition: 0.2s;
}
.upcoming-event-item:hover {
    background-color: var(--bg-element);
    color: var(--text-primary);
}
.upcoming-event-item i {
    font-size: 0.7rem;
    width: 20px;
    text-align: center;
    flex-shrink: 0;
}
.upcoming-event-item .event-details {
    display: flex;
    flex-direction: column;
    overflow: hidden;
}
.upcoming-event-item .event-title {
    font-weight: 500;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.upcoming-event-item .event-date {
    font-size: 0.7rem;
}
/* --- Account Menu --- */
#account-menu-container { position: relative; }
#account-menu-btn {
    display: flex;
    align-items: center;
    width: 100%;
    background: none;
    border: none;
    padding: 10px 12px;
    border-radius: 20px;
    font-family: 'Inter';
    font-size: 14px;
    cursor: pointer;
    color: var(--text-secondary);
    font-weight: 500;
}
.sidebar-left.collapsed #account-menu-btn {
    justify-content: center;
}
.sidebar-left.collapsed #account-menu-btn .account-username, .sidebar-left.collapsed #account-menu-btn .switcher-arrow {
    display: none;
}
#account-menu-btn:hover { background-color: var(--bg-element); color: var(--text-primary); }
.account-avatar {
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background-color: var(--brand-red);
    color: white;
    font-size: 0.7rem;
    font-weight: bold;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-right: 16px;
    text-transform: uppercase;
}
.sidebar-left.collapsed .account-avatar { margin-right: 0; }
.account-username { flex-grow: 1; text-align: left; }
#account-menu-list {
    position: absolute;
    bottom: calc(100% + 8px);
    left: 0;
    width: 100%;
    background-color: var(--bg-element);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    z-index: 1001;
    padding: 6px;
    box-shadow: 0 8px 16px rgba(0,0,0,0.3);
}
.sidebar-left.collapsed #account-menu-list {
    width: 240px;
}
.account-menu-item {
    display: flex;
    align-items: center;
    padding: 10px 12px;
    color: var(--text-secondary);
    text-decoration: none;
    border-radius: 4px;
    font-weight: 500;
    cursor: pointer;
    background: none;
    border: none;
    width: 100%;
    font-size: 14px;
    text-align: left;
}
.account-menu-item:hover { background-color: var(--bg-element-hover); color: var(--text-primary); }
.account-menu-item .account-avatar { font-size: 0.6rem; width: 18px; height: 18px; }
.account-menu-item.active-account { background-color: var(--bg-element-hover); }
.account-menu-item.active-account .account-username { font-weight: bold; color: var(--text-primary); }