/* Custom CSS to complement Bootstrap */

/* Fix multi-select dropdown selected option visibility */
.form-select[multiple] option:checked,
.form-select[multiple] option:checked:hover {
    background-color: #0d6efd !important;
    color: white !important;
}

.form-select[multiple] option {
    padding: 8px;
    color: #212529;
    background-color: white;
}

.form-select[multiple] option:hover {
    background-color: #e9ecef;
    color: #212529;
}

/* Theme Support - Light and Dark */
:root {
    --theme-transition: background-color 0.3s ease, color 0.3s ease, border-color 0.3s ease;
}

body {
    transition: var(--theme-transition);
}

/* Toggle button for theme switching */
.theme-toggle {
    position: fixed;
    bottom: 20px;
    right: 20px;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background-color: var(--bs-primary);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    z-index: 1000;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2);
    transition: transform 0.2s;
}

.theme-toggle:hover {
    transform: scale(1.1);
}

/* Simple Loader */
.loader-container {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.8);
    z-index: 9999;
    justify-content: center;
    align-items: center;
    flex-direction: column;
}

.loader-container.active {
    display: flex;
}

.loader-spinner {
    width: 50px;
    height: 50px;
    border: 4px solid #333;
    border-top: 4px solid #007bff;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-bottom: 20px;
}

.loader-text {
    color: white;
    font-size: 1.2rem;
    text-align: center;
}

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

/* Shapes Container and Items */
.shapes-container {
    border: 1px solid #495057;
    border-radius: 6px;
    padding: 8px;
    background-color: #2d3436;
}

.shape-item {
    background-color: #3a3d42;
    border: 1px solid #495057;
    border-radius: 4px;
    padding: 8px 12px;
    margin-bottom: 6px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-left: 4px solid #0d6efd;
    cursor: pointer;
    transition: all 0.2s ease;
}

.shape-item:hover {
    background-color: #495057;
    border-color: #6c757d;
}

.shape-item.selected {
    background-color: #0d6efd;
    color: white;
    border-color: #0d6efd;
}

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

/* Shape tooltip styling - REMOVED - was causing dark rectangular popup */

/* Discrete Update Action Buttons */
.btn-xs.text-muted {
    transition: color 0.2s ease, opacity 0.2s ease;
    opacity: 0.6;
}

.btn-xs.text-muted:hover {
    opacity: 1;
    transform: scale(1.1);
}

.btn-xs.text-muted:hover i.fa-edit {
    color: #ffc107 !important;
}

.btn-xs.text-muted:hover i.fa-trash {
    color: #dc3545 !important;
}

.btn-xs.text-muted:focus {
    box-shadow: none;
    outline: none;
}

/* Modern Text Message UI Styles */
.message-container {
    max-height: 600px;
    overflow-y: auto;
    padding: 20px;
    background: #f5f5f5;
    border-radius: 0;
}

/* Message wrapper with avatar */
.message-wrapper {
    display: flex;
    align-items: flex-end;
    margin-bottom: 16px;
    gap: 10px;
}

.message-wrapper.sent {
    flex-direction: row-reverse;
}

/* Circular avatars */
.message-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 16px;
    color: white;
}

.message-avatar.other {
    background: #2d3436;
}

.message-avatar.current {
    background: linear-gradient(135deg, #7c3aed, #a78bfa);
}

/* Message bubble container */
.message-item {
    max-width: 65%;
    word-wrap: break-word;
    word-break: break-word;
    overflow-wrap: break-word;
    background: none !important;
    border: none !important;
    box-shadow: none !important;
    outline: none !important;
    margin-bottom: 0;
}

/* Message content bubbles */
.message-bubble {
    padding: 12px 16px;
    border-radius: 20px;
    display: inline-block;
    max-width: 100%;
    word-wrap: break-word;
    word-break: break-word;
    overflow-wrap: break-word;
    white-space: pre-wrap;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
    margin-bottom: 4px;
}

.message-bubble.sent {
    background: linear-gradient(135deg, #7c3aed, #a78bfa);
    color: white;
    border-radius: 20px 20px 4px 20px;
}

.message-bubble.received {
    background: #e5e7eb;
    color: #1f2937;
    border-radius: 20px 20px 20px 4px;
}

/* Message metadata */
.message-meta {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.75rem;
    color: #9ca3af;
    padding: 0 8px;
}

.message-wrapper.sent .message-meta {
    justify-content: flex-end;
}

.message-time {
    font-size: 0.75rem;
    color: #9ca3af;
}

/* Message images */
.message-image {
    margin: 8px 0;
    width: 100%;
}

.message-image img {
    max-width: 100%;
    width: auto;
    max-height: 400px;
    border-radius: 16px;
    object-fit: contain;
    display: block;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.message-wrapper.sent .message-image {
    text-align: right;
}

.message-wrapper.sent .message-image img {
    margin-left: auto;
}

.message-wrapper.received .message-image {
    text-align: left;
}

.message-wrapper.received .message-image img {
    margin-right: auto;
}

/* Legacy support for old templates */
.message-sent {
    margin-left: auto;
    text-align: right;
}

.message-received {
    margin-right: auto;
    text-align: left;
}

.message-sent p {
    background: linear-gradient(135deg, #7c3aed, #a78bfa);
    color: white;
    padding: 12px 16px;
    border-radius: 20px 20px 4px 20px;
    margin: 0;
    display: inline-block;
    max-width: 100%;
    word-wrap: break-word;
    word-break: break-word;
    overflow-wrap: break-word;
    white-space: pre-wrap;
    border: none !important;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
    outline: none !important;
}

.message-received .message-content-wrapper {
    background: #e5e7eb;
    color: #1f2937;
    padding: 12px 16px;
    border-radius: 20px 20px 20px 4px;
    display: inline-block;
    max-width: 100%;
    word-wrap: break-word;
    word-break: break-word;
    overflow-wrap: break-word;
    border: none !important;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
    outline: none !important;
}

.message-received .message-content-wrapper p {
    margin: 0;
    white-space: pre-wrap;
    word-wrap: break-word;
    word-break: break-word;
    overflow-wrap: break-word;
}

.message-content {
    margin: 0;
}

/* Chat container with light theme */
.chat-container {
    background: white;
    border-radius: 12px;
    overflow: hidden;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.05);
}

.chat-header {
    background: white;
    border-bottom: 1px solid #e5e7eb;
    padding: 16px 20px;
}

.chat-header h5,
.chat-header .mb-0 {
    color: #1f2937 !important;
}

.chat-header small,
.chat-header .text-muted {
    color: #6b7280 !important;
}

.chat-messages {
    background: #f5f5f5;
    min-height: 400px;
    max-height: 600px;
    overflow-y: auto;
}

.chat-input-area {
    background: white;
    border-top: 1px solid #e5e7eb;
    padding: 16px 20px;
}

.chat-input-area input[type="text"],
.chat-input-area textarea {
    color: #1f2937 !important;
    background: #f5f5f5 !important;
}

.chat-input-area input[type="text"]::placeholder,
.chat-input-area textarea::placeholder {
    color: #9ca3af !important;
}

/* QR Code Sharing */
.qr-code-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    max-width: 250px;
    margin: 0 auto;
}

.qr-code-image {
    width: 200px;
    height: 200px;
    margin-bottom: 15px;
}

.share-button {
    position: relative;
    overflow: hidden;
}

.share-button .ripple {
    position: absolute;
    border-radius: 50%;
    background-color: rgba(255, 255, 255, 0.4);
    transform: scale(0);
    animation: ripple 0.6s linear;
}

@keyframes ripple {
    to {
        transform: scale(2.5);
        opacity: 0;
    }
}

/* Responsive Dashboard Layout */
.dashboard-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 1.5rem;
}

@media (max-width: 768px) {
    .dashboard-grid {
        grid-template-columns: 1fr;
    }
    
    .hide-on-mobile {
        display: none;
    }
    
    .show-on-mobile {
        display: block;
    }
}

/* Custom colors for roles */
.badge-contractor {
    background-color: var(--bs-primary);
}

.badge-resident {
    background-color: var(--bs-success);
}

.badge-agency {
    background-color: var(--bs-info);
}

/* Project status colors */
.status-planned {
    color: var(--bs-info);
}

.status-in_progress {
    color: var(--bs-primary);
}

.status-delayed {
    color: var(--bs-warning);
}

.status-completed {
    color: var(--bs-success);
}

.status-on_hold {
    color: var(--bs-danger);
}

/* Collapsible section styling */
.collapse-icon {
    transition: transform 0.3s ease;
}

[aria-expanded="false"] .collapse-icon {
    transform: rotate(-90deg);
}

[aria-expanded="true"] .collapse-icon {
    transform: rotate(0deg);
}

/* Message styling */
.message-container {
    max-height: 400px;
    overflow-y: auto;
}

.message-sent {
    background-color: rgba(var(--bs-primary-rgb), 0.2);
    border-radius: 0.5rem;
    padding: 0.75rem;
    margin-left: 25%;
    margin-right: 5%;
    margin-bottom: 1rem;
}

.message-received {
    background-color: rgba(var(--bs-secondary-rgb), 0.2);
    border-radius: 0.5rem;
    padding: 0.75rem;
    margin-right: 25%;
    margin-left: 5%;
    margin-bottom: 1rem;
}

.message-time {
    font-size: 0.8rem;
    color: var(--bs-gray-600);
    text-align: right;
}

/* Project timeline */
.timeline {
    position: relative;
    padding: 1rem 0;
}

.timeline::before {
    content: '';
    position: absolute;
    height: 100%;
    width: 2px;
    background-color: var(--bs-gray-500);
    left: 15px;
    top: 0;
}

.timeline-item {
    position: relative;
    padding-left: 40px;
    margin-bottom: 1.5rem;
}

.timeline-item::before {
    content: '';
    position: absolute;
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background-color: var(--bs-primary);
    left: 10px;
    top: 5px;
}

.timeline-content {
    padding: 0.75rem;
    border-radius: 0.5rem;
    background-color: rgba(var(--bs-gray-200-rgb), 0.1);
}

/* Notification count badge */
.notification-badge {
    position: absolute;
    top: -5px;
    right: -5px;
    font-size: 0.7rem;
}

/* Dashboard cards */
.dashboard-card {
    transition: transform 0.2s;
}

.dashboard-card:hover {
    transform: translateY(-5px);
    box-shadow: 0 0.5rem 1rem rgba(0, 0, 0, 0.15);
}

/* Project card */
.project-card {
    margin-bottom: 1.5rem;
}

/* Limit text overflow */
.text-ellipsis {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Leaflet Map styles */
.leaflet-container {
    background: #303030;  /* Dark background for maps to match theme */
    border-radius: 0.25rem;
}

.leaflet-popup-content-wrapper {
    background: var(--bs-dark);
    color: var(--bs-light);
    border-radius: 0.25rem;
}

.leaflet-popup-tip {
    background: var(--bs-dark);
}

/* Style the drawing tools to match our theme */
.leaflet-draw-toolbar a {
    background-color: var(--bs-dark);
    border: 1px solid var(--bs-gray-700);
}

.leaflet-draw-toolbar a:hover {
    background-color: var(--bs-gray-800);
}

.leaflet-draw-actions a {
    background-color: var(--bs-dark);
    color: var(--bs-light);
}

.leaflet-draw-actions a:hover {
    background-color: var(--bs-gray-800);
}

/* Project boundary colors based on status */
.project-boundary-planned {
    stroke: #0d6efd;
    fill: #0d6efd;
    fill-opacity: 0.2;
}

.project-boundary-in_progress {
    stroke: #6610f2;
    fill: #6610f2;
    fill-opacity: 0.2;
}

.project-boundary-scheduled_next {
    stroke: #fd7e14;
    fill: #fd7e14;
    fill-opacity: 0.2;
}

.project-boundary-delayed {
    stroke: #dc3545;
    fill: #dc3545;
    fill-opacity: 0.2;
}

.project-boundary-closed {
    stroke: #dc3545;
    fill: #dc3545;
    fill-opacity: 0.2;
}

/* Legacy support */
.project-boundary-completed {
    stroke: #198754;
    fill: #198754;
    fill-opacity: 0.2;
}

.project-boundary-on_hold {
    stroke: #dc3545;
    fill: #dc3545;
    fill-opacity: 0.2;
}

/* Improve dark tables inside dark cards for better readability */
.card.bg-dark .table.table-dark {
  --bs-table-color: #E7ECF3;           /* high-contrast text */
  --bs-table-bg: #212529;              /* match app dark background */
  --bs-table-border-color: #2B3035;    /* clearer dividers */
  --bs-table-striped-bg: #1B1F24;      /* subtle striping */
  --bs-table-hover-bg: #21262D;        /* clearer hover */
  --bs-table-striped-color: var(--bs-table-color);
  --bs-table-hover-color: var(--bs-table-color);
  background-color: #212529 !important; /* force dark background */
}

.card.bg-dark .table.table-dark td,
.card.bg-dark .table.table-dark th {
  background-color: #212529 !important; /* ensure all cells are dark */
  border-color: #2B3035 !important;
  color: #FFFFFF !important; /* force white text */
}

.card.bg-dark .table.table-dark strong {
  color: #FFFFFF !important; /* ensure project titles are white */
}

.card.bg-dark .table.table-dark .text-muted {
  color: #ADB5BD !important; /* lighter gray for muted text but still readable */
}

.card.bg-dark .table thead th { 
  color: #F8F9FA; 
  background-color: #0F1115;
}

.card.bg-dark .table thead { 
  background-color: #0F1115; 
}

.card.bg-dark .text-muted { 
  color: #AEB6C2 !important; 
}

/* Completed rows (was table-secondary on dark) - improve contrast */
.card.bg-dark .table.table-dark .table-secondary {
  background-color: #20252B !important; /* custom dark gray */
  color: #D2D9E3 !important;
}

/* Badges: ensure readable text on contextual backgrounds */
.badge.bg-warning { 
  color: #111 !important; 
}

.badge.bg-info { 
  color: #06232F !important; 
}

.badge.bg-secondary { 
  color: #FFF !important; 
}

.badge.bg-success, .badge.bg-primary { 
  color: #FFF !important; 
}

.badge.bg-purple { 
  background-color: #6F42C1 !important; 
  color: #FFF !important; 
}

/* Tabs readability inside dark cards */
.card.bg-dark .nav-tabs { 
  border-color: #2B3035; 
}

.card.bg-dark .nav-tabs .nav-link { 
  color: #CFE0F0; 
}

.card.bg-dark .nav-tabs .nav-link:hover { 
  color: #FFFFFF; 
}

.card.bg-dark .nav-tabs .nav-link.active {
  color: #FFFFFF;
  background-color: rgba(13,110,253,0.12); /* subtle blue tint */
  border-color: #2B3035 #2B3035 transparent;
}
