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

:root {
    --sidebar: #171717;
    --sidebar-hover: #262626;
    --background: #ffffff;
    --surface: #f7f7f8;
    --border: #e5e5e5;
    --text: #171717;
    --muted: #737373;
    --accent: #10a37f;
}

html,
body {
    width: 100%;
    height: 100%;
    font-family:
        Inter,
        ui-sans-serif,
        -apple-system,
        BlinkMacSystemFont,
        "Segoe UI",
        sans-serif;
    color: var(--text);
    background: var(--background);
}

button,
textarea {
    font: inherit;
}

button {
    cursor: pointer;
}

.app {
    display: flex;
    width: 100%;
    height: 100vh;
    overflow: hidden;
}


/* ==============================
   SIDEBAR
   ============================== */

.sidebar {
    width: 270px;
    min-width: 270px;
    height: 100vh;
    background: var(--sidebar);
    color: white;
    display: flex;
    flex-direction: column;
    padding: 14px;
}

.sidebar-top {
    display: flex;
    flex-direction: column;
    gap: 18px;
}

.brand {
    display: flex;
    align-items: center;
    gap: 11px;
    padding: 8px;
}

.brand-icon,
.welcome-logo {
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    background: var(--accent);
    color: white;
}

.brand-icon {
    width: 38px;
    height: 38px;
    border-radius: 10px;
    font-size: 13px;
}

.brand-name {
    font-size: 15px;
    font-weight: 600;
}

.brand-subtitle {
    color: #a3a3a3;
    font-size: 12px;
    margin-top: 2px;
}

.new-chat {
    width: 100%;
    border: 1px solid #404040;
    background: transparent;
    color: white;
    padding: 11px 13px;
    border-radius: 9px;
    text-align: left;
    transition: background 0.15s ease;
}

.new-chat:hover {
    background: var(--sidebar-hover);
}

.sidebar-section {
    margin-top: 26px;
    overflow-y: auto;
}

.sidebar-label {
    color: #737373;
    font-size: 11px;
    font-weight: 600;
    padding: 8px 10px;
    letter-spacing: 0.08em;
}

.quick-link {
    display: block;
    width: 100%;
    border: 0;
    background: transparent;
    color: #e5e5e5;
    text-align: left;
    padding: 10px;
    border-radius: 8px;
    font-size: 14px;
}

.quick-link:hover {
    background: var(--sidebar-hover);
}

.sidebar-footer {
    margin-top: auto;
    display: flex;
    align-items: center;
    gap: 8px;
    color: #a3a3a3;
    border-top: 1px solid #303030;
    padding: 15px 8px 4px;
    font-size: 12px;
}

.status-dot {
    width: 8px;
    height: 8px;
    background: #22c55e;
    border-radius: 50%;
}


/* ==============================
   MAIN
   ============================== */

.main {
    flex: 1;
    min-width: 0;
    height: 100vh;
    display: flex;
    flex-direction: column;
    background: white;
}

.topbar {
    height: 62px;
    min-height: 62px;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    padding: 0 22px;
    background: rgba(255, 255, 255, 0.96);
}

.topbar-title {
    font-size: 14px;
    font-weight: 600;
}

.topbar-subtitle {
    font-size: 11px;
    color: var(--muted);
    margin-top: 2px;
}

.menu-button {
    display: none;
    border: 0;
    background: transparent;
    margin-right: 12px;
    font-size: 20px;
}


/* ==============================
   CHAT AREA
   ============================== */

.chat-area {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    scroll-behavior: smooth;
}

.welcome {
    max-width: 760px;
    margin: 0 auto;
    padding: 11vh 24px 80px;
    text-align: center;
}

.welcome-logo {
    width: 54px;
    height: 54px;
    margin: 0 auto 22px;
    border-radius: 16px;
    font-size: 17px;
}

.welcome h1 {
    font-size: 30px;
    letter-spacing: -0.03em;
    margin-bottom: 10px;
}

.welcome > p {
    color: var(--muted);
    font-size: 15px;
    line-height: 1.6;
}

.suggestions {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
    margin-top: 34px;
}

.suggestion {
    border: 1px solid var(--border);
    background: white;
    padding: 16px;
    border-radius: 13px;
    text-align: left;
    transition:
        background 0.15s ease,
        border 0.15s ease;
}

.suggestion:hover {
    background: var(--surface);
    border-color: #d4d4d4;
}

.suggestion strong {
    display: block;
    font-size: 14px;
    margin-bottom: 5px;
}

.suggestion span {
    color: var(--muted);
    font-size: 12px;
}


/* ==============================
   MESSAGES
   ============================== */

.messages {
    display: none;
    width: 100%;
}

.message {
    width: 100%;
    padding: 24px;
}

.message-inner {
    max-width: 820px;
    margin: 0 auto;
    display: flex;
    gap: 16px;
}

.message.user {
    background: var(--surface);
}

.avatar {
    flex: 0 0 auto;
    width: 31px;
    height: 31px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 11px;
    font-weight: 700;
}

.user .avatar {
    background: #262626;
    color: white;
}

.assistant .avatar {
    background: var(--accent);
    color: white;
}

.message-content {
    min-width: 0;
    flex: 1;
    line-height: 1.7;
    font-size: 14px;
    overflow-wrap: anywhere;
}

.message-content p {
    margin-bottom: 12px;
}

.message-content p:last-child {
    margin-bottom: 0;
}

.message-content ul,
.message-content ol {
    margin: 8px 0 14px 24px;
}

.message-content li {
    margin: 4px 0;
}

.message-content h1,
.message-content h2,
.message-content h3 {
    margin: 20px 0 10px;
}

.message-content strong {
    font-weight: 650;
}


/* ==============================
   ERP TABLES
   ============================== */

.message-content table {
    width: 100%;
    border-collapse: collapse;
    margin: 16px 0;
    font-size: 13px;
    display: block;
    overflow-x: auto;
}

.message-content th,
.message-content td {
    border: 1px solid var(--border);
    padding: 9px 12px;
    text-align: left;
    white-space: nowrap;
}

.message-content th {
    background: var(--surface);
    font-weight: 600;
}

.message-content tr:nth-child(even) td {
    background: #fcfcfc;
}


/* ==============================
   LOADING
   ============================== */

.typing {
    display: flex;
    align-items: center;
    gap: 5px;
    height: 28px;
}

.typing span {
    width: 7px;
    height: 7px;
    background: #a3a3a3;
    border-radius: 50%;
    animation: typing 1.2s infinite ease-in-out;
}

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

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

@keyframes typing {
    0%,
    60%,
    100% {
        opacity: 0.3;
        transform: translateY(0);
    }

    30% {
        opacity: 1;
        transform: translateY(-4px);
    }
}


/* ==============================
   COMPOSER
   ============================== */

.composer-wrapper {
    padding: 12px 22px 15px;
    background: white;
}

.composer {
    max-width: 820px;
    margin: 0 auto;
    border: 1px solid #d4d4d4;
    border-radius: 16px;
    display: flex;
    align-items: flex-end;
    padding: 9px 9px 9px 15px;
    box-shadow:
        0 1px 2px rgba(0, 0, 0, 0.03),
        0 4px 14px rgba(0, 0, 0, 0.04);
}

.composer:focus-within {
    border-color: #a3a3a3;
}

#messageInput {
    flex: 1;
    border: 0;
    outline: 0;
    resize: none;
    max-height: 180px;
    min-height: 28px;
    line-height: 1.5;
    padding: 4px 8px 3px 0;
    background: transparent;
}

.send-button {
    width: 35px;
    height: 35px;
    min-width: 35px;
    border: 0;
    border-radius: 10px;
    background: #171717;
    color: white;
    font-size: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.send-button:hover {
    background: #303030;
}

.send-button:disabled {
    background: #d4d4d4;
    cursor: default;
}

.disclaimer {
    max-width: 820px;
    margin: 8px auto 0;
    text-align: center;
    color: #a3a3a3;
    font-size: 10px;
}


/* ==============================
   ERROR
   ============================== */

.error-message {
    color: #b91c1c;
}


/* ==============================
   MOBILE
   ============================== */

@media (max-width: 760px) {

    .sidebar {
        position: fixed;
        left: -280px;
        top: 0;
        z-index: 100;
        transition: left 0.2s ease;
        box-shadow: 8px 0 30px rgba(0, 0, 0, 0.15);
    }

    .sidebar.open {
        left: 0;
    }

    .menu-button {
        display: block;
    }

    .welcome {
        padding-top: 8vh;
    }

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

    .message {
        padding: 20px 15px;
    }

    .message-inner {
        gap: 11px;
    }

    .composer-wrapper {
        padding: 9px 10px 12px;
    }

    .topbar {
        padding: 0 14px;
    }
}


/* ============================================================
   CHAT HISTORY
   ============================================================ */

.conversation-history {
    flex: 1;
    overflow-y: auto;
    padding: 8px 10px 20px;
    min-height: 0;
}

.history-heading {
    padding: 12px 10px 7px;
    font-size: 12px;
    font-weight: 600;
    color: #8f8f8f;
}

.history-empty {
    padding: 10px;
    font-size: 13px;
    line-height: 1.45;
    color: #777;
}

.history-item {
    width: 100%;
    border: 0;
    background: transparent;
    color: inherit;
    font: inherit;

    display: flex;
    align-items: center;
    gap: 6px;

    min-height: 38px;

    padding: 8px 8px 8px 10px;
    margin: 1px 0;

    border-radius: 8px;

    cursor: pointer;
    text-align: left;
}

.history-item:hover {
    background: rgba(255,255,255,0.08);
}

.history-item.active {
    background: rgba(255,255,255,0.11);
}

.history-title {
    flex: 1;
    min-width: 0;

    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;

    font-size: 14px;
}

.history-delete {
    width: 25px;
    height: 25px;

    display: flex;
    align-items: center;
    justify-content: center;

    border-radius: 6px;

    font-size: 19px;
    line-height: 1;

    opacity: 0;
    transition: opacity 0.15s ease,
                background 0.15s ease;
}

.history-item:hover
.history-delete {
    opacity: 0.7;
}

.history-delete:hover {
    opacity: 1 !important;
    background: rgba(255,255,255,0.12);
}


/* ============================================================
   MESSAGE ACTIONS
   ============================================================ */

.message-copy-button {
    display: block;

    margin-top: 8px;

    border: 0;
    background: transparent;

    padding: 5px 7px;

    border-radius: 6px;

    color: #777;

    font-size: 12px;

    cursor: pointer;

    opacity: 0;

    transition:
        opacity 0.15s ease,
        background 0.15s ease;
}

.message:hover
.message-copy-button {
    opacity: 1;
}

.message-copy-button:hover {
    background: #f1f1f1;
    color: #333;
}


/* ============================================================
   ERP TABLE RESPONSIVENESS
   ============================================================ */

.message-content {
    min-width: 0;
}

.message-content table {
    display: block;

    width: 100%;
    max-width: 100%;

    overflow-x: auto;

    white-space: nowrap;

    -webkit-overflow-scrolling:
        touch;
}


/* ============================================================
   MOBILE HISTORY
   ============================================================ */

@media (max-width: 760px) {

    .conversation-history {
        padding-bottom: 30px;
    }

    .history-delete {
        opacity: 0.65;
    }

    .message-copy-button {
        opacity: 0.75;
    }
}


/* ============================================================
   ASSISTANT COPY ACTION ALIGNMENT
   ============================================================ */

.message-content .message-copy-button {
    display: block;

    width: fit-content;

    margin-top: 10px;
    margin-left: 0;

    position: static;

    font-size: 13px;
    line-height: 1.4;

    border: 0;
    border-radius: 6px;

    padding: 5px 7px;

    background: transparent;
    color: #737373;

    cursor: pointer;
}

.message-content .message-copy-button:hover {
    background: #f1f1f1;
    color: #171717;
}


/* ============================================================
   HISTORY THREE-DOT MENU FIX
   ============================================================ */

.history-item {
    position: relative;
    overflow: visible;
}

.history-title {
    padding-right: 34px;
}

/* Three-dot trigger */

.history-menu-button {
    flex: 0 0 auto;

    width: 28px;
    height: 28px;

    display: flex;
    align-items: center;
    justify-content: center;

    border: 0;
    border-radius: 6px;

    background: transparent;
    color: #b5b5b5;

    font-size: 18px;
    line-height: 1;

    cursor: pointer;

    opacity: 0;

    transition:
        opacity 0.15s ease,
        background 0.15s ease,
        color 0.15s ease;
}

.history-item:hover .history-menu-button,
.history-item.active .history-menu-button,
.history-menu-button:focus {
    opacity: 1;
}

.history-menu-button:hover {
    background: rgba(255,255,255,0.10);
    color: #ffffff;
}


/* Dropdown */

.history-menu {
    position: fixed;

    z-index: 10000;

    min-width: 145px;

    padding: 6px;

    border: 1px solid #3a3a3a;
    border-radius: 9px;

    background: #242424;

    box-shadow:
        0 8px 28px rgba(0,0,0,0.35);

    display: none;
}

.history-menu.open {
    display: block;
}


/* Dropdown actions */

.history-menu button {
    width: 100%;

    display: flex;
    align-items: center;

    border: 0;
    border-radius: 6px;

    padding: 9px 10px;

    background: transparent;
    color: #eeeeee;

    font: inherit;
    font-size: 13px;

    text-align: left;

    cursor: pointer;
}

.history-menu button:hover {
    background: rgba(255,255,255,0.09);
}

.history-menu .delete,
.history-menu .history-menu-delete {
    color: #ff8b8b;
}

.history-menu .delete:hover,
.history-menu .history-menu-delete:hover {
    background: rgba(255,80,80,0.12);
}


/* Old delete control should not interfere */

.history-delete {
    display: none !important;
}


/* Mobile */

@media (max-width: 760px) {

    .history-menu-button {
        opacity: 0.8;
    }

    .history-menu {
        min-width: 135px;
    }
}


/* ==========================================
   ERP WRITE CONFIRMATION CARD
   ========================================== */

.erp-confirmation-card {
    margin-top: 18px;
    border: 1px solid var(--border);
    border-radius: 12px;
    background: var(--surface);
    overflow: hidden;
}

.erp-confirmation-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 14px 16px;
    border-bottom: 1px solid var(--border);
}

.erp-confirmation-title {
    font-size: 14px;
    font-weight: 650;
}

.erp-confirmation-badge {
    display: inline-flex;
    align-items: center;
    padding: 4px 9px;
    border-radius: 999px;
    font-size: 11px;
    font-weight: 600;
    background: #fff3cd;
    color: #7a5800;
    white-space: nowrap;
}

.erp-operation-name {
    padding: 14px 16px 8px;
    font-size: 13px;
    font-weight: 650;
}

.erp-operation-details {
    padding: 0 16px 8px;
}

.erp-operation-row {
    display: grid;
    grid-template-columns: minmax(120px, 180px) 1fr;
    gap: 14px;
    padding: 9px 0;
    border-bottom: 1px solid var(--border);
}

.erp-operation-row:last-child {
    border-bottom: none;
}

.erp-operation-label {
    font-size: 12px;
    font-weight: 600;
    color: #737373;
}

.erp-operation-value {
    margin: 0;
    padding: 0;
    border: 0;
    background: transparent;
    font-family: inherit;
    font-size: 13px;
    line-height: 1.5;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
}

.erp-confirmation-expiry {
    padding: 8px 16px 12px;
    font-size: 12px;
    color: #737373;
}

.erp-confirmation-actions {
    display: flex;
    justify-content: flex-end;
    gap: 9px;
    padding: 13px 16px;
    border-top: 1px solid var(--border);
}

.erp-operation-cancel,
.erp-operation-confirm {
    min-height: 36px;
    padding: 7px 14px;
    border-radius: 8px;
    font-family: inherit;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition:
        opacity 0.15s ease,
        transform 0.15s ease;
}

.erp-operation-cancel {
    border: 1px solid var(--border);
    background: white;
    color: #262626;
}

.erp-operation-confirm {
    border: 1px solid #b42318;
    background: #b42318;
    color: white;
}

.erp-operation-cancel:hover:not(:disabled),
.erp-operation-confirm:hover:not(:disabled) {
    transform: translateY(-1px);
}

.erp-operation-cancel:disabled,
.erp-operation-confirm:disabled {
    opacity: 0.55;
    cursor: not-allowed;
}

.erp-status-success {
    background: #dcfce7;
    color: #166534;
}

.erp-status-cancelled {
    background: #f1f5f9;
    color: #475569;
}


/* Mobile */

@media (max-width: 640px) {
    .erp-operation-row {
        grid-template-columns: 1fr;
        gap: 4px;
    }

    .erp-confirmation-actions {
        flex-direction: column-reverse;
    }

    .erp-operation-cancel,
    .erp-operation-confirm {
        width: 100%;
    }
}


/* ==========================================
   ERP DOCUMENT DOWNLOAD / EXPORT CARDS
   ========================================== */

.erp-document-card {
    margin-top: 14px;
    border: 1px solid var(--border);
    border-radius: 12px;
    background: var(--surface);
    overflow: hidden;
}

.erp-document-header {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 14px 16px;
}

.erp-document-icon {
    width: 38px;
    height: 38px;
    flex: 0 0 38px;

    display: flex;
    align-items: center;
    justify-content: center;

    border-radius: 9px;

    background: #f1f5f9;
    color: #475569;

    font-size: 9px;
    font-weight: 750;
    letter-spacing: 0.4px;
}

.erp-document-title-area {
    min-width: 0;
    flex: 1;
}

.erp-document-type {
    margin-bottom: 2px;

    font-size: 12px;
    font-weight: 600;

    color: #737373;
}

.erp-document-name {
    font-size: 14px;
    font-weight: 650;

    overflow-wrap: anywhere;
}

.erp-document-actions {
    display: flex;
    align-items: center;
    flex-wrap: wrap;

    gap: 8px;

    padding: 12px 16px;

    border-top: 1px solid var(--border);
}

.erp-document-action {
    min-height: 34px;

    padding: 6px 12px;

    border: 1px solid var(--border);
    border-radius: 8px;

    background: white;
    color: #262626;

    font-family: inherit;
    font-size: 12px;
    font-weight: 600;

    cursor: pointer;

    transition:
        background 0.15s ease,
        border-color 0.15s ease,
        transform 0.15s ease;
}

.erp-document-action:hover {
    background: #f8fafc;
    transform: translateY(-1px);
}

.erp-action-preview {
    background: #262626;
    border-color: #262626;
    color: white;
}

.erp-action-preview:hover {
    background: #404040;
}

.erp-action-pdf {
    color: #b42318;
}

.erp-action-excel {
    color: #166534;
}

.erp-action-csv {
    color: #075985;
}

.erp-action-print {
    margin-left: auto;
}


/* Mobile */

@media (max-width: 640px) {

    .erp-document-actions {
        display: grid;

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

    .erp-document-action {
        width: 100%;
    }

    .erp-action-print {
        margin-left: 0;
    }
}
