/* ==========================================================================
   Laplace Employee Portal — Design System
   Replica del CRM-ERP Admin Centre con paleta portal-aligned
   ========================================================================== */

:root {
    --crm-bg: #f4f7f8;
    --crm-sidebar: #ffffff;
    --crm-sidebar-hover: #eef8f8;
    --crm-primary: #00b8b8;
    --crm-primary-dark: #009a9a;
    --crm-white: #ffffff;
    --crm-text: #10242b;
    --crm-muted: #526371;
    --crm-border: #d7e1e4;
    --crm-success: #27b48a;
    --crm-warning: #f4b13d;
    --crm-danger: #e05252;
    --crm-red: #dc2626;
    --sidebar-width: 240px;
}

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

body {
    font-family: Inter, system-ui, -apple-system, sans-serif;
    background:
        radial-gradient(circle at 15% 10%, rgba(0,184,184,.08), transparent 28%),
        linear-gradient(180deg, #f8fbfb 0%, var(--crm-bg) 100%);
    color: var(--crm-text);
    display: flex;
    min-height: 100vh;
}

/* ==========================================================================
   Sidebar
   ========================================================================== */

.crm-sidebar {
    width: var(--sidebar-width);
    background: rgba(255,255,255,.94);
    color: var(--crm-muted);
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0; left: 0; bottom: 0;
    z-index: 100;
    border-right: 1px solid var(--crm-border);
    box-shadow: 12px 0 30px rgba(16,36,43,.06);
}

.crm-sidebar-brand {
    padding: 18px 20px;
    font-size: 1.2rem;
    font-weight: 800;
    color: var(--crm-text);
    border-bottom: 1px solid var(--crm-border);
    display: flex;
    align-items: center;
    gap: 10px;
}

.crm-sidebar-brand img {
    width: 128px;
    height: auto;
    object-fit: contain;
}

.crm-sidebar-brand span {
    color: var(--crm-muted);
    font-size: .72rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .5px;
}

.crm-sidebar-nav {
    flex: 1;
    padding: 12px 0;
    display: flex;
    flex-direction: column;
    gap: 2px;
    overflow-y: auto;
}

.crm-sidebar-nav a {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 12px;
    margin: 0 10px;
    color: #5f7178;
    text-decoration: none;
    font-size: 0.9rem;
    font-weight: 500;
    border-radius: 8px;
    transition: all 0.15s;
}

.crm-sidebar-nav a:hover,
.crm-sidebar-nav a.active {
    background: var(--crm-sidebar-hover);
    color: var(--crm-text);
}

.crm-sidebar-nav a.active {
    box-shadow: inset 3px 0 0 var(--crm-primary);
}

.crm-sidebar-nav a .icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    border-radius: 8px;
    background: #e7f4f4;
    color: #008c8c;
    flex-shrink: 0;
}

.crm-sidebar-nav a .icon svg,
.crm-link-button svg {
    width: 16px;
    height: 16px;
    fill: none;
    stroke: currentColor;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.crm-sidebar-footer {
    padding: 16px 14px;
    border-top: 1px solid var(--crm-border);
    font-size: 0.8rem;
    color: var(--crm-muted);
}

.crm-admin-card {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 12px;
    padding: 10px;
    border-radius: 8px;
    background: #f6fbfb;
    border: 1px solid var(--crm-border);
}

.crm-admin-avatar {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 34px;
    height: 34px;
    flex: 0 0 34px;
    border-radius: 8px;
    background: #e7f4f4;
    color: #008c8c;
    font-size: 0.78rem;
    font-weight: 850;
}

img.crm-admin-avatar {
    display: block;
    object-fit: cover;
}

.crm-admin-card div {
    display: grid;
    min-width: 0;
    gap: 1px;
}

.crm-admin-card strong {
    overflow: hidden;
    color: var(--crm-text);
    font-size: 0.84rem;
    line-height: 1.2;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.crm-admin-card span:last-child {
    color: var(--crm-muted);
    font-size: 0.72rem;
    font-weight: 700;
}

.crm-admin-settings {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 30px;
    height: 30px;
    margin-left: auto;
    border: 1px solid var(--crm-border);
    border-radius: 7px;
    background: #ffffff;
    color: #008c8c;
    text-decoration: none;
}

.crm-admin-settings:hover {
    background: #eef8f8;
    color: #007f7f;
}

.crm-admin-settings svg {
    width: 16px;
    height: 16px;
    fill: none;
    stroke: currentColor;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.crm-sidebar-footer form { display: block; }

.crm-link-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    width: 100%;
    min-height: 38px;
    padding: 0 12px;
    border: 0;
    border-radius: 8px;
    background: #e52229;
    color: #ffffff;
    font: inherit;
    font-size: 0.84rem;
    font-weight: 800;
    cursor: pointer;
    box-shadow: 0 10px 24px rgba(220,38,38,0.18);
    transition: background 160ms ease, box-shadow 160ms ease, transform 160ms ease;
}

.crm-link-button:hover {
    background: #f03238;
    transform: translateY(-1px);
    box-shadow: 0 14px 30px rgba(220,38,38,0.24);
}

.crm-link-button span {
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

/* ==========================================================================
   Main content
   ========================================================================== */

.crm-main {
    margin-left: var(--sidebar-width);
    flex: 1;
    padding: 0;
    min-height: 100vh;
}

.crm-topbar {
    background: rgba(255,255,255,.84);
    backdrop-filter: blur(12px);
    padding: 16px 28px;
    border-bottom: 1px solid var(--crm-border);
    display: flex;
    justify-content: space-between;
    align-items: center;
    position: sticky;
    top: 0;
    z-index: 50;
}

.crm-topbar h1 {
    font-size: 1.3rem;
    font-weight: 700;
}

.crm-topbar-right {
    display: flex;
    align-items: center;
    gap: 14px;
}

.crm-user-chip {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.85rem;
    color: var(--crm-muted);
}

.crm-user-chip strong { color: var(--crm-text); }

/* Search bar */
.crm-search-wrap {
    position: relative;
}

.crm-search-input {
    width: 280px;
    padding: 8px 12px 8px 34px;
    border: 1px solid var(--crm-border);
    border-radius: 8px;
    font-size: 0.85rem;
    font-family: inherit;
    background: var(--crm-white);
    color: var(--crm-text);
    transition: border-color 0.15s, box-shadow 0.15s;
}

.crm-search-input:focus {
    outline: none;
    border-color: var(--crm-primary);
    box-shadow: 0 0 0 3px rgba(0,184,184,0.12);
}

.crm-search-icon {
    position: absolute;
    left: 10px;
    top: 50%;
    transform: translateY(-50%);
    width: 16px;
    height: 16px;
    color: var(--crm-muted);
    pointer-events: none;
}

.crm-search-icon svg {
    width: 16px;
    height: 16px;
    fill: none;
    stroke: currentColor;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.crm-search-results {
    position: absolute;
    top: calc(100% + 6px);
    left: 0;
    right: 0;
    width: 400px;
    background: var(--crm-white);
    border: 1px solid var(--crm-border);
    border-radius: 8px;
    box-shadow: 0 12px 36px rgba(16,36,43,.12);
    z-index: 200;
    max-height: 400px;
    overflow-y: auto;
    display: none;
}

.crm-search-results.visible { display: block; }

.crm-search-group {
    padding: 8px 0;
}

.crm-search-group-title {
    padding: 4px 14px;
    font-size: .7rem;
    font-weight: 800;
    color: var(--crm-muted);
    text-transform: uppercase;
    letter-spacing: .5px;
}

.crm-search-item {
    display: block;
    padding: 8px 14px;
    text-decoration: none;
    color: var(--crm-text);
    font-size: .85rem;
    transition: background .1s;
}

.crm-search-item:hover { background: #f7fbfb; }
.crm-search-item small { color: var(--crm-muted); font-size: .78rem; }

/* Notification bell */
.crm-bell-wrap {
    position: relative;
}

.crm-bell-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    border: 1px solid var(--crm-border);
    border-radius: 8px;
    background: var(--crm-white);
    color: var(--crm-muted);
    cursor: pointer;
    position: relative;
    transition: all .15s;
}

.crm-bell-btn:hover { background: #f7fbfb; color: var(--crm-text); }

.crm-bell-btn svg {
    width: 18px;
    height: 18px;
    fill: none;
    stroke: currentColor;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.crm-bell-badge {
    position: absolute;
    top: -4px;
    right: -4px;
    min-width: 18px;
    height: 18px;
    padding: 0 4px;
    border-radius: 999px;
    background: var(--crm-danger);
    color: white;
    font-size: .65rem;
    font-weight: 800;
    display: flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
}

.crm-bell-dropdown {
    position: absolute;
    top: calc(100% + 6px);
    right: 0;
    width: 340px;
    background: var(--crm-white);
    border: 1px solid var(--crm-border);
    border-radius: 8px;
    box-shadow: 0 12px 36px rgba(16,36,43,.12);
    z-index: 200;
    display: none;
    max-height: 400px;
    overflow-y: auto;
}

.crm-bell-dropdown.visible { display: block; }

.crm-bell-dropdown-header {
    padding: 12px 14px;
    border-bottom: 1px solid var(--crm-border);
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: .85rem;
    font-weight: 700;
}

.crm-bell-dropdown-header button {
    background: none;
    border: none;
    color: var(--crm-primary);
    font-size: .78rem;
    font-weight: 600;
    cursor: pointer;
}

.crm-notif-item {
    display: block;
    padding: 10px 14px;
    border-bottom: 1px solid var(--crm-border);
    text-decoration: none;
    color: var(--crm-text);
    font-size: .82rem;
    transition: background .1s;
}

.crm-notif-item:hover { background: #f7fbfb; }
.crm-notif-item.unread { background: #f0fafa; }
.crm-notif-item strong { display: block; font-size: .82rem; }
.crm-notif-item small { color: var(--crm-muted); font-size: .72rem; }
.crm-notif-empty { padding: 20px 14px; text-align: center; color: var(--crm-muted); font-size: .85rem; }

.crm-content { padding: 28px; }

/* ==========================================================================
   Cards / Stats
   ========================================================================== */

.crm-stats {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 16px;
    margin-bottom: 28px;
}

.crm-stat-card {
    background: var(--crm-white);
    padding: 20px;
    border-radius: 8px;
    border: 1px solid var(--crm-border);
    box-shadow: 0 10px 30px rgba(16,36,43,.05);
}

.crm-stat-card .label {
    font-size: 0.75rem;
    color: var(--crm-muted);
    text-transform: uppercase;
    font-weight: 700;
    letter-spacing: 0.5px;
}

.crm-stat-card .value {
    font-size: 1.8rem;
    font-weight: 800;
    margin-top: 6px;
}

.crm-stat-card .value.green { color: var(--crm-success); }
.crm-stat-card .value.blue { color: var(--crm-primary); }
.crm-stat-card .value.amber { color: var(--crm-warning); }
.crm-stat-card .value.red { color: var(--crm-danger); }

/* ==========================================================================
   Tables
   ========================================================================== */

.crm-table-wrap {
    background: var(--crm-white);
    border-radius: 8px;
    border: 1px solid var(--crm-border);
    box-shadow: 0 10px 30px rgba(16,36,43,.05);
    overflow: hidden;
}

.crm-table-header {
    padding: 16px 20px;
    border-bottom: 1px solid var(--crm-border);
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 10px;
}

.crm-table-header h2 {
    font-size: 1rem;
    font-weight: 700;
}

.crm-table {
    width: 100%;
    border-collapse: collapse;
}

.crm-table th {
    text-align: left;
    padding: 10px 20px;
    font-size: 0.75rem;
    text-transform: uppercase;
    color: #60747c;
    font-weight: 700;
    border-bottom: 1px solid var(--crm-border);
    background: #f6fafb;
}

.crm-table td {
    padding: 12px 20px;
    font-size: 0.88rem;
    border-bottom: 1px solid var(--crm-border);
}

.crm-table tr:last-child td { border-bottom: none; }
.crm-table tr:hover td { background: #f7fbfb; }

/* ==========================================================================
   Buttons
   ========================================================================== */

.crm-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 16px;
    border-radius: 7px;
    font-size: 0.85rem;
    font-weight: 600;
    text-decoration: none;
    border: none;
    cursor: pointer;
    transition: all 0.15s;
    font-family: inherit;
}

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

.crm-btn-outline { background: var(--crm-white); color: var(--crm-text); border: 1px solid var(--crm-border); }
.crm-btn-outline:hover { background: #f1f8f8; color: #007f7f; }

.crm-btn-danger { background: var(--crm-danger); color: var(--crm-white); }
.crm-btn-danger:hover { background: #dc2626; }

.crm-btn-sm { padding: 5px 12px; font-size: 0.8rem; }

.crm-btn:disabled,
.crm-btn-disabled {
    cursor: not-allowed;
    opacity: .5;
    pointer-events: none;
}

.crm-btn-success { background: var(--crm-success); color: var(--crm-white); }
.crm-btn-success:hover { background: #1f9a76; }

/* ==========================================================================
   Status Pills
   ========================================================================== */

.crm-pill {
    display: inline-block;
    padding: 3px 10px;
    border-radius: 999px;
    font-size: 0.75rem;
    font-weight: 700;
}

.crm-pill.pending { background: #fef3c7; color: #92400e; }
.crm-pill.paid { background: #dcfce7; color: #166534; }
.crm-pill.active { background: #dcfce7; color: #166534; }
.crm-pill.draft { background: #e0e7ff; color: #3730a3; }
.crm-pill.open { background: #dbeafe; color: #1e40af; }
.crm-pill.closed { background: #f1f5f9; color: #475569; }
.crm-pill.cancelled { background: #fee2e2; color: #991b1b; }
.crm-pill.rejected { background: #fee2e2; color: #991b1b; }
.crm-pill.completed { background: #dbeafe; color: #1d4ed8; }
.crm-pill.hold { background: #fef3c7; color: #92400e; }
.crm-pill.monitoring { background: #e0f2fe; color: #075985; }
.crm-pill.resolved { background: #dcfce7; color: #166534; }
.crm-pill.sent { background: #e0f2fe; color: #075985; }
.crm-pill.accepted { background: #dcfce7; color: #166534; }
.crm-pill.revisada { background: #dbeafe; color: #1e40af; }
.crm-pill.aprobada { background: #dcfce7; color: #166534; }
.crm-pill.sometida { background: #fef3c7; color: #92400e; }

/* ==========================================================================
   Forms
   ========================================================================== */

.crm-form {
    max-width: 860px;
    background: var(--crm-white);
    padding: 34px;
    border-radius: 8px;
    border: 1px solid var(--crm-border);
    box-shadow: 0 10px 30px rgba(16,36,43,.05);
}

.crm-form label {
    display: block;
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--crm-text);
    margin-bottom: 6px;
    margin-top: 16px;
}

.crm-form label:first-child { margin-top: 0; }

.crm-form input,
.crm-form select,
.crm-form textarea {
    width: 100%;
    padding: 11px 13px;
    border: 1px solid var(--crm-border);
    border-radius: 6px;
    font-size: 0.9rem;
    font-family: inherit;
    transition: border-color 0.15s;
    background: var(--crm-white);
}

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

.crm-form input[readonly],
.crm-form .crm-readonly {
    background: #f1f5f6;
    color: var(--crm-muted);
    cursor: not-allowed;
}

.crm-form textarea { min-height: 100px; resize: vertical; }

.crm-form .form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
}

.form-actions {
    display: flex;
    gap: 12px;
    margin-top: 24px;
    padding-top: 20px;
    border-top: 1px solid var(--crm-border);
}

.crm-fieldset {
    border: 1px solid var(--crm-border);
    border-radius: 8px;
    margin-top: 22px;
    padding: 16px;
}

.crm-fieldset legend {
    padding: 0 8px;
    color: var(--crm-muted);
    font-size: .78rem;
    font-weight: 800;
    text-transform: uppercase;
}

/* Inline form */
.crm-inline-form {
    display: flex;
    align-items: flex-end;
    gap: 12px;
    flex-wrap: wrap;
    margin-top: 20px;
    padding: 20px;
    background: #f7fbfb;
    border-radius: 8px;
    border: 1px solid var(--crm-border);
}

.crm-inline-form label {
    display: grid;
    gap: 5px;
    color: var(--crm-muted);
    font-size: .78rem;
    font-weight: 700;
    margin: 0;
}

.crm-inline-form input,
.crm-inline-form select,
.crm-inline-form textarea {
    min-width: 200px;
    padding: 9px 11px;
    border: 1px solid var(--crm-border);
    border-radius: 6px;
    font: inherit;
    font-size: .85rem;
}

.crm-inline-form textarea {
    min-width: 300px;
    min-height: 60px;
}

/* ==========================================================================
   Alerts
   ========================================================================== */

.crm-alert {
    padding: 12px 16px;
    border-radius: 8px;
    background: #fee2e2;
    color: #991b1b;
    font-size: .85rem;
    font-weight: 500;
    margin-bottom: 20px;
    border-left: 3px solid var(--crm-danger);
}

.crm-success-banner {
    padding: 12px 16px;
    border-radius: 8px;
    background: #dcfce7;
    color: #166534;
    font-size: .85rem;
    font-weight: 500;
    margin-bottom: 20px;
    border-left: 3px solid var(--crm-success);
}

/* ==========================================================================
   Detail grid
   ========================================================================== */

.crm-detail-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 16px;
    margin: 20px 0;
    padding: 20px;
    background: #f7fbfb;
    border-radius: 8px;
    border: 1px solid var(--crm-border);
}

.crm-detail-grid > div .label {
    font-size: .72rem;
    font-weight: 800;
    color: var(--crm-muted);
    text-transform: uppercase;
    letter-spacing: .5px;
    margin-bottom: 3px;
}

.crm-detail-grid > div .value {
    font-size: .92rem;
    font-weight: 600;
    color: var(--crm-text);
}

.crm-section {
    margin-top: 20px;
    padding: 20px;
    background: var(--crm-white);
    border-radius: 8px;
    border: 1px solid var(--crm-border);
}

.crm-section h3 {
    font-size: .92rem;
    font-weight: 700;
    margin-bottom: 10px;
    color: var(--crm-text);
}

.crm-section p {
    font-size: .88rem;
    line-height: 1.6;
    color: var(--crm-muted);
}

/* ==========================================================================
   Two column layout
   ========================================================================== */

.crm-two-col {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
}

/* ==========================================================================
   Quick links
   ========================================================================== */

.crm-quick-links {
    display: flex;
    gap: 10px;
    margin-bottom: 20px;
    flex-wrap: wrap;
}

.crm-quick-link {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 16px;
    border-radius: 7px;
    font-size: .85rem;
    font-weight: 600;
    text-decoration: none;
    background: var(--crm-white);
    color: var(--crm-primary-dark);
    border: 1px solid var(--crm-border);
    transition: all .15s;
}

.crm-quick-link:hover {
    background: #e7f4f4;
    border-color: var(--crm-primary);
    color: #007f7f;
}

/* ==========================================================================
   Timeline
   ========================================================================== */

.crm-timeline {
    padding: 16px 20px;
}

.crm-timeline-item {
    padding: 14px 0;
    border-bottom: 1px solid var(--crm-border);
}

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

.crm-timeline-item > div:first-child {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 6px;
}

.crm-timeline-item strong {
    font-size: .82rem;
    font-weight: 700;
    color: var(--crm-text);
}

.crm-timeline-item span {
    font-size: .72rem;
    font-weight: 700;
    color: var(--crm-muted);
}

.crm-timeline-item p {
    font-size: .85rem;
    line-height: 1.5;
    color: var(--crm-muted);
    white-space: pre-wrap;
}

.crm-timeline-item img {
    max-width: 200px;
    border-radius: 6px;
    margin-top: 8px;
    border: 1px solid var(--crm-border);
}

.crm-timeline-item .timeline-mod-type {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 999px;
    font-size: .68rem;
    font-weight: 800;
    text-transform: uppercase;
    margin-left: 6px;
}

.timeline-mod-type.creacion { background: #dbeafe; color: #1e40af; }
.timeline-mod-type.edicion { background: #fef3c7; color: #92400e; }
.timeline-mod-type.comentario { background: #f1f5f9; color: #475569; }
.timeline-mod-type.cambio_etapa { background: #e0f2fe; color: #075985; }
.timeline-mod-type.aprobacion { background: #dcfce7; color: #166534; }

.crm-empty { color: var(--crm-muted); font-size: .85rem; padding: 16px 0; text-align: center; }

/* ==========================================================================
   Stepper (Legal workflow)
   ========================================================================== */

.legal-stepper {
    display: flex;
    align-items: center;
    gap: 0;
    margin: 24px 0;
    padding: 20px;
    background: var(--crm-white);
    border-radius: 8px;
    border: 1px solid var(--crm-border);
    overflow-x: auto;
}

.stepper-step {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    flex: 1;
    min-width: 140px;
    position: relative;
}

.stepper-step::after {
    content: "";
    position: absolute;
    top: 18px;
    left: calc(50% + 22px);
    right: calc(-50% + 22px);
    height: 3px;
    background: var(--crm-border);
}

.stepper-step:last-child::after { display: none; }

.stepper-step.completed::after { background: var(--crm-success); }
.stepper-step.active::after { background: var(--crm-primary); }

.stepper-circle {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: .85rem;
    font-weight: 800;
    background: var(--crm-border);
    color: var(--crm-muted);
    z-index: 1;
    transition: all .2s;
}

.stepper-step.completed .stepper-circle { background: var(--crm-success); color: white; }
.stepper-step.active .stepper-circle { background: var(--crm-primary); color: white; box-shadow: 0 0 0 4px rgba(0,184,184,.2); }

.stepper-label {
    font-size: .78rem;
    font-weight: 700;
    color: var(--crm-muted);
    text-align: center;
    text-transform: uppercase;
    letter-spacing: .3px;
}

.stepper-step.active .stepper-label { color: var(--crm-primary-dark); }
.stepper-step.completed .stepper-label { color: var(--crm-success); }

/* ==========================================================================
   Invoice lines
   ========================================================================== */

.crm-items-list {
    margin-top: 12px;
}

.crm-item-row {
    display: grid;
    grid-template-columns: 2fr 1.2fr 0.8fr 1fr 1fr auto;
    gap: 10px;
    align-items: end;
    padding: 12px;
    border: 1px solid var(--crm-border);
    border-radius: 8px;
    margin-bottom: 8px;
    background: #fafcfc;
}

.crm-item-row label {
    display: grid;
    gap: 4px;
    margin: 0 !important;
}

.crm-item-row label span {
    font-size: .72rem;
    font-weight: 700;
    color: var(--crm-muted);
    text-transform: uppercase;
}

.crm-item-row input,
.crm-item-row select {
    padding: 8px 10px;
    border: 1px solid var(--crm-border);
    border-radius: 6px;
    font: inherit;
    font-size: .85rem;
}

.crm-item-row input:focus,
.crm-item-row select:focus {
    outline: none;
    border-color: var(--crm-primary);
    box-shadow: 0 0 0 3px rgba(0,184,184,.1);
}

.invoice-line-total {
    display: grid;
    gap: 4px;
}

.invoice-line-total span {
    font-size: .72rem;
    font-weight: 700;
    color: var(--crm-muted);
    text-transform: uppercase;
}

.invoice-line-total strong {
    font-size: 1rem;
    color: var(--crm-text);
}

.invoice-line-tax-detail {
    font-size: .72rem;
    color: var(--crm-muted);
}

.invoice-live-totals {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 16px;
    margin-top: 16px;
    padding: 16px;
    background: #f7fbfb;
    border-radius: 8px;
    border: 1px solid var(--crm-border);
}

.invoice-live-totals > div {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: .85rem;
}

.invoice-live-totals > div span { color: var(--crm-muted); font-weight: 600; }
.invoice-live-totals > div strong { font-weight: 800; color: var(--crm-text); }
.invoice-live-totals > div.grand { border-top: 2px solid var(--crm-border); padding-top: 10px; }
.invoice-live-totals > div.grand strong { font-size: 1.2rem; color: var(--crm-primary-dark); }

.invoice-items-heading {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 24px;
}

.invoice-items-title {
    font-size: .92rem;
    font-weight: 700;
    color: var(--crm-text);
}

.invoice-price-mode {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: .82rem;
    color: var(--crm-muted);
}

.invoice-price-mode select {
    padding: 6px 10px;
    border: 1px solid var(--crm-border);
    border-radius: 6px;
    font: inherit;
    font-size: .82rem;
}

.invoice-fiscal-panel {
    padding: 22px;
    margin-bottom: 20px;
    border-left: 3px solid var(--crm-primary);
    background: #f7fbfb;
    border-radius: 0 8px 8px 0;
}

.invoice-fiscal-head {
    margin-bottom: 16px;
}

.crm-kicker {
    font-size: .7rem;
    font-weight: 850;
    text-transform: uppercase;
    color: var(--crm-primary);
    letter-spacing: .5px;
}

.invoice-document-grid,
.invoice-activity-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
    margin-bottom: 16px;
}

.invoice-document-grid label,
.invoice-activity-grid label {
    display: grid;
    gap: 5px;
    font-size: .82rem;
    font-weight: 600;
    color: var(--crm-text);
}

.invoice-document-grid input,
.invoice-document-grid select,
.invoice-activity-grid input,
.invoice-activity-grid select {
    padding: 10px 12px;
    border: 1px solid var(--crm-border);
    border-radius: 6px;
    font: inherit;
    font-size: .88rem;
}

.invoice-company-row {
    display: flex;
    align-items: flex-end;
    gap: 12px;
}

.invoice-company-row > div { flex: 1; }

.crm-check {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: .85rem;
    color: var(--crm-muted);
    cursor: pointer;
}

.crm-check input[type="checkbox"] {
    width: 18px;
    height: 18px;
    accent-color: var(--crm-primary);
}

.invoice-profile-summary {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: 12px;
    margin-top: 16px;
    padding: 16px;
    background: var(--crm-white);
    border-radius: 8px;
    border: 1px solid var(--crm-border);
}

.invoice-profile-summary > div {
    display: grid;
    gap: 3px;
}

.invoice-profile-summary span {
    font-size: .7rem;
    font-weight: 800;
    color: var(--crm-muted);
    text-transform: uppercase;
}

.invoice-profile-summary strong {
    font-size: .85rem;
    color: var(--crm-text);
    word-break: break-word;
}

.dte-local-notice {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 14px;
    border-radius: 6px;
    background: #e7f4f4;
    font-size: .82rem;
    color: var(--crm-muted);
}

.dte-local-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--crm-primary);
    flex-shrink: 0;
}

.invoice-section {
    margin-top: 22px;
}

/* ==========================================================================
   Filters / Sort bar
   ========================================================================== */

.crm-filter-bar {
    display: flex;
    align-items: flex-end;
    gap: 10px;
    flex-wrap: wrap;
    margin-bottom: 20px;
    padding: 16px 20px;
    background: var(--crm-white);
    border-radius: 8px;
    border: 1px solid var(--crm-border);
    box-shadow: 0 6px 18px rgba(16,36,43,.04);
}

.crm-filter-bar label {
    display: grid;
    gap: 4px;
    font-size: .72rem;
    font-weight: 750;
    color: var(--crm-muted);
}

.crm-filter-bar input,
.crm-filter-bar select {
    padding: 8px 10px;
    border: 1px solid var(--crm-border);
    border-radius: 6px;
    font: inherit;
    font-size: .85rem;
    min-width: 140px;
}

.crm-filter-bar input[type="search"] {
    min-width: 240px;
}

/* ==========================================================================
   Pagination
   ========================================================================== */

.crm-pagination {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    margin-top: 20px;
    padding: 16px 0;
}

.crm-pagination a,
.crm-pagination span {
    padding: 6px 14px;
    border: 1px solid var(--crm-border);
    border-radius: 6px;
    font-size: .82rem;
    font-weight: 500;
    text-decoration: none;
    color: var(--crm-text);
    transition: all .15s;
}

.crm-pagination a:hover { background: #f1f8f8; border-color: var(--crm-primary); }
.crm-pagination span.current { background: var(--crm-primary); color: white; border-color: var(--crm-primary); }
.crm-pagination span.disabled { color: var(--crm-muted); opacity: .5; pointer-events: none; }

/* ==========================================================================
   Multimedia
   ========================================================================== */

.multimedia-drop-zone {
    border: 2px dashed var(--crm-border);
    border-radius: 8px;
    padding: 40px 20px;
    text-align: center;
    background: #fafcfc;
    transition: all .2s;
    cursor: pointer;
    margin-bottom: 20px;
}

.multimedia-drop-zone.dragover {
    border-color: var(--crm-primary);
    background: #e7f4f4;
}

.multimedia-drop-zone p {
    color: var(--crm-muted);
    font-size: .92rem;
    margin-bottom: 10px;
}

.multimedia-drop-zone .drop-icon {
    width: 48px;
    height: 48px;
    margin: 0 auto 12px;
    color: var(--crm-primary);
}

.multimedia-drop-zone .drop-icon svg {
    width: 48px;
    height: 48px;
    fill: none;
    stroke: currentColor;
    stroke-width: 1.5;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.multimedia-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 16px;
}

.multimedia-card {
    border: 1px solid var(--crm-border);
    border-radius: 8px;
    overflow: hidden;
    background: var(--crm-white);
    transition: box-shadow .15s;
}

.multimedia-card:hover {
    box-shadow: 0 8px 24px rgba(16,36,43,.08);
}

.multimedia-card-thumb {
    width: 100%;
    aspect-ratio: 16/10;
    object-fit: cover;
    display: block;
    background: #f1f5f9;
}

.multimedia-card-video-icon {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 40px;
    height: 40px;
    background: rgba(0,0,0,.6);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
}

.multimedia-card-body {
    padding: 10px 12px;
}

.multimedia-card-body strong {
    font-size: .82rem;
    display: block;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.multimedia-card-body small {
    font-size: .72rem;
    color: var(--crm-muted);
}

/* ==========================================================================
   LAP-E Chat
   ========================================================================== */

.lape-chat-container {
    max-width: 800px;
    margin: 0 auto;
    height: calc(100vh - 200px);
    display: flex;
    flex-direction: column;
    background: var(--crm-white);
    border-radius: 8px;
    border: 1px solid var(--crm-border);
    box-shadow: 0 10px 30px rgba(16,36,43,.05);
    overflow: hidden;
}

.lape-chat-header {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 16px 20px;
    border-bottom: 1px solid var(--crm-border);
    background: #f7fbfb;
}

.lape-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--crm-primary), var(--crm-primary-dark));
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-weight: 900;
    font-size: .9rem;
    flex-shrink: 0;
}

.lape-chat-header strong {
    font-size: 1rem;
    display: block;
}

.lape-chat-header small {
    font-size: .78rem;
    color: var(--crm-muted);
}

.lape-messages {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.lape-msg {
    display: flex;
    gap: 10px;
    max-width: 85%;
}

.lape-msg.user {
    align-self: flex-end;
    flex-direction: row-reverse;
}

.lape-msg-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: .72rem;
    font-weight: 800;
}

.lape-msg.assistant .lape-msg-avatar {
    background: linear-gradient(135deg, var(--crm-primary), var(--crm-primary-dark));
    color: white;
}

.lape-msg.user .lape-msg-avatar {
    background: var(--crm-border);
    color: var(--crm-text);
}

.lape-msg-bubble {
    padding: 12px 16px;
    border-radius: 12px;
    font-size: .88rem;
    line-height: 1.5;
    white-space: pre-wrap;
    word-wrap: break-word;
}

.lape-msg.assistant .lape-msg-bubble {
    background: #f1f5f9;
    color: var(--crm-text);
    border-bottom-left-radius: 4px;
}

.lape-msg.user .lape-msg-bubble {
    background: var(--crm-primary);
    color: white;
    border-bottom-right-radius: 4px;
}

.lape-form {
    display: flex;
    gap: 10px;
    padding: 16px 20px;
    border-top: 1px solid var(--crm-border);
    background: var(--crm-white);
}

.lape-form input {
    flex: 1;
    padding: 10px 14px;
    border: 1px solid var(--crm-border);
    border-radius: 8px;
    font: inherit;
    font-size: .88rem;
}

.lape-form input:focus {
    outline: none;
    border-color: var(--crm-primary);
    box-shadow: 0 0 0 3px rgba(0,184,184,.1);
}

.lape-form button {
    padding: 10px 20px;
    border-radius: 8px;
    background: var(--crm-primary);
    color: white;
    border: none;
    font: inherit;
    font-size: .88rem;
    font-weight: 600;
    cursor: pointer;
    transition: background .15s;
}

.lape-form button:hover { background: var(--crm-primary-dark); }
.lape-form button:disabled { opacity: .5; cursor: not-allowed; }

.lape-typing {
    display: flex;
    gap: 4px;
    padding: 8px 16px;
}

.lape-typing span {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--crm-muted);
    animation: lape-typing 1.2s infinite ease-in-out;
}

.lape-typing span:nth-child(2) { animation-delay: .2s; }
.lape-typing span:nth-child(3) { animation-delay: .4s; }

@keyframes lape-typing {
    0%, 60%, 100% { transform: translateY(0); opacity: .4; }
    30% { transform: translateY(-6px); opacity: 1; }
}

/* ==========================================================================
   Login — Replica exacta del CRM-ERP
   ========================================================================== */

.crm-login-page {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    min-height: 100svh;
    padding: max(24px, env(safe-area-inset-top)) 18px max(24px, env(safe-area-inset-bottom));
    background:
        linear-gradient(180deg, rgba(5, 6, 7, 0.78) 0%, rgba(47, 62, 70, 0.56) 100%),
        url("/static/images/hero-background.jpg") center / cover no-repeat;
    isolation: isolate;
    overflow-x: hidden;
    overflow-y: auto;
    position: relative;
    font-family: Inter, system-ui, -apple-system, sans-serif;
}

.lightning-layer {
    position: absolute;
    inset: 0;
    z-index: 1;
    pointer-events: none;
    overflow: hidden;
}

.lightning {
    position: absolute;
    width: 78vw;
    height: 3px;
    opacity: 0;
    border-radius: 999px;
    background: linear-gradient(
        90deg,
        transparent 0%,
        rgba(0, 184, 184, 0.08) 16%,
        rgba(32, 211, 208, 0.8) 48%,
        rgba(255, 255, 255, 0.86) 52%,
        rgba(0, 184, 184, 0.12) 82%,
        transparent 100%
    );
    filter:
        blur(0.2px)
        drop-shadow(0 0 8px rgba(32, 211, 208, 0.76))
        drop-shadow(0 0 24px rgba(0, 184, 184, 0.5))
        drop-shadow(0 0 54px rgba(255, 255, 255, 0.24));
    animation-name: neon-cross;
    animation-iteration-count: infinite;
    animation-timing-function: ease-in-out;
}

.lightning::before {
    content: "";
    position: absolute;
    inset: -18px 0;
    border-radius: inherit;
    background: linear-gradient(
        90deg,
        transparent 0%,
        rgba(45, 212, 191, 0.03) 20%,
        rgba(45, 212, 191, 0.22) 50%,
        rgba(45, 212, 191, 0.03) 80%,
        transparent 100%
    );
    filter: blur(18px);
}

.lightning-one {
    top: 22%;
    left: -82vw;
    transform: rotate(-14deg);
    animation-duration: 8s;
}

.lightning-two {
    top: 58%;
    left: -88vw;
    transform: rotate(12deg);
    animation-duration: 10.5s;
    animation-delay: 2.4s;
}

.lightning-three {
    top: 78%;
    left: -80vw;
    transform: rotate(-7deg);
    animation-duration: 12s;
    animation-delay: 5s;
}

@keyframes neon-cross {
    0% {
        opacity: 0;
        translate: 0 0;
    }
    12% {
        opacity: 0.85;
    }
    42% {
        opacity: 0.95;
    }
    70% {
        opacity: 0.18;
    }
    100% {
        opacity: 0;
        translate: 190vw 0;
    }
}

.crm-login-card {
    position: relative;
    z-index: 2;
    background: var(--crm-white);
    padding: 40px;
    border-radius: 12px;
    width: 400px;
    box-shadow: 0 20px 60px rgba(0,0,0,0.3);
    text-align: center;
}

.crm-login-brand {
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 18px;
}

.crm-login-brand img {
    width: 230px;
    max-width: 82%;
    height: auto;
    object-fit: contain;
}

.crm-login-card .subtitle {
    color: var(--crm-muted);
    margin-bottom: 24px;
    font-size: 0.9rem;
}

.crm-login-card .error {
    background: #fee2e2;
    color: #991b1b;
    padding: 10px;
    border-radius: 6px;
    font-size: 0.85rem;
    margin-bottom: 12px;
}

.microsoft-login-button {
    width: 100%;
    min-height: 48px;
    padding: 12px 16px;
    background: #fff;
    color: #1f2933;
    border: 1px solid #8c959f;
    border-radius: 6px;
    font-size: 0.95rem;
    font-weight: 700;
    cursor: pointer;
    font-family: inherit;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    text-decoration: none;
    transition: border-color 0.15s, box-shadow 0.15s, background 0.15s;
}

.microsoft-login-button:hover {
    background: #f6f8fa;
    border-color: #374151;
    box-shadow: 0 2px 8px rgba(15, 23, 42, 0.12);
}

.microsoft-login-button.is-disabled {
    cursor: not-allowed;
    color: #7b8794;
    background: #f2f4f6;
    border-color: #d5dae0;
}

.microsoft-mark {
    width: 18px;
    height: 18px;
    display: grid;
    grid-template-columns: repeat(2, 8px);
    grid-template-rows: repeat(2, 8px);
    gap: 2px;
    flex: 0 0 18px;
}

.microsoft-mark span:nth-child(1) { background: #f25022; }
.microsoft-mark span:nth-child(2) { background: #7fba00; }
.microsoft-mark span:nth-child(3) { background: #00a4ef; }
.microsoft-mark span:nth-child(4) { background: #ffb900; }

.login-security-note,
.login-setup-note {
    color: var(--crm-muted);
    font-size: 0.78rem;
    line-height: 1.45;
}

.login-security-note {
    margin: 16px 0 0;
}

.login-setup-note {
    margin: 12px 0 0;
}

@media (prefers-reduced-motion: reduce) {
    .lightning {
        animation: none;
    }
}

@supports (min-height: 100dvh) {
    .crm-login-page {
        min-height: 100dvh;
    }
}

@media (max-width: 600px) {
    .crm-login-page {
        align-items: center;
        background-position: center;
    }

    .crm-login-card {
        width: min(100%, 360px);
        padding: 28px 20px;
        border-radius: 18px;
    }

    .crm-login-brand {
        margin-bottom: 14px;
    }

    .crm-login-brand img {
        width: min(178px, 72%);
    }

    .crm-login-card .subtitle {
        margin-bottom: 20px;
    }

    .microsoft-login-button {
        min-height: 48px;
        padding: 12px;
        font-size: 0.9rem;
    }

    .lightning-layer {
        opacity: 0.55;
    }
}

@media (max-width: 600px) and (max-height: 620px) {
    .crm-login-page {
        align-items: flex-start;
    }
}

/* ==========================================================================
   Toast notifications
   ========================================================================== */

.crm-flash-stack {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 10000;
    display: grid;
    gap: 10px;
    width: min(420px, calc(100vw - 32px));
    pointer-events: none;
}

.crm-flash {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 16px;
    padding: 13px 14px;
    border: 1px solid var(--crm-border);
    border-left: 4px solid var(--crm-primary);
    border-radius: 7px;
    background: var(--crm-surface, #fff);
    box-shadow: 0 16px 40px rgba(15, 32, 40, .18);
    color: var(--crm-text);
    font-size: .86rem;
    line-height: 1.45;
    pointer-events: auto;
}

.crm-flash--warning {
    border-left-color: #d39a17;
}

.crm-flash--success {
    border-left-color: var(--crm-success);
}

.crm-flash button {
    border: 0;
    background: transparent;
    color: var(--crm-muted);
    cursor: pointer;
    font: inherit;
    font-size: 1.2rem;
    line-height: 1;
}

@media (max-width: 640px) {
    .crm-flash-stack {
        top: 12px;
        right: 16px;
        left: 16px;
        width: auto;
    }
}

.toast-container {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 9999;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.toast {
    padding: 12px 18px;
    border-radius: 8px;
    font-size: .85rem;
    font-weight: 500;
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 280px;
    box-shadow: 0 8px 24px rgba(0,0,0,.12);
    animation: toast-in .3s ease;
}

.toast.success {
    background: #dcfce7;
    color: #166534;
    border-left: 3px solid var(--crm-success);
}

.toast.error {
    background: #fee2e2;
    color: #991b1b;
    border-left: 3px solid var(--crm-danger);
}

.toast.info {
    background: #e0f2fe;
    color: #075985;
    border-left: 3px solid #0ea5e9;
}

.toast-close {
    margin-left: auto;
    background: none;
    border: none;
    font-size: 1.1rem;
    cursor: pointer;
    color: inherit;
    opacity: .6;
}

.toast-close:hover { opacity: 1; }

@keyframes toast-in {
    from { opacity: 0; transform: translateX(20px); }
    to { opacity: 1; transform: translateX(0); }
}

/* ==========================================================================
   Developer placeholder
   ========================================================================== */

.dev-placeholder {
    text-align: center;
    padding: 80px 40px;
}

.dev-placeholder h2 {
    font-size: 1.8rem;
    font-weight: 800;
    color: var(--crm-text);
    margin-bottom: 12px;
}

.dev-placeholder p {
    color: var(--crm-muted);
    font-size: 1rem;
    max-width: 500px;
    margin: 0 auto 30px;
    line-height: 1.6;
}

.dev-ideas {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 16px;
    max-width: 800px;
    margin: 0 auto;
}

.dev-idea-card {
    padding: 20px;
    background: var(--crm-white);
    border: 1px solid var(--crm-border);
    border-radius: 8px;
    text-align: left;
}

.dev-idea-card strong {
    display: block;
    font-size: .92rem;
    margin-bottom: 6px;
}

.dev-idea-card p {
    font-size: .82rem;
    margin: 0;
}

/* ==========================================================================
   Settings
   ========================================================================== */

.settings-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 24px;
}

.settings-card {
    background: var(--crm-white);
    border: 1px solid var(--crm-border);
    border-radius: 8px;
    padding: 28px;
    box-shadow: 0 10px 30px rgba(16,36,43,.05);
}

.settings-card h2 {
    font-size: 1.05rem;
    font-weight: 700;
    margin-bottom: 20px;
    padding-bottom: 12px;
    border-bottom: 1px solid var(--crm-border);
}

/* ==========================================================================
   Responsive
   ========================================================================== */

.billing-dossier {
    display: grid;
    gap: 20px;
    max-width: 1100px;
    padding: 24px;
    background: var(--crm-white);
    border: 1px solid var(--crm-border);
    border-radius: 8px;
}

.billing-dossier-head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 20px;
}

.billing-dossier-head h2,
.billing-dossier-head p { margin: 3px 0; }

.billing-dossier-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 1px;
    overflow: hidden;
    border: 1px solid var(--crm-border);
    border-radius: 6px;
    background: var(--crm-border);
}

.billing-dossier-grid > div {
    display: grid;
    gap: 5px;
    padding: 14px;
    background: var(--crm-white);
}

.billing-dossier-grid span,
.billing-timeline span { color: var(--crm-muted); font-size: .72rem; }
.billing-document-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.billing-correction-form {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(240px, .45fr) auto;
    gap: 14px;
    align-items: end;
    padding: 18px;
    border: 1px solid #f0c9a9;
    background: #fffaf5;
}
.billing-correction-form label {
    display: block;
    margin-bottom: 6px;
    color: #243743;
    font-size: 13px;
    font-weight: 700;
}
.billing-correction-form label span { color: #667985; font-weight: 500; }
.billing-correction-form textarea,
.billing-correction-form input[type="file"] { width: 100%; }
.billing-timeline { display: grid; gap: 0; border-top: 1px solid var(--crm-border); }
.billing-timeline h3 { margin: 18px 0 8px; font-size: .95rem; }
.billing-timeline > div { display: grid; gap: 3px; padding: 10px 0; border-bottom: 1px solid var(--crm-border); }
.billing-timeline p { margin: 0; color: var(--crm-muted); font-size: .8rem; }

@media (max-width: 768px) {
    .crm-sidebar {
        width: 60px;
    }

    .crm-sidebar-brand img { display: none; }
    .crm-sidebar-brand span { display: none; }
    .crm-sidebar-nav a span:not(.icon) { display: none; }
    .crm-sidebar-nav a .icon { margin: 0 auto; }
    .crm-sidebar-nav a { justify-content: center; padding: 10px; margin: 0 5px; }
    .crm-admin-card div,
    .crm-admin-settings { display: none; }
    .crm-link-button span:last-child { display: none; }

    .crm-main {
        margin-left: 60px;
    }

    .crm-content { padding: 16px; }
    .crm-form .form-row { grid-template-columns: 1fr; }
    .crm-two-col { grid-template-columns: 1fr; }
    .settings-grid { grid-template-columns: 1fr; }
    .invoice-document-grid,
    .invoice-activity-grid { grid-template-columns: 1fr; }

    .crm-item-row {
        grid-template-columns: 1fr;
    }

    .invoice-live-totals {
        grid-template-columns: 1fr;
    }

    .crm-search-input { width: 180px; }
    .crm-search-results { width: 300px; }

    .crm-filter-bar {
        flex-direction: column;
        align-items: stretch;
    }

    .billing-dossier-grid { grid-template-columns: 1fr 1fr; }
    .billing-correction-form { grid-template-columns: 1fr; align-items: stretch; }

    .legal-stepper { flex-direction: column; gap: 16px; }
    .stepper-step::after { display: none; }

    .mm-project-grid { grid-template-columns: 1fr; }
    .mm-file-grid { grid-template-columns: 1fr; }
}

/* ==========================================================================
   Multimedia — Project Workflow
   ========================================================================== */

.mm-project-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 16px;
}

.mm-project-card {
    display: block;
    background: var(--crm-white);
    border: 1px solid var(--crm-border);
    border-radius: 10px;
    overflow: hidden;
    text-decoration: none;
    color: var(--crm-text);
    transition: box-shadow .2s, border-color .2s;
}

.mm-project-card:hover {
    box-shadow: 0 8px 28px rgba(0,184,184,.12);
    border-color: var(--crm-primary);
}

.mm-project-thumb {
    width: 100%;
    aspect-ratio: 16/9;
    overflow: hidden;
    background: #f1f5f9;
    display: flex;
    align-items: center;
    justify-content: center;
}

.mm-project-thumb img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.mm-project-thumb-empty {
    color: var(--crm-muted);
    opacity: .4;
}

.mm-project-body {
    padding: 14px 16px;
    display: grid;
    gap: 6px;
}

.mm-project-body strong {
    font-size: .92rem;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.mm-project-meta {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
    font-size: .78rem;
    color: var(--crm-muted);
}

.mm-project-body small {
    font-size: .75rem;
    color: var(--crm-muted);
}

/* File grid */
.mm-file-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
    gap: 16px;
    padding: 16px 20px;
}

.mm-file-card {
    border: 1px solid var(--crm-border);
    border-radius: 8px;
    overflow: hidden;
    background: var(--crm-white);
}

.mm-file-card-resultado {
    border-color: var(--crm-success);
    box-shadow: 0 0 0 1px rgba(39,180,138,.15);
}

.mm-file-preview {
    width: 100%;
    aspect-ratio: 16/10;
    overflow: hidden;
    background: #f1f5f9;
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
}

.mm-file-preview img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.mm-file-preview video {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.mm-file-video {
    cursor: pointer;
}

.mm-file-play {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: rgba(0,0,0,.6);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
    pointer-events: none;
}

.mm-file-generic {
    font-size: 2.5rem;
    color: var(--crm-muted);
}

.mm-file-info {
    padding: 10px 12px;
    display: grid;
    gap: 3px;
}

.mm-file-info strong {
    font-size: .82rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.mm-file-info small {
    font-size: .72rem;
    color: var(--crm-muted);
}

/* ==========================================================================
   Upload Zone (custom file input)
   ========================================================================== */

.mm-upload-zone {
    border: 2px dashed var(--crm-border);
    border-radius: 10px;
    padding: 16px;
    background: #fafcfc;
    transition: all .2s;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    width: 100%;
}

.mm-upload-zone.dragover {
    border-color: var(--crm-primary);
    background: #e7f4f4;
}

.mm-upload-zone-success.dragover {
    border-color: var(--crm-success);
    background: #e8f8f0;
}

.mm-upload-zone-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    cursor: pointer;
    color: var(--crm-muted);
    text-align: center;
    padding: 8px 0;
    transition: color .15s;
    width: 100%;
}

.mm-upload-zone-content:hover {
    color: var(--crm-primary);
}

.mm-upload-zone-success .mm-upload-zone-content:hover {
    color: var(--crm-success);
}

.mm-upload-zone-content svg {
    opacity: .6;
    transition: opacity .15s;
}

.mm-upload-zone-content:hover svg {
    opacity: 1;
}

.mm-upload-text {
    font-size: .88rem;
}

.mm-upload-text strong {
    color: var(--crm-primary);
}

.mm-upload-zone-success .mm-upload-text strong {
    color: var(--crm-success);
}

.mm-upload-hint {
    font-size: .75rem;
    color: var(--crm-muted);
}

.mm-upload-preview {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    width: 100%;
}

.mm-upload-preview:empty {
    display: none;
}

.mm-upload-file-tag {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 5px 12px;
    background: var(--crm-white);
    border: 1px solid var(--crm-border);
    border-radius: 999px;
    font-size: .78rem;
    color: var(--crm-text);
    animation: fadeUp .2s ease;
}

.mm-upload-file-tag .tag-icon {
    font-size: .9rem;
}

.mm-upload-file-tag .tag-size {
    color: var(--crm-muted);
    font-size: .7rem;
}

.mm-upload-file-tag .tag-remove {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    border: none;
    background: #fee2e2;
    color: #991b1b;
    font-size: .7rem;
    cursor: pointer;
    line-height: 1;
    padding: 0;
    transition: background .1s;
}

.mm-upload-file-tag .tag-remove:hover {
    background: #fca5a5;
}

.mm-upload-btn {
    margin-top: 4px;
}

.mm-spinner {
    display: inline-block;
    width: 14px;
    height: 14px;
    border: 2px solid rgba(255,255,255,.3);
    border-top-color: white;
    border-radius: 50%;
    animation: spin .6s linear infinite;
    vertical-align: middle;
    margin-right: 4px;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

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

/* ==========================================================================
   Project Card Wrapper + Gear Icon
   ========================================================================== */

.mm-project-card-wrap {
    position: relative;
}

.mm-project-gear {
    position: absolute;
    top: 8px;
    right: 8px;
    width: 32px;
    height: 32px;
    border-radius: 8px;
    border: none;
    background: rgba(255,255,255,.85);
    backdrop-filter: blur(6px);
    color: var(--crm-muted);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transition: all .2s;
    z-index: 2;
    box-shadow: 0 2px 8px rgba(0,0,0,.08);
}

.mm-project-card-wrap:hover .mm-project-gear {
    opacity: 1;
}

.mm-project-gear:hover {
    background: var(--crm-white);
    color: var(--crm-primary);
    transform: rotate(45deg);
    box-shadow: 0 4px 12px rgba(0,0,0,.12);
}

/* ==========================================================================
   Project Management Modal
   ========================================================================== */

.mm-modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.45);
    backdrop-filter: blur(4px);
    z-index: 1000;
    display: none;
    align-items: center;
    justify-content: center;
    animation: modalFadeIn .2s ease;
}

.mm-modal-backdrop.visible {
    display: flex;
}

@keyframes modalFadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

.mm-modal {
    background: var(--crm-white);
    border-radius: 12px;
    width: 480px;
    max-width: 92vw;
    max-height: 85vh;
    overflow-y: auto;
    box-shadow: 0 20px 60px rgba(0,0,0,.2);
    animation: modalSlideUp .25s ease;
}

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

.mm-modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px 24px 16px;
    border-bottom: 1px solid var(--crm-border);
}

.mm-modal-header h3 {
    font-size: 1.05rem;
    font-weight: 700;
}

.mm-modal-close {
    width: 32px;
    height: 32px;
    border-radius: 8px;
    border: none;
    background: transparent;
    color: var(--crm-muted);
    font-size: 1.3rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all .15s;
}

.mm-modal-close:hover {
    background: #f1f5f9;
    color: var(--crm-text);
}

.mm-modal-body {
    padding: 20px 24px;
    display: grid;
    gap: 4px;
}

.mm-modal-body label {
    font-size: .82rem;
    font-weight: 700;
    color: var(--crm-muted);
    text-transform: uppercase;
    letter-spacing: .3px;
    margin-top: 10px;
}

.mm-modal-body label:first-child {
    margin-top: 0;
}

.mm-modal-body input,
.mm-modal-body textarea,
.mm-modal-body select {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--crm-border);
    border-radius: 6px;
    font: inherit;
    font-size: .88rem;
    transition: border-color .15s;
}

.mm-modal-body input:focus,
.mm-modal-body textarea:focus,
.mm-modal-body select:focus {
    outline: none;
    border-color: var(--crm-primary);
    box-shadow: 0 0 0 3px rgba(0,184,184,.1);
}

.mm-modal-body textarea {
    resize: vertical;
    min-height: 80px;
}

.mm-modal-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 24px;
    border-top: 1px solid var(--crm-border);
    background: #fafcfc;
    border-radius: 0 0 12px 12px;
}
/* Employee profile settings */
.settings-grid {
    display: grid;
    grid-template-columns: minmax(0, 1.55fr) minmax(300px, .8fr);
    gap: 24px;
    align-items: start;
}

.settings-card {
    min-width: 0;
}

.settings-card-heading {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: 24px;
    padding-bottom: 18px;
    margin-bottom: 24px;
    border-bottom: 1px solid var(--crm-border, #d5e0e3);
}

.settings-card-heading h2 {
    margin: 4px 0 0;
    padding: 0;
    border: 0;
}

.settings-card-heading p {
    max-width: 360px;
    margin: 0;
    color: var(--crm-muted, #61727c);
    font-size: .86rem;
    line-height: 1.5;
    text-align: right;
}

.settings-eyebrow {
    color: var(--crm-primary, #00b9b7);
    font-size: .7rem;
    font-weight: 800;
    letter-spacing: .12em;
    text-transform: uppercase;
}

.employee-profile-form {
    display: grid;
    gap: 24px;
}

.employee-profile-summary {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 16px;
    border: 1px solid var(--crm-border, #d5e0e3);
    border-radius: 16px;
    background: linear-gradient(135deg, rgba(0, 185, 183, .09), rgba(0, 185, 183, .025));
}

.employee-profile-avatar {
    flex: 0 0 auto;
    width: 68px;
    height: 68px;
    border: 2px solid rgba(0, 185, 183, .22);
    border-radius: 16px;
    object-fit: cover;
}

.employee-profile-avatar--fallback {
    display: grid;
    place-items: center;
    background: #e7f4f4;
    color: #008c8c;
    font-size: 1.5rem;
    font-weight: 900;
}

.employee-profile-identity {
    min-width: 0;
}

.employee-profile-identity strong,
.employee-profile-identity span {
    display: block;
}

.employee-profile-identity strong {
    color: var(--crm-text, #172630);
    font-size: 1rem;
}

.employee-profile-identity span {
    margin-top: 4px;
    color: var(--crm-muted, #61727c);
    font-size: .82rem;
}

.profile-form-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 18px 20px;
}

.profile-field {
    display: flex;
    min-width: 0;
    flex-direction: column;
    gap: 8px;
}

.profile-field--full {
    grid-column: 1 / -1;
}

.profile-field label {
    color: var(--crm-text, #172630);
    font-size: .78rem;
    font-weight: 800;
}

.profile-field input {
    width: 100%;
    min-width: 0;
    min-height: 46px;
    padding: 11px 13px;
    border: 1px solid var(--crm-border, #cbd8dc);
    border-radius: 10px;
    outline: none;
    background: #fff;
    color: var(--crm-text, #172630);
    font: inherit;
    transition: border-color .18s ease, box-shadow .18s ease, background .18s ease;
}

.profile-field input:focus {
    border-color: var(--crm-primary, #00b9b7);
    box-shadow: 0 0 0 3px rgba(0, 185, 183, .14);
}

.profile-field input.crm-readonly {
    border-color: #dce5e8;
    background: #f4f7f8;
    color: #64747d;
    cursor: default;
}

.profile-field small {
    color: var(--crm-muted, #61727c);
    font-size: .72rem;
    line-height: 1.4;
}

.profile-photo-field input[type="file"] {
    min-height: 52px;
    padding: 6px;
    color: var(--crm-muted, #61727c);
    cursor: pointer;
}

.profile-photo-field input[type="file"]::file-selector-button {
    min-height: 38px;
    margin-right: 12px;
    padding: 0 16px;
    border: 0;
    border-radius: 8px;
    background: #e7f4f4;
    color: #007f80;
    font-weight: 800;
    cursor: pointer;
}

.profile-form-actions {
    display: flex;
    justify-content: flex-end;
    margin-top: 0;
    padding-top: 20px;
    border-top: 1px solid var(--crm-border, #d5e0e3);
}

.settings-info-panel {
    border-left: 3px solid var(--crm-primary, #00b9b7);
    background: #f7fbfb;
}

.settings-info-panel--spaced {
    margin-top: 24px;
}

@media (max-width: 1080px) {
    .settings-grid {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 680px) {
    .settings-card-heading {
        align-items: flex-start;
        flex-direction: column;
        gap: 8px;
    }

    .settings-card-heading p {
        max-width: none;
        text-align: left;
    }

    .profile-form-grid {
        grid-template-columns: 1fr;
    }

    .profile-field--full {
        grid-column: auto;
    }
}

@media (max-width: 520px) {
    .settings-profile-card {
        padding: 20px 16px;
    }

    .employee-profile-summary {
        align-items: flex-start;
        padding: 14px;
    }

    .employee-profile-avatar {
        width: 58px;
        height: 58px;
        border-radius: 14px;
    }

    .profile-form-actions .crm-btn {
        width: 100%;
    }
}


/* ==========================================================================
   Accessible light/dark employee theme
   ========================================================================== */
:root[data-theme="light"] {
    color-scheme: light;
    --crm-bg: #edf3f4;
    --crm-sidebar: #ffffff;
    --crm-sidebar-hover: #e8f5f5;
    --crm-white: #ffffff;
    --crm-text: #10242b;
    --crm-muted: #526371;
    --crm-border: #cfdbdf;
    --employee-surface: #ffffff;
    --employee-surface-raised: #f8fbfb;
    --employee-surface-soft: #edf5f6;
    --employee-text-faint: #71838d;
    --employee-shadow: 0 18px 48px rgba(16, 36, 43, .1);
    --employee-focus: rgba(0, 174, 176, .2);
}

:root[data-theme="dark"] {
    color-scheme: dark;
    --crm-bg: #071017;
    --crm-sidebar: #0b151d;
    --crm-sidebar-hover: #12252d;
    --crm-primary: #29d3d0;
    --crm-primary-dark: #54e1de;
    --crm-white: #0f1b23;
    --crm-text: #eaf3f5;
    --crm-muted: #a6b7bf;
    --crm-border: #273a44;
    --crm-success: #49d6a9;
    --crm-warning: #f2c164;
    --crm-danger: #f07878;
    --employee-surface: #0f1b23;
    --employee-surface-raised: #13222b;
    --employee-surface-soft: #172a34;
    --employee-text-faint: #8397a1;
    --employee-shadow: 0 20px 56px rgba(0, 0, 0, .34);
    --employee-focus: rgba(41, 211, 208, .22);
}

body,
.crm-sidebar,
.crm-topbar,
.crm-section,
.crm-stat-card,
.crm-table-wrap,
.settings-card,
input,
select,
textarea,
button,
a {
    transition:
        background-color 180ms ease,
        border-color 180ms ease,
        color 180ms ease,
        box-shadow 180ms ease;
}

.portal-theme-toggle {
    position: relative;
    z-index: 1200;
    display: inline-grid;
    place-items: center;
    width: 40px;
    height: 40px;
    flex: 0 0 40px;
    padding: 0;
    border: 1px solid var(--crm-border);
    border-radius: 10px;
    background: var(--employee-surface-raised);
    color: var(--crm-text);
    box-shadow: 0 8px 24px rgba(16, 36, 43, .1);
    cursor: pointer;
}

.portal-theme-toggle:hover {
    border-color: var(--crm-primary);
    background: var(--employee-surface-soft);
    color: var(--crm-primary);
}

.portal-theme-toggle:focus-visible {
    outline: 3px solid var(--employee-focus);
    outline-offset: 2px;
}

.portal-theme-toggle--floating {
    position: fixed;
    top: max(16px, env(safe-area-inset-top));
    right: max(16px, env(safe-area-inset-right));
}

.portal-theme-icon {
    position: absolute;
    width: 19px;
    height: 19px;
    fill: none;
    stroke: currentColor;
    stroke-width: 1.9;
    stroke-linecap: round;
    stroke-linejoin: round;
    transition: opacity 180ms ease, transform 220ms ease;
}

.portal-theme-icon--sun,
.portal-theme-toggle[data-current-theme="dark"] .portal-theme-icon--moon {
    opacity: 0;
    transform: scale(.65) rotate(-35deg);
}

.portal-theme-icon--moon,
.portal-theme-toggle[data-current-theme="dark"] .portal-theme-icon--sun {
    opacity: 1;
    transform: scale(1) rotate(0);
}

.portal-theme-sr {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
}

:root[data-theme] body:not(.crm-login-page) {
    background:
        radial-gradient(circle at 12% 8%, color-mix(in srgb, var(--crm-primary) 8%, transparent), transparent 28%),
        linear-gradient(180deg, var(--employee-surface-raised), var(--crm-bg));
    color: var(--crm-text);
}

:root[data-theme="dark"] .crm-sidebar {
    border-color: var(--crm-border);
    background: rgba(9, 19, 26, .97);
    color: var(--crm-muted);
    box-shadow: 12px 0 36px rgba(0, 0, 0, .3);
}

:root[data-theme="dark"] :is(.crm-sidebar-brand, .crm-sidebar-footer, .crm-admin-card) {
    border-color: var(--crm-border);
    background: transparent;
    color: var(--crm-text);
}

:root[data-theme="dark"] .crm-admin-card {
    background: var(--employee-surface-raised);
}

:root[data-theme="dark"] :is(.crm-admin-settings, .crm-bell-btn) {
    border-color: var(--crm-border);
    background: var(--employee-surface-raised);
    color: var(--crm-primary);
}

:root[data-theme="dark"] .crm-sidebar-nav a {
    color: var(--crm-muted);
}

:root[data-theme="dark"] .crm-sidebar-nav a:hover,
:root[data-theme="dark"] .crm-sidebar-nav a.active {
    background: rgba(41, 211, 208, .1);
    color: #efffff;
}

:root[data-theme="dark"] .crm-sidebar-nav a .icon {
    background: rgba(41, 211, 208, .1);
    color: #67e8e5;
}

:root[data-theme="dark"] :is(.crm-main, .crm-content) {
    background: transparent;
    color: var(--crm-text);
}

:root[data-theme="dark"] .crm-topbar {
    border-color: var(--crm-border);
    background: rgba(13, 24, 32, .91);
    color: var(--crm-text);
    box-shadow: 0 12px 32px rgba(0, 0, 0, .2);
    backdrop-filter: blur(16px);
}

:root[data-theme="dark"] :is(.crm-topbar h1, .crm-user-chip strong) {
    color: var(--crm-text);
}

:root[data-theme="dark"] :is(.crm-user-chip span, .crm-help, .subtitle) {
    color: var(--crm-muted);
}

:root[data-theme="dark"] :is(.crm-search-input, .crm-form input, .crm-form select, .crm-form textarea, .crm-inline-form input, .crm-inline-form select, .crm-inline-form textarea, .profile-field input) {
    border-color: var(--crm-border);
    background: var(--employee-surface-raised);
    color: var(--crm-text);
}

:root[data-theme="dark"] :is(input, textarea)::placeholder {
    color: var(--employee-text-faint);
    opacity: 1;
}

:root[data-theme="dark"] :is(input, select, textarea):focus {
    border-color: var(--crm-primary);
    box-shadow: 0 0 0 3px var(--employee-focus);
}

:root[data-theme="dark"] select option {
    background: var(--employee-surface);
    color: var(--crm-text);
}

:root[data-theme="dark"] .profile-field input.crm-readonly,
:root[data-theme="dark"] .crm-readonly {
    border-color: var(--crm-border);
    background: #0b151c;
    color: #8fa2ab;
}

:root[data-theme="dark"] :is(
    .crm-section,
    .crm-stat-card,
    .crm-table-wrap,
    .crm-detail-grid,
    .crm-filter-bar,
    .crm-empty,
    .crm-item-row,
    .crm-items-list,
    .crm-quick-link,
    .settings-card,
    .employee-profile-summary,
    .settings-info-panel,
    .dev-placeholder,
    .dev-idea-card,
    .legal-stepper,
    .billing-dossier,
    .billing-fiscal-panel,
    .invoice-fiscal-panel,
    .invoice-section,
    .invoice-live-totals,
    .dte-local-notice,
    .mm-project-card,
    .mm-file-card,
    .mm-upload-zone,
    .multimedia-drop-zone,
    .lape-chat-container
) {
    border-color: var(--crm-border);
    background: var(--employee-surface);
    color: var(--crm-text);
    box-shadow: var(--employee-shadow);
}

:root[data-theme="dark"] :is(
    .crm-section,
    .crm-stat-card,
    .crm-table-wrap,
    .crm-detail-grid,
    .crm-filter-bar,
    .crm-empty,
    .settings-card,
    .dev-placeholder,
    .dev-idea-card,
    .billing-dossier,
    .invoice-fiscal-panel,
    .invoice-section,
    .mm-project-card,
    .lape-chat-container
) :is(h1, h2, h3, h4, strong, .value, .label) {
    color: var(--crm-text);
}

:root[data-theme="dark"] :is(
    .crm-section,
    .crm-stat-card,
    .crm-detail-grid,
    .settings-card,
    .employee-profile-identity,
    .mm-project-card,
    .mm-file-info,
    .lape-chat-container
) :is(p, small, span:not(.crm-pill):not(.icon), .subtitle) {
    color: var(--crm-muted);
}

:root[data-theme="dark"] :is(.settings-card-heading, .profile-form-actions, .employee-profile-summary) {
    border-color: var(--crm-border);
}

:root[data-theme="dark"] .employee-profile-summary {
    background: linear-gradient(135deg, rgba(41, 211, 208, .1), rgba(41, 211, 208, .025));
}

:root[data-theme="dark"] .profile-photo-field input[type="file"]::file-selector-button {
    background: rgba(41, 211, 208, .12);
    color: #8bf1ef;
}

:root[data-theme="dark"] :is(.crm-table, table) {
    border-color: var(--crm-border);
    background: var(--employee-surface);
    color: var(--crm-text);
}

:root[data-theme="dark"] :is(.crm-table th, table th, .crm-table-header) {
    border-color: var(--crm-border);
    background: var(--employee-surface-soft);
    color: #d7e4e9;
}

:root[data-theme="dark"] :is(.crm-table td, table td) {
    border-color: var(--crm-border);
    color: var(--crm-muted);
}

:root[data-theme="dark"] :is(.crm-table tbody tr, table tbody tr):hover {
    background: rgba(41, 211, 208, .055);
}

:root[data-theme="dark"] :is(.crm-btn-outline, .crm-pagination a, .crm-pagination span, .mm-upload-btn) {
    border-color: var(--crm-border);
    background: var(--employee-surface-raised);
    color: var(--crm-text);
}

:root[data-theme="dark"] :is(.crm-btn-outline, .crm-pagination a, .mm-upload-btn):hover {
    border-color: var(--crm-primary);
    background: var(--employee-surface-soft);
    color: #efffff;
}

:root[data-theme="dark"] :is(.crm-bell-dropdown, .crm-search-results, .mm-modal) {
    border-color: var(--crm-border);
    background: var(--employee-surface-raised);
    color: var(--crm-text);
    box-shadow: 0 22px 54px rgba(0, 0, 0, .42);
}

:root[data-theme="dark"] :is(.crm-bell-dropdown-header, .crm-notif-list > *, .crm-search-results > *, .mm-modal-header, .mm-modal-footer) {
    border-color: var(--crm-border);
}

:root[data-theme="dark"] :is(.crm-bell-dropdown button, .mark-all-read) {
    color: #67e8e5;
}

:root[data-theme="dark"] :is(.mm-project-thumb, .mm-file-preview, .mm-file-generic, .mm-upload-preview) {
    border-color: var(--crm-border);
    background: #09131a;
}

:root[data-theme="dark"] .mm-modal-backdrop {
    background: rgba(0, 0, 0, .72);
}

:root[data-theme="dark"] :is(.stepper-circle, .legal-stepper::before) {
    border-color: var(--crm-border);
    background: var(--employee-surface-raised);
    color: var(--crm-muted);
}

:root[data-theme="dark"] :is(.stepper-step.active .stepper-circle, .stepper-step.completed .stepper-circle) {
    border-color: var(--crm-primary);
    background: rgba(41, 211, 208, .16);
    color: #8bf1ef;
}

:root[data-theme="dark"] :is(.invoice-company-row, .invoice-fiscal-head, .invoice-items-heading, .invoice-line-tax-detail, .invoice-line-total, .invoice-live-totals > div) {
    border-color: var(--crm-border);
    background: var(--employee-surface-raised);
    color: var(--crm-text);
}

:root[data-theme="dark"] :is(.crm-success-banner, .dte-local-notice) {
    border-color: rgba(73, 214, 169, .34);
    background: rgba(73, 214, 169, .12);
    color: #9aebc9;
}

:root[data-theme="dark"] :is(.crm-alert, .error) {
    border-color: rgba(240, 120, 120, .34);
    background: rgba(240, 120, 120, .12);
    color: #fca5a5;
}

:root[data-theme="dark"] :is(.crm-pill.green, .crm-pill.completed) {
    background: rgba(73, 214, 169, .16);
    color: #86efac;
}

:root[data-theme="dark"] :is(.crm-pill.amber, .crm-pill.pending) {
    background: rgba(242, 193, 100, .16);
    color: #fcd34d;
}

:root[data-theme="dark"] :is(.crm-pill.red, .crm-pill.cancelled) {
    background: rgba(240, 120, 120, .17);
    color: #fca5a5;
}

:root[data-theme="dark"] :is(.crm-pill.blue, .crm-pill.draft) {
    background: rgba(96, 165, 250, .16);
    color: #93c5fd;
}

/* Employee authentication */
:root[data-theme="light"] .crm-login-page {
    background:
        linear-gradient(rgba(244, 249, 250, .84), rgba(231, 239, 241, .91)),
        url("../images/hero-background.jpg") center / cover no-repeat;
}

:root[data-theme="dark"] .crm-login-page {
    background:
        linear-gradient(rgba(3, 10, 15, .82), rgba(5, 14, 20, .9)),
        url("../images/hero-background.jpg") center / cover no-repeat;
}

:root[data-theme] .crm-login-card {
    border: 1px solid var(--crm-border);
    background: color-mix(in srgb, var(--employee-surface) 95%, transparent);
    color: var(--crm-text);
    box-shadow: var(--employee-shadow);
    backdrop-filter: blur(18px);
}

:root[data-theme] .microsoft-login-button {
    border-color: var(--crm-border);
    background: var(--employee-surface-raised);
    color: var(--crm-text);
}

:root[data-theme] .microsoft-login-button:hover {
    border-color: var(--crm-primary);
    background: var(--employee-surface-soft);
}

:root[data-theme] :is(.login-security-note, .login-setup-note, .crm-login-card .subtitle) {
    color: var(--crm-muted);
}

.crm-sidebar-brand img,
.crm-login-brand img {
    object-fit: contain;
}

@media (max-width: 840px) {
    .portal-theme-toggle--floating {
        top: max(12px, env(safe-area-inset-top));
        right: max(12px, env(safe-area-inset-right));
    }
}

@media print {
    .portal-theme-toggle {
        display: none !important;
    }
}


/* Theme contrast remediation */
:root[data-theme] :is(.crm-btn-primary, .lape-form button) {
    color: #042f2e !important;
}

:root[data-theme="light"] .crm-quick-link {
    color: #006f73;
}

:root[data-theme="light"] :is(.crm-stat-card .value.blue, .settings-eyebrow) {
    color: #006f73;
}

:root[data-theme="light"] .crm-stat-card .value.amber {
    color: #895b00;
}

:root[data-theme="light"] .crm-stat-card .value.green {
    color: #147252;
}

:root[data-theme="light"] .crm-stat-card .value.red {
    color: #b4232f;
}

:root[data-theme] .crm-table td[style*="#94a3b8"],
:root[data-theme] table td[style*="#94a3b8"] {
    color: var(--crm-muted) !important;
}

:root[data-theme] :is(.lape-avatar, .lape-msg-avatar) {
    border-color: color-mix(in srgb, var(--crm-primary) 45%, var(--crm-border));
    background: #007f82;
    color: #ffffff;
}

:root[data-theme="dark"] :is(.lape-chat-header, .lape-messages, .lape-form) {
    border-color: var(--crm-border);
    background: var(--employee-surface);
    color: var(--crm-text);
}

:root[data-theme="dark"] .lape-chat-header {
    background: var(--employee-surface-raised);
}

:root[data-theme="dark"] .lape-chat-header :is(strong, h1, h2, h3) {
    color: var(--crm-text);
}

:root[data-theme="dark"] .lape-chat-header :is(small, span) {
    color: var(--crm-muted);
}

:root[data-theme="dark"] .lape-msg-bubble {
    border-color: var(--crm-border);
    background: var(--employee-surface-soft);
    color: var(--crm-text);
}

:root[data-theme="dark"] .lape-form :is(input, textarea) {
    border-color: var(--crm-border);
    background: #0a151c;
    color: var(--crm-text);
}

/* Table and status contrast hardening */
:root[data-theme="dark"] body table tbody tr,
:root[data-theme="dark"] body table tbody td {
    background-color: var(--employee-surface) !important;
    color: var(--crm-text);
}

:root[data-theme="dark"] body table tbody tr:hover td,
:root[data-theme="dark"] body table tbody tr:focus-within td {
    background-color: var(--employee-surface-raised) !important;
    color: var(--crm-text);
}

:root[data-theme="dark"] .crm-pill {
    border: 1px solid #40515a;
    background: #26343b !important;
    color: #e2edf1 !important;
}

:root[data-theme="dark"] :is(.crm-pill.paid, .crm-pill.active, .crm-pill.resolved, .crm-pill.accepted, .crm-pill.aprobada, .crm-pill.green, .crm-pill.completed) {
    border-color: #27654f;
    background: #12352e !important;
    color: #9aebc9 !important;
}

:root[data-theme="dark"] :is(.crm-pill.pending, .crm-pill.hold, .crm-pill.sometida, .crm-pill.amber) {
    border-color: #70551d;
    background: #3a2d15 !important;
    color: #fde68a !important;
}

:root[data-theme="dark"] :is(.crm-pill.cancelled, .crm-pill.rejected, .crm-pill.red) {
    border-color: #7f3540;
    background: #3a2025 !important;
    color: #fecaca !important;
}

:root[data-theme="dark"] :is(.crm-pill.draft, .crm-pill.open, .crm-pill.monitoring, .crm-pill.sent, .crm-pill.revisada, .crm-pill.blue) {
    border-color: #315f88;
    background: #172f4a !important;
    color: #bfdbfe !important;
}

:root[data-theme="dark"] .crm-pill.closed {
    border-color: #465860;
    background: #27343a !important;
    color: #e2e8f0 !important;
}


/* ==========================================================================
   Employee portal responsive navigation and mobile layout
   ========================================================================== */
.crm-mobile-menu-toggle,
.crm-sidebar-overlay {
    display: none;
}

.crm-chart-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 20px;
    margin-bottom: 28px;
}

@media (max-width: 768px) {
    body:not(.crm-login-page) {
        display: block !important;
        min-width: 0;
        overflow-x: hidden;
    }

    body.employee-menu-open {
        overflow: hidden !important;
    }

    .crm-mobile-menu-toggle {
        position: fixed;
        top: max(14px, env(safe-area-inset-top));
        left: max(14px, env(safe-area-inset-left));
        z-index: 1302;
        display: inline-flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        width: 42px;
        height: 42px;
        padding: 0;
        border: 1px solid var(--crm-border);
        border-radius: 11px;
        background: color-mix(in srgb, var(--employee-surface-raised) 94%, transparent);
        color: var(--crm-primary);
        box-shadow: 0 10px 28px rgba(0, 0, 0, 0.16);
        backdrop-filter: blur(14px);
        cursor: pointer;
    }

    .crm-mobile-menu-toggle span {
        display: block;
        width: 17px;
        height: 1.5px;
        margin: 2.5px 0;
        border-radius: 999px;
        background: currentColor;
        transition: opacity 160ms ease, transform 220ms ease;
    }

    body.employee-menu-open .crm-mobile-menu-toggle span:nth-child(1) {
        transform: translateY(6.5px) rotate(45deg);
    }

    body.employee-menu-open .crm-mobile-menu-toggle span:nth-child(2) {
        opacity: 0;
    }

    body.employee-menu-open .crm-mobile-menu-toggle span:nth-child(3) {
        transform: translateY(-6.5px) rotate(-45deg);
    }

    .crm-sidebar-overlay {
        position: fixed;
        inset: 0;
        z-index: 1190;
        display: block;
        padding: 0;
        border: 0;
        background: rgba(3, 11, 16, 0.48);
        opacity: 0;
        pointer-events: none;
        backdrop-filter: blur(2px);
        transition: opacity 240ms ease;
    }

    body.employee-menu-open .crm-sidebar-overlay {
        opacity: 1;
        pointer-events: auto;
    }

    .crm-sidebar {
        top: 0 !important;
        bottom: 0 !important;
        left: 0 !important;
        z-index: 1200 !important;
        width: min(86vw, 320px) !important;
        max-width: 320px !important;
        padding: 0 !important;
        overflow: hidden !important;
        transform: translateX(-105%);
        transition: transform 300ms cubic-bezier(.22, 1, .36, 1), box-shadow 300ms ease !important;
        will-change: transform;
    }

    body.employee-menu-open .crm-sidebar {
        transform: translateX(0);
        box-shadow: 24px 0 60px rgba(0, 0, 0, 0.28);
    }

    .crm-sidebar-brand {
        display: flex !important;
        min-height: 72px;
        padding: 14px 18px 14px 66px !important;
        gap: 10px;
    }

    .crm-sidebar-brand img {
        display: block !important;
        width: 116px !important;
        max-width: 116px;
    }

    .crm-sidebar-brand span {
        display: block !important;
        font-size: 0.64rem;
        letter-spacing: 0.14em;
    }

    .crm-sidebar-nav {
        padding: 12px 8px !important;
        overflow-y: auto;
        overscroll-behavior: contain;
    }

    .crm-sidebar-nav a {
        justify-content: flex-start !important;
        width: auto !important;
        min-height: 48px;
        margin: 2px 4px !important;
        padding: 9px 12px !important;
        gap: 12px !important;
        font-size: 0.9rem;
        white-space: normal;
    }

    .crm-sidebar-nav a .icon {
        margin: 0 !important;
        flex: 0 0 32px;
        width: 32px;
        height: 32px;
    }

    .crm-sidebar-footer {
        padding: 12px !important;
    }

    .crm-admin-card div {
        display: block !important;
        min-width: 0;
    }

    .crm-admin-settings {
        display: inline-grid !important;
    }

    .crm-link-button {
        display: flex !important;
        justify-content: flex-start;
        min-height: 44px;
        padding: 0 14px;
    }

    .crm-main {
        width: 100% !important;
        min-width: 0 !important;
        margin-left: 0 !important;
    }

    .crm-topbar {
        display: grid !important;
        grid-template-columns: minmax(0, 1fr);
        align-items: center;
        gap: 12px;
        width: 100%;
        min-height: 74px;
        padding: 14px 64px 14px 66px !important;
    }

    .crm-topbar h1 {
        min-width: 0;
        margin: 0;
        font-size: clamp(1.15rem, 5vw, 1.35rem);
        line-height: 1.2;
        overflow-wrap: anywhere;
    }

    .crm-topbar-right {
        display: grid !important;
        grid-template-columns: minmax(0, 1fr) 40px;
        align-items: center;
        gap: 10px !important;
        width: 100%;
        min-width: 0;
        grid-column: 1;
    }

    .crm-search-wrap {
        width: 100% !important;
        min-width: 0 !important;
        max-width: none !important;
    }

    .crm-search-input {
        width: 100% !important;
        min-width: 0;
        height: 40px;
        padding-right: 12px;
        text-overflow: ellipsis;
    }

    .crm-user-chip {
        display: none !important;
    }

    .crm-bell-wrap,
    .crm-bell-btn {
        width: 40px;
        height: 40px;
    }

    .crm-bell-dropdown {
        position: fixed !important;
        top: 126px !important;
        right: 12px !important;
        left: 12px !important;
        width: auto !important;
        max-width: none !important;
    }

    .portal-theme-toggle--floating {
        top: max(14px, env(safe-area-inset-top)) !important;
        right: max(14px, env(safe-area-inset-right)) !important;
        width: 42px;
        height: 42px;
    }

    .crm-content {
        width: 100%;
        min-width: 0;
        padding: 16px !important;
    }

    .crm-content > * {
        min-width: 0;
        max-width: 100%;
    }

    .crm-quick-links {
        display: grid !important;
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 10px;
        width: 100%;
        margin-bottom: 16px;
    }

    .crm-quick-link {
        justify-content: center;
        width: 100%;
        min-width: 0;
        min-height: 42px;
        padding: 8px 10px;
        text-align: center;
        line-height: 1.25;
    }

    .crm-stats {
        grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
        gap: 12px !important;
        width: 100%;
        margin-bottom: 20px;
    }

    .crm-stat-card {
        min-width: 0;
        padding: 16px !important;
    }

    .crm-stat-card .label {
        line-height: 1.3;
        overflow-wrap: anywhere;
    }

    .crm-stat-card .value {
        font-size: clamp(1.55rem, 8vw, 2rem);
    }

    .crm-chart-grid,
    .crm-two-col {
        grid-template-columns: minmax(0, 1fr) !important;
        gap: 16px !important;
    }

    .crm-chart-grid {
        margin-bottom: 20px;
    }

    .crm-table-wrap {
        width: 100%;
        max-width: calc(100vw - 32px);
        overflow-x: auto !important;
        overscroll-behavior-inline: contain;
        -webkit-overflow-scrolling: touch;
    }

    .crm-table {
        min-width: 520px;
    }

    .crm-table-header {
        min-width: min(520px, 100%);
        padding: 14px 16px;
    }

    .crm-table th,
    .crm-table td {
        padding-right: 14px;
        padding-left: 14px;
        white-space: nowrap;
    }

    :is(.crm-section, .crm-form, .crm-filter-bar, .crm-detail-grid, .settings-card, .billing-dossier, .invoice-section) {
        min-width: 0;
        max-width: 100%;
    }
}

@media (max-width: 420px) {
    .crm-topbar {
        padding-right: 58px !important;
        padding-left: 60px !important;
    }

    .crm-content {
        padding: 12px !important;
    }

    .crm-quick-links {
        grid-template-columns: minmax(0, 1fr);
    }

    .crm-stats {
        gap: 10px !important;
    }

    .crm-stat-card {
        padding: 14px 12px !important;
    }

    .crm-table-wrap {
        max-width: calc(100vw - 24px);
    }
}


/* Compact mobile employee topbar and on-demand search panel. */
.crm-mobile-search-toggle,
.crm-mobile-search-close,
.crm-mobile-search-overlay {
    display: none;
}

@media (max-width: 768px) {
    body.employee-search-open {
        overflow: hidden !important;
    }

    .crm-topbar {
        grid-template-columns: minmax(0, 1fr) auto !important;
        gap: 10px !important;
        min-height: 70px !important;
        padding: 14px 64px 14px 66px !important;
    }

    .crm-topbar h1 {
        grid-column: 1 !important;
        overflow: hidden;
        min-width: 0;
        padding-left: 8px;
        font-size: clamp(1.05rem, 4.8vw, 1.28rem) !important;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    .crm-topbar-right {
        grid-column: 2 !important;
        display: flex !important;
        align-items: center !important;
        justify-content: flex-end !important;
        gap: 8px !important;
        width: auto !important;
        min-width: 88px;
    }

    .crm-mobile-search-toggle {
        display: inline-grid;
        place-items: center;
        width: 40px;
        height: 40px;
        flex: 0 0 40px;
        padding: 0;
        border: 1px solid var(--crm-border);
        border-radius: 10px;
        background: var(--employee-surface-raised);
        color: var(--crm-primary);
        box-shadow: none;
        cursor: pointer;
    }

    .crm-mobile-search-toggle svg {
        width: 18px;
        height: 18px;
        fill: none;
        stroke: currentColor;
        stroke-width: 2;
        stroke-linecap: round;
        stroke-linejoin: round;
    }

    .crm-mobile-search-toggle:hover,
    .crm-mobile-search-toggle:focus-visible {
        border-color: var(--crm-primary);
        background: var(--employee-surface-soft);
        outline: none;
    }

    .crm-mobile-search-overlay {
        position: fixed;
        inset: 0;
        z-index: 1390;
        display: block;
        padding: 0;
        border: 0;
        background: rgba(3, 11, 16, 0.54);
        opacity: 0;
        pointer-events: none;
        backdrop-filter: blur(3px);
        transition: opacity 220ms ease;
    }

    body.employee-search-open .crm-mobile-search-overlay {
        opacity: 1;
        pointer-events: auto;
    }

    .crm-topbar .crm-search-wrap {
        position: fixed !important;
        top: max(82px, calc(env(safe-area-inset-top) + 72px)) !important;
        right: 14px !important;
        left: 14px !important;
        z-index: 1400 !important;
        display: block !important;
        width: auto !important;
        min-width: 0 !important;
        max-width: 520px !important;
        margin: 0 auto !important;
        padding: 14px !important;
        border: 1px solid var(--crm-border);
        border-radius: 14px;
        background: color-mix(in srgb, var(--employee-surface) 96%, transparent);
        box-shadow: 0 24px 70px rgba(0, 0, 0, 0.34);
        opacity: 0;
        pointer-events: none;
        transform: translateY(-12px) scale(0.98);
        backdrop-filter: blur(18px);
        transition: opacity 180ms ease, transform 240ms cubic-bezier(.22, 1, .36, 1);
    }

    body.employee-search-open .crm-topbar .crm-search-wrap {
        opacity: 1;
        pointer-events: auto;
        transform: translateY(0) scale(1);
    }

    .crm-topbar .crm-search-wrap .crm-search-icon {
        top: 27px !important;
        left: 28px !important;
        z-index: 2;
    }

    .crm-topbar .crm-search-wrap .crm-search-input {
        width: 100% !important;
        height: 46px !important;
        padding: 10px 44px 10px 40px !important;
        border-radius: 10px !important;
        font-size: 16px !important;
    }

    .crm-mobile-search-close {
        position: absolute;
        top: 21px;
        right: 22px;
        z-index: 3;
        display: inline-grid;
        place-items: center;
        width: 32px;
        height: 32px;
        padding: 0;
        border: 0;
        border-radius: 8px;
        background: transparent;
        color: var(--crm-muted);
        font-size: 1.45rem;
        line-height: 1;
        cursor: pointer;
    }

    .crm-mobile-search-close:hover,
    .crm-mobile-search-close:focus-visible {
        background: var(--employee-surface-soft);
        color: var(--crm-text);
        outline: none;
    }

    .crm-topbar .crm-search-results {
        position: static !important;
        width: 100% !important;
        max-height: min(54vh, 420px) !important;
        margin-top: 10px;
        border-radius: 10px !important;
        overflow-y: auto;
        box-shadow: none !important;
    }

    .crm-bell-dropdown {
        top: 72px !important;
    }

    .crm-bell-btn,
    .crm-mobile-search-toggle,
    .portal-theme-toggle--floating {
        border-radius: 10px !important;
    }
}

@media (max-width: 390px) {
    .crm-topbar {
        gap: 6px !important;
        padding-right: 58px !important;
        padding-left: 60px !important;
    }

    .crm-topbar-right {
        gap: 6px !important;
        min-width: 78px;
    }

    .crm-mobile-search-toggle,
    .crm-bell-wrap,
    .crm-bell-btn {
        width: 36px !important;
        height: 36px !important;
        flex-basis: 36px;
    }
}
