:root {
    --primary-color: #007aff;
    --primary-hover: #0066d6;
    --card-bg: rgba(255, 255, 255, 0.08);
    --card-header-bg: rgba(255, 255, 255, 0.06);
    --text-color: #ffffff;
    --text-muted: rgba(255, 255, 255, 0.7);
    --text-tertiary: rgba(255, 255, 255, 0.45);
    --border-color: rgba(255, 255, 255, 0.15);
    --glass-border: rgba(255, 255, 255, 0.2);
    --shadow-sm: inset 0 0.5px 0 rgba(255,255,255,0.2), 0 4px 24px rgba(0,0,0,0.12), 0 1px 4px rgba(0,0,0,0.08);
    --shadow-md: inset 0 0.5px 0 rgba(255,255,255,0.25), 0 8px 32px rgba(0,0,0,0.18), 0 2px 8px rgba(0,0,0,0.1);
    --font-main: -apple-system, BlinkMacSystemFont, 'SF Pro Display', 'SF Pro Text', 'Inter', system-ui, sans-serif;
    --font-heading: -apple-system, BlinkMacSystemFont, 'SF Pro Display', 'SF Pro Text', 'Inter', system-ui, sans-serif;
    --bg-image-url: url('https://images.unsplash.com/photo-1460500063983-994d4c27756c?q=80&w=2940&auto=format&fit=crop');
}

* {
    box-sizing: border-box;
}

body {
    font-family: var(--font-main);
    -webkit-font-smoothing: antialiased;
    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.25);
    pointer-events: none;
    z-index: 0;
}

header {
    padding: 28px 32px 20px;
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    align-items: start;
    margin-bottom: 10px;
    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: 200;
    line-height: 1;
    letter-spacing: -2px;
    text-shadow: 0 2px 12px rgba(0,0,0,0.4);
    margin-bottom: 0;
    color: #fff;
}

.date-display {
    font-size: 0.95em;
    font-weight: 400;
    color: rgba(255, 255, 255, 0.85);
    text-shadow: 0 1px 6px rgba(0,0,0,0.3);
    margin-bottom: 8px;
}

/* Calendar Card */
.calendar-card .card-header {
    padding: 10px 12px;
}

.calendar-card .card-header i {
    margin-right: 4px;
}

.calendar-event {
    display: flex;
    gap: 10px;
    padding: 5px 0;
    text-decoration: none;
    color: #fff;
    border-top: 0.5px solid rgba(255, 255, 255, 0.08);
    transition: opacity 0.15s;
}

.calendar-event:first-of-type {
    border-top: none;
}

.calendar-event:hover {
    opacity: 0.7;
}

.calendar-event-time {
    font-size: 0.75em;
    color: rgba(255, 255, 255, 0.5);
    white-space: nowrap;
    min-width: 65px;
}

.calendar-event-title {
    font-size: 0.8em;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.weather {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 0.9em;
    color: rgba(255, 255, 255, 0.85);
    text-shadow: 0 1px 6px rgba(0,0,0,0.3);
    width: fit-content;
}

.weather i {
    color: var(--text-muted);
    font-size: 1em;
}

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

.search-bar {
    display: flex;
    align-items: center;
    gap: 10px;
    background: rgba(255, 255, 255, 0.12);
    backdrop-filter: blur(40px) saturate(180%);
    -webkit-backdrop-filter: blur(40px) saturate(180%);
    padding: 10px 18px;
    border-radius: 12px;
    border: 0.5px solid var(--glass-border);
    width: 500px;
    max-width: 100%;
    box-shadow: inset 0 0.5px 0 rgba(255,255,255,0.25), 0 2px 8px rgba(0,0,0,0.12);
    transition: all 0.2s;
}

.search-bar:focus-within {
    background: rgba(255, 255, 255, 0.18);
    border-color: rgba(255,255,255,0.35);
    box-shadow: inset 0 0.5px 0 rgba(255,255,255,0.3), 0 4px 20px rgba(0,0,0,0.15);
}

.search-bar i {
    color: var(--text-muted);
    font-size: 0.85em;
}

/* 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);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border: 0.5px solid var(--glass-border);
    cursor: pointer;
    color: var(--text-muted);
    font-size: 0.9em;
    padding: 10px;
    border-radius: 10px;
    width: 40px;
    height: 40px;
    display: flex;
    justify-content: center;
    align-items: center;
    transition: all 0.15s;
    box-shadow: inset 0 0.5px 0 rgba(255,255,255,0.2);
}

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

.apps-dropdown {
    position: absolute;
    top: 120%;
    right: -10px;
    background: rgba(255, 255, 255, 0.12);
    backdrop-filter: blur(40px) saturate(180%);
    -webkit-backdrop-filter: blur(40px) saturate(180%);
    border: 0.5px solid var(--glass-border);
    border-radius: 16px;
    padding: 14px 10px 10px 10px;
    width: 320px;
    box-shadow:
        inset 0 0.5px 0 rgba(255,255,255,0.25),
        0 8px 32px rgba(0,0,0,0.2);
    z-index: 1000;
    transform-origin: top right;
    transition: opacity 0.2s ease, transform 0.2s ease;
    opacity: 1;
    transform: scale(1);
    max-height: 80vh;
    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: rgba(255,255,255,0.15);
    border-radius: 3px;
}


.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: #fff;
    padding: 14px 6px;
    border-radius: 10px;
    transition: background 0.12s;
    height: auto;
    min-height: 84px;
}

.app-item:hover {
    background: rgba(255, 255, 255, 0.1);
}

.app-item img, .google-icon-sprite {
    width: 40px;
    height: 40px;
    margin: 6px auto 10px auto;
    object-fit: contain;
    display: block;
    background-size: contain;
    background-repeat: no-repeat;
    background-position: center;
}

.app-item span {
    font-size: 12px;
    color: var(--text-muted);
    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: 0.9em;
    color: #fff;
    font-family: var(--font-main);
}

.search-bar input::placeholder {
    color: var(--text-tertiary);
}

/* Search bar wrapper for dropdown positioning */
.search-bar-wrapper {
    position: relative;
    width: 500px;
    max-width: 100%;
}

.search-bar-wrapper .search-bar {
    width: 100%;
}

/* Search dropdown */
.search-dropdown {
    position: absolute;
    top: calc(100% + 6px);
    left: 0;
    right: 0;
    background: rgba(255, 255, 255, 0.12);
    backdrop-filter: blur(40px) saturate(180%);
    -webkit-backdrop-filter: blur(40px) saturate(180%);
    border: 0.5px solid var(--glass-border);
    border-radius: 14px;
    padding: 6px;
    box-shadow:
        inset 0 0.5px 0 rgba(255,255,255,0.25),
        0 8px 32px rgba(0,0,0,0.2);
    z-index: 100;
    max-height: 400px;
    overflow-y: auto;
}

.search-dropdown.hidden {
    display: none;
}

.search-dropdown-section {
    padding: 6px 8px 4px;
    font-size: 0.65em;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-tertiary);
}

.search-dropdown-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 12px;
    border-radius: 10px;
    color: var(--text-color);
    text-decoration: none;
    font-size: 0.85em;
    cursor: pointer;
    transition: background 0.1s;
}

.search-dropdown-item:hover,
.search-dropdown-item.active {
    background: rgba(255, 255, 255, 0.1);
}

.search-dropdown-item .search-item-icon {
    width: 16px;
    height: 16px;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-tertiary);
    font-size: 0.8em;
}

.search-dropdown-item .search-item-icon img {
    width: 16px;
    height: 16px;
    border-radius: 3px;
    object-fit: contain;
}

.search-dropdown-item .search-item-text {
    flex: 1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.search-dropdown-item .search-item-group {
    font-size: 0.75em;
    color: var(--text-tertiary);
    flex-shrink: 0;
}

.search-dropdown-divider {
    height: 0.5px;
    background: rgba(255,255,255,0.08);
    margin: 4px 8px;
}

/* Right: Settings */
.settings-controls {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    padding-top: 10px;
    align-items: center;
    position: absolute;
    top: 16px;
    right: 16px;
    z-index: 10;
}

.settings-controls button {
    background: rgba(255, 255, 255, 0.08);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border: 0.5px solid rgba(255, 255, 255, 0.15);
    border-radius: 50%;
    width: 34px;
    height: 34px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 0.8em;
    color: var(--text-muted);
    transition: all 0.15s;
    padding: 0;
}

.settings-controls button.hidden {
    display: none;
}

.settings-controls button:hover {
    background: rgba(255, 255, 255, 0.15);
    color: #fff;
}

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

/* Toast notifications */
.toast-container {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
    z-index: 9999;
    pointer-events: none;
}

.toast {
    background: var(--card-bg);
    backdrop-filter: blur(15px);
    -webkit-backdrop-filter: blur(15px);
    color: #fff;
    padding: 12px 16px;
    border-radius: 12px;
    box-shadow: var(--shadow-md);
    min-width: 260px;
    max-width: 360px;
    font-size: 0.95em;
    border: 1px solid var(--border-color);
    text-align: center;
    pointer-events: auto;
}

.toast.error {
    border-color: #e57373;
}

.toast.success {
    border-color: #81c784;
}

.toast.hide {
    opacity: 0;
    transform: translateY(-10px);
    transition: opacity 0.2s ease, transform 0.2s ease;
}


.grid-container {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 16px;
    padding: 0 32px 40px 32px;
    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 */
    row-gap: 0 !important; /* Disable vertical gap for manual calculation to avoid grid quirks */
    column-gap: 20px !important; /* Keep horizontal gap */
}

.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 */
}

/* Liquid Glass Cards */
.card {
    background: var(--card-bg);
    backdrop-filter: blur(40px) saturate(180%);
    -webkit-backdrop-filter: blur(40px) saturate(180%);
    border-radius: 16px;
    box-shadow: var(--shadow-sm);
    overflow: visible;
    display: flex;
    flex-direction: column;
    transition: transform 0.2s, box-shadow 0.2s;
    position: relative;
    border: 0.5px solid var(--glass-border);
}

/* Animation */
.card.animate-in {
    animation: popIn 0.6s cubic-bezier(0.34, 1.56, 0.64, 1) both;
}

@keyframes popIn {
    0% {
        opacity: 0;
        transform: scale(0.9) translateY(10px);
    }
    100% {
        opacity: 1;
        transform: scale(1) translateY(0);
    }
}

/* Section tint overlay — sits on top of glass backdrop */
.card.section-tinted::after {
    content: '';
    position: absolute;
    inset: 0;
    border-radius: 16px;
    background: var(--section-tint);
    pointer-events: none;
    z-index: 0;
}

.card.section-tinted > * {
    position: relative;
    z-index: 1;
}

.card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}

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

.card-header {
    background: linear-gradient(180deg, rgba(255,255,255,0.06) 0%, transparent 100%);
    color: rgba(255, 255, 255, 0.85);
    text-shadow: 0 1px 4px rgba(0,0,0,0.2);
    padding: 14px 18px 12px;
    font-family: var(--font-heading);
    font-weight: 600;
    text-transform: uppercase;
    font-size: 0.8em;
    letter-spacing: 0.8px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 0.5px solid rgba(255,255,255,0.08);
    border-radius: 16px 16px 0 0;
}

.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 {
    cursor: grab;
    color: rgba(255,255,255,0.7);
    text-shadow: 0 1px 4px rgba(0,0,0,0.3);
    width: 0;
    overflow: hidden;
    margin: 0;
    transition: width 0.15s, margin 0.15s;
}

body.edit-mode .group-handle {
    width: auto;
    overflow: visible;
    margin-right: 10px;
}

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

.card-body {
    padding: 6px 6px 8px;
    flex-grow: 1;
}

.link-item {
    display: flex;
    align-items: center;
    padding: 9px 12px;
    margin-bottom: 0;
    background-color: transparent;
    border-radius: 10px;
    text-decoration: none;
    color: #fff;
    text-shadow: 0 1px 4px rgba(0,0,0,0.2);
    font-family: var(--link-font, inherit);
    font-size: 0.88em;
    font-weight: var(--link-weight, 400);
    transition: background 0.12s;
    border: none;
    gap: 10px;
}

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

/* Large Icon Grid */
.large-icon-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(70px, 1fr));
    gap: 4px;
    padding: 8px 4px 4px;
    border-top: 0.5px solid rgba(255, 255, 255, 0.08);
    margin-top: 4px;
}

.large-icon-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    padding: 10px 4px 8px;
    border-radius: 10px;
    text-decoration: none;
    transition: background 0.12s;
    cursor: pointer;
}

.large-icon-item:hover {
    background: rgba(255, 255, 255, 0.08);
}

.large-icon-img {
    width: 40px;
    height: 40px;
    border-radius: 10px;
    background-size: contain;
    background-repeat: no-repeat;
    background-position: center;
    background-color: rgba(255, 255, 255, 0.1);
}

.large-icon-label {
    font-size: 0.65em;
    color: rgba(255, 255, 255, 0.7);
    text-align: center;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 100%;
    line-height: 1.2;
}

.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: flex;
    gap: 10px;
    visibility: hidden;
}

body.edit-mode .header-actions {
    visibility: visible;
}

.header-btn {
    cursor: pointer;
    color: rgba(255, 255, 255, 0.7);
    transition: all 0.12s;
    font-size: 0.75em;
    padding: 6px;
    border-radius: 6px;
    background: rgba(255, 255, 255, 0.1);
}

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

/* Add Group Button */
.add-group-card {
    border: 1.5px dashed rgba(255,255,255,0.15);
    background: rgba(255,255,255,0.04);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    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);
}

/* List Section (inline) Styles */
.list-section {
    margin-top: 4px;
}

.list-section-title {
    font-size: 0.7em;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: rgba(255, 255, 255, 0.45);
    padding: 6px 10px 2px;
    border-top: 0.5px solid rgba(255, 255, 255, 0.08);
}

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

.list-header {
    padding: 8px 10px;
    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: 100%;
    left: 0;
    width: 100%;
    z-index: 100;

    background: rgba(40, 40, 45, 0.92);
    backdrop-filter: blur(40px) saturate(180%);
    -webkit-backdrop-filter: blur(40px) saturate(180%);
    border: 0.5px solid rgba(255, 255, 255, 0.15);
    border-radius: 12px;
    padding: 5px;
    box-shadow: 0 8px 32px rgba(0,0,0,0.3);

    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-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 Group modal (panel + rows) --- */
#edit-group-modal.modal {
    background: rgba(0, 0, 0, 0.45);
    backdrop-filter: blur(20px) saturate(180%);
    -webkit-backdrop-filter: blur(20px) saturate(180%);
}

#edit-group-modal .edit-group-panel {
    background: rgba(255, 255, 255, 0.92);
    backdrop-filter: blur(40px) saturate(200%);
    -webkit-backdrop-filter: blur(40px) saturate(200%);
    color: #1d1d1f;
    border-radius: 14px;
    width: 720px;
    max-width: 92%;
    box-shadow:
        0 0 0 0.5px rgba(0, 0, 0, 0.12),
        0 24px 80px rgba(0, 0, 0, 0.28),
        0 2px 12px rgba(0, 0, 0, 0.08);
    display: grid;
    grid-template-rows: auto 1fr auto;
    max-height: 82vh;
    overflow: hidden;
    font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Text', system-ui, sans-serif;
}

#edit-group-modal .panel-header {
    padding: 20px 24px 0;
}

#edit-group-modal .title-input {
    width: 100%;
    padding: 10px 14px;
    border: none;
    border-radius: 8px;
    background: rgba(0, 0, 0, 0.04);
    color: #1d1d1f;
    font-size: 1.05em;
    font-weight: 600;
    font-family: inherit;
    letter-spacing: -0.01em;
    transition: background 0.2s, box-shadow 0.2s;
    box-sizing: border-box;
}

#edit-group-modal .title-input:focus {
    outline: none;
    background: #fff;
    box-shadow: 0 0 0 3.5px rgba(0, 122, 255, 0.3);
}

#edit-group-modal .brand-row {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-top: 14px;
    padding-bottom: 16px;
    border-bottom: 0.5px solid rgba(0, 0, 0, 0.1);
}

#edit-group-modal .brand-toggle {
    display: flex;
    align-items: center;
    gap: 7px;
    font-size: 0.82em;
    font-weight: 500;
    color: #86868b;
    cursor: pointer;
    user-select: none;
    white-space: nowrap;
    letter-spacing: -0.01em;
}

#edit-group-modal .brand-toggle input[type="checkbox"] {
    -webkit-appearance: none;
    appearance: none;
    width: 18px;
    height: 18px;
    border-radius: 5px;
    border: 1.5px solid #d2d2d7;
    background: #fff;
    cursor: pointer;
    position: relative;
    transition: all 0.15s;
    flex-shrink: 0;
    margin: 0;
}

#edit-group-modal .brand-toggle input[type="checkbox"]:checked {
    background: #007aff;
    border-color: #007aff;
}

#edit-group-modal .brand-toggle input[type="checkbox"]:checked::after {
    content: '';
    position: absolute;
    top: 2px;
    left: 5.5px;
    width: 5px;
    height: 9px;
    border: solid #fff;
    border-width: 0 1.8px 1.8px 0;
    transform: rotate(45deg);
}

#edit-group-modal .brand-url {
    flex: 1;
    min-width: 0;
    padding: 8px 12px;
    border: none;
    border-radius: 7px;
    background: rgba(0, 0, 0, 0.04);
    color: #1d1d1f;
    font-size: 0.85em;
    font-family: inherit;
    transition: background 0.2s, box-shadow 0.2s;
    box-sizing: border-box;
}

/* Header color picker */
#edit-group-modal .header-color-picker {
    display: flex;
    align-items: center;
    gap: 4px;
    margin-left: auto;
}

#edit-group-modal .color-picker-label {
    display: flex;
    align-items: center;
    gap: 6px;
    cursor: pointer;
    font-size: 0.82em;
    color: #86868b;
    white-space: nowrap;
}

#edit-group-modal .color-picker-label input[type="color"] {
    -webkit-appearance: none;
    appearance: none;
    width: 26px;
    height: 26px;
    border: 2px solid rgba(0,0,0,0.1);
    border-radius: 50%;
    padding: 0;
    margin: 0;
    cursor: pointer;
    background: none;
    overflow: hidden;
}

#edit-group-modal .color-picker-label input[type="color"]::-webkit-color-swatch-wrapper {
    padding: 0;
}

#edit-group-modal .color-picker-label input[type="color"]::-webkit-color-swatch {
    border: none;
    border-radius: 50%;
}

#edit-group-modal .color-clear-btn {
    background: none;
    border: none;
    color: #c7c7cc;
    font-size: 0.75em;
    cursor: pointer;
    padding: 4px;
    line-height: 1;
    border-radius: 4px;
}

#edit-group-modal .color-clear-btn:hover {
    color: #ff3b30;
    background: rgba(255, 59, 48, 0.1);
}

/* Section selector */
#edit-group-modal .section-row {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 24px 14px;
    border-bottom: 0.5px solid rgba(0,0,0,0.06);
}

#edit-group-modal .section-new-btn {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    border: none;
    background: rgba(0,0,0,0.06);
    color: #86868b;
    font-size: 1em;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: all 0.12s;
    line-height: 1;
}

#edit-group-modal .section-new-btn:hover {
    background: rgba(0,122,255,0.1);
    color: #007aff;
}

#edit-group-modal .section-input-row {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 0 24px 10px;
}

#edit-group-modal .section-name-input {
    flex: 1;
    padding: 6px 10px;
    border: none;
    border-radius: 7px;
    background: rgba(0,0,0,0.04);
    color: #1d1d1f;
    font-size: 0.82em;
    font-family: inherit;
    transition: background 0.2s, box-shadow 0.2s;
}

#edit-group-modal .section-name-input:focus {
    outline: none;
    background: #fff;
    box-shadow: 0 0 0 3.5px rgba(0,122,255,0.3);
}

#edit-group-modal .section-confirm-btn {
    padding: 5px 12px;
    border: none;
    border-radius: 6px;
    background: #007aff;
    color: #fff;
    font-size: 0.78em;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    transition: background 0.12s;
}

#edit-group-modal .section-confirm-btn:hover {
    background: #0066d6;
}

#edit-group-modal .section-cancel-btn {
    width: 26px;
    height: 26px;
    border-radius: 50%;
    border: none;
    background: rgba(0,0,0,0.06);
    color: #86868b;
    font-size: 0.75em;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.12s;
}

#edit-group-modal .section-cancel-btn:hover {
    background: rgba(255,59,48,0.1);
    color: #ff3b30;
}

#edit-group-modal .section-select {
    flex: 1;
    padding: 6px 10px;
    border: none;
    border-radius: 7px;
    background: rgba(0,0,0,0.04);
    color: #1d1d1f;
    font-size: 0.82em;
    font-family: inherit;
    cursor: pointer;
    -webkit-appearance: none;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='8' height='5'%3E%3Cpath d='M0 0l4 5 4-5z' fill='%2386868b'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 10px center;
    padding-right: 24px;
}

#edit-group-modal .brand-url:focus {
    outline: none;
    background: #fff;
    box-shadow: 0 0 0 3.5px rgba(0, 122, 255, 0.3);
}

#edit-group-modal .panel-scroll {
    overflow-y: auto;
    min-height: 0;
    padding: 14px 24px;
    mask-image: linear-gradient(to bottom,
        transparent 0px, black 8px,
        black calc(100% - 8px), transparent 100%);
    -webkit-mask-image: linear-gradient(to bottom,
        transparent 0px, black 8px,
        black calc(100% - 8px), transparent 100%);
}

#edit-group-modal .panel-scroll::-webkit-scrollbar {
    width: 6px;
}

#edit-group-modal .panel-scroll::-webkit-scrollbar-track {
    background: transparent;
}

#edit-group-modal .panel-scroll::-webkit-scrollbar-thumb {
    background: rgba(0, 0, 0, 0.15);
    border-radius: 3px;
}

#edit-group-modal .panel-scroll::-webkit-scrollbar-thumb:hover {
    background: rgba(0, 0, 0, 0.25);
}

#edit-group-modal .link-edit-row {
    display: flex;
    gap: 8px;
    align-items: center;
    padding: 8px 10px;
    margin-bottom: 2px;
    border-radius: 8px;
    transition: background 0.12s;
    background: transparent;
    border: none;
    color: #1d1d1f;
}

#edit-group-modal .link-edit-row:hover {
    background: rgba(0, 0, 0, 0.03);
}

#edit-group-modal .link-edit-row .handle {
    color: #c7c7cc;
    cursor: grab;
    font-size: 0.8em;
    padding: 2px;
    flex-shrink: 0;
}

#edit-group-modal .link-edit-row input[type="text"] {
    flex: 1;
    padding: 7px 10px;
    border: none;
    border-radius: 6px;
    background: rgba(0, 0, 0, 0.04);
    color: #1d1d1f;
    font-family: inherit;
    font-size: 0.85em;
    min-width: 0;
    transition: background 0.2s, box-shadow 0.2s;
    box-sizing: border-box;
    margin: 0;
}

#edit-group-modal .link-edit-row input[type="text"]:focus {
    outline: none;
    background: #fff;
    box-shadow: 0 0 0 3px rgba(0, 122, 255, 0.3);
}

#edit-group-modal .link-edit-row input[type="text"]:disabled {
    display: none;
}

#edit-group-modal .link-edit-row .row-actions {
    display: flex;
    align-items: center;
    gap: 4px;
    flex-shrink: 0;
}

#edit-group-modal .icon-btn {
    width: 28px;
    height: 28px;
    border: none;
    border-radius: 6px;
    background: transparent;
    color: #86868b;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.78em;
    transition: all 0.12s;
    padding: 0;
    flex-shrink: 0;
}

#edit-group-modal .icon-btn:hover {
    background: rgba(0, 0, 0, 0.06);
    color: #1d1d1f;
}

#edit-group-modal .icon-btn.favicon-active {
    color: #007aff;
}

#edit-group-modal .icon-btn.delete-btn:hover {
    background: rgba(255, 59, 48, 0.1);
    color: #ff3b30;
}

#edit-group-modal .link-edit-row.list-row {
    background: rgba(255, 247, 237, 0.85);
    box-shadow: inset 0 0 0 1px rgba(245, 158, 11, 0.35);
}

#edit-group-modal .link-edit-row.sub-link-row {
    margin-left: 24px;
    padding-left: 12px;
    border-left: 3px solid #007aff;
    background: rgba(0, 122, 255, 0.04);
    border-radius: 0 8px 8px 0;
}

#edit-group-modal .link-edit-row.dragging {
    opacity: 0.5;
    outline: 2px dashed #007aff;
    outline-offset: 2px;
}

#edit-group-modal .link-edit-row.dragging-child {
    opacity: 0.7;
    background-color: rgba(0, 122, 255, 0.08);
    pointer-events: none;
    transition: none;
}

#edit-group-modal .link-edit-row.drag-over-list {
    outline: 2px dashed #007aff;
    background-color: rgba(0, 122, 255, 0.06);
}

#edit-group-modal .link-edit-row.drag-over-top {
    box-shadow: inset 0 2px 0 0 #007aff;
}

#edit-group-modal .link-edit-row.drag-over-bottom {
    box-shadow: inset 0 -2px 0 0 #007aff;
}

#edit-group-modal .panel-footer {
    padding: 16px 24px;
    border-top: 0.5px solid rgba(0, 0, 0, 0.1);
    background: rgba(246, 246, 246, 0.8);
    border-radius: 0 0 14px 14px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

#edit-group-modal .footer-left,
#edit-group-modal .footer-center,
#edit-group-modal .footer-right {
    display: flex;
    gap: 8px;
    align-items: center;
}

#edit-group-modal .footer-center {
    gap: 6px;
}

#edit-group-modal .panel-footer .btn {
    padding: 7px 16px;
    border: none;
    border-radius: 7px;
    cursor: pointer;
    font-family: inherit;
    font-size: 0.82em;
    font-weight: 500;
    letter-spacing: -0.01em;
    transition: all 0.12s;
}

#edit-group-modal .btn-destructive {
    background: rgba(255, 59, 48, 0.1);
    color: #ff3b30;
}

#edit-group-modal .btn-destructive:hover {
    background: rgba(255, 59, 48, 0.18);
}

#edit-group-modal .btn-secondary {
    background: rgba(0, 0, 0, 0.05);
    color: #1d1d1f;
}

#edit-group-modal .btn-secondary:hover {
    background: rgba(0, 0, 0, 0.1);
}

#edit-group-modal .btn-add {
    background: rgba(0, 0, 0, 0.05);
    color: #86868b;
    font-weight: 400;
}

#edit-group-modal .btn-add:hover {
    background: rgba(0, 0, 0, 0.1);
    color: #1d1d1f;
}

#edit-group-modal .btn-add i {
    margin-right: 3px;
    font-size: 0.85em;
}

#edit-group-modal .btn-cancel {
    background: rgba(0, 0, 0, 0.05);
    color: #1d1d1f;
}

#edit-group-modal .btn-cancel:hover {
    background: rgba(0, 0, 0, 0.1);
}

#edit-group-modal .btn-primary {
    background: #007aff;
    color: #fff;
    font-weight: 600;
}

#edit-group-modal .btn-primary:hover {
    background: #0066d6;
}

#edit-group-modal .btn-primary:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

@media (max-width: 640px) {
    #edit-group-modal.modal {
        align-items: flex-end;
    }

    #edit-group-modal .edit-group-panel {
        width: 100%;
        max-width: 100%;
        max-height: 100vh;
        max-height: 100dvh;
        height: 100vh;
        height: 100dvh;
        border-radius: 0;
        background: rgba(255, 255, 255, 0.97);
    }

    #edit-group-modal .panel-header {
        padding: 16px 18px 0;
        padding-top: max(16px, env(safe-area-inset-top));
    }

    #edit-group-modal .panel-scroll {
        padding: 10px 18px;
    }

    #edit-group-modal .link-edit-row {
        padding: 6px 4px;
    }

    #edit-group-modal .link-edit-row input[type="text"] {
        font-size: 0.84em;
        padding: 8px 8px;
    }

    #edit-group-modal .panel-footer {
        border-radius: 0;
        padding: 0;
        padding-bottom: max(8px, env(safe-area-inset-bottom));
        flex-direction: row;
        justify-content: stretch;
        background: rgba(249, 249, 249, 0.94);
        backdrop-filter: blur(20px);
        -webkit-backdrop-filter: blur(20px);
        border-top: 0.5px solid rgba(0, 0, 0, 0.15);
        gap: 0;
        flex-wrap: nowrap;
    }

    #edit-group-modal .footer-left,
    #edit-group-modal .footer-center,
    #edit-group-modal .footer-right {
        display: contents;
    }

    #edit-group-modal .panel-footer .btn {
        flex: 1;
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        gap: 3px;
        padding: 8px 4px 10px;
        border-radius: 0;
        background: transparent;
        font-size: 0.65em;
        font-weight: 500;
        letter-spacing: 0;
        min-width: 0;
    }

    #edit-group-modal .panel-footer .btn::before {
        font-family: 'Font Awesome 6 Free';
        font-weight: 900;
        font-size: 1.6em;
        line-height: 1;
        display: block;
    }

    #edit-group-modal .panel-footer .btn-destructive::before {
        content: '\f1f8'; /* trash */
    }

    #edit-group-modal .panel-footer .btn-secondary::before {
        content: '\f356'; /* arrow-right */
    }

    #edit-group-modal .panel-footer .btn-add:first-child::before {
        content: '\f0c1'; /* link */
    }

    #edit-group-modal .panel-footer .btn-add:last-child::before {
        content: '\f5fd'; /* layer-group */
    }

    #edit-group-modal .panel-footer .btn-cancel::before {
        content: '\f00d'; /* xmark */
    }

    #edit-group-modal .panel-footer .btn-primary::before {
        content: '\f00c'; /* check */
    }

    #edit-group-modal .panel-footer .btn-destructive {
        color: #ff3b30;
        background: transparent;
    }

    #edit-group-modal .panel-footer .btn-secondary {
        color: #86868b;
        background: transparent;
    }

    #edit-group-modal .panel-footer .btn-add {
        color: #86868b;
        background: transparent;
    }

    #edit-group-modal .panel-footer .btn-add i {
        display: none;
    }

    #edit-group-modal .panel-footer .btn-cancel {
        color: #86868b;
        background: transparent;
    }

    #edit-group-modal .panel-footer .btn-primary {
        color: #007aff;
        background: transparent;
        font-weight: 600;
    }

    #edit-group-modal .panel-footer .btn:active {
        opacity: 0.5;
    }
}

/* ── Settings Panel ── */
#settings-modal.modal {
    background: rgba(0, 0, 0, 0.2);
    backdrop-filter: blur(2px);
    -webkit-backdrop-filter: blur(2px);
}

.settings-panel {
    background: rgba(255, 255, 255, 0.92);
    backdrop-filter: blur(40px) saturate(200%);
    -webkit-backdrop-filter: blur(40px) saturate(200%);
    color: #1d1d1f;
    border-radius: 14px;
    width: 720px;
    max-width: 92%;
    max-height: 82vh;
    overflow: hidden;
    box-shadow:
        0 0 0 0.5px rgba(0, 0, 0, 0.12),
        0 24px 80px rgba(0, 0, 0, 0.28),
        0 2px 12px rgba(0, 0, 0, 0.08);
    font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Text', system-ui, sans-serif;
    display: grid;
    grid-template-columns: 170px 1fr;
    grid-template-rows: 1fr auto;
}

.settings-sidebar {
    grid-row: 1 / 3;
    background: rgba(0, 0, 0, 0.03);
    border-right: 0.5px solid rgba(0, 0, 0, 0.1);
    padding: 16px 8px;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.settings-tab {
    display: block;
    width: 100%;
    text-align: left;
    padding: 8px 14px;
    border: none;
    border-radius: 7px;
    background: transparent;
    color: #555;
    font-size: 0.82em;
    font-weight: 500;
    font-family: inherit;
    cursor: pointer;
    transition: all 0.12s;
}

.settings-tab:hover {
    background: rgba(0, 0, 0, 0.04);
}

.settings-tab.active {
    background: #007aff;
    color: #fff;
}

.settings-content {
    padding: 24px 28px;
    overflow-y: auto;
    min-height: 0;
}

.settings-tab-content {
    display: none;
}

.settings-tab-content.active {
    display: block;
}

.settings-section-label {
    font-size: 11px;
    font-weight: 600;
    color: #86868b;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 12px;
}

.settings-field-label {
    display: block;
    font-size: 0.82em;
    font-weight: 500;
    color: #555;
    margin-bottom: 6px;
}

.settings-hint {
    font-size: 0.75em;
    color: #86868b;
    margin-top: 4px;
    margin-bottom: 8px;
}

.settings-panel select,
.settings-panel input[type="text"],
.settings-panel input[type="password"],
.settings-panel textarea {
    width: 100%;
    padding: 8px 12px;
    border: none;
    border-radius: 7px;
    background: rgba(0, 0, 0, 0.04);
    color: #1d1d1f;
    font-size: 0.85em;
    font-family: inherit;
    margin-bottom: 8px;
    transition: background 0.2s, box-shadow 0.2s;
    box-sizing: border-box;
}

.settings-panel select:focus,
.settings-panel input[type="text"]:focus,
.settings-panel input[type="password"]:focus,
.settings-panel textarea:focus {
    outline: none;
    background: #fff;
    box-shadow: 0 0 0 3.5px rgba(0, 122, 255, 0.3);
}

.settings-json-textarea {
    font-family: 'SF Mono', 'Menlo', monospace;
    font-size: 0.8em;
    resize: vertical;
}

/* Settings panel buttons (apply, copy, etc.) */
.settings-panel .btn {
    padding: 7px 16px;
    border: none;
    border-radius: 7px;
    cursor: pointer;
    font-family: inherit;
    font-size: 0.82em;
    font-weight: 500;
    letter-spacing: -0.01em;
    transition: all 0.12s;
}

.settings-panel .btn-primary {
    background: #007aff;
    color: #fff;
    font-weight: 600;
}

.settings-panel .btn-primary:hover {
    background: #0066d6;
}

.settings-panel .btn-secondary {
    background: rgba(0, 0, 0, 0.05);
    color: #1d1d1f;
}

.settings-panel .btn-secondary:hover {
    background: rgba(0, 0, 0, 0.1);
}

.settings-radio-group {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.settings-radio-group label {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.85em;
    color: #333;
    cursor: pointer;
}

.settings-radio-group input[type="radio"] {
    width: auto;
    margin: 0;
}

.settings-shortcuts {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.shortcut-row {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.85em;
    color: #666;
}

.shortcut-row kbd {
    display: inline-block;
    padding: 2px 7px;
    border-radius: 5px;
    background: rgba(0, 0, 0, 0.06);
    border: 0.5px solid rgba(0, 0, 0, 0.12);
    font-family: inherit;
    font-size: 0.9em;
    color: #333;
    min-width: 24px;
    text-align: center;
}

.shortcut-row span {
    color: #86868b;
}

.settings-checkbox-row {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.85em;
    color: #333;
    cursor: pointer;
    margin-top: 4px;
}

.settings-checkbox-row input[type="checkbox"] {
    width: auto;
    margin: 0;
}

.settings-checkbox-list {
    display: flex;
    flex-direction: column;
    gap: 2px;
    max-height: 50vh;
    overflow-y: auto;
}

.settings-checkbox-list label {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.85em;
    color: #333;
    cursor: pointer;
}

.settings-checkbox-list input[type="checkbox"] {
    width: auto;
    margin: 0;
}

/* App toggle rows */
.app-toggle-row {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 6px 8px;
    border-radius: 8px;
    transition: background 0.12s;
}

.app-toggle-row:hover {
    background: rgba(0,0,0,0.03);
}

.app-toggle-icon {
    width: 24px;
    height: 24px;
    border-radius: 6px;
    flex-shrink: 0;
    background-size: contain;
    background-repeat: no-repeat;
    background-position: center;
}

.app-toggle-icon-letter {
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(0,0,0,0.06);
    color: #86868b;
    font-size: 0.7em;
    font-weight: 600;
}

.app-toggle-name {
    flex: 1;
    font-size: 0.85em;
    color: #1d1d1f;
}

/* Toggle switch */
.toggle-switch {
    position: relative;
    width: 42px;
    height: 26px;
    flex-shrink: 0;
    display: inline-block;
}

.toggle-switch input {
    opacity: 0;
    width: 0;
    height: 0;
    position: absolute;
}

.toggle-slider {
    position: absolute;
    inset: 0;
    background: rgba(0,0,0,0.12);
    border-radius: 13px;
    cursor: pointer;
    transition: all 0.2s;
}

.toggle-slider::before {
    content: '';
    position: absolute;
    width: 22px;
    height: 22px;
    left: 2px;
    bottom: 2px;
    background: #fff;
    border-radius: 50%;
    transition: transform 0.2s;
    box-shadow: 0 1px 3px rgba(0,0,0,0.15);
}

.toggle-switch input:checked + .toggle-slider {
    background: #34c759;
}

.toggle-switch input:checked + .toggle-slider::before {
    transform: translateX(16px);
}

/* Typography controls */
.settings-type-controls {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.settings-type-row {
    display: flex;
    align-items: center;
    gap: 8px;
}

.settings-type-label {
    font-size: 0.82em;
    color: #555;
    width: 50px;
    flex-shrink: 0;
}

.settings-select {
    flex: 1;
    padding: 6px 10px;
    border: none;
    border-radius: 7px;
    background: rgba(0,0,0,0.04);
    color: #1d1d1f;
    font-size: 0.82em;
    font-family: inherit;
    cursor: pointer;
    transition: background 0.2s, box-shadow 0.2s;
    -webkit-appearance: none;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='8' height='5'%3E%3Cpath d='M0 0l4 5 4-5z' fill='%2386868b'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 10px center;
    padding-right: 24px;
}

.settings-select:focus {
    outline: none;
    background-color: #fff;
    box-shadow: 0 0 0 3.5px rgba(0, 122, 255, 0.3);
}

.settings-select-sm {
    flex: 0 0 90px;
}

/* Sections manager */
.sections-manager {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.section-manager-row {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 8px;
    border-radius: 8px;
    background: rgba(0,0,0,0.02);
}

.section-manager-row:hover {
    background: rgba(0,0,0,0.04);
}

.section-manager-row input[type="color"] {
    -webkit-appearance: none;
    appearance: none;
    width: 24px;
    height: 24px;
    border: 0.5px solid rgba(0,0,0,0.12);
    border-radius: 50%;
    padding: 0;
    margin: 0;
    cursor: pointer;
    background: none;
    overflow: hidden;
    flex-shrink: 0;
}

.section-manager-row input[type="color"]::-webkit-color-swatch-wrapper {
    padding: 0;
}

.section-manager-row input[type="color"]::-webkit-color-swatch {
    border: none;
    border-radius: 50%;
}

.section-manager-row input[type="text"] {
    flex: 1;
    padding: 5px 8px;
    border: none;
    border-radius: 6px;
    background: transparent;
    color: #1d1d1f;
    font-size: 0.85em;
    font-family: inherit;
    margin: 0;
}

.section-manager-row input[type="text"]:focus {
    background: rgba(0,0,0,0.04);
    outline: none;
}

.section-manager-delete {
    width: 24px;
    height: 24px;
    border: none;
    border-radius: 50%;
    background: transparent;
    color: #c7c7cc;
    font-size: 0.7em;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: all 0.12s;
}

.section-manager-delete:hover {
    background: rgba(255,59,48,0.1);
    color: #ff3b30;
}

/* Wallpaper grid */
.wallpaper-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
    margin-bottom: 16px;
}

.wallpaper-thumb {
    position: relative;
    cursor: pointer;
    border-radius: 8px;
    overflow: hidden;
}

.wallpaper-thumb img {
    width: 100%;
    aspect-ratio: 16 / 10;
    object-fit: cover;
    display: block;
    border-radius: 8px;
    border: 2.5px solid transparent;
    transition: border-color 0.15s;
}

.wallpaper-thumb.selected img {
    border-color: #007aff;
}

.wallpaper-thumb .wp-check {
    display: none;
    position: absolute;
    bottom: 6px;
    right: 6px;
    width: 18px;
    height: 18px;
    background: #007aff;
    border-radius: 50%;
    color: #fff;
    font-size: 10px;
    line-height: 18px;
    text-align: center;
}

.wallpaper-thumb.selected .wp-check {
    display: block;
}

.wallpaper-thumb .wp-name {
    text-align: center;
    font-size: 10px;
    color: #86868b;
    margin-top: 4px;
}

.wallpaper-thumb-color {
    aspect-ratio: 16 / 10;
    border-radius: 8px;
    border: 2.5px solid transparent;
    cursor: pointer;
    transition: border-color 0.15s;
    position: relative;
    overflow: hidden;
}

.wallpaper-thumb.selected .wallpaper-thumb-color {
    border-color: #007aff;
}

.wallpaper-color-input {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    opacity: 0;
    cursor: pointer;
    border: none;
    padding: 0;
}

.wallpaper-thumb-custom {
    aspect-ratio: 16 / 10;
    border-radius: 8px;
    border: 2.5px dashed #c7c7cc;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(0,0,0,0.02);
    cursor: pointer;
    transition: border-color 0.15s;
}

.wallpaper-thumb.selected .wallpaper-thumb-custom {
    border-color: #007aff;
    border-style: solid;
}

.wallpaper-thumb-custom span {
    font-size: 20px;
    color: #c7c7cc;
}

.custom-url-row {
    display: flex;
    gap: 8px;
    align-items: center;
    background: rgba(0,0,0,0.03);
    border-radius: 8px;
    padding: 12px;
    margin-bottom: 8px;
}

.custom-url-row input[type="text"] {
    flex: 1;
    margin-bottom: 0;
}


.custom-url-row .btn {
    white-space: nowrap;
    flex-shrink: 0;
}

/* Settings footer */
.settings-footer {
    grid-column: 2;
    padding: 14px 28px;
    border-top: 0.5px solid rgba(0, 0, 0, 0.1);
    background: rgba(246, 246, 246, 0.6);
    border-radius: 0 0 14px 0;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.settings-footer .btn {
    padding: 7px 18px;
    border: none;
    border-radius: 7px;
    cursor: pointer;
    font-family: inherit;
    font-size: 0.82em;
    font-weight: 500;
    transition: all 0.12s;
}

.settings-footer .btn-destructive {
    background: rgba(255, 59, 48, 0.1);
    color: #ff3b30;
}

.settings-footer .btn-destructive:hover {
    background: rgba(255, 59, 48, 0.18);
}

.settings-footer .btn-cancel {
    background: rgba(0, 0, 0, 0.05);
    color: #1d1d1f;
}

.settings-footer .btn-cancel:hover {
    background: rgba(0, 0, 0, 0.1);
}

.settings-footer .btn-primary {
    background: #007aff;
    color: #fff;
    font-weight: 600;
}

.settings-footer .btn-primary:hover {
    background: #0066d6;
}

/* Settings mobile */
@media (max-width: 640px) {
    .settings-panel {
        width: 100%;
        max-width: 100%;
        max-height: 100vh;
        max-height: 100dvh;
        height: 100vh;
        height: 100dvh;
        border-radius: 0;
        grid-template-columns: 1fr;
        grid-template-rows: auto 1fr auto;
        background: rgba(255, 255, 255, 0.97);
    }

    .settings-sidebar {
        grid-row: 1;
        flex-direction: row;
        border-right: none;
        border-bottom: 0.5px solid rgba(0, 0, 0, 0.1);
        padding: 12px 12px 10px;
        padding-top: max(12px, env(safe-area-inset-top));
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        gap: 4px;
    }

    .settings-tab {
        white-space: nowrap;
        text-align: center;
        font-size: 0.78em;
    }

    .settings-content {
        padding: 18px 20px;
    }

    .settings-footer {
        grid-column: 1;
        padding: 12px 20px;
        padding-bottom: max(12px, env(safe-area-inset-bottom));
        border-radius: 0;
    }

    .wallpaper-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

/* Copy JSON Button */
.copy-btn {
    padding: 4px 10px;
    font-size: 0.85em;
    cursor: pointer;
    background: #f0f0f0;
    border: 1px solid #ddd;
    border-radius: 4px;
    transition: all 0.2s;
    color: #333;
}

.copy-btn:hover {
    background: #e5e7eb;
    border-color: #bbb;
    transform: translateY(-1px);
}

/* Media Queries for Responsiveness */
/* Move search below header at medium screens */
@media (max-width: 1200px) {
    header {
        grid-template-columns: 1fr auto;
        gap: 12px;
    }

    .search-container {
        grid-column: 1 / -1;
        order: 3;
        justify-content: stretch;
        padding-top: 0;
    }

    .search-bar-wrapper {
        width: 100%;
    }
}

@media (max-width: 800px) {
    header {
        grid-template-columns: 1fr auto;
        gap: 6px;
        padding: 16px 16px 10px;
    }

    .header-left {
        align-items: flex-start;
    }

    .clock {
        font-size: 2.8em;
    }

    .date-display {
        font-size: 0.85em;
    }

    .weather {
        font-size: 0.8em;
    }

    .settings-controls {
        position: static;
        padding-top: 4px;
        gap: 6px;
    }

    .settings-controls button {
        width: 30px;
        height: 30px;
        font-size: 0.7em;
    }

    .search-container {
        grid-column: 1 / -1;
        order: 3;
        padding-top: 6px;
    }

    .search-bar-wrapper {
        width: 100%;
    }

    .search-bar {
        border-radius: 10px;
        padding: 9px 14px;
        font-size: 0.85em;
    }

    .apps-launcher-container {
        margin-left: 8px;
    }

    .apps-btn {
        width: 36px;
        height: 36px;
        border-radius: 10px;
    }

    .grid-container {
        padding: 0 16px 32px;
        gap: 12px;
    }
}

/* ====== Setup Wizard ====== */
.setup-wizard {
    position: fixed;
    inset: 0;
    z-index: 10000;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
}

.setup-wizard.hidden {
    display: none;
}

.setup-card {
    background: rgba(30, 30, 32, 0.95);
    border: 0.5px solid rgba(255, 255, 255, 0.12);
    border-radius: 20px;
    padding: 36px 32px;
    width: 460px;
    max-width: 92%;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: 0 24px 80px rgba(0, 0, 0, 0.5);
    color: #fff;
    font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Text', system-ui, sans-serif;
}

.setup-header {
    text-align: center;
    margin-bottom: 28px;
}

.setup-header h1 {
    font-size: 1.5em;
    font-weight: 600;
    margin: 0 0 6px;
}

.setup-header p {
    color: rgba(255, 255, 255, 0.5);
    margin: 0;
    font-size: 0.9em;
}

.setup-section-label {
    font-size: 0.8em;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: rgba(255, 255, 255, 0.5);
    margin-bottom: 12px;
}

.setup-options {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.setup-option {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 16px;
    border-radius: 12px;
    border: 0.5px solid rgba(255, 255, 255, 0.1);
    background: rgba(255, 255, 255, 0.04);
    color: #fff;
    cursor: pointer;
    transition: all 0.15s;
    text-align: left;
    font-size: 1em;
}

.setup-option:hover {
    background: rgba(255, 255, 255, 0.1);
    border-color: rgba(255, 255, 255, 0.2);
}

.setup-option i {
    font-size: 1.3em;
    width: 32px;
    text-align: center;
    flex-shrink: 0;
    color: var(--primary-color);
}

.setup-option-title {
    font-weight: 600;
    display: block;
}

.setup-option-desc {
    font-size: 0.8em;
    color: rgba(255, 255, 255, 0.5);
    display: block;
    margin-top: 2px;
}

.setup-input {
    width: 100%;
    padding: 10px 14px;
    border-radius: 10px;
    border: 0.5px solid rgba(255, 255, 255, 0.15);
    background: rgba(255, 255, 255, 0.06);
    color: #fff;
    font-size: 0.95em;
    margin-bottom: 10px;
    box-sizing: border-box;
}

.setup-input:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(0, 122, 255, 0.15);
}

.setup-error {
    color: #ff453a;
    font-size: 0.85em;
    margin: 0 0 10px;
}

.setup-actions {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 16px;
}

.setup-primary-btn {
    padding: 10px 20px;
    border-radius: 10px;
    border: none;
    background: var(--primary-color);
    color: #fff;
    font-size: 0.95em;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.15s;
}

.setup-primary-btn:hover {
    background: var(--primary-hover);
}

.setup-back-btn {
    padding: 8px 14px;
    border-radius: 8px;
    border: none;
    background: transparent;
    color: rgba(255, 255, 255, 0.6);
    cursor: pointer;
    font-size: 0.9em;
}

.setup-back-btn:hover {
    color: #fff;
}

.setup-skip-btn {
    padding: 8px 14px;
    border-radius: 8px;
    border: 0.5px solid rgba(255, 255, 255, 0.15);
    background: transparent;
    color: rgba(255, 255, 255, 0.6);
    cursor: pointer;
    font-size: 0.9em;
}

.setup-skip-btn:hover {
    color: #fff;
    border-color: rgba(255, 255, 255, 0.3);
}

.setup-hint {
    font-size: 0.85em;
    color: rgba(255, 255, 255, 0.45);
    margin: 0 0 12px;
}

.setup-hint a {
    color: var(--primary-color);
}

.setup-instructions {
    display: flex;
    flex-direction: column;
    gap: 12px;
    margin-bottom: 16px;
}

.setup-instruction-step {
    display: flex;
    gap: 12px;
    align-items: flex-start;
    font-size: 0.9em;
}

.setup-step-num {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    background: var(--primary-color);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.75em;
    font-weight: 700;
    flex-shrink: 0;
}

.setup-copy-box {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-top: 6px;
    padding: 8px 12px;
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.06);
    border: 0.5px solid rgba(255, 255, 255, 0.1);
}

.setup-copy-box code {
    font-size: 0.8em;
    color: rgba(255, 255, 255, 0.8);
    word-break: break-all;
    flex: 1;
}

.setup-copy-btn {
    background: none;
    border: none;
    color: var(--primary-color);
    cursor: pointer;
    padding: 4px;
    font-size: 0.9em;
}

.setup-code-block {
    padding: 10px 14px;
    border-radius: 8px;
    background: rgba(0, 0, 0, 0.3);
    font-size: 0.8em;
    line-height: 1.6;
    margin: 12px 0;
}

.setup-code-block code {
    color: rgba(255, 255, 255, 0.7);
}

.setup-done-icon {
    text-align: center;
    font-size: 3em;
    color: #30d158;
    margin-bottom: 12px;
}

.setup-step[data-step="done"] {
    text-align: center;
}

.setup-step[data-step="done"] h2 {
    margin: 0 0 8px;
}

.setup-step[data-step="done"] .setup-primary-btn {
    margin-top: 16px;
}

/* Auth Error Banner */
.auth-error-banner {
    position: fixed;
    top: 20px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 10001;
    background: rgba(255, 59, 48, 0.95);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    color: #fff;
    padding: 16px 40px 16px 20px;
    border-radius: 14px;
    max-width: 520px;
    width: 90%;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
    font-size: 0.9em;
    line-height: 1.5;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.auth-error-uri {
    background: rgba(0, 0, 0, 0.25);
    padding: 8px 12px;
    border-radius: 8px;
    font-family: monospace;
    font-size: 0.85em;
    word-break: break-all;
    cursor: pointer;
    transition: background 0.15s;
}

.auth-error-uri:hover {
    background: rgba(0, 0, 0, 0.4);
}
