:root {
    --blue: #0d6efd;
    --blue-dark: #075dd4;
    --bg: #f4f6f9;
    --border: #e4e8ee;
    --text: #20252b;
    --muted: #6f7782;
    --success: #22a06b;
    --danger: #ef5b64;
}

* { box-sizing: border-box; }
body {
    margin: 0;
    font-family: Arial, Helvetica, sans-serif;
    background: var(--bg);
    color: var(--text);
}
button, input, select, textarea { font: inherit; }
button { cursor: pointer; }
.app-shell { min-height: 100vh; display: grid; grid-template-columns: 300px minmax(0,1fr); }
.sidebar {
    background: linear-gradient(180deg,#0d6efd,#0864df);
    color: #fff;
    padding: 36px 30px;
}
.brand { font-size: 36px; font-weight: 700; margin-bottom: 70px; }
.side-link {
    width: 100%;
    border: 0;
    background: transparent;
    color: #fff;
    text-align: left;
    padding: 14px 18px;
    border-radius: 12px;
    font-size: 20px;
    margin-bottom: 14px;
}
.side-link.active, .side-link:hover { background: rgba(255,255,255,.18); }
.main { padding: 28px 36px 50px; min-width: 0; }
.main-tab, .subcontent { display: none; }
.main-tab.active, .subcontent.active { display: block; }
.page-header h1 { color: var(--blue); font-size: 42px; margin: 0 0 8px; }
.page-header p { color: var(--muted); margin: 0 0 30px; font-size: 18px; }
.subtabs {
    background: #fff;
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 10px;
    margin-bottom: 22px;
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}
.subtab {
    border: 0;
    background: transparent;
    color: #616975;
    padding: 14px 24px;
    border-radius: 12px;
    font-weight: 700;
    font-size: 18px;
}
.subtab.active { background: var(--blue); color: #fff; }
.panel {
    background: #fff;
    border: 1px solid var(--border);
    border-radius: 16px;
    box-shadow: 0 4px 16px rgba(26,39,60,.05);
    margin-bottom: 22px;
    overflow: hidden;
}
.panel > h3, .panel > p { padding-left: 18px; padding-right: 18px; }
.panel-head, .panel-title-row {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 16px;
    padding: 18px;
}
.panel-head h3, .panel-title-row h3 { margin: 0 0 6px; }
.panel-head p { margin: 0; color: var(--muted); }
.count-badge, .queue-pill {
    border: 0;
    background: #f1f3f5;
    border-radius: 999px;
    padding: 8px 12px;
    white-space: nowrap;
}
.control-grid {
    display: grid;
    grid-template-columns: repeat(5,minmax(0,1fr));
    gap: 10px;
    padding: 0 18px 18px;
}
.field { display: flex; flex-direction: column; gap: 7px; min-width: 0; }
.field label { font-weight: 700; font-size: 14px; }
input, select, textarea {
    width: 100%;
    border: 1px solid #cfd5dd;
    border-radius: 10px;
    padding: 11px 12px;
    background: #fff;
}
.btn {
    border: 1px solid transparent;
    border-radius: 10px;
    padding: 11px 14px;
    min-height: 44px;
}
.btn.primary { background: var(--blue); color: #fff; }
.btn.success { background: var(--success); color: #fff; }
.btn.outline { background: #fff; border-color: #aeb6c0; color: #4d5560; }
.btn.danger-outline { background: #fff; border-color: #ff8d94; color: #e85059; }
.schedule-box { border-top: 1px solid var(--border); padding: 18px; }
.schedule-box h4 { margin: 0 0 12px; }
.schedule-grid { display: grid; grid-template-columns: 1.4fr 1fr 1fr 1fr; gap: 10px; }
.status-line { margin-top: 12px; background: #f7f8fa; padding: 10px 12px; border-radius: 9px; color: var(--muted); }
.filters {
    padding: 18px;
    border-top: 1px solid var(--border);
    border-bottom: 1px solid var(--border);
    display: grid;
    grid-template-columns: 1.3fr 1fr .75fr;
    gap: 10px;
}
.bulkbar {
    padding: 14px 18px;
    background: #f8f9fb;
    display: flex;
    gap: 12px;
    align-items: center;
    flex-wrap: wrap;
}
.bulkbar select { width: auto; min-width: 190px; }
.table-wrap { overflow: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 14px 18px; border-bottom: 1px solid var(--border); text-align: left; }
th { color: #68717d; background: #fafbfc; font-size: 13px; text-transform: uppercase; }
.panel-footer { padding: 13px 18px; color: var(--muted); }
.status-badge { display: inline-block; padding: 6px 10px; border-radius: 999px; font-size: 13px; background: #edf1f5; }
.status-badge[data-status="Đã gửi Lời Mời"] { background: #fff0bf; color: #725600; }
.status-badge[data-status="Đã chấp nhận"] { background: #dff4e8; color: #11673f; }
.status-badge[data-status="Khách từ chối"] { background: #ffe4e6; color: #a3222a; }
.status-badge[data-status="Đã gửi TN 1"], .status-badge[data-status="Đã gửi TN 2"] { background: #e5efff; color: #075dd4; }

.chat-shell {
    display: grid;
    grid-template-columns: 320px minmax(0,1fr);
    min-height: 650px;
    background: #fff;
    border: 1px solid var(--border);
    border-radius: 16px;
    overflow: hidden;
}
.chat-list-panel { border-right: 1px solid var(--border); }
.chat-search { padding: 16px; border-bottom: 1px solid var(--border); }
.chat-search input { margin-top: 10px; }
.conversation-list { max-height: 590px; overflow: auto; }
.conv-item { padding: 13px 15px; border-bottom: 1px solid #eef1f4; cursor: pointer; }
.conv-item.active, .conv-item:hover { background: #edf4ff; }
.conv-name { font-weight: 700; }
.conv-preview { margin-top: 4px; color: var(--muted); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-main { display: flex; flex-direction: column; background: #f4f7fb; min-width: 0; }
.chat-header { min-height: 72px; background: #fff; border-bottom: 1px solid var(--border); padding: 16px 18px; display:flex; justify-content:space-between; align-items:center; }
.muted { color: var(--muted); font-size: 13px; }
.status-chip { font-size: 12px; background: #e4f5ea; color: #176a44; padding: 6px 9px; border-radius: 999px; }
.chat-messages { flex: 1; padding: 22px; overflow: auto; }
.message-row { display: flex; margin-bottom: 10px; }
.message-row.outgoing { justify-content: flex-end; }
.message-bubble { max-width: 70%; background: #fff; padding: 10px 12px; border-radius: 14px; }
.message-row.outgoing .message-bubble { background: #dcecff; }
.message-time { text-align:right; color:#8b939e; font-size:11px; margin-top:4px; }
.composer { display:flex; gap:10px; padding:14px; background:#fff; border-top:1px solid var(--border); }
.composer textarea { resize: vertical; min-height: 50px; }
.empty-state { color:var(--muted); text-align:center; margin-top:100px; }

.template-filter { padding: 0 18px 14px; display:flex; gap:8px; flex-wrap:wrap; }
.template-filter-btn { border:1px solid #d5dae1; background:#fff; border-radius:999px; padding:7px 12px; }
.template-filter-btn.active { background:#eaf2ff; color:var(--blue); border-color:#b9d0ff; }
.template-grid { display:grid; grid-template-columns:repeat(2,minmax(0,1fr)); gap:14px; padding:0 18px 18px; }
.template-card { border:1px solid var(--border); border-radius:12px; padding:15px; }
.template-card h4 { margin:0 0 8px; }
.template-type { font-size:12px; color:var(--muted); }
.template-text { white-space:pre-wrap; line-height:1.45; min-height:64px; }
.template-actions { display:flex; gap:8px; flex-wrap:wrap; margin-top:12px; }
.template-actions .btn { min-height:auto; padding:8px 10px; }

.import-grid { display:grid; grid-template-columns:.8fr 1.2fr; gap:20px; }
#uploadForm { display:grid; gap:10px; padding:0 18px 18px; }
.action-footer { display:flex; justify-content:space-between; align-items:center; gap:12px; }

.drawer-backdrop {
    position:fixed; inset:0; background:rgba(0,0,0,.28); opacity:0; pointer-events:none; transition:.2s;
}
.drawer-backdrop.show { opacity:1; pointer-events:auto; }
.queue-drawer {
    position:fixed; top:0; right:-440px; width:min(420px,92vw); height:100vh; background:#fff; z-index:30;
    box-shadow:-10px 0 30px rgba(0,0,0,.12); transition:.25s; display:flex; flex-direction:column;
}
.queue-drawer.show { right:0; }
.drawer-head { display:flex; justify-content:space-between; gap:10px; padding:18px; border-bottom:1px solid var(--border); }
.drawer-head h3 { margin:0 0 5px; }
.drawer-head p { margin:0; color:var(--muted); font-size:13px; }
.queue-list { overflow:auto; padding:12px; }
.queue-item { border:1px solid var(--border); border-radius:10px; padding:12px; margin-bottom:10px; display:flex; justify-content:space-between; gap:10px; }
.queue-item small { color:var(--muted); }
.icon-btn { border:0; background:transparent; font-size:28px; }

.modal-backdrop {
    position:fixed; inset:0; background:rgba(0,0,0,.35); z-index:40; display:none; align-items:center; justify-content:center; padding:20px;
}
.modal-backdrop.show { display:flex; }
.modal-card { width:min(560px,96vw); background:#fff; border-radius:14px; padding:18px; box-shadow:0 20px 50px rgba(0,0,0,.18); }
.modal-head { display:flex; justify-content:space-between; align-items:center; }
.modal-actions { display:flex; justify-content:flex-end; gap:10px; margin-top:14px; }

.toast {
    position:fixed; right:22px; bottom:22px; background:#20252b; color:#fff; padding:12px 16px; border-radius:10px;
    opacity:0; transform:translateY(10px); pointer-events:none; transition:.2s; z-index:50;
}
.toast.show { opacity:1; transform:translateY(0); }

@media (max-width: 1100px) {
    .app-shell { grid-template-columns: 220px minmax(0,1fr); }
    .brand { font-size:28px; }
    .control-grid { grid-template-columns:repeat(2,minmax(0,1fr)); }
    .schedule-grid { grid-template-columns:repeat(2,minmax(0,1fr)); }
    .import-grid { grid-template-columns:1fr; }
}
@media (max-width: 760px) {
    .app-shell { display:block; }
    .sidebar { padding:14px; }
    .brand { margin-bottom:14px; font-size:24px; }
    .side-link { display:inline-block; width:auto; font-size:15px; }
    .main { padding:18px 12px 40px; }
    .page-header h1 { font-size:30px; }
    .filters, .control-grid, .schedule-grid, .template-grid { grid-template-columns:1fr; }
    .chat-shell { grid-template-columns:1fr; }
    .chat-list-panel { border-right:0; border-bottom:1px solid var(--border); }
    .conversation-list { max-height:220px; }
}


.logout-link {
    display: block;
    text-decoration: none;
    margin-top: 24px;
}
.login-page {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 20px;
    background: #f4f6f9;
}
.login-card {
    width: min(420px, 96vw);
    background: #fff;
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 26px;
    box-shadow: 0 18px 45px rgba(0,0,0,.08);
}
.login-card h1 {
    margin-top: 0;
    color: var(--blue);
}
.login-card form {
    display: grid;
    gap: 14px;
}
.login-error {
    background: #ffe6e8;
    color: #9a2930;
    border-radius: 10px;
    padding: 10px 12px;
    margin-bottom: 14px;
}

.login-back-link { display:block; text-align:center; margin-top:12px; color:var(--blue); text-decoration:none; }
.sidebar-user { margin:26px 0 8px; padding:12px 14px; border-radius:12px; background:rgba(255,255,255,.14); display:grid; gap:4px; }
.sidebar-user small { opacity:.85; }

.members-layout { display:grid; grid-template-columns:360px minmax(0,1fr); gap:20px; }
.member-form { padding:0 18px 18px; display:grid; gap:14px; }
.member-actions { display:flex; gap:7px; flex-wrap:wrap; }
.role-badge { display:inline-block; border-radius:999px; padding:6px 10px; font-size:12px; background:#edf1f5; color:#48515c; }
.role-badge.admin { background:#e6efff; color:#075dd4; font-weight:700; }
@media (max-width:900px) { .members-layout { grid-template-columns:1fr; } }

/* Member management v2 */
.members-page { max-width: 1500px; }
.members-header { display:flex; align-items:flex-end; justify-content:space-between; gap:20px; }
.members-summary { background:#fff; border:1px solid #e3e8ef; border-radius:14px; padding:12px 18px; box-shadow:0 5px 18px rgba(20,34,60,.05); white-space:nowrap; }
.member-create-card, .member-list-card { margin-bottom:20px; overflow:hidden; }
.member-card-head { padding:22px 24px 4px; }
.member-card-head h3 { margin:0 0 5px; font-size:20px; }
.member-card-head p { margin:0; color:#6b7280; }
.member-form-grid { display:grid; grid-template-columns:1.3fr 1fr .75fr 1.15fr; gap:16px; padding:18px 24px 8px; align-items:start; }
.member-form-grid .field { margin:0; }
.member-form-grid input, .member-form-grid select { min-height:46px; }
.duration-inputs { display:grid; grid-template-columns:.7fr 1fr; gap:8px; }
.duration-field small { display:block; margin-top:6px; color:#7b8492; }
.member-form-actions { padding:10px 24px 22px; display:flex; justify-content:flex-end; }
.member-form-actions .btn { min-width:160px; }
.member-list-card .panel-title-row { padding:20px 22px; }
.members-table th { white-space:nowrap; }
.members-table td { vertical-align:middle; }
.member-identity { display:flex; align-items:center; gap:11px; min-width:190px; }
.member-identity small, .table-sub { display:block; margin-top:3px; color:#7a8492; font-size:12px; font-weight:400; }
.member-avatar { width:38px; height:38px; flex:0 0 38px; border-radius:12px; display:grid; place-items:center; background:#e9f2ff; color:#0874f9; font-weight:800; }
.member-status { display:inline-flex; align-items:center; border-radius:999px; padding:6px 10px; font-size:12px; font-weight:700; white-space:nowrap; }
.member-status.active { background:#eaf8ef; color:#15803d; }
.member-status.waiting { background:#fff7e6; color:#a16207; }
.member-status.expired { background:#feeeee; color:#c62828; }
.member-action-row { display:flex; gap:6px; flex-wrap:wrap; min-width:220px; }
.mini-btn { border:1px solid #d7dee8; background:#fff; color:#344054; border-radius:9px; padding:7px 10px; font-size:12px; cursor:pointer; }
.mini-btn:hover { background:#f6f8fb; }
.mini-btn.danger { color:#c62828; border-color:#f0c7c7; }
.mini-btn.danger:hover { background:#fff3f3; }
@media (max-width:1100px) {
  .member-form-grid { grid-template-columns:1fr 1fr; }
}
@media (max-width:680px) {
  .members-header { align-items:stretch; flex-direction:column; }
  .member-form-grid { grid-template-columns:1fr; padding:16px; }
  .member-card-head { padding:18px 16px 2px; }
  .member-form-actions { padding:8px 16px 18px; }
  .member-form-actions .btn { width:100%; }
}

.member-form-notice {
  margin:16px 24px 0;
  border-radius:10px;
  padding:11px 13px;
  font-size:14px;
  font-weight:600;
}
.member-form-notice.success { background:#ecfdf3; color:#166534; border:1px solid #bbf7d0; }
.member-form-notice.error { background:#fff1f2; color:#b42318; border:1px solid #fecdd3; }
.member-native-form { margin:0; }
