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

:root {
    --accent: #6C5CE7;
    --accent-soft: #8B7DF0;
    --green: #1FAA59;
    --yellow: #C68A12;
    --red: #E0524D;
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
}

[data-theme="dark"] {
    --bg: #131316;
    --bg2: #1A1A1E;
    --surface: #1A1A1E;
    --surface-hover: #202024;
    --border: rgba(255, 255, 255, 0.08);
    --border-strong: rgba(255, 255, 255, 0.14);
    --text: #ECECEE;
    --text-muted: rgba(236, 236, 238, 0.55);
    --text-dim: rgba(236, 236, 238, 0.32);
    --shadow: rgba(0, 0, 0, 0.3);
    --bubble-ai-bg: #1E1B2E;
    --bubble-ai-border: rgba(108, 92, 231, 0.25);
    --bubble-ai-text: #ECECEE;
    --bubble-user-bg: #202024;
    --bubble-user-text: #ECECEE;
    --scrollbar: rgba(255, 255, 255, 0.12);
    --accent-tint: rgba(108, 92, 231, 0.14);
}

[data-theme="light"] {
    --bg: #FAFAFA;
    --bg2: #FFFFFF;
    --surface: #FFFFFF;
    --surface-hover: #F2F1F8;
    --border: rgba(20, 20, 30, 0.08);
    --border-strong: rgba(20, 20, 30, 0.14);
    --text: #1B1B1F;
    --text-muted: rgba(27, 27, 31, 0.55);
    --text-dim: rgba(27, 27, 31, 0.35);
    --shadow: rgba(20, 20, 40, 0.06);
    --bubble-ai-bg: #F1EFFC;
    --bubble-ai-border: rgba(108, 92, 231, 0.18);
    --bubble-ai-text: #1B1B1F;
    --bubble-user-bg: #F2F1F4;
    --bubble-user-text: #1B1B1F;
    --scrollbar: rgba(20, 20, 30, 0.14);
    --accent-tint: rgba(108, 92, 231, 0.08);
}

body {
    background: var(--bg);
    font-family: 'Inter', sans-serif;
    color: var(--text);
    transition: background 0.25s, color 0.25s;
    -webkit-font-smoothing: antialiased;
}

/* ── LAYOUT ── */
.app {
    display: flex;
    height: 100vh;
    width: 100%;
    position: relative;
}

.chat-side {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
    height: 100vh;
}

/* ── TOP NAV ── */
.topnav {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 14px 20px;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

.inventory-toggle {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    font-weight: 500;
    color: var(--text-muted);
    background: transparent;
    cursor: pointer;
    padding: 6px 10px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    transition: color 0.15s, border-color 0.15s, background 0.15s;
    white-space: nowrap;
}

.inventory-toggle:hover {
    color: var(--accent);
    border-color: var(--accent);
    background: var(--accent-tint);
}

.inventory-toggle i {
    font-size: 14px;
}

.inv-badge {
    background: var(--accent);
    color: white;
    font-size: 10px;
    font-weight: 700;
    min-width: 16px;
    height: 16px;
    border-radius: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 4px;
}

.logo {
    width: 30px;
    height: 30px;
    background: var(--accent);
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 15px;
    color: white;
    flex-shrink: 0;
}

.title-block h1 {
    font-size: 14px;
    font-weight: 600;
    letter-spacing: -0.01em;
}

.title-block p {
    font-size: 11px;
    color: var(--text-muted);
    margin-top: 1px;
}

.nav-right {
    margin-left: auto;
    display: flex;
    align-items: center;
    gap: 10px;
}

.sheet-link {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    font-weight: 500;
    color: var(--text-muted);
    text-decoration: none;
    padding: 6px 10px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    transition: color 0.15s, border-color 0.15s, background 0.15s;
    white-space: nowrap;
}

.sheet-link:hover {
    color: var(--accent);
    border-color: var(--accent);
    background: var(--accent-tint);
}

.sheet-link i {
    font-size: 14px;
}

.sheet-link--block {
    margin: 12px;
    justify-content: center;
    padding: 9px 10px;
}

.status-dot {
    display: flex;
    align-items: center;
    gap: 5px;
    font-size: 12px;
    color: var(--text-muted);
}

.status-dot span {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--green);
    animation: pulse 2s infinite;
}

@keyframes pulse {

    0%,
    100% {
        opacity: 1;
    }

    50% {
        opacity: 0.35;
    }
}

.theme-btn {
    width: 32px;
    height: 32px;
    background: transparent;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 15px;
    color: var(--text-muted);
    transition: color 0.15s, border-color 0.15s;
}

.theme-btn:hover {
    color: var(--accent);
    border-color: var(--accent);
}

/* ── CHAT MESSAGES ── */
.chat-wrap {
    flex: 1;
    overflow-y: auto;
    padding: 28px 20px;
    display: flex;
    flex-direction: column;
    gap: 16px;
    min-height: 0;
}

.chat-inner {
    width: 100%;
    max-width: 680px;
    margin: 0 auto;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

@keyframes msgIn {
    from {
        opacity: 0;
        transform: translateY(6px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.msg {
    display: flex;
    gap: 10px;
    align-items: flex-end;
    animation: msgIn 0.2s ease;
}

.msg.user {
    flex-direction: row-reverse;
}

.avatar {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 13px;
    flex-shrink: 0;
}

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

.avatar.user-av {
    background: var(--surface-hover);
    border: 1px solid var(--border);
    color: var(--text-muted);
}

.bubble {
    max-width: 75%;
    padding: 10px 14px;
    border-radius: var(--radius-md);
    font-size: 14px;
    line-height: 1.65;
}

.bubble.howie-bubble {
    background: var(--bubble-ai-bg);
    border: 1px solid var(--bubble-ai-border);
    color: var(--bubble-ai-text);
    border-bottom-left-radius: 4px;
}

.bubble.user-bubble {
    background: var(--bubble-user-bg);
    border: 1px solid var(--border);
    color: var(--bubble-user-text);
    border-bottom-right-radius: 4px;
}

.action-tag {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    background: var(--accent-tint);
    color: var(--accent-soft);
    font-size: 10px;
    font-weight: 700;
    padding: 2px 8px;
    border-radius: 4px;
    margin-bottom: 7px;
    letter-spacing: 0.5px;
    text-transform: uppercase;
}

/* ── SUGGESTIONS ── */
.suggestions {
    padding: 0 20px 12px;
    display: flex;
    flex-wrap: wrap;
    gap: 7px;
    flex-shrink: 0;
    max-width: 720px;
    margin: 0 auto;
    width: 100%;
}

.sug-btn {
    background: transparent;
    border: 1px solid var(--border);
    border-radius: 20px;
    padding: 6px 13px;
    font-size: 12px;
    font-family: 'Inter', sans-serif;
    color: var(--text-muted);
    cursor: pointer;
    transition: color 0.15s, border-color 0.15s, background 0.15s;
    white-space: nowrap;
}

.sug-btn:hover {
    background: var(--accent-tint);
    border-color: var(--accent);
    color: var(--accent-soft);
}

/* ── INPUT BAR ── */
.input-bar {
    padding: 12px 20px 14px;
    flex-shrink: 0;
    border-top: 1px solid var(--border);
}

.input-inner {
    max-width: 680px;
    margin: 0 auto;
    display: flex;
    gap: 8px;
    align-items: center;
    background: var(--bg2);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 6px 6px 6px 14px;
    transition: border-color 0.15s;
}

.input-inner:focus-within {
    border-color: var(--accent);
}

.input-inner input {
    flex: 1;
    background: transparent;
    border: none;
    outline: none;
    font-size: 14px;
    font-family: 'Inter', sans-serif;
    color: var(--text);
}

.input-inner input::placeholder {
    color: var(--text-dim);
}

.send-btn {
    width: 34px;
    height: 34px;
    background: var(--accent);
    border: none;
    border-radius: var(--radius-sm);
    cursor: pointer;
    color: white;
    font-size: 15px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: opacity 0.15s, transform 0.1s;
}

.send-btn:hover {
    opacity: 0.88;
}

.send-btn:active {
    transform: scale(0.95);
}

.send-btn:disabled {
    opacity: 0.3;
    cursor: not-allowed;
    transform: none;
}

.footer-credit {
    text-align: center;
    font-size: 11px;
    color: var(--text-dim);
    margin-top: 10px;
}

.footer-credit a {
    color: var(--text-muted);
    text-decoration: none;
    font-weight: 500;
    border-bottom: 1px solid var(--border-strong);
    transition: color 0.15s, border-color 0.15s;
}

.footer-credit a:hover {
    color: var(--accent);
    border-color: var(--accent);
}

/* ── TYPING ── */
.typing {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 2px 0;
}

.typing span {
    width: 5px;
    height: 5px;
    border-radius: 50%;
    background: var(--accent);
    animation: typeblink 1.2s infinite;
}

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

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

@keyframes typeblink {

    0%,
    80%,
    100% {
        opacity: 0.2;
        transform: scale(0.75);
    }

    40% {
        opacity: 1;
        transform: scale(1);
    }
}

/* ── INVENTORY SIDEBAR ── */
.sidebar {
    width: 300px;
    flex-shrink: 0;
    height: 100vh;
    display: flex;
    flex-direction: column;
    border-left: 1px solid var(--border);
    background: var(--surface);
}

.sidebar-header {
    padding: 14px 16px;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
    font-weight: 600;
    color: var(--text-muted);
    flex-shrink: 0;
}

.sidebar-header i {
    font-size: 15px;
    color: var(--accent);
}

.count-pill {
    margin-left: auto;
    background: var(--accent-tint);
    color: var(--accent);
    font-size: 11px;
    font-weight: 700;
    padding: 2px 9px;
    border-radius: 20px;
}

.sidebar-close {
    display: none;
    width: 26px;
    height: 26px;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: none;
    color: var(--text-muted);
    font-size: 16px;
    cursor: pointer;
}

/* ── STATS ROW ── */
.stats-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    padding: 12px;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

.stat-card {
    background: var(--bg2);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 10px 12px;
}

.stat-card .label {
    font-size: 10px;
    font-weight: 600;
    color: var(--text-dim);
    letter-spacing: 0.6px;
    text-transform: uppercase;
    margin-bottom: 4px;
}

.stat-card .value {
    font-size: 17px;
    font-weight: 600;
    color: var(--text);
}

.stat-card .value.accent {
    color: var(--accent);
}

/* ── TABLE ── */
.table-wrap {
    flex: 1;
    overflow-y: auto;
    padding: 8px;
}

table {
    width: 100%;
    border-collapse: collapse;
    font-size: 12px;
}

thead th {
    text-align: left;
    padding: 7px 8px;
    font-size: 10px;
    font-weight: 600;
    color: var(--text-dim);
    letter-spacing: 0.7px;
    text-transform: uppercase;
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    background: var(--surface);
}

tbody tr {
    border-bottom: 1px solid var(--border);
    transition: background 0.15s;
}

tbody tr:last-child {
    border-bottom: none;
}

tbody tr:hover {
    background: var(--surface-hover);
}

tbody td {
    padding: 10px 8px;
    color: var(--text-muted);
}

tbody td:first-child {
    font-weight: 500;
    color: var(--text);
    max-width: 100px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.stock-badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 20px;
    font-size: 10px;
    font-weight: 600;
}

.stock-ok {
    background: rgba(31, 170, 89, 0.12);
    color: var(--green);
}

.stock-low {
    background: rgba(198, 138, 18, 0.12);
    color: var(--yellow);
}

.stock-out {
    background: rgba(224, 82, 77, 0.12);
    color: var(--red);
}

@keyframes rowflash {
    0% {
        background: var(--accent-tint);
    }

    100% {
        background: transparent;
    }
}

.flash {
    animation: rowflash 1.3s ease forwards;
}

.empty-state {
    text-align: center;
    padding: 40px 16px;
    color: var(--text-dim);
    font-size: 12px;
    line-height: 1.9;
}

.empty-state i {
    font-size: 28px;
    display: block;
    margin-bottom: 8px;
    opacity: 0.4;
}

/* ── SCROLLBAR ── */
::-webkit-scrollbar {
    width: 3px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: var(--scrollbar);
    border-radius: 4px;
}

/* ── MOBILE ── */
.sidebar-backdrop {
    display: none;
}

@media (max-width: 860px) {
    .topnav {
        flex-wrap: wrap;
        row-gap: 10px;
    }

    .nav-right {
        order: 3;
        width: 100%;
        margin-left: 0;
        justify-content: flex-start;
        flex-wrap: wrap;
    }

    .status-dot {
        margin-left: auto;
    }

    .sidebar {
        position: fixed;
        top: 0;
        right: 0;
        z-index: 30;
        width: min(320px, 86vw);
        transform: translateX(100%);
        transition: transform 0.25s ease;
        box-shadow: -8px 0 30px var(--shadow);
    }

    .sidebar.open {
        transform: translateX(0);
    }

    .sidebar-close {
        display: flex;
        margin-left: 4px;
    }

    .sidebar-backdrop {
        position: fixed;
        inset: 0;
        background: rgba(0, 0, 0, 0.4);
        z-index: 20;
        opacity: 0;
        pointer-events: none;
        transition: opacity 0.25s ease;
    }

    .sidebar-backdrop.open {
        opacity: 1;
        pointer-events: auto;
    }

    .bubble {
        max-width: 86%;
    }

    .suggestions {
        padding: 0 14px 10px;
    }

    .topnav {
        padding: 12px 14px;
    }

    .chat-wrap {
        padding: 20px 14px;
    }

    .input-bar {
        padding: 10px 14px 12px;
    }
}
