/* 
  Ultra-Premium Financial/Tech UI
  Design Language: Extreme cleanliness, crisp micro-borders, refined typography
*/

/* Import a very clean, professional font used in high-end dashboards */
@import url('https://fonts.googleapis.com/css2?family=Roboto:wght@400;500;700&family=IBM+Plex+Sans:wght@400;500;600&display=swap');

:root {
    /* Light Mode - Ultra clean, high contrast structural borders */
    --bg-color: #f4f5f7; /* Very light cool gray instead of pure white */
    --bg-surface: #ffffff; /* Actual cards/panels */
    
    --text-primary: #1a1b1e;
    --text-secondary: #5e6470;
    --text-tertiary: #8f95a3;
    
    /* Super precise borders: 1px solid, low opacity */
    --border-subtle: #e2e4e8;
    --border-strong: #d1d5db;
    
    /* Box shadows representing elevation instead of 'glass' */
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.04);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.05), 0 2px 4px -2px rgba(0, 0, 0, 0.03);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.05), 0 4px 6px -4px rgba(0, 0, 0, 0.02);
    
    --card-hover-bg: #f9fafb;
    --card-hover-border: #2563eb; /* Sharp vivid blue for interaction */
    
    --primary-color: #2563eb; /* Modern vibrant blue, slightly less dated than navy */
    --primary-hover: #1d4ed8;
    --danger-color: #ef4444;
    --danger-hover: #dc2828;
    
    /* Gradients removed entirely for a solid structural feel, replaced by clean solid background */
    --gradient-1: var(--bg-color);
    --gradient-2: var(--bg-color);

    --radius-lg: 6px;  /* Sharp, professional corners */
    --radius-md: 4px;
    --radius-sm: 2px;
    
    --transition-fast: 0.15s ease;
}

/* Dark Mode - Morandi Palette (Muted, Dusty, Low-Saturation) */
[data-theme="dark"] {
    /* Deep dusty slate-blue/gray base */
    --bg-color: #2b2d35; 
    /* Slightly lighter dusty gray for cards */
    --bg-surface: #363942; 
    
    /* Soft, warm off-white for text to reduce harsh contrast */
    --text-primary: #dcdadd;
    /* Muted dusty sage/gray for secondary text */
    --text-secondary: #90949d;
    --text-tertiary: #6b6f79;
    
    /* Low contrast structural borders */
    --border-subtle: #454955;
    --border-strong: #5a5f6d;
    
    /* Softer shadows */
    --shadow-sm: 0 1px 2px rgba(20, 21, 25, 0.4);
    --shadow-md: 0 4px 6px -1px rgba(20, 21, 25, 0.5);
    --shadow-lg: 0 10px 15px -3px rgba(20, 21, 25, 0.6);
    
    /* Hover states keeping the muted aesthetic */
    --card-hover-bg: #414550;
    
    /* Primary brand color: A sophisticated, dusty grayish-blue (Morandi Blue) */
    --card-hover-border: #6d869e; 
    --primary-color: #6d869e; 
    --primary-hover: #8da3b8;
    
    --danger-color: #ba6d6c; /* Muted brick/dusty rose instead of harsh red */
    --danger-hover: #d18887;
    
    --gradient-1: var(--bg-color);
    --gradient-2: var(--bg-color);
}

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

body {
    /* Use IBM Plex Sans for a tech/data-heavy feel, fallback to system */
    font-family: 'IBM Plex Sans', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    background-color: var(--bg-color);
    color: var(--text-primary);
    min-height: 100vh;
    transition: background-color var(--transition-fast), color var(--transition-fast);
    /* Improve font rendering */
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* Background animation */
#background-wrapper {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    z-index: -1;
    background: var(--bg-color);
}

/* Replaces old glass-effect with a solid, bordered, elevated surface */
.surface-effect {
    background: var(--bg-surface);
    border: 1px solid var(--border-subtle);
    box-shadow: var(--shadow-sm);
}

/* Navbar */
.navbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.85rem 2rem; 
    position: sticky;
    top: 0;
    z-index: 100;
    background: var(--bg-surface);
    border-bottom: 1px solid var(--border-subtle);
    margin-bottom: 2rem; 
    box-shadow: var(--shadow-sm);
}

.nav-brand {
    font-size: 1.15rem; 
    font-weight: 600;
    letter-spacing: -0.2px;
    color: var(--text-primary);
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.nav-brand::before {
    content: '';
    display: inline-block;
    width: 12px;
    height: 12px;
    background: var(--primary-color);
    border-radius: 2px;
}

.nav-actions {
    display: flex;
    gap: 0.5rem;
}

/* Container */
.container {
    max-width: 1280px; /* Wider professional layout */
    margin: 0 auto;
    padding: 0 2rem 4rem 2rem; 
}

/* Buttons */
button {
    cursor: pointer;
    border: none;
    outline: none;
    font-family: inherit;
    transition: all var(--transition-fast);
}

.icon-btn {
    background: transparent;
    color: var(--text-secondary);
    font-size: 1.1rem; 
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius-sm); /* Square buttons are more pro */
    width: 34px; 
    height: 34px;
    border: 1px solid transparent;
}

.icon-btn.small {
    width: 24px; 
    height: 24px;
    font-size: 1rem;
}

.icon-btn:hover {
    background: var(--bg-color);
    color: var(--text-primary);
    border-color: var(--border-subtle);
}

.icon-btn.active {
    color: var(--primary-color);
    background: rgba(37, 99, 235, 0.08); /* Faint blue bg */
    border-color: rgba(37, 99, 235, 0.2);
}

.primary-btn {
    background: var(--primary-color);
    color: #ffffff;
    padding: 0.4rem 0.85rem; 
    border-radius: var(--radius-md);
    font-size: 0.85rem;
    font-weight: 500;
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    border: 1px solid transparent;
}

.primary-btn:hover {
    background: var(--primary-hover);
    box-shadow: var(--shadow-sm);
}

.secondary-btn {
    background: var(--bg-surface);
    color: var(--text-primary);
    padding: 0.4rem 0.85rem;
    font-size: 0.85rem;
    border-radius: var(--radius-md);
    font-weight: 500;
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    border: 1px solid var(--border-strong);
}

.secondary-btn:hover {
    background: var(--bg-color);
}

.danger {
    color: var(--danger-color) !important;
}

.danger:hover {
    background: rgba(239, 68, 68, 0.05) !important;
    border-color: rgba(239, 68, 68, 0.2) !important;
}

/* Global Actions */
.global-actions {
    margin-bottom: 2rem; 
    display: flex;
    justify-content: center;
    gap: 0.75rem;
}

/* Group Section */
.group-section {
    background: var(--bg-surface);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-lg);
    padding: 1.25rem 1.5rem; 
    margin-bottom: 1.5rem; 
    box-shadow: var(--shadow-sm);
    animation: fadeIn 0.3s ease-out forwards;
}

.group-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.25rem; 
    padding-bottom: 0.75rem;
    border-bottom: 1px solid var(--border-subtle);
}

.group-title-wrapper {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.group-title {
    font-size: 0.95rem; /* Sophisticated typography: smaller but bolder */
    font-weight: 600;
    color: var(--text-primary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.group-footer {
    margin-top: 1.25rem;
    padding-top: 1rem;
    border-top: 1px dotted var(--border-subtle);
    display: flex;
    justify-content: center;
}

/* Link Grid */
.link-grid {
    display: grid;
    /* Clean, rigid grid */
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 0.75rem; 
    min-height: 40px; 
}

/* Link Card */
.link-card {
    background: var(--bg-surface);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-md);
    position: relative;
    overflow: hidden;
    transition: all var(--transition-fast);
    height: 36px; /* Crisply defined height */
}

.link-card::before {
    content: '';
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    width: 3px;
    background: transparent;
    transition: background 0.2s;
}

.link-card:hover {
    background: var(--card-hover-bg);
    border-color: var(--border-strong);
    box-shadow: var(--shadow-sm);
}

/* Add a premium left-border highlight effect like on data rows */
.link-card:hover::before {
    background: var(--card-hover-border);
}

.link-anchor {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0 0.75rem;
    color: var(--text-primary);
    text-decoration: none;
    font-size: 0.85rem; 
    font-weight: 500;
    width: 100%;
    height: 100%;
}

.link-favicon {
    width: 16px;
    height: 16px;
    border-radius: 2px;
    flex-shrink: 0;
    background: transparent;
}

.link-title {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.link-anchor:hover {
    color: var(--primary-color);
}




/* Edit Mode Overlay on Link Cards */
.link-edit-controls {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: var(--bg-surface);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 0.25rem;
    opacity: 0;
    pointer-events: none;
    /* Subdued fade in */
    transition: opacity 0.1s;
    border-left: 3px solid var(--primary-color);
}

/* Only show controls when hovering the card OR when dragging */
.link-card:hover .link-edit-controls,
.sortable-drag .link-edit-controls {
    opacity: 1;
    pointer-events: all;
    background: var(--card-hover-bg);
}

.link-action-buttons {
    display: flex;
    gap: 2px;
}

/* Drag Handles */
.drag-handle {
    cursor: grab;
    color: var(--text-tertiary);
    font-size: 1rem;
    padding: 0.25rem;
}

.drag-handle:active {
    cursor: grabbing;
    color: var(--primary-color);
}

.group-drag-handle {
    font-size: 1.15rem;
}

/* SortableJS Classes */
.sortable-ghost {
    opacity: 0.3;
    background-color: var(--bg-color);
    border: 1px dashed var(--border-strong);
}

.sortable-drag {
    cursor: grabbing !important;
    box-shadow: var(--shadow-lg) !important;
    transform: scale(1.02);
    z-index: 100;
}

/* Modal CSS - Extremely rigid and structured */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background-color: rgba(0, 0, 0, 0.5); /* Solid dark backdrop */
    z-index: 1000;
    display: flex;
    justify-content: center;
    align-items: center;
    opacity: 1;
    transition: opacity var(--transition-fast);
}

.modal-overlay.hidden {
    opacity: 0;
    pointer-events: none;
}

.modal-content {
    background: var(--bg-surface); 
    border-radius: var(--radius-lg);
    border: 1px solid var(--border-subtle);
    padding: 2rem;
    width: 100%;
    max-width: 420px;
    box-shadow: var(--shadow-lg);
}

.modal-content h3 {
    margin-bottom: 1.5rem;
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--text-primary);
    border-bottom: 1px solid var(--border-subtle);
    padding-bottom: 0.75rem;
}

.form-group {
    margin-bottom: 1.25rem;
}

.form-group label {
    display: block;
    margin-bottom: 0.4rem;
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.form-group input {
    width: 100%;
    padding: 0.6rem 0.75rem;
    border-radius: var(--radius-md);
    border: 1px solid var(--border-strong);
    background: var(--bg-color);
    color: var(--text-primary);
    font-family: inherit;
    font-size: 0.95rem;
    outline: none;
    transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}

.form-group input:focus {
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1); /* Focus ring */
    background: var(--bg-surface);
}

.modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 0.75rem;
    margin-top: 2rem;
    padding-top: 1.25rem;
    border-top: 1px solid var(--border-subtle);
}

/* Utility */
.hidden {
    display: none !important;
}

/* Animations */
@keyframes fadeIn {
    from { opacity: 0; transform: translateY(2px); }
    to { opacity: 1; transform: translateY(0); }
}

@media (max-width: 600px) {
    .link-grid {
        grid-template-columns: repeat(3, 1fr);
    }
}

/* Empty Slots */
.empty-slot {
    background: transparent !important;
    border: 1px dashed transparent !important;
    box-shadow: none !important;
    pointer-events: none; /* Ignore clicks in normal mode */
}

/* Edit mode styles */
body.is-edit-mode .empty-slot {
    border-color: var(--border-strong) !important;
    background: rgba(0, 0, 0, 0.02) !important;
    pointer-events: auto; /* Allow drag targets */
}

body.is-edit-mode .empty-slot:hover {
    border-color: var(--primary-color) !important;
}

[data-theme="dark"] body.is-edit-mode .empty-slot {
    background: rgba(255, 255, 255, 0.02) !important;
}

.sortable-swap-highlight {
    box-shadow: 0 0 0 2px var(--primary-color) inset !important;
    background: rgba(37, 99, 235, 0.1) !important;
}
