:root {
    --font-main: 'Sarabun', system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    --bg: #f4f4f5;
    --surface: #ffffff;
    --surface-soft: #fafafa;
    --black: #111111;
    --text: #1f1f1f;
    --muted: #77706a;
    --line: #ececec;
    --red: #ea1d2c;
    --red-dark: #b5121e;
    --success: #16803c;
    --warning: #a96800;
    --info: #275f9f;
    --purple: #6d44c5;
    --danger: #bb2332;
    --radius: 22px;
    --shadow: 0 18px 40px rgba(17, 17, 17, .06);
}

* { box-sizing: border-box; }

html,
body {
    width: 100%;
    max-width: 100%;
    overflow-x: hidden;
}

body {
    margin: 0;
    font-family: var(--font-main);
    color: var(--text);
    background: var(--bg);
}

a {
    color: inherit;
    text-decoration: none;
}

button,
input,
select {
    font-family: inherit;
}

input,
select {
    font-size: 14px;
}

.admin-shell {
    min-height: 100vh;
    display: flex;
    width: 100%;
    max-width: 100vw;
    overflow-x: hidden;
}

.sidebar {
    width: 268px;
    min-width: 268px;
    min-height: 100vh;
    background: var(--black);
    color: #fff;
    padding: 22px 16px;
    display: flex;
    flex-direction: column;
    position: sticky;
    top: 0;
    z-index: 20;
}

.brand-box {
    display: flex;
    flex-direction: column;
    gap: 12px;
    padding: 8px 10px 22px;
    border-bottom: 1px solid rgba(255, 255, 255, .10);
}

.brand-logo-wrap {
    height: 42px;
    display: flex;
    align-items: center;
}

.brand-logo-wide {
    display: block;
    width: 128px;
    max-width: 128px;
    height: auto;
}

.brand-mark {
    width: 50px;
    height: 50px;
    border-radius: 16px;
    display: grid;
    place-items: center;
    background: linear-gradient(135deg, var(--red), var(--black));
    font-weight: 800;
    font-size: 22px;
}

.brand-copy strong,
.admin-profile strong {
    display: block;
    font-size: 15px;
}

.brand-copy span,
.admin-profile span {
    display: block;
    font-size: 12px;
    color: rgba(255, 255, 255, .64);
    margin-top: 3px;
}

.sidebar-nav {
    display: grid;
    gap: 8px;
    margin-top: 24px;
}

.nav-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 13px 14px;
    border-radius: 16px;
    color: rgba(255, 255, 255, .78);
    transition: .2s ease;
    font-weight: 600;
}

.nav-item-left {
    display: flex;
    align-items: center;
    gap: 12px;
    min-width: 0;
}

.nav-item svg {
    width: 20px;
    height: 20px;
    flex: 0 0 auto;
}

.nav-item-left span {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.nav-item:hover,
.nav-item.active {
    background: #fff;
    color: var(--black);
}

.menu-badge,
.floating-badge,
.chat-unread-pill {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 22px;
    height: 22px;
    padding: 0 7px;
    border-radius: 999px;
    background: #ff2d3f;
    color: #fff;
    font-size: 12px;
    font-weight: 800;
    line-height: 1;
    flex: 0 0 auto;
}

.sidebar-footer {
    margin-top: auto;
    padding: 18px 8px 0;
    color: rgba(255, 255, 255, .45);
}

.main-content {
    flex: 1;
    min-width: 0;
    width: 100%;
    max-width: calc(100vw - 268px);
    overflow-x: hidden;
}

.topbar {
    min-height: 92px;
    background: var(--surface);
    border-bottom: 1px solid var(--line);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 18px;
    padding: 18px 28px;
    position: sticky;
    top: 0;
    z-index: 10;
}

.menu-toggle {
    display: none;
    border: 0;
    background: var(--surface-soft);
    border-radius: 14px;
    width: 44px;
    height: 44px;
    cursor: pointer;
}

.page-heading {
    min-width: 0;
}

.page-heading span,
.eyebrow {
    color: var(--red);
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: .08em;
    font-weight: 800;
    margin: 0 0 6px;
}

.page-heading h1,
.dashboard-header h2,
.page-card-header h2,
.chat-list-top h2 {
    margin: 0;
    font-size: 28px;
    letter-spacing: -.03em;
}

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

.search-box,
.chat-search-box {
    height: 46px;
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 0 14px;
    border: 1px solid var(--line);
    border-radius: 16px;
    background: var(--surface-soft);
}

.search-box {
    width: min(320px, 30vw);
}

.search-box input,
.chat-search-box input {
    width: 100%;
    border: 0;
    outline: 0;
    background: transparent;
    color: var(--text);
}

.search-box svg,
.icon-button svg,
.primary-button svg,
.ghost-button svg,
.chat-search-box svg {
    width: 19px;
    height: 19px;
}

.icon-button {
    width: 46px;
    height: 46px;
    border: 1px solid var(--line);
    background: var(--surface);
    border-radius: 16px;
    cursor: pointer;
    position: relative;
    flex: 0 0 auto;
}

.floating-badge {
    position: absolute;
    top: -5px;
    right: -5px;
    min-width: 20px;
    height: 20px;
    font-size: 11px;
}

.admin-profile {
    display: flex;
    align-items: center;
    gap: 10px;
    padding-left: 4px;
}

.admin-profile span {
    color: var(--muted);
}

.avatar {
    width: 42px;
    height: 42px;
    border-radius: 50%;
    background: var(--black);
    color: #fff;
    display: grid;
    place-items: center;
    font-weight: 700;
}

.content-area {
    padding: 28px;
    width: 100%;
    max-width: 100%;
    min-width: 0;
    overflow-x: hidden;
}

.dashboard-header,
.page-card-header,
.panel-title {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 18px;
    margin-bottom: 22px;
}

.dashboard-header span,
.page-card-header span {
    display: block;
    color: var(--muted);
    margin-top: 8px;
}

.primary-button,
.ghost-button {
    border: 0;
    border-radius: 15px;
    min-height: 46px;
    padding: 0 18px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 9px;
    cursor: pointer;
    font-weight: 800;
    flex-shrink: 0;
}

.primary-button {
    background: var(--black);
    color: #fff;
}

.ghost-button {
    background: var(--surface-soft);
    color: var(--red);
    border: 1px solid var(--line);
}

.stats-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 18px;
    width: 100%;
}

.stat-card,
.panel,
.page-card,
.mini-stat-card,
.summary-grid article {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    min-width: 0;
}

.stat-card {
    padding: 20px;
    display: flex;
    align-items: center;
    gap: 16px;
    overflow: hidden;
}

.stat-icon {
    width: 52px;
    height: 52px;
    border-radius: 18px;
    display: grid;
    place-items: center;
    background: var(--surface-soft);
    color: var(--red);
    flex: 0 0 auto;
}

.stat-icon svg {
    width: 24px;
    height: 24px;
}

.stat-card span,
.stat-card small {
    display: block;
    color: var(--muted);
    font-size: 13px;
}

.stat-card strong {
    display: block;
    font-size: clamp(24px, 2vw, 34px);
    margin: 5px 0;
    letter-spacing: -.03em;
    white-space: nowrap;
}

.summary-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 18px;
    margin-top: 18px;
    width: 100%;
}

.summary-grid article {
    padding: 18px;
    box-shadow: none;
}

.summary-grid span,
.summary-grid small {
    display: block;
    color: var(--muted);
    font-size: 13px;
}

.summary-grid strong {
    display: block;
    margin: 6px 0 4px;
    font-size: 24px;
}

.summary-grid a {
    color: var(--red);
    font-weight: 800;
}

.panel,
.page-card {
    padding: 22px;
    overflow: hidden;
}

.full-panel {
    margin-top: 18px;
    width: 100%;
}

.panel-title h3 {
    margin: 0;
    font-size: 20px;
}

.table-wrap {
    width: 100%;
    max-width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.table-wrap-card {
    border: 1px solid var(--line);
    border-radius: 18px;
}

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

th,
td {
    text-align: left;
    padding: 14px 10px;
    border-bottom: 1px solid var(--line);
    vertical-align: middle;
}

th {
    color: var(--muted);
    font-size: 13px;
    font-weight: 800;
}

.badge {
    display: inline-flex;
    align-items: center;
    padding: 8px 12px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 800;
    white-space: nowrap;
}

.badge.warning { color: var(--warning); background: #fff5de; }
.badge.success { color: var(--success); background: #e8f8ed; }
.badge.info { color: var(--info); background: #e8f1fb; }
.badge.purple { color: var(--purple); background: #f1ebff; }
.badge.danger { color: var(--danger); background: #feecef; }

.muted-block {
    display: block;
    color: var(--muted);
    font-size: 13px;
    margin-top: 4px;
}

.settings-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 16px;
}

.settings-grid label {
    display: grid;
    gap: 8px;
    font-weight: 800;
    color: var(--red-dark);
}

.settings-grid input,
.filter-group input,
.filter-group select,
.chat-compose input {
    height: 48px;
    border: 1px solid var(--line);
    border-radius: 15px;
    padding: 0 14px;
    outline: 0;
    background: var(--surface-soft);
    color: var(--text);
    width: 100%;
}

.filters-card {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 18px;
    margin-bottom: 18px;
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr)) auto;
    gap: 14px;
    align-items: end;
    width: 100%;
}

.filter-group {
    display: grid;
    gap: 8px;
    min-width: 0;
}

.filter-group label {
    color: var(--red-dark);
    font-size: 13px;
    font-weight: 800;
}

.order-summary-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 16px;
    margin-bottom: 18px;
}

.mini-stat-card {
    padding: 18px 20px;
}

.mini-stat-card span,
.mini-stat-card small {
    display: block;
    color: var(--muted);
}

.mini-stat-card strong {
    display: block;
    margin: 7px 0 4px;
    font-size: 30px;
}

.mini-stat-card.warning { border-color: #f3deb0; }
.mini-stat-card.danger { border-color: #f4c8cf; }

.empty-state {
    min-height: 330px;
    display: grid;
    place-items: center;
    text-align: center;
    color: var(--muted);
    padding: 35px;
    background: var(--surface-soft);
    border: 1px dashed #f0b3b8;
    border-radius: 20px;
}

.empty-state svg {
    width: 62px;
    height: 62px;
    color: var(--red);
}

.empty-state h3 {
    margin: 12px 0 0;
    color: var(--text);
}

.empty-state p {
    max-width: 470px;
    line-height: 1.55;
}

.quick-actions {
    display: grid;
    gap: 10px;
}

.quick-actions a {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 14px;
    border-radius: 16px;
    background: var(--surface-soft);
    border: 1px solid var(--line);
    font-weight: 700;
}

.quick-actions svg {
    width: 20px;
    height: 20px;
    color: var(--red);
}

/* CHAT */
.chat-screen {
    width: 100%;
    max-width: 100%;
    overflow: hidden;
}

.chat-layout {
    display: grid;
    grid-template-columns: 360px minmax(0, 1fr);
    gap: 18px;
    height: calc(100vh - 148px);
    min-height: 610px;
    width: 100%;
    max-width: 100%;
}

.chat-list,
.chat-window {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 24px;
    box-shadow: var(--shadow);
    overflow: hidden;
    min-width: 0;
}

.chat-list {
    padding: 18px;
    display: flex;
    flex-direction: column;
}

.chat-list-top {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 12px;
    margin-bottom: 14px;
}

.chat-counter {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 8px 12px;
    border-radius: 999px;
    background: #fff1f2;
    color: var(--red);
    font-size: 12px;
    font-weight: 800;
    white-space: nowrap;
}

.chat-search-box {
    margin-bottom: 14px;
    width: 100%;
    flex: 0 0 auto;
}

.chat-conversation-list {
    display: grid;
    gap: 10px;
    overflow-y: auto;
    padding-right: 3px;
}

.conversation-item {
    display: flex;
    gap: 12px;
    padding: 14px;
    border-radius: 18px;
    background: var(--surface-soft);
    border: 1px solid transparent;
    transition: .2s ease;
    min-width: 0;
}

.conversation-item:hover,
.conversation-item.active {
    border-color: #ffd7db;
    background: #fff8f8;
}

.conversation-avatar {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    background: #1b1b1b;
    color: #fff;
    display: grid;
    place-items: center;
    font-weight: 800;
    flex: 0 0 auto;
}

.conversation-avatar.large {
    width: 54px;
    height: 54px;
}

.conversation-body {
    min-width: 0;
    flex: 1;
}

.conversation-head,
.conversation-meta {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
}

.conversation-head strong {
    font-size: 15px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.conversation-head span,
.conversation-body small,
.conversation-meta span:first-child {
    color: var(--muted);
    font-size: 13px;
}

.conversation-meta {
    margin-top: 4px;
}

.conversation-meta span:first-child {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    flex: 1;
}

.conversation-body small {
    display: block;
    margin-top: 6px;
}

.chat-window {
    display: flex;
    flex-direction: column;
    background: #fff;
}

.chat-window-header {
    padding: 18px 20px;
    border-bottom: 1px solid var(--line);
    display: flex;
    justify-content: space-between;
    gap: 16px;
    align-items: center;
    flex: 0 0 auto;
}

.chat-thread-user {
    display: flex;
    align-items: center;
    gap: 12px;
    min-width: 0;
}

.chat-thread-user strong {
    display: block;
}

.chat-thread-user span {
    display: block;
    color: var(--muted);
    margin-top: 4px;
    font-size: 13px;
}

.chat-thread-status {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    color: var(--muted);
    font-size: 13px;
    font-weight: 700;
    white-space: nowrap;
}

.status-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    display: inline-block;
}

.status-dot.online { background: #14a44d; }
.status-dot.offline { background: #bcc2cc; }

.chat-order-card {
    margin: 16px 20px 0;
    padding: 14px 16px;
    border-radius: 18px;
    background: var(--surface-soft);
    border: 1px solid var(--line);
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    flex: 0 0 auto;
}

.chat-order-card small {
    display: block;
    color: var(--muted);
    margin-bottom: 3px;
}

.chat-order-card a {
    color: var(--red);
    font-weight: 800;
}

.chat-messages {
    flex: 1;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 14px;
    overflow-y: auto;
    background: radial-gradient(circle at top left, rgba(234, 29, 44, .04), transparent 34%), #fff;
}

.message-row {
    display: flex;
    width: 100%;
}

.message-row.from-admin { justify-content: flex-end; }
.message-row.from-customer { justify-content: flex-start; }

.message-bubble {
    max-width: min(560px, 82%);
    padding: 14px 16px;
    border-radius: 18px;
    box-shadow: 0 10px 24px rgba(17, 17, 17, .04);
}

.message-row.from-customer .message-bubble {
    background: var(--surface-soft);
    border-bottom-left-radius: 6px;
}

.message-row.from-admin .message-bubble {
    background: #fff1f2;
    border-bottom-right-radius: 6px;
}

.message-bubble p {
    margin: 0;
    line-height: 1.5;
}

.message-bubble span {
    display: block;
    margin-top: 8px;
    font-size: 12px;
    color: var(--muted);
}

.chat-compose {
    padding: 16px 20px;
    border-top: 1px solid var(--line);
    display: flex;
    align-items: center;
    gap: 12px;
    flex: 0 0 auto;
}

.chat-compose input {
    flex: 1;
}

@media (max-width: 1180px) {
    .stats-grid,
    .summary-grid,
    .order-summary-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

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

    .search-box {
        width: 240px;
    }
}

@media (max-width: 980px) {
    .sidebar {
        position: fixed;
        left: -290px;
        z-index: 30;
        transition: .25s ease;
    }

    .sidebar.open {
        left: 0;
    }

    .main-content {
        max-width: 100vw;
    }

    .menu-toggle {
        display: grid;
        place-items: center;
    }

    .topbar {
        align-items: flex-start;
        flex-wrap: wrap;
        padding: 16px;
    }

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

    .search-box {
        width: auto;
        min-width: 0;
        flex: 1;
    }

    .admin-profile div:not(.avatar) {
        display: none;
    }

    .content-area {
        padding: 16px;
    }

    .stats-grid,
    .summary-grid,
    .order-summary-grid,
    .filters-card,
    .settings-grid {
        grid-template-columns: 1fr;
    }

    .dashboard-header,
    .page-card-header,
    .panel-title {
        flex-direction: column;
        align-items: flex-start;
    }

    .primary-button,
    .ghost-button {
        width: 100%;
    }

    .chat-layout {
        grid-template-columns: 1fr;
        height: auto;
        min-height: 0;
    }

    .chat-list {
        max-height: 360px;
    }

    .chat-window {
        min-height: 620px;
    }
}

@media (max-width: 640px) {
    .content-area {
        padding: 12px;
    }

    .topbar-actions {
        gap: 8px;
    }

    .chat-window-header,
    .chat-order-card,
    .chat-compose {
        flex-direction: column;
        align-items: stretch;
    }

    .chat-compose .primary-button {
        width: 100%;
    }

    .message-bubble {
        max-width: 92%;
    }

    table {
        min-width: 720px;
    }
}


/* Correção final: centralizar topo da sidebar */
.sidebar .brand-box {
    align-items: center !important;
    justify-content: center !important;
    text-align: center !important;
    padding-left: 0 !important;
    padding-right: 0 !important;
}

.sidebar .brand-logo-wrap {
    width: 100% !important;
    height: auto !important;
    min-height: 62px !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    text-align: center !important;
}

.sidebar .brand-logo-wide {
    display: block !important;
    width: 150px !important;
    max-width: 150px !important;
    height: auto !important;
    margin-left: auto !important;
    margin-right: auto !important;
}

.sidebar .brand-copy {
    width: 100% !important;
    text-align: center !important;
    display: block !important;
}

.sidebar .brand-copy strong {
    display: none !important;
}

.sidebar .brand-copy span {
    width: 100% !important;
    display: block !important;
    text-align: center !important;
    color: rgba(255,255,255,.82) !important;
    font-size: 14px !important;
    font-weight: 500 !important;
    margin-top: 0 !important;
}
