/**
 * CRM Theme — main.css
 * Layout: sidebar trái + nội dung phải, vừa 1 màn hình
 */

/* ── RESET & BASE ────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; }

:root {
  --gold:       #0b7e9b;
  --gold-light: #e6f4f8;
  --gold-dark:  #085f75;
  --bg:         #f2f6f8;
  --white:      #ffffff;
  --border:     #d0e4ea;
  --text:       #111827;
  --muted:      #6b7280;
  --danger:     #dc2626;
  --success:    #16a34a;
  --shadow:     0 1px 4px rgba(0,0,0,.08);
  --radius:     8px;
  --sidebar-w:  220px;
  --sidebar-bg: #0a1929;
}

html {
  height: 100%;
  overflow: hidden;
  background: var(--sidebar-bg);
}
body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--sidebar-bg);
  color: var(--text);
  font-family: 'Segoe UI', Arial, sans-serif;
  font-size: 14px;
}

/* ── ẨN NỘI DUNG NGOÀI CRM APP (theme header/footer từ wp_footer) ── */
body.crm-body > *:not(.crm-app):not(script):not(noscript):not(style):not(link) {
  display: none !important;
}

/* ── APP SHELL ───────────────────────────────────────────────── */
.crm-app {
  display: flex;
  height: 100vh;
  height: 100dvh; /* iOS Safari fix */
  width: 100vw;
  overflow: hidden;
}

/* ── SIDEBAR ─────────────────────────────────────────────────── */
.crm-sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: var(--sidebar-bg);
  border-right: 1px solid #0e2a3d;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  overflow-x: hidden;
}

.crm-sidebar-logo {
  padding: 18px 16px 14px;
  border-bottom: 1px solid #0e2a3d;
  flex-shrink: 0;
}
.crm-sidebar-logo a {
  text-decoration: none;
  display: flex;
  align-items: center;
  gap: 10px;
}
.crm-sidebar-brand {
  color: #fff;
  font-weight: 700;
  font-size: 15px;
  line-height: 1.2;
}
.crm-sidebar-brand small {
  display: block;
  color: #7ab8cc;
  font-size: 10px;
  font-weight: 400;
  margin-top: 1px;
}

.crm-sidebar-nav {
  flex: 1;
  padding: 10px 0;
  overflow-y: auto;
  overflow-x: hidden;
}

.crm-sidebar-section {
  padding: 8px 14px 4px;
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .6px;
  color: #3a7a96;
}

.crm-nav-link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 16px;
  color: #7ab8cc;
  text-decoration: none;
  font-size: 13px;
  font-weight: 500;
  transition: background .15s, color .15s;
  border-left: 3px solid transparent;
  white-space: nowrap;
}
.crm-nav-link:hover {
  background: rgba(11,126,155,.15);
  color: #fff;
}
.crm-nav-link.active {
  background: rgba(11,126,155,.25);
  color: #fff;
  border-left-color: var(--gold);
}
.crm-nav-icon { font-size: 16px; flex-shrink: 0; }

.crm-sidebar-footer {
  padding: 12px 16px 16px;
  border-top: 1px solid #0e2a3d;
  flex-shrink: 0;
}
.crm-sidebar-user-link {
  display: block;
  text-decoration: none;
  margin-bottom: 10px;
}
.crm-sidebar-user {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: 8px;
  background: rgba(255,255,255,.04);
  transition: background .18s;
}
.crm-sidebar-user-link:hover .crm-sidebar-user {
  background: rgba(11,126,155,.18);
}
.sidebar-avatar {
  width: 36px; height: 36px; border-radius: 50%; object-fit: cover;
  border: 2px solid var(--gold); flex-shrink: 0;
}
.sidebar-avatar-initials {
  width: 36px; height: 36px; border-radius: 50%;
  background: var(--gold); color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-size: 15px; font-weight: 700; flex-shrink: 0;
}
.sidebar-user-info { min-width: 0; }
.sidebar-user-name {
  font-size: 12px; font-weight: 600; color: #fff;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.sidebar-user-sub {
  font-size: 10px; color: #7ab8cc; margin-top: 2px;
}
.crm-sidebar-logout {
  display: block;
  font-size: 12px;
  color: #3a7a96;
  text-decoration: none;
  padding: 4px 2px;
}
.crm-sidebar-logout:hover { color: var(--danger); }

/* ── CONTENT AREA ────────────────────────────────────────────── */
.crm-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  overflow: hidden;
  background: var(--bg);
}

/* Topbar trong content */
.crm-topbar {
  background: var(--white);
  border-bottom: 1px solid var(--border);
  padding: 0 16px;
  height: 50px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
  box-shadow: 0 1px 3px rgba(0,0,0,.05);
  position: sticky;
  top: 0;
  z-index: 100;
}
.crm-topbar-title {
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
  margin: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.crm-topbar-actions { display: flex; gap: 8px; align-items: center; }

/* Scrollable page body */
.crm-main {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 20px 24px;
  -webkit-overflow-scrolling: touch;
}

/* ── LAYOUT UTILS ────────────────────────────────────────────── */
.crm-page-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 18px; gap: 10px;
}
.crm-page-header h1 { margin: 0; font-size: 20px; font-weight: 600; }
.crm-header-actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* ── ORDER TYPE BUTTONS ─────────────────────────────────────── */
.order-type-btn {
  display: flex; align-items: center; gap: 8px;
  padding: 10px 20px; border-radius: 8px; cursor: pointer;
  border: 2px solid var(--border); background: var(--white);
  font-size: 13px; font-weight: 500; color: var(--text-muted);
  transition: all .15s;
}
.order-type-btn:hover { border-color: var(--primary); color: var(--primary); }
.order-type-btn.active { border-color: var(--primary); background: #e8f5f2; color: var(--primary); font-weight: 700; }
.otb-icon { font-size: 18px; }
.badge-topup    { background: #ede9fe; color: #6d28d9; padding: 2px 8px; border-radius: 99px; font-size: 11px; font-weight: 700; }
.badge-service  { background: #e0f2fe; color: #0369a1; padding: 2px 8px; border-radius: 99px; font-size: 11px; font-weight: 700; }

/* ── CARDS ───────────────────────────────────────────────────── */
.crm-card {
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 20px;
  margin-bottom: 14px;
  box-shadow: var(--shadow);
}
.crm-card-title {
  margin: 0 0 12px; font-size: 14px; font-weight: 600;
  color: var(--gold-dark); border-bottom: 1px solid var(--border); padding-bottom: 9px;
}
.crm-card-title-row {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 0; padding-bottom: 10px; border-bottom: 1px solid var(--border);
}

/* ── GRID ────────────────────────────────────────────────────── */
.crm-grid-2col    { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.crm-grid-2col-sm { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.crm-form-row     { display: flex; gap: 10px; flex-wrap: wrap; align-items: flex-end; }
.crm-form-group   { display: flex; flex-direction: column; gap: 4px; flex: 1; min-width: 130px; }
.crm-form-group--btn { flex: 0 0 auto; }

/* ── FORM ELEMENTS ───────────────────────────────────────────── */
label { font-size: 11px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .4px; }

input[type="text"],
input[type="number"],
input[type="email"],
input[type="date"],
input[type="time"],
select,
textarea {
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 7px 10px;
  font-size: 13px;
  color: var(--text);
  background: var(--white);
  width: 100%;
  transition: border-color .2s;
  -webkit-appearance: none;
  appearance: none;
}
select { background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%236b7280' stroke-width='1.5' fill='none' stroke-linecap='round'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 10px center; padding-right: 28px; }
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--gold);
  box-shadow: 0 0 0 3px rgba(11,126,155,.15);
}
textarea { resize: vertical; min-height: 60px; }

/* ── BUTTONS ─────────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 7px 14px; border-radius: 6px; font-size: 13px; font-weight: 500;
  border: none; cursor: pointer; transition: all .2s; white-space: nowrap;
  -webkit-tap-highlight-color: transparent;
}
.btn-primary   { background: var(--gold); color: #fff; }
.btn-primary:hover   { background: var(--gold-dark); }
.btn-secondary { background: var(--bg); color: var(--text); border: 1px solid var(--border); }
.btn-secondary:hover { background: var(--border); }
.btn-danger    { background: var(--danger); color: #fff; }
.btn-danger:hover { background: #a93226; }
.btn-success   { background: var(--success); color: #fff; }
.btn-sm        { padding: 4px 10px; font-size: 12px; }
.btn:disabled  { opacity: .5; cursor: not-allowed; }

/* ── TABLES ──────────────────────────────────────────────────── */
.crm-table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  /* subtle scroll hint on mobile */
  background:
    linear-gradient(to right, white 30%, rgba(255,255,255,0)),
    linear-gradient(to right, rgba(255,255,255,0), white 70%) 0 100%,
    radial-gradient(farthest-side at 0% 50%, rgba(0,0,0,.08), transparent),
    radial-gradient(farthest-side at 100% 50%, rgba(0,0,0,.08), transparent) 0 100%;
  background-repeat: no-repeat;
  background-color: white;
  background-size: 40px 100%, 40px 100%, 8px 100%, 8px 100%;
  background-attachment: local, local, scroll, scroll;
}
.crm-table { width: 100%; border-collapse: collapse; }
.crm-table th {
  background: #e6f4f8; color: var(--gold-dark);
  padding: 9px 12px; font-size: 11px; font-weight: 600;
  text-align: left; border-bottom: 2px solid var(--gold);
  white-space: nowrap; position: sticky; top: 0; z-index: 1;
}
.crm-table td {
  padding: 9px 12px; font-size: 13px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
.crm-table tr:last-child td { border-bottom: none; }
.crm-table tr:hover td { background: #edf6f9; }
.text-right { text-align: right; }
.text-center { text-align: center; }
.text-muted { color: var(--muted); }

/* ── CUSTOMER SEARCH DROPDOWN ────────────────────────────────── */
.crm-search-wrap { position: relative; }
.crm-dropdown-results {
  position: absolute; z-index: 300; top: 100%; left: 0; right: 0;
  background: var(--white); border: 1px solid var(--border);
  border-radius: 6px; box-shadow: 0 4px 16px rgba(0,0,0,.12);
  max-height: 220px; overflow-y: auto;
}
th.text-right.crm-sortable {
    width: 150px;
    text-align: right;
}
.crm-result-item {
  padding: 8px 12px; font-size: 13px; cursor: pointer;
  border-bottom: 1px solid var(--border);
}
.crm-result-item:hover { background: var(--gold-light); color: var(--gold-dark); }
.crm-result-item:last-child { border-bottom: none; }

/* ── COMMISSION GRID ─────────────────────────────────────────── */
.crm-comm-grid { display: grid; grid-template-columns: repeat(4,1fr); gap: 12px; }
.crm-comm-item { display: flex; flex-direction: column; gap: 5px; }
.crm-comm-label { font-size: 11px; font-weight: 700; color: var(--gold-dark); text-transform: uppercase; }
.crm-comm-inputs { display: flex; gap: 5px; }
.crm-comm-inputs select { flex: 0 0 54px; }
.crm-comm-inputs input  { flex: 1; }
.crm-comm-preview { font-size: 12px; color: var(--success); font-weight: 600; }

/* ── SUMMARY ─────────────────────────────────────────────────── */
.crm-summary-card { background: linear-gradient(135deg, #edf6f9, #d0eaf2); }
.crm-summary-row {
  display: flex; justify-content: space-between; align-items: center;
  padding: 7px 0; font-size: 13px; border-bottom: 1px solid var(--border);
}
.crm-summary-row:last-child { border-bottom: none; }
.crm-summary-discount strong { color: var(--danger); }
.crm-summary-total {
  font-size: 17px; font-weight: 700; color: var(--gold-dark);
  padding-top: 10px; margin-top: 4px;
}

/* ── NOTICES ─────────────────────────────────────────────────── */
.crm-notice {
  padding: 9px 14px; border-radius: 6px; margin-bottom: 10px;
  font-size: 13px; font-weight: 500;
}
.notice-success { background: #e8f5e9; color: #1b5e20; border: 1px solid #a5d6a7; }
.notice-error   { background: #ffebee; color: #b71c1c; border: 1px solid #ef9a9a; }
.alert-warning  { background: #fff8e1; color: #e65100; border: 1px solid #ffe082;
                  padding: 7px 12px; border-radius: 6px; margin-bottom: 7px; font-size: 12px; }

/* ── BADGE ───────────────────────────────────────────────────── */
.badge {
  display: inline-block; padding: 2px 8px; border-radius: 10px;
  font-size: 11px; font-weight: 600; white-space: nowrap;
}
.badge-draft     { background: #fff8e1; color: #f57f17; }
.badge-confirmed { background: #e8f5e9; color: #2e7d32; }
.badge-completed { background: #e3f2fd; color: #1565c0; }
.badge-cancelled { background: #fce4ec; color: #880e4f; }
.badge-refunded  { background: #f3e5f5; color: #6a1b9a; }
.badge-pending     { background: #fff3e0; color: #e65100; }
.badge-in_progress { background: #e0f2f1; color: #00695c; }
.badge-on_journey  { background: #ede7f6; color: #4527a0; }
.badge-pay-unpaid  { background: #fce4ec; color: #880e4f; }
.badge-pay-partial { background: #fff8e1; color: #e65100; }
.badge-pay-paid    { background: #e8f5e9; color: #1b5e20; }
.badge-scheduled   { background: #e3f2fd; color: #1565c0; }
.badge-done        { background: #e8f5e9; color: #2e7d32; }
.badge-no_show     { background: #fce4ec; color: #880e4f; }

/* ── MODAL ───────────────────────────────────────────────────── */
.crm-modal { position:fixed; inset:0; z-index:1000; display:flex; align-items:center; justify-content:center; }
.crm-modal-backdrop { position:absolute; inset:0; background:rgba(0,0,0,.45); }
.crm-modal-box {
  position:relative; background:var(--white); border-radius:var(--radius);
  width:calc(100% - 24px); max-width:600px; max-height:90vh; overflow:hidden;
  display:flex; flex-direction:column;
  box-shadow:0 8px 32px rgba(0,0,0,.22);
}
.crm-modal-box--lg { max-width:780px; }
.crm-modal-header {
  display:flex; align-items:center; justify-content:space-between;
  padding:14px 20px; border-bottom:1px solid var(--border); flex-shrink:0;
}
.crm-modal-header h3 { margin:0; font-size:15px; }
.crm-modal-close { background:none; border:none; font-size:18px; cursor:pointer; color:var(--muted); padding:4px 8px; }
.crm-modal-close:hover { color:var(--danger); }
.crm-modal-body { padding:18px 20px; overflow-y:auto; flex:1; -webkit-overflow-scrolling:touch; }
.crm-modal-footer { display:flex; justify-content:flex-end; gap:8px; padding:12px 20px; border-top:1px solid var(--border); flex-shrink:0; }

/* ── STAT CARDS ──────────────────────────────────────────────── */
.crm-stat-grid { display:grid; grid-template-columns:repeat(4,1fr); gap:12px; margin-bottom:14px; }
.crm-stat-card {
  background:var(--white); border:1px solid var(--border); border-radius:var(--radius);
  padding:14px 16px; display:flex; align-items:center; gap:12px; box-shadow:var(--shadow);
}
.crm-stat-icon { width:40px; height:40px; border-radius:9px; display:flex; align-items:center; justify-content:center; font-size:18px; flex-shrink:0; }
.crm-stat-value { font-size:18px; font-weight:700; color:var(--text); line-height:1.2; }
.crm-stat-label { font-size:11px; color:var(--muted); margin-top:2px; }

/* ── LINK UTILS ──────────────────────────────────────────────── */
.crm-link-sm { font-size: 12px; color: var(--gold); text-decoration: none; }
.crm-link-sm:hover { text-decoration: underline; }

/* ── PACKAGE PICKER ──────────────────────────────────────────── */
.pkg-group-block {
  border: 1px solid var(--border); border-radius: var(--radius);
  margin-bottom: 10px; overflow: hidden;
}
.pkg-group-header {
  background: #e6f4f8; padding: 9px 14px;
  font-size: 13px; font-weight: 600; color: var(--gold-dark);
  display: flex; align-items: center; gap: 8px;
}
.pkg-group-body { padding: 10px 14px; display: flex; flex-direction: column; gap: 6px; }
.pkg-service-row {
  display: flex; align-items: center; gap: 8px;
  padding: 5px 8px; border-radius: 5px; cursor: pointer;
}
.pkg-service-row:hover { background: var(--gold-light); }
.pkg-service-row input[type="checkbox"] { width: auto; flex-shrink: 0; accent-color: var(--gold); }
input[type="checkbox"] { accent-color: var(--gold); }
.pkg-service-name { font-size: 13px; flex: 1; }
.pkg-service-price { font-size: 12px; color: var(--muted); }

/* ── ROLE BADGES ─────────────────────────────────────────────── */
.badge-role        { display:inline-block; padding:3px 10px; border-radius:12px; font-size:11px; font-weight:600; white-space:nowrap; }
.role-admin        { background:#111827; color:#fff; }
.role-ceo          { background:#0b7e9b; color:#fff; }
.role-leader       { background:#085f75; color:#fff; }
.role-accountant   { background:#0e7490; color:#fff; }
.role-sale         { background:#e6f4f8; color:#085f75; }
.role-doctor       { background:#ccebf3; color:#085f75; }
.role-ktv          { background:#ddf2f8; color:#0b7e9b; }
.role-cskh         { background:#f0fafd; color:#085f75; border:1px solid #d0e4ea; }
/* alias cũ để tránh vỡ giao diện nếu còn dữ liệu/role cũ */
.role-sale_manager { background:#085f75; color:#fff; }
.role-sale_lead    { background:#0e7490; color:#fff; }

/* ── APPT STATUS COLORS ──────────────────────────────────────── */
.badge-in_progress { background: #fff3e0; color: #e65100; }

/* ── WRAP ────────────────────────────────────────────────────── */
.crm-wrap {
  max-width: 100%;
  min-height: 100%;
}

/* ══════════════════════════════════════════════════════════════
   RESPONSIVE
   ══════════════════════════════════════════════════════════════ */

/* ── Tablet 768–900: thu gọn sidebar thành icon ── */
@media (max-width: 900px) {
  :root { --sidebar-w: 56px; }
  .crm-sidebar-brand, .crm-nav-link span:not(.crm-nav-icon),
  .crm-sidebar-section, .crm-sidebar-user-link { display: none; }
  .crm-nav-link { padding: 10px; justify-content: center; }
  .crm-sidebar-logo { padding: 12px 8px; justify-content: center; }
  .crm-sidebar-footer { padding: 8px; text-align: center; }
  .crm-grid-2col   { grid-template-columns: 1fr; }
  .crm-comm-grid   { grid-template-columns: repeat(2,1fr); }
  .crm-stat-grid   { grid-template-columns: repeat(2,1fr); }
  .crm-main        { padding: 16px; }
}

/* ── Mobile: sidebar ẩn, hiện toggle button ── */
@media (max-width: 640px) {
  :root { --sidebar-w: 0px; }

  /* App shell */
  .crm-app {
    flex-direction: column;
    height: 100vh;
    height: 100dvh;
  }

  /* Sidebar: ẩn mặc định, slide in khi open */
  .crm-sidebar {
    position: fixed;
    left: 0; top: 0; bottom: 0;
    z-index: 500;
    width: 260px !important;
    transform: translateX(-100%);
    transition: transform .25s ease;
    box-shadow: 4px 0 24px rgba(0,0,0,.4);
  }
  .crm-sidebar.open { transform: translateX(0); }
  .crm-sidebar-brand, .crm-nav-link span:not(.crm-nav-icon),
  .crm-sidebar-section { display: block !important; }
  .crm-sidebar-user-link { display: block !important; }
  .crm-nav-link { padding: 10px 16px; justify-content: flex-start; }
  .crm-sidebar-logo { padding: 16px; }
  .crm-sidebar-footer { padding: 12px 16px; }

  /* Overlay khi sidebar mở */
  .crm-sidebar-overlay {
    display: none; position: fixed; inset: 0; z-index: 499;
    background: rgba(0,0,0,.45);
  }
  .crm-sidebar-overlay.active { display: block; }

  /* Content: full width */
  .crm-content { width: 100%; flex: 1; min-height: 0; }
  .crm-main { padding: 10px 12px 20px; overflow-x: hidden; }

  /* Topbar */
  .crm-topbar { padding: 0 12px; height: 48px; }
  .crm-topbar-title { font-size: 14px; }
  .crm-menu-toggle {
    background: none; border: none; cursor: pointer;
    color: var(--text); font-size: 22px; padding: 6px 8px;
    display: flex; align-items: center; margin-right: 4px;
    -webkit-tap-highlight-color: transparent;
  }

  /* Grids: 1 cột */
  .crm-grid-2col, .crm-grid-2col-sm { grid-template-columns: 1fr !important; }
  .crm-comm-grid { grid-template-columns: 1fr 1fr !important; }
  .crm-stat-grid { grid-template-columns: 1fr 1fr !important; }
  .crm-form-row { flex-direction: column; gap: 8px; }
  .crm-form-group { min-width: 0; }

  /* Page header */
  .crm-page-header { flex-wrap: wrap; gap: 8px; margin-bottom: 12px; }
  .crm-page-header h1 { font-size: 16px; }
  .crm-header-actions { flex-wrap: wrap; gap: 6px; }

  /* Tables */
  .crm-table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; margin: 0 -1px; }
  .crm-table { min-width: 500px; }
  .crm-table th, .crm-table td { padding: 7px 9px; font-size: 12px; }

  /* Cards */
  .crm-card { padding: 12px 14px; }

  /* Modal: full screen */
  .crm-modal-box {
    width: 100% !important;
    max-width: 100% !important;
    max-height: 92dvh !important;
    margin: 0 !important;
    border-radius: 16px 16px 0 0 !important;
    position: fixed !important;
    bottom: 0 !important;
    left: 0 !important;
    right: 0 !important;
    top: auto !important;
  }

  /* Orders: layout 2 cột → 1 cột */
  .crm-order-layout { flex-direction: column !important; }
  .crm-order-sidebar { width: 100% !important; max-width: 100% !important; }

  /* Commission: 2 cột */
  .crm-comm-grid { grid-template-columns: 1fr 1fr !important; }

  /* Staff grid */
  .staff-grid { grid-template-columns: 1fr 1fr !important; }

  /* Reports */
  .rpt-kpi-grid { grid-template-columns: 1fr 1fr !important; }
  .rpt-row, .rpt-row-3 { grid-template-columns: 1fr !important; }
  .dept-grid { grid-template-columns: 1fr !important; }
  .ind-kpi-row { grid-template-columns: 1fr 1fr !important; }
  .rpt-toolbar { flex-direction: column; align-items: stretch; }
  .rpt-presets { flex-wrap: wrap; }
  .rpt-preset { font-size: 11px; padding: 5px 9px; }

  /* Appointments */
  .appt-filters { flex-direction: column; }
  .appt-warning-banner { font-size: 12px; }

  /* Buttons: đủ lớn để tap */
  .btn { padding: 9px 13px; font-size: 13px; min-height: 38px; }
  .btn-sm { padding: 5px 10px; font-size: 12px; min-height: 30px; }

  /* Settings grid */
  .settings-grid { grid-template-columns: 1fr !important; }
  .bank-form-grid { grid-template-columns: 1fr !important; }

  /* Filter bars: stack vertically */
  form[style*="display:flex"] { flex-wrap: wrap !important; }

  /* Payments table trong đơn hàng */
  #payments-table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
}

@media (max-width: 400px) {
  .crm-stat-grid { grid-template-columns: 1fr 1fr !important; }
  .staff-grid    { grid-template-columns: 1fr !important; }
  .crm-comm-grid { grid-template-columns: 1fr !important; }
  .crm-main      { padding: 8px 10px 16px; }
}

/* ── Catch-all: bất kỳ table nào trong .crm-main đều scroll ngang ── */
@media (max-width: 640px) {
  .crm-main table:not(.no-scroll) {
    display: block;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    max-width: 100%;
  }
}

/* ── Đơn hàng: cột Tư vấn / Bác sĩ TH / KTV TH (gọn, có nhãn) ── */
.ic-group{ margin-bottom:6px; }
.ic-group:last-child{ margin-bottom:0; }
.ic-lbl{ display:block; font-size:10px; font-weight:600; color:var(--muted);
  text-transform:uppercase; letter-spacing:.3px; margin-bottom:2px; }
.ic-sel, .ic-inp{ width:100%; min-width:140px; box-sizing:border-box; }
.ic-sub{ margin-top:6px; padding-top:6px; border-top:1px dashed var(--border); }
.ic-inline{ display:flex; gap:4px; align-items:center; }
.ic-hh{ display:flex; align-items:center; gap:3px; margin-top:4px; }
.ic-hh input{ flex:1; text-align:right; min-width:80px; box-sizing:border-box; }
.ic-hh .ic-cur{ font-size:11px; color:var(--muted); }
