:root {
    --bg: #eef3f9;
    --panel: #ffffff;
    --panel-soft: #f6f8fc;
    --line: #d8e0eb;
    --text: #17253a;
    --muted: #66748d;
    --blue: #2475ea;
    --yellow: #f2b41b;
    --green: #1f9563;
    --orange: #ef7c31;
    --red: #d9434f;
    --accent: #1e58c7;
    --shadow: 0 16px 36px rgba(17, 37, 69, 0.08);
    --radius-xl: 22px;
    --radius-lg: 18px;
    --radius-md: 14px;
    --radius-sm: 10px;
    --font-ui: "Segoe UI", "Trebuchet MS", sans-serif;
}

* {
    box-sizing: border-box;
}

html {
    scroll-behavior: smooth;
    overflow-x: hidden;
}

body {
    margin: 0;
    min-height: 100vh;
    font-family: var(--font-ui);
    color: var(--text);
    background: linear-gradient(180deg, #f7f9fc, var(--bg));
    overflow-x: hidden;
}

button,
input,
select,
textarea {
    font: inherit;
}

button {
    border: 0;
    cursor: pointer;
    transition: transform 0.16s ease, opacity 0.16s ease;
}

button:hover {
    transform: translateY(-1px);
}

.app-shell {
    width: min(1280px, calc(100% - 20px));
    max-width: 1280px;
    margin: 10px auto 22px;
}

.panel {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow);
}

.app-header {
    padding: 0 0 12px;
    display: flex;
    justify-content: space-between;
    gap: 16px;
    align-items: center;
}

.board-toolbar {
    display: grid;
    gap: 14px;
}

.schedule-panel {
    width: min(980px, 100%);
}

.board-toolbar-head {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    align-items: center;
}

.screen-head p,
.section-header p,
.subsection-head p,
.feedback,
.empty-state p,
.service-card p,
.service-row p,
.client-card p,
.manual-card p,
.history-card p,
.chat-bubble p,
.chat-bubble ul {
    margin: 0;
    color: var(--muted);
    overflow-wrap: anywhere;
}

.tab {
    padding: 11px 14px;
    border-radius: 10px;
    border: 1px solid var(--line);
    background: #fff;
    color: var(--text);
    text-align: center;
    white-space: nowrap;
}

.tab.is-active {
    background: var(--blue);
    color: #fff;
    border-color: var(--blue);
}

.desktop-nav {
    display: flex;
    gap: 10px;
    align-items: center;
}

.menu-shell {
    position: relative;
    display: none;
}

.menu-toggle {
    width: 48px;
    height: 48px;
    padding: 0;
    display: grid;
    place-items: center;
    gap: 4px;
    border-radius: 14px;
    border: 1px solid var(--line);
    background: #fff;
}

.menu-toggle span {
    display: block;
    width: 18px;
    height: 2px;
    border-radius: 999px;
    background: var(--text);
}

.hamburger-menu {
    position: absolute;
    right: 0;
    top: calc(100% + 8px);
    width: 200px;
    padding: 10px;
    display: none;
    gap: 8px;
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow);
    z-index: 20;
}

.hamburger-menu.is-open {
    display: grid;
}

.screen {
    display: none;
    gap: 16px;
    min-width: 0;
}

.screen.is-active {
    display: grid;
}

.screen-head {
    display: flex;
    justify-content: space-between;
    gap: 16px;
}

.screen-head h1,
.section-header h2,
.section-header h3,
.subsection-head h3,
.column-head h4 {
    margin: 0;
}

.assistant-layout,
.screen-grid {
    display: grid;
    grid-template-columns: minmax(0, 1.2fr) minmax(330px, 0.8fr);
    gap: 16px;
    align-items: start;
}

.assistant-layout > *,
.screen-grid > *,
.screen-head > *,
.section-header > *,
.client-card-head > *,
.service-row-head > *,
.manual-card-head > *,
.history-card-head > *,
.column-head > * {
    min-width: 0;
}

.sidebar-stack,
.service-list,
.client-list,
.history-list,
.manual-list {
    display: grid;
    gap: 12px;
}

.panel {
    padding: 16px;
    min-width: 0;
}

.section-header,
.board-toolbar-head,
.client-card-head,
.service-row-head,
.manual-card-head,
.history-card-head,
.column-head {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    align-items: flex-start;
}

.field-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 12px;
    min-width: 0;
}

.quick-schedule-form .field-grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
}

.compact-head {
    align-items: center;
}

.field {
    display: grid;
    gap: 8px;
}

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

label {
    font-size: 0.9rem;
    font-weight: 700;
}

input,
select,
textarea {
    width: 100%;
    padding: 12px 13px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--line);
    background: #fff;
    color: var(--text);
}

textarea {
    min-height: 98px;
    resize: vertical;
}

form {
    display: grid;
    gap: 14px;
}

.chat-panel {
    display: grid;
    gap: 14px;
}

.chat-thread {
    min-height: 420px;
    max-height: 68vh;
    overflow-y: auto;
    padding: 10px;
    border: 1px solid var(--line);
    border-radius: var(--radius-md);
    background: linear-gradient(180deg, #f8fbff, #f3f7fc);
    display: grid;
    gap: 12px;
    align-content: start;
}

.chat-message {
    display: flex;
}

.chat-message.user {
    justify-content: flex-end;
}

.chat-message.assistant {
    justify-content: flex-start;
}

.chat-bubble {
    width: min(100%, 760px);
    padding: 12px 14px;
    border-radius: 16px;
    display: grid;
    gap: 10px;
    border: 1px solid var(--line);
    background: #fff;
}

.chat-message.user .chat-bubble {
    background: linear-gradient(135deg, var(--blue), var(--accent));
    color: #fff;
    border-color: transparent;
}

.chat-message.user .chat-bubble p,
.chat-message.user .chat-bubble strong,
.chat-message.user .chat-bubble small {
    color: #fff;
}

.chat-meta {
    display: flex;
    justify-content: space-between;
    gap: 10px;
    font-size: 0.78rem;
}

.chat-resources {
    display: grid;
    gap: 8px;
}

.resource-chip {
    padding: 9px 10px;
    border-radius: 12px;
    background: var(--panel-soft);
    border: 1px solid var(--line);
}

.chat-compose {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 10px;
    align-items: end;
}

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

.form-actions,
.small-actions,
.tag-row {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
}

.primary-btn {
    padding: 11px 16px;
    border-radius: 999px;
    background: linear-gradient(135deg, var(--blue), var(--accent));
    color: #fff;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.ghost-btn,
.mini-btn {
    padding: 10px 14px;
    border-radius: 999px;
    background: var(--panel-soft);
    border: 1px solid var(--line);
    color: var(--text);
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.mini-btn {
    padding: 7px 10px;
}

.square-btn {
    min-width: 36px;
    min-height: 30px;
    padding: 0;
    border-radius: 6px;
    display: grid;
    place-items: center;
    font-size: 0.74rem;
    font-weight: 700;
}

.square-btn svg {
    width: 16px;
    height: 16px;
}

.square-btn[data-next-status] {
    background: #eef4ff;
    border-color: #c7d8fa;
    color: var(--blue);
}

.square-btn[data-open-note] {
    background: #eefbff;
    border-color: #a9deea;
    color: #1390a9;
}

.square-btn[data-edit-service] {
    background: #fff7e8;
    border-color: #f2d292;
    color: #9a6a00;
}

.square-btn[data-delete-service] {
    background: #fff0f2;
    border-color: #f1b6bf;
    color: var(--red);
}

.square-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.collapse-panel summary {
    cursor: pointer;
    font-weight: 700;
    list-style: none;
}

.collapse-panel summary::-webkit-details-marker {
    display: none;
}

.collapse-panel[open] summary {
    margin-bottom: 14px;
}

.feedback[data-tone="success"] {
    color: var(--green);
}

.feedback[data-tone="error"] {
    color: var(--red);
}

.pill-count,
.tag,
.priority-tag,
.status-pill {
    display: inline-flex;
    align-items: center;
    padding: 6px 10px;
    border-radius: 999px;
    font-size: 0.74rem;
    font-weight: 700;
    max-width: 100%;
    overflow-wrap: anywhere;
}

.pill-count,
.tag {
    background: #eef3fb;
    color: var(--muted);
}

.priority-tag[data-priority="baixa"] {
    background: rgba(31, 149, 99, 0.12);
    color: var(--green);
}

.priority-tag[data-priority="normal"] {
    background: rgba(242, 180, 27, 0.16);
    color: #785300;
}

.priority-tag[data-priority="alta"],
.priority-tag[data-priority="urgente"] {
    background: rgba(217, 67, 79, 0.14);
    color: var(--red);
}

.status-pill[data-status="agendado"] {
    background: rgba(36, 117, 234, 0.14);
    color: var(--blue);
}

.status-pill[data-status="em_rota"] {
    background: rgba(242, 180, 27, 0.17);
    color: #785300;
}

.status-pill[data-status="em_execucao"] {
    background: rgba(31, 149, 99, 0.14);
    color: var(--green);
}

.status-pill[data-status="aguardando"] {
    background: rgba(239, 124, 49, 0.14);
    color: var(--orange);
}

.status-pill[data-status="finalizado"] {
    background: rgba(217, 67, 79, 0.14);
    color: var(--red);
}

.client-card,
.service-row,
.manual-card,
.history-card,
.service-card {
    border: 1px solid var(--line);
    border-radius: var(--radius-md);
    background: #fff;
    padding: 14px;
    display: grid;
    gap: 10px;
}

.client-access-box {
    border: 1px solid var(--line);
    border-radius: var(--radius-md);
    background: var(--panel-soft);
    padding: 12px;
}

.client-access-box summary {
    cursor: pointer;
    font-weight: 700;
}

.client-access-box[open] summary {
    margin-bottom: 10px;
}

.access-grid {
    display: grid;
    gap: 10px;
}

.access-field {
    display: grid;
    gap: 5px;
    padding: 10px 12px;
    border: 1px solid var(--line);
    border-radius: var(--radius-sm);
    background: #fff;
}

.access-field span {
    font-size: 0.78rem;
    color: var(--muted);
}

.board-panel {
    padding: 12px;
}

.kanban-board {
    display: grid;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    gap: 10px;
    overflow: visible;
    min-width: 0;
}

.board-column {
    min-height: 440px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    border: 1px solid var(--line);
    border-radius: var(--radius-md);
    background: var(--panel-soft);
    overflow: hidden;
}

.column-head {
    padding: 12px 14px;
    color: #fff;
    align-items: center;
    touch-action: pan-x;
}

.column-head span {
    min-width: 28px;
    height: 28px;
    display: grid;
    place-items: center;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.22);
}

.column-head-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}

.column-add-btn {
    width: 28px;
    height: 28px;
    padding: 0;
    border-radius: 999px;
    border: 1px solid rgba(255, 255, 255, 0.35);
    background: rgba(255, 255, 255, 0.18);
    color: inherit;
    display: grid;
    place-items: center;
    font-size: 1rem;
    font-weight: 700;
}

.column-add-btn:hover {
    transform: none;
    background: rgba(255, 255, 255, 0.28);
}

.board-column[data-status-column="agendado"] .column-head {
    background: var(--blue);
}

.board-column[data-status-column="em_rota"] .column-head {
    background: var(--yellow);
    color: #5f4200;
}

.board-column[data-status-column="em_execucao"] .column-head {
    background: var(--green);
}

.board-column[data-status-column="aguardando"] .column-head {
    background: var(--orange);
}

.board-column[data-status-column="finalizado"] .column-head {
    background: var(--red);
}

.service-card,
.board-column .empty-state {
    margin: 0 10px;
}

.service-card:first-of-type,
.board-column .empty-state:first-of-type {
    margin-top: 10px;
}

.service-card:last-child,
.board-column .empty-state:last-child {
    margin-bottom: 10px;
}

.service-card {
    cursor: grab;
    touch-action: pan-y;
}

.service-card.dragging {
    opacity: 0.45;
}

.kanban-card-actions {
    display: flex;
    gap: 6px;
    align-items: center;
    justify-content: flex-start;
}

.service-note-list {
    display: grid;
    gap: 8px;
}

.service-note {
    padding: 8px 10px;
    border-radius: 10px;
    background: var(--note-bg);
    border-left: 4px solid var(--note-color);
    font-size: 0.84rem;
}

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

.empty-state {
    padding: 16px;
    border: 1px dashed var(--line);
    border-radius: var(--radius-md);
    background: rgba(255, 255, 255, 0.7);
    text-align: center;
}

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

.note-modal {
    position: fixed;
    inset: 0;
    z-index: 40;
}

.note-modal-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(17, 37, 69, 0.42);
}

.note-modal-card {
    position: relative;
    z-index: 1;
    width: min(420px, calc(100% - 20px));
    margin: 8vh auto 0;
    padding: 18px;
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow);
}

.note-color-grid {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.color-option {
    cursor: pointer;
}

.color-option input {
    position: absolute;
    opacity: 0;
    pointer-events: none;
}

.color-option span {
    width: 24px;
    height: 24px;
    display: inline-block;
    border-radius: 6px;
    background: var(--note-color);
    border: 2px solid transparent;
}

.color-option input:checked + span {
    border-color: #17253a;
    box-shadow: 0 0 0 2px rgba(23, 37, 58, 0.12);
}

@media (max-width: 1100px) {
    .assistant-layout,
    .screen-grid {
        grid-template-columns: 1fr;
    }

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

    .kanban-board {
        grid-template-columns: repeat(3, minmax(0, 1fr));
    }
}

@media (max-width: 780px) {
    .app-shell {
        width: min(1280px, calc(100% - 14px));
        margin: 8px auto 18px;
    }

    .app-header,
    .menu-shell {
        width: 100%;
    }

    .desktop-nav {
        display: none;
    }

    .menu-shell {
        display: block;
    }

    .menu-toggle {
        margin-left: 0;
    }

    .hamburger-menu {
        width: 100%;
        left: 0;
        right: auto;
    }

    .field-grid {
        grid-template-columns: 1fr;
    }

    .quick-schedule-form .field-grid {
        grid-template-columns: 1fr;
    }

    .screen-head,
    .section-header,
    .board-toolbar-head,
    .client-card-head,
    .service-row-head,
    .manual-card-head,
    .history-card-head,
    .chat-compose,
    .chat-meta {
        flex-direction: column;
    }

    .screen-head,
    .section-header,
    .board-toolbar-head {
        align-items: stretch;
    }

    .chat-compose {
        display: grid;
        grid-template-columns: 1fr;
    }

    .chat-thread {
        min-height: 300px;
        max-height: 56vh;
    }

    .board-panel {
        padding: 8px;
    }

    .kanban-board {
        grid-template-columns: repeat(5, minmax(86vw, 1fr));
        overflow-x: auto;
        overflow-y: visible;
        padding-bottom: 6px;
        scroll-snap-type: x proximity;
        -webkit-overflow-scrolling: touch;
        touch-action: pan-x;
    }

    .board-column {
        min-height: auto;
        scroll-snap-align: start;
    }

    .note-modal-card {
        margin: 5vh auto 0;
    }
}

@media (max-width: 560px) {
    .panel {
        padding: 12px;
    }

    .screen {
        gap: 12px;
    }

    .screen-head {
        gap: 12px;
    }

    .hamburger-menu {
        padding: 8px;
    }

    .tab {
        width: 100%;
    }

    .chat-thread {
        min-height: 260px;
        max-height: none;
    }

    textarea,
    .chat-compose textarea {
        min-height: 110px;
    }

    .form-actions > *,
    .small-actions > *,
    .tag-row > * {
        flex: 1 1 100%;
    }

    .primary-btn,
    .ghost-btn {
        width: 100%;
        justify-content: center;
    }

    .kanban-board {
        grid-template-columns: repeat(5, minmax(90vw, 1fr));
    }

    .note-modal-card {
        width: calc(100% - 16px);
        margin-top: 3vh;
        padding: 14px;
    }
}
