/**
 * Design System
 *
 * This file establishes the foundational visual language for the entire
 * application. It defines reusable properties like colors, typography,
 * spacing, and shadows as CSS custom properties (variables).
 *
 * By centralizing these values, we ensure a consistent look and feel
 * across all components and make future theme adjustments much easier.
 */

:root {
    /* 1. Color Palette (Light Mode - Default) */
    --color-primary: #007bff;
    --color-primary-dark: #0056b3;
    --color-white: #ffffff;
    --color-black: #000000;

    /* Semantic colors for user feedback */
    --color-success: #28a745;
    --color-danger: #dc3545;
    --color-warning: #ffc107;
    --color-info: #17a2b8;

    /* Component Colors */
    --color-background-body: var(--color-gray-50);
    --color-background-header: var(--color-white);
    --color-background-sidebar: var(--color-white);
    --color-background-widget: var(--color-white);
    --color-background-widget-header: var(--color-gray-50);
    --color-background-footer: var(--color-gray-50);
    --color-text-primary: var(--color-gray-800);
    --color-text-secondary: var(--color-gray-600);
    --color-border: var(--color-gray-200);

    /* Neutral shades for backgrounds, borders, and text */
    --color-gray-50: #f8f9fa;
    --color-gray-100: #f1f3f5;
    --color-gray-200: #e9ecef;
    --color-gray-300: #dee2e6;
    --color-gray-400: #ced4da;
    --color-gray-500: #adb5bd;
    --color-gray-600: #868e96;
    --color-gray-700: #495057;
    --color-gray-800: #343a40;
    --color-gray-900: #212529;

    /* 2. Typography */
    --font-family-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol";
    --font-family-mono: SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;

    --font-size-base: 16px;
    --font-size-sm: 0.875rem; /* 14px */
    --font-size-md: 1rem;     /* 16px */
    --font-size-lg: 1.125rem; /* 18px */
    --font-size-xl: 1.25rem;  /* 20px */

    --line-height-base: 1.5;

    /* 3. Spacing */
    /* Used for padding, margins, gaps, etc. */
    --space-xs: 4px;
    --space-sm: 8px;
    --space-md: 16px;
    --space-lg: 24px;
    --space-xl: 32px;
    --space-xxl: 48px;

    /* 4. Borders & Shadows */
    --border-radius-sm: 0.2rem;
    --border-radius-md: 0.3rem;
    --border-radius-lg: 0.5rem;

    --border-width: 1px;
    --border-color: var(--color-gray-300);

    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
}

/* Dark Mode Color Overrides */
.dark-mode {
    --color-background-body: var(--color-gray-900);
    --color-background-header: var(--color-gray-800);
    --color-background-sidebar: var(--color-gray-800);
    --color-background-widget: var(--color-gray-800);
    --color-background-widget-header: #31373e; /* Slightly lighter than widget bg */
    --color-background-footer: var(--color-gray-800);
    --color-text-primary: var(--color-gray-100);
    --color-text-secondary: var(--color-gray-400);
    --color-border: var(--color-gray-700);

    /* Adjust shadows for dark mode */
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.3), 0 2px 4px -1px rgba(0, 0, 0, 0.25);
}

/* 5. Generic Components */

/* Links */
.mp-link {
    color: var(--color-primary);
    text-decoration: none;
    font-weight: 500;
}

.mp-link:hover {
    color: var(--color-primary-dark);
    text-decoration: underline;
}

/* Buttons */
.mp-button {
    display: inline-block;
    padding: var(--space-sm) var(--space-md);
    font-size: var(--font-size-sm);
    font-weight: 600;
    border: none;
    border-radius: var(--border-radius-md);
    cursor: pointer;
    text-align: center;
    text-decoration: none;
    transition: background-color 0.2s ease, color 0.2s ease, border-color 0.2s ease;
}

.mp-button--primary {
    color: var(--color-white);
    background-color: var(--color-primary);
}

.mp-button--primary:hover {
    background-color: var(--color-primary-dark);
}

/* Visually hide an element but keep it accessible to screen readers */
.visually-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}


/* Apply base styles to the body */
body.mp-pro-app-body {
    font-family: var(--font-family-sans);
    font-size: var(--font-size-base);
    font-weight: var(--font-weight-normal);
    line-height: var(--line-height-base);
    color: var(--color-text-primary);
    background-color: var(--color-background-body);
}

/* Update layout with design system colors */
#mp-pro-sidebar {
    background-color: var(--color-background-sidebar);
    border-right: 1px solid var(--color-border);
}

#mp-pro-header {
    background-color: var(--color-background-header);
    border-bottom: 1px solid var(--color-border);
}

#mp-pro-content {
    background-color: var(--color-background-body);
}

/* Basic style for Gridstack widgets to use our design system */
.grid-stack-item-content {
    background-color: var(--color-background-widget);
    border-radius: var(--border-radius);
    box-shadow: var(--box-shadow);
    color: var(--color-text-primary);
    padding: var(--space-md);
    box-sizing: border-box;
}

.mp-widget-footer {
    padding: var(--space-sm) var(--space-lg);
    border-top: var(--border-width) solid var(--border-color);
    background-color: var(--color-background-widget-header);
    display: flex;
    align-items: center;
    justify-content: flex-start; /* Align items to the start by default */
}

/* === COMMUNICATION CENTER STYLES === */
.mp-communication-templates,
.mp-communication-logs {
    margin-top: 20px;
}

.mp-templates-header,
.mp-logs-header {
    margin-bottom: 20px;
    padding-bottom: 15px;
    border-bottom: 1px solid #ddd;
}

.mp-system-badge {
    background: #0073aa;
    color: white;
    padding: 2px 6px;
    border-radius: 3px;
    font-size: 11px;
    margin-left: 8px;
}

.mp-status-active {
    color: #46b450;
    font-weight: bold;
}

.mp-status-inactive {
    color: #dc3232;
    font-weight: bold;
}

.mp-status-success {
    color: #46b450;
    font-weight: bold;
}

.mp-status-error {
    color: #dc3232;
    font-weight: bold;
}

.mp-placeholders-help {
    margin-top: 30px;
    padding: 20px;
    background: #f9f9f9;
    border-radius: 5px;
}

.mp-placeholders-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 20px;
    margin-top: 15px;
}

.mp-placeholder-category h4 {
    margin-bottom: 10px;
    color: #0073aa;
}

.mp-placeholder-category ul {
    list-style: none;
    padding: 0;
}

.mp-placeholder-category li {
    margin-bottom: 8px;
    padding: 5px 0;
}

.mp-placeholder-category code {
    background: #0073aa;
    color: white;
    padding: 2px 6px;
    border-radius: 3px;
    font-family: monospace;
    margin-right: 8px;
}

.mp-logs-filters {
    margin-bottom: 20px;
    padding: 15px;
    background: #f9f9f9;
    border-radius: 5px;
}

.mp-logs-filters form {
    display: flex;
    gap: 10px;
    align-items: center;
}

.mp-error-message {
    color: #dc3232;
    cursor: help;
    text-decoration: underline;
}

.mp-success-message {
    color: #46b450;
}

/* Modal Styles */
.mp-modal {
    position: fixed;
    z-index: 100000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0,0,0,0.5);
}

.mp-modal-content {
    background-color: #fefefe;
    margin: 5% auto;
    padding: 0;
    border: 1px solid #888;
    width: 80%;
    max-width: 800px;
    border-radius: 5px;
    box-shadow: 0 4px 6px rgba(0,0,0,0.1);
}

.mp-modal-large {
    max-width: 1000px;
    width: 90%;
}

.mp-modal-header {
    padding: 20px;
    background: #0073aa;
    color: white;
    border-radius: 5px 5px 0 0;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.mp-modal-header h3 {
    margin: 0;
    color: white;
}

.mp-modal-close {
    color: white;
    font-size: 28px;
    font-weight: bold;
    cursor: pointer;
    line-height: 1;
}

.mp-modal-close:hover {
    opacity: 0.7;
}

.mp-modal-body {
    padding: 20px;
    max-height: 70vh;
    overflow-y: auto;
}

.mp-modal-actions {
    margin-top: 20px;
    padding-top: 15px;
    border-top: 1px solid #ddd;
    text-align: right;
}

.mp-modal-actions .button {
    margin-left: 10px;
}

.mp-preview-content {
    border: 1px solid #ddd;
    border-radius: 5px;
    overflow: hidden;
}

.mp-preview-subject {
    padding: 15px;
    background: #f9f9f9;
    border-bottom: 1px solid #ddd;
    font-weight: bold;
}

.mp-preview-body {
    padding: 20px;
    min-height: 200px;
}

/* Statistics Styles */
.mp-communication-statistics {
    margin-top: 20px;
}

.mp-stats-header {
    margin-bottom: 30px;
    padding-bottom: 15px;
    border-bottom: 1px solid #ddd;
}

.mp-stats-cards {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 20px;
    margin-bottom: 30px;
}

.mp-stat-card {
    background: #f9f9f9;
    padding: 20px;
    border-radius: 8px;
    text-align: center;
    border: 1px solid #ddd;
}

.mp-stat-card h3 {
    margin: 0 0 10px 0;
    font-size: 14px;
    color: #666;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.mp-stat-number {
    font-size: 32px;
    font-weight: bold;
    color: #0073aa;
    margin: 0;
}

.mp-stats-charts {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 30px;
    margin-bottom: 30px;
}

.mp-chart-container {
    background: #fff;
    padding: 20px;
    border: 1px solid #ddd;
    border-radius: 8px;
}

.mp-chart-container h3 {
    margin-top: 0;
    margin-bottom: 20px;
    color: #0073aa;
}

.mp-chart-placeholder {
    min-height: 200px;
}

.mp-recent-activity,
.mp-error-analysis {
    background: #fff;
    padding: 20px;
    border: 1px solid #ddd;
    border-radius: 8px;
    margin-bottom: 20px;
}

.mp-recent-activity h3,
.mp-error-analysis h3 {
    margin-top: 0;
    margin-bottom: 20px;
    color: #0073aa;
}

/* Provider Management Styles */
.mp-communication-providers {
    margin-top: 20px;
}

.mp-providers-header {
    margin-bottom: 30px;
    padding-bottom: 15px;
    border-bottom: 1px solid #ddd;
}

.mp-current-provider {
    margin-bottom: 30px;
}

.mp-current-provider h3 {
    margin-bottom: 15px;
    color: #0073aa;
}

.mp-providers-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 20px;
    margin-bottom: 30px;
}

.mp-provider-card {
    background: #fff;
    border: 1px solid #ddd;
    border-radius: 8px;
    padding: 20px;
    position: relative;
    transition: all 0.3s ease;
}

.mp-provider-card:hover {
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}

.mp-provider-current {
    border-color: #0073aa;
    background: #f8f9fa;
}

.mp-provider-active {
    border-color: #46b450;
    background: #f0f8f0;
}

.mp-provider-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 15px;
}

.mp-provider-header h4 {
    margin: 0;
    color: #333;
}

.mp-provider-badges {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.mp-provider-badge {
    padding: 4px 8px;
    border-radius: 4px;
    font-size: 11px;
    font-weight: bold;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.mp-provider-active-badge {
    background: #46b450;
    color: white;
}

.mp-provider-coming-soon-badge {
    background: #ffb900;
    color: white;
}

.mp-provider-description {
    color: #666;
    margin-bottom: 20px;
    line-height: 1.5;
}

.mp-provider-actions {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
}

.mp-provider-actions .button {
    margin: 0;
}

.mp-provider-test {
    background: #f9f9f9;
    padding: 20px;
    border-radius: 8px;
    border: 1px solid #ddd;
}

.mp-provider-test h3 {
    margin-top: 0;
    margin-bottom: 15px;
    color: #0073aa;
}

.mp-test-form {
    max-width: 600px;
}

/* Message Styles */
.mp-message {
    padding: 15px;
    border-radius: 5px;
    margin: 15px 0;
    border-left: 4px solid;
    animation: fadeIn 0.3s ease-in;
}

.mp-message-success {
    background-color: #d4edda;
    border-color: #46b450;
    color: #155724;
}

.mp-message-error {
    background-color: #f8d7da;
    border-color: #dc3232;
    color: #721c24;
}

.mp-message-warning {
    background-color: #fff3cd;
    border-color: #ffb900;
    color: #856404;
}

.mp-message-info {
    background-color: #d1ecf1;
    border-color: #0073aa;
    color: #0c5460;
}

.mp-message h4 {
    margin: 0 0 10px 0;
    font-size: 16px;
}

.mp-message p {
    margin: 5px 0;
}

.mp-message ul {
    margin: 10px 0;
    padding-left: 20px;
}

.mp-message li {
    margin: 5px 0;
}

.mp-message-details {
    font-size: 14px;
    opacity: 0.8;
    margin-top: 10px;
}

.mp-message-close {
    float: right;
    background: none;
    border: none;
    font-size: 18px;
    cursor: pointer;
    opacity: 0.7;
    margin-top: -5px;
}

.mp-message-close:hover {
    opacity: 1;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(-10px); }
    to { opacity: 1; transform: translateY(0); }
}

/* === DMS MODAL WINDOW === */
.mp-dms-fullscreen {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 10000;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease, visibility 0.3s ease;
    padding: 20px;
}

.mp-dms-fullscreen.active {
    opacity: 1;
    visibility: visible;
}

.mp-dms-window {
    background: white;
    border-radius: 12px;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.25);
    width: 98vw;
    height: 95vh;
    max-width: none;
    max-height: none;
    display: flex;
    flex-direction: column;
    transform: scale(0.95) translateY(20px);
    transition: transform 0.3s ease;
    overflow: hidden;
}

.mp-dms-fullscreen.active .mp-dms-window {
    transform: scale(1) translateY(0);
}

.mp-dms-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 20px 24px;
    border-bottom: 1px solid var(--color-border);
    background: linear-gradient(135deg, #f8fafc 0%, #f1f5f9 100%);
    flex-shrink: 0;
    border-radius: 12px 12px 0 0;
}

.mp-dms-title {
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 20px;
    font-weight: 700;
    color: var(--color-text-primary);
}

.mp-dms-title .mp-icon {
    width: 24px;
    height: 24px;
    color: var(--color-primary);
}

.mp-dms-context {
    display: flex;
    align-items: center;
    padding: 8px 16px;
    background: white;
    border: 1px solid var(--color-border);
    border-radius: 8px;
    font-size: 14px;
    color: var(--color-text-secondary);
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

.mp-context-separator {
    color: var(--color-text-muted);
    margin: 0 4px;
}

.mp-dms-close {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    border: none;
    background: rgba(255, 255, 255, 0.8);
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s;
    color: var(--color-text-secondary);
    border: 1px solid var(--color-border);
}

.mp-dms-close:hover {
    background: #ef4444;
    color: white;
    border-color: #ef4444;
    transform: scale(1.05);
}

.mp-dms-close .mp-icon {
    width: 20px;
    height: 20px;
}

.mp-dms-body {
    flex: 1;
    overflow: hidden;
    position: relative;
    background: white;
}

/* Responsive Design */
@media (max-width: 768px) {
    .mp-dms-fullscreen {
        padding: 10px;
    }

    .mp-dms-window {
        width: 100%;
        height: 100%;
        border-radius: 8px;
    }

    .mp-dms-header {
        padding: 16px 20px;
        border-radius: 8px 8px 0 0;
    }

    .mp-dms-title {
        font-size: 18px;
    }

    .mp-dms-context {
        display: none; /* Hide context on mobile */
    }
}

/* ========================================
   Modern Form and UI Enhancements
   ======================================== */

/* Enhanced Cards */
.card {
    border: 1px solid var(--color-border);
    border-radius: var(--border-radius-lg);
    box-shadow: var(--shadow-sm);
    transition: box-shadow 0.15s ease-in-out;
    animation: fadeInUp 0.3s ease-out;
}

.card:hover {
    box-shadow: var(--shadow-md);
}

.card-header {
    background-color: var(--color-background-widget-header);
    border-bottom: 1px solid var(--color-border);
    padding: var(--spacing-md);
    border-radius: var(--border-radius-lg) var(--border-radius-lg) 0 0;
}

.card-header h6 {
    margin: 0;
    font-weight: var(--font-weight-semibold);
    color: var(--color-text-primary);
}

.card-body {
    padding: var(--spacing-lg);
}

/* Enhanced Form Controls */
.form-control:focus,
.form-select:focus {
    border-color: var(--color-primary);
    box-shadow: 0 0 0 0.2rem rgba(0, 123, 255, 0.25);
}

/* Enhanced Buttons */
.btn-primary {
    background-color: var(--color-primary);
    border-color: var(--color-primary);
    transition: all 0.15s ease-in-out;
}

.btn-primary:hover {
    background-color: var(--color-primary-dark);
    border-color: var(--color-primary-dark);
    transform: translateY(-1px);
    box-shadow: var(--shadow-md);
}

.btn-outline-primary {
    color: var(--color-primary);
    border-color: var(--color-primary);
    transition: all 0.15s ease-in-out;
}

.btn-outline-primary:hover {
    background-color: var(--color-primary);
    border-color: var(--color-primary);
    transform: translateY(-1px);
    box-shadow: var(--shadow-sm);
}

.btn-outline-secondary {
    transition: all 0.15s ease-in-out;
}

.btn-outline-secondary:hover {
    transform: translateY(-1px);
    box-shadow: var(--shadow-sm);
}

/* Loading States */
.mp-loading {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: var(--spacing-xl);
    color: var(--color-text-secondary);
}

.mp-loading .spinner-border {
    margin-right: var(--spacing-sm);
}

/* Form Validation */
.was-validated .form-control:valid {
    border-color: var(--color-success);
}

.was-validated .form-control:invalid {
    border-color: var(--color-danger);
}

.invalid-feedback {
    color: var(--color-danger);
    font-size: var(--font-size-sm);
    margin-top: var(--spacing-xs);
}

/* Animations */
@keyframes fadeInUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Enhanced Tabs */
.nav-tabs .nav-link {
    border: none;
    border-bottom: 2px solid transparent;
    color: var(--color-text-secondary);
    transition: all 0.15s ease-in-out;
}

.nav-tabs .nav-link:hover {
    border-bottom-color: var(--color-primary);
    color: var(--color-primary);
}

.nav-tabs .nav-link.active {
    border-bottom-color: var(--color-primary);
    color: var(--color-primary);
    background-color: transparent;
}

/* Enhanced Modals */
.modal-content {
    border: none;
    border-radius: var(--border-radius-lg);
    box-shadow: var(--shadow-xl);
}

.modal-header {
    border-bottom: 1px solid var(--color-border);
    background-color: var(--color-background-widget-header);
}

.modal-footer {
    border-top: 1px solid var(--color-border);
    background-color: var(--color-background-widget-header);
}

/* Mobile Responsive Enhancements */
@media (max-width: 768px) {
    .card-body {
        padding: var(--spacing-md);
    }

    .modal-dialog {
        margin: var(--spacing-sm);
    }

    .modal-dialog-lg {
        max-width: calc(100vw - 2rem);
    }
}