:root {
  --navy: #1b2a4a;
  --navy-2: #2a3d66;
  --accent: #d7263d;
  --bg: #f5f6f8;
  --surface: #ffffff;
  --line: #e4e7ec;
  --line-2: #eef0f3;
  --text: #1a2233;
  --muted: #6b7385;
  --faint: #9aa1af;
  --word: #2b579a;
  --cell: #217346;
  --slide: #c4501f;
  --ok: #1f8a4c;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .05), 0 1px 3px rgba(16, 24, 40, .06);
  --shadow-lg: 0 12px 32px rgba(16, 24, 40, .14);
  --topbar: 56px;
  --sidebar: 264px;
  --chat: 340px;
  font-family: "Be Vietnam Pro", "Segoe UI", Arial, sans-serif;
  color: var(--text);
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); }
body { font-size: 14px; line-height: 1.5; -webkit-font-smoothing: antialiased; }
button, input, textarea { font: inherit; color: inherit; }
a { color: var(--navy-2); }
.boot { display: grid; place-items: center; height: 100vh; color: var(--muted); }
.hidden { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

/* ---------- nút ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 36px; padding: 0 14px; border-radius: 8px; border: 1px solid var(--line);
  background: var(--surface); cursor: pointer; font-weight: 500; white-space: nowrap;
  transition: background .15s, border-color .15s, box-shadow .15s;
}
.btn:hover { background: #f8f9fb; border-color: #d3d7de; }
.btn:focus-visible, .icon-btn:focus-visible, .input:focus-visible { outline: 2px solid var(--navy-2); outline-offset: 2px; }
.btn-primary { background: var(--navy); border-color: var(--navy); color: #fff; }
.btn-primary:hover { background: var(--navy-2); border-color: var(--navy-2); }
.btn-danger { color: var(--accent); }
.btn-danger.solid { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-ghost { border-color: transparent; background: transparent; }
.btn-ghost:hover { background: var(--line-2); border-color: transparent; }
.btn[disabled] { opacity: .55; cursor: default; }
.icon-btn {
  display: inline-grid; place-items: center; width: 34px; height: 34px; border-radius: 8px;
  border: 0; background: transparent; cursor: pointer; color: var(--muted); position: relative;
}
.icon-btn:hover { background: var(--line-2); color: var(--text); }
.icon-btn svg, .btn svg { width: 18px; height: 18px; flex: none; }
.badge {
  position: absolute; top: 2px; right: 2px; min-width: 16px; height: 16px; padding: 0 4px;
  border-radius: 8px; background: var(--accent); color: #fff; font-size: 10px; font-weight: 700;
  display: grid; place-items: center;
}

.input {
  width: 100%; height: 42px; padding: 0 12px; border: 1px solid var(--line); border-radius: 8px;
  background: #fff; transition: border-color .15s;
}
.input:focus { border-color: var(--navy-2); outline: none; }
textarea.input { height: auto; padding: 10px 12px; resize: vertical; }
label.field { display: block; margin-bottom: 14px; }
label.field span { display: block; margin-bottom: 6px; font-weight: 500; font-size: 13px; }

/* ---------- đăng nhập ---------- */
.login {
  min-height: 100vh; display: grid; place-items: center; padding: 24px 16px;
  background: linear-gradient(180deg, #eef1f6 0%, var(--bg) 60%);
}
.login-card {
  width: 100%; max-width: 400px; background: var(--surface); border-radius: 16px;
  padding: 36px 32px; box-shadow: var(--shadow-lg);
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; color: var(--navy); }
.brand-mark { width: 30px; height: 30px; border-radius: 8px; background: var(--navy); display: grid; place-items: center; flex: none; }
.brand-mark svg { width: 18px; height: 18px; }
.login-card h1 { font-size: 22px; margin: 28px 0 6px; letter-spacing: -.01em; }
.login-card p.lead { margin: 0 0 24px; color: var(--muted); }
.login-card .btn { width: 100%; height: 44px; margin-top: 6px; }
.form-error { color: var(--accent); font-size: 13px; min-height: 20px; margin-top: 8px; }

/* ---------- khung ứng dụng ---------- */
.shell {
  height: 100vh; display: grid;
  grid-template-columns: var(--sidebar) minmax(0, 1fr) var(--chat);
  grid-template-rows: var(--topbar) minmax(0, 1fr);
  grid-template-areas: "top top top" "side main chat";
}
.shell.no-chat { grid-template-columns: var(--sidebar) minmax(0, 1fr) 0; }
.shell.editing { grid-template-columns: 0 minmax(0, 1fr) var(--chat); }
.shell.editing.no-chat { grid-template-columns: 0 minmax(0, 1fr) 0; }

.topbar {
  grid-area: top; display: flex; align-items: center; gap: 12px; padding: 0 16px;
  background: var(--surface); border-bottom: 1px solid var(--line); min-width: 0;
}
.topbar .crumbs { display: flex; align-items: center; gap: 8px; min-width: 0; flex: 1; color: var(--muted); }
.topbar .crumbs b { color: var(--text); font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.topbar .crumbs .sep { color: var(--faint); }
.topbar .crumbs .crumb-room { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 30%; cursor: pointer; }
.topbar .crumbs .crumb-room:hover { color: var(--text); }
.save-state { font-size: 12px; color: var(--faint); white-space: nowrap; }
.user-chip { display: flex; align-items: center; gap: 8px; padding: 4px 4px 4px 10px; border-radius: 20px; border: 1px solid var(--line); }
.user-chip .name { max-width: 140px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 500; }
.menu-toggle { display: none; }

.sidebar {
  grid-area: side; background: var(--surface); border-right: 1px solid var(--line);
  display: flex; flex-direction: column; min-height: 0; overflow: hidden;
}
.sidebar-head { display: flex; align-items: center; justify-content: space-between; padding: 18px 16px 10px; }
.sidebar-head h2 { margin: 0; font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.room-list { list-style: none; margin: 0; padding: 0 8px 16px; overflow-y: auto; flex: 1; }
.room-item {
  display: flex; align-items: center; gap: 10px; padding: 9px 10px; border-radius: 8px; cursor: pointer;
  color: var(--text); text-decoration: none;
}
.room-item:hover { background: var(--line-2); }
.room-item.active { background: #e9edf5; }
.room-item.active .room-name { font-weight: 600; color: var(--navy); }
.room-icon { width: 30px; height: 30px; border-radius: 8px; display: grid; place-items: center; font-weight: 700; font-size: 13px; color: #fff; flex: none; }
.room-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.online-dot { display: inline-flex; align-items: center; gap: 4px; font-size: 11px; color: var(--ok); }
.online-dot::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: var(--ok); }
.sidebar-empty { padding: 12px 16px; color: var(--muted); font-size: 13px; }

.main { grid-area: main; min-width: 0; min-height: 0; overflow: auto; }
.main.editor-mode { overflow: hidden; display: flex; flex-direction: column; }
.page { max-width: 1080px; margin: 0 auto; padding: 28px 32px 48px; }

/* ---------- trang phòng ---------- */
.room-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 24px; flex-wrap: wrap; }
.room-head h1 { margin: 0; font-size: 24px; letter-spacing: -.015em; line-height: 1.25; word-break: break-word; }
.room-head p { margin: 6px 0 0; color: var(--muted); max-width: 640px; }
.room-actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

.avatars { display: flex; align-items: center; }
.avatar {
  width: 30px; height: 30px; border-radius: 50%; display: grid; place-items: center; flex: none;
  color: #fff; font-weight: 600; font-size: 12px; border: 2px solid #fff; user-select: none;
}
.avatars .avatar + .avatar { margin-left: -8px; }
.avatar.sm { width: 22px; height: 22px; font-size: 10px; border-width: 1.5px; }
.avatars .more { background: var(--line); color: var(--muted); }

.create-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; margin-bottom: 28px; }
.create-card {
  display: flex; align-items: center; gap: 12px; padding: 14px; border-radius: var(--radius);
  background: var(--surface); border: 1px solid var(--line); cursor: pointer; text-align: left;
  transition: border-color .15s, box-shadow .15s, transform .15s;
}
.create-card:hover { border-color: #cfd4dc; box-shadow: var(--shadow); transform: translateY(-1px); }
.create-card b { display: block; font-weight: 600; }
.create-card small { color: var(--muted); font-size: 12px; }
.create-card.upload { border-style: dashed; }
.create-card.dragover { border-color: var(--navy-2); background: #f0f3f9; }

.ficon {
  width: 38px; height: 38px; border-radius: 9px; display: grid; place-items: center; flex: none;
  color: #fff; font-size: 10px; font-weight: 700; letter-spacing: .03em;
}
.ficon.word { background: var(--word); }
.ficon.cell { background: var(--cell); }
.ficon.slide { background: var(--slide); }
.ficon.up { background: var(--line-2); color: var(--navy); }
.ficon.up svg { width: 20px; height: 20px; }
.ficon.sm { width: 32px; height: 32px; border-radius: 8px; font-size: 9px; }

.section-title { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin: 0 0 10px; }
.section-title h2 { font-size: 15px; margin: 0; }
.search { max-width: 240px; height: 34px; }

.doc-table { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.doc-row {
  display: grid; grid-template-columns: minmax(0, 1fr) 190px 90px 132px; align-items: center; gap: 12px;
  padding: 10px 14px; border-top: 1px solid var(--line-2);
}
.doc-row:first-child { border-top: 0; }
.doc-row.head { background: #fafbfc; color: var(--muted); font-size: 12px; font-weight: 500; padding-top: 8px; padding-bottom: 8px; }
.doc-row:not(.head):hover { background: #fafbfc; }
.doc-main { display: flex; align-items: center; gap: 12px; min-width: 0; cursor: pointer; }
.doc-title { font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.doc-main:hover .doc-title { color: var(--navy-2); text-decoration: underline; }
.doc-sub { font-size: 12px; color: var(--muted); display: flex; align-items: center; gap: 6px; }
.doc-meta { color: var(--muted); font-size: 13px; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.doc-acts { display: flex; justify-content: flex-end; gap: 2px; }
.editing-now { display: inline-flex; align-items: center; gap: 4px; color: var(--ok); font-weight: 500; }

.empty {
  padding: 48px 24px; text-align: center; color: var(--muted);
  background: var(--surface); border: 1px dashed var(--line); border-radius: var(--radius);
}
.empty h3 { color: var(--text); margin: 0 0 6px; font-size: 16px; }
.empty p { margin: 0 0 16px; }

.welcome { max-width: 560px; margin: 12vh auto 0; text-align: center; padding: 0 16px; }
.welcome h1 { font-size: 26px; letter-spacing: -.015em; margin: 0 0 8px; }
.welcome p { color: var(--muted); margin: 0 0 22px; }
.steps { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin-top: 36px; text-align: left; }
.step { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; }
.step b { display: block; color: var(--navy); margin-bottom: 4px; }
.step span { color: var(--muted); font-size: 13px; }

/* ---------- trình soạn thảo ---------- */
.editor-wrap { flex: 1; min-height: 0; position: relative; background: #fff; }
.editor-wrap iframe { display: block; border: 0; }
.editor-status {
  position: absolute; inset: 0; display: grid; place-items: center; text-align: center; padding: 24px;
  background: var(--bg); color: var(--muted);
}
.editor-status .box { max-width: 520px; }
.editor-status h3 { color: var(--text); margin: 12px 0 6px; }
.editor-status code { background: #fff; border: 1px solid var(--line); padding: 2px 6px; border-radius: 4px; font-size: 12px; word-break: break-all; }
.spinner { width: 28px; height: 28px; border-radius: 50%; border: 3px solid var(--line); border-top-color: var(--navy); animation: spin 0.8s linear infinite; margin: 0 auto; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- khung chat ---------- */
.chat {
  grid-area: chat; background: var(--surface); border-left: 1px solid var(--line);
  display: flex; flex-direction: column; min-height: 0; min-width: 0; overflow: hidden;
}
.no-chat .chat { border-left: 0; }
.chat-head { padding: 12px 12px 10px 16px; border-bottom: 1px solid var(--line); }
.chat-head .row { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.chat-head h2 { margin: 0; font-size: 15px; }
.conn { margin-left: 8px; font-weight: 400; font-size: 11px; color: var(--faint); display: inline-flex; align-items: center; gap: 5px; }
.conn::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: var(--faint); }
.conn.on { color: var(--ok); } .conn.on::before { background: var(--ok); }
.people { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.person { display: inline-flex; align-items: center; gap: 6px; padding: 2px 8px 2px 2px; border-radius: 14px; background: var(--line-2); font-size: 12px; max-width: 100%; }
.person span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.person .where { color: var(--muted); }

.messages { flex: 1; overflow-y: auto; padding: 12px 16px; display: flex; flex-direction: column; gap: 2px; }
.load-older { align-self: center; margin-bottom: 8px; font-size: 12px; height: 28px; }
.day-sep { align-self: center; font-size: 11px; color: var(--faint); margin: 12px 0 6px; }
.msg { display: grid; grid-template-columns: 30px minmax(0, 1fr); gap: 0 10px; margin-top: 10px; }
.msg.cont { margin-top: 0; }
.msg.cont .avatar { visibility: hidden; height: 0; }
.msg-head { display: flex; align-items: baseline; gap: 8px; }
.msg-head b { font-size: 13px; }
.msg-head time { font-size: 11px; color: var(--faint); }
.msg-text { white-space: pre-wrap; word-wrap: break-word; overflow-wrap: anywhere; }
.msg.mine .msg-head b { color: var(--navy); }
.msg-empty { margin: auto; text-align: center; color: var(--muted); padding: 24px; }
.typing { height: 18px; padding: 0 16px; font-size: 12px; color: var(--muted); }

.composer { padding: 8px 12px 12px; border-top: 1px solid var(--line); }
.composer form { display: flex; align-items: flex-end; gap: 8px; border: 1px solid var(--line); border-radius: 10px; padding: 6px 6px 6px 12px; background: #fff; }
.composer form:focus-within { border-color: var(--navy-2); }
.composer textarea { flex: 1; border: 0; outline: none; resize: none; max-height: 140px; min-height: 22px; padding: 5px 0; line-height: 1.45; background: transparent; }
.composer .btn { height: 32px; padding: 0 12px; }
.composer .hint { font-size: 11px; color: var(--faint); margin-top: 6px; }

/* ---------- modal & toast ---------- */
.modal-backdrop { position: fixed; inset: 0; background: rgba(16, 24, 40, .45); display: grid; place-items: center; padding: 16px; z-index: 50; }
.modal { width: 100%; max-width: 420px; background: #fff; border-radius: 14px; box-shadow: var(--shadow-lg); padding: 22px; }
.modal h3 { margin: 0 0 6px; font-size: 17px; }
.modal p { margin: 0 0 16px; color: var(--muted); }
.modal .actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 8px; }

#toasts { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); display: flex; flex-direction: column; gap: 8px; z-index: 60; width: max-content; max-width: calc(100vw - 32px); }
.toast { background: var(--navy); color: #fff; padding: 10px 14px; border-radius: 10px; box-shadow: var(--shadow-lg); font-size: 13px; animation: rise .2s ease-out; }
.toast.error { background: var(--accent); }
@keyframes rise { from { opacity: 0; transform: translateY(6px); } }

.scrim { display: none; }

/* ---------- màn hình nhỏ ---------- */
@media (max-width: 1100px) {
  :root { --chat: 300px; --sidebar: 230px; }
  .create-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .doc-row { grid-template-columns: minmax(0, 1fr) 90px 132px; }
  .doc-row .col-updated { display: none; }
}
@media (max-width: 860px) {
  .shell, .shell.no-chat, .shell.editing, .shell.editing.no-chat { grid-template-columns: minmax(0, 1fr); grid-template-areas: "top" "main"; }
  .menu-toggle { display: inline-grid; }
  .sidebar, .chat {
    position: fixed; top: var(--topbar); bottom: 0; z-index: 40; box-shadow: var(--shadow-lg);
    transition: transform .2s ease-out;
  }
  .sidebar { left: 0; width: min(300px, 86vw); transform: translateX(-100%); }
  .chat { right: 0; width: min(380px, 100vw); transform: translateX(100%); }
  .shell.side-open .sidebar { transform: none; }
  .shell:not(.no-chat) .chat { transform: none; }
  .shell.side-open .scrim, .shell:not(.no-chat) .scrim { display: block; position: fixed; inset: var(--topbar) 0 0 0; background: rgba(16, 24, 40, .3); z-index: 30; }
  .page { padding: 20px 16px 40px; }
  .user-chip .name { display: none; }
  .user-chip { padding: 2px; border: 0; }
  .topbar { padding: 0 8px; gap: 6px; }
  .topbar .brand-text { display: none; }
  .steps { grid-template-columns: 1fr; }
}
@media (max-width: 560px) {
  .chat { width: 100vw; }
  .create-grid { grid-template-columns: minmax(0, 1fr); }
  .doc-row { grid-template-columns: minmax(0, 1fr) 96px; }
  .doc-row .col-size { display: none; }
  .search { max-width: 150px; }
  .room-head h1 { font-size: 20px; }
}

/* ---------- fallback editor ---------- */
.fallback-editor {
  display: flex;
  flex-direction: column;
  height: 100%;
  width: 100%;
  background: var(--surface);
  position: absolute;
  inset: 0;
  z-index: 10;
}
.fallback-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 18px;
  background: #fff;
  border-bottom: 1px solid var(--line);
  gap: 12px;
  flex-wrap: wrap;
}
.fallback-toolbar-left {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}
.fallback-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: #f0fdf4;
  color: #166534;
  border: 1px solid #bbf7d0;
  padding: 4px 10px;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 600;
}
.fallback-status {
  font-size: 13px;
  color: var(--muted);
}
.fallback-status.dirty {
  color: #b54708;
  font-weight: 500;
}
.fallback-status.saved {
  color: var(--ok);
  font-weight: 500;
}
.fallback-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}
.fallback-notice {
  padding: 8px 18px;
  background: #eff8ff;
  border-bottom: 1px solid #d1e9ff;
  font-size: 13px;
  color: #175cd3;
  display: flex;
  align-items: center;
  gap: 8px;
}
.fallback-body {
  flex: 1;
  padding: 20px;
  background: #f4f6f8;
  overflow: auto;
  display: flex;
  justify-content: center;
}
.fallback-sheet {
  width: 100%;
  max-width: 880px;
  min-height: calc(100% - 20px);
  background: #fff;
  box-shadow: 0 4px 16px rgba(0,0,0,0.07);
  border-radius: 6px;
  border: 1px solid var(--line);
  display: flex;
  flex-direction: column;
}
.fallback-sheet-header {
  padding: 16px 24px 12px;
  border-bottom: 1px solid var(--line-2);
}
.fallback-doc-title {
  font-size: 18px;
  font-weight: 600;
  color: var(--navy);
}
.fallback-doc-meta {
  font-size: 12px;
  color: var(--muted);
  margin-top: 4px;
}
.fallback-sheet textarea {
  flex: 1;
  width: 100%;
  min-height: 480px;
  padding: 20px 24px;
  border: 0;
  outline: none;
  resize: vertical;
  font-family: inherit;
  font-size: 15px;
  line-height: 1.7;
  color: var(--text);
  background: transparent;
}

