:root {
  --bg: #07101d;
  --sidebar: rgba(7, 16, 29, 0.94);
  --surface: rgba(14, 25, 42, 0.84);
  --surface-strong: #101d30;
  --surface-soft: rgba(19, 32, 51, 0.72);
  --line: rgba(148, 163, 184, 0.15);
  --line-strong: rgba(148, 163, 184, 0.28);
  --text: #edf4ff;
  --muted: #8ea0b8;
  --subtle: #61748e;
  --green: #5ee095;
  --blue: #55b9f3;
  --amber: #f6bd60;
  --violet: #9ca8ff;
  --danger: #f4777c;
  --radius-xl: 22px;
  --radius-lg: 16px;
  --radius-md: 12px;
  --shadow: 0 24px 60px rgba(2, 6, 23, 0.3);
  --ease: 200ms cubic-bezier(.16, 1, .3, 1);
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html { min-height: 100%; }

body {
  min-height: 100vh;
  color: var(--text);
  background:
    radial-gradient(850px 540px at 88% -12%, rgba(21, 128, 61, 0.13), transparent 60%),
    linear-gradient(145deg, #08111f 0%, #050b14 100%);
  font-family: "Avenir Next", "PingFang TC", "Noto Sans TC", "Microsoft JhengHei", sans-serif;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  opacity: 0.25;
  background-image:
    linear-gradient(rgba(148, 163, 184, 0.05) 1px, transparent 1px),
    linear-gradient(90deg, rgba(148, 163, 184, 0.05) 1px, transparent 1px);
  background-size: 56px 56px;
  mask-image: linear-gradient(to bottom, black, transparent 84%);
}

button, input, select { font: inherit; }
button, select { cursor: pointer; }
a { color: inherit; }
svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; }

.ambient {
  position: fixed;
  width: 340px;
  height: 340px;
  top: -260px;
  left: 58%;
  border-radius: 50%;
  background: rgba(94, 224, 149, 0.18);
  filter: blur(100px);
  pointer-events: none;
}

.sidebar {
  position: fixed;
  z-index: 30;
  inset: 0 auto 0 0;
  width: 256px;
  display: flex;
  flex-direction: column;
  padding: 24px 18px 18px;
  border-right: 1px solid var(--line);
  background: var(--sidebar);
  backdrop-filter: blur(20px);
}

.brand { display: flex; align-items: center; gap: 12px; padding: 0 8px; text-decoration: none; }
.brand-mark {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  border-radius: 13px;
  color: #06120b;
  background: linear-gradient(135deg, #8af0b5, #43ca7c);
  box-shadow: 0 12px 30px rgba(67, 202, 124, 0.18);
  font-size: 18px;
  font-weight: 900;
}
.brand-copy { display: grid; }
.brand-copy strong { font-size: 14px; }
.brand-copy small { color: var(--subtle); font-size: 9px; font-weight: 800; letter-spacing: .16em; text-transform: uppercase; }

.nav { margin-top: 38px; }
.nav-label { display: block; padding: 0 12px 9px; color: var(--subtle); font-size: 10px; font-weight: 800; letter-spacing: .14em; text-transform: uppercase; }
.nav-label--spaced { margin-top: 28px; }
.nav-item {
  min-height: 46px;
  display: flex;
  align-items: center;
  gap: 11px;
  margin-bottom: 4px;
  padding: 0 12px;
  border: 1px solid transparent;
  border-radius: 12px;
  color: var(--muted);
  text-decoration: none;
  font-size: 13px;
  font-weight: 700;
  transition: color var(--ease), background var(--ease), border-color var(--ease);
}
.nav-item svg { width: 18px; height: 18px; }
.nav-item:hover { color: var(--text); background: rgba(148, 163, 184, 0.06); }
.nav-item.is-active {
  color: #d8ffe7;
  border-color: rgba(94, 224, 149, 0.18);
  background: linear-gradient(90deg, rgba(94, 224, 149, 0.14), rgba(94, 224, 149, 0.04));
}
.coming-soon { margin-left: auto; color: var(--subtle); font-size: 9px; font-weight: 700; }

.admin-card {
  min-height: 62px;
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: auto;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: rgba(15, 25, 42, 0.7);
}
.avatar {
  width: 38px;
  height: 38px;
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  border-radius: 50%;
  color: #06120b;
  background: #6ee7a2;
  font-size: 12px;
  font-weight: 900;
}
.avatar--owner { background: linear-gradient(135deg, #8af0b5, #43ca7c); }
.admin-card div { min-width: 0; display: grid; }
.admin-card strong { overflow: hidden; font-size: 12px; text-overflow: ellipsis; white-space: nowrap; }
.admin-card small { color: var(--subtle); font-size: 10px; }
.logout-button {
  width: 32px;
  height: 32px;
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  margin-left: auto;
  border: 0;
  border-radius: 9px;
  color: var(--subtle);
  background: transparent;
  transition: color var(--ease), background var(--ease);
}
.logout-button:hover { color: var(--text); background: rgba(148, 163, 184, .08); }
.logout-button svg { width: 16px; height: 16px; }

.main { position: relative; z-index: 1; min-height: 100vh; margin-left: 256px; }
.topbar {
  height: 72px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 clamp(22px, 4vw, 54px);
  border-bottom: 1px solid var(--line);
  background: rgba(7, 16, 29, .55);
  backdrop-filter: blur(18px);
}
.breadcrumb { display: flex; align-items: center; gap: 9px; color: var(--subtle); font-size: 12px; }
.breadcrumb a { text-decoration: none; }
.breadcrumb strong { color: var(--muted); }
.prototype-badge {
  min-height: 32px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 0 11px;
  border: 1px solid rgba(246, 189, 96, .18);
  border-radius: 999px;
  color: #f8d89b;
  background: rgba(246, 189, 96, .08);
  font-size: 10px;
  font-weight: 800;
}
.prototype-badge span { width: 6px; height: 6px; border-radius: 50%; background: var(--amber); }
.menu-button { display: none !important; }

.content { width: min(1280px, calc(100% - 44px)); margin: 0 auto; padding: 38px 0 40px; }
.page-heading { display: flex; align-items: end; justify-content: space-between; gap: 24px; margin-bottom: 28px; }
.eyebrow { margin-bottom: 7px; color: var(--green); font-size: 10px; font-weight: 850; letter-spacing: .18em; }
.page-heading h1 { font-size: clamp(32px, 3.5vw, 48px); line-height: 1; letter-spacing: -.045em; }
.page-heading p:last-child { margin-top: 10px; color: var(--muted); font-size: 13px; }

.primary-button, .secondary-button, .icon-button {
  border: 0;
  color: inherit;
  transition: transform var(--ease), background var(--ease), border-color var(--ease), box-shadow var(--ease);
}
.primary-button {
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 0 16px;
  border-radius: 12px;
  color: #06120b;
  background: linear-gradient(135deg, #7be8a9, #42cb7b);
  box-shadow: 0 12px 28px rgba(66, 203, 123, .17);
  font-size: 12px;
  font-weight: 850;
}
.primary-button svg { width: 17px; height: 17px; }
.primary-button:hover { transform: translateY(-2px); box-shadow: 0 16px 34px rgba(66, 203, 123, .26); }
.secondary-button {
  min-height: 44px;
  padding: 0 17px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: rgba(148, 163, 184, .06);
  font-size: 12px;
  font-weight: 800;
}
.secondary-button:hover { border-color: var(--line-strong); background: rgba(148, 163, 184, .1); }
.icon-button { width: 38px; height: 38px; display: grid; place-items: center; border-radius: 10px; background: transparent; }
.icon-button:hover { background: rgba(148, 163, 184, .08); }

.stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; margin-bottom: 14px; }
.stat-card {
  min-height: 90px;
  display: flex;
  align-items: center;
  gap: 13px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  background: var(--surface);
  box-shadow: 0 14px 34px rgba(2, 6, 23, .18);
}
.stat-icon { width: 42px; height: 42px; flex: 0 0 auto; display: grid; place-items: center; border-radius: 13px; }
.stat-icon svg { width: 20px; height: 20px; }
.stat-icon--green { color: var(--green); background: rgba(94, 224, 149, .11); }
.stat-icon--blue { color: var(--blue); background: rgba(85, 185, 243, .11); }
.stat-icon--amber { color: var(--amber); background: rgba(246, 189, 96, .11); }
.stat-icon--violet { color: var(--violet); background: rgba(156, 168, 255, .11); }
.stat-card div { display: grid; }
.stat-card span { color: var(--muted); font-size: 10px; font-weight: 750; }
.stat-card strong { margin-top: 2px; font-size: 25px; line-height: 1; }

.users-panel {
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: var(--radius-xl);
  background: var(--surface);
  box-shadow: var(--shadow);
}
.panel-heading { display: flex; align-items: center; justify-content: space-between; gap: 20px; padding: 20px 22px 16px; }
.panel-heading h2 { font-size: 17px; }
.panel-heading p { margin-top: 3px; color: var(--muted); font-size: 11px; }
.result-count { color: var(--subtle); font-size: 10px; font-weight: 800; }

.toolbar { display: flex; gap: 9px; padding: 0 22px 16px; }
.search-field, .select-field {
  min-height: 40px;
  display: flex;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 11px;
  background: rgba(5, 12, 23, .58);
}
.search-field { width: min(360px, 100%); gap: 9px; padding: 0 12px; }
.search-field svg { width: 17px; height: 17px; color: var(--subtle); }
.search-field input, .select-field select {
  width: 100%;
  border: 0;
  outline: 0;
  color: var(--text);
  background: transparent;
  font-size: 11px;
}
.search-field input::placeholder { color: var(--subtle); }
.select-field { min-width: 126px; padding: 0 10px; }
.select-field select { color: var(--muted); }
.search-field:focus-within, .select-field:focus-within { border-color: rgba(94, 224, 149, .5); box-shadow: 0 0 0 3px rgba(94, 224, 149, .08); }

.table-wrap { overflow-x: auto; border-top: 1px solid var(--line); }
table { width: 100%; border-collapse: collapse; min-width: 860px; }
th { padding: 11px 18px; color: var(--subtle); background: rgba(5, 12, 23, .38); font-size: 9px; font-weight: 850; letter-spacing: .08em; text-align: left; text-transform: uppercase; }
td { padding: 14px 18px; border-top: 1px solid rgba(148, 163, 184, .09); color: var(--muted); font-size: 11px; vertical-align: middle; }
tbody tr { transition: background var(--ease); }
tbody tr:hover { background: rgba(148, 163, 184, .035); }
.user-cell { display: flex; align-items: center; gap: 11px; }
.user-cell .avatar { width: 36px; height: 36px; color: var(--text); background: linear-gradient(135deg, #1e3a52, #244c45); }
.user-copy { min-width: 0; display: grid; }
.user-copy strong { color: var(--text); font-size: 12px; }
.user-copy small { color: var(--subtle); font-size: 10px; }
.role-badge, .status-badge {
  display: inline-flex;
  align-items: center;
  width: fit-content;
  min-height: 25px;
  padding: 0 9px;
  border-radius: 999px;
  font-size: 9px;
  font-weight: 850;
  white-space: nowrap;
}
.role-owner { color: #d8ffe7; background: rgba(94, 224, 149, .12); }
.role-admin { color: #dbe1ff; background: rgba(156, 168, 255, .12); }
.role-member { color: #caecff; background: rgba(85, 185, 243, .12); }
.role-viewer { color: #d7dfeb; background: rgba(148, 163, 184, .11); }
.status-badge { gap: 6px; }
.status-badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; }
.status-active { color: #c8f7da; background: rgba(94, 224, 149, .1); }
.status-active::before { background: var(--green); }
.status-inactive { color: #b7c1cf; background: rgba(148, 163, 184, .09); }
.status-inactive::before { background: var(--subtle); }

.permission-stack { display: flex; align-items: center; }
.permission-dot {
  width: 27px;
  height: 27px;
  display: grid;
  place-items: center;
  margin-left: -5px;
  border: 2px solid #101b2c;
  border-radius: 50%;
  color: #d9e6f5;
  background: #24364d;
  font-size: 8px;
  font-weight: 900;
}
.permission-dot:first-child { margin-left: 0; }
.permission-more { margin-left: 7px; color: var(--subtle); font-size: 9px; }
.last-active { display: grid; }
.last-active strong { color: #c6d1df; font-size: 10px; font-weight: 700; }
.last-active small { color: var(--subtle); font-size: 9px; }
.row-action {
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  margin-left: auto;
  border: 1px solid var(--line);
  border-radius: 10px;
  color: var(--muted);
  background: transparent;
  transition: color var(--ease), border-color var(--ease), background var(--ease);
}
.row-actions { display: flex; justify-content: flex-end; gap: 6px; }
.row-action--danger:hover { color: #ffc1c4; border-color: rgba(244, 119, 124, .3); background: rgba(244, 119, 124, .08); }
.row-action svg { width: 16px; height: 16px; }
.row-action:hover { color: var(--text); border-color: var(--line-strong); background: rgba(148, 163, 184, .08); }
.row-action:disabled { cursor: not-allowed; opacity: .35; }

.empty-state { padding: 48px 20px; text-align: center; }
.empty-state > span { width: 44px; height: 44px; display: grid; place-items: center; margin: 0 auto 12px; border-radius: 14px; color: var(--subtle); background: rgba(148, 163, 184, .08); }
.empty-state h3 { font-size: 14px; }
.empty-state p { margin-top: 4px; color: var(--subtle); font-size: 11px; }

.security-note {
  display: flex;
  gap: 12px;
  margin-top: 14px;
  padding: 15px 17px;
  border: 1px solid rgba(246, 189, 96, .14);
  border-radius: 14px;
  background: rgba(246, 189, 96, .055);
}
.security-note > span { width: 34px; height: 34px; flex: 0 0 auto; display: grid; place-items: center; border-radius: 10px; color: var(--amber); background: rgba(246, 189, 96, .1); }
.security-note svg { width: 18px; height: 18px; }
.security-note strong { color: #f5ddb0; font-size: 11px; }
.security-note p { margin-top: 2px; color: #9f927c; font-size: 10px; }

.sidebar-backdrop { display: none; }
.user-dialog {
  width: min(680px, calc(100% - 32px));
  max-height: min(820px, calc(100vh - 32px));
  overflow-y: auto;
  margin: auto;
  border: 1px solid var(--line-strong);
  border-radius: 22px;
  color: var(--text);
  background: #0d192a;
  box-shadow: 0 34px 100px rgba(0, 0, 0, .55);
}
.user-dialog::backdrop { background: rgba(1, 5, 12, .76); backdrop-filter: blur(7px); }
.user-dialog form { padding: 24px; }
.dialog-heading { display: flex; align-items: start; justify-content: space-between; margin-bottom: 22px; }
.dialog-heading h2 { font-size: 24px; letter-spacing: -.035em; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.form-field { display: grid; gap: 7px; }
.form-field > span, .permission-fieldset legend { color: #c7d2e1; font-size: 10px; font-weight: 800; }
.form-field em { color: var(--subtle); font-size: 8px; font-style: normal; font-weight: 600; }
.form-field input, .form-field select {
  width: 100%;
  min-height: 43px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 11px;
  outline: 0;
  color: var(--text);
  background: rgba(5, 12, 23, .58);
  font-size: 12px;
}
.form-field input:focus, .form-field select:focus { border-color: rgba(94, 224, 149, .48); box-shadow: 0 0 0 3px rgba(94, 224, 149, .08); }
.form-field input.is-invalid { border-color: rgba(244, 119, 124, .65); }
.password-field {
  min-height: 43px;
  display: flex;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 11px;
  background: rgba(5, 12, 23, .58);
}
.password-field:focus-within { border-color: rgba(94, 224, 149, .48); box-shadow: 0 0 0 3px rgba(94, 224, 149, .08); }
.password-field:has(.is-invalid) { border-color: rgba(244, 119, 124, .65); }
.password-field input { min-height: 41px; border: 0; background: transparent; box-shadow: none !important; }
.password-field button { width: 38px; height: 38px; flex: 0 0 auto; display: grid; place-items: center; margin-right: 2px; border: 0; border-radius: 9px; color: var(--subtle); background: transparent; }
.password-field button:hover { color: var(--text); background: rgba(148, 163, 184, .08); }
.password-field svg { width: 16px; height: 16px; }
.field-error { min-height: 14px; color: #ff9fa3; font-size: 9px; }
.permission-fieldset { position: relative; margin-top: 22px; padding: 17px; border: 1px solid var(--line); border-radius: 14px; }
.permission-fieldset legend { padding: 0 6px; }
.permission-fieldset > p { margin-bottom: 14px; color: var(--subtle); font-size: 10px; }
.permission-actions { position: absolute; top: 13px; right: 14px; display: flex; gap: 7px; }
.permission-actions button { border: 0; color: var(--green); background: transparent; font-size: 9px; font-weight: 800; }
.permission-actions button:hover { text-decoration: underline; }
.permission-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.permission-option {
  min-height: 52px;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 10px;
  border: 1px solid var(--line);
  border-radius: 11px;
  background: rgba(5, 12, 23, .3);
  cursor: pointer;
}
.permission-option:has(input:checked) { border-color: rgba(94, 224, 149, .3); background: rgba(94, 224, 149, .055); }
.permission-option input { width: 16px; height: 16px; accent-color: #43ca7c; }
.permission-copy { min-width: 0; display: grid; }
.permission-copy strong { overflow: hidden; color: #dce7f5; font-size: 10px; text-overflow: ellipsis; white-space: nowrap; }
.permission-copy small { color: var(--subtle); font-size: 8px; }
.dialog-footer { display: flex; justify-content: flex-end; gap: 9px; margin-top: 22px; padding-top: 18px; border-top: 1px solid var(--line); }

.delete-dialog {
  width: min(470px, calc(100% - 32px));
  margin: auto;
  border: 1px solid rgba(244, 119, 124, .24);
  border-radius: 20px;
  color: var(--text);
  background: #111a29;
  box-shadow: 0 34px 100px rgba(0, 0, 0, .58);
}
.delete-dialog::backdrop { background: rgba(1, 5, 12, .8); backdrop-filter: blur(7px); }
.delete-dialog form { padding: 24px; }
.danger-icon { width: 45px; height: 45px; display: grid; place-items: center; margin-bottom: 15px; border-radius: 14px; color: #ffafb3; background: rgba(244, 119, 124, .1); }
.danger-icon svg { width: 22px; height: 22px; }
.delete-dialog h2 { font-size: 23px; letter-spacing: -.035em; }
.delete-dialog > form > p { margin: 7px 0 20px; color: var(--muted); font-size: 11px; line-height: 1.65; }
.delete-dialog > form > p strong, .delete-dialog .form-field b { color: #ffbdc0; }
.delete-dialog .form-field b { font-family: "SFMono-Regular", Consolas, monospace; }
.danger-button {
  min-height: 44px;
  padding: 0 16px;
  border: 1px solid rgba(244, 119, 124, .28);
  border-radius: 12px;
  color: #fff;
  background: #c44f55;
  font-size: 11px;
  font-weight: 850;
  transition: background var(--ease), opacity var(--ease);
}
.danger-button:hover:not(:disabled) { background: #dc5b62; }
.danger-button:disabled { cursor: not-allowed; opacity: .36; }

.toast {
  position: fixed;
  z-index: 50;
  right: 22px;
  bottom: 22px;
  min-width: 220px;
  padding: 13px 16px;
  border: 1px solid rgba(94, 224, 149, .24);
  border-radius: 12px;
  color: #d8ffe7;
  background: #10261d;
  box-shadow: var(--shadow);
  font-size: 11px;
  font-weight: 750;
  opacity: 0;
  pointer-events: none;
  transform: translateY(10px);
  transition: opacity var(--ease), transform var(--ease);
}
.toast.is-visible { opacity: 1; transform: translateY(0); }

button:focus-visible, a:focus-visible, input:focus-visible, select:focus-visible {
  outline: 2px solid #7be8a9;
  outline-offset: 3px;
}

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

@media (max-width: 820px) {
  .sidebar { transform: translateX(-100%); transition: transform var(--ease); }
  body.sidebar-open .sidebar { transform: translateX(0); }
  .sidebar-backdrop { position: fixed; z-index: 20; inset: 0; display: block; background: rgba(1, 5, 12, .68); opacity: 0; pointer-events: none; transition: opacity var(--ease); }
  body.sidebar-open .sidebar-backdrop { opacity: 1; pointer-events: auto; }
  .main { margin-left: 0; }
  .menu-button { display: grid !important; }
  .topbar { justify-content: flex-start; gap: 12px; }
  .prototype-badge { margin-left: auto; }
  .content { width: min(100% - 30px, 1280px); padding-top: 28px; }
  .toolbar { flex-wrap: wrap; }
  .search-field { width: 100%; }
  .select-field { flex: 1; }
}

@media (max-width: 620px) {
  .prototype-badge { font-size: 0; padding: 0 10px; }
  .page-heading { align-items: stretch; flex-direction: column; }
  .page-heading .primary-button { width: 100%; }
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
  .stat-card { min-height: 78px; padding: 12px; }
  .stat-icon { width: 36px; height: 36px; }
  .stat-card strong { font-size: 21px; }
  .panel-heading { align-items: flex-start; }
  .toolbar, .panel-heading { padding-left: 14px; padding-right: 14px; }
  .table-wrap { overflow: visible; padding: 0 10px 10px; border-top: 1px solid var(--line); }
  table, tbody { display: block; min-width: 0; }
  thead { display: none; }
  tbody tr {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 11px 14px;
    margin-top: 10px;
    padding: 14px;
    border: 1px solid var(--line);
    border-radius: 14px;
    background: rgba(5, 12, 23, .34);
  }
  td { display: block; padding: 0; border: 0; }
  td:nth-child(1) { grid-column: 1 / -1; }
  td:nth-child(3) { grid-column: 1 / -1; }
  td:nth-child(4) { display: none; }
  td:nth-child(6) { grid-column: 2; grid-row: 2; }
  .permission-stack { padding-top: 2px; }
  .row-action { width: 32px; height: 32px; }
  .row-actions { gap: 5px; }
  .form-grid, .permission-grid { grid-template-columns: 1fr; }
  .user-dialog form { padding: 18px; }
  .permission-actions { position: static; justify-content: flex-end; margin: -3px 0 10px; }
  .security-note p { font-size: 9px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition-duration: .01ms !important; }
}
