/* ============================================
   TWLF Portal - Full Dashboard System
   Multi-dashboard, themes, shapes, widgets
   ============================================ */

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

/* ---- Theme Variables ---- */
:root, [data-theme="dark"], [data-theme="light"] {
    --cell: 100px;
    --gap: 6px;
    --radius: 14px;
    --header-height: 52px;
    --sidebar-width: 220px;
}

[data-theme="dark"] {
    --bg-color: #0f1923;
    --bg-surface: #162231;
    --bg-elevated: #1c2d3f;
    --bg-hover: rgba(255,255,255,0.06);
    --bg-active: rgba(255,255,255,0.1);
    --border-color: rgba(255,255,255,0.08);
    --text-primary: #e8eaed;
    --text-secondary: #8892a4;
    --text-muted: #5a6577;
    --shadow: rgba(0,0,0,0.4);
    --accent: #17D6E5;
    --danger: #ff4757;
    --tile-shadow: rgba(0,0,0,0.35);
    --modal-bg: #1c2d3f;
    --input-bg: rgba(255,255,255,0.06);
    --scrollbar-thumb: rgba(255,255,255,0.08);
}

[data-theme="light"] {
    --bg-color: #f0f2f5;
    --bg-surface: #ffffff;
    --bg-elevated: #ffffff;
    --bg-hover: rgba(0,0,0,0.04);
    --bg-active: rgba(0,0,0,0.08);
    --border-color: rgba(0,0,0,0.1);
    --text-primary: #1a1a2e;
    --text-secondary: #5a6577;
    --text-muted: #8892a4;
    --shadow: rgba(0,0,0,0.1);
    --accent: #0ea5c7;
    --danger: #e74c3c;
    --tile-shadow: rgba(0,0,0,0.12);
    --modal-bg: #ffffff;
    --input-bg: rgba(0,0,0,0.04);
    --scrollbar-thumb: rgba(0,0,0,0.12);
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    background-color: var(--bg-color);
    background-size: cover; background-position: center; background-attachment: fixed;
    color: var(--text-primary);
    height: 100vh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    user-select: none;
}

/* ---- Header ---- */
.header {
    height: var(--header-height);
    background: var(--bg-surface);
    display: flex; align-items: center;
    padding: 0 12px; gap: 10px;
    z-index: 100;
    box-shadow: 0 2px 12px var(--shadow);
    flex-shrink: 0;
    border-bottom: 1px solid var(--border-color);
}

.header-left { flex: 0 0 auto; display: flex; align-items: center; gap: 8px; }

.sidebar-toggle { display: flex; }

.logo {
    display: flex; align-items: center; gap: 8px;
    font-size: 15px; font-weight: 700; color: var(--text-primary); white-space: nowrap;
}
.logo-img { width: 26px; height: 26px; }

.header-center { flex: 1; max-width: 500px; margin: 0 auto; position: relative; }

.search-bar {
    display: flex; align-items: center;
    background: var(--input-bg);
    border: 1px solid var(--border-color);
    border-radius: 24px; padding: 0 14px; height: 36px;
    transition: all 0.2s;
}
.search-bar:focus-within {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(23,214,229,0.12);
}
.search-bar i { color: var(--text-muted); font-size: 12px; margin-right: 8px; }
.search-bar input {
    flex: 1; background: none; border: none; color: var(--text-primary);
    font-size: 13px; outline: none; font-family: inherit;
}
.search-bar input::placeholder { color: var(--text-muted); }
.search-shortcut {
    font-size: 10px; padding: 2px 6px; border-radius: 4px;
    background: var(--bg-hover); color: var(--text-muted);
    border: 1px solid var(--border-color); font-family: inherit;
    margin-right: 6px;
}
.search-engine-toggle {
    width: 22px; height: 22px; border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    cursor: pointer; opacity: 0.7; transition: opacity 0.2s;
}
.search-engine-toggle:hover { opacity: 1; }
.search-engine-toggle img { width: 14px; height: 14px; border-radius: 2px; }

.search-results {
    position: absolute; top: 44px; left: 0; right: 0;
    background: var(--bg-elevated); border-radius: 12px;
    box-shadow: 0 8px 32px var(--shadow);
    border: 1px solid var(--border-color);
    max-height: 360px; overflow-y: auto;
    display: none; z-index: 200;
}
.search-results.active { display: block; }
.search-result-item {
    display: flex; align-items: center; gap: 10px;
    padding: 8px 14px; cursor: pointer; transition: background 0.12s;
}
.search-result-item:hover { background: var(--bg-hover); }
.search-result-item .result-icon {
    width: 28px; height: 28px; border-radius: 6px;
    display: flex; align-items: center; justify-content: center;
    flex-shrink: 0; overflow: hidden;
}
.search-result-item .result-icon img { width: 22px; height: 22px; border-radius: 3px; object-fit: contain; }
.search-result-item .result-info { flex: 1; min-width: 0; }
.search-result-item .result-name { font-size: 12px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.search-result-item .result-url { font-size: 10px; color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.search-result-web {
    border-top: 1px solid var(--border-color);
    padding: 8px 14px; display: flex; align-items: center; gap: 10px;
    cursor: pointer; color: var(--accent); font-size: 12px;
}
.search-result-web:hover { background: var(--bg-hover); }

/* Header Right */
.header-right { flex: 0 0 auto; display: flex; align-items: center; gap: 4px; }

.size-slider-wrap {
    display: flex; align-items: center; gap: 5px;
    background: var(--bg-hover); border-radius: 16px; padding: 3px 10px;
}
.size-icon-sm { font-size: 9px; color: var(--text-muted); }
.size-icon-lg { font-size: 12px; color: var(--text-muted); }

#tileSizeSlider {
    width: 70px; height: 3px;
    -webkit-appearance: none; appearance: none;
    background: var(--border-color); border-radius: 2px;
    outline: none; cursor: pointer;
}
#tileSizeSlider::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 12px; height: 12px; border-radius: 50%;
    background: var(--accent); cursor: pointer;
    border: 2px solid var(--bg-surface);
    box-shadow: 0 1px 3px var(--shadow);
}

.header-btn {
    width: 32px; height: 32px; border-radius: 8px; border: none;
    background: transparent; color: var(--text-secondary);
    cursor: pointer; display: flex; align-items: center; justify-content: center;
    font-size: 12px; transition: all 0.15s;
}
.header-btn:hover { background: var(--bg-hover); color: var(--text-primary); }
.header-btn.active { background: var(--accent); color: #fff; }

.edit-mode-btn.active {
    background: var(--danger);
    color: #fff;
    animation: editPulse 2s infinite;
}
@keyframes editPulse { 0%,100% { box-shadow: 0 0 0 0 rgba(255,71,87,0.4); } 50% { box-shadow: 0 0 0 6px rgba(255,71,87,0); } }

.clock {
    font-size: 12px; font-weight: 500; color: var(--text-secondary);
    min-width: 60px; text-align: right; font-variant-numeric: tabular-nums;
}

/* ---- Sidebar ---- */
.sidebar {
    position: fixed; left: -260px; top: var(--header-height);
    width: var(--sidebar-width);
    height: calc(100vh - var(--header-height));
    background: var(--bg-surface);
    border-right: 1px solid var(--border-color);
    z-index: 90;
    display: flex; flex-direction: column;
    transition: left 0.25s ease;
    box-shadow: 4px 0 20px var(--shadow);
}
.sidebar.open { left: 0; }

.sidebar-header {
    display: flex; align-items: center; justify-content: space-between;
    padding: 16px; border-bottom: 1px solid var(--border-color);
}
.sidebar-header h3 { font-size: 14px; font-weight: 700; }
.sidebar-add-btn {
    width: 28px; height: 28px; border-radius: 6px; border: none;
    background: var(--accent); color: #fff; cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    font-size: 11px; transition: filter 0.15s;
}
.sidebar-add-btn:hover { filter: brightness(1.15); }

.sidebar-list { flex: 1; overflow-y: auto; padding: 8px; }

.sidebar-item {
    display: flex; align-items: center; gap: 10px;
    padding: 10px 12px; border-radius: 8px;
    cursor: pointer; transition: all 0.12s; font-size: 13px;
    margin-bottom: 2px; color: var(--text-secondary);
}
.sidebar-item:hover { background: var(--bg-hover); color: var(--text-primary); }
.sidebar-item.active { background: var(--bg-active); color: var(--accent); font-weight: 600; }
.sidebar-item i { width: 16px; text-align: center; font-size: 12px; }
.sidebar-item .dash-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sidebar-item .dash-count { font-size: 10px; color: var(--text-muted); background: var(--bg-hover); padding: 2px 6px; border-radius: 10px; }

.sidebar-item-actions {
    display: none; gap: 2px;
}
.sidebar-item:hover .sidebar-item-actions { display: flex; }
.sidebar-item-actions button {
    width: 22px; height: 22px; border: none; border-radius: 4px;
    background: transparent; color: var(--text-muted);
    cursor: pointer; font-size: 10px; display: flex; align-items: center; justify-content: center;
}
.sidebar-item-actions button:hover { background: var(--bg-hover); color: var(--text-primary); }
.sidebar-item-actions .delete-dash:hover { color: var(--danger); }

.sidebar-footer {
    padding: 12px; border-top: 1px solid var(--border-color);
}
.sidebar-footer-btn {
    width: 100%; padding: 8px; border: none; border-radius: 8px;
    background: var(--bg-hover); color: var(--text-secondary);
    cursor: pointer; font-size: 12px; font-family: inherit;
    display: flex; align-items: center; gap: 8px; justify-content: center;
    transition: all 0.15s;
}
.sidebar-footer-btn:hover { background: var(--bg-active); color: var(--text-primary); }

.sidebar-overlay {
    display: none; position: fixed; inset: 0; z-index: 85;
    background: rgba(0,0,0,0.3);
}
.sidebar-overlay.active { display: block; }

/* ---- Dashboard Tabs ---- */
.dashboard-tabs {
    display: flex; gap: 4px; padding: 8px 24px 0;
    overflow-x: auto; flex-shrink: 0;
}
.dashboard-tabs::-webkit-scrollbar { height: 0; }

.dash-tab {
    padding: 6px 16px; border-radius: 8px 8px 0 0; border: none;
    background: var(--bg-hover); color: var(--text-secondary);
    font-size: 12px; font-weight: 500; cursor: pointer;
    font-family: inherit; transition: all 0.15s; white-space: nowrap;
    border-bottom: 2px solid transparent;
}
.dash-tab:hover { background: var(--bg-active); color: var(--text-primary); }
.dash-tab.active {
    background: var(--bg-active);
    color: var(--accent);
    border-bottom-color: var(--accent);
    font-weight: 600;
}

/* ---- Main Content ---- */
.main-content {
    flex: 1; overflow-y: auto; overflow-x: hidden;
    display: flex; flex-direction: column;
}

.grid-container {
    flex: 1; padding: 16px 24px 40px;
    position: relative;
}

.grid-container .category-section {
    position: absolute;
    transition: transform 0.3s ease, left 0.3s ease, top 0.3s ease;
}

/* ---- Category Section (grouped card) ---- */
.category-section {
    background: var(--bg-surface);
    border: 1px solid var(--border-color);
    border-radius: 16px;
    overflow: hidden;
    box-shadow: 0 2px 8px var(--shadow);
    /* Width is set inline based on columns property */
    flex-shrink: 0;
    transition: box-shadow 0.2s, transform 0.15s;
}

.category-section.cat-dragging {
    opacity: 0.5; transform: scale(0.96);
}
.category-section.cat-drag-over {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
    transform: scale(1.01);
}

.category-header {
    display: flex; align-items: center; gap: 8px;
    padding: 8px 12px;
    border-bottom: 1px solid var(--border-color);
    background: var(--bg-hover);
    cursor: grab;
}
.category-header:active { cursor: grabbing; }

.category-header .cat-color-bar {
    width: 4px; height: 18px; border-radius: 2px; flex-shrink: 0;
}
.category-header h2 {
    font-size: 11px; font-weight: 700;
    text-transform: uppercase; letter-spacing: 1px;
    color: var(--text-secondary);
    flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.category-header .cat-line { display: none; }

/* Three-dot menu button - always visible */
.cat-menu-btn {
    width: 24px; height: 24px; border: none; border-radius: 6px;
    background: transparent; color: var(--text-muted); cursor: pointer;
    font-size: 12px; display: flex; align-items: center; justify-content: center;
    transition: all 0.15s; flex-shrink: 0;
}
.cat-menu-btn:hover { background: var(--bg-active); color: var(--text-primary); }

/* Edit-only actions */
.category-header .cat-actions { display: none; gap: 2px; }
body.edit-mode .category-header .cat-actions { display: flex; }
.category-header .cat-actions button {
    width: 22px; height: 22px; border: none; border-radius: 4px;
    background: transparent; color: var(--text-muted); cursor: pointer;
    font-size: 10px; display: flex; align-items: center; justify-content: center;
}
.category-header .cat-actions button:hover { background: var(--bg-active); color: var(--text-primary); }

.cat-size-label {
    font-size: 9px; color: var(--text-muted); font-weight: 600;
    padding: 2px 6px; border-radius: 4px; background: var(--bg-active);
    white-space: nowrap;
}

/* ---- Category Settings Popover ---- */
.cat-settings-popover {
    position: absolute; z-index: 500;
    background: var(--modal-bg);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    box-shadow: 0 12px 40px var(--shadow);
    width: 280px;
    overflow: hidden;
    display: none;
}
.cat-settings-popover.active { display: block; }

.cat-settings-header {
    display: flex; align-items: center; justify-content: space-between;
    padding: 10px 14px;
    border-bottom: 1px solid var(--border-color);
    background: var(--bg-hover);
}
.cat-settings-header h4 {
    font-size: 12px; font-weight: 700; color: var(--text-primary);
}
.cat-settings-close {
    width: 22px; height: 22px; border: none; border-radius: 6px;
    background: transparent; color: var(--text-muted); cursor: pointer;
    font-size: 14px; display: flex; align-items: center; justify-content: center;
}
.cat-settings-close:hover { background: var(--bg-active); color: var(--text-primary); }

.cat-settings-body { padding: 12px 14px; }

.cat-settings-group {
    margin-bottom: 12px;
}
.cat-settings-group:last-child { margin-bottom: 0; }

.cat-settings-group label {
    display: block; font-size: 10px; font-weight: 600;
    color: var(--text-secondary); margin-bottom: 5px;
    text-transform: uppercase; letter-spacing: 0.5px;
}

.cat-settings-group input[type="text"],
.cat-settings-group select {
    width: 100%; padding: 6px 10px;
    background: var(--input-bg);
    border: 1px solid var(--border-color);
    border-radius: 6px; color: var(--text-primary);
    font-size: 12px; font-family: inherit; outline: none;
}
.cat-settings-group input:focus,
.cat-settings-group select:focus { border-color: var(--accent); }

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

.cat-settings-row input[type="color"] {
    width: 32px; height: 32px; border: none; background: none;
    cursor: pointer; border-radius: 6px; flex-shrink: 0;
}

.cat-settings-row input[type="range"] {
    flex: 1; height: 3px;
    -webkit-appearance: none; appearance: none;
    background: var(--border-color); border-radius: 2px;
    outline: none; cursor: pointer;
}
.cat-settings-row input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 14px; height: 14px; border-radius: 50%;
    background: var(--accent); cursor: pointer;
    border: 2px solid var(--bg-surface);
}

.cat-settings-range-val {
    font-size: 10px; font-weight: 600; color: var(--text-muted);
    min-width: 28px; text-align: right;
}

.cat-settings-footer {
    padding: 8px 14px;
    border-top: 1px solid var(--border-color);
    display: flex; gap: 6px; justify-content: flex-end;
}
.cat-settings-footer .btn { padding: 5px 12px; font-size: 11px; }

body.hide-headers .category-header { display: none; }
body.hide-headers .category-section { margin-bottom: 0; }

/* ---- Tile Grid ---- */
.tile-grid {
    display: grid;
    /* columns set inline via style attribute */
    grid-template-columns: repeat(var(--cat-cols, 6), var(--cell));
    grid-auto-rows: var(--cell);
    gap: var(--gap);
    padding: 10px;
}

/* ---- Tiles ---- */
.tile {
    border-radius: var(--radius);
    display: flex; flex-direction: column;
    align-items: center; justify-content: center;
    cursor: pointer;
    transition: transform 0.15s ease, box-shadow 0.15s ease;
    position: relative;
    color: #fff; overflow: hidden;
    text-decoration: none;
    min-width: 0;
    /* Glossy glass effect */
    border: 1px solid rgba(255,255,255,0.18);
    box-shadow:
        0 4px 16px rgba(0,0,0,0.25),
        inset 0 1px 0 rgba(255,255,255,0.35),
        inset 0 -1px 0 rgba(0,0,0,0.15);
}

/* Glossy highlight overlay */
.tile::before {
    content: '';
    position: absolute;
    top: 0; left: 0; right: 0;
    height: 50%;
    background: linear-gradient(
        180deg,
        rgba(255,255,255,0.28) 0%,
        rgba(255,255,255,0.08) 60%,
        transparent 100%
    );
    border-radius: var(--radius) var(--radius) 0 0;
    pointer-events: none;
    z-index: 1;
}

/* Bottom subtle reflection */
.tile::after {
    content: '';
    position: absolute;
    bottom: 0; left: 0; right: 0;
    height: 30%;
    background: linear-gradient(
        0deg,
        rgba(0,0,0,0.15) 0%,
        transparent 100%
    );
    border-radius: 0 0 var(--radius) var(--radius);
    pointer-events: none;
    z-index: 1;
}

/* Keep tile content above overlays */
.tile > * { position: relative; z-index: 2; }

/* Tile shapes */
body.shape-circle .tile { border-radius: 50%; }
body.shape-circle .tile::before { border-radius: 50% 50% 0 0; }
body.shape-circle .tile::after { border-radius: 0 0 50% 50%; }
body.shape-circle .tile.size-2x1,
body.shape-circle .tile.size-3x1,
body.shape-circle .tile.size-4x1,
body.shape-circle .tile.size-2x2 { border-radius: calc(var(--cell) * 0.5); }
body.shape-rectangle .tile { border-radius: 6px; }
body.shape-rectangle .tile::before { border-radius: 6px 6px 0 0; }
body.shape-rectangle .tile::after { border-radius: 0 0 6px 6px; }

/* Size classes */
.tile.size-1x1 { grid-column: span 1; grid-row: span 1; }
.tile.size-2x1 { grid-column: span 2; grid-row: span 1; }
.tile.size-2x2 { grid-column: span 2; grid-row: span 2; }
.tile.size-3x1 { grid-column: span 3; grid-row: span 1; }
.tile.size-4x1 { grid-column: span 4; grid-row: span 1; }

.tile:hover {
    transform: scale(1.04);
    box-shadow:
        0 8px 32px rgba(0,0,0,0.35),
        inset 0 1px 0 rgba(255,255,255,0.45),
        inset 0 -1px 0 rgba(0,0,0,0.1);
    border-color: rgba(255,255,255,0.28);
    z-index: 10;
}
.tile:hover::before {
    background: linear-gradient(
        180deg,
        rgba(255,255,255,0.38) 0%,
        rgba(255,255,255,0.12) 50%,
        transparent 100%
    );
}
.tile:active { transform: scale(0.97); }

/* Tile marker */
.tile .tile-marker {
    position: absolute; top: 0; left: 0; right: 0;
    height: 4px; border-radius: var(--radius) var(--radius) 0 0;
}
body.shape-circle .tile .tile-marker { border-radius: 50% 50% 0 0; height: 5px; }

/* Tile icon */
.tile .tile-icon {
    display: flex; align-items: center; justify-content: center;
    flex-shrink: 0;
}
.tile.size-1x1 .tile-icon { width: 42%; height: 42%; }
.tile.size-2x1 .tile-icon { width: 28%; height: 55%; }
.tile.size-2x2 .tile-icon { width: 35%; height: 35%; }
.tile.size-3x1 .tile-icon { width: 18%; height: 55%; }
.tile.size-4x1 .tile-icon { width: 12%; height: 55%; }

.tile .tile-icon img {
    width: 100%; height: 100%;
    border-radius: 6px; object-fit: contain;
    background: rgba(255,255,255,0.92); padding: 2px;
}
body.shape-circle .tile .tile-icon img { border-radius: 50%; }

.tile .letter-fallback {
    font-weight: 800; opacity: 0.85;
    text-shadow: 0 1px 3px rgba(0,0,0,0.3);
}
.tile.size-1x1 .letter-fallback { font-size: calc(var(--cell) * 0.32); }
.tile.size-2x1 .letter-fallback,
.tile.size-3x1 .letter-fallback,
.tile.size-4x1 .letter-fallback { font-size: calc(var(--cell) * 0.38); }
.tile.size-2x2 .letter-fallback { font-size: calc(var(--cell) * 0.5); }

/* Tile label */
.tile .tile-label {
    font-size: 10px; font-weight: 500;
    text-align: center; line-height: 1.2;
    padding: 2px 6px 0; max-width: 100%;
    overflow: hidden; text-overflow: ellipsis;
    white-space: normal; word-wrap: break-word;
    display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
    text-shadow: 0 1px 3px rgba(0,0,0,0.5);
}
.tile.size-2x1 .tile-label,
.tile.size-3x1 .tile-label,
.tile.size-4x1 .tile-label { font-size: 11px; }
.tile.size-2x2 .tile-label { font-size: 13px; font-weight: 600; }

body.hide-labels .tile .tile-label { display: none; }

/* Empty cells removed - use category menu to add tiles */

/* ---- List View ---- */
.tile-list {
    padding: 6px 10px;
}

.list-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 6px 8px;
    border-radius: 8px;
    cursor: pointer;
    transition: background 0.15s;
    border-bottom: 1px solid var(--border-color);
}
.list-item:last-child { border-bottom: none; }
.list-item:hover { background: var(--bg-hover); }

.list-item-icon {
    width: 32px; height: 32px;
    border-radius: 8px;
    flex-shrink: 0;
    display: flex; align-items: center; justify-content: center;
    overflow: hidden;
    /* Glass effect for list icons */
    border: 1px solid rgba(255,255,255,0.15);
    box-shadow: 0 2px 6px rgba(0,0,0,0.2),
        inset 0 1px 0 rgba(255,255,255,0.3);
    position: relative;
}
.list-item-icon::before {
    content: '';
    position: absolute; top: 0; left: 0; right: 0; height: 50%;
    background: linear-gradient(180deg, rgba(255,255,255,0.25) 0%, transparent 100%);
    border-radius: 7px 7px 0 0;
    pointer-events: none;
}
.list-item-icon img {
    width: 22px; height: 22px;
    border-radius: 4px;
    object-fit: contain;
    background: rgba(255,255,255,0.9);
    padding: 1px;
    position: relative; z-index: 1;
}
.list-item-icon .list-letter {
    font-size: 14px; font-weight: 700;
    color: #fff;
    text-shadow: 0 1px 2px rgba(0,0,0,0.3);
    position: relative; z-index: 1;
}

.list-item-text {
    flex: 1; min-width: 0;
}

.list-item-name {
    font-size: 13px; font-weight: 600;
    color: var(--text-primary);
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

.list-item-desc {
    font-size: 11px; font-weight: 400;
    color: var(--text-secondary);
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
    margin-top: 1px;
}

.list-item-marker {
    width: 8px; height: 8px;
    border-radius: 50%;
    flex-shrink: 0;
}

/* Detailed list: slightly more vertical padding */
.tile-list-detailed .list-item {
    padding: 8px 8px;
}
.tile-list-detailed .list-item-icon {
    width: 38px; height: 38px;
}
.tile-list-detailed .list-item-icon img {
    width: 26px; height: 26px;
}

/* ---- Widget Tiles ---- */
.tile.widget-tile {
    background: var(--bg-elevated) !important;
    border: 1px solid var(--border-color);
    backdrop-filter: blur(8px);
    color: var(--text-primary);
}

/* Search widget */
.widget-search { flex-direction: row; gap: 8px; padding: 0 12px; }
.widget-search .widget-search-bar {
    flex: 1; display: flex; align-items: center;
    background: var(--input-bg); border-radius: 20px;
    padding: 0 12px; height: 34px; gap: 8px;
}
.widget-search .widget-search-bar input {
    flex: 1; background: none; border: none; color: var(--text-primary);
    font-size: 12px; outline: none; font-family: inherit;
}
.widget-search .widget-search-bar input::placeholder { color: var(--text-muted); }
.widget-search .widget-search-bar i { color: var(--text-muted); font-size: 12px; }
.widget-search .g-logo { font-size: 20px; font-weight: 700; letter-spacing: -1px; }
.widget-search .g-logo .g-b { color: #4285F4; }
.widget-search .g-logo .g-r { color: #EA4335; }
.widget-search .g-logo .g-y { color: #FBBC05; }
.widget-search .g-logo .g-g { color: #34A853; }

/* Clock widget */
.widget-clock { flex-direction: column; gap: 2px; }
.widget-clock .clock-time {
    font-weight: 700; letter-spacing: -1px;
    font-variant-numeric: tabular-nums;
}
.tile.size-1x1 .clock-time { font-size: calc(var(--cell) * 0.28); }
.tile.size-2x1 .clock-time { font-size: calc(var(--cell) * 0.38); }
.tile.size-2x2 .clock-time { font-size: calc(var(--cell) * 0.45); }
.widget-clock .clock-date {
    font-size: 10px; color: var(--text-muted); font-weight: 500;
}

/* Notes widget */
.widget-notes { padding: 10px; align-items: stretch; }
.widget-notes textarea {
    flex: 1; width: 100%;
    background: var(--input-bg); border: 1px solid var(--border-color);
    border-radius: 8px; color: var(--text-primary);
    font-size: 11px; font-family: inherit;
    padding: 8px; outline: none; resize: none;
}
.widget-notes textarea:focus { border-color: var(--accent); }
.widget-notes .widget-note-label {
    font-size: 10px; font-weight: 600; color: var(--accent);
    margin-bottom: 4px; text-transform: uppercase; letter-spacing: 0.5px;
}

/* Todo widget */
.widget-todo { padding: 8px 10px; align-items: stretch; overflow: hidden; }
.widget-todo .widget-todo-header {
    font-size: 10px; font-weight: 600; color: var(--accent);
    margin-bottom: 4px; text-transform: uppercase; letter-spacing: 0.5px;
}
.widget-todo .todo-mini-list { list-style: none; flex: 1; overflow-y: auto; }
.widget-todo .todo-mini-list li {
    display: flex; align-items: center; gap: 6px;
    padding: 3px 0; font-size: 11px;
    border-bottom: 1px solid var(--border-color);
}
.widget-todo .todo-mini-list li input[type="checkbox"] {
    accent-color: var(--accent); width: 13px; height: 13px; flex-shrink: 0;
}
.widget-todo .todo-mini-list li.done span { text-decoration: line-through; opacity: 0.4; }
.widget-todo .todo-mini-input { display: flex; gap: 4px; margin-top: 4px; }
.widget-todo .todo-mini-input input {
    flex: 1; padding: 4px 8px; background: var(--input-bg);
    border: 1px solid var(--border-color); border-radius: 6px;
    color: var(--text-primary); font-size: 10px; font-family: inherit; outline: none;
}
.widget-todo .todo-mini-input button {
    padding: 4px 8px; border: none; border-radius: 6px;
    background: var(--accent); color: #000;
    font-size: 10px; font-weight: 600; cursor: pointer; font-family: inherit;
}

/* Weather widget */
.widget-weather { flex-direction: column; gap: 2px; }
.widget-weather .weather-temp { font-size: calc(var(--cell) * 0.35); font-weight: 700; }
.widget-weather .weather-desc { font-size: 10px; color: var(--text-muted); font-weight: 500; }
.widget-weather .weather-loc { font-size: 9px; color: var(--text-muted); }

/* ---- Edit Mode ---- */
body.edit-mode .tile:not(.widget-tile) .edit-indicator {
    position: absolute; top: 4px; right: 4px;
    width: 18px; height: 18px;
    background: rgba(0,0,0,0.5); color: #fff;
    border-radius: 50%; font-size: 8px;
    z-index: 5;
    display: flex; align-items: center; justify-content: center;
}

.edit-banner {
    display: none;
    position: fixed; bottom: 0; left: 0; right: 0;
    background: var(--danger); color: #fff;
    padding: 8px 20px; gap: 10px;
    align-items: center; justify-content: center;
    font-size: 13px; font-weight: 500;
    z-index: 100;
    box-shadow: 0 -4px 20px var(--shadow);
}
body.edit-mode .edit-banner { display: flex; }
.edit-banner .btn-sm {
    padding: 4px 14px; border: 2px solid #fff; border-radius: 6px;
    background: transparent; color: #fff; font-size: 12px;
    font-weight: 600; cursor: pointer; font-family: inherit;
    margin-left: 12px;
}
.edit-banner .btn-sm:hover { background: rgba(255,255,255,0.2); }

/* Drag states */
.tile.dragging { opacity: 0.4; transform: scale(0.92); }
.tile.drag-over {
    outline: 2px solid var(--accent); outline-offset: 2px;
    transform: scale(1.03);
}

/* ---- Modals ---- */
.modal-overlay {
    position: fixed; inset: 0;
    background: rgba(0,0,0,0.5); backdrop-filter: blur(4px);
    display: none; align-items: center; justify-content: center; z-index: 500;
}
.modal-overlay.active { display: flex; }

.modal {
    background: var(--modal-bg); border-radius: 16px;
    width: 90%; max-width: 500px;
    box-shadow: 0 16px 48px var(--shadow);
    border: 1px solid var(--border-color);
    overflow: hidden;
}
.modal-wide { max-width: 600px; }

.modal-header {
    display: flex; align-items: center; justify-content: space-between;
    padding: 14px 18px; border-bottom: 1px solid var(--border-color);
}
.modal-header h3 { font-size: 15px; font-weight: 600; }
.modal-close {
    width: 30px; height: 30px; border: none;
    background: var(--bg-hover); color: var(--text-secondary);
    border-radius: 8px; cursor: pointer; font-size: 16px;
    display: flex; align-items: center; justify-content: center;
    transition: all 0.15s;
}
.modal-close:hover { background: var(--bg-active); color: var(--text-primary); }

.modal-body { padding: 18px; max-height: 65vh; overflow-y: auto; }
.modal-footer {
    display: flex; gap: 8px; justify-content: flex-end;
    padding: 10px 18px; border-top: 1px solid var(--border-color);
}

.form-group { margin-bottom: 14px; }
.form-group label {
    display: block; font-size: 10px; font-weight: 600;
    color: var(--text-secondary); margin-bottom: 5px;
    text-transform: uppercase; letter-spacing: 0.5px;
}
.form-group input[type="text"],
.form-group input[type="url"],
.form-group select {
    width: 100%; padding: 8px 12px;
    background: var(--input-bg);
    border: 1px solid var(--border-color);
    border-radius: 8px; color: var(--text-primary);
    font-size: 13px; font-family: inherit; outline: none;
    transition: border-color 0.2s;
}
.form-group input:focus, .form-group select:focus { border-color: var(--accent); }
.form-group input[type="color"] {
    width: 36px; height: 36px; border: none; background: none;
    cursor: pointer; border-radius: 6px;
}
.inline-form { display: flex; gap: 8px; align-items: center; }
.inline-form input { flex: 1; }

.url-validation {
    font-size: 10px; margin-top: 3px; min-height: 14px;
}
.url-validation.valid { color: #27AE60; }
.url-validation.invalid { color: var(--danger); }

.settings-section {
    margin-bottom: 20px; padding-bottom: 16px;
    border-bottom: 1px solid var(--border-color);
}
.settings-section:last-child { border-bottom: none; margin-bottom: 0; }
.settings-section h4 {
    font-size: 12px; font-weight: 700; color: var(--accent);
    text-transform: uppercase; letter-spacing: 1px;
    margin-bottom: 12px;
}

.shortcut-list { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.shortcut-item {
    display: flex; align-items: center; gap: 8px;
    font-size: 11px; color: var(--text-secondary);
}
.shortcut-item kbd {
    font-size: 10px; padding: 2px 6px; border-radius: 4px;
    background: var(--bg-hover); border: 1px solid var(--border-color);
    font-family: inherit; color: var(--text-primary);
    min-width: 24px; text-align: center;
}

.category-manage-list { display: flex; flex-direction: column; gap: 4px; margin-top: 8px; }
.cat-manage-item {
    display: flex; align-items: center; gap: 8px;
    padding: 6px 8px; border-radius: 6px; font-size: 12px;
    background: var(--bg-hover);
}
.cat-manage-item .cat-manage-color {
    width: 14px; height: 14px; border-radius: 3px; flex-shrink: 0;
}
.cat-manage-item .cat-manage-name { flex: 1; }
.cat-manage-item button {
    width: 20px; height: 20px; border: none; border-radius: 4px;
    background: transparent; color: var(--text-muted); cursor: pointer;
    font-size: 10px; display: flex; align-items: center; justify-content: center;
}
.cat-manage-item button:hover { color: var(--danger); }

/* Size Picker */
.size-picker { display: flex; gap: 8px; flex-wrap: wrap; }
.size-option {
    display: flex; flex-direction: column; align-items: center; gap: 4px;
    padding: 8px; border-radius: 8px;
    border: 2px solid var(--border-color);
    cursor: pointer; transition: all 0.15s;
}
.size-option:hover { border-color: var(--text-muted); }
.size-option.selected { border-color: var(--accent); background: rgba(23,214,229,0.08); }
.size-option span { font-size: 9px; font-weight: 600; color: var(--text-muted); }
.size-preview { background: var(--accent); border-radius: 3px; opacity: 0.6; }
.s1x1 { width: 20px; height: 20px; }
.s2x1 { width: 40px; height: 20px; }
.s2x2 { width: 40px; height: 40px; }
.s3x1 { width: 60px; height: 20px; }
.s4x1 { width: 80px; height: 20px; }

/* Color Picker */
.color-picker { display: flex; gap: 5px; flex-wrap: wrap; }
.color-swatch {
    width: 28px; height: 28px; border-radius: 6px;
    cursor: pointer; border: 3px solid transparent; transition: all 0.15s;
}
.color-swatch:hover { transform: scale(1.15); }
.color-swatch.selected { border-color: var(--text-primary); box-shadow: 0 0 0 2px var(--accent); }

/* Marker Picker */
.marker-picker { display: flex; gap: 6px; flex-wrap: wrap; }
.marker-option {
    display: flex; align-items: center; justify-content: center;
    padding: 6px 10px; border-radius: 6px;
    border: 2px solid var(--border-color); cursor: pointer; transition: all 0.15s;
}
.marker-option:hover { border-color: var(--text-muted); }
.marker-option.selected { border-color: var(--accent); }
.marker-option span { font-size: 10px; color: var(--text-muted); }
.marker-dot { width: 14px; height: 14px; border-radius: 50%; }

/* Share */
.share-desc { font-size: 12px; color: var(--text-secondary); margin-bottom: 14px; line-height: 1.5; }
.share-status { font-size: 11px; color: var(--accent); margin-top: 8px; }

/* Buttons */
.btn {
    padding: 7px 16px; border: none; border-radius: 8px;
    font-size: 12px; font-weight: 600; cursor: pointer;
    font-family: inherit; transition: all 0.15s;
    display: inline-flex; align-items: center; gap: 6px;
}
.btn-primary { background: var(--accent); color: #000; }
.btn-primary:hover { filter: brightness(1.15); }
.btn-secondary { background: var(--bg-hover); color: var(--text-primary); }
.btn-secondary:hover { background: var(--bg-active); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { filter: brightness(1.15); }

/* Context Menu */
.context-menu {
    position: fixed; background: var(--bg-elevated); border-radius: 10px;
    padding: 5px; box-shadow: 0 8px 32px var(--shadow);
    border: 1px solid var(--border-color);
    min-width: 180px; display: none; z-index: 600;
}
.context-menu.active { display: block; }
.context-item {
    display: flex; align-items: center; gap: 8px;
    padding: 7px 12px; border-radius: 6px;
    font-size: 12px; cursor: pointer; transition: background 0.12s;
}
.context-item:hover { background: var(--bg-hover); }
.context-item i { width: 14px; text-align: center; font-size: 11px; color: var(--text-muted); }
.context-danger { color: var(--danger); }
.context-danger i { color: var(--danger); }
.context-divider { height: 1px; background: var(--border-color); margin: 3px 0; padding: 0; cursor: default; }

/* ---- Scrollbar ---- */
.main-content::-webkit-scrollbar, .sidebar-list::-webkit-scrollbar,
.modal-body::-webkit-scrollbar { width: 6px; }
.main-content::-webkit-scrollbar-track, .sidebar-list::-webkit-scrollbar-track,
.modal-body::-webkit-scrollbar-track { background: transparent; }
.main-content::-webkit-scrollbar-thumb, .sidebar-list::-webkit-scrollbar-thumb,
.modal-body::-webkit-scrollbar-thumb { background: var(--scrollbar-thumb); border-radius: 3px; }

/* ---- Responsive ---- */
@media (max-width: 900px) {
    .size-slider-wrap { display: none; }
    .dashboard-tabs { padding: 8px 12px 0; }
}
@media (max-width: 768px) {
    .header { padding: 0 8px; gap: 6px; }
    .logo span { display: none; }
    .clock { display: none; }
    .grid-container { padding: 12px 8px 30px; }
    .search-shortcut { display: none; }
    .header-btn#shareBtn { display: none; }
}
@media (max-width: 480px) {
    :root { --cell: 70px; }
    .header-right .header-btn:not(#editModeBtn):not(#settingsBtn) { display: none; }
}
