/* Reset and Base Styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    /* Default Light Theme */
    --bg-primary: #f8f9fa;
    --bg-secondary: #ffffff;
    --text-primary: #212529;
    --text-secondary: #6c757d;
    --accent: #667eea;
    --accent-hover: #5a67d8;
    --border: #dee2e6;
    --shadow: rgba(0, 0, 0, 0.1);
    --card-radius: 12px;
    --card-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    --font-family: 'Inter', system-ui, -apple-system, sans-serif;
}

body {
    font-family: var(--font-family);
    background: var(--bg-primary);
    color: var(--text-primary);
    min-height: 100vh;
    transition: background-color 0.3s ease, color 0.3s ease;
}

/* Dark Mode */
body.dark-mode {
    --bg-primary: #1a1a2e;
    --bg-secondary: #16213e;
    --text-primary: #f1f1f1;
    --text-secondary: #a8a8a8;
    --accent: #7c3aed;
    --accent-hover: #6d28d9;
    --border: #2d3748;
    --shadow: rgba(0, 0, 0, 0.3);
}

/* App Container */
.app-container {
    max-width: 1400px;
    margin: 0 auto;
    padding: 20px;
}

/* Header */
.page-header {
    text-align: center;
    padding: 40px 20px;
    margin-bottom: 40px;
}

.site-title {
    font-size: 2.5rem;
    font-weight: 700;
    margin-bottom: 10px;
    background: linear-gradient(135deg, var(--accent) 0%, #764ba2 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    /* Firefox fallback */
    -moz-background-clip: text;
    -moz-text-fill-color: transparent;
    /* Fallback for browsers that don't support background-clip: text */
    color: var(--accent);
}

.site-tagline {
    font-size: 1.1rem;
    color: var(--text-secondary);
}

/* Masonry Grid */
.masonry-container {
    -webkit-column-count: 4;
    -moz-column-count: 4;
    column-count: 4;
    -webkit-column-gap: 20px;
    -moz-column-gap: 20px;
    column-gap: 20px;
    margin: 0 auto;
    padding: 0 20px;
}

@media (max-width: 1200px) {
    .masonry-container {
        -webkit-column-count: 3;
        -moz-column-count: 3;
        column-count: 3;
    }
}

@media (max-width: 768px) {
    .masonry-container {
        -webkit-column-count: 2;
        -moz-column-count: 2;
        column-count: 2;
        -webkit-column-gap: 15px;
        -moz-column-gap: 15px;
        column-gap: 15px;
    }
}

@media (max-width: 480px) {
    .masonry-container {
        -webkit-column-count: 1;
        -moz-column-count: 1;
        column-count: 1;
    }
}

/* Link Cards */
.link-card {
    background: var(--bg-secondary);
    border-radius: var(--card-radius);
    padding: 20px;
    margin-bottom: 20px;
    -webkit-column-break-inside: avoid;
    page-break-inside: avoid;
    break-inside: avoid;
    box-shadow: var(--card-shadow);
    -webkit-transition: transform 0.2s ease, box-shadow 0.2s ease;
    -moz-transition: transform 0.2s ease, box-shadow 0.2s ease;
    -o-transition: transform 0.2s ease, box-shadow 0.2s ease;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
    cursor: pointer;
    position: relative;
    overflow: hidden;
    /* Ensure cards don't break across columns in all browsers */
    display: inline-block;
    width: 100%;
}

.link-card:hover {
    -webkit-transform: translateY(-4px);
    -moz-transform: translateY(-4px);
    -ms-transform: translateY(-4px);
    -o-transform: translateY(-4px);
    transform: translateY(-4px);
    box-shadow: 0 8px 20px var(--shadow);
}

.link-card.has-image {
    padding: 0;
}

.link-card-image {
    width: 100%;
    height: auto;
    border-radius: var(--card-radius) var(--card-radius) 0 0;
}

.link-card-content {
    padding: 20px;
}

.link-card.has-image .link-card-content {
    padding-top: 15px;
}

.link-card-category {
    display: inline-block;
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--accent);
    margin-bottom: 8px;
    font-weight: 600;
}

.link-card-title {
    font-size: 1.25rem;
    font-weight: 600;
    margin-bottom: 8px;
    color: inherit;
    text-decoration: none;
    display: block;
}

.link-card-description {
    font-size: 0.95rem;
    color: var(--text-secondary);
    line-height: 1.5;
    margin-bottom: 12px;
}

.link-card-url {
    font-size: 0.85rem;
    color: var(--accent);
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    gap: 5px;
}

.link-card-url:hover {
    text-decoration: underline;
}

/* Settings Button */
.settings-btn {
    position: fixed;
    bottom: 30px;
    right: 30px;
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: var(--accent);
    color: white;
    border: none;
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.4);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
    z-index: 100;
}

.settings-btn:hover {
    -webkit-transform: scale(1.1);
    -moz-transform: scale(1.1);
    -ms-transform: scale(1.1);
    -o-transform: scale(1.1);
    transform: scale(1.1);
    box-shadow: 0 6px 20px rgba(102, 126, 234, 0.5);
}

/* Options Dialog */
.options-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 200;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.options-overlay.active {
    display: block;
    opacity: 1;
}

.options-dialog {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%) scale(0.9);
    background: var(--bg-secondary);
    border-radius: 16px;
    width: 90%;
    max-width: 700px;
    max-height: 85vh;
    overflow: hidden;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
    z-index: 201;
    display: none;
    opacity: 0;
    transition: transform 0.3s ease, opacity 0.3s ease;
}

.options-dialog.active {
    display: block;
    transform: translate(-50%, -50%) scale(1);
    opacity: 1;
}

.dialog-header {
    padding: 20px;
    border-bottom: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.dialog-header h2 {
    font-size: 1.5rem;
    font-weight: 600;
}

.close-btn {
    background: none;
    border: none;
    font-size: 2rem;
    color: var(--text-secondary);
    cursor: pointer;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 8px;
    transition: background-color 0.2s ease;
}

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

.dialog-content {
    overflow-y: auto;
    max-height: calc(85vh - 70px);
}

/* Tabs */
.tabs {
    display: flex;
    gap: 5px;
    padding: 15px 20px;
    border-bottom: 1px solid var(--border);
}

.tab-btn {
    padding: 10px 20px;
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    border-radius: 8px;
    font-size: 0.95rem;
    font-weight: 500;
    transition: all 0.2s ease;
}

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

.tab-btn.active {
    background: var(--accent);
    color: white;
}

.tab-content {
    display: none;
    padding: 20px;
}

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

/* Import/Export Section */
.import-export-section {
    background: var(--bg-primary);
    padding: 20px;
    border-radius: 8px;
    margin-bottom: 25px;
}

.button-group {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    margin: 15px 0;
}

.info-message {
    background: rgba(102, 126, 234, 0.1);
    border-left: 3px solid var(--accent);
    padding: 15px;
    border-radius: 4px;
    margin-top: 15px;
}

.info-message p {
    margin: 0 0 10px 0;
    font-weight: 500;
}

.info-message ol {
    margin: 0;
    padding-left: 20px;
}

.info-message li {
    margin: 5px 0;
}

/* Forms */
.form-group {
    margin-bottom: 15px;
}

.form-group label {
    display: block;
    margin-bottom: 5px;
    font-size: 0.9rem;
    font-weight: 500;
    color: var(--text-secondary);
}

.form-group input[type="text"],
.form-group input[type="url"],
.form-group input[type="password"],
.form-group textarea,
.form-group select {
    width: 100%;
    padding: 10px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--bg-primary);
    color: var(--text-primary);
    font-size: 0.95rem;
    transition: border-color 0.2s ease;
    /* Better cross-browser support */
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
    font-family: inherit;
}

.form-group input:focus,
.form-group textarea:focus,
.form-group select:focus {
    outline: none;
    border-color: var(--accent);
}

.form-group textarea {
    resize: vertical;
    font-family: inherit;
}

.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 15px;
}

.form-group input[type="color"] {
    width: 50px;
    height: 40px;
    border: 1px solid var(--border);
    border-radius: 8px;
    cursor: pointer;
}

.form-group input[type="range"] {
    width: 100%;
}

/* Buttons */
.btn {
    padding: 10px 20px;
    border: none;
    border-radius: 8px;
    font-size: 0.95rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
}

.btn-primary {
    background: var(--accent);
    color: white;
}

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

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

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

.btn-danger {
    background: #dc3545;
    color: white;
}

.btn-danger:hover {
    background: #c82333;
}

/* Links List */
.links-list {
    max-height: 400px;
    overflow-y: auto;
    padding: 10px 0;
}

.link-item {
    display: flex;
    align-items: center;
    padding: 12px;
    background: var(--bg-primary);
    border-radius: 8px;
    margin-bottom: 10px;
    transition: background-color 0.2s ease;
}

.link-item:hover {
    background: var(--border);
}

.link-item-handle {
    cursor: move;
    margin-right: 10px;
    color: var(--text-secondary);
}

.link-item-info {
    flex: 1;
}

.link-item-title {
    font-weight: 500;
    margin-bottom: 2px;
}

.link-item-url {
    font-size: 0.85rem;
    color: var(--text-secondary);
}

.link-item-actions {
    display: flex;
    gap: 8px;
}

.link-item-actions button {
    padding: 6px 12px;
    font-size: 0.85rem;
}

/* Theme Toggle Switch */
.theme-toggle {
    display: flex;
    align-items: center;
    gap: 15px;
    margin: 20px 0;
}

.switch {
    position: relative;
    display: inline-block;
    width: 50px;
    height: 24px;
}

.switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: var(--border);
    transition: 0.3s;
    border-radius: 24px;
}

.slider:before {
    position: absolute;
    content: "";
    height: 18px;
    width: 18px;
    left: 3px;
    bottom: 3px;
    background-color: white;
    transition: 0.3s;
    border-radius: 50%;
}

input:checked + .slider {
    background-color: var(--accent);
}

input:checked + .slider:before {
    transform: translateX(26px);
}

/* Color Presets */
.color-presets {
    display: flex;
    gap: 10px;
    margin: 20px 0;
}

.color-preset {
    width: 50px;
    height: 50px;
    border-radius: 8px;
    border: 2px solid transparent;
    cursor: pointer;
    transition: all 0.2s ease;
}

.color-preset:hover {
    transform: scale(1.1);
}

.color-preset.active {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.2);
}

/* Pattern Options */
.pattern-options {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 10px;
}

.pattern-btn {
    padding: 15px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--bg-primary);
    cursor: pointer;
    transition: all 0.2s ease;
}

.pattern-btn:hover {
    border-color: var(--accent);
    background: var(--accent);
    color: white;
}

.pattern-btn.active {
    background: var(--accent);
    color: white;
    border-color: var(--accent);
}

/* Edit Modal */
.edit-modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 300;
    display: flex;
    align-items: center;
    justify-content: center;
}

.modal-content {
    background: var(--bg-secondary);
    border-radius: 12px;
    padding: 25px;
    width: 90%;
    max-width: 500px;
}

.modal-content h3 {
    margin-bottom: 20px;
}

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

/* Dragging State */
.dragging {
    opacity: 0.5;
}

.drag-over {
    background: var(--accent);
    opacity: 0.2;
}

/* Password Dialog */
.password-overlay {
    display: none !important;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.7);
    z-index: 300;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.password-overlay.active {
    display: block !important;
    opacity: 1;
}

.password-dialog {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%) scale(0.9);
    background: var(--bg-secondary);
    border-radius: 16px;
    width: 90%;
    max-width: 400px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
    z-index: 301;
    display: none !important;
    opacity: 0;
    transition: transform 0.3s ease, opacity 0.3s ease;
}

.password-dialog.active {
    display: block !important;
    transform: translate(-50%, -50%) scale(1);
    opacity: 1;
}

.password-content {
    padding: 30px;
    text-align: center;
}

.password-content h2 {
    margin-bottom: 10px;
    color: var(--text-primary);
}

.password-content p {
    color: var(--text-secondary);
    margin-bottom: 25px;
}

.password-actions {
    display: flex;
    gap: 10px;
    justify-content: center;
    margin-top: 20px;
}

#passwordInput {
    width: 100%;
    padding: 12px;
    font-size: 1rem;
    text-align: center;
    letter-spacing: 2px;
}

.error-message {
    color: #dc3545;
    margin-top: 15px;
    font-size: 0.9rem;
    padding: 10px;
    background: rgba(220, 53, 69, 0.1);
    border-radius: 8px;
}

/* Responsive Adjustments */
@media (max-width: 768px) {
    .page-header {
        padding: 30px 15px;
    }
    
    .site-title {
        font-size: 2rem;
    }
    
    .options-dialog {
        width: 95%;
        max-height: 90vh;
    }
    
    .form-row {
        grid-template-columns: 1fr;
    }
    
    .settings-btn {
        bottom: 20px;
        right: 20px;
    }
}

/* Background Patterns */
body.pattern-dots {
    background-image: radial-gradient(circle, var(--text-secondary) 1px, transparent 1px);
    background-size: 20px 20px;
}

body.pattern-grid {
    background-image: 
        linear-gradient(var(--border) 1px, transparent 1px),
        linear-gradient(90deg, var(--border) 1px, transparent 1px);
    background-size: 20px 20px;
}

body.pattern-diagonal {
    background-image: repeating-linear-gradient(
        45deg,
        transparent,
        transparent 10px,
        var(--border) 10px,
        var(--border) 11px
    );
}

body.pattern-waves {
    background-image: url("data:image/svg+xml,%3Csvg width='100' height='20' viewBox='0 0 100 20' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M21.184 20c.357-.13.72-.264 1.088-.402l1.768-.661C33.64 15.347 39.647 14 50 14c10.271 0 15.362 1.222 24.629 4.928.955.383 1.869.74 2.75 1.072h6.225c-2.51-.73-5.139-1.691-8.233-2.928C65.888 13.278 60.562 12 50 12c-10.626 0-16.855 1.397-26.66 5.063l-1.767.662c-2.475.923-4.66 1.674-6.724 2.275h6.335zm0-20C13.258 2.892 8.077 4 0 4V2c5.744 0 9.951-.574 14.85-2h6.334zM77.38 0C85.239 2.966 90.502 4 100 4V2c-6.842 0-11.386-.542-16.396-2h-6.225zM0 14c8.44 0 13.718-1.21 22.272-4.402l1.768-.661C33.64 5.347 39.647 4 50 4c10.271 0 15.362 1.222 24.629 4.928C84.112 12.722 89.438 14 100 14v-2c-10.271 0-15.362-1.222-24.629-4.928C65.888 3.278 60.562 2 50 2 39.374 2 33.145 3.397 23.34 7.063l-1.767.662C13.223 10.84 8.163 12 0 12v2z' fill='%23dee2e6' fill-opacity='0.2'/%3E%3C/svg%3E");
}
