:root {
    --ui-bg: #f3f6f9;
    --ui-surface: #ffffff;
    --ui-border: #d7e0e8;
    --ui-ink: #17242f;
    --ui-muted: #667784;
    --ui-primary: #1f5f94;
    --ui-primary-ink: #ffffff;
    --ui-danger: #8f1d1d;
    --ui-warning-bg: #fff1cf;
    --ui-warning-border: #e7c46f;
}

* { box-sizing: border-box; }

html, body {
    margin: 0 !important;
    padding: 0 !important;
}

body {
    font-family: "Segoe UI", Arial, sans-serif !important;
    color: var(--ui-ink) !important;
    background: var(--ui-bg) !important;
    line-height: 1.4 !important;
}

.page {
    width: min(1240px, calc(100% - 24px)) !important;
    margin: 0 auto !important;
    padding: 16px 0 28px !important;
}

.login {
    width: min(460px, calc(100% - 20px)) !important;
    margin: 28px auto !important;
    padding: 24px !important;
}

.site-topbar.app-topbar {
    position: sticky;
    top: 0;
    z-index: 20;
    display: flex !important;
    flex-wrap: wrap;
    gap: 10px !important;
    align-items: center;
    padding: 10px;
    margin: 0 0 14px !important;
    border: 1px solid var(--ui-border);
    border-radius: 10px;
    background: #ffffffee;
    backdrop-filter: blur(6px);
}

.site-brand {
    text-transform: none !important;
    letter-spacing: 0 !important;
    font-size: 15px !important;
    font-weight: 800 !important;
    color: var(--ui-primary) !important;
}

.site-nav {
    display: flex;
    flex-wrap: wrap;
    gap: 8px !important;
}

.site-nav a {
    border-radius: 8px !important;
    border: 1px solid var(--ui-border) !important;
    padding: 8px 10px !important;
    background: #fff !important;
    color: var(--ui-ink) !important;
    font-size: 13px !important;
    font-weight: 650 !important;
    text-decoration: none !important;
}

.site-nav a.active {
    color: var(--ui-primary-ink) !important;
    border-color: var(--ui-primary) !important;
    background: var(--ui-primary) !important;
}

.app-nav-toggle {
    display: none;
    margin-left: auto;
    border: 1px solid var(--ui-border);
    border-radius: 8px;
    padding: 8px 10px;
    background: #fff;
    color: var(--ui-ink);
    font: inherit;
    font-weight: 700;
}

.panel,
.hero,
.toolbar,
.table-wrap,
.add-panel,
.login,
.card,
.draft,
.account-card,
.provider-box,
.resource {
    background: var(--ui-surface) !important;
    border: 1px solid var(--ui-border) !important;
    border-radius: 10px !important;
    box-shadow: none !important;
}

.panel,
.hero,
.toolbar,
.add-panel {
    padding: 14px !important;
}

.hero { margin-bottom: 12px !important; }

.muted,
.hint,
.small,
.meta,
.lead {
    color: var(--ui-muted) !important;
}

h1, h2, h3 {
    letter-spacing: 0 !important;
    margin-top: 0 !important;
}

h1 {
    font-size: 28px !important;
    line-height: 1.15 !important;
}

h2 { font-size: 20px !important; }

input,
select,
textarea {
    border: 1px solid #cbd5df !important;
    border-radius: 8px !important;
    padding: 9px 10px !important;
    font: inherit !important;
    color: var(--ui-ink) !important;
    background: #fff !important;
}

button,
.button {
    border: 1px solid var(--ui-primary) !important;
    border-radius: 8px !important;
    padding: 9px 12px !important;
    background: var(--ui-primary) !important;
    color: var(--ui-primary-ink) !important;
    font: inherit !important;
    font-weight: 700 !important;
    cursor: pointer !important;
    text-decoration: none !important;
}

button.secondary,
.button.secondary,
.button.ghost {
    border-color: #aebdca !important;
    background: #edf3f8 !important;
    color: #1a3d5c !important;
}

.tabs {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    margin: 12px 0;
}

.tabs a {
    display: inline-flex;
    align-items: center;
    min-height: 36px;
    padding: 8px 12px;
    border: 1px solid #d8dee9;
    border-radius: 8px;
    background: #fff;
    color: #243044;
    font-weight: 700;
    text-decoration: none;
}

.tabs a.active {
    border-color: #1f7a8c;
    background: #e9f6f8;
    color: #125765;
}

button.danger,
.button.danger {
    border-color: #bd4747 !important;
    background: #bd4747 !important;
    color: #fff !important;
}

.notice,
.info,
.info-box,
.error,
.error-box,
.status,
.notice.success,
.notice.error,
.notice.info {
    border-radius: 8px !important;
    border: 1px solid var(--ui-border) !important;
    padding: 10px 12px !important;
    margin-bottom: 12px !important;
}

.notice,
.notice.success {
    background: #e9f7ef !important;
    color: #1d6336 !important;
}

.info,
.info-box,
.notice.info {
    background: #edf4fb !important;
    color: #28527a !important;
}

.error,
.error-box,
.notice.error {
    background: #fff4f2 !important;
    color: #a33a2f !important;
}

.status,
.badge,
.status-pill {
    display: inline-flex !important;
    align-items: center;
    border-radius: 999px !important;
    padding: 4px 9px !important;
    font-size: 12px !important;
    font-weight: 700 !important;
    border: 1px solid #d5dfe8 !important;
    background: #eef4fb !important;
    color: #2a4f78 !important;
}

.status.fail,
.status.disabled,
.status.cancelled,
.status.problem,
.status-pill.problem {
    background: #ffe8e8 !important;
    border-color: #e6a0a0 !important;
    color: var(--ui-danger) !important;
}

.status.pending,
.status.waiting {
    background: var(--ui-warning-bg) !important;
    border-color: var(--ui-warning-border) !important;
    color: #7a4a00 !important;
}

.status.ok,
.status.learned,
.status.active {
    background: #e9f7ef !important;
    border-color: #b9e4c6 !important;
    color: #25633f !important;
}

table {
    width: 100% !important;
    border-collapse: collapse !important;
}

th,
td {
    border-bottom: 1px solid #e7ebef !important;
    padding: 9px 10px !important;
    text-align: left;
    vertical-align: top;
}

th {
    background: #f0f3f6 !important;
    color: #52606d !important;
    font-size: 12px !important;
    text-transform: uppercase !important;
}

.table-wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.layout,
.grid {
    gap: 12px !important;
}

.cards {
    gap: 10px !important;
}

.hero .brand,
.eyebrow {
    display: inline-block;
    padding: 6px 10px;
    border-radius: 999px;
    background: #edf3f8;
    color: #2a4f78;
    font-size: 12px;
    font-weight: 700;
}

.lead {
    margin: 8px 0 0;
    font-size: 15px !important;
    line-height: 1.55 !important;
}

.layout {
    display: grid !important;
    grid-template-columns: minmax(260px, 320px) minmax(0, 1fr) !important;
    align-items: start !important;
}

.grid {
    display: grid !important;
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
    align-items: start !important;
}

.cards,
.summary {
    display: grid !important;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)) !important;
}

.metric,
.draft,
.account-card,
.resource,
.provider-box {
    padding: 12px !important;
}

.metric strong,
.card .v {
    display: block;
    font-size: 24px !important;
    line-height: 1.2;
    margin-top: 4px;
}

.card .k {
    font-size: 12px !important;
    text-transform: uppercase;
    color: var(--ui-muted) !important;
}

.toolbar,
.actions-bar,
.filters,
.fields,
.actions,
.add-actions,
.row-actions {
    display: flex !important;
    flex-wrap: wrap !important;
    gap: 8px !important;
    align-items: center;
}

.filters .field,
.field {
    display: grid;
    gap: 4px;
}

.field label {
    font-size: 12px;
    font-weight: 700;
    color: #52606d;
}

.checklist {
    display: grid;
    gap: 6px;
    max-height: 220px;
    overflow: auto;
    padding: 10px;
    border: 1px solid var(--ui-border);
    border-radius: 8px;
    background: #fff;
}

.check-item {
    display: flex;
    gap: 8px;
    align-items: flex-start;
    font-size: 13px;
}

.switch-inline {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    color: #3f4d59;
}

.code,
.mono,
.token-value,
.secret {
    font-family: Consolas, "Courier New", monospace !important;
    font-size: 12px !important;
}

.table-wrap table {
    min-width: 980px;
}

.products-sync-bar {
    display: flex !important;
    flex-wrap: wrap;
    gap: 10px !important;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 12px;
}

.products-market-buttons {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.products-table {
    table-layout: fixed;
}

.products-table th,
.products-table td {
    padding: 7px 6px !important;
}

.products-table input.inline {
    width: 100%;
    min-width: 0;
    padding: 7px 8px !important;
}

.products-table .name-input {
    font-weight: 600;
}

.products-table .switch-inline {
    justify-content: center;
    width: 100%;
}

.products-table .market-cell,
.products-table .status-col {
    text-align: center;
}

.products-table .split {
    gap: 4px;
}

.readonly-stock {
    display: block;
    width: 100%;
    border: 1px solid #d7e0e8;
    border-radius: 8px;
    padding: 8px 6px;
    background: #f8fafc;
    text-align: center;
    font-weight: 600;
}

.row-status {
    width: 100%;
    justify-content: center;
    white-space: nowrap;
}

.photo,
.photo-empty {
    width: 56px;
    height: 56px;
    border-radius: 6px;
    object-fit: cover;
    display: grid;
    place-items: center;
    background: #e8edf2;
}

.split {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 6px;
}

.split-label {
    display: block;
    font-size: 10px;
    color: var(--ui-muted);
    margin-bottom: 2px;
    text-transform: uppercase;
}

.status.is-visible {
    display: block !important;
}

.session-list,
.drafts,
.tokens,
.resource-list {
    display: grid;
    gap: 8px;
}

.session-link {
    display: block;
    padding: 10px;
    border: 1px solid var(--ui-border);
    border-radius: 8px;
    color: var(--ui-ink);
    text-decoration: none;
}

.session-link.active {
    border-color: var(--ui-primary);
    background: #edf4fb;
}

.chat-box {
    display: grid;
    gap: 10px;
    max-height: 62vh;
    overflow: auto;
}

.bubble {
    max-width: 92%;
    border: 1px solid var(--ui-border);
    border-radius: 10px;
    padding: 10px 12px;
    white-space: pre-wrap;
    background: #fff;
}

.bubble.user {
    margin-left: auto;
    background: #edf4fb;
}

.bubble.assistant {
    background: #fff8ee;
}

.composer {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 8px;
    margin-top: 10px;
}

.composer textarea {
    min-height: 96px;
}

.pill,
.link,
.metric-link {
    color: #1a3d5c;
    text-decoration: none;
}

@media (max-width: 980px) {
    .app-nav-toggle {
        display: inline-flex;
        align-items: center;
        justify-content: center;
    }

    .app-main-nav {
        width: 100%;
        display: none;
        margin-top: 8px;
    }

    .app-main-nav.is-open {
        display: flex;
    }

    .app-main-nav a {
        flex: 1 1 calc(50% - 8px);
    }

    .page {
        width: min(100% - 12px, 1240px) !important;
        padding: 10px 0 20px !important;
    }

    h1 {
        font-size: 24px !important;
        line-height: 1.15 !important;
    }

    .lead {
        font-size: 15px !important;
        line-height: 1.5 !important;
    }

    .toolbar,
    .actions-bar,
    .filters,
    .fields,
    .actions,
    .add-actions,
    .row-actions,
    .products-sync-bar,
    .composer {
        display: grid !important;
        grid-template-columns: 1fr !important;
        gap: 8px !important;
        align-items: stretch !important;
    }

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

    .search,
    input[type="search"] {
        width: 100% !important;
    }
}

@media (max-width: 760px) {
    table.table-mobile-cards {
        min-width: 0 !important;
        width: 100% !important;
    }

    table.table-mobile-cards thead {
        display: none;
    }

    table.table-mobile-cards tbody,
    table.table-mobile-cards tr,
    table.table-mobile-cards td {
        display: block;
        width: 100%;
    }

    table.table-mobile-cards tr {
        padding: 10px;
        margin-bottom: 10px;
        border: 1px solid var(--ui-border);
        border-radius: 10px;
        background: #fff;
    }

    table.table-mobile-cards td {
        border: 0 !important;
        padding: 6px 0 !important;
    }

    table.table-mobile-cards td::before {
        content: attr(data-label);
        display: block;
        margin-bottom: 4px;
        color: #6a7883;
        font-size: 11px;
        text-transform: uppercase;
        font-weight: 700;
    }

    table.table-mobile-cards .photo,
    table.table-mobile-cards .photo-empty {
        width: 72px !important;
        height: 72px !important;
    }

    table.table-mobile-cards .name-input,
    table.table-mobile-cards .sku-input,
    table.table-mobile-cards .meta-input,
    table.table-mobile-cards .cost-input,
    table.table-mobile-cards .stock-input {
        width: 100% !important;
        min-width: 0 !important;
    }

    table.table-mobile-cards .split {
        grid-template-columns: 1fr !important;
        gap: 8px !important;
    }

    table.table-mobile-cards .row-actions {
        display: grid !important;
        grid-template-columns: 1fr 1fr !important;
        gap: 8px;
    }

    .products-market-buttons {
        display: grid;
        grid-template-columns: 1fr;
        gap: 8px;
    }

    .products-table input.inline,
    .readonly-stock {
        font-size: 16px;
    }

    .table-wrap table {
        min-width: 760px !important;
    }
}
