/* ===== CSS Custom Properties & Reset ===== */
:root {
    --color-bg: #0f0f1a;
    --color-bg-secondary: #1a1a2e;
    --color-surface: rgba(255, 255, 255, 0.05);
    --color-surface-hover: rgba(255, 255, 255, 0.1);
    --color-surface-card: rgba(255, 255, 255, 0.07);
    --color-border: rgba(255, 255, 255, 0.08);
    --color-border-hover: rgba(255, 255, 255, 0.18);
    --color-text: #e8e8f0;
    --color-text-secondary: #9ca3b0;
    --color-text-muted: #6b7280;
    --color-primary: #6366f1;
    --color-primary-light: #818cf8;
    --color-primary-glow: rgba(99, 102, 241, 0.3);
    --color-accent: #a78bfa;
    --color-danger: #ef4444;
    --color-danger-hover: #dc2626;
    --color-success: #10b981;
    --color-warning: #f59e0b;
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --radius-xl: 20px;
    --shadow-sm: 0 2px 8px rgba(0,0,0,0.2);
    --shadow-md: 0 4px 20px rgba(0,0,0,0.3);
    --shadow-lg: 0 8px 40px rgba(0,0,0,0.4);
    --shadow-glow: 0 0 30px rgba(99, 102, 241, 0.15);
    --transition-fast: 0.15s cubic-bezier(0.4, 0, 0.2, 1);
    --transition-base: 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    --transition-slow: 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    --font-sans: 'Noto Sans SC', 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    --header-height: 72px;
}

*, *::before, *::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html {
    font-size: 16px;
    scroll-behavior: smooth;
}

body {
    font-family: var(--font-sans);
    background: var(--color-bg);
    color: var(--color-text);
    min-height: 100vh;
    overflow-x: hidden;
    line-height: 1.6;
    position: relative;
}

/* ===== Background Blobs ===== */
.bg-blobs {
    position: fixed;
    inset: 0;
    z-index: 0;
    overflow: hidden;
    pointer-events: none;
}

.blob {
    position: absolute;
    border-radius: 50%;
    filter: blur(80px);
    opacity: 0.35;
    animation: blobFloat 20s ease-in-out infinite;
}

.blob-1 {
    width: 500px;
    height: 500px;
    background: radial-gradient(circle, #4f46e5 0%, transparent 70%);
    top: -10%;
    left: -5%;
    animation-duration: 25s;
}

.blob-2 {
    width: 400px;
    height: 400px;
    background: radial-gradient(circle, #7c3aed 0%, transparent 70%);
    top: 50%;
    right: -8%;
    animation-duration: 20s;
    animation-delay: -5s;
}

.blob-3 {
    width: 350px;
    height: 350px;
    background: radial-gradient(circle, #2563eb 0%, transparent 70%);
    bottom: -5%;
    left: 30%;
    animation-duration: 22s;
    animation-delay: -10s;
}

@keyframes blobFloat {
    0%, 100% { transform: translate(0, 0) scale(1); }
    25% { transform: translate(40px, -30px) scale(1.05); }
    50% { transform: translate(-20px, 20px) scale(0.95); }
    75% { transform: translate(30px, 40px) scale(1.02); }
}

/* ===== Header ===== */
.header {
    position: sticky;
    top: 0;
    z-index: 100;
    backdrop-filter: blur(20px) saturate(1.5);
    -webkit-backdrop-filter: blur(20px) saturate(1.5);
    background: rgba(15, 15, 26, 0.75);
    border-bottom: 1px solid var(--color-border);
    height: var(--header-height);
}

.header-inner {
    max-width: 1400px;
    margin: 0 auto;
    padding: 0 32px;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.logo-section {
    display: flex;
    align-items: center;
    gap: 14px;
}

.logo-icon svg {
    width: 40px;
    height: 40px;
    display: block;
}

.logo-text h1 {
    font-size: 1.2rem;
    font-weight: 700;
    letter-spacing: 0.5px;
    background: linear-gradient(135deg, #e8e8f0 30%, #a78bfa);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.logo-text p {
    font-size: 0.72rem;
    color: var(--color-text-muted);
    font-weight: 400;
    letter-spacing: 1px;
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 12px;
}

/* ===== Search ===== */
.search-box {
    position: relative;
    display: flex;
    align-items: center;
}

.search-icon {
    position: absolute;
    left: 12px;
    width: 16px;
    height: 16px;
    color: var(--color-text-muted);
    pointer-events: none;
    transition: color var(--transition-fast);
}

#searchInput {
    width: 220px;
    padding: 9px 14px 9px 36px;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    background: var(--color-surface);
    color: var(--color-text);
    font-family: var(--font-sans);
    font-size: 0.85rem;
    outline: none;
    transition: all var(--transition-base);
}

#searchInput:focus {
    width: 300px;
    border-color: var(--color-primary);
    background: rgba(99, 102, 241, 0.08);
    box-shadow: 0 0 0 3px var(--color-primary-glow);
}

#searchInput:focus + .search-icon,
.search-box:hover .search-icon {
    color: var(--color-primary-light);
}

#searchInput::placeholder {
    color: var(--color-text-muted);
}

/* ===== Buttons ===== */
.btn-icon {
    width: 40px;
    height: 40px;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    background: var(--color-surface);
    color: var(--color-text-secondary);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all var(--transition-base);
}

.btn-icon svg {
    width: 18px;
    height: 18px;
}

.btn-icon:hover {
    background: var(--color-surface-hover);
    border-color: var(--color-border-hover);
    color: var(--color-text);
    transform: rotate(30deg);
}

.btn {
    padding: 9px 18px;
    border: none;
    border-radius: var(--radius-sm);
    font-family: var(--font-sans);
    font-size: 0.85rem;
    font-weight: 500;
    cursor: pointer;
    transition: all var(--transition-base);
    white-space: nowrap;
}

.btn-primary {
    background: linear-gradient(135deg, var(--color-primary), #7c3aed);
    color: white;
    box-shadow: 0 2px 10px rgba(99, 102, 241, 0.3);
}

.btn-primary:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 16px rgba(99, 102, 241, 0.5);
}

.btn-secondary {
    background: var(--color-surface);
    color: var(--color-text-secondary);
    border: 1px solid var(--color-border);
}

.btn-secondary:hover {
    background: var(--color-surface-hover);
    color: var(--color-text);
    border-color: var(--color-border-hover);
}

.btn-danger {
    background: rgba(239, 68, 68, 0.15);
    color: var(--color-danger);
    border: 1px solid rgba(239, 68, 68, 0.2);
}

.btn-danger:hover {
    background: rgba(239, 68, 68, 0.25);
}

.btn-sm {
    padding: 5px 10px;
    font-size: 0.78rem;
}

/* ===== Main Content ===== */
.main-content {
    max-width: 1400px;
    margin: 0 auto;
    padding: 40px 32px 60px;
    position: relative;
    z-index: 1;
}

/* ===== Group ===== */
.group {
    margin-bottom: 48px;
    animation: fadeInUp 0.5s ease both;
}

.group-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 20px;
    padding-bottom: 12px;
    border-bottom: 1px solid var(--color-border);
}

.group-title {
    display: flex;
    align-items: center;
    gap: 10px;
}

.group-title-icon {
    font-size: 1.4rem;
    line-height: 1;
}

.group-title h2 {
    font-size: 1.15rem;
    font-weight: 600;
    color: var(--color-text);
    letter-spacing: 0.3px;
}

.group-title .group-count {
    font-size: 0.75rem;
    color: var(--color-text-muted);
    background: var(--color-surface);
    padding: 2px 8px;
    border-radius: 20px;
    font-weight: 500;
}

.group-actions {
    display: flex;
    gap: 6px;
    opacity: 0;
    transition: opacity var(--transition-base);
}

.group:hover .group-actions {
    opacity: 1;
}

.group-actions .btn-sm {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    color: var(--color-text-muted);
    cursor: pointer;
    border-radius: var(--radius-sm);
    font-family: var(--font-sans);
    transition: all var(--transition-fast);
}

.group-actions .btn-sm:hover {
    background: var(--color-surface-hover);
    color: var(--color-text);
}

/* ===== Cards Grid ===== */
.cards-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 16px;
}

/* ===== Card ===== */
.nav-card {
    position: relative;
    background: var(--color-surface-card);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    padding: 24px;
    cursor: pointer;
    text-decoration: none;
    color: var(--color-text);
    transition: all var(--transition-base);
    display: flex;
    flex-direction: column;
    gap: 12px;
    overflow: hidden;
}

.nav-card::before {
    content: '';
    position: absolute;
    inset: 0;
    border-radius: var(--radius-lg);
    background: linear-gradient(135deg, rgba(99, 102, 241, 0.08), transparent 60%);
    opacity: 0;
    transition: opacity var(--transition-base);
}

.nav-card:hover {
    transform: translateY(-4px);
    border-color: var(--color-primary);
    box-shadow: var(--shadow-glow), var(--shadow-md);
}

.nav-card:hover::before {
    opacity: 1;
}

.nav-card:active {
    transform: translateY(-2px);
}

.card-top {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    position: relative;
    z-index: 1;
}

.card-icon {
    width: 48px;
    height: 48px;
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
    background: linear-gradient(135deg, rgba(99, 102, 241, 0.2), rgba(124, 58, 237, 0.15));
    border: 1px solid rgba(99, 102, 241, 0.15);
    flex-shrink: 0;
}

.card-arrow {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--color-surface);
    color: var(--color-text-muted);
    transition: all var(--transition-base);
    flex-shrink: 0;
}

.card-arrow svg {
    width: 14px;
    height: 14px;
}

.nav-card:hover .card-arrow {
    background: var(--color-primary);
    color: white;
    transform: translate(2px, -2px);
}

.card-info {
    position: relative;
    z-index: 1;
}

.card-info h3 {
    font-size: 1rem;
    font-weight: 600;
    margin-bottom: 4px;
}

.card-info p {
    font-size: 0.8rem;
    color: var(--color-text-muted);
    line-height: 1.5;
}

.card-url {
    font-size: 0.72rem;
    color: var(--color-text-muted);
    opacity: 0.6;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    position: relative;
    z-index: 1;
    transition: opacity var(--transition-fast);
}

.nav-card:hover .card-url {
    opacity: 1;
    color: var(--color-primary-light);
}

/* Card drag state */
.nav-card.dragging {
    opacity: 0.5;
    transform: scale(0.98);
}

.nav-card.drag-over {
    border-color: var(--color-primary-light);
    box-shadow: 0 0 0 2px var(--color-primary-glow);
}

/* ===== Panel ===== */
.panel-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(4px);
    z-index: 200;
    opacity: 0;
    visibility: hidden;
    transition: all var(--transition-base);
}

.panel-overlay.active {
    opacity: 1;
    visibility: visible;
}

.manage-panel {
    position: fixed;
    top: 0;
    right: 0;
    width: 440px;
    max-width: 90vw;
    height: 100vh;
    background: var(--color-bg-secondary);
    border-left: 1px solid var(--color-border);
    z-index: 201;
    transform: translateX(100%);
    transition: transform var(--transition-slow);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.manage-panel.active {
    transform: translateX(0);
}

.panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 20px 24px;
    border-bottom: 1px solid var(--color-border);
    flex-shrink: 0;
}

.panel-header h2 {
    font-size: 1.1rem;
    font-weight: 600;
}

.btn-close-panel {
    border: none;
    background: none;
    color: var(--color-text-muted);
}

.btn-close-panel:hover {
    color: var(--color-text);
    transform: rotate(90deg) !important;
}

.panel-body {
    flex: 1;
    overflow-y: auto;
    padding: 24px;
}

.panel-body::-webkit-scrollbar {
    width: 4px;
}

.panel-body::-webkit-scrollbar-track {
    background: transparent;
}

.panel-body::-webkit-scrollbar-thumb {
    background: var(--color-border);
    border-radius: 2px;
}

.panel-section {
    margin-bottom: 28px;
}

.panel-section h3 {
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--color-text-secondary);
    margin-bottom: 12px;
    display: flex;
    align-items: center;
    gap: 6px;
}

.hint {
    font-size: 0.75rem;
    color: var(--color-text-muted);
    margin-bottom: 10px;
}

/* ===== Form elements ===== */
.form-row {
    display: flex;
    gap: 8px;
    align-items: center;
    flex-wrap: wrap;
}

.form-stack {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.form-input {
    flex: 1;
    padding: 9px 14px;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    background: var(--color-surface);
    color: var(--color-text);
    font-family: var(--font-sans);
    font-size: 0.85rem;
    outline: none;
    transition: all var(--transition-fast);
    min-width: 0;
}

.form-input:focus {
    border-color: var(--color-primary);
    box-shadow: 0 0 0 3px var(--color-primary-glow);
}

.form-input::placeholder {
    color: var(--color-text-muted);
}

.form-input-sm {
    max-width: 72px;
    flex: 0 0 72px;
    text-align: center;
}

select.form-input {
    cursor: pointer;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%236b7280' d='M2.5 4.5L6 8l3.5-3.5'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 10px center;
    padding-right: 28px;
}

select.form-input option {
    background: var(--color-bg-secondary);
    color: var(--color-text);
}

/* ===== Management list ===== */
.management-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.mgmt-group {
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    overflow: hidden;
}

.mgmt-group-header {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 12px;
    background: var(--color-surface);
    cursor: grab;
    user-select: none;
}

.mgmt-group-header:active {
    cursor: grabbing;
}

.mgmt-drag-handle {
    color: var(--color-text-muted);
    display: flex;
    align-items: center;
    flex-shrink: 0;
}

.mgmt-drag-handle svg {
    width: 14px;
    height: 14px;
}

.mgmt-group-name {
    flex: 1;
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--color-text);
}

.mgmt-group-actions {
    display: flex;
    gap: 4px;
}

.mgmt-group-actions button {
    background: none;
    border: none;
    color: var(--color-text-muted);
    cursor: pointer;
    width: 24px;
    height: 24px;
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.75rem;
    transition: all var(--transition-fast);
}

.mgmt-group-actions button:hover {
    background: var(--color-surface-hover);
    color: var(--color-text);
}

.mgmt-group-actions button.delete-btn:hover {
    color: var(--color-danger);
}

.mgmt-links {
    padding: 6px;
    display: flex;
    flex-direction: column;
    gap: 4px;
    min-height: 32px;
}

.mgmt-link-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 10px;
    border-radius: var(--radius-sm);
    background: var(--color-bg);
    border: 1px solid transparent;
    cursor: grab;
    user-select: none;
    transition: all var(--transition-fast);
}

.mgmt-link-item:active {
    cursor: grabbing;
}

.mgmt-link-item:hover {
    border-color: var(--color-border);
}

.mgmt-link-item.dragging {
    opacity: 0.4;
}

.mgmt-link-item.drag-over {
    border-color: var(--color-primary);
    background: rgba(99, 102, 241, 0.05);
}

.mgmt-link-icon {
    font-size: 1rem;
    flex-shrink: 0;
    width: 24px;
    text-align: center;
}

.mgmt-link-name {
    flex: 1;
    font-size: 0.8rem;
    color: var(--color-text-secondary);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.mgmt-link-actions {
    display: flex;
    gap: 2px;
}

.mgmt-link-actions button {
    background: none;
    border: none;
    color: var(--color-text-muted);
    cursor: pointer;
    width: 22px;
    height: 22px;
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.7rem;
    transition: all var(--transition-fast);
}

.mgmt-link-actions button:hover {
    background: var(--color-surface-hover);
    color: var(--color-text);
}

.mgmt-link-actions button.delete-btn:hover {
    color: var(--color-danger);
}

/* Sortable group dragging */
.mgmt-group.dragging {
    opacity: 0.4;
}

.mgmt-group.drag-over-group {
    border-color: var(--color-primary);
    box-shadow: 0 0 0 2px var(--color-primary-glow);
}

/* ===== Modal ===== */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(6px);
    z-index: 300;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    visibility: hidden;
    transition: all var(--transition-base);
}

.modal-overlay.active {
    opacity: 1;
    visibility: visible;
}

.modal {
    background: var(--color-bg-secondary);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-xl);
    width: 440px;
    max-width: 90vw;
    max-height: 80vh;
    display: flex;
    flex-direction: column;
    transform: scale(0.95) translateY(10px);
    transition: transform var(--transition-base);
    box-shadow: var(--shadow-lg);
}

.modal-overlay.active .modal {
    transform: scale(1) translateY(0);
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 20px 24px 16px;
}

.modal-header h3 {
    font-size: 1rem;
    font-weight: 600;
}

.modal-body {
    padding: 0 24px;
    overflow-y: auto;
    flex: 1;
}

.modal-body .form-stack {
    margin-bottom: 16px;
}

.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    padding: 16px 24px 20px;
}

/* ===== Toast ===== */
.toast-container {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 500;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.toast {
    padding: 12px 20px;
    border-radius: var(--radius-md);
    background: var(--color-bg-secondary);
    border: 1px solid var(--color-border);
    color: var(--color-text);
    font-size: 0.85rem;
    box-shadow: var(--shadow-md);
    animation: toastIn 0.3s ease, toastOut 0.3s ease 2.5s forwards;
    display: flex;
    align-items: center;
    gap: 8px;
}

.toast.success { border-color: var(--color-success); }
.toast.error { border-color: var(--color-danger); }
.toast.warning { border-color: var(--color-warning); }

@keyframes toastIn {
    from { transform: translateX(100%); opacity: 0; }
    to { transform: translateX(0); opacity: 1; }
}

@keyframes toastOut {
    from { transform: translateX(0); opacity: 1; }
    to { transform: translateX(100%); opacity: 0; }
}

/* ===== Footer ===== */
.footer {
    text-align: center;
    padding: 24px 32px;
    color: var(--color-text-muted);
    font-size: 0.75rem;
    position: relative;
    z-index: 1;
    border-top: 1px solid var(--color-border);
}

/* ===== Animations ===== */
@keyframes fadeInUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.card-enter {
    animation: fadeInUp 0.4s ease both;
}

/* ===== Empty state ===== */
.empty-state {
    text-align: center;
    padding: 60px 20px;
    color: var(--color-text-muted);
}

.empty-state svg {
    width: 64px;
    height: 64px;
    margin-bottom: 16px;
    opacity: 0.3;
}

.empty-state h3 {
    font-size: 1rem;
    margin-bottom: 8px;
    color: var(--color-text-secondary);
}

.empty-state p {
    font-size: 0.85rem;
}

/* ===== Responsive ===== */
@media (max-width: 768px) {
    :root {
        --header-height: 60px;
    }

    .header-inner {
        padding: 0 16px;
    }

    .logo-text h1 {
        font-size: 1rem;
    }

    .logo-text p {
        display: none;
    }

    #searchInput {
        width: 160px;
    }

    #searchInput:focus {
        width: 200px;
    }

    .main-content {
        padding: 24px 16px 40px;
    }

    .cards-grid {
        grid-template-columns: 1fr;
        gap: 12px;
    }

    .manage-panel {
        width: 100vw;
    }
}

@media (max-width: 480px) {
    .search-box {
        display: none;
    }

    .cards-grid {
        grid-template-columns: 1fr;
    }
}

/* ===== Card Color Variants Based on Data Attribute ===== */
.nav-card[data-color="blue"] .card-icon {
    background: linear-gradient(135deg, rgba(59, 130, 246, 0.2), rgba(37, 99, 235, 0.15));
    border-color: rgba(59, 130, 246, 0.2);
}

.nav-card[data-color="purple"] .card-icon {
    background: linear-gradient(135deg, rgba(139, 92, 246, 0.2), rgba(124, 58, 237, 0.15));
    border-color: rgba(139, 92, 246, 0.2);
}

.nav-card[data-color="green"] .card-icon {
    background: linear-gradient(135deg, rgba(16, 185, 129, 0.2), rgba(5, 150, 105, 0.15));
    border-color: rgba(16, 185, 129, 0.2);
}

.nav-card[data-color="red"] .card-icon {
    background: linear-gradient(135deg, rgba(239, 68, 68, 0.2), rgba(220, 38, 38, 0.15));
    border-color: rgba(239, 68, 68, 0.2);
}

.nav-card[data-color="amber"] .card-icon {
    background: linear-gradient(135deg, rgba(245, 158, 11, 0.2), rgba(217, 119, 6, 0.15));
    border-color: rgba(245, 158, 11, 0.2);
}

.nav-card[data-color="teal"] .card-icon {
    background: linear-gradient(135deg, rgba(20, 184, 166, 0.2), rgba(13, 148, 136, 0.15));
    border-color: rgba(20, 184, 166, 0.2);
}

/* ===== No Results ===== */
.no-results {
    grid-column: 1 / -1;
    text-align: center;
    padding: 40px;
    color: var(--color-text-muted);
    font-size: 0.9rem;
}

/* Hidden groups when searching */
.group.hidden {
    display: none;
}
