:root {
  --brand: #34c77b;
  --brand-dark: #1f9e5c;
  --brand-darker: #178049;
  --bg-soft: #f0faf4;
  --bg-soft-2: #e3f5ea;
  --ink: #243b30;
  --muted: #6b8579;
  --card-radius: 16px;
  --shadow-sm: 0 2px 8px rgba(31, 158, 92, 0.08);
  --shadow-md: 0 8px 24px rgba(31, 158, 92, 0.12);
}

html {
  font-size: 14px;
  position: relative;
  min-height: 100%;
}

@media (min-width: 768px) {
  html { font-size: 15px; }
}

body {
  margin-bottom: 0;
  min-height: 100vh;
  color: var(--ink);
  background: linear-gradient(160deg, var(--bg-soft) 0%, var(--bg-soft-2) 100%);
  background-attachment: fixed;
  font-family: 'Segoe UI', system-ui, -apple-system, 'Helvetica Neue', Arial, sans-serif;
}

/* ===== Navbar ===== */
.app-navbar {
  background: #ffffff;
  box-shadow: var(--shadow-sm);
  padding: .55rem 0;
}
.app-navbar .navbar-brand {
  font-weight: 700;
  color: var(--brand-dark) !important;
  letter-spacing: .3px;
}
.app-navbar .nav-link {
  color: var(--ink) !important;
  font-weight: 500;
  border-radius: 8px;
  padding: .4rem .9rem !important;
}
.app-navbar .nav-link:hover { background: var(--bg-soft-2); }
.app-navbar .user-chip {
  display: inline-flex;
  align-items: center;
  gap: .4rem;
  background: var(--bg-soft-2);
  color: var(--brand-darker);
  padding: .35rem .8rem;
  border-radius: 999px;
  font-weight: 600;
  font-size: .85rem;
  white-space: nowrap;      /* không cắt/xuống dòng tên cửa hàng */
  flex: 0 0 auto;
}
.app-navbar .store-chip { background: var(--brand-dark); color: #fff; }

/* ===== Headings ===== */
.page-title {
  color: var(--brand-darker);
  font-weight: 700;
  margin: .25rem 0 1.25rem;
}
.page-title small { color: var(--muted); font-weight: 500; font-size: .9rem; }

/* ===== Cards ===== */
.card {
  border: none;
  border-radius: var(--card-radius);
  box-shadow: var(--shadow-sm);
  background: #ffffff;
}
.table-wrapper { background: #fff; border-radius: var(--card-radius); box-shadow: var(--shadow-sm); }
/* Bảng đơn: cho cuộn ngang nếu chật, nút thao tác không bị cắt */
.table-wrapper .table-responsive { overflow-x: auto; }
.table-wrapper .table > :not(caption) > * > * { padding-left: .5rem; padding-right: .5rem; } /* thu gọn padding ô */
/* Cột Người nhận / Liên hệ: giới hạn rộng + cho xuống dòng giá trị dài */
.col-recv { max-width: 160px; }
.col-contact { max-width: 220px; }
.col-recv, .col-contact, .col-contact div {
  white-space: normal;
  word-break: break-word;
  overflow-wrap: anywhere;
}
.table-wrapper .table td:last-child,
.table-wrapper .table th:last-child { position: sticky; right: 0; background: #fff; box-shadow: -6px 0 8px -6px rgba(0,0,0,.12); }
.table-wrapper .table-hover > tbody > tr:hover td:last-child { background: var(--bg-soft); }
.table-wrapper .btn-sm { padding: .2rem .4rem; font-size: .8rem; }

/* ===== Stat cards ===== */
.stat-card {
  border-radius: var(--card-radius);
  padding: 1rem 1.15rem;
  background: #fff;
  box-shadow: var(--shadow-sm);
  display: flex;
  align-items: center;
  gap: .85rem;
  transition: transform .15s ease, box-shadow .15s ease;
  border-left: 4px solid var(--brand);
}
.stat-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-md); }
.stat-card .stat-icon {
  width: 44px; height: 44px;
  border-radius: 12px;
  display: flex; align-items: center; justify-content: center;
  font-size: 1.3rem;
  background: var(--bg-soft-2);
  color: var(--brand-dark);
  flex: 0 0 auto;
}
.stat-card .stat-label { color: var(--muted); font-size: .8rem; font-weight: 600; text-transform: uppercase; letter-spacing: .3px; }
.stat-card .stat-value { font-size: 1.6rem; font-weight: 700; line-height: 1.1; color: var(--ink); }

.stat-total  { border-left-color: #1f9e5c; }
.stat-total  .stat-icon { background: #e3f5ea; color: #1f9e5c; }
.stat-new    { border-left-color: #3b82f6; }
.stat-new    .stat-icon { background: #e8f0fe; color: #3b82f6; }
.stat-deliver{ border-left-color: #f59e0b; }
.stat-deliver .stat-icon { background: #fef3e2; color: #f59e0b; }
.stat-done   { border-left-color: #10b981; }
.stat-done   .stat-icon { background: #e6f7f1; color: #10b981; }
.stat-cancel { border-left-color: #ef4444; }
.stat-cancel .stat-icon { background: #fdeaea; color: #ef4444; }

/* ===== Tables ===== */
.table { margin-bottom: 0; font-size: 1.02rem; }
.table > thead th {
  background: var(--bg-soft-2);
  color: var(--brand-darker);
  border-bottom: none;
  font-weight: 600;
  font-size: .9rem;
  text-transform: uppercase;
  letter-spacing: .3px;
  padding: 1rem 1.1rem;
  white-space: nowrap;
}
.table > tbody td { padding: 1rem 1.1rem; vertical-align: middle; border-color: #eef3f0; }
.table-hover > tbody > tr:hover { background: var(--bg-soft); }

/* Khung nội dung rộng hơn để bảng to ra */
.app-container { max-width: 1600px; }

/* ===== Badges & buttons ===== */
.status-badge { font-size: .78rem; padding: .4em .7em; border-radius: 999px; font-weight: 600; }
.btn-success { background: var(--brand-dark); border-color: var(--brand-dark); }
.btn-success:hover { background: var(--brand-darker); border-color: var(--brand-darker); }
.btn-outline-success { color: var(--brand-dark); border-color: var(--brand-dark); }
.btn-outline-success:hover { background: var(--brand-dark); border-color: var(--brand-dark); }
.btn { border-radius: 9px; font-weight: 500; }
.btn-sm { border-radius: 8px; }
.form-control, .form-select { border-radius: 10px; border-color: #d7e7de; }
.form-control:focus, .form-select:focus { border-color: var(--brand); box-shadow: 0 0 0 .2rem rgba(52, 199, 123, .18); }

/* ===== Login ===== */
.login-wrapper { max-width: 410px; margin: 8vh auto; }
.login-card { padding: 2.2rem; border-radius: 20px; box-shadow: var(--shadow-md); }
.login-logo {
  width: 64px; height: 64px; border-radius: 18px; margin: 0 auto 1rem;
  display: flex; align-items: center; justify-content: center; font-size: 2rem;
  background: linear-gradient(135deg, var(--brand) 0%, var(--brand-dark) 100%);
  color: #fff; box-shadow: var(--shadow-sm);
}

/* ===== Language switch ===== */
.lang-switch { display: inline-flex; border: 1px solid #cfe6d8; border-radius: 999px; overflow: hidden; }
.lang-switch a {
  padding: .25rem .7rem; font-size: .8rem; font-weight: 600;
  color: var(--brand-dark); text-decoration: none; background: #fff;
}
.lang-switch a + a { border-left: 1px solid #cfe6d8; }
.lang-switch a.active { background: var(--brand-dark); color: #fff; }
.lang-switch a:hover:not(.active) { background: var(--bg-soft-2); }

/* ===== Live indicator ===== */
.live-dot {
  display: inline-block;
  width: 9px; height: 9px;
  border-radius: 50%;
  background: #16a34a;
  margin-right: 4px;
  box-shadow: 0 0 0 0 rgba(22, 163, 74, .6);
  animation: live-pulse 1.6s infinite;
}
@keyframes live-pulse {
  0%   { box-shadow: 0 0 0 0 rgba(22, 163, 74, .6); }
  70%  { box-shadow: 0 0 0 8px rgba(22, 163, 74, 0); }
  100% { box-shadow: 0 0 0 0 rgba(22, 163, 74, 0); }
}
#new-order-banner { border-radius: 12px; }
.stat-value.bump { animation: stat-bump .5s ease; }
@keyframes stat-bump {
  0% { transform: scale(1); }
  40% { transform: scale(1.25); color: #16a34a; }
  100% { transform: scale(1); }
}

/* ===== Modal chi tiết: to gần full màn hình ===== */
.detail-modal-dialog {
  max-width: 95vw;
  margin-left: auto;
  margin-right: auto;
}
.barcode-text { font-family: 'Consolas', monospace; font-weight: 600; letter-spacing: .5px; }

/* ===== Bảng tóm tắt thanh toán (không dùng .table để tránh CSS chung) ===== */
.pay-summary .pay-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: .35rem 0;
}
.pay-summary .pay-row + .pay-row { border-top: 1px dashed #e0ebe4; }
.pay-summary .pay-total {
  border-top: 2px solid #cfe6d8;
  margin-top: .25rem;
  padding-top: .6rem;
}

/* ===== Select2 khớp chiều cao input Bootstrap ===== */
.select2-container--bootstrap-5 .select2-selection {
  border-radius: 10px;
  border-color: #d7e7de;
  min-height: calc(1.5em + .75rem + 2px);
}
.select2-container--bootstrap-5.select2-container--focus .select2-selection,
.select2-container--bootstrap-5.select2-container--open .select2-selection {
  border-color: var(--brand);
  box-shadow: 0 0 0 .2rem rgba(52, 199, 123, .18);
}

/* ===== Toast thông báo (to & nổi bật) ===== */
.app-toast {
  min-width: 360px;
  max-width: 520px;
  border-radius: 14px;
  box-shadow: 0 14px 40px rgba(0, 0, 0, 0.45);
  color: #fff;
  overflow: hidden;
  border: 3px solid #fff;            /* viền trắng tách khỏi nền cùng màu */
  outline: 1px solid rgba(0,0,0,.15);
}
.app-toast .app-toast-icon {
  flex: 0 0 auto;
  width: 46px;
  height: 46px;
  margin: .65rem .25rem .65rem .8rem;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.5rem;
  font-weight: 700;
  background: rgba(255, 255, 255, 0.25);
}
.app-toast .app-toast-body {
  flex: 1 1 auto;
  padding: .9rem .6rem;
  font-size: 1.15rem;
  font-weight: 700;
  line-height: 1.3;
}
.app-toast-success { background: linear-gradient(135deg, #1f9e5c 0%, #34c77b 100%); }
.app-toast-error   { background: linear-gradient(135deg, #d32f2f 0%, #ef5350 100%); }
.app-toast-info    { background: linear-gradient(135deg, #1565c0 0%, #42a5f5 100%); }

/* hiệu ứng trượt xuống khi hiện */
.app-toast.showing, .app-toast.show { animation: toast-drop .3s ease; }
@keyframes toast-drop {
  from { transform: translateY(-16px); opacity: 0; }
  to   { transform: translateY(0); opacity: 1; }
}

/* Toast bấm được (thông báo chat) */
.app-toast-clickable { text-decoration: underline; text-underline-offset: 2px; }
.app-toast-clickable:hover { opacity: .9; }

/* ===== Chat ===== */
.chat-wrapper { padding: 0; overflow: hidden; }
.chat-wrapper .row { min-height: 70vh; }

/* Chat trong modal — chiều cao theo viewport */
.chat-wrapper-modal .row { height: 72vh; }
#chat-modal .modal-body { overflow: hidden; }
.chat-wrapper-modal .chat-room-list { max-height: calc(72vh - 52px); }
.chat-wrapper-modal .chat-empty { min-height: 72vh; }
.chat-wrapper-modal .chat-active { height: 72vh; }

.chat-rooms { border-right: 1px solid #eef3f0; display: flex; flex-direction: column; }
.chat-rooms-header { padding: .6rem; border-bottom: 1px solid #eef3f0; }
.chat-room-list { overflow-y: auto; max-height: 70vh; }
.chat-room-item {
  padding: .7rem .9rem; border-bottom: 1px solid #f2f7f4; cursor: pointer;
  display: flex; gap: .6rem; align-items: flex-start;
}
.chat-room-item:hover { background: var(--bg-soft); }
.chat-room-item.active { background: var(--bg-soft-2); }
.chat-room-item .avatar {
  width: 40px; height: 40px; border-radius: 50%; flex: 0 0 auto;
  display: flex; align-items: center; justify-content: center;
  background: var(--brand); color: #fff; font-weight: 700;
}
.chat-room-item .room-name { font-weight: 600; color: var(--ink); }
.chat-room-item .room-order { font-weight: 500; font-size: .78rem; color: var(--brand-dark); }
.chat-room-item .room-last { color: var(--muted); font-size: .82rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 180px; }
.chat-room-item.unread .room-name::after { content: "●"; color: #ef4444; font-size: .6rem; margin-left: .35rem; vertical-align: middle; }

.chat-conversation { display: flex; flex-direction: column; position: relative; }
.chat-empty { flex: 1; display: flex; align-items: center; justify-content: center; min-height: 70vh; }
.chat-active { display: flex; flex-direction: column; height: 70vh; }
.chat-header { padding: .8rem 1rem; border-bottom: 1px solid #eef3f0; background: #fff; }
.chat-messages { flex: 1; overflow-y: auto; padding: 1rem; background: var(--bg-soft); display: flex; flex-direction: column; gap: .5rem; }

.msg { position: relative; max-width: 70%; padding: .55rem .8rem; border-radius: 14px; font-size: .95rem; line-height: 1.35; word-break: break-word; white-space: pre-wrap; }
/* Nút thu hồi tin nhắn (chỉ tin cửa hàng) — pill đỏ nằm bên TRÁI bong bóng, luôn hiện mờ, rõ khi hover */
.msg .msg-del {
    position: absolute; top: 50%; right: calc(100% + 8px); transform: translateY(-50%);
    white-space: nowrap; border: 1px solid #f0c2c2; background: #fff; color: #d33;
    padding: .15rem .5rem; border-radius: 999px; line-height: 1; font-size: .72rem; cursor: pointer;
    box-shadow: 0 1px 3px rgba(0,0,0,.12); opacity: .55; transition: opacity .15s, background .15s;
}
.msg.from-store:hover .msg-del { opacity: 1; }
.msg .msg-del:hover { background: #ffecec; color: #b00020; }
.msg .msg-time { display: block; font-size: .7rem; opacity: .7; margin-top: .2rem; }
.msg.from-store { align-self: flex-end; background: var(--brand-dark); color: #fff; border-bottom-right-radius: 4px; }
.msg.from-user { align-self: flex-start; background: #fff; color: var(--ink); border: 1px solid #e6efe9; border-bottom-left-radius: 4px; }
/* Tin nhắn ảnh (type=2): hiển thị ảnh, bấm để xem lớn */
.msg .msg-img { display: block; max-width: 220px; max-height: 220px; width: auto; height: auto; border-radius: 10px; cursor: pointer; object-fit: cover; }
/* Header GHIM thông tin đơn hàng — luôn hiển thị ở đầu khung chat */
.chat-order-pinned { flex: 0 0 auto; max-height: 42vh; overflow-y: auto; background: #fff; border-bottom: 1px solid #e6efe9; padding: .35rem .5rem; }
.chat-order-pinned .order-card { margin: 0; }

/* Thẻ thông tin đơn hàng — full-width, thu gọn/mở rộng */
.order-card { align-self: stretch; width: 100%; background: #f4faf6; border: 1px solid #d6e9dd; border-radius: 12px; overflow: hidden; margin: .2rem 0 .4rem; }
.order-card-head { display: flex; align-items: center; gap: .5rem; background: var(--brand-dark); color: #fff; font-weight: 600; padding: .4rem .7rem; font-size: .88rem; cursor: pointer; user-select: none; }
.order-card-head .oc-collapsed-text, .order-card-head .oc-expanded-text { flex: 1 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.order-card-head .oc-toggle { flex: 0 0 auto; opacity: .85; }
.order-card-head .oc-toggle::before { content: '\25BE'; } /* ▾ */
.order-card:not(.collapsed) .order-card-head .oc-toggle::before { content: '\25B4'; } /* ▴ */
.order-card.collapsed .oc-expanded-text { display: none; }
.order-card:not(.collapsed) .oc-collapsed-text { display: none; }
.order-card.collapsed .order-card-body { display: none; }
.order-card-body { padding: .55rem .75rem; font-size: .86rem; color: var(--ink); }
.order-card .oc-row { margin-bottom: .25rem; line-height: 1.4; }
.order-card .oc-label { font-weight: 600; }
.order-card .oc-row-products { display: block; }
.order-card .oc-products { margin: .15rem 0 0; padding-left: 1.1rem; }
.order-card .oc-products li { margin-bottom: .1rem; }

/* Tin nhắn vị trí (type=5): bản đồ nhúng + link mở bản đồ */
.msg .msg-map { width: 230px; }
.msg .msg-map-frame { width: 230px; height: 150px; border: 0; border-radius: 10px; display: block; }
.msg .msg-map-link { display: inline-block; margin-top: .25rem; font-size: .8rem; text-decoration: none; }
.msg.from-store .msg-map-link { color: #fff; }
/* Tin nhắn đã xóa (type=3): chữ nghiêng, mờ */
.msg .msg-deleted { font-style: italic; opacity: .7; }
/* Nút dịch tin nhắn — pill có nền, dễ nhìn */
.msg .msg-translate { display: inline-block; margin-top: .35rem; padding: .14rem .6rem; border-radius: 999px; border: 1px solid transparent; font-size: .74rem; font-weight: 600; line-height: 1.3; cursor: pointer; }
.msg.from-store .msg-translate { background: rgba(255,255,255,.22); color: #fff; border-color: rgba(255,255,255,.55); }
.msg.from-store .msg-translate:hover { background: rgba(255,255,255,.38); }
.msg.from-user .msg-translate { background: #eaf5ee; color: var(--brand-dark); border-color: #cfe6d8; }
.msg.from-user .msg-translate:hover { background: #d6ecde; }
.msg .msg-translated { margin-top: .35rem; padding-top: .3rem; border-top: 1px dashed rgba(255,255,255,.45); font-size: .92rem; }
.msg.from-user .msg-translated { border-top-color: #e0e6e2; }

.chat-input { display: flex; gap: .5rem; padding: .7rem; border-top: 1px solid #eef3f0; background: #fff; align-items: center; }
.chat-input .form-control { border-radius: 999px; }

/* ===== Footer ===== */
.footer { color: var(--muted); font-size: .85rem; }
