:root {
    --primary-color: #fbbf24; /* Warm yellow/orange from flower */
    --primary-hover: #f59e0b;
    --card-bg: rgba(20, 20, 20, 0.45); /* Dark glass */
    --card-header-bg: rgba(255, 255, 255, 0.1); /* Subtle header sep */
    --text-color: #ffffff;
    --text-muted: rgba(255, 255, 255, 0.7);
    --border-color: rgba(255, 255, 255, 0.15);
    --shadow-sm: 0 2px 4px rgba(0, 0, 0, 0.2);
    --shadow-md: 0 8px 16px rgba(0, 0, 0, 0.3);
    --font-main: 'Inter', sans-serif;
    --font-heading: 'Poppins', sans-serif;
    --bg-image-url: url('https://images.unsplash.com/photo-1460500063983-994d4c27756c?q=80&w=2940&auto=format&fit=crop'); /* Warm nature/flower vibe */
}

* {
    box-sizing: border-box;
}

body {
    font-family: var(--font-main);
    margin: 0;
    padding: 0;
    background-image: var(--bg-image-url);
    background-size: cover;
    background-position: center;
    background-attachment: fixed;
    color: var(--text-color);
    min-height: 100vh;
    overflow-x: hidden;
}

/* Dark overlay to ensure text readability */
.background-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.3);
    pointer-events: none;
    z-index: 0;
}

header {
    padding: 30px 50px;
    display: grid;
    grid-template-columns: 1fr auto 1fr; /* Left widgets, center search, right settings */
    align-items: start;
    margin-bottom: 20px;
    position: relative;
    z-index: 10;
}

/* Header Left: Clock/Weather Widget Vibe */
.header-left {
    display: flex;
    flex-direction: column;
    gap: 5px;
}

.clock {
    font-family: var(--font-heading);
    font-size: 4em;
    font-weight: 300; /* Thin font like image */
    line-height: 1;
    text-shadow: 0 2px 10px rgba(0,0,0,0.3);
    margin-bottom: 0;
}

.date-display {
    font-size: 1.2em;
    font-weight: 400;
    color: rgba(255, 255, 255, 0.9);
    margin-bottom: 15px;
}

.weather {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    background: rgba(20, 20, 20, 0.5);
    backdrop-filter: blur(10px);
    padding: 10px 20px;
    border-radius: 15px;
    border: 1px solid var(--border-color);
    font-size: 1em;
    color: rgba(255, 255, 255, 0.9);
    width: fit-content;
}

.weather i {
    color: var(--primary-color);
    font-size: 1.2em;
}

/* Center: Search Bar */
.search-container {
    display: flex;
    justify-content: center;
    padding-top: 10px;
}

.search-bar {
    display: flex;
    align-items: center;
    background: rgba(255, 255, 255, 0.95); /* White bar like image */
    padding: 12px 25px;
    border-radius: 30px;
    width: 500px;
    max-width: 100%;
    box-shadow: 0 5px 15px rgba(0,0,0,0.2);
    transition: transform 0.2s;
}

.search-bar:focus-within {
    transform: scale(1.02);
}

.search-bar i {
    color: #666;
    margin-right: 15px;
    font-size: 1.1em;
}

/* Google Apps Launcher */
.apps-launcher-container {
    position: relative;
    margin-left: 15px;
    display: flex;
    align-items: center;
}

.apps-btn {
    background: rgba(255, 255, 255, 0.1);
    border: none;
    cursor: pointer;
    color: rgba(255, 255, 255, 0.8);
    font-size: 1.2em;
    padding: 10px;
    border-radius: 50%;
    width: 40px;
    height: 40px;
    display: flex;
    justify-content: center;
    align-items: center;
    transition: all 0.2s;
}

.apps-btn:hover, .apps-btn.active {
    background: rgba(255, 255, 255, 0.2);
    color: #fff;
}

.apps-dropdown {
    position: absolute;
    top: 120%;
    right: -10px; /* Align slightly off-center to match reference */
    background: #fcfcfc; /* Near white background */
    border: 1px solid #dadce0;
    border-radius: 8px;
    padding: 20px 10px 10px 10px;
    width: 320px; /* Wider for 3 columns */
    box-shadow: 0 1px 2px 0 rgba(60,64,67,0.3), 0 1px 3px 1px rgba(60,64,67,0.15);
    z-index: 1000;
    transform-origin: top right;
    transition: opacity 0.2s ease, transform 0.2s ease;
    opacity: 1;
    transform: scale(1);
    max-height: 450px;
    overflow-y: auto;
}

.apps-dropdown.hidden {
    display: none;
    opacity: 0;
    transform: scale(0.95);
}

/* Scrollbar for apps dropdown */
.apps-dropdown::-webkit-scrollbar {
    width: 8px;
}

.apps-dropdown::-webkit-scrollbar-track {
    background: transparent;
}

.apps-dropdown::-webkit-scrollbar-thumb {
    background-color: #dadce0;
    border-radius: 4px;
}


.apps-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 10px; /* Reduced gap */
}

.app-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-start;
    text-decoration: none;
    color: #202124; /* Dark grey text */
    padding: 14px 6px; /* Official-like padding */
    border-radius: 8px;
    transition: background 0.2s;
    height: auto;
    min-height: 84px;
}

.app-item:hover {
    background: #e8f0fe; /* Light blue hover */
}

.app-item img, .google-icon-sprite {
    width: 53px; /* Match logical sprite width */
    height: 58px; /* Match logical sprite stride */
    margin: 6px auto 10px auto;
    object-fit: contain;
    border-radius: 0 !important;
    display: block;
}

.google-icon-sprite {
    background-image: url('https://ssl.gstatic.com/gb/images/sprites/p_2x_6ab3ae91cfe4.png');
    background-size: 53px auto; /* 53px (106/2) matches the 58px stride (116/2) of the offsets */
    background-repeat: no-repeat;
    width: 53px; 
    height: 58px;
    margin: 6px auto 10px auto; /* Center block and add spacing for scale */
    display: block;
    transform: scale(1.2); /* Scale up to ~64px visual size */
    transform-origin: center center;
}

.app-item span {
    font-size: 12px;
    color: #202124;
    text-align: center;
    white-space: normal; /* Allow wrapping */
    overflow: hidden;
    text-overflow: ellipsis;
    /* width: 100%; */
    line-height: 1.3;
    margin-top: 4px;
    display: -webkit-box;
    -webkit-line-clamp: 2; /* Limit to 2 lines */
    line-clamp: 2;
    -webkit-box-orient: vertical;
    max-width: 100%;
}

.search-bar input {
    border: none;
    background: transparent;
    outline: none;
    width: 100%;
    font-size: 1.1em;
    color: #333;
    font-family: var(--font-main);
}

/* Right: Settings */
.settings-controls {
    display: flex;
    justify-content: flex-end;
    gap: 15px;
    padding-top: 10px;
}

.settings-controls button {
    background: transparent;
    border: none;
    cursor: pointer;
    font-size: 1.2em;
    color: rgba(255, 255, 255, 0.7);
    transition: all 0.2s ease;
    padding: 5px;
}

.settings-controls button:hover {
    color: #fff;
    transform: rotate(15deg);
}

.settings-controls button.active {
    color: var(--primary-color);
}


.grid-container {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
    gap: 20px; 
    padding: 0 50px 50px 50px;
    max-width: 100%;
    position: relative;
    z-index: 1;
}

.grid-container.masonry-mode {
    align-items: start !important;
    grid-auto-rows: 1px !important; /* Enable masonry-like row sizing */
}

.grid-container.grid-mode {
    align-items: stretch !important; /* Cards stretch to equal height */
    grid-auto-rows: auto !important;
}

.grid-container.grid-mode .card {
    height: 100%; /* Ensure card fills the stretched space */
}

/* Glass Cards */
.card {
    background: var(--card-bg);
    backdrop-filter: blur(15px);
    -webkit-backdrop-filter: blur(15px);
    border-radius: 16px;
    box-shadow: var(--shadow-sm);
    overflow: visible;
    display: flex;
    flex-direction: column;
    transition: all 0.3s ease;
    position: relative;
    border: 1px solid var(--border-color);
}

.card:hover {
    transform: translateY(-5px);
    background: rgba(30, 30, 30, 0.55);
    box-shadow: var(--shadow-md);
    border-color: rgba(255, 255, 255, 0.3);
}

.card.dragging {
    opacity: 0.6;
    border: 2px dashed var(--primary-color);
    background: rgba(255, 255, 255, 0.1);
}

.card-header {
    background: transparent; /* No separate header bg */
    color: var(--text-color);
    padding: 10px 15px; /* Reduced from 15px 20px */
    font-family: var(--font-heading);
    font-weight: 600;
    text-transform: uppercase;
    font-size: 0.9em;
    letter-spacing: 1px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid var(--border-color);
    border-radius: 16px 16px 0 0; /* Rounded top corners */
}

.card-header.branded {
    /* Branded headers might need to be taller if we want a big banner */
    min-height: 100px; /* Increased for better banner visibility */
    position: relative;
    align-items: flex-start; /* Align controls to top */
    padding-top: 10px;
}

.branded-icon-wrapper {
    position: absolute;
    bottom: -20px;
    left: 15px;
    width: 50px;
    height: 50px;
    border-radius: 50%;
    background: #fff;
    border: 3px solid var(--card-bg); /* Cutout effect matching card bg */
    overflow: hidden;
    box-shadow: 0 4px 6px rgba(0,0,0,0.2);
    z-index: 2;
    display: flex;
    align-items: center;
    justify-content: center;
}

.branded-icon-wrapper img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.branded-title-text {
    /* If we want text below banner? */
    /* Or if we just use icon. */
    /* For now, user wants icon. */
    display: none;
}

/* Adjust body padding if branded icon is overlapping */
.card.has-branded-header .card-body {
    padding-top: 25px; /* Make space for the overlapping icon */
}

/* Group Handle */
.group-handle {
    display: none !important;
    cursor: grab;
    color: rgba(255,255,255,0.5);
    margin-right: 10px;
}

body.edit-mode .group-handle {
    display: inline-block !important;
}

.group-handle:hover {
    color: #fff;
}

.card-body {
    padding: 8px; /* Reduced from 10px */
    flex-grow: 1;
}

.link-item {
    display: flex;
    align-items: center;
    padding: 8px 10px; /* Reduced from 12px 15px */
    margin-bottom: 2px; /* Reduced from 4px */
    background-color: transparent;
    border-radius: 10px;
    text-decoration: none;
    color: var(--text-color); /* White text */
    font-size: 0.9em; /* Slightly reduced */
    font-weight: 400;
    transition: all 0.2s;
    border: 1px solid transparent;
    gap: 12px; /* Space between icon and text */
}

.link-item:hover {
    background-color: rgba(255, 255, 255, 0.1);
    backdrop-filter: blur(5px);
    transform: translateX(5px);
}

.link-icon {
    width: 20px;
    height: 20px;
    object-fit: contain;
    border-radius: 50%; /* Circle mask */
    flex-shrink: 0; /* Prevent shrinking if text is long */
}

i.link-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1em;
    border-radius: 0;
    color: var(--primary-color);
}

/* Header Actions */
.header-actions {
    display: none;
    gap: 10px;
}

body.edit-mode .header-actions {
    display: flex;
}

.header-btn {
    cursor: pointer;
    color: rgba(255,255,255,0.5);
    transition: all 0.2s;
}

.header-btn:hover {
    color: var(--primary-color);
}

/* Add Group Button */
.add-group-card {
    border: 2px dashed rgba(255,255,255,0.2);
    background: rgba(255,255,255,0.05);
    backdrop-filter: blur(4px);
    display: none;
    justify-content: center;
    align-items: center;
    min-height: 200px;
    cursor: pointer;
    color: rgba(255,255,255,0.5);
    font-size: 2.5em;
    border-radius: 16px;
    transition: all 0.3s;
}

body.edit-mode .add-group-card {
    display: flex;
}

.add-group-card:hover {
    border-color: var(--primary-color);
    color: var(--primary-color);
    background: rgba(255,255,255,0.1);
}

/* Dropdown/List Styles */
.list-container {
    margin-bottom: 2px; /* Reduced from 4px */
    border-radius: 10px;
    overflow: visible;
    position: relative;
}

.list-header {
    padding: 8px 10px; /* Reduced from 12px 15px */
    background-color: transparent;
    cursor: pointer;
    font-weight: 500;
    display: flex;
    justify-content: space-between;
    align-items: center;
    color: var(--text-color);
    user-select: none;
    position: relative;
    z-index: 2;
    border-radius: 10px;
    transition: background 0.2s;
}

.list-header:hover {
    background-color: rgba(255, 255, 255, 0.1);
}

.list-header i {
    transition: transform 0.3s;
    font-size: 0.8em;
    opacity: 0.7;
}

.list-header.open i {
    transform: rotate(180deg);
}

/* Popup Menu for List Items */
.list-items {
    display: none;
    position: absolute;
    top: 50%; /* Overlap slightly */
    left: 100%; /* Flyout to right? Or Standard dropdown? Reference had sidebar flyout. */
    /* Let's stick to standard drop DOWN for grid layout, but styled like glass */
    top: 100%;
    left: 0;
    width: 100%;
    z-index: 100;
    
    background: rgba(30, 30, 30, 0.95); /* Opaque dark */
    backdrop-filter: blur(15px);
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 12px;
    padding: 5px;
    box-shadow: 0 10px 30px rgba(0,0,0,0.5);
    
    margin-top: 5px;
    animation: fadeIn 0.2s ease;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(-5px); }
    to { opacity: 1; transform: translateY(0); }
}

.list-items.open {
    display: block;
}

.list-items .link-item {
    padding-left: 15px;
    border-radius: 8px;
    font-size: 0.9em;
}

.list-items .link-item:hover {
    background-color: rgba(255, 255, 255, 0.15);
}

/* --- Modals (Light Theme for readability in editing) --- */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.7);
    backdrop-filter: blur(8px);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
}

.hidden {
    display: none;
}

.modal-content {
    background: #fff; /* Keep modals light for easy editing */
    color: #333;
    padding: 30px;
    border-radius: 20px;
    width: 500px;
    max-width: 90%;
    box-shadow: 0 25px 50px rgba(0,0,0,0.4);
    max-height: 90vh;
    overflow-y: auto;
}

.modal-content h3 {
    margin-top: 0;
    font-family: var(--font-heading);
    border-bottom: 1px solid #eee;
    padding-bottom: 15px;
}

.modal-content.wide {
    width: 800px;
}

.modal-content input,
.modal-content textarea {
    width: 100%;
    padding: 12px;
    margin: 10px 0;
    border: 1px solid #ddd;
    border-radius: 8px;
    background: #f9fafb;
    color: #333;
}

/* Modal Buttons */
.modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    margin-top: 20px;
}

.modal-actions button {
    padding: 10px 20px;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-weight: 600;
}

.modal-actions button#cancel-group-edit,
.modal-actions button#cancel-add-group,
.modal-actions button#close-settings {
    background: #e5e7eb;
    color: #374151;
}

.modal-actions button.primary-btn {
    background: var(--primary-color);
    color: #fff; /* Might need dark text on yellow? */
    color: #000; /* Black text on yellow for better contrast */
}

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

/* Edit Rows in Modal */
.link-edit-row {
    background: #fff;
    border: 1px solid #e5e7eb;
    color: #333;
    display: flex;
    gap: 10px;
    align-items: center;
    padding: 10px;
    margin-bottom: 8px;
    border-radius: 8px;
}

.link-edit-row input {
    background: #fff;
    border: 1px solid #d1d5db;
}

.link-edit-row.list-row {
    background: #fff7ed; /* Light orange tint */
    border-color: var(--primary-color);
}

.sub-link-row {
    margin-left: 30px;
    border-left: 3px solid var(--primary-color);
    background: #f9fafb;
}

.link-edit-row.dragging {
    opacity: 0.5;
    border: 2px dashed var(--primary-color);
}

.add-link-row-btn, .add-list-btn {
    background: #f3f4f6;
    color: #4b5563;
    border: 1px dashed #9ca3af;
    width: 100%;
    padding: 12px;
    border-radius: 8px;
    margin-top: 10px;
    cursor: pointer;
}

.add-link-row-btn:hover, .add-list-btn:hover {
    background: #e5e7eb;
    border-color: var(--primary-color);
    color: var(--primary-color);
}

/* Helper class for children being moved with their parent list */
.link-edit-row.dragging-child {
    opacity: 0.7;
    background-color: #f0f8ff;
    pointer-events: none; /* Ensure they don't interfere with drag events */
    transition: none; /* Snap with parent */
}

/* Visual feedback when dragging over a list to nest inside it */
.link-edit-row.drag-over-list {
    border: 2px dashed #2c82c9;
    background-color: #e6f7ff;
}

/* Visual feedback for inserting before/after */
.link-edit-row.drag-over-top {
    border-top: 2px solid #2c82c9;
}

.link-edit-row.drag-over-bottom {
    border-bottom: 2px solid #2c82c9;
}

/* Media Queries for Responsiveness */
@media (max-width: 800px) {
    header {
        grid-template-columns: 1fr;
        gap: 20px;
        text-align: center;
    }
    
    .header-left {
        align-items: center;
    }
    
    .search-container {
        width: 100%;
    }
    
    .search-bar {
        width: 100%;
    }
    
    .settings-controls {
        justify-content: center;
    }
    
    .clock {
        font-size: 3em;
    }
}
