:root {
  font-family: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", "Microsoft YaHei", sans-serif;
  color-scheme: dark;
  --bg: #0b1320;
  --panel: #131e30;
  --panel-deep: #0f1828;
  --line: #283a56;
  --line-soft: #1e2c43;
  --text: #e8effb;
  --muted: #8da3c2;
  --muted-2: #667d9e;
  --blue: #8bb1ef;
  --blue-soft: #8bb1ef18;
  --orange: #f0a35e;
  --orange-soft: #f0a35e16;
  --green: #7fd1b0;
  --red: #e48b96;
  --red-soft: #e48b9616;
}

* { box-sizing: border-box; }
html, body { min-height: 100%; }
body {
  margin: 0;
  color: var(--text);
  background:
    radial-gradient(ellipse at 12% 4%, #244a8530, transparent 42%),
    radial-gradient(ellipse at 92% 100%, #5b3a7a1a, transparent 42%),
    var(--bg);
}
button, input { font: inherit; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: .45; }
[hidden] { display: none !important; }
h1, h2, p { margin: 0; }
h1 { font-size: 28px; line-height: 1.25; font-weight: 650; letter-spacing: .2px; }
h2 { font-size: 18px; line-height: 1.3; font-weight: 650; }
small { color: var(--muted); }
:focus-visible { outline: 2px solid var(--blue); outline-offset: 2px; }

.eyebrow {
  margin-bottom: 8px;
  color: var(--muted-2);
  font-size: 10px;
  font-weight: 650;
  letter-spacing: 1.8px;
  text-transform: uppercase;
}
.hint { color: var(--muted-2); font-size: 11px; line-height: 1.8; }
.form-error {
  margin-top: 12px;
  padding: 10px 12px;
  color: #ffc2c8;
  background: var(--red-soft);
  border: 1px solid #a955644d;
  border-radius: 8px;
  font-size: 12px;
  line-height: 1.7;
}

/* Login */
.login-view {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 36px 20px;
}
.login-card {
  width: min(100%, 430px);
  padding: 34px 32px 27px;
  border: 1px solid #34486670;
  border-radius: 19px;
  background: linear-gradient(145deg, #1a2941ec, #111c2fee);
  box-shadow: 0 28px 100px #02071255;
}
.brand { display: flex; align-items: center; gap: 12px; margin-bottom: 36px; }
.brand-mark {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border-radius: 13px 13px 13px 4px;
  color: #14213a;
  background: linear-gradient(135deg, #a8c7ff, #7ea7e9);
  font-size: 23px;
  font-weight: 800;
}
.brand-mark.small { width: 34px; height: 34px; border-radius: 10px 10px 10px 3px; font-size: 18px; }
.brand-name { color: #edf4ff; font-size: 17px; font-weight: 650; letter-spacing: .5px; }
.brand-name small { margin-left: 5px; color: var(--muted-2); font-size: 10px; letter-spacing: 1px; }
.login-form { display: grid; gap: 16px; margin-top: 28px; }
.login-form label { display: grid; gap: 8px; color: #b3c4dc; font-size: 12px; }
input, select {
  width: 100%;
  min-width: 0;
  padding: 11px 12px;
  color: var(--text);
  background: #0c1728;
  border: 1px solid #354967;
  border-radius: 7px;
  font-size: 13px;
  outline: none;
}
input:focus { border-color: #7ba6e8; box-shadow: 0 0 0 3px #8bb1ef17; }
input::placeholder { color: #617896; }
button {
  padding: 9px 14px;
  color: #dfeafb;
  background: #1b2739;
  border: 1px solid #334762;
  border-radius: 7px;
  font-size: 12px;
  font-weight: 550;
  transition: background .15s, border-color .15s, opacity .15s;
}
button:hover:not(:disabled) { background: #26364d; border-color: #4f6a91; }
button.primary {
  color: #111d31;
  background: linear-gradient(135deg, #a8c7ff, #82aaeb);
  border-color: #9bbcf6;
  font-weight: 700;
}
button.primary:hover:not(:disabled) { background: linear-gradient(135deg, #b9d3ff, #92b8f5); }
button.text-button {
  padding: 4px 0;
  color: var(--muted);
  background: none;
  border: 0;
  font-size: 11px;
}
button.text-button:hover:not(:disabled) { color: #c9dcf4; background: none; }
.login-form button { min-height: 44px; margin-top: 2px; font-size: 13px; }

/* Top bar */
.topbar {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 14px 28px;
  border-bottom: 1px solid #22324a;
  background: #0b1320e8;
  backdrop-filter: blur(14px);
}
.topbar-brand { display: flex; align-items: center; gap: 10px; }
.topbar-brand > div { display: grid; gap: 2px; }
.topbar-brand strong { color: #eaf2ff; font-size: 14px; letter-spacing: .5px; }
.topbar-brand small { color: var(--muted-2); font-size: 9px; letter-spacing: 1px; }
.topbar-actions { display: flex; flex-wrap: wrap; align-items: center; justify-content: flex-end; gap: 11px; }
.mode-badge {
  padding: 4px 8px;
  color: #9ec8c4;
  background: #6bc2b610;
  border: 1px solid #61b9ad36;
  border-radius: 999px;
  font-size: 10px;
}
.mode-badge.mysql { color: #d9ba8e; background: #d8a15b10; border-color: #d8a15b40; }
.admin-chip {
  padding: 4px 8px;
  color: #f3c08c;
  background: var(--orange-soft);
  border: 1px solid #f0a35e3d;
  border-radius: 999px;
  font-size: 10px;
}
.current-user { color: #d8e5f7; font-size: 12px; font-weight: 550; }

/* Main */
.dashboard { width: min(100%, 1380px); margin: 0 auto; padding: 28px 28px 64px; }
.demo-banner {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 8px 14px;
  margin-bottom: 18px;
  padding: 12px 15px;
  color: #d9bd99;
  background: var(--orange-soft);
  border: 1px solid #f0a35e38;
  border-radius: 9px;
  font-size: 11px;
  line-height: 1.7;
}
.demo-banner strong { color: #f3c18b; }
.demo-banner span { color: #b99d7d; }
.stats {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 20px;
}
.stat {
  min-width: 0;
  padding: 16px 16px 13px;
  border: 1px solid var(--line-soft);
  border-radius: 10px;
  background: linear-gradient(150deg, #162238d9, #111a2bd9);
}
.stat > span { display: block; color: var(--muted); font-size: 10px; }
.stat > strong { display: block; margin-top: 8px; color: #e7f1ff; font-size: 27px; line-height: 1; font-weight: 650; font-variant-numeric: tabular-nums; }
.stat > small { display: block; margin-top: 8px; color: #617998; font-size: 9px; line-height: 1.5; }
.panel {
  min-width: 0;
  margin-bottom: 20px;
  padding: 22px;
  border: 1px solid var(--line-soft);
  border-radius: 12px;
  background: #121c2dd9;
}
.panel-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 22px;
  margin-bottom: 17px;
}
.panel-heading > div:first-child { flex: 1 1 auto; min-width: 0; }
.panel-heading h2 { margin-bottom: 6px; }
.panel-note { max-width: 720px; color: var(--muted-2); font-size: 11px; line-height: 1.8; }
.search-box { flex: 0 0 auto; display: grid; gap: 6px; width: min(260px, 100%); color: var(--muted); font-size: 10px; }
.panel-tools { flex: 0 0 auto; display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: flex-end; gap: 10px; width: min(360px, 100%); }
.panel-tools .search-box { width: min(230px, 100%); }
.role-select { width: auto; min-width: 82px; padding: 5px 7px; font-size: 10px; }
.role-select.admin { color: #f2bb85; border-color: #f0a35e4d; background: #f0a35e12; }
.role-select.member { color: #a8c0dc; }
.status-select { width: auto; min-width: 82px; padding: 5px 7px; font-size: 10px; }
.status-select.on { color: #91d7bf; border-color: #6fd4b340; background: #6fd4b30d; }
.status-select.off { color: #dda0a8; border-color: #d58a9440; background: #d58a940d; }
.search-box input { padding: 9px 10px; font-size: 11px; }
.count-chip { padding: 5px 9px; color: var(--muted); background: #8bb1ef0b; border: 1px solid #344b6c; border-radius: 999px; font-size: 10px; white-space: nowrap; }

/* User table */
.table-wrap { overflow-x: auto; border: 1px solid #20304a; border-radius: 9px; }
table { width: 100%; border-collapse: collapse; text-align: left; }
th, td { padding: 11px 13px; border-bottom: 1px solid #1d2b42; white-space: nowrap; }
th { color: #7288a7; background: #0f1929; font-size: 9px; font-weight: 600; letter-spacing: .8px; text-transform: uppercase; }
td { color: #b4c6df; font-size: 11px; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover td { background: #18263c66; }
td.user-name { color: #e2ecfb; font-weight: 550; }
td.user-uid { color: #728aa9; font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 10px; }
.badge { display: inline-flex; align-items: center; padding: 3px 7px; border: 1px solid transparent; border-radius: 999px; font-size: 9px; line-height: 1.4; }
.badge-admin { color: #f2bb85; background: var(--orange-soft); border-color: #f0a35e36; }
.badge-member { color: #91a9c8; background: #9ab7df0b; border-color: #3b5271; }
.badge-on { color: #91d7bf; background: #6fd4b30f; border-color: #6fd4b333; }
.badge-off { color: #dda0a8; background: var(--red-soft); border-color: #d58a9433; }
.empty { padding: 26px 12px; color: #6982a3; text-align: center; font-size: 11px; }

/* Libraries */
.library-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(310px, 1fr)); gap: 12px; }
.library-card {
  display: flex;
  flex-direction: column;
  gap: 13px;
  min-width: 0;
  padding: 17px;
  border: 1px solid #293b56;
  border-radius: 10px;
  background: linear-gradient(150deg, #162239e6, #111a2be6);
}
.library-card.is-disabled { opacity: .68; }
.library-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 14px; }
.library-name { min-width: 0; margin: 0; color: #e3eefc; font-size: 14px; font-weight: 600; line-height: 1.5; overflow-wrap: anywhere; }
.library-meta { margin-top: 5px; color: #7189aa; font-size: 10px; line-height: 1.7; }
.library-status { flex: 0 0 auto; padding: 3px 7px; border-radius: 999px; font-size: 9px; white-space: nowrap; }
.status-live { color: #8fd8bf; background: #6fd4b30f; border: 1px solid #6fd4b333; }
.status-off { color: #dca0a8; background: var(--red-soft); border: 1px solid #d58a9433; }
.status-draft { color: #c8b18f; background: #d8a15b0d; border: 1px solid #d8a15b33; }
.visibility-line { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; color: #8fa7c5; font-size: 11px; line-height: 1.6; }
.visibility-line strong { color: #c5d9f2; font-weight: 550; }
.visibility-badge { padding: 3px 7px; color: #a7c4f0; background: #8bb1ef0e; border: 1px solid #47648d; border-radius: 5px; font-size: 9px; }
.visibility-badge.selected { color: #ecc08e; background: var(--orange-soft); border-color: #f0a35e3b; }
.selected-preview { margin-top: 4px; color: #657e9d; font-size: 10px; line-height: 1.7; overflow-wrap: anywhere; }
.library-actions { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-top: auto; padding-top: 2px; }
.library-readonly { color: #b38b7e; font-size: 10px; line-height: 1.6; }

/* Dialog */
.visibility-dialog, .user-dialog { width: min(720px, calc(100vw - 28px)); max-height: 88vh; padding: 0; color: var(--text); background: transparent; border: 0; }
.user-dialog { width: min(760px, calc(100vw - 28px)); }
.visibility-dialog::backdrop, .user-dialog::backdrop { background: #020711b8; backdrop-filter: blur(3px); }
.user-dialog .dialog-card { max-height: 86vh; overflow: auto; }
.dialog-card { margin: 0; padding: 23px; border: 1px solid #385073; border-radius: 14px; background: #142136; box-shadow: 0 30px 100px #00000066; }
.dialog-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 20px; margin-bottom: 19px; }
.dialog-heading .panel-note { margin-top: 6px; }
.icon-button { flex: 0 0 auto; width: 30px; height: 30px; padding: 0; color: #a9bdd8; background: #18263b; border-color: #334966; font-size: 19px; line-height: 1; }
.visibility-modes { display: flex; flex-wrap: wrap; gap: 11px 24px; margin: 0; padding: 14px 15px; border: 1px solid #2b3f5c; border-radius: 9px; }
.visibility-modes legend { padding: 0 5px; color: #9db2ce; font-size: 10px; }
.visibility-modes label { display: inline-flex; align-items: center; gap: 8px; color: #c1d2e8; font-size: 12px; cursor: pointer; }
input[type="radio"], input[type="checkbox"] { width: 15px; height: 15px; min-height: 0; margin: 0; padding: 0; accent-color: var(--blue); box-shadow: none; }
.visibility-members { margin-top: 16px; }
.visibility-members .search-box { width: 100%; }
.visibility-members .hint { margin-top: 10px; }
.member-list { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 7px; max-height: 300px; margin-top: 10px; padding: 8px; overflow: auto; border: 1px solid #273a55; border-radius: 9px; background: #0e1828; }
.member-list .empty { grid-column: 1 / -1; }
.member-row { display: flex; align-items: center; gap: 9px; min-width: 0; padding: 8px 9px; border: 1px solid transparent; border-radius: 7px; cursor: pointer; }
.member-row:hover { background: #172740; }
.member-row.is-selected { border-color: #435e86; background: #1a2b46; }
.member-row.is-disabled { opacity: .55; cursor: not-allowed; }
.member-row input { flex: 0 0 auto; }
.member-copy { display: grid; min-width: 0; gap: 2px; }
.member-copy strong { overflow: hidden; color: #d4e2f4; font-size: 11px; font-weight: 550; text-overflow: ellipsis; white-space: nowrap; }
.member-copy small { overflow: hidden; color: #6e86a6; font-size: 9px; text-overflow: ellipsis; white-space: nowrap; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 9px; margin-top: 21px; padding-top: 17px; border-top: 1px solid #263a55; }
.dialog-actions button { min-width: 86px; }
.user-form-grid { display: grid; grid-template-columns: minmax(0, 1.5fr) minmax(150px, 1fr); gap: 12px; }
.user-form-grid label { display: grid; gap: 7px; color: var(--muted); font-size: 11px; }
.member-search-field { margin: 17px 0 0; padding: 13px 14px; border: 1px solid #2b3f5c; border-radius: 9px; }
.member-search-field legend { padding: 0 5px; color: #9db2ce; font-size: 10px; }
.member-search-field .search-box { width: 100%; }
.member-results { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 7px; max-height: 210px; margin-top: 9px; overflow: auto; }
.member-results .empty { grid-column: 1 / -1; }
.member-result { display: flex; flex-direction: column; align-items: flex-start; gap: 3px; width: 100%; padding: 9px 10px; color: #c3d5ea; background: #0e1828; border: 1px solid #273a55; border-radius: 7px; text-align: left; }
.member-result:hover:not(:disabled) { background: #1a2b46; border-color: #47648d; }
.member-result.is-bound { opacity: .55; }
.member-result strong { color: #dbe8f8; font-size: 11px; font-weight: 550; }
.member-result small { color: #7189aa; font-size: 9px; }
.member-result.is-selected { border-color: #f0a35e80; background: #f0a35e12; }
.selected-member { display: flex; flex-wrap: wrap; align-items: baseline; gap: 6px 10px; margin-top: 12px; padding: 10px 12px; color: #9eb5d2; background: #8bb1ef0d; border: 1px solid #3d597e; border-radius: 8px; font-size: 10px; }
.selected-member strong { color: #dceafb; font-size: 12px; font-weight: 550; }
.selected-member small { color: #7189aa; font-size: 10px; }
.selected-member .text-button { margin-left: auto; }

/* Toast and misc */
.toast {
  position: fixed;
  right: 24px;
  bottom: 24px;
  z-index: 20;
  max-width: min(420px, calc(100vw - 48px));
  padding: 11px 14px;
  color: #d8eee5;
  background: #17352e;
  border: 1px solid #4f9b8155;
  border-radius: 8px;
  box-shadow: 0 15px 45px #0000004d;
  font-size: 11px;
  line-height: 1.7;
}
.toast.error { color: #ffd1d6; background: #3a1e25; border-color: #b5637055; }
.noscript { padding: 40px; color: var(--muted); text-align: center; }

@media (max-width: 1100px) {
  .stats { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}
@media (max-width: 820px) {
  .topbar { align-items: flex-start; padding: 13px 18px; }
  .panel-tools { width: 100%; justify-content: flex-start; }
  .user-form-grid, .member-results { grid-template-columns: minmax(0, 1fr); }
  .topbar-actions { gap: 8px; }
  .dashboard { padding: 20px 16px 48px; }
  .panel-heading { flex-direction: column; gap: 14px; }
  .search-box { width: 100%; }
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .member-list { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 520px) {
  .login-card { padding: 28px 22px 23px; }
  .brand { margin-bottom: 28px; }
  .topbar { flex-direction: column; }
  .topbar-actions { justify-content: flex-start; }
  .stats { grid-template-columns: minmax(0, 1fr); }
  .stat { display: grid; grid-template-columns: 1fr auto; align-items: baseline; gap: 4px 12px; }
  .stat > strong { grid-row: span 2; margin: 0; font-size: 24px; }
  .stat > small { margin: 0; }
  .panel { padding: 16px; }
  .library-grid { grid-template-columns: minmax(0, 1fr); }
  .dialog-card { padding: 18px; }
  .toast { right: 16px; bottom: 16px; }
}
@media (prefers-reduced-motion: reduce) {
  * { scroll-behavior: auto !important; transition: none !important; animation: none !important; }
}
