/* ========================================
   CONTACT MANAGEMENT SYSTEM - CLEAN CSS
   ======================================== */

/* ========== ROOT VARIABLES ========== */
:root {
    /* Colors - Primary Palette */
    --primary-color: #3b82f6;
    --primary-dark: #2563eb;
    --primary-light: #dbeafe;
    --success-color: #10b981;
    --error-color: #ef4444;
    --warning-color: #f59e0b;
    
    /* Text Colors */
    --text-primary: #111827;
    --text-secondary: #6b7280;
    
    /* Background Colors */
    --bg-primary: #ffffff;
    --bg-secondary: #f9fafb;
    --surface-color: #ffffff;
    --hover-color: #f3f4f6;
    --border-color: #e5e7eb;
    
    /* Shadows */
    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
    
    /* Typography */
    --font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    
    /* Spacing */
    --space-1: 0.25rem;
    --space-2: 0.5rem;
    --space-4: 1rem;
    --space-6: 1.5rem;
    --space-8: 2rem;
}

/* ========== BASE STYLES & RESET ========== */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: var(--font-family);
    background-color: var(--bg-secondary);
    color: var(--text-primary);
    line-height: 1.6;
    min-height: 100vh;
}

/* ========== LAYOUT ========== */
.app-container {
    max-width: 1200px;
    margin: 0 auto;
    padding: var(--space-4) var(--space-4) 0;
}

.app-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: var(--space-4) 0;
    margin-bottom: var(--space-4);
    border-bottom: 1px solid var(--border-color);
}

.header-left .app-title {
    margin: 0;
    font-size: 1.5rem;
    font-weight: 600;
    color: var(--text-primary);
}

.header-left .app-title i {
    margin-right: var(--space-2);
    color: var(--primary-color);
}

.header-right {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.main-content {
    display: grid;
    grid-template-columns: 280px 1fr 400px;
    gap: var(--space-4);
    min-height: calc(100vh - 200px);
    max-height: calc(100vh - 200px);
}

/* ========== BUTTONS ========== */
.btn {
    padding: 0.75rem 1.5rem;
    border: none;
    border-radius: 6px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    white-space: nowrap;
}

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

.btn-primary:hover {
    background: var(--primary-dark);
    transform: translateY(-1px);
    box-shadow: 0 4px 8px rgba(59, 130, 246, 0.3);
}

.btn-secondary {
    background: var(--surface-color);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
}

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

.btn-ghost {
    background: transparent;
    color: var(--text-secondary);
    border: none;
    padding: 0.75rem;
    text-decoration: underline;
}

.btn-ghost:hover {
    color: var(--primary-color);
    text-decoration: none;
}

.btn-small {
    padding: var(--space-2) var(--space-4);
    font-size: 0.75rem;
    font-weight: 500;
}

.btn-icon {
    padding: 0.5rem;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    background: var(--surface-color);
    color: var(--text-secondary);
    cursor: pointer;
    transition: all 0.2s ease;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 2.5rem;
    height: 2.5rem;
    font-size: 1rem;
    box-shadow: var(--shadow-sm);
}

.btn-icon:hover {
    background: var(--primary-light);
    color: var(--primary-color);
    border-color: var(--primary-color);
    transform: translateY(-1px);
}

/* ========== FORMS ========== */
.form-group {
    margin-bottom: 1.5rem;
}

.form-group label {
    display: block;
    margin-bottom: 0.5rem;
    font-weight: 600;
    color: var(--text-primary);
}

.form-group input,
.form-group select,
.form-group textarea {
    width: 100%;
    padding: 0.75rem;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    font-size: 1rem;
    transition: border-color 0.2s ease;
    background: var(--surface-color);
    color: var(--text-primary);
    min-height: 44px;
    box-sizing: border-box;
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

.field-error {
    color: var(--error-color);
    font-size: 0.875rem;
    margin-top: 0.25rem;
    display: none;
}

.field-error:not(:empty) {
    display: block;
}

/* Enhanced error type styling with visual indicators */
.field-error.error-user-not-found {
    background-color: #fff3cd;
    border: 1px solid #ffeaa7;
    border-left: 4px solid #fdcb6e;
    padding: 0.75rem;
    border-radius: 0.375rem;
    color: #856404;
    font-weight: 500;
}

.field-error.error-subscription {
    background-color: #f8d7da;
    border: 1px solid #f5c6cb;
    border-left: 4px solid #dc3545;
    padding: 0.75rem;
    border-radius: 0.375rem;
    color: #721c24;
    font-weight: 500;
}

.field-error.error-network {
    background-color: #d1ecf1;
    border: 1px solid #bee5eb;
    border-left: 4px solid #17a2b8;
    padding: 0.75rem;
    border-radius: 0.375rem;
    color: #0c5460;
    font-weight: 500;
}

/* Default enhanced field error styling */
.field-error {
    color: var(--error-color);
    font-size: 0.875rem;
    margin-top: 0.25rem;
    display: none;
    line-height: 1.4;
    transition: all 0.2s ease-in-out;
}

/* Override for enhanced error messages with better spacing */
.field-error:not(.error-user-not-found):not(.error-subscription):not(.error-network) {
    padding: 0.5rem 0;
}

.form-actions {
    display: flex;
    gap: 1rem;
    justify-content: flex-end;
    margin-top: 2rem;
    padding-top: 1.5rem;
    border-top: 1px solid var(--border-color);
}

/* ========== MODALS ========== */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    padding: 1rem;
    box-sizing: border-box;
    overflow-y: auto;
}

.modal-content {
    background: var(--bg-primary);
    border-radius: 12px;
    box-shadow: var(--shadow-lg);
    width: 95%;
    max-width: min(800px, 95vw);
    max-height: min(75vh, 700px);
    overflow: hidden;
    position: relative;
    margin: 2.5vh auto;
    display: flex;
    flex-direction: column;
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--space-4);
    border-bottom: 1px solid var(--border-color);
    flex-shrink: 0;
}

.modal-header h2 {
    margin: 0;
    color: var(--text-primary);
}

.modal-close {
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    padding: var(--space-2);
    border-radius: 4px;
    transition: all 0.2s;
    font-size: 1.5rem;
}

.modal-close:hover {
    color: var(--text-primary);
    background-color: var(--hover-color);
}

.modal-body {
    padding: var(--space-6);
    overflow-y: auto;
    overflow-x: hidden;
    flex: 1;
    min-height: 0;
    scroll-behavior: smooth;
    -webkit-overflow-scrolling: touch;
}

/* Username Management Modal */
.username-management {
    padding: var(--space-4) 0;
}

.input-group {
    display: flex;
    gap: var(--space-2);
    align-items: center;
}

.input-group input {
    flex: 1;
}

.current-usernames {
    margin-top: var(--space-4);
}

.current-usernames h4 {
    margin-bottom: var(--space-3);
    color: var(--text-primary);
    font-size: 0.9rem;
    font-weight: 600;
}

.usernames-list {
    max-height: 300px;
    overflow-y: auto;
    border-radius: 6px;
    padding: var(--space-2);
    background: var(--bg-primary);
}

.username-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--space-2) var(--space-3);
    margin: var(--space-1) 0;
    background: var(--bg-primary);
    border-radius: 4px;
}

.username-item .username {
    font-weight: 500;
    color: var(--text-primary);
    flex: 1;
}

.remove-username-btn {
    background: var(--error-color);
    color: white;
    border: none;
    padding: var(--space-1) var(--space-2);
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.75rem;
    transition: all 0.2s ease;
    white-space: nowrap;
}

.remove-username-btn:hover {
    background: #c82333;
}

.empty-usernames {
    text-align: center;
    color: var(--text-secondary);
    padding: var(--space-5);
    font-style: italic;
}

/* ========== SIDEBAR ========== */
.sidebar {
    background: var(--bg-primary);
    border-right: 1px solid var(--border-color);
    padding: var(--space-4);
    max-height: calc(100vh - 220px);
    height: calc(100vh - 220px);
    overflow-y: auto;
}

.sidebar-section {
    margin-bottom: var(--space-6);
}

.sidebar-section h3 {
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.025em;
    margin-bottom: var(--space-4);
}

/* Search */
.search-container {
    position: relative;
    margin-bottom: var(--space-4);
}

.search-input {
    width: 100%;
    padding: var(--space-2) var(--space-4);
    padding-right: 4.5rem;
    border: 2px solid var(--primary-color);
    border-radius: 6px;
    font-size: 0.875rem;
    background: var(--bg-secondary);
    transition: all 0.2s ease;
}

.search-input:focus {
    outline: none;
    border-color: var(--primary-color);
    background: var(--bg-primary);
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

.search-icon {
    position: absolute;
    right: var(--space-2);
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-secondary);
    pointer-events: none;
}

.search-clear {
    position: absolute;
    right: 2.5rem;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-secondary);
    cursor: pointer;
    padding: 2px;
    display: none;
    transition: color 0.2s ease;
}

.search-clear:hover {
    color: var(--text-primary);
}

.search-clear.visible {
    display: block;
}

/* Filter Controls */
.filter-controls {
    margin-bottom: var(--space-4);
}

.filter-title {
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: var(--space-2);
    display: flex;
    align-items: center;
    gap: var(--space-2);
}

.filter-options {
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
}

.checkbox-item {
    display: flex;
    align-items: center; /* Changed from baseline to center for better radio button alignment */
    gap: 0.5rem; /* Increased from 0.375rem for better spacing with radio buttons */
    padding: 0.5rem; /* Increased padding to match radio-item */
    cursor: pointer;
    border-radius: 4px;
    transition: background-color 0.2s ease;
}

.checkbox-item:hover {
    background: var(--hover-color);
}

.checkbox-item input[type="checkbox"] {
    width: 1rem; /* Increased to match radio buttons */
    height: 1rem; /* Increased to match radio buttons */
    margin: 0;
    accent-color: var(--primary-color);
    cursor: pointer;
    flex-shrink: 0;
}

.checkbox-item span {
    line-height: 1.4; /* Improved line height to match radio items */
    font-size: 0.95rem; /* Slightly larger to match radio items */
}

/* Stats Grid */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
    margin-top: 8px;
}

.stat-item {
    text-align: center;
    padding: 8px 4px;
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: 4px;
    transition: all 0.2s ease;
}

.stat-item:hover {
    background: var(--primary-light);
    border-color: var(--primary-color);
    transform: translateY(-1px);
}

/* Distribution Lists */
.distribution-lists {
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
}

.distribution-list-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--space-2) var(--space-4);
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s ease;
    color: var(--text-primary);
    text-decoration: none;
    border: 1px solid transparent;
}

.distribution-list-item:hover {
    background: var(--hover-color);
    border-color: var(--border-color);
}

.distribution-list-item.active {
    background: var(--primary-light);
    border-color: var(--primary-color);
    color: var(--primary-color);
}

.distribution-list-name {
    font-weight: 500;
    font-size: 0.875rem;
}

.distribution-list-count {
    background: var(--text-secondary);
    color: white;
    font-size: 0.75rem;
    font-weight: 600;
    padding: 0.125rem 0.375rem;
    border-radius: 12px;
    min-width: 1.25rem;
    text-align: center;
}

.distribution-list-item.active .distribution-list-count {
    background: var(--primary-color);
}

/* Distribution List User Display */
.distribution-list-users {
    font-size: 0.85em;
    color: var(--text-secondary);
    margin-top: var(--space-1);
}

.user-count {
    display: none; /* Hidden since count is already shown in .distribution-list-count */
}

.distribution-list-actions {
    display: flex;
    align-items: center;
    gap: var(--space-2);
}

.manage-list-btn, .delete-list-btn {
    background: none;
    border: none;
    color: var(--primary-color);
    cursor: pointer;
    font-size: 0.75rem;
    padding: var(--space-1);
    border-radius: 4px;
    transition: all 0.2s ease;
}

.manage-list-btn:hover, .delete-list-btn:hover {
    background: var(--hover-color);
}

.delete-list-btn {
    color: var(--error-color);
}

/* ========== CONTACT LIST PANEL ========== */
.contact-list-panel {
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    max-height: calc(100vh - 220px);
    height: calc(100vh - 220px);
}

.panel-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: var(--space-4);
    border-bottom: 1px solid var(--border-color);
    background: var(--bg-secondary);
}

.panel-header h2 {
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--text-primary);
}

.view-controls {
    display: flex;
    align-items: center;
    gap: var(--space-2);
}

.view-controls .btn {
    padding: var(--space-2);
    font-size: 0.875rem;
}

.view-controls .btn.active {
    background: var(--primary-color);
    color: white;
}

/* Bulk Actions Toolbar */
.bulk-actions-toolbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: var(--space-3) var(--space-4);
    background: var(--primary-light);
    border-bottom: 1px solid var(--primary-color);
    animation: slideDown 0.2s ease-out;
}

.bulk-actions-toolbar.hidden {
    display: none;
}

@keyframes slideDown {
    from {
        opacity: 0;
        transform: translateY(-10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.bulk-selection-info {
    display: flex;
    align-items: center;
    gap: var(--space-2);
}

.bulk-selection-info .checkbox-item {
    margin: 0;
    font-weight: 600;
    color: var(--primary-dark);
}

.bulk-actions {
    display: flex;
    align-items: center;
    gap: var(--space-2);
}

/* Contact Card Checkbox */
.contact-card {
    position: relative;
}

.contact-card-checkbox {
    position: absolute;
    top: var(--space-2);
    left: var(--space-2);
    width: 20px;
    height: 20px;
    cursor: pointer;
    z-index: 10;
    accent-color: var(--primary-color);
}

.contact-card.bulk-select-mode {
    padding-left: var(--space-8);
}

.contact-card.selected {
    background: var(--primary-light);
    border-color: var(--primary-color);
}

.contact-list {
    overflow-y: auto;
    flex: 1;
    min-height: 0;
    scrollbar-width: thin;
    scrollbar-color: var(--border-color) var(--bg-secondary);
}

.contact-list::-webkit-scrollbar {
    width: 8px;
}

.contact-list::-webkit-scrollbar-track {
    background: var(--bg-secondary);
    border-radius: 4px;
}

.contact-list::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 4px;
    transition: background-color 0.2s ease;
}

.contact-list::-webkit-scrollbar-thumb:hover {
    background: var(--text-secondary);
}

/* Card View */
.contact-list.card-view {
    display: flex;
    flex-direction: column;
    gap: 4px;
    padding: 8px;
    overflow-y: auto;
    flex: 1;
    min-height: 0;
}

.contact-card {
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 8px;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: flex-start;
    gap: 8px;
    margin: 0;
    min-height: auto;
    flex-shrink: 0;
}

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

.contact-card.selected {
    border-color: var(--primary-color);
    box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.2);
    background: var(--primary-light);
}

.contact-card[data-archived="true"] {
    opacity: 0.7;
    background: linear-gradient(135deg, var(--bg-primary) 0%, #f5f5f5 100%);
    border-left: 4px solid var(--warning-color);
}

/* List View */
.contact-list.list-view {
    display: flex;
    flex-direction: column;
    gap: 0;
    padding: 0;
    overflow-y: auto;
    flex: 1;
    min-height: 0;
}

.contact-list.list-view .contact-list-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--space-2) var(--space-4);
    height: 36px;
    border-bottom: 1px solid var(--border-color);
    cursor: pointer;
    transition: background-color 0.2s ease;
    background: var(--bg-primary);
    font-size: 0.875rem;
}

.contact-list.list-view .contact-list-item:hover {
    background: var(--hover-color);
}

.contact-list.list-view .contact-list-item.selected {
    background: var(--primary-light);
    border-left: 3px solid var(--primary-color);
    padding-left: calc(var(--space-4) - 3px);
}

.contact-list.list-view .contact-list-item .contact-name {
    flex: 1;
    font-size: 0.875rem;
    font-weight: 500;
    color: #000000;
    margin: 0;
    padding: calc(0.875rem * 0.2);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    line-height: 1.2;
}

/* Hide elements based on view mode */
.contact-list-item {
    display: none;
}

.contact-list.list-view .contact-card {
    display: none;
}

.contact-list.card-view .contact-list-item {
    display: none;
}

.contact-list.list-view .contact-list-item {
    display: flex;
}

/* Contact Avatar */
.contact-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--primary-color) 0%, var(--primary-dark) 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.contact-avatar .avatar-initial {
    color: white;
    font-weight: 600;
    font-size: 0.875rem;
    line-height: 1;
}

.contact-avatar-large {
    width: 80px;
    height: 80px;
    border-radius: 50%;
    background: var(--primary-color);
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto var(--space-4);
}

.contact-avatar-large .avatar-initial {
    font-size: 2rem;
    font-weight: 600;
    color: white;
}

/* Avatar Types */
/* Owned contacts - Blue (default, keep current styling) */
.contact-avatar.avatar-owned {
    background: linear-gradient(135deg, var(--primary-color) 0%, var(--primary-dark) 100%);
}

.contact-avatar-large.avatar-owned {
    background: var(--primary-color);
}

/* Shared contacts - Green */
.contact-avatar.avatar-shared {
    background: linear-gradient(135deg, var(--success-color) 0%, #059669 100%);
}

.contact-avatar-large.avatar-shared {
    background: var(--success-color);
}

/* Imported contacts - Orange/Yellow */
.contact-avatar.avatar-imported {
    background: linear-gradient(135deg, var(--warning-color) 0%, #d97706 100%);
}

.contact-avatar-large.avatar-imported {
    background: var(--warning-color);
}

/* Contact Info */
.contact-info {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 3px;
}

.contact-info .contact-name {
    font-weight: 600;
    font-size: 0.95rem;
    color: var(--text-primary);
    margin: 0;
    line-height: 1.2;
    padding-top: calc(0.95rem * 0.2);
    padding-bottom: calc(0.95rem * 0.2);
}

.contact-info .contact-card-name {
    font-weight: 500;
    font-size: 0.825rem;
    color: var(--primary-color);
    margin: 0;
    font-style: italic;
    line-height: 1.2;
}

.contact-info .contact-details {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.contact-info .contact-phone,
.contact-info .contact-email {
    display: flex;
    align-items: center;
    gap: 6px;
    color: var(--text-secondary);
    font-size: 0.825rem;
    line-height: 1.2;
}

.contact-info .contact-phone i,
.contact-info .contact-email i {
    width: 11px;
    text-align: center;
    color: var(--primary-color);
    font-size: 0.75rem;
    opacity: 0.7;
}

.contact-info .contact-meta {
    margin-top: 3px;
}

/* Shared Indicators */
.shared-indicator {
    background: transparent;
    color: #007bff;
    padding: 2px 6px;
    border-radius: 12px;
    font-size: 0.75rem;
    font-weight: 500;
    white-space: nowrap;
}

.tag-shared-out {
    background: transparent;
    color: #007bff;
}

.tag-shared {
    background: var(--primary-color);
    color: white;
}

/* ========== CONTACT DETAIL PANEL ========== */
.contact-detail-panel {
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    max-height: calc(100vh - 220px);
    height: calc(100vh - 220px);
}

.contact-detail-panel .detail-content {
    height: 100%;
    overflow-y: auto;
}

/* Welcome State */
.welcome-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: var(--space-8);
    text-align: center;
    height: 100%;
    min-height: 400px;
}

.welcome-state i {
    font-size: 3rem;
    color: var(--text-secondary);
    margin-bottom: var(--space-4);
}

.welcome-state h3 {
    font-size: 1.5rem;
    margin-bottom: var(--space-2);
    color: var(--text-primary);
}

.welcome-state p {
    color: var(--text-secondary);
    margin-bottom: var(--space-6);
    max-width: 300px;
    line-height: 1.6;
}

/* Contact Detail Header */
.contact-detail-header {
    padding: var(--space-6);
    border-bottom: 1px solid var(--border-color);
    background: var(--bg-secondary);
}

.contact-detail-header .contact-info {
    text-align: center;
    margin-bottom: var(--space-4);
}

.contact-detail-header .contact-name {
    font-size: 1.5rem;
    font-weight: 600;
    margin-bottom: var(--space-2);
    color: var(--text-primary);
}

.contact-detail-header .contact-organization,
.contact-detail-header .contact-title {
    color: var(--text-secondary);
    margin-bottom: var(--space-1);
    font-size: 0.95rem;
}

/* Contact Detail Actions */
.contact-detail-actions {
    display: flex;
    gap: var(--space-2);
    justify-content: center;
    flex-wrap: wrap;
    margin-top: var(--space-4);
    padding-top: var(--space-4);
    border-top: 1px solid var(--border-color);
}

.contact-detail-actions .btn-icon {
    width: 40px;
    height: 40px;
    border-radius: 8px;
    font-size: 16px;
}

/* Action button colors */
.contact-detail-actions .btn-icon.edit-contact {
    color: var(--primary-color);
}

.contact-detail-actions .btn-icon.edit-contact:hover {
    background: var(--primary-color);
    color: white;
}

.contact-detail-actions .btn-icon.share-contact {
    color: #10b981;
}

.contact-detail-actions .btn-icon.share-contact:hover {
    background: #10b981;
    color: white;
}

.contact-detail-actions .btn-icon.delete-contact {
    color: #ef4444;
}

.contact-detail-actions .btn-icon.delete-contact:hover {
    background: #ef4444;
    color: white;
}

.contact-detail-actions .btn-icon.export-contact {
    color: #8b5cf6;
}

.contact-detail-actions .btn-icon.export-contact:hover {
    background: #8b5cf6;
    color: white;
}

.contact-detail-actions .btn-icon.restore-contact {
    color: var(--warning-color);
}

.contact-detail-actions .btn-icon.restore-contact:hover {
    background: var(--warning-color);
    color: white;
}

.contact-detail-actions .btn-icon.archive-contact {
    color: #6b7280;
}

.contact-detail-actions .btn-icon.archive-contact:hover {
    background: #6b7280;
    color: white;
}

/* Contact Detail Body */
.contact-detail-body {
    padding: var(--space-6);
    flex: 1;
}

.field-group {
    margin-bottom: var(--space-6);
}

.field-group:last-child {
    margin-bottom: 0;
}

.field-group h4 {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: var(--space-4);
    padding-bottom: var(--space-2);
    border-bottom: 1px solid var(--border-color);
}

.field-group h4 i {
    color: var(--primary-color);
    font-size: 1.1rem;
    width: 20px;
    text-align: center;
}

.field-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-2);
    padding: var(--space-3);
    margin-bottom: var(--space-2);
    background: var(--bg-secondary);
    border-radius: 6px;
    transition: background-color 0.2s ease;
}

.field-item:last-child {
    margin-bottom: 0;
}

.field-item:hover {
    background: var(--hover-color);
}

.field-value {
    flex: 1;
    color: var(--text-primary);
    font-weight: 500;
    word-break: break-word;
    font-size: 0.95rem;
}

.field-value a {
    color: var(--primary-color);
    text-decoration: none;
    transition: color 0.2s ease;
}

.field-value a:hover {
    color: var(--primary-dark);
    text-decoration: underline;
}

.field-type {
    font-size: 0.8rem;
    color: var(--text-secondary);
    text-transform: uppercase;
    font-weight: 600;
    letter-spacing: 0.025em;
    background: var(--bg-primary);
    padding: 0.25rem 0.5rem;
    border-radius: 4px;
    border: 1px solid var(--border-color);
}

.field-primary {
    font-size: 0.75rem;
    color: var(--primary-color);
    background: var(--primary-light);
    padding: 0.25rem 0.5rem;
    border-radius: 4px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.025em;
}

/* Field metadata container */
.field-meta {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    flex-shrink: 0;
}

/* Address Fields */
.address-display {
    background: var(--bg-secondary);
    border-radius: 6px;
    padding: var(--space-3);
    margin-bottom: var(--space-2);
    border-left: 3px solid var(--primary-color);
}

.address-display:last-child {
    margin-bottom: 0;
}

.address-lines {
    color: var(--text-primary);
    line-height: 1.5;
}

.address-lines .address-line {
    margin-bottom: 0.25rem;
}

.address-lines .address-line:last-child {
    margin-bottom: 0;
}

/* QR Code Section */
.qr-code-section {
    margin-top: var(--space-6);
    padding-top: var(--space-4);
    border-top: 1px solid var(--border-color);
}

.qr-code-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: var(--space-4);
    background: var(--bg-primary);
    border-radius: 8px;
}

.qr-code-wrapper {
    display: flex;
    justify-content: center;
    align-items: center;
    padding: var(--space-4);
    background: white;
    border-radius: 8px;
    border: 1px solid var(--border-color);
    margin-bottom: var(--space-3);
    max-width: 280px;
    width: 100%;
}

/* Support both SVG and IMG formats for QR codes */
.qr-code-wrapper svg,
.qr-code-wrapper img,
.qr-code-wrapper .qr-code-image {
    width: 100%;
    height: auto;
    display: block;
    /* Enable iOS tap-and-hold QR detection */
    -webkit-touch-callout: default;
    user-select: auto;
}

.qr-help-text {
    text-align: center;
    color: var(--text-secondary);
    font-size: 0.875rem;
    margin: 0;
    display: flex;
    align-items: center;
    gap: var(--space-2);
    justify-content: center;
}

.qr-help-text i {
    color: var(--primary-color);
}

.qr-error {
    color: var(--error-color);
    text-align: center;
    padding: var(--space-3);
    font-size: 0.875rem;
}

/* Metadata Section */
.metadata-section {
    border-top: 1px solid var(--border-color);
    padding-top: var(--space-4);
    margin-top: var(--space-6);
}

.metadata-section h4 {
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.025em;
    margin-bottom: var(--space-3);
}

.metadata-item {
    display: flex;
    justify-content: space-between;
    padding: var(--space-2) 0;
    border-bottom: 1px solid var(--border-color);
    font-size: 0.875rem;
}

.metadata-item:last-child {
    border-bottom: none;
}

.metadata-label {
    color: var(--text-secondary);
    font-weight: 500;
}

.metadata-value {
    color: var(--text-primary);
    font-weight: 400;
}

/* Sharing Information Styles */
.metadata-sharing {
    flex-direction: column;
    align-items: flex-start;
    gap: var(--space-2);
}

.metadata-sharing .metadata-label {
    display: flex;
    align-items: center;
    gap: var(--space-1);
    margin-bottom: var(--space-2);
}

.metadata-sharing .metadata-label i {
    color: var(--primary-color);
}

.shared-users-list {
    width: 100%;
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
}

.shared-user-item {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    padding: var(--space-2);
    transition: background-color 0.2s ease;
    display: flex;
    flex-direction: column;
    gap: var(--space-1);
}

.shared-user-item:hover {
    background: var(--hover-color);
}

.shared-user-main {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    justify-content: space-between;
}

.shared-username {
    font-weight: 500;
    color: var(--text-primary);
    flex: 1;
    min-width: 120px;
}

.shared-permission {
    font-size: 0.75rem;
    background: var(--primary-color);
    color: white;
    padding: 0.125rem 0.375rem;
    border-radius: 0.25rem;
    text-transform: uppercase;
    letter-spacing: 0.025em;
    white-space: nowrap;
    flex-shrink: 0;
}

.shared-date {
    font-size: 0.75rem;
    color: var(--text-secondary);
    margin-left: var(--space-1);
    padding-left: var(--space-1);
    border-left: 1px solid var(--border-color);
}

/* Revoke Button Styles */
.btn-revoke {
    background: #dc3545;
    color: white;
    border: none;
    padding: 0.375rem 0.75rem;
    border-radius: var(--radius);
    font-size: 0.75rem;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    gap: 0.25rem;
    white-space: nowrap;
}

.btn-revoke:hover {
    background: #c82333;
    transform: translateY(-1px);
    box-shadow: 0 2px 4px rgba(220, 53, 69, 0.3);
}

.btn-revoke:active {
    transform: translateY(0);
    box-shadow: none;
}

.btn-revoke i {
    font-size: 0.625rem;
}

.share-summary {
    margin-top: var(--space-2);
    padding-top: var(--space-2);
    border-top: 1px solid var(--border-color);
    font-size: 0.75rem;
    color: var(--text-secondary);
    text-align: center;
}

/* Mobile Responsive Sharing Styles */
@media (max-width: 768px) {
    .shared-user-item {
        gap: var(--space-1);
        padding: var(--space-1) var(--space-2);
    }
    
    .shared-user-main {
        /* Keep horizontal layout but adjust spacing */
        gap: var(--space-1);
    }
    
    .shared-username {
        min-width: 80px;
        font-size: 0.9rem;
        flex: 1;
    }
    
    .shared-permission {
        font-size: 0.65rem;
        padding: 0.1rem 0.25rem;
    }
    
    .btn-revoke {
        font-size: 0.7rem;
        padding: 0.25rem 0.5rem;
        min-height: 32px; /* Touch-friendly minimum */
    }
    
    .metadata-sharing .metadata-label {
        font-size: 0.8rem;
    }
}

/* Extra small screens - even more compact but still horizontal */
@media (max-width: 480px) {
    .shared-user-main {
        gap: 0.25rem;
    }
    
    .shared-username {
        min-width: 60px;
        font-size: 0.85rem;
    }
    
    .shared-permission {
        font-size: 0.6rem;
        padding: 0.05rem 0.2rem;
    }
    
    .btn-revoke {
        font-size: 0.65rem;
        padding: 0.2rem 0.4rem;
    }
    
    .shared-date {
        font-size: 0.65rem;
        margin-left: 0.25rem;
        padding-left: 0.25rem;
    }
}

/* ========== FORMS & INPUT COMPONENTS ========== */

/* Radio Button Groups */
.radio-group {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.radio-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    cursor: pointer;
    padding: 0.5rem;
    border-radius: 0.375rem;
    transition: background-color 0.2s ease;
}

.radio-item:hover {
    background-color: var(--hover-color);
}

.radio-item input[type="radio"] {
    margin: 0;
    width: 1rem;
    height: 1rem;
    accent-color: var(--primary-color);
}

.radio-item span {
    font-size: 0.95rem;
    line-height: 1.4;
}

.radio-item .help-text {
    font-size: 0.8rem;
    color: var(--text-secondary);
    margin-top: 0.25rem;
    margin-left: 1.5rem;
    display: block;
}

/* Multi-field Forms */
.multi-field-container {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    margin-bottom: 0.5rem;
}

.multi-field-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.75rem;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 0.5rem;
    transition: border-color 0.2s ease;
}

.multi-field-item:hover {
    border-color: var(--primary-color);
}

.multi-field-item:focus-within {
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

.field-type-select {
    min-width: 80px;
    max-width: 100px;
    padding: 0.5rem;
    border: 1px solid var(--border-color);
    border-radius: 0.375rem;
    background: var(--bg-primary);
    font-size: 0.875rem;
    color: var(--text-primary);
}

.field-type-select:focus {
    outline: none;
    border-color: var(--primary-color);
}

.multi-field-item input[type="tel"],
.multi-field-item input[type="email"],
.multi-field-item input[type="url"] {
    flex: 1;
    padding: 0.5rem;
    border: 1px solid var(--border-color);
    border-radius: 0.375rem;
    font-size: 0.875rem;
    background: var(--bg-primary);
}

.multi-field-item input:focus {
    outline: none;
    border-color: var(--primary-color);
}

.primary-checkbox {
    display: flex;
    align-items: center; /* Changed from baseline to center for better alignment */
    gap: 0.5rem; /* Increased from 0.375rem for better spacing */
    font-size: 0.875rem; /* Slightly larger font */
    color: var(--text-secondary);
    cursor: pointer;
    white-space: nowrap;
}

.primary-checkbox input[type="checkbox"] {
    width: 1rem; /* Increased to be consistent with other checkboxes */
    height: 1rem; /* Increased to be consistent with other checkboxes */
    margin: 0;
    accent-color: var(--primary-color);
    cursor: pointer;
}

.remove-field-btn {
    background: none;
    border: none;
    color: var(--error-color);
    cursor: pointer;
    padding: 0.25rem;
    border-radius: 0.25rem;
    transition: background-color 0.2s ease;
    font-size: 0.875rem;
}

.remove-field-btn:hover {
    background-color: rgba(239, 68, 68, 0.1);
}

.add-field-btn {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 1rem;
    background: none;
    border: 2px dashed var(--border-color);
    border-radius: 0.5rem;
    color: var(--text-secondary);
    cursor: pointer;
    font-size: 0.875rem;
    transition: all 0.2s ease;
}

.add-field-btn:hover {
    border-color: var(--primary-color);
    color: var(--primary-color);
    background-color: rgba(59, 130, 246, 0.05);
}

/* Info Box */
.info-box {
    display: flex;
    align-items: flex-start;
    gap: var(--space-2);
    padding: var(--space-4);
    background: var(--primary-light);
    border: 1px solid rgba(59, 130, 246, 0.2);
    border-radius: 8px;
    margin-bottom: var(--space-4);
}

.info-box i {
    color: var(--primary-color);
    margin-top: 2px;
    flex-shrink: 0;
}

.info-box p {
    margin: 0;
    font-size: 0.875rem;
    color: var(--text-secondary);
    line-height: 1.5;
}

/* Export Preview */
.export-preview {
    background: var(--bg-secondary);
    padding: 1rem;
    border-radius: 0.5rem;
    border: 1px solid var(--border-color);
    margin-top: 1rem;
}

.export-preview h4 {
    color: var(--text-primary);
    margin-bottom: 0.5rem;
    font-size: 0.9rem;
    font-weight: 600;
}

.export-count {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.count-number {
    font-weight: 700;
    color: var(--primary-color);
    font-size: 1.1rem;
}

/* Help Text */
.help-text {
    font-size: 0.8rem;
    color: var(--text-secondary);
    margin-top: 0.25rem;
    display: block;
    line-height: 1.3;
}

/* Format Badges for Export */
.format-badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 12px;
    font-size: 12px;
    font-weight: 500;
    margin-left: 8px;
}

.format-badge.standard {
    background-color: #10b981;
    color: white;
}

.format-badge.apple {
    background-color: #007AFF;
    color: white;
}

/* Field Error */
.field-error {
    color: var(--error-color);
    font-size: 0.875rem;
    margin-top: 0.25rem;
    display: none;
}

.field-error:not(:empty) {
    display: block;
}
.share-form {
    display: flex;
    flex-direction: column;
    gap: var(--space-4);
}

/* Input groups for buttons next to inputs */
.input-group {
    display: flex;
    gap: 8px;
    align-items: stretch;
}

.input-group input {
    flex: 1;
    border-radius: 4px 0 0 4px;
}

.input-group .btn {
    border-radius: 0 4px 4px 0;
    white-space: nowrap;
    padding: 8px 12px;
    font-size: 0.9em;
}

/* Field help text */
.field-help {
    color: var(--text-secondary);
    font-size: 0.85em;
    margin-top: 4px;
    display: block;
}

/* Verification status */
.verification-status {
    margin-top: 8px;
    padding: 8px 12px;
    border-radius: 4px;
    font-size: 0.9em;
    display: flex;
    align-items: flex-start;
    gap: 8px;
    word-break: break-word;
}

.verification-status span {
    flex: 1;
}

.verification-status code {
    background: #f0f0f0;
    padding: 4px 8px;
    border-radius: 4px;
    font-family: monospace;
    word-break: break-all;
    display: inline-block;
    margin: 4px 0;
}

.verification-status.success {
    background-color: #d4edda;
    color: #155724;
    border: 1px solid #c3e6cb;
}

.verification-status.error {
    background-color: #f8d7da;
    color: #721c24;
    border: 1px solid #f5c6cb;
}

.verification-status.loading {
    background-color: #d1ecf1;
    color: #0c5460;
    border: 1px solid #bee5eb;
}

.contact-preview {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: var(--space-4);
    margin-bottom: var(--space-4);
}

.contact-preview h3 {
    margin-bottom: var(--space-2);
    color: var(--text-secondary);
    font-size: 0.875rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.025em;
}

.share-type-tabs {
    display: flex;
    gap: 8px;
    margin-bottom: 20px;
}

.share-type-tab {
    flex: 1;
    padding: 12px 16px;
    border: 2px solid #dee2e6;
    background: #f8f9fa;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    font-weight: 500;
}

.share-type-tab:hover {
    border-color: var(--primary-color);
    background: #e3f2fd;
}

.share-type-tab.active {
    border-color: var(--primary-color);
    background: var(--primary-color);
    color: white;
}

.share-section {
    display: none;
}

.share-section.active {
    display: block;
}

/* ========== LOADING & UTILITY ========== */
.loading-spinner {
    width: 40px;
    height: 40px;
    border: 4px solid var(--border-color);
    border-top: 4px solid var(--primary-color);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

.loading-container,
.success-container,
.error-container,
.warning-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: var(--space-8);
    text-align: center;
}

.success-icon {
    width: 60px;
    height: 60px;
    background: var(--success-color);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: var(--space-4);
}

.success-icon i {
    color: white;
    font-size: 24px;
}

.error-icon {
    width: 60px;
    height: 60px;
    background: var(--error-color);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: var(--space-4);
}

.error-icon i {
    color: white;
    font-size: 24px;
}

.warning-icon {
    width: 60px;
    height: 60px;
    background: var(--warning-color);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: var(--space-4);
}

.warning-icon i {
    color: white;
    font-size: 24px;
}

.share-details {
    background: var(--background-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    padding: var(--space-3);
    margin: var(--space-3) 0;
    font-family: monospace;
    font-size: 0.9em;
    white-space: pre-line;
    max-height: 150px;
    overflow-y: auto;
}

.hidden {
    display: none !important;
}

/* Mobile-only elements - hidden by default on desktop */
.mobile-only,
.mobile-header,
.mobile-back-btn,
.mobile-menu-btn,
.mobile-action-btn,
.mobile-page-title,
.mobile-header-actions {
    display: none;
}

.empty-state {
    text-align: center;
    padding: 3rem 2rem;
    color: var(--text-secondary);
}

.empty-state i {
    font-size: 3rem;
    margin-bottom: 1rem;
    opacity: 0.5;
}

.empty-state h3 {
    margin: 0 0 0.5rem 0;
    color: var(--text-primary);
}

.empty-state p {
    margin: 0;
    font-size: 0.9rem;
}

/* ========== AUTHENTICATION ========== */
#auth-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    display: none; /* Hidden by default - only show when needed */
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.auth-modal-content {
    background: var(--bg-primary);
    padding: var(--space-8);
    border-radius: 12px;
    box-shadow: var(--shadow-lg);
    width: 100%;
    max-width: 400px;
    position: relative;
}

.auth-welcome {
    text-align: center;
    margin-bottom: 1rem;
    padding: 0.75rem;
    background-color: #f8fafc;
    color: #374151;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
}

.auth-welcome h3 {
    font-size: 1.25rem;
    font-weight: 600;
    margin: 0 0 0.5rem 0;
    color: #1f2937;
}

.auth-welcome p {
    font-size: 0.875rem;
    margin: 0;
    color: #6b7280;
    line-height: 1.4;
}

#keep-signed-in-group .checkbox-item {
    padding: 0.125rem 0;
    background: transparent;
    gap: 0.5rem;
    align-items: baseline;
}

#keep-signed-in-group .checkbox-item input[type="checkbox"] {
    width: 0.875rem !important;
    height: 0.875rem !important;
    min-height: auto !important;
    padding: 0 !important;
    position: relative;
    top: 0.1rem;
}

#keep-signed-in-group .checkbox-item span {
    font-size: 0.9rem;
    color: var(--text-primary);
}

/* ========== FOOTER ========== */
.app-footer {
    text-align: center;
    padding: 8px 0;
    margin-top: 16px;
    font-size: 0.875rem;
    color: #6b7280;
    background: #f9fafb;
    border-top: 1px solid #e5e7eb;
    position: relative;
    z-index: 1;
}

.app-footer a {
    color: #6b7280;
    text-decoration: underline;
    transition: color 0.2s ease;
}

.app-footer a:hover {
    color: var(--primary-color);
}

/* ========== RESPONSIVE DESIGN ========== */

/* Tablet (1200px and below) */
@media (max-width: 1200px) {
    .main-content {
        grid-template-columns: 260px 1fr 350px;
    }
}

/* Small tablets (1024px and below) */
@media (max-width: 1024px) {
    .main-content {
        grid-template-columns: 240px 1fr 320px;
    }
    
    .contact-detail-header {
        padding: var(--space-4);
    }
    
    .contact-detail-body {
        padding: var(--space-4);
    }
    
    .field-group {
        margin-bottom: var(--space-4);
    }

    .contact-list-panel {
        max-height: calc(100vh - 200px);
        height: calc(100vh - 200px);
    }
}

/* Mobile (768px and below) */
@media (max-width: 768px) {
    .main-content {
        display: block;
        gap: var(--space-4);
    }
    
    .sidebar,
    .contact-list-panel,
    .contact-detail-panel {
        margin-bottom: var(--space-4);
        max-height: 50vh;
        height: auto;
    }
    
    .header-right {
        flex-wrap: wrap;
        gap: 0.25rem;
    }
    
    .btn {
        padding: 0.5rem 1rem;
        font-size: 0.875rem;
    }
    
    /* Contact card optimizations for mobile */
    .contact-list.card-view {
        gap: 3px;
        padding: 6px;
    }
    
    .contact-card {
        padding: 6px;
        gap: 6px;
        border-radius: 6px;
    }
    
    .contact-avatar {
        width: 32px;
        height: 32px;
    }
    
    .contact-avatar .avatar-initial {
        font-size: 0.75rem;
    }
    
    .contact-list.list-view .contact-list-item {
        height: 32px;
        padding: 6px 8px;
        font-size: 0.8rem;
    }
}

/* Small mobile (480px and below) */
@media (max-width: 480px) {
    .modal-content {
        width: 100%;
        max-width: 100vw;
        margin: 0;
        max-height: 100vh;
        border-radius: 0;
        display: flex;
        flex-direction: column;
    }
    
    .modal-body {
        padding: var(--space-2);
        flex: 1;
        min-height: 0;
    }
    
    .form-group {
        margin-bottom: 1rem;
    }
    
    .field-item {
        gap: 0.375rem;
    }

    .field-type,
    .field-primary {
        font-size: 0.7rem;
        padding: 0.2rem 0.4rem;
    }

    .multi-field-item {
        padding: 0.5rem;
    }
    
    .add-field-btn {
        padding: 0.75rem;
        font-size: 0.8rem;
    }
}

/* Very small viewports - height constraint */
@media (max-height: 600px) {
    .modal-content {
        max-height: 95vh;
        margin: 2.5vh auto;
        display: flex;
        flex-direction: column;
    }
    
    .modal-body {
        padding: var(--space-4);
        flex: 1;
        min-height: 0;
    }
    
    .form-group {
        margin-bottom: 1rem;
    }
}

/* High-DPI displays */
@media (min-resolution: 2dppx), (-webkit-min-device-pixel-ratio: 2) {
    .modal-content {
        max-width: min(900px, 90vw);
    }
    
    .form-group input,
    .form-group select,
    .form-group textarea {
        font-size: 1.1rem;
        padding: 0.875rem;
    }
}

/* Modal scrollbars */
.modal-body::-webkit-scrollbar {
    width: 8px;
}

.modal-body::-webkit-scrollbar-track {
    background: var(--bg-secondary);
    border-radius: 4px;
}

.modal-body::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 4px;
}

.modal-body::-webkit-scrollbar-thumb:hover {
    background: var(--text-secondary);
}

.modal-body {
    scrollbar-width: thin;
    scrollbar-color: var(--border-color) var(--bg-secondary);
}

/* ========================================
   BAICAL CARDDAV INTEGRATION STYLES
   ======================================== */

/* Sync Status Widget */
.sync-status-widget {
    display: flex;
    align-items: center;
    gap: var(--space-2);
}

.sync-status-widget .btn {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    font-size: 0.875rem;
    position: relative;
}

#baical-sync-indicator {
    font-weight: 500;
}

#baical-sync-indicator.connected {
    color: var(--success-color);
}

#baical-sync-indicator.syncing {
    color: var(--warning-color);
    animation: pulse 2s infinite;
}

#baical-sync-indicator.error {
    color: var(--error-color);
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

/* Baical Modal Tabs */
.baical-modal-tabs {
    display: flex;
    border-bottom: 2px solid var(--border-color);
    margin-bottom: var(--space-6);
    gap: var(--space-1);
}

.baical-tab {
    background: none;
    border: none;
    padding: var(--space-4) var(--space-6);
    cursor: pointer;
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--text-secondary);
    border-bottom: 2px solid transparent;
    transition: all 0.2s ease;
}

.baical-tab:hover {
    color: var(--text-primary);
    background-color: var(--hover-color);
}

.baical-tab.active {
    color: var(--primary-color);
    border-bottom-color: var(--primary-color);
    background-color: var(--primary-light);
}

/* Tab Content */
.baical-tab-content {
    display: none;
}

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

/* Connection Form Styles */
.connection-info {
    background: var(--primary-light);
    padding: var(--space-6);
    border-radius: 8px;
    margin-bottom: var(--space-6);
    border-left: 4px solid var(--primary-color);
}

.connection-info h3 {
    color: var(--text-primary);
    margin-bottom: var(--space-2);
}

.connection-info p {
    color: var(--text-secondary);
    font-size: 0.875rem;
}

.connection-status {
    margin-top: var(--space-4);
    padding: var(--space-4);
    border-radius: 6px;
}

.status {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    padding: var(--space-4);
    border-radius: 6px;
    font-size: 0.875rem;
    font-weight: 500;
}

.status.success {
    background: #d1fae5;
    color: #065f46;
    border: 1px solid #a7f3d0;
}

.status.error {
    background: #fee2e2;
    color: #991b1b;
    border: 1px solid #fca5a5;
}

.status.info {
    background: #dbeafe;
    color: #1e40af;
    border: 1px solid #93c5fd;
}

.status.warning {
    background: #fef3c7;
    color: #92400e;
    border: 1px solid #fcd34d;
}

/* Profiles List */
.profiles-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: var(--space-6);
}

.profiles-header h3 {
    color: var(--text-primary);
    margin: 0;
}

.profiles-list {
    display: flex;
    flex-direction: column;
    gap: var(--space-4);
}

.profile-item {
    background: var(--bg-secondary);
    padding: var(--space-6);
    border-radius: 8px;
    border: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    transition: all 0.2s ease;
}

.profile-item:hover {
    box-shadow: var(--shadow-md);
    border-color: var(--primary-color);
}

.profile-info {
    flex: 1;
}

.profile-info h4 {
    color: var(--text-primary);
    font-size: 1.1rem;
    margin-bottom: var(--space-2);
}

.profile-info p {
    color: var(--text-secondary);
    font-size: 0.875rem;
    margin-bottom: var(--space-1);
}

.profile-info p:last-child {
    margin-bottom: 0;
}

.profile-status {
    font-weight: 500;
    font-size: 0.875rem;
}

.profile-actions {
    display: flex;
    gap: var(--space-2);
    flex-wrap: wrap;
}

.profile-actions .btn {
    font-size: 0.75rem;
    padding: 0.5rem 0.75rem;
    min-width: auto;
}

.no-profiles {
    text-align: center;
    padding: var(--space-8);
    color: var(--text-secondary);
}

.no-profiles p {
    margin-bottom: var(--space-2);
}

.no-profiles p:last-child {
    margin-bottom: 0;
}

/* Sync Status Styles */
.sync-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: var(--space-6);
}

.sync-header h3 {
    color: var(--text-primary);
    margin: 0;
}

.sync-overview {
    background: var(--bg-secondary);
    padding: var(--space-6);
    border-radius: 8px;
    margin-bottom: var(--space-6);
    border-left: 4px solid var(--success-color);
}

.sync-overview h4 {
    color: var(--text-primary);
    margin-bottom: var(--space-4);
}

.sync-overview p {
    color: var(--text-secondary);
    font-size: 0.875rem;
    margin-bottom: var(--space-2);
}

.sync-overview p:last-child {
    margin-bottom: 0;
}

.sync-details {
    display: flex;
    flex-direction: column;
    gap: var(--space-4);
}

.sync-item {
    background: var(--surface-color);
    padding: var(--space-4);
    border-radius: 6px;
    border: 1px solid var(--border-color);
}

.sync-item h5 {
    color: var(--text-primary);
    font-size: 1rem;
    margin-bottom: var(--space-2);
}

.sync-item p {
    color: var(--text-secondary);
    font-size: 0.875rem;
    margin-bottom: var(--space-1);
}

.sync-item p:last-child {
    margin-bottom: 0;
}

.sync-status-list {
    min-height: 200px;
}

/* Source Badge for Baical Contacts */
.source-badge {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    padding: 0.25rem 0.5rem;
    font-size: 0.75rem;
    font-weight: 500;
    border-radius: 12px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.source-badge.baical {
    background: var(--primary-color);
    color: white;
}

.source-badge.baical::before {
    content: "🔗";
    font-size: 0.625rem;
}

/* Responsive Baical Styles */
@media (max-width: 768px) {
    .baical-modal-tabs {
        flex-wrap: wrap;
        gap: 0;
    }
    
    .baical-tab {
        flex: 1;
        min-width: 0;
        padding: var(--space-3) var(--space-2);
        font-size: 0.8rem;
        text-align: center;
    }
    
    .profile-item {
        flex-direction: column;
        gap: var(--space-4);
    }
    
    .profile-actions {
        justify-content: flex-start;
        width: 100%;
    }
    
    .profile-actions .btn {
        flex: 1;
        min-width: 0;
    }
    
    .sync-header,
    .profiles-header {
        flex-direction: column;
        gap: var(--space-3);
        align-items: stretch;
    }
    
    .sync-status-widget .btn {
        font-size: 0.75rem;
        padding: 0.5rem 0.75rem;
    }
    
    #baical-sync-indicator {
        display: none;
    }
    
    .sync-status-widget .btn::after {
        content: attr(title);
    }
}

@media (max-width: 480px) {
    .connection-info {
        padding: var(--space-4);
    }
    
    .profile-item {
        padding: var(--space-4);
    }
    
    .sync-overview {
        padding: var(--space-4);
    }
    
    .baical-tab {
        padding: var(--space-2);
        font-size: 0.75rem;
    }
}

/* ===============================================
   URL Validation Styles
   =============================================== */
.url-validation {
    margin-top: 8px;
    padding: 12px;
    border-radius: 6px;
    font-size: 0.9em;
    line-height: 1.4;
    border: 1px solid;
    animation: fadeIn 0.3s ease-in;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(-5px); }
    to { opacity: 1; transform: translateY(0); }
}

.url-validation strong {
    font-weight: 600;
}

.url-validation small {
    font-size: 0.85em;
    opacity: 0.9;
}

.url-validation.url-success {
    background-color: #d4edda;
    color: #155724;
    border-color: #c3e6cb;
}

.url-validation.url-warning {
    background-color: #fff3cd;
    color: #856404;
    border-color: #ffeaa7;
}

.url-validation.url-info {
    background-color: #d1ecf1;
    color: #0c5460;
    border-color: #bee5eb;
}

.url-validation.url-error {
    background-color: #f8d7da;
    color: #721c24;
    border-color: #f5c6cb;
}

.url-guidance {
    margin-top: 6px;
    padding: 10px;
    background-color: #f8f9fa;
    border: 1px solid #e9ecef;
    border-radius: 4px;
    font-size: 0.85em;
    line-height: 1.4;
}

.url-guidance strong {
    color: #495057;
    font-weight: 600;
}