@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap');

:root {
    --sidebar-width: 300px;
    --primary-bg: #e3e9f1;
    --secondary-bg: #e3e9f1;
    --border-color: #e5e7eb;
    --text-primary: #1f2937;
    --text-secondary: #6b7280;
    --accent-primary: #3b82f6;
    --accent-primary-hover: #2563eb;
    --accent-primary-light: #eff6ff;
    --danger-primary: #ef4444;
    --danger-primary-hover: #dc2626;
    --warning-primary: #f59e0b;
    --success-primary: #10b981;
    --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
    --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
    --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);
    --radius-sm: 0.5rem; /* 8px */
    --radius-md: 0.75rem;   /* 12px */
    --radius-lg: 1rem;  /* 16px */
    --transition-fast: all 0.2s ease-in-out;
}

html {
    box-sizing: border-box;
}

*, *::before, *::after {
    box-sizing: inherit;
}

body {
    font-family: var(--font-sans);
    background-color: var(--primary-bg);
    margin: 0;
    color: var(--text-primary);
    overflow-x: hidden;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    min-width: 300px; /* Set a minimum width */
}

.overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(31, 41, 55, 0.5);
    z-index: 199;
    backdrop-filter: blur(4px);
}

.overlay.active {
    display: block;
}

.container {
    display: flex;
    flex-direction: column;
    height: 100vh;
}

.main-header {
    display: flex;
    align-items: center;
    padding: 0.75rem 1.5rem;
    background-color: var(--secondary-bg);
    flex-shrink: 0;
    position: relative;
    z-index: 10;
    box-shadow: var(--shadow-md);
}

.hamburger-btn {
    display: block;
    background: none;
    border: none;
    cursor: pointer;
    padding: 0.5rem;
    margin-right: 1rem;
    border-radius: var(--radius-md);
    transition: var(--transition-fast);
}

.hamburger-btn:hover {
    background-color: var(--primary-bg);
}

.hamburger-btn span {
    display: block;
    width: 24px;
    height: 2px;
    background-color: var(--text-primary);
    margin: 5px 0;
    transition: var(--transition-fast);
}

.main-header h1 {
    margin: 0;
    font-size: 1.25rem;
    font-weight: 700;
    text-align: center;
    flex-grow: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
}

.header-icon {
    color: var(--accent-primary);
    margin-top: -2px; /* visual alignment */
}

.main-layout {
    display: flex;
    flex-grow: 1;
    overflow: hidden;
}

.sidebar {
    width: var(--sidebar-width);
    background-color: var(--secondary-bg);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    transition: margin-left 0.3s ease-in-out, width 0.3s ease-in-out;
}

.sidebar-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem 1.5rem;
    border-bottom: 1px solid var(--border-color);
}

.sidebar-header h2 {
    margin: 0;
    font-size: 1rem;
    font-weight: 600;
}

.add-tab-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    font-size: 1.5rem;
    cursor: pointer;
    border: none;
    background: var(--primary-bg);
    color: var(--text-secondary);
    border-radius: 50%;
    transition: var(--transition-fast);
}

.add-tab-btn:hover {
    background-color: var(--accent-primary);
    color: white;
}

.search-container {
    padding: 1rem 1.5rem;
    border-bottom: 1px solid var(--border-color);
}

.search-container input {
    width: 100%;
    padding: 0.625rem 1rem;
    box-sizing: border-box;
    border: 1px solid var(--text-primary);
    border-radius: var(--radius-md);
    background-color: var(--primary-bg);
    transition: var(--transition-fast);
}

.search-container input:focus {
    outline: none;
    border-color: var(--accent-primary);
    box-shadow: 0 0 0 2px var(--accent-primary-light);
}

.main-content .search-container {
    padding: 0 0 1.5rem 0;
    border-bottom: none;
}

.tabs {
    flex-grow: 1;
    overflow-y: auto;
    padding: 0.5rem 0;
}

.sidebar-actions {
    padding: 1rem 1.5rem;
    border-top: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.sidebar-btn {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    width: 100%;
    padding: 0.75rem 1rem;
    text-align: left;
    background-color: var(--primary-bg);
    border: 1px solid var(--text-primary);
    border-radius: var(--radius-md);
    cursor: pointer;
    font-weight: 500;
    color: var(--text-primary);
    transition: var(--transition-fast);
}

.sidebar-btn:hover {
    background-color: var(--border-color);
}

.tab {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.75rem 1.5rem;
    margin: 0.25rem 1rem;
    cursor: pointer;
    border-radius: var(--radius-md);
    position: relative;
    transition: var(--transition-fast);
    border: 1px solid transparent;
}

.tab:hover {
    background-color: var(--primary-bg);
}

.tab-info {
    display: flex;
    flex-direction: column;
    gap: 0.125rem;
    min-width: 0; /* Allow text container to shrink */
}

.tab-name {
    font-size: 0.9rem;
    font-weight: 500;
    color: var(--text-primary);
}

.tab-timestamps {
    font-size: 0.75rem;
    color: var(--text-secondary);
}

.tab.active {
    background-color: var(--accent-primary);
    color: white;
    font-weight: 600;
}

.tab.active .tab-name, .tab.active .tab-timestamps {
    color: white;
}

.tab.pinned {
    background-color: var(--accent-primary-light);
}

.tab.active.pinned {
    background-color: var(--accent-primary);
}

.tab.active.pinned .tab-name, .tab.active.pinned .tab-timestamps {
    color: white;
}

.tab-controls {
    display: flex;
    align-items: center;
    gap: 0.25rem;
    opacity: 0;
    transition: var(--transition-fast);
}

.tab:hover .tab-controls {
    opacity: 1;
}
.tab.pinned .tab-controls {
    opacity: 1 !important;
}

.pin-tab-btn, .delete-tab-btn, .edit-tab-btn {
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    font-size: 1rem;
    padding: 0.25rem;
    border-radius: var(--radius-sm);
    transition: var(--transition-fast);
}

.pin-tab-btn:hover, .delete-tab-btn:hover, .edit-tab-btn:hover {
    background-color: var(--border-color);
    color: var(--text-primary);
}

.pin-tab-btn svg, .pin-note-btn svg {
    width: 16px;
    height: 16px;
    display: block;
}

.tab.active .pin-tab-btn, .tab.active .delete-tab-btn, .tab.active .edit-tab-btn {
    color: rgba(255, 255, 255, 0.7);
}

.tab.active .pin-tab-btn:hover, .tab.active .delete-tab-btn:hover, .tab.active .edit-tab-btn:hover {
    background-color: rgba(255, 255, 255, 0.1);
    color: white;
}

.tab.pinned .pin-tab-btn {
    color: var(--accent-primary);
}

.tab.active.pinned .pin-tab-btn {
    color: white;
}

.delete-tab-btn {
    font-size: 1.25rem;
}

.main-content {
    flex-grow: 1;
    padding: 2rem 2.5rem;
    overflow-y: auto;
}

.add-note-btn {
    display: block;
    width: 100%;
    padding: 0.875rem;
    font-size: 1rem;
    font-weight: 500;
    background-color: var(--accent-primary);
    color: white;
    border: none;
    border-radius: var(--radius-md);
    cursor: pointer;
    margin-bottom: 1.5rem;
    transition: var(--transition-fast);
    box-shadow: var(--shadow-sm);
}

.add-note-btn:hover {
    background-color: var(--accent-primary-hover);
    box-shadow: var(--shadow-md);
}

.notes-container {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 2rem;
}

.note-card {
    background: var(--secondary-bg);
    border: 1px solid var(--text-primary);
    border-radius: var(--radius-lg);
    overflow: hidden;
    display: flex;
    flex-direction: column;
    transition: var(--transition-fast);
    box-shadow: var(--shadow-sm);
    position: relative;
}

.note-card:hover {
    transform: translateY(-4px);
    box-shadow: var(--shadow-md);
}

.note-card.pinned {
    border-top: 4px solid var(--accent-primary);
    background-color: var(--secondary-bg);
}

.note-card-content {
    padding: 1rem;
    cursor: pointer;
    flex-grow: 1;
}

.note-card-image-container {
    position: relative;
    margin: -1rem -1rem 1rem -1rem;
    height: 160px;
    background-color: var(--primary-bg);
}

.note-card .preview-image {
    width: 100%;
    height: 100%;
    object-fit: contain;
    display: block;
}

.quick-view-btn {
    position: absolute;
    top: 0.75rem;
    right: 0.75rem;
    background: rgba(31, 41, 55, 0.6);
    color: white;
    border: none;
    border-radius: 50%;
    width: 36px;
    height: 36px;
    font-size: 1.125rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transition: var(--transition-fast);
    z-index: 10;
    backdrop-filter: blur(4px);
}

.note-card-image-container:hover .quick-view-btn {
    opacity: 1;
}

.note-card h3 {
    margin: 0 0 0.5rem 0;
    font-size: 1.125rem;
    font-weight: 600;
}

.note-card p {
    font-size: 0.9rem;
    color: var(--text-secondary);
    margin: 0;
    line-height: 1.5;
}

.note-timestamps {
    font-size: 0.75rem;
    color: var(--text-secondary);
    margin-top: 1rem;
}

.note-timestamps p {
    margin: 2px 0;
    font-size: 0.75rem;
}

.view-timestamps {
    margin-bottom: 1rem;
    padding-bottom: 1rem;
    border-bottom: 1px solid var(--border-color);
}

.note-card-actions {
    display: flex;
    border-top: 1px solid var(--border-color);
    background-color: var(--primary-bg);
}

.pin-note-btn {
    position: absolute;
    top: 0.75rem;
    right: 3.25rem; /* Move it to the left to make space for the quick-view button */
    background: rgba(31, 41, 55, 0.6);
    color: white;
    border: none;
    border-radius: 50%;
    width: 36px;
    height: 36px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--transition-fast);
    z-index: 15;
    backdrop-filter: blur(4px);
    opacity: 0;
}

/* If there's no image, the pin button should be on the far right */
.note-card:not(:has(.note-card-image-container)) .pin-note-btn {
    right: 0.75rem;
}

.note-card:hover .pin-note-btn {
    opacity: 1;
}

.pin-note-btn svg {
    fill: white;
    width: 16px;
    height: 16px;
}

.note-card.pinned .pin-note-btn {
    opacity: 1;
    background: var(--accent-primary-light);
}

.note-card.pinned .pin-note-btn svg {
    fill: var(--accent-primary);
}

.pin-note-btn:hover {
    background-color: rgba(31, 41, 55, 0.8);
}

.note-card.pinned .pin-note-btn:hover {
    background-color: var(--accent-primary);
}
.note-card.pinned .pin-note-btn:hover svg {
    fill: white;
}

.note-card-actions .card-btn {
    flex: 1;
    padding: 0.75rem;
    font-size: 0.8rem;
    font-weight: 500;
    background-color: transparent;
    color: var(--text-secondary);
    border: none;
    border-right: 1px solid var(--border-color);
    cursor: pointer;
    transition: var(--transition-fast);
}

.note-card-actions .card-btn:last-child {
    border-right: none;
}

.note-card-actions .card-btn:hover {
    background-color: var(--border-color);
    color: var(--text-primary);
}

/* Modal Styles */
.modal {
    display: none;
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    overflow: auto;
    background-color: rgba(31, 41, 55, 0.5);
    backdrop-filter: blur(4px);
    padding: 2rem;
}

#image-zoom-modal {
    background-color: rgba(0,0,0,0.8);
    align-items: center;
    justify-content: center;
}

.modal-content {
    background-color: var(--secondary-bg);
    margin: auto;
    padding: 2rem;
    border: none;
    width: 100%;
    max-width: 640px;
    border-radius: var(--radius-lg);
    position: relative;
    box-shadow: var(--shadow-lg);
}

.modal-content h2 {
    margin-top: 0;
    font-size: 1.25rem;
    font-weight: 600;
}

.close-btn {
    position: absolute;
    top: 1rem;
    right: 1rem;
    color: var(--text-secondary);
    font-size: 1.5rem;
    font-weight: bold;
    cursor: pointer;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: var(--transition-fast);
}

.close-btn:hover {
    background-color: var(--primary-bg);
    color: var(--text-primary);
}

.modal-content input[type="text"], .modal-content textarea, .modal-content input[type="file"] {
    width: 100%;
    padding: 0.75rem 1rem;
    margin: 0.5rem 0 1rem 0;
    box-sizing: border-box;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    background-color: var(--secondary-bg);
    transition: var(--transition-fast);
}

.modal-content input[type="file"] {
    display: none;
}

.modal-content input[type="text"]:focus, .modal-content textarea:focus {
    outline: none;
    border-color: var(--accent-primary);
    box-shadow: 0 0 0 2px var(--accent-primary-light);
}

.modal-content textarea {
    min-height: 120px;
    resize: vertical;
}

.modal-content button {
    width: 100%;
    padding: 0.875rem;
    background-color: var(--accent-primary);
    color: white;
    border: none;
    cursor: pointer;
    border-radius: var(--radius-md);
    font-weight: 500;
    transition: var(--transition-fast);
}

.modal-content button:hover {
    background-color: var(--accent-primary-hover);
}

.photos-preview {
    display: flex;
    gap: 0.75rem;
    margin: 0.5rem 0 1rem 0;
    flex-wrap: wrap;
}

.photos-preview img {
    width: 80px;
    height: 80px;
    object-fit: cover;
    border-radius: var(--radius-md);
    border: 1px solid var(--border-color);
}

.photos-preview .photo-wrapper {
    position: relative;
}

.photos-preview .delete-photo-btn {
    position: absolute;
    top: -4px;
    right: -4px;
    background: var(--danger-primary);
    color: white;
    border: 2px solid var(--secondary-bg);
    border-radius: 50%;
    cursor: pointer;
    width: 24px;
    height: 24px;
    line-height: 1;
    text-align: center;
    font-size: 1rem;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--transition-fast);
}

.photos-preview .delete-photo-btn:hover {
    background-color: var(--danger-primary-hover);
    transform: scale(1.1);
}

#view-note-description {
    white-space: pre-wrap;
    word-wrap: break-word;
    overflow-wrap: break-word;
    background-color: var(--primary-bg);
    padding: 1rem;
    border-radius: var(--radius-md);
    border: 1px solid var(--border-color);
    max-height: 40vh;
    overflow-y: auto;
    font-size: 1rem;
    line-height: 1.6;
    color: var(--text-primary);
}

.image-viewer {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 1.5rem 0;
}

.image-viewer img {
    max-width: 100%;
    max-height: 60vh;
    border-radius: var(--radius-lg);
    background-color: var(--primary-bg);
}

.image-viewer button {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    margin: 0 1rem;
    padding: 0;
    background: rgba(255, 255, 255, 0.8);
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    cursor: pointer;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
    transition: var(--transition-fast);
    box-shadow: var(--shadow-md);
}

.image-viewer button:hover {
    background-color: white;
    transform: translateY(-50%) scale(1.1);
}

.image-viewer #prev-image-btn {
    left: 0;
}

.image-viewer #next-image-btn {
    right: 0;
}

.image-viewer .zoom-btn {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: rgba(31, 41, 55, 0.6);
    color: white;
    border: none;
    border-radius: 50%;
    width: 56px;
    height: 56px;
    font-size: 1.5rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transition: var(--transition-fast);
    z-index: 10;
    backdrop-filter: blur(4px);
}

.image-viewer:hover .zoom-btn {
    opacity: 1;
}

.image-actions, .modal-footer-buttons {
    display: flex;
    gap: 0.75rem;
    margin-top: 1.5rem;
    flex-wrap: wrap;
}

.image-actions button, .modal-footer-buttons button {
    flex: 1;
    padding: 0.75rem 1rem;
    border: none;
    border-radius: var(--radius-md);
    cursor: pointer;
    font-size: 0.9rem;
    font-weight: 500;
    transition: var(--transition-fast);
}

.button-primary {
    background-color: var(--accent-primary);
    color: white;
}
.button-primary:hover {
    background-color: var(--accent-primary-hover);
}

.button-secondary {
    background-color: var(--primary-bg);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
}
.button-secondary:hover {
    background-color: var(--border-color);
}

.button-edit {
    background-color: var(--warning-primary);
    color: white;
}
.button-edit:hover {
    background-color: #d97706;
}

.button-delete, .button-delete-photo {
    background-color: var(--danger-primary);
    color: white;
}
.button-delete:hover, .button-delete-photo:hover {
    background-color: var(--danger-primary-hover);
}

.image-viewer img.zoomable {
    cursor: zoom-in;
}

.modal-content-zoom {
    margin: auto;
    display: block;
    max-width: 95%;
    max-height: 95vh;
    object-fit: contain;
}

#image-zoom-modal .close-btn {
    position: absolute;
    top: 1rem;
    right: 2rem;
    color: #f1f1f1;
    font-size: 2.5rem;
}

/* Mobile Adaptation */
@media (max-width: 768px) {
    :root {
        --sidebar-width: 280px;
    }
    .sidebar {
        position: fixed;
        top: 0;
        left: calc(-1 * var(--sidebar-width));
        height: 100%;
        z-index: 200;
        transition: left 0.3s ease-in-out;
        box-shadow: var(--shadow-lg);
    }
    .sidebar.active {
        left: 0;
    }
    .main-content {
        padding: 1rem;
    }
    .sidebar-actions {
        gap: 1rem;
    }
    .modal {
        padding: 1rem;
    }
    .modal-content {
        padding: 1.5rem;
    }
    .notes-container {
        grid-template-columns: 1fr;
        gap: 1rem;
    }
    .tab .tab-controls {
        opacity: 1;
        gap: 0.75rem;
    }
    .quick-view-btn,
    .pin-note-btn {
        opacity: 1;
    }
}

.support-fab {
    position: fixed;
    bottom: 1.5rem;
    right: 1.5rem;
    width: 56px;
    height: 56px;
    background-color: var(--accent-primary);
    color: white;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.75rem;
    font-weight: 600;
    text-decoration: none;
    box-shadow: var(--shadow-lg);
    z-index: 999;
    transition: var(--transition-fast);
}

.support-fab:hover {
    background-color: var(--accent-primary-hover);
    transform: scale(1.05);
}

@media (max-width: 400px) {
    .notes-container {
        /* Adjust grid for smaller phones */
        grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
    }
    .main-header {
        padding: 0.5rem 1rem;
    }
    .main-header h1 {
        font-size: 1rem;
    }
    .main-content {
        padding: 0.75rem;
    }
    .sidebar {
        --sidebar-width: 260px;
    }
    .sidebar-header, .search-container, .sidebar-actions {
        padding: 0.75rem 1rem;
    }
    .tab {
        padding: 0.6rem 1rem;
        margin: 0.25rem 0.5rem;
    }
    .support-fab {
        width: 48px;
        height: 48px;
        font-size: 1.5rem;
        bottom: 1rem;
        right: 1rem;
    }
}

@media (max-width: 320px) {
    :root {
        --sidebar-width: 240px;
        font-size: 14px; /* Reduce base font size */
    }
    .main-header h1 {
        font-size: 0.9rem;
    }
    .main-content {
        padding: 0.5rem;
    }
    .notes-container {
        gap: 0.75rem;
    }
    .note-card-content {
        padding: 0.75rem;
    }
    .note-card h3 {
        font-size: 1rem; /* Adjust note title size */
    }
    .modal {
        padding: 0.5rem;
    }
    .modal-content {
        padding: 1rem;
    }
    .support-fab {
        width: 44px;
        height: 44px;
        font-size: 1.3rem;
        bottom: 0.75rem;
        right: 0.75rem;
    }
    .sidebar-btn span {
        font-size: 0.85rem;
    }
    .tab {
        padding: 0.5rem 0.75rem;
        margin: 0.25rem;
    }
    .tab-name {
        word-break: break-all; /* Force break long words */
    }
    .tab-controls {
        gap: 0.25rem;
    }
    .pin-tab-btn, .delete-tab-btn, .edit-tab-btn {
        font-size: 0.9rem;
        padding: 0.2rem;
    }
    .delete-tab-btn {
        font-size: 1.1rem;
    }
}

.file-input-label {
    display: inline-block;
    width: 100%;
    padding: 0.875rem;
    background-color: var(--primary-bg);
    color: var(--text-primary);
    border: 1px solid var(--text-primary);
    border-radius: var(--radius-md);
    cursor: pointer;
    font-weight: 500;
    text-align: center;
    transition: var(--transition-fast);
    margin-bottom: 1rem;
}

.file-input-label:hover {
    background-color: var(--border-color);
}

@media (min-width: 769px) {
    .sidebar.collapsed {
        width: 0;
        overflow: hidden;
        padding-top: 0;
        padding-bottom: 0;
        border-right: none;
    }

    .sidebar.collapsed .sidebar-header,
    .sidebar.collapsed .search-container,
    .sidebar.collapsed .tabs,
    .sidebar.collapsed .sidebar-actions {
        visibility: hidden;
    }
}