:root {
    --bg: #f5f6f8;
    --panel: #ffffff;
    --text: #1f2933;
    --muted: #667085;
    --line: #d8dee8;
    --primary: #176b87;
    --primary-dark: #0f4e63;
    --danger: #b42318;
    --sidebar-width: 270px;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font: 15px/1.45 Arial, Helvetica, sans-serif;
}

.app-shell {
    display: flex;
    min-height: 100vh;
}

.sidebar {
    background: #ffffff;
    border-right: 1px solid var(--line);
    bottom: 0;
    flex: 0 0 var(--sidebar-width);
    left: 0;
    min-height: 100vh;
    overflow-y: auto;
    padding: 18px 14px;
    position: fixed;
    top: 0;
    transition: margin-left .2s ease;
    width: var(--sidebar-width);
    z-index: 30;
}

body.sidebar-collapsed .sidebar {
    margin-left: calc(var(--sidebar-width) * -1);
}

.side-tree details {
    margin-bottom: 8px;
}

.side-tree summary {
    color: #344054;
    cursor: pointer;
    font-weight: 800;
    list-style: none;
    padding: 9px 10px;
}

.side-tree summary::-webkit-details-marker {
    display: none;
}

.side-tree summary::before {
    color: var(--primary);
    content: "▸";
    display: inline-block;
    margin-right: 8px;
    transition: transform .15s ease;
}

.side-tree details[open] summary::before {
    transform: rotate(90deg);
}

.side-tree a {
    border-radius: 6px;
    color: #344054;
    display: block;
    font-weight: 700;
    margin: 2px 0 2px 22px;
    padding: 8px 10px;
    text-decoration: none;
}

.side-tree a:hover {
    background: #eef6f8;
    color: var(--primary-dark);
}

.print-menu summary {
    list-style: none;
}

.print-menu {
    position: relative;
}

.print-menu summary::-webkit-details-marker {
    display: none;
}

.print-options {
    position: absolute;
    right: 0;
    top: calc(100% + 8px);
    min-width: 230px;
    background: #ffffff;
    border: 1px solid var(--line);
    border-radius: 8px;
    box-shadow: 0 16px 32px rgba(31, 41, 51, 0.12);
    padding: 8px;
    z-index: 30;
}

.print-options a,
.print-options p,
.print-options strong {
    display: block;
    padding: 8px 10px;
}

.print-options p {
    color: var(--muted);
    margin: 0;
}

.app-main {
    flex: 1;
    margin-left: var(--sidebar-width);
    min-width: 0;
    transition: margin-left .2s ease;
}

body.sidebar-collapsed .app-main {
    margin-left: 0;
}

.app-header {
    align-items: center;
    background: #ffffff;
    border-bottom: 1px solid var(--line);
    display: grid;
    gap: 16px;
    grid-template-columns: minmax(180px, auto) 1fr auto;
    min-height: 64px;
    padding: 0 24px;
    position: sticky;
    top: 0;
    z-index: 20;
}

.header-left {
    align-items: center;
    display: flex;
    gap: 12px;
    min-width: 0;
}

.header-system-logo {
    display: block;
    height: 34px;
    max-width: 150px;
    object-fit: contain;
}

.company-header-logo {
    align-items: center;
    display: flex;
    justify-content: center;
    min-height: 44px;
}

.company-header-logo img {
    display: block;
    height: 34px;
    max-width: min(180px, 32vw);
    object-fit: contain;
}

.user-menu {
    align-items: center;
    display: flex;
    gap: 10px;
}

.user-menu span {
    color: var(--muted);
    font-weight: 700;
}

.page {
    width: min(1180px, calc(100% - 32px));
    margin: 0 auto;
    padding: 28px 0 48px;
}

.public-page {
    width: min(1180px, calc(100% - 32px));
}

.toolbar,
.section-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 18px;
}

.section-tools {
    align-items: center;
    display: flex;
    gap: 12px;
}

.contacts-sticky-head {
    background: var(--panel);
    border-bottom: 1px solid var(--line);
    margin: -18px -18px 16px;
    padding: 18px;
    position: sticky;
    top: 64px;
    z-index: 15;
}

h1,
h2,
p {
    margin: 0;
}

h1 {
    font-size: 28px;
}

h2 {
    font-size: 19px;
    margin-bottom: 14px;
}

p,
.section-head span,
.muted-text {
    color: var(--muted);
}

.actions,
.filter-actions,
.form-actions,
.row-actions {
    display: flex;
    align-items: center;
    gap: 10px;
}

.button,
button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 38px;
    padding: 8px 14px;
    border: 1px solid var(--line);
    border-radius: 6px;
    background: #fff;
    color: var(--text);
    text-decoration: none;
    cursor: pointer;
    font-weight: 700;
}

.icon-button,
.print-menu summary {
    width: 38px;
    min-height: 38px;
    padding: 0;
    border: 1px solid var(--line);
    border-radius: 6px;
    background: #fff;
    color: var(--primary-dark);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
}

.menu-toggle {
    min-width: 68px;
    padding: 0 12px;
    width: auto;
}

.button.primary,
button.primary {
    background: var(--primary);
    border-color: var(--primary);
    color: #fff;
}

.button.primary:hover,
button.primary:hover {
    background: var(--primary-dark);
}

.panel {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 18px;
    margin-bottom: 18px;
}

.filter-grid,
.form-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 14px;
}

.form-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
}

.span-2 {
    grid-column: span 2;
}

label {
    display: flex;
    flex-direction: column;
    gap: 6px;
    color: #344054;
    font-weight: 700;
}

input,
select,
textarea {
    width: 100%;
    min-height: 38px;
    border: 1px solid var(--line);
    border-radius: 6px;
    padding: 8px 10px;
    color: var(--text);
    font: inherit;
    font-weight: 400;
}

textarea {
    resize: vertical;
}

.field-hint {
    color: var(--muted);
    font-size: 12px;
    font-weight: 400;
    min-height: 16px;
}

.error-text {
    color: var(--danger);
}

.filter-actions {
    align-self: end;
}

.table-wrap {
    overflow-x: auto;
}

table {
    width: 100%;
    border-collapse: collapse;
    min-width: 960px;
    table-layout: fixed;
}

th,
td {
    border-bottom: 1px solid var(--line);
    padding: 10px;
    text-align: left;
    vertical-align: top;
}

th {
    color: #475467;
    font-size: 13px;
    text-transform: uppercase;
}

.draggable-column {
    cursor: grab;
    user-select: none;
}

.draggable-column:active {
    cursor: grabbing;
}

.contacts-table {
    min-width: 1460px;
    table-layout: auto;
}

.contacts-table [data-col="select"] {
    text-align: center;
    width: 44px;
}

.contacts-table [data-col="company"] {
    width: 150px;
}

.contacts-table [data-col="name"] {
    width: 120px;
}

.contacts-table [data-col="birthday"] {
    width: 110px;
}

.contacts-table [data-col="email"] {
    width: 210px;
}

.contacts-table [data-col="city_state"] {
    width: 150px;
}

.contacts-table [data-col="country"] {
    width: 90px;
}

.contacts-table [data-col="mobile"],
.contacts-table [data-col="phone"] {
    white-space: nowrap;
    width: 170px;
}

.contacts-table [data-col="action_agenda"],
.contacts-table [data-col="action_edit"],
.contacts-table [data-col="action_delete"] {
    min-width: 112px;
    white-space: nowrap;
    width: 112px;
}

.contacts-table td {
    overflow-wrap: anywhere;
}

.contacts-table [data-col^="action_"] {
    overflow-wrap: normal;
    word-break: keep-all;
}

.table-action-cell {
    text-align: center;
    white-space: nowrap;
}

.table-action-cell .small-button {
    color: var(--primary-dark);
    display: inline-flex;
    min-height: 30px;
    min-width: 82px;
    padding: 5px 10px;
    white-space: nowrap;
    width: auto;
    word-break: keep-all;
}

.table-action-cell .danger-button {
    border-color: #fecdca;
    color: var(--danger);
}

.empty {
    color: var(--muted);
    text-align: center;
}

.alert {
    border: 1px solid #fecdca;
    border-radius: 8px;
    background: #fffbfa;
    color: var(--danger);
    padding: 12px 14px;
    margin-bottom: 14px;
}

.success {
    border: 1px solid #abefc6;
    border-radius: 8px;
    background: #f6fef9;
    color: #067647;
    padding: 12px 14px;
    margin-bottom: 14px;
}

.setup-steps {
    color: #344054;
    margin: 0 0 12px 18px;
    padding: 0;
}

.setup-steps li {
    margin-bottom: 8px;
}

.phone-cell {
    align-items: center;
    display: inline-flex;
    gap: 8px;
}

.whatsapp-icon {
    align-items: center;
    background: transparent;
    border: 0;
    border-radius: 999px;
    display: inline-flex;
    height: 30px;
    justify-content: center;
    text-decoration: none;
    width: 30px;
}

.whatsapp-icon img {
    display: block;
    height: 24px;
    width: 24px;
}

.chat-panel {
    background: #eef6f2;
    border: 1px solid var(--line);
    border-radius: 8px;
    display: flex;
    flex-direction: column;
    min-height: 560px;
    overflow: hidden;
}

.chat-thread {
    display: flex;
    flex: 1;
    flex-direction: column;
    gap: 10px;
    padding: 18px;
}

.chat-bubble {
    border-radius: 8px;
    max-width: min(680px, 86%);
    padding: 10px 12px;
}

.chat-bubble p {
    color: var(--text);
}

.chat-bubble span,
.chat-bubble small {
    color: var(--muted);
    display: block;
    font-size: 12px;
    margin-top: 6px;
}

.chat-bubble.incoming {
    align-self: flex-start;
    background: #ffffff;
}

.chat-bubble.outgoing {
    align-self: flex-end;
    background: #d9fdd3;
}

.chat-compose {
    align-items: flex-end;
    background: #ffffff;
    border-top: 1px solid var(--line);
    display: flex;
    gap: 10px;
    padding: 12px;
}

.chat-dock {
    bottom: 0;
    pointer-events: none;
    position: fixed;
    right: 0;
    z-index: 80;
}

.chat-popup {
    background: #eef6f2;
    border: 1px solid var(--line);
    border-radius: 8px 8px 0 0;
    bottom: 0;
    box-shadow: 0 16px 38px rgba(31, 41, 51, 0.2);
    display: flex;
    flex-direction: column;
    height: 500px;
    overflow: hidden;
    position: fixed;
    width: 320px;
    z-index: 90;
}

.chat-popup-head {
    align-items: center;
    background: #176b87;
    color: #ffffff;
    display: flex;
    justify-content: space-between;
    min-height: 52px;
    padding: 9px 12px;
}

.chat-popup-head strong,
.chat-popup-head span {
    display: block;
}

.chat-popup-head span {
    color: rgba(255, 255, 255, 0.78);
    font-size: 12px;
}

.chat-popup-head button {
    background: transparent;
    border: 0;
    color: #ffffff;
    font-size: 24px;
    min-height: 32px;
    padding: 0 4px;
}

.chat-popup-thread {
    display: flex;
    flex: 1;
    flex-direction: column;
    gap: 8px;
    overflow-y: auto;
    padding: 12px;
}

.chat-popup .chat-bubble {
    max-width: 88%;
}

.chat-popup-compose {
    align-items: flex-end;
    background: #ffffff;
    border-top: 1px solid var(--line);
    display: flex;
    gap: 8px;
    padding: 10px;
}

.chat-popup-compose textarea {
    min-height: 44px;
}

.chat-queue-indicator {
    background: #ffffff;
    border: 1px solid var(--line);
    border-radius: 8px;
    bottom: 18px;
    box-shadow: 0 12px 28px rgba(31, 41, 51, 0.14);
    color: var(--text);
    display: none;
    flex-direction: column;
    min-height: 52px;
    padding: 8px 12px;
    position: fixed;
    right: 18px;
    z-index: 75;
}

.chat-queue-indicator.has-items {
    display: flex;
}

.chat-queue-indicator::after {
    align-items: center;
    background: #d92d20;
    border-radius: 999px;
    color: #ffffff;
    content: attr(data-unread);
    display: flex;
    font-size: 12px;
    font-weight: 800;
    height: 22px;
    justify-content: center;
    min-width: 22px;
    padding: 0 6px;
    position: absolute;
    right: -8px;
    top: -8px;
}

.chat-queue-indicator[data-unread="0"]::after {
    display: none;
}

.login-shell {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 24px;
}

.login-card {
    width: min(380px, 100%);
    background: #ffffff;
    border: 1px solid var(--line);
    border-radius: 8px;
    display: grid;
    gap: 14px;
    overflow: hidden;
    padding: 24px;
}

.login-system-logo {
    display: block;
    height: 116px;
    justify-self: center;
    max-width: 332px;
    object-fit: contain;
    width: 100%;
}

.login-company-logo {
    border-top: 1px solid var(--line);
    display: block;
    height: 82px;
    justify-self: center;
    max-width: 320px;
    object-fit: contain;
    padding-top: 12px;
    width: auto;
}

.filter-config {
    border-bottom: 1px solid var(--line);
    margin-bottom: 14px;
    padding-bottom: 14px;
}

.filter-group {
    border: 1px solid var(--line);
    border-radius: 8px;
    margin-bottom: 12px;
    padding: 12px;
}

.filter-group summary {
    cursor: pointer;
    font-weight: 800;
    list-style: none;
}

.filter-group summary::-webkit-details-marker {
    display: none;
}

.filter-group .filter-grid {
    margin-top: 14px;
}

.filter-config summary {
    cursor: pointer;
    font-weight: 800;
    list-style: none;
}

.filter-config-grid {
    align-items: center;
    display: flex;
    flex-wrap: wrap;
    gap: 10px 16px;
    margin-top: 12px;
}

.checkbox-line.compact {
    padding-top: 0;
}

.logo-preview {
    align-items: center;
    background: #f8fafc;
    border: 1px dashed var(--line);
    border-radius: 8px;
    display: flex;
    justify-content: center;
    min-height: 120px;
    padding: 18px;
}

.logo-preview img {
    max-height: 96px;
    max-width: 320px;
    object-fit: contain;
}

.calendar-grid {
    display: grid;
    gap: 1px;
    grid-template-columns: repeat(7, minmax(130px, 1fr));
    overflow-x: auto;
}

.calendar-week-grid {
    display: grid;
    gap: 1px;
    grid-template-columns: repeat(7, minmax(180px, 1fr));
    overflow-x: auto;
}

.calendar-weekday,
.calendar-day {
    background: #f8fafc;
    min-height: 44px;
    padding: 10px;
}

.calendar-day {
    min-height: 138px;
}

.calendar-date {
    background: transparent;
    border: 0;
    color: var(--muted);
    cursor: pointer;
    font-weight: 800;
    margin-bottom: 8px;
    min-height: auto;
    padding: 0;
    text-align: left;
}

.calendar-day-head {
    align-items: center;
    display: flex;
    justify-content: space-between;
    margin-bottom: 8px;
}

.calendar-add-button {
    background: #ffffff;
    border: 1px solid var(--line);
    border-radius: 999px;
    color: var(--primary-dark);
    font-size: 16px;
    font-weight: 800;
    height: 26px;
    line-height: 1;
    min-height: 26px;
    padding: 0;
    width: 26px;
}

.muted-day {
    opacity: .55;
}

.calendar-event {
    background: #ffffff;
    border-left: 4px solid var(--primary);
    border-radius: 6px;
    color: var(--text);
    display: block;
    margin-bottom: 6px;
    padding: 7px 8px;
    text-decoration: none;
}

.calendar-event span {
    color: var(--muted);
    display: block;
    font-size: 12px;
}

.calendar-event.done {
    border-left-color: #067647;
}

.calendar-event.cancelled {
    border-left-color: var(--danger);
}

.calendar-filter-bar {
    align-items: end;
    display: grid;
    gap: 14px;
    grid-template-columns: 150px 180px minmax(260px, 1fr) auto;
}

.activity-type-filter {
    border: 1px solid var(--line);
    border-radius: 8px;
    display: flex;
    flex-wrap: wrap;
    gap: 6px 14px;
    margin: 0;
    min-height: 38px;
    padding: 10px 12px;
}

.activity-type-filter legend {
    color: #344054;
    font-weight: 800;
    padding: 0 6px;
}

.calendar-day-view {
    display: grid;
    gap: 16px;
    grid-template-columns: 220px minmax(0, 1fr);
}

.calendar-day-slot {
    align-items: flex-start;
    background: #f8fafc;
    border: 1px dashed var(--line);
    border-radius: 8px;
    color: var(--text);
    display: flex;
    flex-direction: column;
    justify-content: flex-start;
    min-height: 160px;
    padding: 14px;
}

.calendar-day-slot span {
    color: var(--muted);
    font-weight: 400;
}

.calendar-agenda-list {
    display: grid;
    gap: 8px;
}

.modal-backdrop {
    align-items: center;
    background: rgba(31, 41, 51, .42);
    bottom: 0;
    display: flex;
    justify-content: center;
    left: 0;
    padding: 20px;
    position: fixed;
    right: 0;
    top: 0;
    z-index: 80;
}

.modal-backdrop[hidden] {
    display: none;
}

.modal-card {
    background: #ffffff;
    border-radius: 8px;
    box-shadow: 0 24px 56px rgba(31, 41, 51, .24);
    max-height: calc(100vh - 40px);
    max-width: 680px;
    overflow: auto;
    padding: 18px;
    width: min(680px, 100%);
}

.checkbox-line {
    align-items: center;
    flex-direction: row;
    gap: 10px;
    padding-top: 28px;
}

.checkbox-line input,
.check-cell input {
    width: auto;
    min-height: auto;
}

.permission-box {
    border-top: 1px solid var(--line);
    margin-top: 6px;
    padding-top: 16px;
}

.permission-grid {
    display: grid;
    grid-template-columns: minmax(150px, 1fr) repeat(4, 100px);
    gap: 1px;
    overflow-x: auto;
}

.owner-permission-grid {
    display: grid;
    grid-template-columns: minmax(180px, 1fr) 80px repeat(4, 100px);
    gap: 1px;
    overflow-x: auto;
}

.company-permission-grid {
    display: grid;
    grid-template-columns: minmax(180px, 1fr) 100px 140px;
    gap: 1px;
    overflow-x: auto;
}

.permission-grid > *,
.owner-permission-grid > *,
.company-permission-grid > * {
    background: #f8fafc;
    min-height: 40px;
    padding: 10px;
}

.permission-column-toggle {
    background: #f8fafc;
    border: 0;
    color: var(--primary-dark);
    cursor: pointer;
    font-weight: 800;
    justify-content: flex-start;
    min-height: 40px;
    padding: 10px;
}

.check-cell {
    align-items: center;
    justify-content: center;
}

.pre-line {
    white-space: pre-line;
}

@media (max-width: 1024px) {
    .app-shell {
        display: block;
    }

    .sidebar {
        bottom: 0;
        box-shadow: 0 18px 40px rgba(31, 41, 51, .22);
        left: 0;
        position: fixed;
        top: 0;
        transform: translateX(0);
        transition: transform .2s ease;
        width: 270px;
    }

    body.sidebar-collapsed .sidebar {
        margin-left: 0;
        transform: translateX(-100%);
    }

    .app-main,
    body.sidebar-collapsed .app-main {
        margin-left: 0;
    }

    .app-header {
        gap: 12px;
        grid-template-columns: auto 1fr auto;
        padding: 14px 18px;
    }

    .header-system-logo {
        height: 30px;
        max-width: 124px;
    }

    .company-header-logo img {
        height: 30px;
        max-width: 120px;
    }

    .user-menu {
        gap: 6px;
        margin-left: 0;
    }

    .user-menu span {
        display: none;
    }

    .toolbar,
    .section-head {
        align-items: flex-start;
        flex-direction: column;
    }

    .contacts-sticky-head {
        top: 72px;
    }

    .filter-grid,
    .form-grid,
    .calendar-filter-bar,
    .calendar-day-view {
        grid-template-columns: 1fr;
    }

    .span-2 {
        grid-column: span 1;
    }

    .chat-popup {
        height: 70vh;
        left: 12px;
        right: 12px !important;
        width: auto;
    }
}
