/* CSS Reset & Variables */
:root {
    color-scheme: dark;
    --bg-color: #0f172a;
    --glass-bg: rgba(30, 41, 59, 0.7);
    --glass-border: rgba(255, 255, 255, 0.1);
    --primary: #3b82f6;
    --primary-hover: #2563eb;
    --secondary: #475569;
    --secondary-hover: #334155;
    --text-main: #f8fafc;
    --text-muted: #94a3b8;
    --accent: #10b981;
    --danger: #ef4444;
    
    --font-family: 'Inter', sans-serif;
    --radius-lg: 16px;
    --radius-md: 8px;
    --transition: all 0.3s ease;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: var(--font-family);
    background-color: var(--bg-color);
    background-image: 
        radial-gradient(at 0% 0%, rgba(59, 130, 246, 0.15) 0px, transparent 50%),
        radial-gradient(at 100% 100%, rgba(16, 185, 129, 0.1) 0px, transparent 50%);
    background-attachment: fixed;
    color: var(--text-main);
    min-height: 100vh;
    line-height: 1.6;
}

/* Typography & Utilities */
h1, h2, h3, h4 {
    font-weight: 600;
    letter-spacing: -0.025em;
}

.text-accent { color: var(--accent); }
.hidden { display: none !important; }
.text-right { text-align: right; }

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 10px 20px;
    border-radius: var(--radius-md);
    font-weight: 500;
    font-family: var(--font-family);
    cursor: pointer;
    border: none;
    transition: var(--transition);
    font-size: 0.95rem;
}

.btn-primary {
    background: var(--primary);
    color: white;
    box-shadow: 0 4px 14px 0 rgba(59, 130, 246, 0.39);
}

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

.btn-primary-outline {
    background: transparent;
    color: var(--primary);
    border: 1px solid var(--primary);
}

.btn-primary-outline:hover {
    background: rgba(59, 130, 246, 0.1);
}

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

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

.btn-sm {
    padding: 6px 12px;
    font-size: 0.85rem;
}

/* Glass Panels */
.glass-panel {
    background: var(--glass-bg);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid var(--glass-border);
    border-radius: var(--radius-lg);
    box-shadow: 0 10px 30px -10px rgba(0,0,0,0.5);
}

/* Layout */
.navbar {
    padding: 15px 0;
    margin-bottom: 30px;
    background: rgba(15, 23, 42, 0.82);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.35);
}

.nav-content {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.logo {
    font-size: 1.5rem;
    color: #ffffff;
    font-weight: 700;
    letter-spacing: -0.5px;
}
.logo span {
    color: var(--primary);
}

.container {
    max-width: 900px;
    margin: 0 auto;
    padding: 0 20px 40px;
    display: flex;
    flex-direction: column;
    gap: 30px;
}

@media (max-width: 768px) {
    .nav-content {
        flex-direction: column;
        gap: 15px;
        text-align: center;
    }
    .nav-content > div:first-child {
        flex-direction: column;
        align-items: center;
        gap: 10px !important;
    }
    .global-nav {
        margin-left: 0 !important;
        justify-content: center;
        flex-wrap: wrap;
    }
    .nav-actions {
        width: 100%;
        display: flex;
        justify-content: center;
        gap: 10px;
    }
}

/* Form Styles */
.form-panel, .summary-panel {
    padding: 25px;
}

.section-title {
    font-size: 1.25rem;
    margin-bottom: 25px;
    padding-bottom: 15px;
    border-bottom: 1px solid var(--glass-border);
}

.form-section {
    margin-bottom: 25px;
}

.form-section h3 {
    font-size: 1rem;
    color: var(--text-muted);
    margin-bottom: 15px;
}

.form-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 20px;
}

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

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

.input-group input, .input-group select {
    background: rgba(15, 23, 42, 0.6);
    border: 1px solid var(--glass-border);
    color: white;
    padding: 10px 15px;
    border-radius: var(--radius-md);
    font-family: inherit;
    font-size: 0.95rem;
    transition: var(--transition);
}

.input-group input:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

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

/* Date & Time Picker visibility for dark theme */
input[type="date"],
input[type="time"],
input[type="datetime-local"] {
    color-scheme: dark;
}

input[type="date"]::-webkit-calendar-picker-indicator,
input[type="time"]::-webkit-calendar-picker-indicator,
input[type="datetime-local"]::-webkit-calendar-picker-indicator {
    cursor: pointer;
    filter: brightness(1.25);
    padding: 3px 5px;
    border-radius: 4px;
    opacity: 0.9;
    transition: all 0.2s ease;
}

input[type="date"]::-webkit-calendar-picker-indicator:hover,
input[type="time"]::-webkit-calendar-picker-indicator:hover,
input[type="datetime-local"]::-webkit-calendar-picker-indicator:hover {
    background: rgba(59, 130, 246, 0.25);
    filter: brightness(1.6);
    opacity: 1;
}

/* PDF Formal Document Layout */
.pdf-container {
    background: #e2e8f0;
    padding: 15px;
    border-radius: var(--radius-md);
    overflow-x: auto;
    max-height: 800px;
    overflow-y: auto;
}

.formal-document {
    background: white;
    color: #111;
    font-family: Arial, Helvetica, sans-serif;
    padding: 40px;
    width: 210mm; /* A4 width */
    min-height: 297mm; /* A4 height */
    margin: 0 auto;
    box-shadow: 0 0 10px rgba(0,0,0,0.1);
    font-size: 10pt;
    line-height: 1.5;
    box-sizing: border-box;
}

/* Let the PDF container wrap inside the viewport on smaller screens for preview only */
@media (max-width: 1200px) {
    .formal-document {
        transform-origin: top left;
        transform: scale(0.85); /* temporary scaling down for small screens in preview */
        margin-bottom: -15%;
    }
}
@media (max-width: 768px) {
    .formal-document {
        transform: scale(0.6); 
        margin-bottom: -40%;
    }
}

.doc-header {
    margin-bottom: 30px;
    border-bottom: 2px solid #222;
    padding-bottom: 15px;
}

.doc-header h1 {
    font-size: 16pt;
    color: #222;
    text-transform: uppercase;
    margin-bottom: 20px;
    text-align: center;
}

.doc-meta {
    display: flex;
    justify-content: space-between;
    background: #f8f9fa;
    padding: 10px 15px;
    border: 1px solid #ddd;
}

.meta-box {
    font-size: 9pt;
}

.doc-section {
    margin-bottom: 25px;
    break-inside: avoid;
    page-break-inside: avoid;
}

.rec-card {
    break-inside: avoid !important;
    page-break-inside: avoid !important;
}

.doc-section h2 {
    font-size: 12pt;
    color: #333;
    border-bottom: 1px solid #ccc;
    padding-bottom: 5px;
    margin-bottom: 10px;
}

.doc-section h3 {
    font-size: 10.5pt;
    margin-top: 15px;
    margin-bottom: 5px;
    color: #444;
}

.doc-table-simple, .doc-table-services {
    width: 100%;
    border-collapse: collapse;
    margin-bottom: 15px;
    font-size: 9.5pt;
}

.doc-table-simple th, .doc-table-simple td {
    padding: 6px;
    border: 1px solid #ddd;
}

.doc-table-simple th {
    background: #f8f9fa;
    width: 30%;
    text-align: left;
}

.doc-table-services th, .doc-table-services td {
    border: 1px solid #ccc;
    padding: 8px;
}

.doc-table-services thead th {
    background: #eee;
    font-weight: bold;
    text-align: left;
}

.doc-table-services tbody td {
    vertical-align: top;
}

.doc-table-services tfoot th, .doc-table-services tfoot td {
    background: #f8f9fa;
    font-size: 10pt;
}

.doc-section ul {
    padding-left: 20px;
    margin-bottom: 10px;
}

.doc-section li {
    margin-bottom: 5px;
    text-align: justify;
}

/* Modal Settings */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.6);
    backdrop-filter: blur(5px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    opacity: 0;
    pointer-events: none;
    transition: var(--transition);
}

.modal.active {
    opacity: 1;
    pointer-events: auto;
}

.modal-content {
    width: 90%;
    max-width: 900px;
    max-height: 90vh;
    overflow-y: auto;
    padding: 30px;
    transform: translateY(20px);
    transition: var(--transition);
}

.modal.active .modal-content {
    transform: translateY(0);
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 25px;
    padding-bottom: 15px;
    border-bottom: 1px solid var(--glass-border);
}

.close-btn {
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 1.5rem;
    cursor: pointer;
    transition: var(--transition);
}

.close-btn:hover {
    color: white;
}

.settings-layout {
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.settings-tabs {
    display: flex;
    gap: 10px;
    border-bottom: 1px solid var(--glass-border);
    padding-bottom: 10px;
    overflow-x: auto;
}

.tab-btn {
    background: none;
    border: none;
    color: var(--text-muted);
    padding: 8px 16px;
    cursor: pointer;
    border-radius: var(--radius-md);
    transition: var(--transition);
    font-family: inherit;
    font-size: 0.95rem;
    white-space: nowrap;
}

.tab-btn:hover {
    color: white;
    background: rgba(255, 255, 255, 0.05);
}

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

.settings-tab-content {
    display: none;
}

.settings-tab-content.active {
    display: block;
    animation: fadeIn 0.3s ease;
}

.settings-grid {
    display: flex;
    flex-direction: column;
    gap: 15px;
}

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

.db-list {
    margin-bottom: 15px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.db-item {
    background: rgba(15, 23, 42, 0.6);
    border: 1px solid var(--glass-border);
    padding: 10px 15px;
    border-radius: var(--radius-md);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.db-item-info strong {
    display: block;
    color: white;
}
.db-item-info span {
    font-size: 0.8rem;
    color: var(--text-muted);
}

.db-item-actions button {
    background: none;
    border: none;
    color: var(--primary);
    cursor: pointer;
    font-size: 0.85rem;
    font-family: var(--font-family);
    font-weight: 500;
}

.db-item-actions button.action-danger {
    color: var(--danger);
}

.chemical-form {
    margin-top: 20px;
    padding: 20px;
    background: rgba(15, 23, 42, 0.8);
    border-radius: var(--radius-md);
    border: 1px solid var(--glass-border);
    display: flex;
    flex-direction: column;
    gap: 15px;
}

.flex-actions {
    display: flex;
    gap: 10px;
    margin-top: 10px;
}

/* PDF Page Break Rules to avoid text/image/table splitting */
.formal-document tr {
    break-inside: avoid !important;
    page-break-inside: avoid !important;
}

.formal-document li {
    break-inside: avoid !important;
    page-break-inside: avoid !important;
}

.formal-document img {
    break-inside: avoid !important;
    page-break-inside: avoid !important;
}

.formal-document h1,
.formal-document h2,
.formal-document h3,
.formal-document h4 {
    break-after: avoid !important;
    page-break-after: avoid !important;
}

.formal-document .finding-block {
    break-inside: avoid !important;
    page-break-inside: avoid !important;
}

.formal-document .pdf-photo-wrapper {
    break-inside: avoid !important;
    page-break-inside: avoid !important;
}

/* Ensure the client selector modal is always on top of other modals */
#clients-modal {
    z-index: 1100;
}

/* ============================================================
   ASANA-STYLE MULTI-USER AUDIT TRAIL, ROLE BADGES & COMMENTS
   ============================================================ */

/* User Role Badges */
.user-role-badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-size: 0.72rem;
    font-weight: 600;
    padding: 2px 7px;
    border-radius: 9999px;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    line-height: 1.2;
    vertical-align: middle;
}
.user-role-badge.admin {
    background: rgba(59, 130, 246, 0.2);
    color: #93c5fd;
    border: 1px solid rgba(59, 130, 246, 0.4);
}
.user-role-badge.tech {
    background: rgba(16, 185, 129, 0.2);
    color: #6ee7b7;
    border: 1px solid rgba(16, 185, 129, 0.4);
}
.user-role-badge.client {
    background: rgba(245, 158, 11, 0.2);
    color: #fcd34d;
    border: 1px solid rgba(245, 158, 11, 0.4);
}

/* User Avatars */
.user-avatar-circle {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 0.75rem;
    color: #fff;
    background: linear-gradient(135deg, #3b82f6, #1d4ed8);
    flex-shrink: 0;
    text-transform: uppercase;
    box-shadow: 0 2px 6px rgba(0,0,0,0.25);
    border: 1px solid rgba(255,255,255,0.2);
}
.user-avatar-circle.tech {
    background: linear-gradient(135deg, #10b981, #047857);
}
.user-avatar-circle.client {
    background: linear-gradient(135deg, #f59e0b, #b45309);
}

/* Asana Comment Item */
.asana-comment-item {
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 10px;
    padding: 10px 12px;
    margin-bottom: 10px;
    transition: background 0.2s, border-color 0.2s;
}
.asana-comment-item:hover {
    background: rgba(255, 255, 255, 0.05);
    border-color: rgba(255, 255, 255, 0.15);
}
.asana-comment-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 6px;
    gap: 8px;
}
.asana-author-left {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}
.asana-author-name {
    font-size: 0.84rem;
    font-weight: 600;
    color: #f1f5f9;
}
.asana-comment-time {
    font-size: 0.72rem;
    color: #94a3b8;
}
.asana-comment-body {
    margin: 0;
    font-size: 0.88rem;
    color: #cbd5e1;
    white-space: pre-wrap;
    line-height: 1.45;
    padding-left: 36px;
}
.asana-comment-actions {
    display: flex;
    gap: 8px;
    font-size: 0.75rem;
    align-items: center;
}
.asana-comment-actions a {
    text-decoration: none;
    font-weight: 500;
}
.asana-comment-actions a:hover {
    text-decoration: underline;
}

/* In-Card Activity Item */
.asana-activity-pill {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 7px 11px;
    background: rgba(255, 255, 255, 0.02);
    border-left: 3px solid #3b82f6;
    border-radius: 4px;
    margin-bottom: 8px;
    font-size: 0.8rem;
    color: #cbd5e1;
}
.asana-activity-pill.dates { border-left-color: #3b82f6; }
.asana-activity-pill.crm { border-left-color: #f59e0b; }
.asana-activity-pill.services { border-left-color: #10b981; }
.asana-activity-pill.quotes { border-left-color: #8b5cf6; }
.asana-activity-pill.reports { border-left-color: #ec4899; }
.asana-activity-pill.clients { border-left-color: #6366f1; }

.asana-activity-pill .act-icon {
    font-size: 0.95rem;
    flex-shrink: 0;
}
.asana-activity-pill strong {
    color: #f8fafc;
}
.asana-activity-pill .act-time {
    margin-left: auto;
    font-size: 0.72rem;
    color: #94a3b8;
    white-space: nowrap;
}

/* Global Audit Modal & Timeline */
.audit-card {
    display: flex;
    gap: 12px;
    padding: 12px 14px;
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid rgba(255, 255, 255, 0.07);
    border-radius: 10px;
    margin-bottom: 10px;
    align-items: flex-start;
    transition: transform 0.15s, border-color 0.15s, background 0.15s;
}
.audit-card:hover {
    border-color: rgba(59, 130, 246, 0.35);
    background: rgba(255, 255, 255, 0.05);
}
.audit-action-chip {
    font-size: 0.72rem;
    padding: 2px 7px;
    border-radius: 4px;
    font-weight: 600;
    display: inline-flex;
    align-items: center;
    gap: 4px;
    text-transform: uppercase;
}
.audit-action-chip.dates { background: rgba(59, 130, 246, 0.15); color: #60a5fa; border: 1px solid rgba(59, 130, 246, 0.3); }
.audit-action-chip.comments { background: rgba(148, 163, 184, 0.15); color: #cbd5e1; border: 1px solid rgba(148, 163, 184, 0.3); }
.audit-action-chip.crm { background: rgba(245, 158, 11, 0.15); color: #fbbf24; border: 1px solid rgba(245, 158, 11, 0.3); }
.audit-action-chip.services { background: rgba(16, 185, 129, 0.15); color: #34d399; border: 1px solid rgba(16, 185, 129, 0.3); }
.audit-action-chip.quotes { background: rgba(139, 92, 246, 0.15); color: #c084fc; border: 1px solid rgba(139, 92, 246, 0.3); }
.audit-action-chip.reports { background: rgba(236, 72, 153, 0.15); color: #f472b6; border: 1px solid rgba(236, 72, 153, 0.3); }
.audit-action-chip.clients { background: rgba(99, 102, 241, 0.15); color: #818cf8; border: 1px solid rgba(99, 102, 241, 0.3); }

/* Clear Date/Time Buttons */
.btn-clear-date,
.btn-clear-time {
    transition: all 0.2s ease;
    touch-action: manipulation;
    user-select: none;
}
.btn-clear-date:hover,
.btn-clear-time:hover,
.btn-clear-date:active,
.btn-clear-time:active {
    background: rgba(239, 68, 68, 0.25) !important;
    border-color: rgba(239, 68, 68, 0.6) !important;
    color: #fff !important;
}

/* Mobile Global Adaptations */
@media (max-width: 768px) {
    .hide-mobile {
        display: none !important;
    }
    .modal-content {
        max-width: 95vw !important;
        width: 95vw !important;
        max-height: 90vh !important;
        margin: 10px auto !important;
        padding: 16px !important;
    }
    input[type="text"],
    input[type="tel"],
    input[type="email"],
    input[type="number"],
    input[type="date"],
    input[type="time"],
    select,
    textarea {
        font-size: 16px !important; /* Prevents auto-zoom in iOS Safari */
    }
}
