* {
    box-sizing: border-box;
}

html,
body {
    margin: 0;
    min-height: 100%;
}

body {
    font-family: Inter, "Segoe UI", Arial, sans-serif;
    background: #f4f6f5;
    color: #17201d;
}

button,
input,
select {
    font: inherit;
}

button {
    cursor: pointer;
}

button:disabled {
    cursor: not-allowed;
    opacity: 0.6;
}

.app-shell {
    min-height: 100vh;
    display: grid;
    grid-template-rows: auto 1fr;
}

.topbar {
    min-height: 72px;
    padding: 14px 24px;
    border-bottom: 1px solid #d6ded9;
    background: #ffffff;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 16px;
}

.topbar h1,
.section-heading h2,
.inline-section h3,
.operation-form h3,
.flow-panel h3 {
    margin: 0;
    letter-spacing: 0;
}

.topbar h1 {
    font-size: 20px;
    font-weight: 680;
}

.eyebrow {
    margin: 0 0 4px;
    color: #62716c;
    font-size: 12px;
    font-weight: 700;
    text-transform: uppercase;
}

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

.status-indicator {
    display: inline-flex;
    align-items: center;
    justify-content: flex-end;
    gap: 8px;
    min-width: 132px;
    color: #42524c;
    font-size: 13px;
    white-space: nowrap;
}

.status-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: #2c7a45;
    flex: 0 0 auto;
}

.status-dot.pending {
    background: #b47a12;
}

.status-dot.error {
    background: #b3261e;
}

.icon-button,
.nav-button,
.primary-button,
.secondary-button,
.danger-button {
    min-height: 38px;
    border-radius: 6px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    border: 1px solid transparent;
    font-weight: 650;
    white-space: nowrap;
}

.icon-button {
    padding: 0 12px;
    background: #eef4f1;
    color: #1f4f3a;
    border-color: #c9dad1;
}

.primary-button {
    padding: 0 14px;
    background: #176b4d;
    color: #ffffff;
}

.secondary-button {
    padding: 0 14px;
    background: #eef4f1;
    color: #1d5540;
    border-color: #c9dad1;
}

.danger-button {
    min-height: 32px;
    padding: 0 10px;
    background: #fff1ed;
    color: #9e2f22;
    border-color: #f2c8bd;
}

.icon-button svg,
.nav-button svg,
.primary-button svg,
.secondary-button svg,
.danger-button svg {
    width: 17px;
    height: 17px;
    flex: 0 0 auto;
}

.layout {
    min-height: 0;
    display: grid;
    grid-template-columns: 220px minmax(0, 1fr);
}

.sidebar {
    border-right: 1px solid #d6ded9;
    background: #ffffff;
    padding: 16px 12px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.nav-button {
    width: 100%;
    justify-content: flex-start;
    padding: 0 12px;
    color: #42524c;
    background: transparent;
}

.nav-button.active {
    background: #e6f1ec;
    color: #134b35;
    border-color: #c4dbd1;
}

.workspace {
    min-width: 0;
    padding: 24px;
    overflow: auto;
}

.module-panel {
    display: none;
}

.module-panel.active {
    display: block;
}

.section-heading {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 18px;
}

.section-heading h2 {
    font-size: 22px;
    font-weight: 680;
}

.section-heading.compact {
    margin-bottom: 12px;
}

.flow-panel,
.inline-section,
.operation-form,
.table-shell,
.kpi-card {
    background: #ffffff;
    border: 1px solid #d6ded9;
    border-radius: 8px;
}

.kpi-grid {
    display: grid;
    grid-template-columns: repeat(5, minmax(140px, 1fr));
    gap: 12px;
    margin-bottom: 18px;
}

.kpi-card {
    min-height: 112px;
    padding: 14px;
    display: grid;
    gap: 6px;
    align-content: center;
}

.kpi-label,
.last-updated {
    color: #62716c;
    font-size: 13px;
}

.kpi-card strong {
    font-size: clamp(24px, 3vw, 34px);
    line-height: 1;
}

.kpi-card span:last-child {
    color: #4f615a;
    font-size: 13px;
}

.flow-panel {
    padding: 16px;
}

.flow-steps {
    list-style: none;
    padding: 0;
    margin: 0;
    display: grid;
    grid-template-columns: repeat(5, minmax(130px, 1fr));
    gap: 10px;
}

.flow-step {
    min-height: 104px;
    border: 1px solid #d6ded9;
    border-radius: 8px;
    padding: 12px;
    background: #f8faf9;
    display: grid;
    align-content: start;
    gap: 6px;
}

.flow-step.complete {
    border-color: #95c7ad;
    background: #eff8f3;
}

.flow-step strong {
    font-size: 14px;
}

.flow-step span {
    color: #62716c;
    font-size: 13px;
    overflow-wrap: anywhere;
}

.form-grid {
    display: grid;
    grid-template-columns: repeat(5, minmax(132px, 1fr)) auto;
    gap: 12px;
    align-items: end;
    margin-bottom: 16px;
}

.compact-form {
    grid-template-columns: repeat(3, minmax(120px, 1fr)) auto;
}

label {
    display: grid;
    gap: 6px;
    color: #4f615a;
    font-size: 13px;
    font-weight: 650;
}

input,
select {
    width: 100%;
    min-width: 0;
    min-height: 38px;
    border: 1px solid #b9c6c0;
    border-radius: 6px;
    padding: 8px 10px;
    background: #ffffff;
    color: #17201d;
}

input:focus,
select:focus {
    outline: 2px solid #8bc2a9;
    border-color: #176b4d;
}

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

table {
    width: 100%;
    border-collapse: collapse;
    min-width: 680px;
}

th,
td {
    padding: 11px 12px;
    border-bottom: 1px solid #e2e8e4;
    text-align: left;
    font-size: 14px;
    vertical-align: middle;
}

th {
    color: #62716c;
    font-size: 12px;
    font-weight: 750;
    text-transform: uppercase;
    background: #f8faf9;
}

td {
    overflow-wrap: anywhere;
}

tbody tr:last-child td {
    border-bottom: 0;
}

.status-pill {
    display: inline-flex;
    align-items: center;
    min-height: 26px;
    padding: 0 9px;
    border-radius: 999px;
    background: #eef4f1;
    color: #1d5540;
    font-size: 12px;
    font-weight: 750;
}

.status-pill.warn {
    background: #fff6df;
    color: #7a520d;
}

.status-pill.done {
    background: #e6f4ea;
    color: #1f6b3a;
}

.status-pill.bad {
    background: #fff1ed;
    color: #9e2f22;
}

.empty-state {
    display: none;
    padding: 24px;
    color: #62716c;
    text-align: center;
}

.empty-state.visible {
    display: block;
}

.split-layout {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    gap: 18px;
}

.inline-section {
    padding: 16px;
}

.inline-section h3,
.operation-form h3 {
    font-size: 16px;
    margin-bottom: 14px;
}

.three-column {
    display: grid;
    grid-template-columns: repeat(3, minmax(180px, 1fr));
    gap: 12px;
    margin-bottom: 16px;
}

.operation-form {
    padding: 16px;
    display: grid;
    gap: 12px;
}

.erp-ai-dock {
    position: fixed;
    right: 24px;
    bottom: 24px;
    z-index: 30;
    pointer-events: none;
}

.assistant-launcher {
    min-height: 52px;
    padding: 0 18px;
    border: 1px solid #a8cdbc;
    border-radius: 999px;
    background: #176b4d;
    color: #ffffff;
    box-shadow: 0 16px 38px rgb(23 32 29 / 22%);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    font-weight: 750;
    pointer-events: auto;
}

.assistant-launcher svg {
    width: 19px;
    height: 19px;
}

.erp-ai-dock.open .assistant-launcher {
    display: none;
}

.erp-ai-panel {
    width: min(460px, calc(100vw - 48px));
    height: min(680px, calc(100vh - 48px));
    min-height: 480px;
    position: relative;
    display: none;
    grid-template-rows: 50px minmax(0, 1fr) auto;
    overflow: hidden;
    border: 1px solid #dce5e1;
    border-radius: 8px;
    background: #ffffff;
    box-shadow: 0 20px 60px rgb(23 32 29 / 18%);
    pointer-events: auto;
}

.erp-ai-dock.open .erp-ai-panel {
    display: grid;
}

.assistant-panel-bar {
    min-width: 0;
    padding: 8px 12px;
    background: linear-gradient(120deg, #fff7f9 0%, #f7fbff 58%, #ffffff 100%);
    display: grid;
    grid-template-columns: auto minmax(0, 1fr) auto;
    align-items: center;
    gap: 8px;
}

.assistant-fullscreen-button,
.assistant-close-button {
    min-height: 32px;
    border: 1px solid transparent;
    border-radius: 6px;
    background: rgb(255 255 255 / 68%);
    color: #1b2a26;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    font-weight: 700;
}

.assistant-fullscreen-button {
    padding: 0 9px;
}

.assistant-close-button {
    width: 32px;
    padding: 0;
}

.assistant-fullscreen-button:hover,
.assistant-close-button:hover,
.assistant-launcher:hover {
    filter: brightness(0.98);
}

.assistant-fullscreen-button svg,
.assistant-close-button svg {
    width: 17px;
    height: 17px;
}

.assistant-panel-title {
    min-width: 0;
    display: grid;
    gap: 2px;
}

.assistant-panel-title strong,
.assistant-panel-title span {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.assistant-panel-title strong {
    font-size: 14px;
}

.assistant-panel-title span {
    color: #62716c;
    font-size: 12px;
}

.assistant-chat-body {
    min-height: 0;
    padding: 14px 20px 12px;
    overflow: auto;
    scrollbar-gutter: stable;
    background:
        radial-gradient(circle at 14% 8%, rgb(252 226 232 / 48%), transparent 26%),
        radial-gradient(circle at 88% 0%, rgb(218 235 255 / 58%), transparent 30%),
        #ffffff;
}

.assistant-welcome {
    min-height: 100%;
    display: grid;
    align-content: center;
    gap: 16px;
}

.assistant-avatar {
    width: 58px;
    height: 58px;
    border-radius: 50%;
    background: linear-gradient(135deg, #f9f0e8, #e8f4ff);
    color: #176b4d;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 8px 22px rgb(23 32 29 / 12%);
}

.assistant-avatar svg {
    width: 28px;
    height: 28px;
}

.assistant-welcome h2,
.assistant-welcome p {
    margin: 0;
    letter-spacing: 0;
}

.assistant-welcome h2 {
    font-size: 28px;
    line-height: 1.28;
}

.assistant-welcome p {
    color: #4f615a;
    font-size: 16px;
    font-weight: 650;
}

.assistant-suggestions {
    display: grid;
    gap: 10px;
    margin-top: 14px;
}

.assistant-suggestions button {
    min-height: 50px;
    padding: 0 12px 0 14px;
    border: 1px solid #e4ebe8;
    border-radius: 999px;
    background: #ffffff;
    color: #293934;
    display: grid;
    grid-template-columns: auto minmax(0, 1fr) auto;
    align-items: center;
    gap: 10px;
    box-shadow: 0 6px 16px rgb(23 32 29 / 5%);
    text-align: left;
}

.assistant-suggestions button:hover {
    border-color: #bfd6cc;
    background: #fbfdfc;
}

.assistant-suggestions svg {
    width: 16px;
    height: 16px;
    color: #176b4d;
}

.assistant-suggestions span {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.assistant-messages {
    display: grid;
    gap: 14px;
}

.assistant-message {
    max-width: 100%;
    display: block;
}

.assistant-message.user {
    max-width: 82%;
    margin-left: auto;
    display: flex;
    justify-content: flex-end;
}

.assistant-message.assistant {
    max-width: 100%;
    width: 100%;
    margin-right: auto;
}

.assistant-message-content {
    padding: 0;
    border-radius: 0;
    background: transparent;
    color: #17201d;
    font-size: 15px;
    line-height: 1.72;
    overflow-wrap: anywhere;
}

.assistant-message.user .assistant-message-content {
    padding: 10px 13px;
    border-radius: 8px;
    background: #176b4d;
    color: #ffffff;
    font-size: 14px;
    line-height: 1.55;
}

.assistant-message.error .assistant-message-content {
    padding: 10px 12px;
    border-radius: 8px;
    background: #fff1ed;
    color: #9e2f22;
}

.assistant-message-content p {
    margin: 0;
}

.assistant-message-content p + p {
    margin-top: 8px;
}

.assistant-message-content h2,
.assistant-message-content h3 {
    margin: 10px 0 6px;
    color: #183a2b;
    letter-spacing: 0;
    line-height: 1.35;
}

.assistant-message-content h2 {
    font-size: 17px;
    font-weight: 780;
}

.assistant-message-content h3 {
    font-size: 15px;
    font-weight: 760;
}

.assistant-message-content hr {
    height: 1px;
    margin: 10px 0;
    border: 0;
    background: #dce8e2;
}

.assistant-message-content ul,
.assistant-message-content ol {
    margin: 6px 0;
    padding-left: 20px;
}

.assistant-message-content li + li {
    margin-top: 4px;
}

.assistant-message-content a {
    color: #176b4d;
    font-weight: 700;
    text-decoration: none;
}

.assistant-message.user .assistant-message-content a {
    color: #ffffff;
    text-decoration: underline;
}

.assistant-message-content code {
    padding: 2px 5px;
    border-radius: 5px;
    background: #e8f1ed;
    color: #163d2c;
    font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
    font-size: 12px;
}

.assistant-message.user .assistant-message-content code {
    background: rgb(255 255 255 / 18%);
    color: #ffffff;
}

.assistant-message-content pre {
    margin: 8px 0 0;
    padding: 10px 12px;
    overflow-x: auto;
    border: 1px solid #dce8e2;
    border-radius: 8px;
    background: #f7faf8;
}

.assistant-message-content pre code {
    padding: 0;
    border-radius: 0;
    background: transparent;
    color: #17201d;
    white-space: pre;
}

.assistant-table-wrap {
    max-width: 100%;
    margin: 8px 0;
    overflow-x: auto;
    border: 1px solid #dce8e2;
    border-radius: 8px;
    background: #ffffff;
}

.assistant-message-content table {
    width: 100%;
    min-width: 320px;
    border-collapse: collapse;
}

.assistant-message-content th,
.assistant-message-content td {
    padding: 8px 10px;
    border-bottom: 1px solid #e6eee9;
    text-align: left;
    vertical-align: top;
    font-size: 13px;
}

.assistant-message-content th {
    background: #f0f7f3;
    color: #214b38;
    font-weight: 750;
}

.assistant-message-content tr:last-child td {
    border-bottom: 0;
}

.assistant-typing,
.assistant-event-card {
    color: #62716c;
    font-size: 13px;
}

.assistant-event-card {
    width: 100%;
    min-height: 42px;
    padding: 10px 12px;
    border: 1px solid #e2eae6;
    border-radius: 8px;
    background: rgb(255 255 255 / 86%);
    color: #42524c;
    display: grid;
    grid-template-columns: auto minmax(0, 1fr);
    align-items: center;
    gap: 9px;
}

.assistant-event-marker {
    width: 18px;
    height: 18px;
    border-radius: 50%;
    border: 1px solid #a7b8b0;
    color: #496258;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    font-weight: 800;
}

.assistant-event-card.completed .assistant-event-marker {
    border-color: #7cb694;
    color: #1f6b3a;
}

.assistant-event-card.failed,
.assistant-event-card.error {
    border-color: #f2c8bd;
    background: #fff8f6;
    color: #9e2f22;
}

.assistant-event-text {
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.assistant-composer {
    padding: 12px 14px 14px;
    background: #ffffff;
}

.assistant-composer-card {
    min-height: 118px;
    padding: 16px 16px 13px;
    border: 1px solid #dce5e1;
    border-radius: 8px;
    background: #ffffff;
    box-shadow: 0 8px 24px rgb(23 32 29 / 6%);
    display: grid;
    grid-template-rows: minmax(48px, 1fr) auto;
    gap: 10px;
}

.assistant-composer-action {
    display: flex;
    justify-content: flex-end;
}

.assistant-composer textarea {
    min-height: 48px;
    max-height: 96px;
    resize: none;
    border: 0;
    outline: 0;
    padding: 0;
    background: transparent;
    color: #17201d;
    font-size: 15px;
    line-height: 1.55;
}

.assistant-composer textarea::placeholder {
    color: #8a9692;
    font-size: 15px;
}

.assistant-send-button {
    width: 38px;
    height: 38px;
    border: 0;
    border-radius: 50%;
    background: #176b4d;
    color: #ffffff;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.assistant-send-button svg {
    width: 17px;
    height: 17px;
}

.toast {
    position: fixed;
    right: 18px;
    bottom: 18px;
    max-width: min(420px, calc(100vw - 36px));
    min-height: 42px;
    padding: 11px 14px;
    border-radius: 8px;
    background: #17201d;
    color: #ffffff;
    box-shadow: 0 12px 36px rgb(23 32 29 / 18%);
    transform: translateY(90px);
    opacity: 0;
    transition: transform 160ms ease, opacity 160ms ease;
    overflow-wrap: anywhere;
    z-index: 10;
}

.toast.visible {
    transform: translateY(0);
    opacity: 1;
}

.toast.error {
    background: #9e2f22;
}

@media (max-width: 1180px) {
    .kpi-grid {
        grid-template-columns: repeat(3, minmax(140px, 1fr));
    }

    .flow-steps {
        grid-template-columns: repeat(3, minmax(130px, 1fr));
    }

    .form-grid,
    .compact-form {
        grid-template-columns: repeat(3, minmax(132px, 1fr));
    }

    .form-grid button {
        width: fit-content;
    }

    .three-column {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 760px) {
    .topbar {
        align-items: flex-start;
        flex-direction: column;
        padding: 14px 16px;
    }

    .topbar-actions {
        width: 100%;
        justify-content: space-between;
    }

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

    .sidebar {
        border-right: 0;
        border-bottom: 1px solid #d6ded9;
        padding: 10px;
        overflow-x: auto;
        flex-direction: row;
    }

    .nav-button {
        width: auto;
        min-width: 94px;
    }

    .workspace {
        padding: 16px;
    }

    .section-heading {
        flex-direction: column;
        gap: 6px;
    }

    .kpi-grid,
    .flow-steps,
    .form-grid,
    .compact-form {
        grid-template-columns: 1fr;
    }

    .form-grid button,
    .compact-form button,
    .operation-form button {
        width: 100%;
    }

    .kpi-card {
        min-height: 96px;
    }

    table {
        min-width: 620px;
    }

    .erp-ai-dock {
        right: 12px;
        bottom: 12px;
    }

    .erp-ai-panel {
        width: calc(100vw - 24px);
        height: min(620px, calc(100vh - 24px));
        min-height: 420px;
    }

    .assistant-panel-bar {
        grid-template-columns: auto minmax(0, 1fr) auto;
    }

    .assistant-fullscreen-button span {
        display: none;
    }
}
