:root {
  --bg: #f6f7fb;
  --surface: #ffffff;
  --surface-2: #f1f3f8;
  --border: #e3e6ee;
  --text: #171b26;
  --muted: #5d6578;
  --primary: #2563eb;
  --primary-soft: #e8efff;
  --shadow: 0 1px 2px rgba(16, 24, 40, .05), 0 4px 16px rgba(16, 24, 40, .06);
  --radius: 14px;
  --ok: #15803d;   --ok-bg: #e7f6ec;
  --warn: #b45309; --warn-bg: #fdf3e2;
  --off: #6b7280;  --off-bg: #eef0f3;
  --info: #0369a1; --info-bg: #e0f2fe;
  --plan: #7c3aed; --plan-bg: #f1eafe;
}
:root[data-theme="dark"] {
  --bg: #0f1218;
  --surface: #171b24;
  --surface-2: #1f2430;
  --border: #2a303d;
  --text: #e8ebf2;
  --muted: #9aa3b5;
  --primary: #6b9bff;
  --primary-soft: #1d2a47;
  --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 4px 16px rgba(0, 0, 0, .25);
  --ok: #4ade80;   --ok-bg: #15301f;
  --warn: #fbbf24; --warn-bg: #352812;
  --off: #9ca3af;  --off-bg: #262b35;
  --info: #38bdf8; --info-bg: #0f2a3a;
  --plan: #c4b5fd; --plan-bg: #2a2045;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; }
body {
  font-family: "Be Vietnam Pro", system-ui, -apple-system, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  display: flex;
  min-height: 100vh;
}
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
svg.lucide { width: 18px; height: 18px; flex-shrink: 0; display: block; }

.container { max-width: 1280px; width: 100%; min-width: 0; margin: 0 auto; padding: 0 40px; }

.main-header { padding: 32px 0 16px; position: relative; }
.header-container { display: flex; justify-content: center; align-items: center; min-height: 44px; }
.header-titles h1 { margin: 0 0 4px; font-size: clamp(22px, 3vw, 28px); letter-spacing: -.02em; font-weight: 700; text-align: center; }
.header-titles p { margin: 0; color: var(--muted); font-size: 15px; text-align: center; }
.top-actions { position: absolute; right: 40px; top: 32px; z-index: 10; display: flex; align-items: center; gap: 16px; }

/* Sidebar */
.sidebar {
  width: 260px;
  background: transparent;
  border-right: none;
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
  flex-shrink: 0;
}
.sidebar-head { padding: 24px; }
.sidebar-nav { flex: 1; padding: 0 16px; display: flex; flex-direction: column; gap: 8px; }

.brand { display: flex; align-items: center; gap: 10px; color: var(--text); font-size: 18px; }
.brand:hover { text-decoration: none; }
.brand b { color: var(--primary); }
.brand-logo { width: 36px; height: 36px; border-radius: 50%; display: block; }
.brand-sub { font-size: 12px; font-weight: 500; color: var(--muted); margin-left: 4px; padding: 2px 8px; border-radius: 999px; background: var(--surface-2); }

.sidebar-nav .btn { justify-content: flex-start; border-color: transparent; background: transparent; padding: 10px 14px; font-size: 15px; }
.sidebar-nav .btn:hover { background: var(--surface-2); }
.sidebar-nav .btn svg.lucide { width: 20px; height: 20px; }

.main-content { flex: 1; min-width: 0; display: flex; flex-direction: column; min-height: 100vh; }
.main-content > .footer { margin-top: auto; }

/* Hero */
.hero { padding: 0 0 24px; text-align: center; }
.search { display: flex; align-items: center; gap: 12px; max-width: 640px; margin: 0 auto; padding: 0 20px; height: 56px; border-radius: 14px; background: var(--surface); border: 1px solid var(--border); box-shadow: var(--shadow); color: var(--muted); }
.search:focus-within { border-color: var(--primary); }
.search input { flex: 1; min-width: 0; border: 0; outline: 0; background: transparent; color: var(--text); font: inherit; font-size: 16px; }
.search svg.lucide { width: 20px; height: 20px; }

/* Tabs */
.tabs { display: flex; justify-content: center; gap: 4px; border-bottom: 1px solid var(--border); overflow-x: auto; scrollbar-width: none; }
.tab { display: flex; align-items: center; gap: 8px; padding: 12px 14px; border: 0; background: none; color: var(--muted); font: inherit; font-weight: 500; cursor: pointer; border-bottom: 2px solid transparent; margin-bottom: -1px; white-space: nowrap; }
.tab:hover { color: var(--text); }
.tab.active { color: var(--primary); border-bottom-color: var(--primary); }
.count { font-size: 12px; padding: 1px 8px; border-radius: 999px; background: var(--surface-2); color: var(--muted); }
.tab.active .count { background: var(--primary-soft); color: var(--primary); }

/* Chips */
.chips { display: flex; justify-content: center; flex-wrap: wrap; gap: 8px; padding: 18px 0; }
.chip { padding: 6px 14px; border-radius: 999px; border: 1px solid var(--border); background: var(--surface); color: var(--muted); font: inherit; font-size: 14px; cursor: pointer; }
.chip:hover { color: var(--text); }
.chip.active { background: var(--primary); border-color: var(--primary); color: #fff; }

/* Grid & cards */
.grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; padding-bottom: 48px; }
.card { display: flex; flex-direction: column; gap: 12px; padding: 18px; border-radius: var(--radius); background: var(--surface); border: 1px solid var(--border); box-shadow: var(--shadow); transition: transform .15s, border-color .15s; }
.card.link { color: inherit; text-decoration: none; }
.card.link:hover { transform: translateY(-2px); border-color: var(--primary); text-decoration: none; }
.card .corner { margin-left: auto; color: var(--muted); }
.card h3 .badge { vertical-align: 2px; margin-left: 4px; }
.card-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.card-actions .btn { flex: 1 1 auto; justify-content: center; white-space: nowrap; }
.card-actions:has(> .btn:only-child) .btn { flex: 0 1 auto; }
.card-head { display: flex; gap: 12px; align-items: flex-start; }
.card-head > div { min-width: 0; }
.card h3 { margin: 0; font-size: 16px; }
.card .url { font-size: 13px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; display: block; }
.card p { margin: 0; color: var(--muted); font-size: 14px; flex: 1; }
.card-foot { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }

.tool-icon { display: grid; place-items: center; width: 46px; height: 46px; border-radius: 12px; color: #fff; flex-shrink: 0; font-weight: 700; font-size: 18px; }
.tool-icon svg.lucide { width: 24px; height: 24px; }
.tool-icon.ext { background: var(--surface-2); border: 1px solid var(--border); }
.tool-icon.ext img { width: 26px; height: 26px; }

.badge { display: inline-flex; align-items: center; gap: 4px; font-size: 12px; padding: 2px 9px; border-radius: 999px; background: var(--surface-2); color: var(--muted); white-space: nowrap; }
.badge svg.lucide { width: 13px; height: 13px; }
.badge.ok { background: var(--ok-bg); color: var(--ok); }
.badge.warn { background: var(--warn-bg); color: var(--warn); }
.badge.off { background: var(--off-bg); color: var(--off); }
.badge.info { background: var(--info-bg); color: var(--info); }
.badge.plan { background: var(--plan-bg); color: var(--plan); }
.badge.primary { background: var(--primary-soft); color: var(--primary); }

.btn { display: inline-flex; align-items: center; gap: 6px; padding: 9px 14px; border-radius: 10px; border: 1px solid var(--border); background: var(--surface); color: var(--text); font: inherit; font-size: 14px; font-weight: 500; cursor: pointer; }
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.primary:hover { filter: brightness(1.08); }

.icon-btn { display: grid; place-items: center; width: 38px; height: 38px; border-radius: 10px; border: 1px solid var(--border); background: var(--surface); color: var(--text); cursor: pointer; padding: 0; }
.icon-btn:hover { background: var(--surface-2); }
.icon-btn.sm { width: 32px; height: 32px; border-radius: 8px; border-color: transparent; background: transparent; color: var(--muted); }
.icon-btn.sm svg.lucide { width: 16px; height: 16px; }

.empty { text-align: center; color: var(--muted); padding: 48px 0; }

/* Modal */
.modal { width: min(640px, calc(100vw - 32px)); max-height: calc(100vh - 48px); padding: 0; border: 1px solid var(--border); border-radius: 18px; background: var(--surface); color: var(--text); box-shadow: 0 24px 64px rgba(0, 0, 0, .25); }
.modal::backdrop { background: rgba(10, 14, 22, .5); }
.modal-body { padding: 24px; display: flex; flex-direction: column; gap: 18px; }
.modal-head { display: flex; gap: 14px; align-items: flex-start; }
.modal-head h2 { margin: 0; font-size: 20px; }
.modal-head .grow { flex: 1; min-width: 0; }
.modal-head .tool-icon { width: 56px; height: 56px; }
.modal p { margin: 0; color: var(--muted); }
.meta { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; }
.meta div { padding: 12px; border-radius: 12px; background: var(--surface-2); }
.meta small { display: block; color: var(--muted); font-size: 12px; margin-bottom: 2px; }
.section-title { font-size: 13px; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin: 0 0 8px; }
.doc-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.doc-list a { display: flex; align-items: center; gap: 8px; padding: 10px 12px; border-radius: 10px; border: 1px solid var(--border); color: var(--text); }
.doc-list a:hover { border-color: var(--primary); text-decoration: none; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; }

.footer { border-top: 1px solid var(--border); padding: 20px 0; color: var(--muted); font-size: 14px; text-align: center; }

@media (max-width: 1024px) {
  .grid { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 768px) {
  body { flex-direction: column; }
  .container { padding: 0 20px; }
  .sidebar { width: 100%; height: auto; position: static; border-right: none; border-bottom: 1px solid var(--border); padding: 12px 20px; flex-direction: row; align-items: center; justify-content: flex-start; gap: 12px; }
  .sidebar-head { display: none; }
  .sidebar-nav { flex-direction: row; padding: 0; flex: 0; margin: 0; }
  .sidebar-nav .btn span { display: none; }
  .sidebar-nav .btn { padding: 8px; }
  .sidebar-foot { padding: 0; border: none; }
  .main-content { height: auto; overflow: visible; }
  .main-header { padding: 16px 0; position: static; }
  .header-container { flex-direction: column; align-items: flex-start; gap: 16px; }
  .header-titles h1, .header-titles p { text-align: left; }
  .top-actions { position: absolute; right: 20px; top: 12px; justify-content: flex-end; padding-right: 0; align-self: auto; z-index: 100; }
  .grid { grid-template-columns: 1fr; }
  .tabs { justify-content: flex-start; }
  .card .url { white-space: normal; word-break: break-all; overflow-wrap: break-word; }
}

@media (max-width: 560px) {
  .grid { grid-template-columns: 1fr; }
  .meta { grid-template-columns: 1fr; }
  .hide-sm { display: none; }
  .brand-sub { display: none; }
  .hero { padding: 28px 0 20px; }
}

.btn.disabled { color: var(--muted); background: var(--surface-2); border-style: dashed; cursor: default; }
.btn.disabled:hover { background: var(--surface-2); }

.notice { display: flex; gap: 14px; align-items: flex-start; max-width: 620px; margin: 24px auto 64px; padding: 20px; border-radius: var(--radius); background: var(--surface); border: 1px solid var(--border); box-shadow: var(--shadow); }
.notice > svg.lucide { width: 24px; height: 24px; color: var(--primary); }
.notice.error > svg.lucide { color: var(--warn); }
.notice p { margin: 4px 0 0; color: var(--muted); }

/* ---------- Admin ---------- */
.admin-main { padding-top: 12px; padding-bottom: 96px; }
.admin-head h1 { margin: 0 0 6px; font-size: 24px; letter-spacing: -.01em; }
.admin-head p { margin: 0 0 20px; color: var(--muted); max-width: 760px; }
.toolbar { display: flex; gap: 12px; align-items: center; justify-content: space-between; padding: 18px 0 6px; }
.search.small { margin: 0; height: 40px; max-width: 320px; flex: 1; box-shadow: none; padding: 0 12px; border-radius: 10px; }
.search.small input { font-size: 14px; }
.search.small svg.lucide { width: 18px; height: 18px; }
.hint { margin: 6px 0 14px; color: var(--muted); font-size: 13px; }

.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); }
.matrix { width: 100%; border-collapse: collapse; font-size: 14px; }
.matrix th { position: sticky; top: 0; background: var(--surface-2); color: var(--muted); font-weight: 600; font-size: 12px; text-align: left; padding: 10px; white-space: nowrap; border-bottom: 1px solid var(--border); }
.matrix td { padding: 8px 10px; border-bottom: 1px solid var(--border); }
.matrix tr:last-child td { border-bottom: 0; }
.matrix tbody tr:hover td { background: color-mix(in srgb, var(--primary-soft) 45%, transparent); }
.matrix .c { text-align: center; width: 1%; }
.matrix th.everyone { color: var(--primary); }
.matrix .name-col { position: sticky; left: 0; background: var(--surface); min-width: 240px; z-index: 1; }
.matrix th.name-col { background: var(--surface-2); z-index: 2; }
.matrix input[type="checkbox"] { width: 18px; height: 18px; accent-color: var(--primary); cursor: pointer; }
.matrix input[type="checkbox"]:disabled { opacity: .45; cursor: default; }
.matrix.groups .name-col { min-width: 220px; }

.name-btn { display: flex; align-items: center; gap: 10px; border: 0; background: none; padding: 0; color: var(--text); font: inherit; text-align: left; cursor: pointer; }
.name-btn span { display: flex; flex-direction: column; line-height: 1.25; justify-content: center; padding-top: 2px; }
.name-btn b { font-weight: 600; }
.name-btn:hover b { color: var(--primary); text-decoration: underline; }
.name-btn small, .user-cell small { color: var(--muted); font-size: 12px; }
.mini-icon { display: grid; place-items: center; width: 30px; height: 30px; border-radius: 8px; color: #fff; flex-shrink: 0; }
.mini-icon svg.lucide { width: 16px; height: 16px; }
.user-cell { display: flex; flex-direction: column; gap: 2px; }

.inline-input { width: 100%; padding: 4px 6px; border: 1px solid transparent; border-radius: 6px; background: transparent; color: var(--muted); font: inherit; font-size: 13px; }
.inline-input.strong { color: var(--text); font-size: 14px; font-weight: 600; }
.inline-input:hover { border-color: var(--border); }
.inline-input:focus { border-color: var(--primary); outline: 0; background: var(--surface); color: var(--text); }

.icon-btn.danger:hover { color: #dc2626; background: color-mix(in srgb, #dc2626 12%, transparent); }

.modal h2 { margin: 0; font-size: 19px; }
.field { display: flex; flex-direction: column; gap: 6px; font-size: 14px; }
.field > span { font-weight: 500; }
.field input:not([type="checkbox"]), .field textarea, .field select { width: 100%; padding: 9px 12px; border-radius: 10px; border: 1px solid var(--border); background: var(--bg); color: var(--text); font: inherit; font-size: 14px; }
.field input[type="color"] { height: 40px; padding: 4px; max-width: 90px; }
.field input:focus, .field textarea:focus, .field select:focus { outline: 0; border-color: var(--primary); }
.pick { display: flex; flex-wrap: wrap; gap: 8px; }
.pick-item { display: flex; align-items: center; gap: 6px; padding: 6px 12px; border-radius: 999px; border: 1px solid var(--border); cursor: pointer; font-size: 14px; }
.pick-item:has(input:checked) { border-color: var(--primary); background: var(--primary-soft); color: var(--primary); }
.pick-item.everyone { font-weight: 600; }
.pick-item input { accent-color: var(--primary); }
.actions.end { justify-content: flex-end; }

.savebar { position: fixed; left: 0; right: 0; bottom: 0; z-index: 20; background: var(--surface); border-top: 1px solid var(--border); box-shadow: 0 -6px 24px rgba(0, 0, 0, .08); }
.savebar-inner { display: flex; align-items: center; justify-content: space-between; gap: 12px; height: 64px; }
.savebar-inner > span { display: flex; align-items: center; gap: 8px; color: var(--warn); font-weight: 500; font-size: 14px; }
.savebar-inner > div { display: flex; gap: 8px; }

.toast { position: fixed; left: 50%; bottom: 84px; transform: translateX(-50%); z-index: 30; padding: 10px 18px; border-radius: 10px; background: var(--text); color: var(--bg); font-size: 14px; box-shadow: var(--shadow); max-width: calc(100vw - 32px); }
.toast.error { background: #dc2626; color: #fff; }
.name-btn em.badge, .user-cell em.badge { font-style: normal; font-weight: 500; margin-left: 4px; }

/* Sắp xếp thứ tự */
.name-wrap { display: flex; align-items: center; gap: 6px; }
.grip { display: grid; place-items: center; width: 22px; height: 30px; margin-left: -4px; border-radius: 6px; color: var(--muted); cursor: grab; flex-shrink: 0; touch-action: none; }
.grip:hover { background: var(--surface-2); color: var(--text); }
.grip svg.lucide { width: 16px; height: 16px; }
.row-actions { display: flex; align-items: center; justify-content: flex-end; gap: 2px; }
.icon-btn.sm:disabled { opacity: .3; cursor: default; background: transparent; }
.matrix tr.dragging td { opacity: .4; }
.matrix tr.drop-before td { box-shadow: inset 0 2px 0 var(--primary); }
.matrix tr.drop-after td { box-shadow: inset 0 -2px 0 var(--primary); }



/* Fix optical centering */
@media (min-width: 1400px) {
  .container {
    padding-right: 300px;
    max-width: 1540px;
  }
}
