/* CRM Shared Components */

/* Main Content Containers */
.module-container {
    max-width: 1200px;
    margin: 0 auto;
}

@media (max-width: 768px) {
    .module-container {
        max-width: 100% !important;
    }
}

.module-header.content-aligned-header {
    max-width: 850px;
    margin: 0 0 1.5rem 0;
}

.theme-card {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 16px;
    max-width: 100%;
    box-sizing: border-box;
}

.theme-card-half {
    width: calc(50% - 8px);
}

@media (max-width: 768px) {
    .theme-card-half {
        width: 100% !important;
    }
}

/* CRM Card - Centralized Card Component */
.crm-card {
    background: var(--bg-secondary, #ffffff);
    padding: 24px;
    border-radius: 12px;
    border: 1px solid var(--border-color, #e5e7eb);
    box-shadow: var(--shadow-md, 0 4px 6px -1px rgba(0, 0, 0, 0.1));
    margin-bottom: 24px;
    max-width: 850px;
    margin-left: auto;
    margin-right: auto;
}

body.theme-light .crm-card,
body.theme-light .theme-card {
    background: #ffffff !important;
}

/* CRM Section within a Card */
.crm-section {
    padding: 24px 0;
    border-bottom: 1px solid var(--border-color, rgba(255, 255, 255, 0.05));
}

.crm-section:last-child {
    border-bottom: none;
}

.crm-section:first-child {
    padding-top: 0;
}

/* CRM Section Title */
.crm-section-title {
    margin: 0 0 16px 0;
    font-size: 0.95rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted, #888);
    display: inline-block;
    padding: 0.25rem 0.5rem;
    border-radius: var(--radius-sm);
    font-size: 0.85rem;
    font-weight: 500;
}

/* Theme Switch Component */
.theme-switch {
    display: inline-block;
    height: 34px;
    position: relative;
    width: 60px;
}

.theme-switch input {
    display: none;
}

.slider {
    background-color: #ccc;
    bottom: 0;
    cursor: pointer;
    left: 0;
    position: absolute;
    right: 0;
    top: 0;
    transition: .4s;
    border-radius: 34px;
    display: flex;
    align-items: center;
    justify-content: space-around;
    padding: 0 5px;
    font-size: 14px;
    color: white;
}

.slider .fa-sun {
    color: #f59e0b;
}

.slider .fa-moon {
    color: #f1f5f9;
}

.slider:before {
    background-color: white;
    bottom: 4px;
    content: "";
    height: 26px;
    left: 4px;
    position: absolute;
    transition: .4s;
    width: 26px;
    border-radius: 50%;
    z-index: 2;
}

input:checked+.slider {
    background-color: #2196F3;
}

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

.crm-section-title i {
    color: var(--primary, #6366f1);
}

/* Form Grid & Groups (Shared with Settings) */
.form-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 16px;
}

.form-group {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.form-label {
    font-size: 0.9rem;
    color: var(--text-muted, #ccc);
    font-weight: 500;
}

.form-input {
    flex: 1;
    background: var(--input-bg, rgba(0, 0, 0, 0.02));
    border: 1px solid var(--border-color, #e5e7eb);
    color: var(--text-main);
    padding: 10px 14px;
    border-radius: 8px;
    outline: none;
    transition: all 0.2s;
    font-size: 0.95rem;
}

.theme-dark .form-input {
    background: rgba(0, 0, 0, 0.2);
    border-color: rgba(255, 255, 255, 0.1);
}

/* Detail Display (Label/Value pair) */
.detail-item {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.detail-label {
    font-size: 0.85rem;
    color: var(--text-muted);
    font-weight: 500;
}

.detail-value {
    font-size: 1rem;
    color: var(--text-main);
    font-weight: 600;
}

/* Input with action button */
.input-with-btn {
    display: flex;
    gap: 8px;
    align-items: stretch;
}

.input-with-btn .form-input {
    flex: 1;
    min-width: 0;
}

.input-with-btn .save-btn {
    flex-shrink: 0;
    width: 42px;
    padding: 12px;
}

/* Subscription Items */
.subscription-list {
    display: grid;
    gap: 12px;
}

.subscription-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px;
    background: var(--bg-secondary, rgba(0, 0, 0, 0.02));
    border-radius: 8px;
    border-left: 4px solid var(--success, #10b981);
    border: 1px solid var(--border-color);
    border-left-width: 4px;
}

.theme-dark .subscription-item {
    background: rgba(255, 255, 255, 0.03);
}

/* ==========================================================================
   Shared Utilities & Components (Refactored from Modules)
   ========================================================================== */

/* Layout Utilities (Flexbox & Grid) */
.flex {
    display: flex;
}

.grid-cols-1 {
    grid-template-columns: 1fr !important;
}

.hidden {
    display: none !important;
}

.block {
    display: block;
}

.flex-between {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.flex-start {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
}

.flex-align-center {
    display: flex;
    align-items: center;
}

.flex-column {
    display: flex;
    flex-direction: column;
}

.flex-wrap {
    flex-wrap: wrap;
}

.items-center {
    align-items: center;
}

.justify-center {
    justify-content: center;
}

/* Spacing Utilities (Gap & Margin & Padding) */
.gap-xs {
    gap: 0.25rem;
}

.gap-sm {
    gap: 0.5rem;
}

.gap-md {
    gap: 0.75rem;
}

.gap-lg {
    gap: 1rem;
}

.gap-xl {
    gap: 1.5rem;
}

.gap-2xl {
    gap: 2rem;
}

.mb-xs {
    margin-bottom: 0.25rem;
}

.mb-sm {
    margin-bottom: 0.5rem;
}

.mb-md {
    margin-bottom: 0.75rem;
}

.mb-lg {
    margin-bottom: 1rem;
}

.mb-xl {
    margin-bottom: 1.5rem;
}

.mb-2xl {
    margin-bottom: 2rem;
}

.mt-md {
    margin-top: 0.75rem;
}

.mt-lg {
    margin-top: 1rem;
}

.mt-xl {
    margin-top: 1.5rem;
}

.mr-sm {
    margin-right: 0.5rem;
}

.pl-0 {
    padding-left: 0 !important;
}

/* Text Utilities */
.text-muted {
    color: var(--text-muted);
}

.text-small {
    font-size: 0.85rem;
}

.text-xs {
    font-size: 0.75rem;
}

.text-semibold {
    font-weight: 500;
}

.text-bold {
    font-weight: 600;
}

.text-center {
    text-align: center;
}

.text-right {
    text-align: right;
}

.text-italic {
    font-style: italic;
}

.text-strike {
    text-decoration: line-through;
}

.lh-base {
    line-height: 1.6;
}

/* Sizing Utilities */
.width-full {
    width: 100%;
}

.width-fit {
    width: fit-content;
}

.min-width-200 {
    min-width: 200px;
}

.width-100 {
    width: 100px;
}

.width-30 {
    width: 30px;
}

.height-full {
    height: 100%;
}

.min-width-300 {
    min-width: 300px;
}

.border-none {
    border: none !important;
}

.transition-opacity {
    transition: opacity 0.3s;
}

.logo-preview-container {
    margin-top: -1rem;
}

/* Settings & Media Utilities */
.logo-preview-img {
    box-shadow: var(--shadow-sm);
}

.logo-preview-empty {
    width: 150px;
    height: 150px;
    border-radius: 20px;
    background: #eee;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #aaa;
    border: 2px dashed #ccc;
}

.map-preview {
    margin-bottom: 1.5rem;
    height: 200px;
    border-radius: var(--radius-md);
    overflow: hidden;
    background: #e5e7eb;
    position: relative;
    border: 1px solid var(--border-color);
}

/* Icons & Links */
.external-link {
    color: var(--primary);
    text-decoration: none;
}

.chevron-icon {
    color: #ccc;
}

/* Status Badges */
.status-badge {
    display: inline-flex;
    align-items: center;
    padding: 2px 8px;
    border-radius: 12px;
    font-size: 0.75rem;
    font-weight: 600;
    line-height: 1.4;
    width: fit-content;
}

.status-badge.critical {
    background-color: #fee2e2;
    color: #991b1b;
}

.status-badge.high {
    background-color: #ffedd5;
    color: #9a3412;
}

.status-badge.medium {
    background-color: #fef9c3;
    color: #854d0e;
}

.status-badge.low {
    background-color: #dbeafe;
    color: #1e40af;
}

.status-badge.finished {
    background-color: var(--success);
    color: white;
}

.status-badge.closed {
    background-color: var(--text-muted);
    color: white;
}

.status-badge.in-progress {
    background-color: var(--primary);
    color: white;
}

.status-badge.backlog {
    background-color: var(--accent);
    color: white;
}

/* Priority Indicators */
.priority-indicator {
    width: 8px;
    height: 8px;
    border-radius: 50%;
}

.priority-critical {
    background: var(--danger);
}

.priority-high {
    background: #f97316;
}

.priority-medium {
    background: #eab308;
}

.priority-low {
    background: #3b82f6;
}

/* Avatars & Users */
.user-pill {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    background: var(--bg-secondary);
    padding: 4px 12px 4px 4px;
    border-radius: 24px;
    border: 1px solid var(--border-color);
    color: var(--text-main, #111827);
    font-size: 0.85rem;
    font-weight: 500;
}

.user-pill .avatar-circle {
    margin: 0;
}

.avatar-stack {
    display: flex;
    align-items: center;
}

.avatar-circle {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    background: #eee;
    border: 2px solid white;
    margin-left: -8px;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 10px;
    color: #666;
}

.avatar-circle:first-child {
    margin-left: 0;
}

.avatar-img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

/* Empty States */
.empty-state {
    padding: 3rem;
    text-align: center;
}

.empty-state-large {
    grid-column: 1 / -1;
    text-align: center;
    padding: 4rem;
}

.empty-state-icon {
    font-size: 3rem;
    color: #ddd;
    margin-bottom: 1rem;
}

/* Dark Theme: Status Badges */
body.theme-dark .status-badge.critical {
    background-color: rgba(239, 68, 68, 0.2);
    color: #fca5a5;
}

body.theme-dark .status-badge.high {
    background-color: rgba(249, 115, 22, 0.2);
    color: #fdba74;
}

body.theme-dark .status-badge.medium {
    background-color: rgba(234, 179, 8, 0.2);
    color: #fde047;
}

body.theme-dark .status-badge.low {
    background-color: rgba(59, 130, 246, 0.2);
    color: #93c5fd;
}

/* Dark Theme Overrides for Components & Utilities */
body.theme-dark .avatar-circle {
    border-color: var(--card-bg);
    background: #334155;
    color: var(--text-main);
}

body.theme-dark .user-pill {
    background: rgba(255, 255, 255, 0.05);
    border-color: var(--border-color);
    color: var(--text-main);
}

body.theme-dark .priority-indicator {
    opacity: 0.9;
}

body.theme-dark .empty-state-icon {
    color: rgba(255, 255, 255, 0.1);
}

body.theme-dark .chevron-icon {
    color: #475569;
}

body.theme-dark .logo-preview-empty {
    background: #334155;
    border-color: #475569;
    color: #94a3b8;
}

/* ==========================================================================
   Subscription Gate: Blur + Modal
   ========================================================================== */

.main-content--blurred {
    filter: blur(6px);
    pointer-events: none;
    user-select: none;
    overflow: hidden;
    max-height: calc(100vh - var(--header-height, 70px));
}

.subscribe-overlay {
    position: fixed;
    inset: 0;
    z-index: 9000;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(0, 0, 0, 0.3);
    backdrop-filter: blur(2px);
    animation: subscribeOverlayIn 0.3s ease-out;
}

@keyframes subscribeOverlayIn {
    from {
        opacity: 0;
    }

    to {
        opacity: 1;
    }
}

.subscribe-modal {
    background: var(--card-bg, #fff);
    border: 1px solid var(--border-color, #e5e7eb);
    border-radius: 20px;
    padding: 3rem 2.5rem;
    max-width: 420px;
    width: 90%;
    text-align: center;
    box-shadow: 0 24px 48px rgba(0, 0, 0, 0.25);
    animation: subscribeModalIn 0.4s cubic-bezier(0.22, 1, 0.36, 1);
}

@keyframes subscribeModalIn {
    from {
        opacity: 0;
        transform: translateY(30px) scale(0.95);
    }

    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

.subscribe-modal__icon {
    width: 72px;
    height: 72px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--primary, #6366f1), #818cf8);
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto 1.5rem;
    font-size: 1.8rem;
    color: white;
    box-shadow: 0 8px 24px rgba(99, 102, 241, 0.3);
}

.subscribe-modal__title {
    margin: 0 0 0.75rem;
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--text-main, #111827);
}

.subscribe-modal__text {
    margin: 0 0 2rem;
    color: var(--text-muted, #6b7280);
    font-size: 0.95rem;
    line-height: 1.6;
}

.subscribe-modal__btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    width: 100%;
    padding: 14px 24px;
    background: linear-gradient(135deg, var(--primary, #6366f1), #818cf8);
    color: white;
    border: none;
    border-radius: 12px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: transform 0.2s, box-shadow 0.2s;
}

.subscribe-modal__btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 20px rgba(99, 102, 241, 0.4);
}

.subscribe-modal__btn:disabled {
    opacity: 0.7;
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}

.subscribe-modal__link {
    display: inline-block;
    margin-top: 1.25rem;
    color: var(--text-muted, #6b7280);
    font-size: 0.85rem;
    text-decoration: none;
    transition: color 0.2s;
}

.subscribe-modal__link:hover {
    color: var(--primary, #6366f1);
}

/* Sidebar: Locked Module Link */
.nav-link--locked {
    opacity: 0.5;
}

.nav-link--locked:hover {
    opacity: 0.8;
}

.nav-lock-icon {
    margin-left: auto;
    font-size: 0.7rem;
    opacity: 0.6;
}

.sidebar.collapsed .nav-lock-icon {
    display: none;
}

/* ==========================================================================
   Modules Dashboard Grid
   ========================================================================== */

.modules-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 1.25rem;
    max-width: 800px;
}

.module-tile {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.75rem;
    padding: 2rem 1.5rem;
    background: var(--card-bg, #fff);
    border: 1px solid var(--border-color, #e5e7eb);
    border-radius: 16px;
    text-decoration: none;
    color: var(--text-main);
    transition: transform 0.2s, box-shadow 0.2s;
    position: relative;
}

.module-tile:hover {
    transform: translateY(-4px);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.12);
}

.module-tile__icon {
    width: 56px;
    height: 56px;
    border-radius: 14px;
    background: linear-gradient(135deg, var(--primary, #6366f1), #818cf8);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.4rem;
    color: white;
}

.module-tile__name {
    font-weight: 600;
    font-size: 1rem;
}

.module-tile--locked {
    opacity: 0.6;
}

.module-tile--locked:hover {
    opacity: 0.85;
}

.module-tile__lock {
    position: absolute;
    top: 0.75rem;
    right: 0.75rem;
    font-size: 0.8rem;
    color: var(--text-muted);
}

/* ==== Modal Utilities ==== */
.modal-header {
    display: flex;
    flex-direction: row-reverse;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.25rem;
    padding-bottom: 0.875rem;
    border-bottom: 1px solid var(--border-color, #e5e7eb);
}

.modal-header h2 {
    margin: 0;
    font-size: 1.2rem;
    font-weight: 700;
    color: var(--text-main, var(--text-primary, #111));
    font-family: inherit;
    letter-spacing: -0.01em;
}

.close-modal {
    color: var(--text-muted, #666);
    font-size: 24px;
    font-weight: bold;
    cursor: pointer;
    line-height: 1;
    flex-shrink: 0;
    background: none;
    border: none;
    padding: 0;
    transition: color 0.15s ease;
}

.close-modal:hover {
    color: var(--text-main, #111);
}

.btn-cancel-modal {
    appearance: none;
    -webkit-appearance: none;
    box-sizing: border-box;
    padding: 0.6rem 1.2rem;
    border-radius: 0.5rem;
    font-weight: 600;
    font-size: 0.9rem;
    cursor: pointer;
    border: 1.5px solid var(--border-color);
    background: transparent;
    color: var(--text-muted);
    font-family: inherit;
    line-height: 1.5;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.btn-cancel-modal:hover {
    background: rgba(255, 255, 255, 0.06);
    border-color: var(--text-muted, #9ca3af);
    color: var(--text-main, #f1f5f9);
}

body.theme-light .btn-cancel-modal:hover {
    background: rgba(0, 0, 0, 0.06);
}

.modal-overlay {
    position: fixed;
    inset: 0;
    z-index: 10000 !important;
    display: none;
    align-items: center;
    justify-content: center;
    background: rgba(0, 0, 0, 0.75);
    backdrop-filter: blur(4px);
}

.modal-overlay:not(.hidden) {
    display: flex;
}

.d-flex {
    display: flex !important;
}

.d-none {
    display: none !important;
}
