:root {
    --bg-color: #000000;
    --text-color: #FFFFFF;
    --accent-color: #D71921;
    --accent-red: #D71921;
    --accent-yellow: #C8A005;
    /* Deeper, darker yellow */
    --widget-bg: #141414;
    --item-bg: #0a0a0a;
    --preview-bg: #111111;
    --border-color: #333333;
    --font-main: 'Share Tech Mono', monospace;
}

[data-theme="light"] {
    --bg-color: #EAEAEA;
    /* Slightly darker white for better contrast */
    --text-color: #000000;
    --widget-bg: #FFFFFF;
    --item-bg: #FFFFFF;
    --preview-bg: #F5F5F5;
    --border-color: #000000;
    /* Sharp black borders for light mode */
}

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

body {
    background-color: var(--bg-color);
    color: var(--text-color);
    font-family: var(--font-main);
    display: flex;
    justify-content: flex-start;
    min-height: 100vh;
    padding-left: 5%;
}

.app-container {
    width: 98%;
    /* Use almost full width */
    max-width: none;
    /* Remove fixed width constraint */
    background-color: var(--bg-color);
    padding: 40px 10px;
    /* Reduced horizontal padding */
    position: relative;
    display: flex;
    flex-direction: column;
}

/* Layout Wrapper */
.main-wrapper {
    display: flex;
    gap: 10px;
    /* Aggressively reduced gap */
    width: 100%;
}

main {
    flex-grow: 1;
}

/* Filter Sidebar */
.filter-sidebar {
    width: 170px;
    /* Increased to align border with hamburger menu */
    flex-shrink: 0;
    border-left: 1px solid var(--border-color);
    border-right: none;
    padding-left: 10px;
    padding-right: 2px;
    /* Minimal padding */
    display: block;
    text-align: right;
    /* Align tags to right */
}

.sidebar-title {
    font-size: 14px;
    color: var(--accent-color);
    margin-bottom: 20px;
    letter-spacing: 1px;
}

#tagFilterList {
    list-style: none;
}

#tagFilterList li {
    padding: 8px 0;
    color: #666;
    cursor: pointer;
    font-size: 14px;
    transition: color 0.2s;
    text-transform: uppercase;
}

#tagFilterList li:hover {
    color: var(--text-color);
}

#tagFilterList li.active {
    color: var(--accent-color);
    font-weight: bold;
}

#tagFilterList li.active::before {
    content: '> ';
}

/* Header */
header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 30px;
    padding-top: 10px;
}

.brand {
    font-size: 24px;
    font-weight: 400;
    letter-spacing: 1px;
}

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

.dots {
    color: var(--accent-color);
    font-size: 24px;
    letter-spacing: 2px;
}

.mobile-menu-btn {
    display: none;
    background: none;
    border: 1px solid var(--border-color);
    color: var(--accent-color);
    font-size: 20px;
    padding: 5px 10px;
    border-radius: 4px;
    cursor: pointer;
}

/* Widgets */
.widgets-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
    margin-bottom: 40px;
    max-width: 800px;
    /* Restored previous size constraint */
}

.widget {
    background-color: var(--widget-bg);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 15px;
    height: 140px;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    transition: transform 0.2s;
    position: relative;
}

.widget:hover {
    border-color: var(--text-color);
}

.widget-header {
    font-size: 12px;
    color: #888;
}

.widget-content {
    flex-grow: 1;
    display: flex;
    flex-direction: column;
    justify-content: center;
    font-size: 14px;
    overflow: hidden;
}

.preview-box {
    width: 100%;
    height: 60px;
    background-size: cover;
    background-position: center;
    background-color: #222;
    margin-bottom: 8px;
    border-radius: 4px;
    border: 1px solid #333;
}

.widget-footer {
    font-size: 12px;
    color: #666;
    text-align: right;
}

.widget-footer.accent {
    color: var(--accent-color);
}

/* Memory Section */
.section-title {
    font-size: 16px;
    color: var(--accent-color);
    margin-bottom: 20px;
    border-bottom: 1px solid var(--accent-color);
    display: inline-block;
    padding-bottom: 2px;
}

.memory-list {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
    gap: 20px;
    padding-bottom: 100px;
}

.memory-item {
    background-color: var(--item-bg);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 15px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    cursor: pointer;
    transition: all 0.2s;
    position: relative;
    height: 100%;
}

.memory-item:hover {
    border-color: #555;
    transform: translateY(-2px);
}

.memory-item.pinned {
    border-color: var(--accent-color);
}

.pinned-badge {
    position: absolute;
    top: 10px;
    right: 10px;
    background-color: rgba(128, 128, 128, 0.2);
    color: var(--text-color);
    font-family: var(--font-main);
    font-size: 10px;
    padding: 4px 8px;
    border-radius: 2px;
    letter-spacing: 1px;
    border: 1px solid var(--border-color);
    z-index: 2;
}

.item-image-preview {
    width: 100%;
    height: 120px;
    object-fit: cover;
    border-radius: 4px;
    margin-bottom: 5px;
    background-color: var(--preview-bg);
}

.item-left {
    display: flex;
    flex-direction: column;
    gap: 5px;
}

.item-type {
    color: var(--accent-color);
    font-size: 12px;
}

.item-content {
    font-size: 14px;
    line-height: 1.4;
    display: -webkit-box;
    -webkit-line-clamp: 3;
    line-clamp: 3;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.item-time {
    font-size: 12px;
    color: #666;
    margin-top: auto;
    text-align: right;
}

/* FAB Container */
.fab-container {
    position: fixed;
    bottom: 40px;
    right: 40px;
    display: flex;
    flex-direction: row;
    /* Side by side */
    align-items: center;
    gap: 15px;
    z-index: 100;
}

.fab {
    position: relative;
    bottom: auto;
    right: auto;
    width: 60px;
    height: 60px;
    border-radius: 50%;
    border: none;
    font-size: 32px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.2s, background-color 0.2s;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.3);
}

.fab.primary {
    background-color: var(--accent-color);
    color: var(--bg-color);
    /* Inverted for contrast */
}

.fab.secondary {
    background-color: var(--widget-bg);
    color: var(--text-color);
    border: 1px solid var(--border-color);
    font-size: 24px;
}

.fab:hover {
    transform: scale(1.1);
}

/* Settings Menu */
.settings-menu {
    position: absolute;
    bottom: 100%;
    right: 0;
    /* Align to right */
    margin-bottom: 15px;
    background-color: var(--widget-bg);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 15px;
    width: 200px;
    display: none;
    /* Hidden by default */
    flex-direction: column;
    gap: 15px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.5);
}

.settings-menu.active {
    display: flex;
}

.settings-header {
    font-size: 14px;
    color: var(--accent-color);
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 8px;
    letter-spacing: 1px;
}

.setting-item label {
    display: block;
    font-size: 12px;
    color: #888;
    margin-bottom: 8px;
}

.toggle-group {
    display: flex;
    gap: 10px;
}

.toggle-btn {
    flex: 1;
    background: transparent;
    border: 1px solid var(--border-color);
    color: #666;
    padding: 6px;
    font-family: var(--font-main);
    font-size: 12px;
    cursor: pointer;
    transition: all 0.2s;
}

.toggle-btn:hover {
    border-color: var(--text-color);
    color: var(--text-color);
}

.toggle-btn.active {
    background-color: var(--accent-color);
    color: var(--bg-color);
    border-color: var(--accent-color);
    font-weight: bold;
}

/* Modals */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.85);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
}

.modal-overlay.active {
    opacity: 1;
    pointer-events: all;
}

.modal-content {
    background-color: var(--widget-bg);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    width: 90%;
    max-width: 450px;
    padding: 20px;
    transform: translateY(20px);
    transition: transform 0.3s ease;
    max-height: 90vh;
    overflow-y: auto;
}

.modal-overlay.active .modal-content {
    transform: translateY(0);
}

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

.modal-header h3 {
    color: var(--accent-color);
    font-size: 18px;
    font-weight: normal;
}

.close-btn {
    background: none;
    border: none;
    color: #666;
    font-size: 24px;
    cursor: pointer;
}

.close-btn:hover {
    color: var(--text-color);
}

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

.form-group label {
    display: block;
    font-size: 12px;
    color: #888;
    margin-bottom: 5px;
}

select,
textarea,
input[type="text"],
input[type="date"],
input[type="datetime-local"] {
    width: 100%;
    background-color: #000;
    border: 1px solid var(--border-color);
    color: var(--text-color);
    padding: 10px;
    border-radius: 4px;
    font-family: var(--font-main);
    font-size: 14px;
}

select:focus,
textarea:focus,
input:focus {
    outline: none;
    border-color: var(--accent-color);
}

input[type="file"] {
    color: #888;
    font-size: 12px;
}

/* Mic Button */
.mic-btn {
    position: absolute;
    bottom: 10px;
    right: 10px;
    background: none;
    border: none;
    font-size: 18px;
    cursor: pointer;
    opacity: 0.5;
    transition: all 0.2s;
}

.mic-btn:hover {
    opacity: 1;
    transform: scale(1.1);
}

.mic-btn.recording {
    opacity: 1;
    color: var(--accent-color);
    animation: pulse 1.5s infinite;
}

@keyframes pulse {
    0% {
        transform: scale(1);
    }

    50% {
        transform: scale(1.2);
    }

    100% {
        transform: scale(1);
    }
}

/* Tags */
.tag-input-container {
    background-color: #000;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    padding: 5px;
    display: flex;
    flex-wrap: wrap;
    gap: 5px;
}

.tag-input-container input {
    border: none;
    flex-grow: 1;
    min-width: 60px;
    padding: 5px;
}

.tag-input-container input:focus {
    border: none;
    outline: none;
}

.tags-list {
    display: flex;
    flex-wrap: wrap;
    gap: 5px;
}

.tag-pill {
    background-color: #222;
    color: #ccc;
    font-size: 12px;
    padding: 2px 8px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    gap: 5px;
    border: 1px solid #333;
}

.tag-pill .remove-tag {
    cursor: pointer;
    color: #666;
    font-weight: bold;
}

.tag-pill .remove-tag:hover {
    color: var(--accent-color);
}

.modal-footer {
    margin-top: 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

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

.btn-primary {
    background-color: var(--accent-color);
    color: var(--text-color);
    border: none;
    padding: 10px 20px;
    border-radius: 4px;
    cursor: pointer;
    font-family: var(--font-main);
    font-size: 14px;
}

.btn-primary:hover {
    background-color: var(--accent-color);
    filter: brightness(1.1);
    box-shadow: 0 0 10px var(--accent-color);
}

.btn-secondary {
    background-color: transparent;
    color: var(--text-color);
    border: 1px solid var(--border-color);
    padding: 10px 20px;
    border-radius: 4px;
    cursor: pointer;
    font-family: var(--font-main);
    font-size: 14px;
}

.btn-secondary:hover {
    border-color: var(--text-color);
}

.btn-danger {
    background-color: transparent;
    color: #ff4444;
    border: 1px solid #ff4444;
    padding: 8px 16px;
    border-radius: 4px;
    cursor: pointer;
    font-family: var(--font-main);
    font-size: 14px;
}

.btn-danger:hover {
    background-color: rgba(255, 68, 68, 0.1);
}

/* View Modal Specifics */
.view-text {
    font-size: 16px;
    line-height: 1.5;
    margin-bottom: 15px;
    white-space: pre-wrap;
}

.meta-info {
    font-size: 12px;
    color: #666;
    border-top: 1px solid var(--border-color);
    padding-top: 10px;
}

#viewImageContainer img {
    max-width: 100%;
    border-radius: 4px;
    margin-bottom: 15px;
    border: 1px solid var(--border-color);
}

/* Scrollbar */
::-webkit-scrollbar {
    width: 6px;
}

::-webkit-scrollbar-track {
    background: var(--bg-color);
}

::-webkit-scrollbar-thumb {
    background: #333;
    border-radius: 3px;
}

/* Responsive */
@media (max-width: 768px) {
    body {
        padding-left: 0;
    }

    .app-container {
        width: 100%;
        padding: 20px 15px;
    }

    .mobile-menu-btn {
        display: block;
    }

    .dots {
        display: none;
    }

    .main-wrapper {
        flex-direction: column;
        position: relative;
    }

    /* Off-canvas Sidebar */
    .filter-sidebar {
        position: fixed;
        top: 0;
        left: -250px; /* Hide off-screen */
        width: 250px;
        height: 100vh;
        background-color: var(--widget-bg);
        border-right: 1px solid var(--border-color);
        border-left: none;
        border-top: none;
        padding: 20px;
        z-index: 1000;
        transition: left 0.3s ease;
        box-shadow: 2px 0 10px rgba(0,0,0,0.5);
        text-align: left;
    }

    .filter-sidebar.active {
        left: 0;
    }

    /* Overlay for sidebar */
    .sidebar-overlay {
        display: none;
        position: fixed;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
        background: rgba(0,0,0,0.5);
        z-index: 999;
        opacity: 0;
        transition: opacity 0.3s;
    }

    .sidebar-overlay.active {
        display: block;
        opacity: 1;
    }

    .widgets-grid {
        grid-template-columns: 1fr;
        gap: 15px;
        margin-bottom: 30px;
    }

    .memory-list {
        grid-template-columns: 1fr; /* Single column for mobile */
        gap: 15px;
    }

    .fab-container {
        right: 20px;
        bottom: 20px;
        gap: 10px;
    }

    .fab {
        width: 50px;
        height: 50px;
        font-size: 24px;
    }

    .settings-menu {
        right: 0;
        bottom: 70px; /* Adjust for smaller FAB */
    }
    
    /* Touch Optimizations */
    button, 
    .memory-item,
    .widget,
    input,
    select,
    textarea {
        cursor: default; /* Remove pointer cursor on touch */
    }

    .memory-item:hover,
    .widget:hover {
        transform: none; /* Disable hover lift */
        border-color: var(--border-color);
    }
    
    /* Increase tap targets */
    #tagFilterList li {
        padding: 12px 0;
        font-size: 16px;
    }
    
    .close-btn {
        padding: 10px; /* Larger hit area */
    }
}

/* Voice Recorder UI */
.recorder-container {
    background-color: #000;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 20px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 15px;
    margin-bottom: 15px;
}

.recorder-status {
    font-size: 12px;
    color: #666;
    letter-spacing: 2px;
}

.recorder-status.recording {
    color: var(--accent-color);
    animation: blink 1s infinite;
}

@keyframes blink {
    50% {
        opacity: 0.5;
    }
}

.recorder-timer {
    font-size: 32px;
    font-family: var(--font-main);
    color: var(--text-color);
}

.recorder-visualizer {
    display: flex;
    gap: 4px;
    height: 40px;
    align-items: center;
}

.bar {
    width: 4px;
    height: 4px;
    background-color: #333;
    border-radius: 2px;
    transition: height 0.1s;
}

.recorder-status.recording~.recorder-visualizer .bar {
    background-color: var(--accent-color);
    animation: visualize 0.5s infinite ease-in-out alternate;
}

.recorder-status.recording~.recorder-visualizer .bar:nth-child(odd) {
    animation-duration: 0.4s;
}

.recorder-status.recording~.recorder-visualizer .bar:nth-child(2n) {
    animation-duration: 0.6s;
}

@keyframes visualize {
    0% {
        height: 4px;
    }

    100% {
        height: 30px;
    }
}

.recorder-controls {
    display: flex;
    gap: 15px;
}

.rec-btn,
.stop-btn,
.play-btn,
.del-btn {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    border: 1px solid var(--border-color);
    background: transparent;
    color: var(--text-color);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}

.rec-btn::after {
    content: '';
    width: 12px;
    height: 12px;
    background-color: var(--accent-color);
    border-radius: 50%;
}

.rec-btn:hover {
    border-color: var(--accent-color);
}

.stop-btn::after {
    content: '';
    width: 12px;
    height: 12px;
    background-color: var(--text-color);
    border-radius: 2px;
}

.stop-btn:disabled,
.play-btn:disabled,
.del-btn:disabled {
    opacity: 0.3;
    cursor: not-allowed;
    border-color: #333;
}

.play-btn:hover:not(:disabled),
.del-btn:hover:not(:disabled) {
    border-color: var(--text-color);
    background-color: #111;
}

.transcription-preview {
    width: 100%;
    font-size: 12px;
    color: #888;
    text-align: center;
    min-height: 20px;
    margin-top: 5px;
    font-style: italic;
}

/* Custom Audio Player in Grid */
.audio-player-custom {
    display: flex;
    align-items: center;
    gap: 10px;
    background-color: var(--bg-color);
    padding: 10px;
    border-radius: 4px;
    border: 1px solid var(--border-color);
    margin-bottom: 5px;
}

.audio-play-btn {
    background: none;
    border: none;
    color: var(--accent-color);
    font-size: 20px;
    cursor: pointer;
}

.audio-wave {
    flex-grow: 1;
    height: 2px;
    background-color: #333;
    position: relative;
}

.audio-progress {
    position: absolute;
    left: 0;
    top: 0;
    height: 100%;
    background-color: var(--accent-color);
    width: 0%;
}

.transcribe-btn {
    background: none;
    border: 1px solid var(--border-color);
    color: #666;
    font-size: 10px;
    padding: 2px 6px;
    border-radius: 4px;
    cursor: pointer;
    margin-top: 5px;
}

.transcribe-btn:hover {
    color: var(--text-color);
    border-color: var(--text-color);
}

.transcript-text {
    font-size: 12px;
    color: #888;
    margin-top: 5px;
    padding: 5px;
    border-left: 2px solid var(--border-color);
    display: none;
}

.transcript-text.visible {
    display: block;
}